Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkImageToListSampleAdaptor_h
00018 #define __itkImageToListSampleAdaptor_h
00019
00020 #include <typeinfo>
00021
00022 #include "itkImage.h"
00023 #include "itkPixelTraits.h"
00024 #include "itkListSample.h"
00025 #include "itkSmartPointer.h"
00026 #include "itkImageRegionIterator.h"
00027 #include "itkFixedArray.h"
00028 #include "itkMacro.h"
00029 #include "itkMeasurementVectorTraits.h"
00030
00031 namespace itk {
00032 namespace Statistics {
00033
00048 template < class TImage >
00049 class ITK_EXPORT ImageToListSampleAdaptor :
00050 public ListSample< typename MeasurementVectorPixelTraits< typename TImage::PixelType >::MeasurementVectorType >
00051 {
00052 public:
00054 typedef ImageToListSampleAdaptor Self;
00055
00056 typedef ListSample< typename MeasurementVectorPixelTraits<
00057 typename TImage::PixelType >::MeasurementVectorType >
00058 Superclass;
00059
00060 typedef SmartPointer< Self > Pointer;
00061 typedef SmartPointer<const Self> ConstPointer;
00062
00064 itkTypeMacro(ImageToListSampleAdaptor, ListSample);
00065
00067 itkNewMacro(Self);
00068
00070 typedef TImage ImageType;
00071 typedef typename ImageType::Pointer ImagePointer;
00072 typedef typename ImageType::ConstPointer ImageConstPointer;
00073 typedef typename ImageType::IndexType IndexType;
00074 typedef typename ImageType::PixelType PixelType;
00075 typedef typename ImageType::PixelContainerConstPointer PixelContainerConstPointer;
00076
00078 typedef ImageRegionIterator< ImageType > ImageIteratorType;
00079 typedef ImageRegionConstIterator< ImageType > ImageConstIteratorType;
00080 typedef PixelTraits< typename TImage::PixelType > PixelTraitsType;
00081
00084 typedef typename MeasurementVectorPixelTraits<
00085 PixelType >::MeasurementVectorType MeasurementVectorType;
00086 typedef typename MeasurementVectorTraitsTypes<
00087 MeasurementVectorType >::ValueType MeasurementType;
00088 itkSuperclassTraitMacro( AbsoluteFrequencyType )
00089 itkSuperclassTraitMacro( TotalAbsoluteFrequencyType )
00090 itkSuperclassTraitMacro( MeasurementVectorSizeType )
00091 itkSuperclassTraitMacro( InstanceIdentifier )
00093
00094 typedef MeasurementVectorType ValueType;
00095
00097 void SetImage(const TImage* image);
00098
00100 const TImage* GetImage() const;
00101
00103 InstanceIdentifier Size() const;
00104
00106 virtual const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const;
00107
00109 AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const;
00110
00112 TotalAbsoluteFrequencyType GetTotalFrequency() const;
00113
00115 itkSetMacro( UsePixelContainer, bool );
00116
00118 itkGetConstMacro( UsePixelContainer, bool );
00119
00121 itkBooleanMacro( UsePixelContainer );
00122
00123
00124
00126 class ConstIterator
00127 {
00128 friend class ImageToListSampleAdaptor;
00129 public:
00130
00131 ConstIterator( const ImageToListSampleAdaptor * adaptor )
00132 {
00133 *this = adaptor->Begin();
00134 }
00135
00136 ConstIterator(const ConstIterator &iter)
00137 {
00138 m_Iter = iter.m_Iter;
00139 m_InstanceIdentifier = iter.m_InstanceIdentifier;
00140 }
00141
00142 ConstIterator& operator=( const ConstIterator & iter )
00143 {
00144 m_Iter = iter.m_Iter;
00145 m_InstanceIdentifier = iter.m_InstanceIdentifier;
00146 return *this;
00147 }
00148
00149 AbsoluteFrequencyType GetFrequency() const
00150 {
00151 return 1;
00152 }
00153
00154 const MeasurementVectorType & GetMeasurementVector() const
00155 {
00156 MeasurementVectorTraits::Assign( this->m_MeasurementVectorCache, m_Iter.Get());
00157 return this->m_MeasurementVectorCache;
00158 }
00159
00160 InstanceIdentifier GetInstanceIdentifier() const
00161 {
00162 return m_InstanceIdentifier;
00163 }
00164
00165 ConstIterator& operator++()
00166 {
00167 ++m_Iter;
00168 ++m_InstanceIdentifier;
00169 return *this;
00170 }
00171
00172 bool operator!=(const ConstIterator &it)
00173 {
00174 return (m_Iter != it.m_Iter);
00175 }
00176
00177 bool operator==(const ConstIterator &it)
00178 {
00179 return (m_Iter == it.m_Iter);
00180 }
00181
00182 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
00183 protected:
00184 #endif
00185
00186 ConstIterator(
00187 ImageConstIteratorType iter,
00188 InstanceIdentifier iid)
00189 {
00190 m_Iter = iter;
00191 m_InstanceIdentifier = iid;
00192 }
00193
00194
00195 ConstIterator();
00196
00197 private:
00198 ImageConstIteratorType m_Iter;
00199 mutable MeasurementVectorType m_MeasurementVectorCache;
00200 InstanceIdentifier m_InstanceIdentifier;
00201 };
00202
00204 class Iterator : public ConstIterator
00205 {
00206
00207 friend class ImageToListSampleAdaptor;
00208
00209 public:
00210
00211 Iterator(Self * adaptor):ConstIterator(adaptor)
00212 {
00213 }
00214
00215 Iterator(const Iterator &iter):ConstIterator( iter )
00216 {
00217 }
00218
00219 Iterator& operator =(const Iterator & iter)
00220 {
00221 this->ConstIterator::operator=( iter );
00222 return *this;
00223 }
00224
00225 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
00226 protected:
00227 #endif
00228
00229
00230 Iterator();
00231 Iterator(const Self * adaptor);
00232 Iterator( ImageConstIteratorType iter, InstanceIdentifier iid);
00233 Iterator(const ConstIterator & it);
00234 ConstIterator& operator=(const ConstIterator& it);
00235 Iterator(
00236 ImageIteratorType iter,
00237 InstanceIdentifier iid):ConstIterator( iter, iid )
00238 {
00239 }
00240
00241 private:
00242 };
00243
00244
00246 Iterator Begin()
00247 {
00248 ImagePointer nonConstImage = const_cast< ImageType* >(m_Image.GetPointer());
00249 ImageIteratorType imageIterator( nonConstImage, nonConstImage->GetLargestPossibleRegion());
00250 Iterator iter(imageIterator.Begin(), 0);
00251 return iter;
00252 }
00254
00256 Iterator End()
00257 {
00258 ImagePointer nonConstImage = const_cast< ImageType* >(m_Image.GetPointer());
00259 ImageIteratorType imageIterator( nonConstImage, nonConstImage->GetLargestPossibleRegion());
00260 Iterator iter(imageIterator.End(), m_Image->GetPixelContainer()->Size());
00261 return iter;
00262 }
00264
00265
00267 ConstIterator Begin() const
00268 {
00269 ImageConstIteratorType imageConstIterator( m_Image, m_Image->GetLargestPossibleRegion());
00270 ConstIterator iter(imageConstIterator.Begin(), 0);
00271 return iter;
00272 }
00274
00276 ConstIterator End() const
00277 {
00278 ImageConstIteratorType imageConstIterator( m_Image, m_Image->GetLargestPossibleRegion());
00279 ConstIterator iter(imageConstIterator.End(), m_Image->GetPixelContainer()->Size());
00280 return iter;
00281 }
00283
00284
00285 protected:
00286 ImageToListSampleAdaptor();
00287 virtual ~ImageToListSampleAdaptor() {}
00288 void PrintSelf(std::ostream& os, Indent indent) const;
00289
00290 private:
00291 ImageToListSampleAdaptor(const Self&);
00292 void operator=(const Self&);
00293
00294 ImageConstPointer m_Image;
00295 mutable MeasurementVectorType m_MeasurementVectorInternal;
00296 bool m_UsePixelContainer;
00297
00298 PixelContainerConstPointer m_PixelContainer;
00299
00300 };
00301
00302 }
00303 }
00304
00305 #ifndef ITK_MANUAL_INSTANTIATION
00306 #include "itkImageToListSampleAdaptor.txx"
00307 #endif
00308
00309 #endif
00310