00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkMeanShiftModeCacheMethod.h,v $ 00005 Language: C++ 00006 Date: $Date: 2005/07/26 15:55:00 $ 00007 Version: $Revision: 1.5 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #ifndef __itkMeanShiftModeCacheMethod_h 00019 #define __itkMeanShiftModeCacheMethod_h 00020 00021 #include <map> 00022 #include "itkMacro.h" 00023 #include "itkObject.h" 00024 #include "itkMeasurementVectorTraits.h" 00025 00026 namespace itk{ 00027 namespace Statistics{ 00028 00056 template< class TMeasurementVector > 00057 class MeanShiftModeCacheMethod : 00058 public Object 00059 { 00060 public: 00062 typedef MeanShiftModeCacheMethod Self; 00063 typedef Object Superclass ; 00064 typedef SmartPointer<Self> Pointer; 00065 typedef SmartPointer<const Self> ConstPointer; 00066 00068 itkTypeMacro(MeanShiftModeCacheMethod, Object); 00069 itkNewMacro(Self) ; 00070 00071 typedef TMeasurementVector MeasurementVectorType ; 00072 00073 struct LessMeasurementVector 00074 { 00075 bool operator()(const MeasurementVectorType& mv1, 00076 const MeasurementVectorType& mv2) const 00077 { 00078 // It is assumed that mv1 and mv2 are of the same length. For efficieny, 00079 // no checking is performed here. 00080 for ( unsigned int i = 0 ; 00081 i < MeasurementVectorTraits::GetLength( &mv1 ); 00082 ++i ) 00083 { 00084 if (mv1[i] < mv2[i]) 00085 { 00086 return true ; 00087 } 00088 } 00089 return false ; 00090 } 00091 } ; // end of struct 00092 00093 typedef std::map< MeasurementVectorType, MeasurementVectorType, LessMeasurementVector > CacheTableType ; 00094 00095 void SetMaximumConsecutiveFailures(unsigned int number) 00096 { m_MaximumConsecutiveFailures = number ; } 00097 00098 unsigned int GetMaximumConsecutiveFailures() 00099 { return m_MaximumConsecutiveFailures ; } 00100 00101 void SetHitRatioThreshold(float threshold) 00102 { m_HitRatioThreshold = threshold ; } 00103 00104 void SetMaximumEntries(unsigned int number) 00105 { m_MaximumEntries = number ; } 00106 00107 unsigned int GetMaximumEntries() 00108 { return m_MaximumEntries ; } 00109 00110 bool SetMeasurementVector(MeasurementVectorType& source, 00111 MeasurementVectorType& target) ; 00112 00113 bool GetMeasurementVector(MeasurementVectorType& source, 00114 MeasurementVectorType& target) ; 00115 00116 bool IsFull() ; 00117 00118 void DestroyCacheTable() ; 00119 00120 protected: 00121 MeanShiftModeCacheMethod() ; 00122 virtual ~MeanShiftModeCacheMethod() ; 00123 void PrintSelf(std::ostream& os, Indent indent) const; 00124 00125 private: 00126 unsigned int m_MaximumEntries ; 00127 float m_HitRatioThreshold ; 00128 unsigned int m_MaximumConsecutiveFailures ; 00129 00130 unsigned int m_NumberOfRequests ; 00131 unsigned int m_ConsecutiveFailures ; 00132 unsigned int m_HitsSuccess ; 00133 00134 unsigned long m_TotalHitsSuccess ; 00135 unsigned long m_TotalHitsFailure ; 00136 00137 unsigned long m_TotalTableSize ; 00138 unsigned int m_TimesOfRebuilding ; 00139 00140 unsigned int m_TimesOfRebuildingByHitRatio ; 00141 unsigned int m_TimesOfRebuildingByConsecutiveFailures ; 00142 00143 CacheTableType m_CacheTable ; 00144 } ; // end of class 00145 00146 } // end of namespace Statistics 00147 } // end of namespace itk 00148 00149 #ifndef ITK_MANUAL_INSTANTIATION 00150 #include "itkMeanShiftModeCacheMethod.txx" 00151 #endif 00152 00153 #endif 00154