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/12/15 01:00:46 $ 00007 Version: $Revision: 1.26 $ 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 typedef SmartPointer<const Self> ConstPointer; 00037 00039 itkTypeMacro(Subsample, Sample); 00040 00042 itkNewMacro(Self) ; 00043 00045 typedef typename TSample::Pointer SamplePointer ; 00046 00049 typedef typename TSample::MeasurementVectorType MeasurementVectorType; 00050 typedef typename TSample::MeasurementType MeasurementType; 00051 typedef typename TSample::InstanceIdentifier InstanceIdentifier; 00052 typedef typename TSample::FrequencyType FrequencyType ; 00053 typedef MeasurementVectorType ValueType ; 00054 00056 itkStaticConstMacro(MeasurementVectorSize, unsigned int, 00057 TSample::MeasurementVectorSize); 00058 00063 typedef std::vector< InstanceIdentifier > InstanceIdentifierHolder ; 00064 00066 void SetSample(const TSample* sample) 00067 { m_Sample = sample ; } 00068 00069 const TSample* GetSample() const 00070 { return m_Sample ; } 00071 00072 00073 void InitializeWithAllInstances() 00074 { 00075 m_IdHolder.resize(m_Sample->Size()) ; 00076 typename InstanceIdentifierHolder::iterator idIter = m_IdHolder.begin() ; 00077 typename TSample::ConstIterator iter = m_Sample->Begin() ; 00078 typename TSample::ConstIterator last = m_Sample->End() ; 00079 m_TotalFrequency = NumericTraits< FrequencyType >::Zero ; 00080 while (iter != last) 00081 { 00082 *idIter++ = iter.GetInstanceIdentifier() ; 00083 m_TotalFrequency += iter.GetFrequency() ; 00084 ++iter ; 00085 } 00086 } 00087 00088 void AddInstance(InstanceIdentifier id) 00089 { 00090 m_IdHolder.push_back(id) ; 00091 m_TotalFrequency += m_Sample->GetFrequency(id) ; 00092 } 00093 00096 unsigned int Size() const 00097 { 00098 return static_cast<unsigned int>( m_IdHolder.size() ); 00099 } 00100 00101 void Clear() 00102 { 00103 m_IdHolder.clear() ; 00104 m_TotalFrequency = NumericTraits< FrequencyType >::Zero ; 00105 } 00106 00109 const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const 00110 { return m_Sample->GetMeasurementVector(id) ; } 00111 00113 FrequencyType GetFrequency(const InstanceIdentifier &id) const 00114 { return m_Sample->GetFrequency(id) ; } 00115 00117 FrequencyType GetTotalFrequency() const 00118 { return m_TotalFrequency ; } 00119 00120 void Swap(int index1, int index2) ; 00121 00122 MeasurementVectorType GetMeasurementVectorByIndex(int index) const ; 00123 00124 FrequencyType GetFrequencyByIndex(int index) const; 00125 00126 InstanceIdentifier GetInstanceIdentifier(int index) const; 00127 00128 00129 00130 class Iterator 00131 { 00132 public: 00133 Iterator(typename InstanceIdentifierHolder::iterator iter, 00134 Self* classSample) 00135 :m_Iter(iter), m_Subsample(classSample), 00136 m_Sample(classSample->GetSample()) 00137 {} 00138 00139 FrequencyType GetFrequency() const 00140 { return m_Sample->GetFrequency(*m_Iter) ; } 00141 00142 const MeasurementVectorType & GetMeasurementVector() const 00143 { return m_Sample->GetMeasurementVector(*m_Iter) ; } 00144 00145 InstanceIdentifier GetInstanceIdentifier() const 00146 { return *m_Iter ; } 00147 00148 Iterator& operator++() 00149 { 00150 ++m_Iter ; 00151 return *this ; 00152 } 00153 00154 Iterator& operator+() 00155 { m_Iter += n; return *this ;} 00156 00157 Iterator& operator+(int n) 00158 { m_Iter += n; return *this ;} 00159 00160 Iterator& operator-(int n) 00161 { m_Iter -= n; return *this ;} 00162 00163 bool operator!=(const Iterator& it) 00164 { return (m_Iter != it.m_Iter) ; } 00165 00166 bool operator==(const Iterator& it) 00167 { return (m_Iter == it.m_Iter) ; } 00168 00169 Iterator& operator=(const Iterator& iter) 00170 { 00171 m_Iter = iter.m_Iter; 00172 m_Subsample = iter.m_Subsample ; 00173 m_Sample = iter.m_Sample ; 00174 return *this ; 00175 } 00176 00177 Iterator(const Iterator& iter) 00178 { 00179 m_Iter = iter.m_Iter; 00180 m_Subsample = iter.m_Subsample ; 00181 m_Sample = iter.m_Sample ; 00182 } 00183 00184 private: 00185 // Iterator pointing to ImageToListAdaptor 00186 typename InstanceIdentifierHolder::iterator m_Iter ; 00187 // Pointer to Subsample object 00188 Self* m_Subsample ; 00189 const TSample* m_Sample ; 00190 } ; 00191 00192 00193 00194 class ConstIterator 00195 { 00196 public: 00197 ConstIterator(typename InstanceIdentifierHolder::const_iterator iter, 00198 const Self* classSample) 00199 :m_Iter(iter), m_Subsample(classSample), 00200 m_Sample(classSample->GetSample()) 00201 {} 00202 00203 FrequencyType GetFrequency() const 00204 { return m_Sample->GetFrequency(*m_Iter) ; } 00205 00206 const MeasurementVectorType & GetMeasurementVector() const 00207 { return m_Sample->GetMeasurementVector(*m_Iter) ; } 00208 00209 InstanceIdentifier GetInstanceIdentifier() const 00210 { return *m_Iter ; } 00211 00212 ConstIterator& operator++() 00213 { 00214 ++m_Iter ; 00215 return *this ; 00216 } 00217 00218 ConstIterator& operator+() 00219 { m_Iter += n; return *this ;} 00220 00221 ConstIterator& operator+(int n) 00222 { m_Iter += n; return *this ;} 00223 00224 ConstIterator& operator-(int n) 00225 { m_Iter -= n; return *this ;} 00226 00227 bool operator!=(const ConstIterator& it) 00228 { return (m_Iter != it.m_Iter) ; } 00229 00230 bool operator==(const ConstIterator& it) 00231 { return (m_Iter == it.m_Iter) ; } 00232 00233 ConstIterator& operator=(const ConstIterator& iter) 00234 { 00235 m_Iter = iter.m_Iter; 00236 m_Subsample = iter.m_Subsample ; 00237 m_Sample = iter.m_Sample ; 00238 return *this ; 00239 } 00240 00241 ConstIterator(const ConstIterator& iter) 00242 { 00243 m_Iter = iter.m_Iter; 00244 m_Subsample = iter.m_Subsample ; 00245 m_Sample = iter.m_Sample ; 00246 } 00247 00248 private: 00249 // ConstIterator pointing to ImageToListAdaptor 00250 typename InstanceIdentifierHolder::const_iterator m_Iter ; 00251 // Pointer to Subsample object 00252 const Self* m_Subsample ; 00253 const TSample* m_Sample ; 00254 } ; 00255 00256 00257 00258 Iterator Begin() 00259 { 00260 Iterator iter(m_IdHolder.begin(), this) ; 00261 return iter; 00262 } 00263 00264 Iterator End() 00265 { 00266 Iterator iter(m_IdHolder.end(), this) ; 00267 return iter; 00268 } 00269 00270 ConstIterator Begin() const 00271 { 00272 ConstIterator iter(m_IdHolder.begin(), this) ; 00273 return iter; 00274 } 00275 00276 ConstIterator End() const 00277 { 00278 ConstIterator iter(m_IdHolder.end(), this) ; 00279 return iter; 00280 } 00281 00282 protected: 00283 Subsample() ; 00284 virtual ~Subsample() {} 00285 void PrintSelf(std::ostream& os, Indent indent) const; 00286 00287 private: 00288 Subsample(const Self&) ; //purposely not implemented 00289 void operator=(const Self&) ; //purposely not implemented 00290 00291 const TSample* m_Sample ; 00292 InstanceIdentifierHolder m_IdHolder ; 00293 unsigned int m_ActiveDimension ; 00294 FrequencyType m_TotalFrequency ; 00295 } ; // end of class 00296 00297 00298 } // end of namespace Statistics 00299 } // end of namespace itk 00300 00301 00302 #ifndef ITK_MANUAL_INSTANTIATION 00303 #include "itkSubsample.txx" 00304 #endif 00305 00306 #endif 00307 00308 00309 00310 00311 00312 00313

Generated at Sun Apr 1 02:45:21 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000