Package gov.nih.mipav.model.structures
Class VOIContour
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f>
-
- gov.nih.mipav.model.structures.VOIBase
-
- gov.nih.mipav.model.structures.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
VOIContour.positionItem
private class
VOIContour.positionLowerComparator
private class
VOIContour.positionUpperComparator
-
Field Summary
Fields Modifier and Type Field Description private static long
serialVersionUID
Use serialVersionUID for interoperability.-
Fields inherited from class gov.nih.mipav.model.structures.VOIBase
active, autoLabel, averagePt, cenMassPt, cenMassPtB, cenMassPtG, cenMassPtR, CIRCLE, closed, display, DOWN, fixed, gcPt, label, lastPoint, LEFT, LEFT_MIDDLE, LOWER_LEFT, LOWER_MIDDLE, LOWER_RIGHT, m_akImageMinMax, m_bQuickLUT, m_bReloadPoints, m_bSplit, m_bUpdateAverage, m_bUpdateBounds, m_bUpdateGeometricCenter, m_bUpdateMask, m_bUpdatePlane, m_iAnchorIndex, m_iPlane, m_iVOIType, m_kColor, m_kPositionSum, m_kVolumeVOI, nearBoundPoint, nearPoint, NOT_A_PLANE, NOT_A_POINT, numPixels, process, RIGHT, RIGHT_MIDDLE, SQUARE, UNKNOWN_SUBTYPE, UP, UPPER_LEFT, UPPER_MIDDLE, UPPER_RIGHT, voiGroup, volumeDisplayRange, XPLANE, YPLANE, ZPLANE
-
-
Constructor Summary
Constructors Constructor Description VOIContour(boolean flag)
Construct a new closed or open VOI.VOIContour(boolean bFixed, boolean bClosed)
Construct a new VOIContour.VOIContour(boolean bFixed, boolean bClosed, java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f> kPositions)
Construct a new VOIContour.VOIContour(VOIContour kVOI)
Copy Constructor.VOIContour(VOIContour kVOI, int iPropDir)
Copies the input contour and changes it's slice +/-VOIContour(VOIContour kVOI, TransMatrix tMatrix)
Copies the input VOIBase, transformed by the input TransMatrix.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
boxCountBoundary2D(int xDim, int yDim)
double
calcAsymmetryIndex(int xDim, int yDim)
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 VOIprivate boolean
ccw(double[][] P, int i, int j, int k)
VOIBase
clone()
boolean
contains3D(WildMagic.LibFoundation.Mathematics.Vector3f pt)
void
convexHull()
private double
det(double x1, double x2, double x3, double y1, double y2, double y3)
double
euclideanDistance2D(int xDim, int yDim)
java.awt.Polygon
exportPolygon()
Exports the points of the contour as a polygon (z data can not be encoded in the polygon).int
getPositionAndIntensity(WildMagic.LibFoundation.Mathematics.Vector3f[] position, float[] intensity, float[] imageBuffer, int xDim)
Gets position/intensity along the boundary of this contour VOI.int
getPositionAndIntensityIndex(int[] position, float[] intensity, float[] imageBuffer, int xDim)
Gets the position/intensity along the boundary of this contour VOI.void
importPolygon(java.awt.Polygon gon, int slice)
Saves the polygon in the contour.double[]
invariantMoments(int xDim, int yDim)
boolean
isCounterClockwise()
Determines if the points are ordered in a counterClockwise manner.private int
make_chain(double[][] V, int offset, int n, boolean lower)
void
makeClockwise()
Make contour clockwise.void
makeCounterClockwise()
Checks to see if Contour is counter-clockwise.void
makeCounterClockwise(int start)
Checks to see if Contour is counter-clockwise.double
pinpol(double xpoint, double ypoint, boolean[] snear, int[] index1, int[] index2)
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.void
reloadPoints(float[] xPts, float[] yPts)
Reloads points in this array for speed purposes.void
removeActivePt()
Forget about the last clicked (active) point in the contour.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.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.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.void
transformContour(TransMatrix tMatrix, boolean doRound)
Transforms self.void
translate(float xT, float yT, float zT)
Translates a VOI by some amount in x and y.-
Methods inherited from class gov.nih.mipav.model.structures.VOIBase
addElement, addElement, area, areaTwice, calcIntensity, calcIntensity, calcIntensityThreshold, calcRGBIntensity, calcRGBIntensity, calcRGBIntensityThreshold, contain, contains, contains, contains, createVolumeVOI, cycleActivePt, delete, deleteVolumeVOI, display, dispose, distanceToVOI, equals, exportArrays, exportArrays, fillVolume, findPositionAndCurvature, findPositionAndIntensity, findPositionAndIntensity, findVOIIndentations2D, getActivePt, getAllContourPoints, getAnchor, getAverage, getBounds, getBounds, getCenterOfMass, getCenterOfMass, getCenterOfMassB, getCenterOfMassG, getCenterOfMassR, getContourID, getDoGeometricCenterLabel, getGeometricCenter, getGeometricCenterA, getGroup, getImageBoundingBox, getLabel, getLastNumPixels, getLengthPtToPt, getLengthPtToPt, getLengthString, getMaskPositions, getName, getNearBoundPoint, getNearPoint, getNumVoxels, getPlane, getProcess, getSelectedPoint, getSubtype, getTotalLengthString, getType, getVolumeDisplayRange, getVolumeVOI, importArrays, importArrays, importPoints, isActive, isClosed, isFixed, isM_bUpdateBounds, isM_bUpdateGeometricCenter, isQuickLUT, isSplit, nearLine, nearLine, planeFit, reloadPoints, setActive, setAnchor, setClosed, setDoGeometricCenterLabel, setFixed, setGroup, setLabel, setMask, setMaskSlice, setNearBoundPoint, setNearPoint, setPlane, setProcess, setQuickLUT, setSelectedPoint, setSplit, setSubtype, setVolumeDisplayRange, slice, slice, transform, trimPoints, update, update, update
-
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, firstElement, forEach, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, iterator, lastElement, lastIndexOf, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeIf, removeRange, replaceAll, retainAll, set, setElementAt, setSize, size, sort, spliterator, subList, toArray, toArray, toString, trimToSize
-
-
-
-
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 coordinatesintensity
- the corresponding intensities along the lineimageBuffer
- image array in which VOIs and lines are foundxDim
- 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 + indexXintensity
- the corresponding intensities along the lineimageBuffer
- image array in which the VOis and lines are foundxDim
- 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 savedslice
- 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 imagepAxis
- output principal axiseccentricity
- output eccentricitymajorAxis
- output major axis lengthminorAxis
- 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 axiseccentricity
- shape (circle = 0; line = 1)majorAxis
- diameter of major axisminorAxis
- diameter of minor axisxCenter
-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 matrixdoRound
- 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 directionyT
- translate this amount in the y direction
-
contains3D
public boolean contains3D(WildMagic.LibFoundation.Mathematics.Vector3f pt)
-
-