13#ifndef ML_CLUSTER_ALGORITHM_H
14#define ML_CLUSTER_ALGORITHM_H
35 similarityToleranceIntensities = 0;
36 similarityToleranceVectors = 0.98;
38 contentImage =
nullptr;
40 useBackgroundValue =
true;
42 useImageValueAsUserData =
false;
44 progressCBUserData =
nullptr;
61template <
typename CLUSTERVOXELTYPE,
typename DerivedAlgorithm>
class ClusterAlgorithm;
64template <
typename CLUSTERVOXELTYPE,
typename DerivedAlgorithm>
87 OrderedProcessAllPagesHandler::calculateOutputImageProperties(image);
124 _algorithm->storeNextSlice(
images[0]);
125 _error = _algorithm->processSlice(
images[0].getOrigin().z, _inImageExtent, maskImage);
165 enum { _NR_OF_SUBIMAGES = 2 } NumInImagesEnum;
204 template <
typename CLUSTERVOXELTYPE,
typename DerivedAlgorithm>
220template <
typename CLUSTERVOXELTYPE,
typename DerivedAlgorithm>
272 setInSliceVoxelType(_parameters.contentImage->getDataType());
283 if ((_parameters.neighborhoodRelation ==
NBH_2D_4_XY) || (_parameters.neighborhoodRelation ==
NBH_2D_8_XY))
285 _clusters->setUse2DNeighborhood();
288 const bool useMask = _parameters.maskImage !=
nullptr;
290 if (!Host::getDefaultHost().getUseClassicHost())
295 std::vector<PagedImage*>
images;
296 images.push_back(_parameters.contentImage);
299 images.push_back(_parameters.maskImage);
302 errorCode = Host::getDefaultHost().processAllPagesWithInputImages(
images, handler,
SubImageBox(), _parameters.progressCB, _parameters.progressCBUserData);
352 const ClusterVoxelType backgroundValue = DerivedAlgorithm::convertBackgroundValue(_parameters.backgroundValue);
356 const MLDataType dataType = _currentSlices[1].getDataType();
364 const bool useMask = _parameters.maskImage !=
nullptr;
365 const bool useBackgroundValue = _parameters.useBackgroundValue;
394 if (useBackgroundValue && (currentValue == backgroundValue))
412 switch (_parameters.neighborhoodRelation)
415 if ((
xi > 0) && (
yi > 0))
428 if ((
xi > 0) && (
yi > 0) && (
zi > 0))
446 if ((
xi>0) && (
yi > 0))
454 if ((
zi > 0) && (
xi > 0))
462 if ((
zi>0) && (
yi > 0))
493 if (_parameters.useImageValueAsUserData)
495 imageValue = DerivedAlgorithm::getVoxelAsDouble(
slicePtr);
@ CLUSTER_MODE_IdenticalIntensities
Interface class for clustering algorithms.
Clusters * _clusters
Result clusters.
ClusterAlgorithmBase(const ComputeClusterParameters ¶meters, Clusters *clusters)
Constructor to be used.
MLErrorCode loadMaskSlice(TSubImage< MLint8 > &slice, MLint sliceNr, const ImageVector &inImgExt) const
Gets current slice of the mask image.
virtual ~ClusterAlgorithmBase()
Default virtual destructor.
void freeInSliceData()
Releases memory of input image slices.
MLErrorCode loadNextSlice(MLint sliceNr, const ImageVector &inImgExt)
Gets next image data.
void setResultFlag(bool result)
Sets internal result flag to result.
MLuint mergeClusterReference(MLint x, MLint y, MLint z, MLuint currClusterRef)
Merges a cluster reference currClusterRef for position (x,y,z).
ComputeClusterParameters _parameters
void storeNextSlice(SubImage &slice)
Sets next image data, expects the data to be managed by memory manager.
bool hasResults() const
Returns whether getCluster() and getClusterOfVoxel() contains cluster data.
void setInSliceVoxelType(MLDataType dt)
Sets voxel type of input slices.
Type specific implementations of the interface class for clustering algorithms.
static CLUSTERVOXELTYPE convertBackgroundValue(MLdouble backgroundValue)
CLUSTERVOXELTYPE ClusterVoxelType
The used type of the voxels, needed by derived classes.
MLuint updateClusterRefForNeighbor(void *neighborVoxelPtr, MLint x, MLint y, MLint z, CLUSTERVOXELTYPE currentValue, MLuint currentClusterRef)
Checks if neighbor at position x,y,z belongs to the same cluster given by currentClusterRef.
MLErrorCode runClustering()
MLErrorCode processSlice(MLint zi, const ImageVector &inputImageExtent, TSubImage< MLint8 > &inMaskSlice)
MLErrorCode calcClustersForSlices()
Template applying cluster calculations for one slice.
ClusterAlgorithm(const ComputeClusterParameters ¶meters, Clusters *clusters)
Constructor to be used.
ClusterHandler that is used to provide slice-by-slice data to the cluster algorithm.
MLErrorCode processTiles(SubImage *images) override
Re-implement this method to do the processing, return ML_RESULT_OK if processing should go on,...
void calculateOutputImageProperties(PagedImage *image) override
Calculates the (temporary and virtual) output image's properties, which by default has the properties...
SubImageBox calculateInputSubImageBox(int inputIndex, const SubImageBox &outputSubImageBox) override
Called by the host to determine which input image region (tile) of input inputIndex is required to ca...
void setParameters(bool useMask, MLDataType type)
Stores all parameters that are needed to call the algorithm.
MLErrorCode getErrorCode() const
ClusterHandler(ClusterAlgorithm< CLUSTERVOXELTYPE, DerivedAlgorithm > *algorithm)
Structure computes and holds all cluster information. For internal use.
ImageVector getImageExtent() const
Returns the extent of the (sub)image.
A ProcessAllPages handler that offers ordered tile delivery on any number of input images.
Class which represents an image, which manages properties of an image and image data which is located...
MLEXPORT void setInputSubImageDataType(int inputIndex, MLDataType dataType)
Sets the dataType for the given inputIndex.
MLEXPORT void setPageExtent(const ImageVector &pageExtent)
Sets the extents of the pages to pageExtent.
MLEXPORT void setDataType(MLDataType dataType) override
Sets type of data to dataType. Overriden to perform access check.
virtual MLEXPORT void setImageExtent(const ImageVector &extent)
Sets the extents of the image to extent. The list of valid pages and its content are cleared.
MLEXPORT void setInputSubImagesAreReadOnly(bool readOnly=true)
Sets the read-only flag for all input images (see setInputSubImageIsReadOnly() for details)
This class manages/represents a rectangular 6d image region which is organized linearly in memory.
This template class manages/represents a rectangular 6d image region in memory which is organized lin...
#define ML_DISALLOW_COPY_AND_ASSIGN(className)
Defines basic macros.
MLEXPORT size_t MLSizeOf(MLDataType dataType)
Returns the size of the data type dataType in bytes.
MLint32 MLDataType
MLDataType.
@ MLint8Type
Enumerator for the signed 8 bit ML integer type.
#define ML_PROGRAMMING_ERROR
A case occurred which should not appear and here are a variety of reasons, typically it is a programm...
MLint32 MLErrorCode
Type of an ML Error code.
#define ML_RESULT_OK
No error. Everything seems to be okay.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
void MLRequestProgressCB(void *usrData, double progress)
MLuint64 MLuint
An unsigned ML integer type with at least 64 bits used for index calculations on very large images ev...
unsigned char MLTypeData
This is the pointer type used to point to the data of MLType data instances.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Cluster user data parameters.
bool useImageValueAsUserData
Structure to hold parameters for cluster computation.
CLUSTER_MODE_TYPE clusterMode
ComputeClusterParameters()
MLdouble similarityToleranceIntensities
void * progressCBUserData
bool useImageValueAsUserData
MLRequestProgressCB * progressCB
MLdouble similarityToleranceVectors
PagedImage * contentImage
NBH_TYPE neighborhoodRelation