Package gov.nih.mipav.model.algorithms
Class AlgorithmBSpline
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.AlgorithmBSpline
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class AlgorithmBSpline extends AlgorithmBase
Modified code from Aaron Carass's Java implementation of Philippe Thevenaz's Cubic B-spline Interpolation. Code is simply wrapped to allow for calls consistent with MIPAV style as well as allow for 2D images. B-Spline interpolation.- Author:
- Philippe Thevenaz, Aaron Carass Jet code is untouched from when the new code was implemented on June 24th, 2014. Fourth-order Bspline for 1-3D lines and 2D surface. This class is based on code from Dave Eberly's MAGIC C++ library.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
AlgorithmBSpline.ColorInterpolation
-
Field Summary
Fields Modifier and Type Field Description private AlgorithmBSpline.ColorInterpolation
colorInter
private double
DBL_EPSILON
private int
degree
DOCUMENT ME!private int
depth
DOCUMENT ME!private double[]
dt
DOCUMENT ME!private double[]
dt_double
DOCUMENT ME!private double[]
geoms
DOCUMENT ME!private double[]
geomx
DOCUMENT ME!private double[]
geomy
DOCUMENT ME!private double[]
geomz
DOCUMENT ME!private int
height
DOCUMENT ME!private double[][][]
imData
private static double[][]
mat4
Blending matrix for a 4th degree Bspline.private int
width
DOCUMENT ME!private int
xold_tbase
DOCUMENT ME!private int
xyold_tbase
DOCUMENT ME!-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStopped
-
-
Constructor Summary
Constructors Constructor Description AlgorithmBSpline()
default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
bSpline2D(int orderDx, int orderDy, double x, double y)
This method is out of date, as it provides smoothed interpolation as opposed to precise interpolation.double[]
bSpline2DC(int orderDx, int orderDy, double x, double y)
This method is out of date, as it provides smoothed interpolation as opposed to precise interpolation.double
bSpline3D(int orderDx, int orderDy, int orderDz, double x, double y, double z)
This method is out of date, as it provides smoothed interpolation as opposed to precise interpolation.double[]
bSpline3DC(int orderDx, int orderDy, int orderDz, double x, double y, double z)
This method is out of date, as it provides smoothed interpolation as opposed to precise interpolation.float
bSplineJet1D(byte derivOrder, float t, float[] dataX)
This method can also be used to calculate derivatives of the Bspline.WildMagic.LibFoundation.Mathematics.Vector2f
bSplineJetXY(int derivOrder, float t, float[] dataX, float[] dataY)
This method can also be used to calculate derivatives of the Bspline.WildMagic.LibFoundation.Mathematics.Vector3f
bSplineJetXYZ(int derivOrder, float t, float[] dataX, float[] dataY, float[] dataZ)
This method can also be used to calculate derivatives of the Bspline.javax.vecmath.Vector3d
bSplineJetXYZ_double(int derivOrder, float t, float[] dataX, float[] dataY, float[] dataZ)
This method can also be used to calculate derivatives of the Bspline.private void
ConvertToInterpolationCoefficients(double[] c, int DataLength, double[] z, int NbPoles, double Tolerance)
void
finalize()
Clean up memeory.private double[]
GetColumn(int x, int z, double[][][] Image)
private double[]
GetRow(int y, int z, double[][][] Image, int width)
private double[]
GetVertical(int x, int y, double[][][] Image)
private double
InitialAntiCausalCoefficient(double[] c, int DataLength, double z)
private double
InitialCausalCoefficient(double[] c, int DataLength, double z, double Tolerance)
private double
interpolateBSpline(double[][][] image, double x, double y, double z, int SplineDegree)
Do the B-Spline Interpolationprivate double
interpolateBSpline2D(double[][][] image, double x, double y, int SplineDegree)
private void
PutColumn(double[] Line, int x, int z, double[][][] Image)
private void
PutRow(double[] Line, int y, int z, double[][][] Image)
private void
PutVertical(double[] Line, int x, int y, double[][][] Image)
void
resetBspline()
Resets parameters used by the Bsplines.void
runAlgorithm()
Default method that is not really appropriate for this class but must be defined because this class extends AlgorithmBase.private int
SamplesToCoefficients(double[][][] Image, int SplineDegree)
private int
SamplesToCoefficients2D(double[][][] Image, int SplineDegree)
void
setup2DBSpline(double[] vol, int[] extents, int _degree)
Allocates memory and constructs arrays needed for BSpline.void
setup2DBSplineC(double[] vol, int[] extents, int _degree)
Allocates memory and constructs arrays needed for BSpline.void
setup3DBSpline(double[] vol, int[] extents, int _degree)
setup3DBSpline - setup 3D Bspline for black and white.void
setup3DBSplineC(double[] vol, int[] extents, int _degree)
Allocates memory and constructs arrays needed for BSpline.-
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, 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, windowOpened
-
Methods 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, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
mat4
private static double[][] mat4
Blending matrix for a 4th degree Bspline.
-
DBL_EPSILON
private final double DBL_EPSILON
- See Also:
- Constant Field Values
-
degree
private int degree
DOCUMENT ME!
-
dt
private double[] dt
DOCUMENT ME!
-
dt_double
private double[] dt_double
DOCUMENT ME!
-
geoms
private double[] geoms
DOCUMENT ME!
-
geomx
private double[] geomx
DOCUMENT ME!
-
geomy
private double[] geomy
DOCUMENT ME!
-
geomz
private double[] geomz
DOCUMENT ME!
-
width
private int width
DOCUMENT ME!
-
height
private int height
DOCUMENT ME!
-
depth
private int depth
DOCUMENT ME!
-
xold_tbase
private int xold_tbase
DOCUMENT ME!
-
xyold_tbase
private int xyold_tbase
DOCUMENT ME!
-
colorInter
private AlgorithmBSpline.ColorInterpolation colorInter
-
imData
private double[][][] imData
-
-
Method Detail
-
bSpline2D
public double bSpline2D(int orderDx, int orderDy, double x, double y)
This method is out of date, as it provides smoothed interpolation as opposed to precise interpolation. For precise interpolation, use the analogous method in AlgorithmBSpline3D instead, as that provides true B-spline interpolation. This method can also be used to calculate derivatives of the Bspline.- Parameters:
orderDx
- derivative order in x direction (n <= 4 )orderDy
- derivative order in y direction (n <= 4 )x
- double point index along the Bspline indicating point of interesty
- double point index along the Bspline indicating point of interest- Returns:
- the Bspline interpolated data point
-
bSpline2DC
public double[] bSpline2DC(int orderDx, int orderDy, double x, double y)
This method is out of date, as it provides smoothed interpolation as opposed to precise interpolation. For precise interpolation, use the analogous method in AlgorithmBSpline3D instead, as that provides true B-spline interpolation. This method can also be used to calculate derivatives of the Bspline.- Parameters:
orderDx
- derivative order in x direction (n <= 4 )orderDy
- derivative order in y direction (n <= 4 )x
- double point index along the Bspline indicating point of interesty
- double point index along the Bspline indicating point of interest- Returns:
- the Bspline interpolated data point
-
bSpline3D
public double bSpline3D(int orderDx, int orderDy, int orderDz, double x, double y, double z)
This method is out of date, as it provides smoothed interpolation as opposed to precise interpolation. For precise interpolation, use the analogous method in AlgorithmBSpline3D instead, as that provides true B-spline interpolation. 3D graph Bspline for black and white. This method can also be used to calculate derivatives of the Bspline. WARNING - programmer must call setup3DBSpline before using this function!!!- Parameters:
orderDx
- derivative order in x direction (n <= 4 )orderDy
- derivative order in y direction (n <= 4 )orderDz
- derivative order in z direction (n <= 4 )x
- double point index along the Bspline indicating point of interesty
- double point index along the Bspline indicating point of interestz
- double point index along the Bspline indicating pointof interest- Returns:
- the Bspline interpolated data point
-
bSpline3DC
public double[] bSpline3DC(int orderDx, int orderDy, int orderDz, double x, double y, double z)
This method is out of date, as it provides smoothed interpolation as opposed to precise interpolation. For precise interpolation, use the analogous method in AlgorithmBSpline3D instead, as that provides true B-spline interpolation. 3D graph Bspline for color. This method can also be used to calculate derivatives of the Bspline. WARNING - programmer must call setup3DBSpline before using this function!!!- Parameters:
orderDx
- derivative order in x direction (n <= 4 )orderDy
- derivative order in y direction (n <= 4 )orderDz
- derivative order in z direction (n <= 4 )x
- double point index along the Bspline indicating point of interesty
- double point index along the Bspline indicating point of interestz
- double point index along the Bspline indicating point of interest- Returns:
- the Bspline interpolated data point
-
bSplineJet1D
public float bSplineJet1D(byte derivOrder, float t, float[] dataX)
This method can also be used to calculate derivatives of the Bspline.- Parameters:
derivOrder
- derivative order (n <= 4 )t
- float point index along the Bspline indicating point of interestdataX
- control points for the Bspline- Returns:
- the Bspline interpolated data point
-
bSplineJetXY
public WildMagic.LibFoundation.Mathematics.Vector2f bSplineJetXY(int derivOrder, float t, float[] dataX, float[] dataY)
This method can also be used to calculate derivatives of the Bspline. Used for smoothing VOI lines- Parameters:
derivOrder
- derivative order (n <= 4 )t
- float point index along the Bspline indicating point of interestdataX
- control points for the BsplinedataY
- control points for the Bspline- Returns:
- the Bspline interpolated data point
-
bSplineJetXYZ
public WildMagic.LibFoundation.Mathematics.Vector3f bSplineJetXYZ(int derivOrder, float t, float[] dataX, float[] dataY, float[] dataZ)
This method can also be used to calculate derivatives of the Bspline. Used for smoothing VOI lines- Parameters:
derivOrder
- derivative order (n <= 4 )t
- float point index along the Bspline indicating point of interestdataX
- control points for the BsplinedataY
- control points for the BsplinedataZ
- control points for the Bspline- Returns:
- the Bspline interpolated data point
-
bSplineJetXYZ_double
public javax.vecmath.Vector3d bSplineJetXYZ_double(int derivOrder, float t, float[] dataX, float[] dataY, float[] dataZ)
This method can also be used to calculate derivatives of the Bspline.- Parameters:
derivOrder
- derivative order (n <= 4 )t
- float point index along the Bspline indicating point of interestdataX
- control points for the BsplinedataY
- control points for the BsplinedataZ
- control points for the Bspline- Returns:
- the Bspline interpolated data point
-
finalize
public void finalize()
Clean up memeory.- Overrides:
finalize
in classAlgorithmBase
-
resetBspline
public void resetBspline()
Resets parameters used by the Bsplines.
-
runAlgorithm
public void runAlgorithm()
Default method that is not really appropriate for this class but must be defined because this class extends AlgorithmBase.- Specified by:
runAlgorithm
in classAlgorithmBase
-
setup2DBSpline
public void setup2DBSpline(double[] vol, int[] extents, int _degree)
Allocates memory and constructs arrays needed for BSpline.- Parameters:
vol
- volume comprising control points for the Bsplineextents
- vol extents (xDim,yDim)_degree
- degree of spline (3 or 4)
-
setup2DBSplineC
public void setup2DBSplineC(double[] vol, int[] extents, int _degree)
Allocates memory and constructs arrays needed for BSpline.- Parameters:
vol
- volume comprising control points for the Bsplineextents
- vol extents (xDim,yDim)_degree
- degree of spline (3 or 4)
-
setup3DBSpline
public void setup3DBSpline(double[] vol, int[] extents, int _degree)
setup3DBSpline - setup 3D Bspline for black and white. Allocates memory and constructs arrays needed for BSpline- Parameters:
vol
- volume comprising control points for the Bsplineextents
- vol extents (xDim,yDim, zDim)_degree
- degree of spline (3 or 4)
-
setup3DBSplineC
public void setup3DBSplineC(double[] vol, int[] extents, int _degree)
Allocates memory and constructs arrays needed for BSpline.- Parameters:
vol
- volume comprising control points for the Bsplineextents
- vol extents (xDim,yDim, zDim)_degree
- degree of spline (3 or 4)
-
interpolateBSpline
private double interpolateBSpline(double[][][] image, double x, double y, double z, int SplineDegree)
Do the B-Spline Interpolation- Parameters:
Bcoeff
- B-spline array of coefficientsWidth
- Width of the imageHeight
- Height of the imageDepth
- Depth of the imagex
- x coordinate where to interpolatey
- y coordinate where to interpolatez
- z coordinate where to interpolateSplineDegree
- Degree of the B-Spline
-
interpolateBSpline2D
private double interpolateBSpline2D(double[][][] image, double x, double y, int SplineDegree)
-
ConvertToInterpolationCoefficients
private void ConvertToInterpolationCoefficients(double[] c, int DataLength, double[] z, int NbPoles, double Tolerance)
- Parameters:
c
- SamplesDataLength
- Number of samples or coefficientsz
- PolesNbPoles
- Number of polesTolerance
- Admissible relative error
-
InitialCausalCoefficient
private double InitialCausalCoefficient(double[] c, int DataLength, double z, double Tolerance)
-
InitialAntiCausalCoefficient
private double InitialAntiCausalCoefficient(double[] c, int DataLength, double z)
-
GetRow
private double[] GetRow(int y, int z, double[][][] Image, int width)
-
PutRow
private void PutRow(double[] Line, int y, int z, double[][][] Image)
-
GetColumn
private double[] GetColumn(int x, int z, double[][][] Image)
-
PutColumn
private void PutColumn(double[] Line, int x, int z, double[][][] Image)
-
GetVertical
private double[] GetVertical(int x, int y, double[][][] Image)
-
PutVertical
private void PutVertical(double[] Line, int x, int y, double[][][] Image)
-
SamplesToCoefficients
private int SamplesToCoefficients(double[][][] Image, int SplineDegree)
-
SamplesToCoefficients2D
private int SamplesToCoefficients2D(double[][][] Image, int SplineDegree)
-
-