MeVisLab Toolbox Reference
mlSimilarVectorDirectionsClusterAlgorithm.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_SIMILAR_VECTOR_DIRECTIONS_CLUSTER_ALGORITHM_H
14#define ML_SIMILAR_VECTOR_DIRECTIONS_CLUSTER_ALGORITHM_H
15
16#include "mlClusterAlgorithm.h"
17#include "mlClusterRefVolume.h"
19
21
22
30class SimilarVectorDirectionsClusterAlgorithm : public ClusterAlgorithm<const void*, SimilarVectorDirectionsClusterAlgorithm>
31{
32public:
33
36
42
44 {
45 const MLDataType inputDataType = _parameters.contentImage->getDataType();
46 const bool isFloatVector = isFloatVectorType(inputDataType);
47
48 const size_t numVectorComponents = getNumVectorComponents(inputDataType);
49
50 // Allow only vector images to be processed.
52
53 if (ML_RESULT_OK == errorCode)
54 {
55 _numVectorComponents = static_cast<int>(numVectorComponents);
56 _isFloatVector = isFloatVector;
58 }
59 return errorCode;
60 }
61
64 {
65 return static_cast<SimilarVectorDirectionsClusterVoxelType*>(position);
66 }
67
69 {
70 return 0;
71 }
72
76 {
77 double result = 0.0;
78
79 if (_isFloatVector)
80 {
81 const float* inFloat1Ptr = reinterpret_cast<const float*>(vec1Ptr);
82 const float* inFloat2Ptr = reinterpret_cast<const float*>(vec2Ptr);
83 for (size_t i = 0u; i < static_cast<std::size_t>(_numVectorComponents); ++i)
84 {
86 }
87 }
88 else
89 {
90 const double* inDouble1Ptr = reinterpret_cast<const double*>(vec1Ptr);
91 const double* inDouble2Ptr = reinterpret_cast<const double*>(vec2Ptr);
92 for (size_t i = 0u; i < static_cast<std::size_t>(_numVectorComponents); ++i)
93 {
95 }
96 }
97 return result;
98 }
99
104 {
105 double dotProduct = calcDotProduct(currentValue, neighborValue);
106 return std::abs(dotProduct) > _parameters.similarityToleranceVectors;
107 }
108
110 {
111 return nullptr;
112 }
113
114private:
115
116 ML_FORCE_INLINE bool isFloatVectorType(MLDataType inputDataType)
117 {
118 return (inputDataType == MLDataTypeFromName("vecf2")) ||
119 (inputDataType == MLDataTypeFromName("vecf3")) ||
120 (inputDataType == MLDataTypeFromName("vecf4")) ||
121 (inputDataType == MLDataTypeFromName("vecf5")) ||
122 (inputDataType == MLDataTypeFromName("vecf6")) ||
123 (inputDataType == MLDataTypeFromName("vecf7")) ||
124 (inputDataType == MLDataTypeFromName("vecf8")) ||
125 (inputDataType == MLDataTypeFromName("vecf9")) ||
126 (inputDataType == MLDataTypeFromName("vecf10")) ||
127 (inputDataType == MLDataTypeFromName("vecf16")) ||
128 (inputDataType == MLDataTypeFromName("vecf32")) ||
129 (inputDataType == MLDataTypeFromName("vecf64"));
130 }
131
132 ML_FORCE_INLINE size_t getNumVectorComponents(MLDataType inputDataType)
133 {
134 return (inputDataType == MLDataTypeFromName("vecf2") || inputDataType == MLDataTypeFromName("vec2")) ? static_cast<size_t>(2) :
147 }
148
149 int _numVectorComponents;
150 bool _isFloatVector;
151};
152
153
155
156
157#endif
Type specific implementations of the interface class for clustering algorithms.
CLUSTERVOXELTYPE ClusterVoxelType
The used type of the voxels, needed by derived classes.
Structure computes and holds all cluster information. For internal use.
Definition mlClusters.h:29
Implementation of a clustering algorithm for vector data types.
ClusterAlgorithm< constvoid *, SimilarVectorDirectionsClusterAlgorithm >::ClusterVoxelType SimilarVectorDirectionsClusterVoxelType
Voxel type to be used for the VectorClusterAlgorithm.
ML_FORCE_INLINE bool isInTolerance(SimilarVectorDirectionsClusterVoxelType neighborValue, SimilarVectorDirectionsClusterVoxelType currentValue)
Tolerance calculation for vector images.
static ML_FORCE_INLINE SimilarVectorDirectionsClusterVoxelType getVoxel(void *position)
Get the typed voxel value for current position.
SimilarVectorDirectionsClusterAlgorithm(const ComputeClusterParameters &parameters, Clusters *clusters)
Constructor.
ML_FORCE_INLINE double calcDotProduct(SimilarVectorDirectionsClusterVoxelType vec1Ptr, SimilarVectorDirectionsClusterVoxelType vec2Ptr)
Calculates the dot product of two n-dimensional vectors.
static ML_FORCE_INLINE const void * convertBackgroundValue(MLdouble)
MLint32 MLDataType
MLDataType.
Definition mlTypeDefs.h:596
MLEXPORT MLDataType MLDataTypeFromName(const char *const name)
Returns the id of the data type with name name.
#define ML_BAD_DATA_TYPE
A wrong or unexpected data type has been passed to an algorithm which often is a programming error; t...
Definition mlTypeDefs.h:782
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:716
#define ML_RESULT_OK
No error. Everything seems to be okay.
Definition mlTypeDefs.h:724
#define ML_FORCE_INLINE
Forcing the use of 'inline' for methods.
Definition mlMacros.h:54
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
double MLdouble
Definition mlTypeDefs.h:217
Structure to hold parameters for cluster computation.