Class RayCastRenderer

  • Direct Known Subclasses:
    RayCastColor, RayCastIntensity

    public abstract class RayCastRenderer
    extends Renderer
    A ray tracer for 3D images. Either a parallel or perspective camera model can be selected to form the rays. In the parallel case, zooming is accomplished by changing the size of the viewport. In the perspective case, zooming is accomplished by moving the eye point. The line segment of intersection (if it exists) of a ray with the bounding box of the image is computed. The image is trilinearly interpolated to allow subvoxel evaluations.

    The camera coordinate system has eye point is E = (0,0,z). The direction vector is D = (0,0,1), the up vector is U = (0,1,0), and the right vector is R = (1,0,0). Only the eye point is allowed to change. Since the 3D image can be arbitrarily rotated (via a virtual trackball), any portion of the image can be viewed either close up or far away.

    The view plane has normal D and origin at E+n*D (n=near). The view frustum is orthogonal and has no far plane. For a perspective camera, the field of view is given as an angle A subtended at the eye point. In camera coordinates, the view port is the square [-e,e]^2 where e = n*tan(A/2). In world coordinates, the corners of the square are E+n*D+s*e*U+t*e*R where |s| = |t| = 1 (four choices on sign). For a parallel camera, there is no field of view.

    The mapping between the viewport [-e,e]^2 and the B-by-B render image is the following. If (i,j) is a pixel in the image, then the corresponding viewport point is (r,u) = (-e+2*e*i/(B-1),-e+2*e*j/(B-1)).

    • Field Detail

      • m_fInvXDelta

        protected float m_fInvXDelta
        The inverse delta values are for scaling back to original coordinates for correct interpolation of the image.
      • m_fInvYDelta

        protected float m_fInvYDelta
        The inverse delta values are for scaling back to original coordinates for correct interpolation of the image.
      • m_fInvZDelta

        protected float m_fInvZDelta
        The inverse delta values are for scaling back to original coordinates for correct interpolation of the image.
      • m_kExtent

        protected javax.vecmath.Vector3f m_kExtent
        Oriented bounding box of image, centered at (0,0,0), axes are stored as the columns of a rotation matrix, and half-widths are specified.
      • m_kMDir

        protected javax.vecmath.Vector3f m_kMDir
        DOCUMENT ME!
      • m_kMOrig

        protected javax.vecmath.Point3f m_kMOrig
        Ray in box (model) coordinates.
      • m_kP0

        protected javax.vecmath.Point3f m_kP0
        the intersection points of ray with box.
      • m_kP1

        protected javax.vecmath.Point3f m_kP1
        the intersection points of ray with box.
      • m_kPDiff

        protected javax.vecmath.Vector3f m_kPDiff
        DOCUMENT ME!
      • m_kV

        protected javax.vecmath.Vector3f m_kV
        Intersection of ray with view plane.
      • m_kWDir

        protected javax.vecmath.Vector3f m_kWDir
        DOCUMENT ME!
      • m_kWOrig

        protected javax.vecmath.Vector3f m_kWOrig
        Ray in world coordinates.
      • opacityFunctA

        protected ModelLUT opacityFunctA
        DOCUMENT ME!
      • opacityFunctB

        protected ModelLUT opacityFunctB
        DOCUMENT ME!
      • red

        protected float red
        DOCUMENT ME!
      • green

        protected float green
        DOCUMENT ME!
      • blue

        protected float blue
        DOCUMENT ME!
      • vertexDiffuse

        protected javax.vecmath.Color3f vertexDiffuse
        Vertex material diffuse color.
      • vertexSpecular

        protected javax.vecmath.Color3f vertexSpecular
        Vertex material specular color.
      • xLUTa

        protected float[] xLUTa
        Used to store the transfer function points for remapping to the LUT.
      • xLUTb

        protected float[] xLUTb
        DOCUMENT ME!
      • yLUTa

        protected float[] yLUTa
        DOCUMENT ME!
      • yLUTb

        protected float[] yLUTb
        DOCUMENT ME!
      • clipRegionXNeg

        float clipRegionXNeg
        The clip plane position in the box.
      • clipRegionXPos

        float clipRegionXPos
        The clip plane position in the box.
      • clipRegionYNeg

        float clipRegionYNeg
        DOCUMENT ME!
      • clipRegionYPos

        float clipRegionYPos
        DOCUMENT ME!
      • clipRegionZNeg

        float clipRegionZNeg
        DOCUMENT ME!
      • clipRegionZPos

        float clipRegionZPos
        DOCUMENT ME!
      • fXDelta

        float fXDelta
        x, y, z delta value.
      • fYDelta

        float fYDelta
        x, y, z delta value.
      • fZDelta

        float fZDelta
        x, y, z delta value.
      • bluring

        private boolean bluring
        Blur the final image to reduce voxel contrast.
      • m_fT0

        private float m_fT0
        the parameters for clipped rays.
      • m_fT1

        private float m_fT1
        the parameters for clipped rays.
      • tempImage

        private final int[] tempImage
        DOCUMENT ME!
      • multiThreadingEnabled

        private final boolean multiThreadingEnabled
      • nthreads

        private final int nthreads
    • Constructor Detail

      • RayCastRenderer

        protected RayCastRenderer​(ModelImage kImage,
                                  int iRBound,
                                  int[] aiRImage)
        The constructor for the ray tracer. Currently, the only client of this class is VolumeRenderer.
        Parameters:
        kImage - the 3D image
        iRBound - the dimension of the square 2D renderer image
        aiRImage - The rendered image data stored in row-major order. Each integer pixel represents an RGB color in the format B | (G
    • Method Detail

      • disposeLocal

        public void disposeLocal​(boolean flag)
        Clean memory.
        Parameters:
        flag - is true call the super.disposeLocal
      • getAxis

        public javax.vecmath.Vector3f getAxis​(int i)
        Read the current axis at index i.
        Specified by:
        getAxis in class Renderer
        Parameters:
        i - the axis index (0, 1, or 2)
        Returns:
        the current axis vector at index i
      • rotateBy

        public void rotateBy​(javax.vecmath.AxisAngle4f kAxisAngle)
        Rotate the oriented bounding box of the 3D image about the specified axis with the specified angle.
        Specified by:
        rotateBy in class Renderer
        Parameters:
        kAxisAngle - the axis and angle formulation for the rotation
      • rotateFrameBy

        public void rotateFrameBy​(javax.media.j3d.Transform3D transform)
        Rotate the oriented bounding box of the 3D image about the specified axis with the specified angle.
        Specified by:
        rotateFrameBy in class Renderer
        Parameters:
        transform - the axis and angle formulation for the rotation
      • setAxis

        public void setAxis​(int i,
                            javax.vecmath.Vector3f kAxis)
        Change an axis of the oriented bounding box of the 3D image.
        Parameters:
        i - the axis index (0, 1, or 2)
        kAxis - the new axis vector at index i
      • setBlurFlag

        public void setBlurFlag​(boolean flag)
        Blur the resulting image or not.
        Parameters:
        flag - true blur the image, false not blur.
      • setDiffuse

        public void setDiffuse​(java.awt.Color color)
        Set vertex material diffuse color.
        Parameters:
        color - true blur the image, false not blur.
      • setOpacityFunctions

        public void setOpacityFunctions​(ModelLUT opacityFunctionA,
                                        ModelLUT opacityFunctionB)
        Add here.
        Parameters:
        opacityFunctionA - DOCUMENT ME!
        opacityFunctionB - DOCUMENT ME!
      • setSpecular

        public void setSpecular​(java.awt.Color color)
        Set vertex material specular color.
        Parameters:
        color - true blur the image, false not blur.
      • setXBoundNeg

        public void setXBoundNeg​(float value)
        Setup the X Negative clipping plane position.
        Specified by:
        setXBoundNeg in class Renderer
        Parameters:
        value - position of the X negative clip slider.
      • setXBoundPos

        public void setXBoundPos​(float value)
        Setup the X positive clipping plane position.
        Specified by:
        setXBoundPos in class Renderer
        Parameters:
        value - position of the X positive clip slider.
      • setYBoundNeg

        public void setYBoundNeg​(float value)
        Setup the Y Negative clipping plane position.
        Specified by:
        setYBoundNeg in class Renderer
        Parameters:
        value - position of the Y negative clip slider.
      • setYBoundPos

        public void setYBoundPos​(float value)
        Setup the Y positive clipping plane position.
        Specified by:
        setYBoundPos in class Renderer
        Parameters:
        value - positin of the Y positve clip slider.
      • setZBoundNeg

        public void setZBoundNeg​(float value)
        Setup the Z negative clipping plane position.
        Specified by:
        setZBoundNeg in class Renderer
        Parameters:
        value - position of the Z negative clip slider.
      • setZBoundPos

        public void setZBoundPos​(float value)
        Setup the Z positive clipping plane position.
        Specified by:
        setZBoundPos in class Renderer
        Parameters:
        value - position of the Z positive clip slider.
      • trace

        public final void trace​(int rayTraceStepSize,
                                int iSpacing)
        Ray trace the 3D image in its current orientation as determined by the oriented bounding box. The rendered image is initialized to the background color. A pixel is overwritten only when a ray intersects the bounding box of the image, that pixel corresponding to the given ray.
        Parameters:
        rayTraceStepSize - DOCUMENT ME!
        iSpacing - A positive value indicating how often to sample the rendered image. The typical value is 1 indicating that all rays corresponding to all pixels should be processed. If the value is 2, rays corresponding to pixels (x,y) with (x mod 2) = 0 and (y mod 2) = 0 are processed. The other pixels are assigned values of the modulo 2 neighbor pixel. Similar reduced sampling occurs with larger values of iSpacing. VolumeRenderer sets the spacing to be 2 when the image is being rotated by the virtual track ball. Once the image is finished rotating, a final trace is made with a spacing of 1.
      • traceBlockRays

        public void traceBlockRays​(int xStart,
                                   int xEnd,
                                   int yStart,
                                   int yEnd,
                                   int rayTraceStepSize,
                                   int iSpacing)
        Parameters:
        xStart -
        xEnd -
        yStart -
        yEnd -
        rayTraceStepSize -
        iSpacing -
      • processRay

        protected abstract void processRay​(int iIndex,
                                           int rayTraceStepSize)
        Process a ray that has intersected the oriented bounding box of the 3D image. The method is only called if there is a line segment of intersection. The 'intersectsBox' stores the end points of the line segment in the class members m_kP0 and m_kP1 in image coordinates.

        The function sets the color of the pixel corresponding to the processed ray. The RGB value is stored as an integer in the format B | (G

        Parameters:
        iIndex - index of the pixel corresponding to the processed ray
        rayTraceStepSize - DOCUMENT ME!
      • processRay

        protected abstract void processRay​(javax.vecmath.Point3f p0,
                                           javax.vecmath.Point3f p1,
                                           int iIndex,
                                           int rayTraceStepSize)
        Process a ray that has intersected the oriented bounding box of the 3D image. The method is only called if there is a line segment of intersection. The 'intersectsBox' stores the end points of the line segment in the class members P0 and P1 in image coordinates. The local P0 and p1 are used for the multi-theading rendering.

        The function sets the color of the pixel corresponding to the processed ray. The RGB value is stored as an integer in the format B | (G

        Parameters:
        p0 - Local starting point.
        p1 - Local ending point
        iIndex - index of the pixel corresponding to the processed ray
        rayTraceStepSize - raycast step size.
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Calls dispose.
        Overrides:
        finalize in class Renderer
        Throws:
        java.lang.Throwable - DOCUMENT ME!
      • interpolate

        protected final int interpolate​(javax.vecmath.Point3f kP,
                                        byte[] acImage)
        Trilinear interpolation of the image to produce image values at points P that are not at the integer voxel locations.
        Parameters:
        kP - the spatial point to be assigned an interpolated value
        acImage - The array of byte values to be interpolated
        Returns:
        The interpolated value for the point. If kP is not within the bounding box of the image, a value of -1 is returned.
      • clipped

        private boolean clipped​(float fDen,
                                float fNum,
                                float[] t)
        Support for clipping line segments against coordinate planes. The function computes the line segment parameter corresponding to the intersection of the segment with a coordinate plane. However, the expensive division is performed only if in fact there is an intersection. The deferred division speeds up the ray tracing a lot since this method is called up to 6 times per ray.
        Parameters:
        fDen - the denominator of the line segment parameter of the intersection
        fNum - the numerator of the line segment parameter of the intersection
        t - [] t[0] for the line starting point intersection parameter, t[1] for the line ending point intersection parameter.
        Returns:
        true if the entire line segment is entirely clipped by the current plane (segment is "outside" the plane), false if the segment intersects the plane or is contained "inside" the plane.
      • intersectsBox

        private boolean intersectsBox​(javax.vecmath.Vector3f mDir,
                                      javax.vecmath.Point3f mOrig,
                                      javax.vecmath.Point3f p0,
                                      javax.vecmath.Point3f p1)
        Clip the current ray against the oriented bounding box of the 3D image. The trace method sets up the ray in world coordinates. The intersector converts the ray to box coordinates so that the ray is clipped against an axis-aligned box.

        The end points of the intersecting line segment are stored in class members m_kP0 and m_kP1 as image coordinates. The bounding box is centered at the origin. The image coordinates are just a translation of box coordinates so that the center of the box becomes the center of the image. The class members m_fT0 and m_fT1 are the corresponding line segment parameters. They are class members only because Java does not support call-by-reference semantics. In another language, the parameters can be local and passed to 'clipped' with the potential to be changed by 'clipped'.

        Returns:
        true if and only if the ray intersects the box