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

itkSubsample.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkSubsample.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/09/10 14:29:48 $ 00007 Version: $Revision: 1.23 $ 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 __itkSubsample_h 00018 #define __itkSubsample_h 00019 00020 #include "itkSample.h" 00021 #include "itkMacro.h" 00022 #include "itkObjectFactory.h" 00023 00024 namespace itk{ 00025 namespace Statistics{ 00026 00027 template< class TSample > 00028 class ITK_EXPORT Subsample : 00029 public Sample< typename TSample::MeasurementVectorType > 00030 { 00031 public: 00033 typedef Subsample Self; 00034 typedef Sample< typename TSample::MeasurementVectorType > Superclass ; 00035 typedef SmartPointer< Self > Pointer ; 00036 00038 itkTypeMacro(Subsample, Sample); 00039 00041 itkNewMacro(Self) ; 00042 00044 typedef typename TSample::Pointer SamplePointer ; 00045 00048 typedef typename TSample::MeasurementVectorType MeasurementVectorType; 00049 typedef typename TSample::MeasurementType MeasurementType; 00050 typedef typename TSample::InstanceIdentifier InstanceIdentifier; 00051 typedef typename TSample::FrequencyType FrequencyType ; 00052 typedef MeasurementVectorType ValueType ; 00053 00055 itkStaticConstMacro(MeasurementVectorSize, unsigned int, 00056 TSample::MeasurementVectorSize); 00057 00062 typedef std::vector< InstanceIdentifier > InstanceIdentifierHolder ; 00063 00065 void SetSample(TSample* sample) 00066 { m_Sample = sample ; } 00067 00068 TSample* GetSample() 00069 { return m_Sample ; } 00070 00071 void InitializeWithAllInstances() 00072 { 00073 m_IdHolder.resize(m_Sample->Size()) ; 00074 typename InstanceIdentifierHolder::iterator idIter = m_IdHolder.begin() ; 00075 typename TSample::Iterator iter = m_Sample->Begin() ; 00076 typename TSample::Iterator last = m_Sample->End() ; 00077 m_TotalFrequency = NumericTraits< FrequencyType >::Zero ; 00078 while (iter != last) 00079 { 00080 *idIter++ = iter.GetInstanceIdentifier() ; 00081 m_TotalFrequency += iter.GetFrequency() ; 00082 ++iter ; 00083 } 00084 } 00085 00086 void AddInstance(InstanceIdentifier id) 00087 { 00088 m_IdHolder.push_back(id) ; 00089 m_TotalFrequency += m_Sample->GetFrequency(id) ; 00090 } 00091 00094 unsigned int Size() const 00095 { 00096 return static_cast<unsigned int>( m_IdHolder.size() ); 00097 } 00098 00099 void Clear() 00100 { 00101 m_IdHolder.clear() ; 00102 m_TotalFrequency = NumericTraits< FrequencyType >::Zero ; 00103 } 00104 00107 MeasurementVectorType GetMeasurementVector(const InstanceIdentifier &id) 00108 { return m_Sample->GetMeasurementVector(id) ; } 00109 00111 FrequencyType GetFrequency(const InstanceIdentifier &id) const 00112 { return m_Sample->GetFrequency(id) ; } 00113 00115 FrequencyType GetTotalFrequency() const 00116 { return m_TotalFrequency ; } 00117 00118 void Swap(int index1, int index2) ; 00119 00120 MeasurementVectorType GetMeasurementVectorByIndex(int index) ; 00121 00122 FrequencyType GetFrequencyByIndex(int index) ; 00123 00124 InstanceIdentifier GetInstanceIdentifier(int index) ; 00125 00126 class Iterator; 00127 friend class Iterator; 00128 00129 Iterator Begin() 00130 { 00131 Iterator iter(m_IdHolder.begin(), this) ; 00132 return iter; 00133 } 00134 00135 Iterator End() 00136 { 00137 Iterator iter(m_IdHolder.end(), this) ; 00138 return iter; 00139 } 00140 00141 class Iterator 00142 { 00143 public: 00144 Iterator(typename InstanceIdentifierHolder::iterator iter, 00145 Self* classSample) 00146 :m_Iter(iter), m_Subsample(classSample), 00147 m_Sample(classSample->GetSample()) 00148 {} 00149 00150 FrequencyType GetFrequency() const 00151 { return m_Sample->GetFrequency(*m_Iter) ; } 00152 00153 MeasurementVectorType GetMeasurementVector() 00154 { return m_Sample->GetMeasurementVector(*m_Iter) ; } 00155 00156 InstanceIdentifier GetInstanceIdentifier() const 00157 { return *m_Iter ; } 00158 00159 Iterator& operator++() 00160 { 00161 ++m_Iter ; 00162 return *this ; 00163 } 00164 00165 Iterator& operator+() 00166 { m_Iter += n; return *this ;} 00167 00168 Iterator& operator+(int n) 00169 { m_Iter += n; return *this ;} 00170 00171 Iterator& operator-(int n) 00172 { m_Iter -= n; return *this ;} 00173 00174 bool operator!=(const Iterator& it) 00175 { return (m_Iter != it.m_Iter) ; } 00176 00177 bool operator==(const Iterator& it) 00178 { return (m_Iter == it.m_Iter) ; } 00179 00180 Iterator& operator=(const Iterator& iter) 00181 { 00182 m_Iter = iter.m_Iter; 00183 m_Subsample = iter.m_Subsample ; 00184 m_Sample = iter.m_Sample ; 00185 return *this ; 00186 } 00187 00188 Iterator(const Iterator& iter) 00189 { 00190 m_Iter = iter.m_Iter; 00191 m_Subsample = iter.m_Subsample ; 00192 m_Sample = iter.m_Sample ; 00193 } 00194 00195 private: 00196 // Iterator pointing to ImageToListAdaptor 00197 typename InstanceIdentifierHolder::iterator m_Iter ; 00198 // Pointer to Subsample object 00199 Self* m_Subsample ; 00200 TSample* m_Sample ; 00201 } ; 00202 00203 protected: 00204 Subsample() ; 00205 virtual ~Subsample() {} 00206 void PrintSelf(std::ostream& os, Indent indent) const; 00207 00208 private: 00209 Subsample(const Self&) ; //purposely not implemented 00210 void operator=(const Self&) ; //purposely not implemented 00211 00212 TSample* m_Sample ; 00213 InstanceIdentifierHolder m_IdHolder ; 00214 unsigned int m_ActiveDimension ; 00215 FrequencyType m_TotalFrequency ; 00216 } ; // end of class 00217 00218 00219 } // end of namespace Statistics 00220 } // end of namespace itk 00221 00222 00223 #ifndef ITK_MANUAL_INSTANTIATION 00224 #include "itkSubsample.txx" 00225 #endif 00226 00227 #endif 00228 00229 00230 00231 00232 00233 00234

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