Package gov.nih.mipav.model.algorithms
Class OpenCLAlgorithmBase
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.OpenCLAlgorithmBase
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
- Direct Known Subclasses:
OpenCLAlgorithmDeconvolution
,OpenCLAlgorithmFFT
,OpenCLAlgorithmGaussianBlur
,OpenCLAlgorithmGradientMagnitude
,OpenCLAlgorithmLaplacian
,OpenCLAlgorithmMarchingCubes
,OpenCLAlgorithmVolumeCrop
,OpenCLAlgorithmVolumeNormals
public abstract class OpenCLAlgorithmBase extends AlgorithmBase
Abstract base class for implementing Algorithms in OpenCL. Extends AlgorithmBase.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.jocl.cl_context
cl
protected int
color
protected int[]
colorMask
Color flags.protected static java.util.Vector<org.jocl.cl_context>
contextLibrary
protected int
depth
protected org.jocl.cl_device_id
device
protected boolean
entireImage
Flag, if true, indicates that the whole image should be processed.protected int
height
private static boolean
isOCL_CPU_Available
private static boolean
isOCL_GPU_Available
private static boolean
isOCLAvailable
protected long
m_iDeviceType
protected com.jogamp.opengl.GL3
m_kGL
protected static java.util.Vector<java.lang.Long>
openCLTypeLibrary
private static int
platformIndex
protected int
time
private static boolean
wasOCLChecked
protected int
width
-
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 OpenCLAlgorithmBase()
OpenCLAlgorithmBase(ModelImage destImg, ModelImage srcImg, boolean entireImage, long type)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkError(int errcode)
Checks the OpenCL error status.void
finalize()
Prepare this class for destruction.static int
getInt(org.jocl.cl_device_id device, int paramName)
Returns the value of the device info parameter with the given namestatic int[]
getInts(org.jocl.cl_device_id device, int paramName, int numValues)
Returns the values of the device info parameter with the given namestatic long
getLong(org.jocl.cl_device_id device, int paramName)
Returns the value of the device info parameter with the given namestatic long[]
getLongs(org.jocl.cl_device_id device, int paramName, int numValues)
Returns the values of the device info parameter with the given nameprotected long
getMaxMemoryUsed(int nBuffers, int elementCount, float[] sigmas)
Determines the amount of memory used for the OpenCL buffers required for the gaussian kernels for the given sigmas.static java.lang.String
getString(org.jocl.cl_device_id device, int paramName)
Returns the value of the device info parameter with the given namestatic java.lang.String
getString(org.jocl.cl_platform_id platform, int paramName)
Returns the value of the platform info parameter with the given nameprotected void
initCL(long iType, com.jogamp.opengl.GL3 gl)
private static void
initContextProperties(org.jocl.cl_context_properties contextProperties, com.jogamp.opengl.GL gl)
Initializes the given context properties so that they may be used to create an OpenCL context for the given GL object.static boolean
isOCLAvailable()
static java.lang.String
readKernelFile(java.lang.String fileName)
Helper function which reads the file with the given name and returns the contents of this file as a String.protected static long
roundUp(long groupSize, long globalSize)
void
saveImage(float[] data, int time, boolean calcMinMax)
void
saveImage(float[] data, int time, int zSlice, boolean calcMinMax)
void
setBlue(boolean flag)
Sets the flag for the blue channel.void
setGreen(boolean flag)
Sets the flag for the green channel.void
setRed(boolean flag)
Sets the flag for the red channel.void
setTime(int timeSlice)
-
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, runAlgorithm, 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
-
contextLibrary
protected static java.util.Vector<org.jocl.cl_context> contextLibrary
-
openCLTypeLibrary
protected static java.util.Vector<java.lang.Long> openCLTypeLibrary
-
cl
protected org.jocl.cl_context cl
-
device
protected org.jocl.cl_device_id device
-
isOCLAvailable
private static boolean isOCLAvailable
-
isOCL_CPU_Available
private static boolean isOCL_CPU_Available
-
isOCL_GPU_Available
private static boolean isOCL_GPU_Available
-
wasOCLChecked
private static boolean wasOCLChecked
-
platformIndex
private static final int platformIndex
- See Also:
- Constant Field Values
-
width
protected int width
-
height
protected int height
-
depth
protected int depth
-
time
protected int time
-
color
protected int color
-
colorMask
protected int[] colorMask
Color flags.
-
m_iDeviceType
protected long m_iDeviceType
-
m_kGL
protected com.jogamp.opengl.GL3 m_kGL
-
entireImage
protected boolean entireImage
Flag, if true, indicates that the whole image should be processed. If false only process the image over the mask areas.
-
-
Constructor Detail
-
OpenCLAlgorithmBase
public OpenCLAlgorithmBase()
-
OpenCLAlgorithmBase
public OpenCLAlgorithmBase(ModelImage destImg, ModelImage srcImg, boolean entireImage, long type)
-
-
Method Detail
-
initCL
protected void initCL(long iType, com.jogamp.opengl.GL3 gl)
-
initContextProperties
private static void initContextProperties(org.jocl.cl_context_properties contextProperties, com.jogamp.opengl.GL gl)
Initializes the given context properties so that they may be used to create an OpenCL context for the given GL object.- Parameters:
contextProperties
- The context propertiesgl
- The GL object
-
checkError
protected void checkError(int errcode)
Checks the OpenCL error status.- Parameters:
errcode
-
-
finalize
public void finalize()
Prepare this class for destruction.- Overrides:
finalize
in classAlgorithmBase
-
saveImage
public void saveImage(float[] data, int time, int zSlice, boolean calcMinMax)
-
saveImage
public void saveImage(float[] data, int time, boolean calcMinMax)
-
isOCLAvailable
public static boolean isOCLAvailable()
-
roundUp
protected static long roundUp(long groupSize, long globalSize)
-
getInt
public static int getInt(org.jocl.cl_device_id device, int paramName)
Returns the value of the device info parameter with the given name- Parameters:
device
- The deviceparamName
- The parameter name- Returns:
- The value
-
getInts
public static int[] getInts(org.jocl.cl_device_id device, int paramName, int numValues)
Returns the values of the device info parameter with the given name- Parameters:
device
- The deviceparamName
- The parameter namenumValues
- The number of values- Returns:
- The value
-
getLong
public static long getLong(org.jocl.cl_device_id device, int paramName)
Returns the value of the device info parameter with the given name- Parameters:
device
- The deviceparamName
- The parameter name- Returns:
- The value
-
getLongs
public static long[] getLongs(org.jocl.cl_device_id device, int paramName, int numValues)
Returns the values of the device info parameter with the given name- Parameters:
device
- The deviceparamName
- The parameter namenumValues
- The number of values- Returns:
- The value
-
getString
public static java.lang.String getString(org.jocl.cl_device_id device, int paramName)
Returns the value of the device info parameter with the given name- Parameters:
device
- The deviceparamName
- The parameter name- Returns:
- The value
-
getString
public static java.lang.String getString(org.jocl.cl_platform_id platform, int paramName)
Returns the value of the platform info parameter with the given name- Parameters:
platform
- The platformparamName
- The parameter name- Returns:
- The value
-
setBlue
public void setBlue(boolean flag)
Sets the flag for the blue channel.- Parameters:
flag
- if set to true then the blue channel is processed.
-
setGreen
public void setGreen(boolean flag)
Sets the flag for the green channel.- Parameters:
flag
- if set to true then the green channel is processed.
-
setRed
public void setRed(boolean flag)
Sets the flag for the red channel.- Parameters:
flag
- if set to true then the red channel is processed.
-
setTime
public void setTime(int timeSlice)
-
readKernelFile
public static java.lang.String readKernelFile(java.lang.String fileName)
Helper function which reads the file with the given name and returns the contents of this file as a String. Will exit the application if the file can not be read.- Parameters:
fileName
- The name of the file to read.- Returns:
- The contents of the file
-
getMaxMemoryUsed
protected long getMaxMemoryUsed(int nBuffers, int elementCount, float[] sigmas)
Determines the amount of memory used for the OpenCL buffers required for the gaussian kernels for the given sigmas. Plus the memory used for the nBuffers OpenCL buffers, each elementCount in size.- Parameters:
nBuffers
- number of bufferselementCount
- buffer sizesigmas
-- Returns:
-
-