Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkMembershipSample.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkMembershipSample.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/09/10 14:29:47 $ 00007 Version: $Revision: 1.25 $ 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 #ifndef __itkMembershipSample_h 00018 #define __itkMembershipSample_h 00019 00020 #include "itk_hash_map.h" 00021 #include "itkSample.h" 00022 #include "itkSubsample.h" 00023 00024 #include "itkExceptionObject.h" 00025 00026 namespace itk{ 00027 namespace Statistics{ 00028 00050 template< class TSample > 00051 class ITK_EXPORT MembershipSample : 00052 public Sample< typename TSample::MeasurementVectorType > 00053 { 00054 public: 00056 typedef MembershipSample Self; 00057 typedef Sample< typename TSample::MeasurementVectorType > Superclass ; 00058 typedef SmartPointer< Self > Pointer ; 00059 00061 itkTypeMacro(MembershipSample, Sample); 00062 itkNewMacro(Self) ; 00063 00066 typedef typename TSample::MeasurementVectorType MeasurementVectorType; 00067 typedef typename TSample::MeasurementType MeasurementType; 00068 typedef typename TSample::InstanceIdentifier InstanceIdentifier; 00069 typedef typename TSample::FrequencyType FrequencyType ; 00070 // typedef typename TSample::SizeType SizeType ; 00071 // typedef typename TSample::SizeValueType SizeValueType ; 00072 00074 itkStaticConstMacro(MeasurementVectorSize, unsigned int, 00075 TSample::MeasurementVectorSize); 00076 00079 typedef std::vector< unsigned int > UniqueClassLabelsType ; 00080 00083 typedef itk::hash_map< InstanceIdentifier, unsigned int> ClassLabelHolderType ; 00084 00087 typedef Subsample< TSample > ClassSampleType ; 00088 00090 void SetSample(TSample* sample) ; 00091 00093 TSample* GetSample() ; 00094 00096 void SetNumberOfClasses(unsigned int numberOfClasses) ; 00097 00099 unsigned int GetNumberOfClasses() const ; 00100 00105 void AddInstance(const unsigned int &classLabel, const InstanceIdentifier &id) ; 00108 unsigned int GetClassLabel(const InstanceIdentifier &id) const ; 00109 00112 int GetInternalClassLabel(const unsigned int classLabel ) const ; 00113 00116 unsigned int GetClassSampleSize(const unsigned int &classLabel) const ; 00117 00120 ClassSampleType* GetClassSample(const unsigned int &classLabel) ; 00121 00124 ClassLabelHolderType* GetClassLabels() 00125 { return &m_ClassLabelHolder ; } 00126 00128 unsigned int Size(void) const ; 00129 00132 MeasurementVectorType GetMeasurementVector(const InstanceIdentifier &id) ; 00133 00136 MeasurementType GetMeasurement(const InstanceIdentifier &id, 00137 const unsigned int &dimension) ; 00138 00140 FrequencyType GetFrequency(const InstanceIdentifier &id) const ; 00141 00143 FrequencyType GetTotalFrequency() const ; 00144 00145 void Resize(unsigned int n) 00146 { 00147 m_ClassLabelHolder.resize(n) ; 00148 } 00149 00150 class Iterator; 00151 friend class Iterator; 00152 00153 Iterator Begin() 00154 { 00155 Iterator iter(0, this) ; 00156 return iter; 00157 } 00158 00159 Iterator End() 00160 { 00161 Iterator iter(this->Size(), this) ; 00162 return iter; 00163 } 00164 00165 class Iterator 00166 { 00167 public: 00168 Iterator(InstanceIdentifier id, Self* membershipSample) 00169 :m_Id(id), m_MembershipSample(membershipSample), 00170 m_Sample(membershipSample->GetSample()) 00171 {} 00172 00173 FrequencyType GetFrequency() const 00174 { return m_Sample->GetFrequency(m_Id) ; } 00175 00176 MeasurementVectorType GetMeasurementVector() 00177 { return m_Sample->GetMeasurementVector(m_Id) ; } 00178 00179 InstanceIdentifier GetInstanceIdentifier() const 00180 { return m_Id ; } 00181 00182 void SetClassLabel(unsigned int classLabel) 00183 { m_MembershipSample->AddInstance(classLabel, m_Id) ; } 00184 00185 unsigned int GetClassLabel() const 00186 { return m_MembershipSample->GetClassLabel(m_Id) ; } 00187 00188 Iterator& operator++() 00189 { 00190 ++m_Id ; 00191 return *this ; 00192 } 00193 00194 bool operator!=(const Iterator& it) 00195 { 00196 if (m_Id != it.m_Id || 00197 m_MembershipSample != it.m_MembershipSample || 00198 m_Sample != it.m_Sample) 00199 { 00200 return true ; 00201 } 00202 else 00203 { 00204 return false ; 00205 } 00206 } 00207 00208 bool operator==(const Iterator& it) 00209 { 00210 if (m_Id == it.m_Id && 00211 m_MembershipSample == it.m_MembershipSample && 00212 m_Sample == it.m_Sample) 00213 { 00214 return true ; 00215 } 00216 else 00217 { 00218 return false ; 00219 } 00220 } 00221 00222 Iterator& operator=(const Iterator& it) 00223 { 00224 m_Id = it.m_Id; 00225 m_MembershipSample = it.m_MembershipSample ; 00226 m_Sample = it.m_Sample ; 00227 return *this ; 00228 } 00229 00230 Iterator(const Iterator& it) 00231 { 00232 m_Id = it.m_Id; 00233 m_MembershipSample = it.m_MembershipSample ; 00234 m_Sample = it.m_Sample ; 00235 } 00236 00237 private: 00238 // identifier for the instance 00239 InstanceIdentifier m_Id ; 00240 // Pointer to MemebershipSample object 00241 Self* m_MembershipSample ; 00242 TSample* m_Sample ; 00243 } ; 00244 00245 protected: 00246 MembershipSample() ; 00247 virtual ~MembershipSample() {} 00248 void PrintSelf(std::ostream& os, Indent indent) const; 00249 00250 private: 00251 MembershipSample(const Self&) ; //purposely not implemented 00252 void operator=(const Self&) ; //purposely not implemented 00253 00254 TSample* m_Sample ; 00255 unsigned int m_CurrentClassLabel ; 00256 UniqueClassLabelsType m_UniqueClassLabels ; 00257 ClassLabelHolderType m_ClassLabelHolder ; 00258 unsigned int m_NumberOfClasses ; 00259 std::vector< unsigned int > m_ClassSampleSizes ; 00260 std::vector< typename ClassSampleType::Pointer > m_ClassSamples ; 00261 } ; // end of class 00262 00263 00264 } // end of namespace Statistics 00265 } // end of namespace itk 00266 00267 00268 #ifndef ITK_MANUAL_INSTANTIATION 00269 #include "itkMembershipSample.txx" 00270 #endif 00271 00272 #endif 00273 00274 00275 00276 00277 00278 00279

Generated at Sat Mar 31 02:24:25 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000