00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkImageToListAdaptor_h
00018 #define __itkImageToListAdaptor_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
00028 namespace itk{
00029 namespace Statistics{
00030
00060 template < class TImage >
00061 class ITK_EXPORT ImageToListAdaptor :
00062 public ListSample< typename TImage::PixelType >
00063 {
00064 public:
00066 typedef ImageToListAdaptor Self;
00067 typedef ListSample< typename TImage::PixelType > Superclass;
00068 typedef SmartPointer< Self > Pointer;
00069
00071 itkTypeMacro(ImageToListAdaptor, ListSample) ;
00072
00074 itkNewMacro(Self) ;
00075
00077 typedef TImage ImageType;
00078 typedef typename ImageType::Pointer ImagePointer ;
00079 typedef typename ImageType::IndexType IndexType ;
00080 typedef typename ImageType::PixelType PixelType ;
00081 typedef typename ImageType::PixelContainerPointer PixelContainerPointer ;
00082 typedef typename ImageType::PixelContainer::ElementIdentifier
00083 InstanceIdentifier;
00084
00086 typedef ImageRegionIterator< ImageType > IteratorType ;
00087 typedef PixelTraits< typename TImage::PixelType > PixelTraitsType ;
00088
00090 itkStaticConstMacro(MeasurementVectorSize, unsigned int,
00091 PixelTraitsType::Dimension);
00092
00095 typedef typename PixelTraitsType::ValueType MeasurementType ;
00096 typedef PixelType MeasurementVectorType;
00097 typedef MeasurementVectorType ValueType ;
00098 typedef typename Superclass::FrequencyType FrequencyType ;
00099
00101 void SetImage(ImagePointer image) ;
00102
00104 ImagePointer GetImage() ;
00105
00107 unsigned int Size() const ;
00108
00109 unsigned int Size(const unsigned int &dimension) const ;
00110
00111 unsigned int GetNumberOfInstances() const ;
00112
00113 void SetMeasurementVector(const InstanceIdentifier id,
00114 const MeasurementVectorType &measurementVector) ;
00115
00116 MeasurementVectorType& GetMeasurementVector(const InstanceIdentifier &id) ;
00117
00118 void SetMeasurement(const InstanceIdentifier &id,
00119 const unsigned int &dim,
00120 const MeasurementType &value) ;
00121
00122 FrequencyType GetFrequency(const InstanceIdentifier &id) const ;
00123
00124 FrequencyType GetTotalFrequency(const unsigned int &dimension) const ;
00125
00126 class Iterator;
00127 friend class Iterator;
00128
00129 Iterator Begin()
00130 {
00131 Iterator iter(0, this);
00132 return iter;
00133 }
00134
00135 Iterator End()
00136 {
00137 Iterator iter(this->Size(), this);
00138 return iter;
00139 }
00140
00141 class Iterator
00142 {
00143 public:
00144
00145 Iterator(){}
00146
00147 Iterator(InstanceIdentifier id, Pointer pContainer)
00148 :m_Id(id),m_Container(pContainer)
00149 {}
00150
00151 FrequencyType GetFrequency() const
00152 { return 1 ;}
00153
00154 MeasurementVectorType& GetMeasurementVector()
00155 { return m_Container->GetMeasurementVector(m_Id) ;}
00156
00157 InstanceIdentifier GetInstanceIdentifier() const
00158 { return m_Id ;}
00159
00160 Iterator& operator++()
00161 { ++m_Id ; return *this ;}
00162
00163 Iterator& operator+()
00164 { m_Id += n; return *this ;}
00165
00166 Iterator& operator+(int n)
00167 { m_Id += n; return *this ;}
00168
00169 Iterator& operator-(int n)
00170 { m_Id -= n; return *this ;}
00171
00172 bool operator!=(const Iterator &it)
00173 {
00174 if (m_Id != it.m_Id)
00175 {return true ;}
00176
00177 if (m_Container != it.m_Container)
00178 { return true ;}
00179
00180 return false ;
00181 }
00182
00183 bool operator==(const Iterator &it)
00184 { return !(this != it);}
00185
00186 Iterator& operator = (const Iterator &iter)
00187 {
00188 m_Id = iter.m_Id;
00189 m_Container = iter.m_Container ;
00190 return *this ;
00191 }
00192
00193 Iterator(const Iterator &iter)
00194 {
00195 m_Id = iter.m_Id;
00196 m_Container = iter.m_Container ;
00197 }
00198
00199 private:
00200 InstanceIdentifier m_Id;
00201 Pointer m_Container ;
00202 } ;
00203
00204 protected:
00205 ImageToListAdaptor() {}
00206 virtual ~ImageToListAdaptor() {}
00207 void PrintSelf(std::ostream& os, Indent indent) const;
00208
00209 private:
00210 ImageToListAdaptor(const Self&) ;
00211 void operator=(const Self&) ;
00212
00213 ImagePointer m_Image ;
00214 PixelContainerPointer m_PixelContainer ;
00215 } ;
00216
00217 }
00218 }
00219
00220 #ifndef ITK_MANUAL_INSTANTIATION
00221 #include "itkImageToListAdaptor.txx"
00222 #endif
00223
00224 #endif