18 #ifndef itkKdTreeBasedKmeansEstimator_h
19 #define itkKdTreeBasedKmeansEstimator_h
22 #include "itksys/hash_map.hxx"
76 template<
typename TKdTree >
132 itkSetMacro(MaximumIteration,
int);
133 itkGetConstMacro(MaximumIteration,
int);
138 itkSetMacro(CentroidPositionChangesThreshold,
double);
139 itkGetConstMacro(CentroidPositionChangesThreshold,
double);
142 void SetKdTree(TKdTree *tree);
144 const TKdTree * GetKdTree()
const;
149 itkGetConstMacro(CurrentIteration,
int);
150 itkGetConstMacro(CentroidPositionChanges,
double);
156 void StartOptimization();
160 itkSetMacro(UseClusterLabels,
bool);
161 itkGetConstMacro(UseClusterLabels,
bool);
167 void PrintSelf(std::ostream & os,
Indent indent)
const override;
191 return static_cast< int >( m_Candidates.size() );
199 m_Candidates.resize( centroids.size() );
200 for (
unsigned int i = 0; i < centroids.size(); i++ )
205 m_MeasurementVectorSize);
208 m_Candidates[i] = candidate;
218 centroids.resize( this->
Size() );
219 for ( i = 0; i < (
unsigned int)this->
Size(); i++ )
221 centroids[i] = m_Candidates[i].Centroid;
231 for ( i = 0; i < (
unsigned int)this->
Size(); i++ )
233 if ( m_Candidates[i].
Size > 0 )
235 for ( j = 0; j < m_MeasurementVectorSize; j++ )
237 m_Candidates[i].Centroid[j] =
238 m_Candidates[i].WeightedCentroid[j]
239 / double(m_Candidates[i].
Size);
248 return m_Candidates[index];
264 double GetSumOfSquaredPositionChanges(InternalParametersType & previous,
265 InternalParametersType & current);
269 int GetClosestCandidate(ParameterType & measurements,
270 std::vector< int > & validIndexes);
273 bool IsFarther(ParameterType & pointA,
274 ParameterType & pointB,
275 MeasurementVectorType & lowerBound,
276 MeasurementVectorType & upperBound);
280 void Filter(KdTreeNodeType *node,
281 std::vector< int > validIndexes,
282 MeasurementVectorType & lowerBound,
283 MeasurementVectorType & upperBound);
286 void CopyParameters(InternalParametersType & source, InternalParametersType & target);
289 void CopyParameters(ParametersType & source, InternalParametersType & target);
292 void CopyParameters(InternalParametersType & source, ParametersType & target);
295 void GetPoint(ParameterType & point, MeasurementVectorType measurements);
297 void PrintPoint(ParameterType & point);
301 int m_CurrentIteration{0};
304 int m_MaximumIteration{100};
307 double m_CentroidPositionChanges{0.0};
311 double m_CentroidPositionChangesThreshold{0.0};
326 bool m_UseClusterLabels{
false};
327 bool m_GenerateClusterLabels{
false};
335 #ifndef ITK_MANUAL_INSTANTIATION
336 #include "itkKdTreeBasedKmeansEstimator.hxx"
ParametersType m_Parameters
EuclideanDistanceMetric< ParameterType >::Pointer m_DistanceMetric
CandidateVector m_CandidateVector
Light weight base class for most itk classes.
typename DistanceToCentroidMembershipFunctionType::Pointer DistanceToCentroidMembershipFunctionPointer
Define numeric traits for std::vector.
typename TKdTree::InstanceIdentifier InstanceIdentifier
TKdTree::Pointer m_KdTree
itksys::hash_map< InstanceIdentifier, unsigned int > ClusterLabelsType
ParameterType m_TempVertex
typename TKdTree::SampleType SampleType
fast k-means algorithm implementation using k-d tree structure
typename TKdTree::KdTreeNodeType KdTreeNodeType
typename MembershipFunctionVectorObjectType::Pointer MembershipFunctionVectorObjectPointer
std::vector< ParameterType > InternalParametersType
typename KdTreeNodeType::CentroidType CentroidType
Candidate & operator[](int index)
MembershipFunctionVectorObjectPointer m_MembershipFunctionsObject
void SetCentroids(InternalParametersType ¢roids)
Decorates any "simple" data type (data types without smart pointers) with a DataObject API...
std::vector< MembershipFunctionPointer > MembershipFunctionVectorType
MembershipFunctionBase defines common interfaces for membership functions.
Represent a n-dimensional size (bounds) of a n-dimensional image.
typename TKdTree::MeasurementVectorType MeasurementVectorType
typename TKdTree::MeasurementType MeasurementType
void GetCentroids(InternalParametersType ¢roids)
std::vector< Candidate > m_Candidates
DistanceToCentroidMembershipFunction models class membership using a distance metric.
Control indentation during Print() invocation.
CentroidType WeightedCentroid
Base class for most ITK classes.
typename MembershipFunctionType::ConstPointer MembershipFunctionPointer
unsigned int MeasurementVectorSizeType
ClusterLabelsType m_ClusterLabels