Class VOIContour

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<WildMagic.LibFoundation.Mathematics.Vector3f>, java.util.Collection<WildMagic.LibFoundation.Mathematics.Vector3f>, java.util.List<WildMagic.LibFoundation.Mathematics.Vector3f>, java.util.RandomAccess

    public class VOIContour
    extends VOIBase
    This class is fundamental to the VOI class in which points are stored that describe a curve of an VOI. The points are 3D and are floats (see Vector3f). It extends VOIBase and therefore it extends Vector. Vector makes it very easy to add points and remove points from the contour. An VOI is formed from one or many contours.

    Routines that wish to sample all integer x,y values along a line must sample the line at 1/2 unit increments. As an example, suppose we have a line with the following (x,y) values: (0.2,0.7),(0.7,1.2),(1.2,1.7), (1.7,2.2). If we sample at unit increments with rounding we could either obtain the points (0,1),(1,2) or (1,1),(2,2). By sampling at 1/2 unit increments along the line we sample at (0,1),(1,1),(1,2),(2,2).

    Version:
    0.1 Oct 27, 1997
    Author:
    Matthew J. McAuliffe, Ph.D.
    See Also:
    VOIBase, VOILine, VOI, $Logfile: /mipav/src/gov/nih/mipav/model/structures/VOIContour.java $ $Revision: 114 $ $Date: 2/24/06 3:34p $ , Serialized Form
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        Use serialVersionUID for interoperability.
        See Also:
        Constant Field Values
    • Constructor Detail

      • VOIContour

        public VOIContour​(boolean flag)
        Construct a new closed or open VOI.
        Parameters:
        flag - whether the voi contour is closed
      • VOIContour

        public VOIContour​(boolean bFixed,
                          boolean bClosed)
        Construct a new VOIContour.
        Parameters:
        bFixed - , true if this VOIContour is fixed (cannot be changed).
        bClosed - , true if this VOIContour is closed.
      • VOIContour

        public VOIContour​(boolean bFixed,
                          boolean bClosed,
                          java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f> kPositions)
        Construct a new VOIContour.
        Parameters:
        bFixed - , true if this VOIContour is fixed (cannot be changed).
        bClosed - , true if this VOIContour is closed.
        kLocal -
      • VOIContour

        public VOIContour​(VOIContour kVOI)
        Copy Constructor.
        Parameters:
        kVOI -
      • VOIContour

        public VOIContour​(VOIContour kVOI,
                          int iPropDir)
        Copies the input contour and changes it's slice +/-
        Parameters:
        kBase -
        iPropDir -
      • VOIContour

        public VOIContour​(VOIContour kVOI,
                          TransMatrix tMatrix)
        Copies the input VOIBase, transformed by the input TransMatrix.
        Parameters:
        kBase - VOI to copy.
        tMatrix - transformation
    • Method Detail

      • calcLargestSliceDistance

        public double calcLargestSliceDistance​(int[] extents,
                                               float[] res,
                                               WildMagic.LibFoundation.Mathematics.Vector3f kPos1,
                                               WildMagic.LibFoundation.Mathematics.Vector3f kPos2)
        Calculate the distance of the largest line segment contained entirely within the slice of the VOI
        Parameters:
        xRes -
        yRes -
        Returns:
        largestDistance
      • pinpol

        public double pinpol​(double xpoint,
                             double ypoint,
                             boolean[] snear,
                             int[] index1,
                             int[] index2)
      • det

        private double det​(double x1,
                           double x2,
                           double x3,
                           double y1,
                           double y2,
                           double y3)
      • euclideanDistance2D

        public double euclideanDistance2D​(int xDim,
                                          int yDim)
      • boxCountBoundary2D

        public double boxCountBoundary2D​(int xDim,
                                         int yDim)
      • invariantMoments

        public double[] invariantMoments​(int xDim,
                                         int yDim)
      • principalAxis

        public double principalAxis​(int xDim,
                                    int yDim)
        From statics it is known that any planar shape or closed curve possesses two principal axes 90 degrees apart intersecting at the centroid of the area. (For certain areas such as a circle, there may be more than two principal axes about the centroid, but there are always at least two.) The moment of inertia is maximum about one principal axis and minimum about the other principal axis. Here the angle in degrees with the principal axis having the minimum moment of inertia is reported. For an ellipse with semimajor axis = a and semiminor axis = b, the moment of inertia has its smallest value of PI*a*b^3/8 about the major axis and its largest value of PI*a^3*b/8 about the minor axis. Reference: On the Computation of the Moments of a Polygon, with Some Applications by Soerjadi
        Parameters:
        xDim -
        yDim -
        Returns:
      • calcAsymmetryIndex

        public double calcAsymmetryIndex​(int xDim,
                                         int yDim)
        Parameters:
        xDim -
        yDim -
        Returns:
      • convexHull

        public void convexHull()
      • make_chain

        private int make_chain​(double[][] V,
                               int offset,
                               int n,
                               boolean lower)
      • ccw

        private boolean ccw​(double[][] P,
                            int i,
                            int j,
                            int k)
      • exportPolygon

        public java.awt.Polygon exportPolygon()
        Exports the points of the contour as a polygon (z data can not be encoded in the polygon).
        Returns:
        returns polygon
      • getPositionAndIntensity

        public int getPositionAndIntensity​(WildMagic.LibFoundation.Mathematics.Vector3f[] position,
                                           float[] intensity,
                                           float[] imageBuffer,
                                           int xDim)
        Gets position/intensity along the boundary of this contour VOI.
        Parameters:
        position - array that is filled with all x,y coordinates
        intensity - the corresponding intensities along the line
        imageBuffer - image array in which VOIs and lines are found
        xDim - x-Dimension of image
        Returns:
        the number of points in the position and intensity array that have valid data.
      • getPositionAndIntensityIndex

        public int getPositionAndIntensityIndex​(int[] position,
                                                float[] intensity,
                                                float[] imageBuffer,
                                                int xDim)
        Gets the position/intensity along the boundary of this contour VOI.
        Parameters:
        position - array that is filled with all the indices in the form of indexY*xDim + indexX
        intensity - the corresponding intensities along the line
        imageBuffer - image array in which the VOis and lines are found
        xDim - x-Dimension of image
        Returns:
        the number of points in the position and intensity array that hava valid data.
      • importPolygon

        public void importPolygon​(java.awt.Polygon gon,
                                  int slice)
        Saves the polygon in the contour.
        Parameters:
        gon - polygon to be saved
        slice - index to save the polygon at
      • isCounterClockwise

        public boolean isCounterClockwise()
        Determines if the points are ordered in a counterClockwise manner.
        Returns:
        true if points are counter clockwise and false if clockwise.
      • makeClockwise

        public void makeClockwise()
        Make contour clockwise.
      • makeCounterClockwise

        public void makeCounterClockwise()
        Checks to see if Contour is counter-clockwise. If not it makes the contour counter-clockwise.
      • makeCounterClockwise

        public void makeCounterClockwise​(int start)
        Checks to see if Contour is counter-clockwise. If not it makes the contour counter-clockwise.
        Parameters:
        start - , the index of the first point.
      • reloadPoints

        public void reloadPoints​(float[] xPts,
                                 float[] yPts)
        Reloads points in this array for speed purposes.
        Parameters:
        xPts - loads the x-values into the xPts array.
        yPts - loads the y-values into the yPts array.
      • removeActivePt

        public void removeActivePt()
        Forget about the last clicked (active) point in the contour.
      • secondOrderAttributes

        public void secondOrderAttributes​(ModelImage kImage,
                                          float[] pAxis,
                                          float[] eccentricity,
                                          float[] majorAxis,
                                          float[] minorAxis)
        Find the least squares fit of the points in the contour to an ellipsoid. Uses a variant of Powell's algorithm to find the minimum of the 9D function: center x,y,z, rotation x,y,z, and axis x,y,z.
        Parameters:
        kImage - input image
        pAxis - output principal axis
        eccentricity - output eccentricity
        majorAxis - output major axis length
        minorAxis - output minor axis length
      • secondOrderAttributeslsq

        public void secondOrderAttributeslsq​(float xRes,
                                             float yRes,
                                             int xUnits,
                                             int yUnits,
                                             double[] angleAxis,
                                             double[] eccentricity,
                                             double[] majorAxis,
                                             double[] minorAxis,
                                             double[] xCenter,
                                             double[] yCenter)
        Finds the second order attributes.

        Reference: Fitzgibbon, Pilu, Fisher: Direct Least Squares Fitting of Ellipses at http://www.robots.ox.ac.uk/~awf/ellipse/fitellipse.html

        Parameters:
        xRes - DOCUMENT ME!
        yRes - DOCUMENT ME!
        xUnits - DOCUMENT ME!
        yUnits - DOCUMENT ME!
        angleAxis - angle in radians with major axis
        eccentricity - shape (circle = 0; line = 1)
        majorAxis - diameter of major axis
        minorAxis - diameter of minor axis
        xCenter -
        yCenter -
      • residuals_ellipse

        public void residuals_ellipse​(double[] residualSumOfSquares,
                                      double[][] xyproj,
                                      java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f> xy,
                                      double centerX,
                                      double centerY,
                                      double majorAxis,
                                      double minorAxis,
                                      double angle)
        This is a port of the MATLAB file Reisduals_ellipse written by Hui Ma on May 24, 2010. This code is covered by a BSD license. On the MATLAB exchange it was listed under distance from points to an ellipse. file ID #27708. The text at the front of the file is as follows: % Projecting a given set of points onto an ellipse % and computing the distances from the points to the ellipse % % This is a modified version of an iterative algorithm published by D. Eberly % Internet publication: "Distance from a point to an ellipse in 2D" (2004) % Geometric Tools, LLC, www.geometrictools.com % Book publication: "3D Game Engine Design", 2nd edition. % Morgan Kaufmann Publishers, San Francisco, CA, 2007. % (see Section 14.13.1) % % Input: XY(n,2) is the array of coordinates of n points x(i)=XY(i,1), y(i)=XY(i,2) % ParG is a vector 5x1 of the ellipse parameters % ParG = [Center(1:2), Axes(1:2), Angle]' % Center - the coordinates of the ellipse's center % Axes - the axes (major, minor) % Angle - the angle of tilt of the ellipse % % Output: RSS is the Residual Sum of Squares (the sum of squares of the distances) % XYproj is the array of coordinates of projections % % The algorithm is proven to converge and reaches an accuracy of 7-8 significant digit % It takes 4-5 iterations per point, on average. input axes are diameters input angle is in radians Calling routine should supply xyproj as a double[][] = new double[xy.size()][2]
      • transformContour

        public void transformContour​(TransMatrix tMatrix,
                                     boolean doRound)
        Transforms self.
        Parameters:
        tMatrix - transformation matrix
        doRound - if true round point coordinates to integers
      • translate

        public void translate​(float xT,
                              float yT,
                              float zT)
        Translates a VOI by some amount in x and y.
        Parameters:
        xT - translate this amount in the x direction
        yT - translate this amount in the y direction
      • contains3D

        public boolean contains3D​(WildMagic.LibFoundation.Mathematics.Vector3f pt)