Package gov.nih.mipav.model.algorithms
Class AlgorithmConstELSUNCOpt3D
java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.AlgorithmConstELSUNCOpt3D
- All Implemented Interfaces:
ActionListener,WindowListener,Runnable,EventListener
Runs ELSUNC for a 3D image.
Based on ELSUNC allowed by the author with acknowledgement:
Gauss-Newton Based Algorithms For Constrained Nonlinear Least Squares Problems by Per Lindstrom and Per-Ake Wedin, Institute of Information Processing, University of Umea, S-901 87 Umea, Sweden This can be downleaded from http://www.cs.umu.se/~perl/reports/alg.ps.gz
- Version:
- 0.1 March 19, 2012
- Author:
- William Gandler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classNested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intThe initial bracket size for first iteration of ELSUNC.private AlgorithmOptimizeFunctionBaseCost function called to measure cost - 1D.(package private) AlgorithmConstELSUNCOpt3D.FitOAR3DConstrainedModelprivate double[]Final point when optimization is complete.private TransMatrixdThe transformation matrix from the origin of the input image.private doubleThe cost of the function at the best minimum.private intThe maximum number of iterations the optimization allows.private doubleprivate ViewJProgressBarProgress bar that may be set for long optimization runs.private intDegress of freedom.private double[]Array of tolerances for each dimension.private AlgorithmBaseParent algorithm that called this optimization.private double[]Point that is currently being optimized.private intWhere progress is when sent in.private intThe max the progress can go to.private double[]Point that was initially passed into function.private intprivate booleanIndicates whether the ELSUNC algorithm succeeded in finding a minimum.protected TransMatrixdThe transformation matrix to the origin of the input image.private float[][]Array of translation and rotation limits for each dimension.Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStoppedFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionAlgorithmConstELSUNCOpt3D(AlgorithmBase parent, WildMagic.LibFoundation.Mathematics.Vector3f com, int degreeOfFreedom, AlgorithmOptimizeFunctionBase costFunc, double[] initial, double[] tols, int maxIter, int bracketBound) Constructs a new algorithm with the given centers of mass (needed for setting the transformations), the given cost function (which was constructed with the proper images), the initial point we're looking at, some tolerance within that point to look for the minimum, and the maximum number of iterations. -
Method Summary
Modifier and TypeMethodDescriptionconvertToMatrix(double[] vector) Helper method to take the "point" we've been working with as a vector, and convert it into a transformation matrix.convertToMatrixHalf(double[] vector) Helper method to take the "point" we've been working with as a vector, and convert it into a transformation matrix.convertToMatrixMidsagittal(double[] vector) Helper method to take the "point" we've been working with as a vector, and convert it into a transformation matrix.booleanReturns whether or not a minimum was found.voidSets everything to null and prepares this class for destruction.doublegetCost()Returns the cost of the best transformation.double[]getFinal()Accessor that returns the final point with translations, rotations, scales, and skews representing the best tranformation.double[]getFinal(double[] point) Accessor that returns the final point with translations, rotations, scales, and skews representing the best tranformation.double[]getFinal(float sample) Accessor that returns the final point with translations, rotations, scales, and skews representing the best tranformation.Accessor that returns the matrix representing the best transformation.getMatrix(float sample) Accessor that returns the matrix representing the best transformation.Accessor that returns the matrix representing the best tranformation.getMatrixHalf(float sample) Accessor that returns the matrix representing the best tranformation.Accessor that returns the matrix representing the best tranformation.getMatrixMidsagittal(float sample) Accessor that returns the matrix representing the best tranformation.double[]getPoint()Returns the optimized point, with length == degrees of freedom.voidCalls cost function with point and saves result in functionAtBest.voidRuns ELSUNC along one dimension at a time as long as the costFunction improves during one cycle of runs along every dimension.voidsetInitialPoint(double[] initial) Sets the initial point to the value passed in.voidsetLimits(float[][] limits) Sets the limits on rotation and translation.voidsetMaxIterations(int max) Sets the maximum number of iterations.voidsetProgressBar(ViewJProgressBar progress, int begin, int max) Accessor that sets the progress bar so it can be updated from here.Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, finalize, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpenedMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
dModel
-
bracketBound
private int bracketBoundThe initial bracket size for first iteration of ELSUNC. -
costFunction
Cost function called to measure cost - 1D. -
finalPoint
private double[] finalPointFinal point when optimization is complete. -
fromOrigin
The transformation matrix from the origin of the input image. -
functionAtBest
private double functionAtBestThe cost of the function at the best minimum. -
minFunctionAtBest
private double minFunctionAtBest -
maxIterations
private int maxIterationsThe maximum number of iterations the optimization allows. -
myProgressBar
Progress bar that may be set for long optimization runs. -
nDims
private int nDimsDegress of freedom. -
parent
Parent algorithm that called this optimization. -
point
private double[] pointPoint that is currently being optimized. -
progressBegin
private int progressBeginWhere progress is when sent in. -
progressMax
private int progressMaxThe max the progress can go to. -
start
private double[] startPoint that was initially passed into function. -
success
private boolean successIndicates whether the ELSUNC algorithm succeeded in finding a minimum. -
OARTolerance
private double[] OARToleranceArray of tolerances for each dimension. -
toOrigin
The transformation matrix to the origin of the input image. -
trLimits
private float[][] trLimitsArray of translation and rotation limits for each dimension. -
status
private int status
-
-
Constructor Details
-
AlgorithmConstELSUNCOpt3D
public AlgorithmConstELSUNCOpt3D(AlgorithmBase parent, WildMagic.LibFoundation.Mathematics.Vector3f com, int degreeOfFreedom, AlgorithmOptimizeFunctionBase costFunc, double[] initial, double[] tols, int maxIter, int bracketBound) Constructs a new algorithm with the given centers of mass (needed for setting the transformations), the given cost function (which was constructed with the proper images), the initial point we're looking at, some tolerance within that point to look for the minimum, and the maximum number of iterations.- Parameters:
parent- Algorithm that called this optimization.com- Center of Mass of the input image.degreeOfFreedom- Degree of freedom for transformation (must be 3, 4, 6, 7, 9, or 12).costFunc- Cost function to use.initial- Initial point to start from, length of 12.tols- Tolerance for each dimension (tols.length == degreeOfFreedom).maxIter- Maximum number of iterations.bracketBound- DOCUMENT ME!
-
-
Method Details
-
disposeLocal
public void disposeLocal()Sets everything to null and prepares this class for destruction. -
convertToMatrix
Helper method to take the "point" we've been working with as a vector, and convert it into a transformation matrix. The length of the vector should be equal to the global variable nDims, which in turn was initialized by the degrees of freedom originally sent to this algorithm. Therefore, if there are 3 degrees of freedom, we set only the translations; 4 means translation and global scaling; 6 means rotation and translation; 7 means rotation, translation, and global scaling; 9 means rotation, translation, and scaling; and 12 means rotation, translation, scaling, and skewing.- Parameters:
vector- Vector that represented a "point" in the algorithm which needs to be converted to a matrix.- Returns:
- The transformation matrix created from the vector.
-
convertToMatrixHalf
Helper method to take the "point" we've been working with as a vector, and convert it into a transformation matrix. The length of the vector should be equal to the global variable nDims, which in turn was initialized by the degrees of freedom originally sent to this algorithm. Therefore, if there are 3 degrees of freedom, we set only the translations; 4 means translation and global scaling; 6 means rotation and translation; 7 means rotation, translation, and global scaling; 9 means rotation, translation, and scaling; and 12 means rotation, translation, scaling, and skewing.- Parameters:
vector- Vector that represented a "point" in the algorithm which needs to be converted to a matrix.- Returns:
- The transformation matrix created from the vector.
-
convertToMatrixMidsagittal
Helper method to take the "point" we've been working with as a vector, and convert it into a transformation matrix. The length of the vector should be equal to the global variable nDims, which in turn was initialized by the degrees of freedom originally sent to this algorithm. Therefore, if there are 3 degrees of freedom, we set only the translations; 4 means translation and global scaling; 6 means rotation and translation; 7 means rotation, translation, and global scaling; 9 means rotation, translation, and scaling; and 12 means rotation, translation, scaling, and skewing.- Parameters:
vector- Vector that represented a "point" in the algorithm which needs to be converted to a matrix.- Returns:
- The transformation matrix created from the vector.
-
getFinal
public double[] getFinal()Accessor that returns the final point with translations, rotations, scales, and skews representing the best tranformation.- Returns:
- vector representing the best transformation in terms of translations, rotations, scales, and skews.
-
getFinal
public double[] getFinal(double[] point) Accessor that returns the final point with translations, rotations, scales, and skews representing the best tranformation.- Returns:
- vector representing the best transformation in terms of translations, rotations, scales, and skews.
-
getFinal
public double[] getFinal(float sample) Accessor that returns the final point with translations, rotations, scales, and skews representing the best tranformation.- Parameters:
sample- the voxel resolution- Returns:
- vector representing the best transformation in terms of translations, rotations, scales, and skews.
-
getMatrix
Accessor that returns the matrix representing the best transformation.- Returns:
- matrix representing the best transformation.
-
getMatrix
Accessor that returns the matrix representing the best transformation. The passed in parameter represents the resolution (same in all directions and for both input and reference images, since resampled isotropically). Since the optimization was done in pixel space, not millimeter space, the translation parameters need to be scaled by the sample value.- Parameters:
sample- the voxel resolution- Returns:
- matrix representing the best transformation.
-
getMatrixHalf
Accessor that returns the matrix representing the best tranformation. All of the components of the transformation are halved from the 'best transformation' matrix.- Returns:
- matrix representing the best transformation with its components halved.
-
getMatrixHalf
Accessor that returns the matrix representing the best tranformation. The passed in parameter represents the resolution (same in all directions and for both input and reference images, since resampled isotropically). Since the optimization was done in pixel space, not millimeter space, the translation parameters need to be scaled by the sample value. All of the components of the transformation are halved from the 'best transformation' matrix.- Parameters:
sample- the voxel resolution- Returns:
- matrix representing the best transformation with its components halved.
-
getMatrixMidsagittal
Accessor that returns the matrix representing the best tranformation. This transformation contains only the z rotation and the x and y translation, to be used in the midsagittal alignment algorithm.- Returns:
- matrix representing the best transformation's z rot and x and y trans.
-
getMatrixMidsagittal
Accessor that returns the matrix representing the best tranformation. The passed in parameter represents the resolution (same in all directions and for both input and reference images, since resampled isotropically). Since the optimization was done in pixel space, not millimeter space, the translation parameters need to be scaled by the sample value. This transformation contains only the z rotation and the x and y translation, to be used in the midsagittal alignment algorithm.- Parameters:
sample- the voxel resolution- Returns:
- matrix representing the best transformation's z rot and x and y trans.
-
measureCost
public void measureCost()Calls cost function with point and saves result in functionAtBest. -
runAlgorithm
public void runAlgorithm()Runs ELSUNC along one dimension at a time as long as the costFunction improves during one cycle of runs along every dimension.- Specified by:
runAlgorithmin classAlgorithmBase
-
setInitialPoint
public void setInitialPoint(double[] initial) Sets the initial point to the value passed in.- Parameters:
initial- Initial point.
-
setLimits
public void setLimits(float[][] limits) Sets the limits on rotation and translation.- Parameters:
limits- limits
-
getCost
public double getCost()Returns the cost of the best transformation.- Returns:
- The cost of the best transformation.
-
getPoint
public double[] getPoint()Returns the optimized point, with length == degrees of freedom.- Returns:
- The optimized point.
-
setMaxIterations
public void setMaxIterations(int max) Sets the maximum number of iterations.- Parameters:
max- The max number of iterations.
-
didSucceed
public boolean didSucceed()Returns whether or not a minimum was found.- Returns:
- whether or not a minimum was found.
-
setProgressBar
Accessor that sets the progress bar so it can be updated from here.- Parameters:
progress- DOCUMENT ME!begin- Value of progress bar when sent here.max- Maximum value allowed.
-