itkJointDomainImageToListSampleAdaptor.h
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 __itkJointDomainImageToListSampleAdaptor_h
00018 #define __itkJointDomainImageToListSampleAdaptor_h
00019
00020 #include "itkMacro.h"
00021 #include "itkFixedArray.h"
00022 #include "itkPoint.h"
00023 #include "itkPixelTraits.h"
00024 #include "itkImageRegionConstIteratorWithIndex.h"
00025 #include "itkImageRegionIterator.h"
00026 #include "itkImageRegionConstIterator.h"
00027 #include "itkListSample.h"
00028
00029 namespace itk {
00030 namespace Statistics {
00031
00039 template< class TImage >
00040 struct ImageJointDomainTraits
00041 {
00042 typedef ImageJointDomainTraits Self;
00043 typedef PixelTraits< typename TImage::PixelType > PixelTraitsType;
00044 typedef typename PixelTraitsType::ValueType RangeDomainMeasurementType;
00045 typedef typename TImage::IndexType::IndexValueType IndexValueType;
00046
00047 itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
00048 itkStaticConstMacro(Dimension,
00049 unsigned int,
00050 TImage::ImageDimension +
00051 PixelTraitsType::Dimension );
00052
00053 typedef float CoordinateRepType;
00054 typedef Point< CoordinateRepType, itkGetStaticConstMacro(ImageDimension) > PointType;
00055 typedef JoinTraits< RangeDomainMeasurementType, CoordinateRepType > JoinTraitsType;
00056 typedef typename JoinTraitsType::ValueType MeasurementType;
00057
00058 typedef FixedArray< MeasurementType, itkGetStaticConstMacro(Dimension) >
00059 MeasurementVectorType;
00060 };
00061
00062
00092 template < class TImage >
00093 class ITK_EXPORT JointDomainImageToListSampleAdaptor
00094 : public ListSample< typename ImageJointDomainTraits< TImage >::MeasurementVectorType >
00095 {
00096 public:
00097
00099 typedef JointDomainImageToListSampleAdaptor Self;
00100
00101 typedef ListSample <
00102 typename ImageJointDomainTraits< TImage >::MeasurementVectorType > Superclass;
00103
00104 typedef SmartPointer< Self > Pointer;
00105 typedef SmartPointer<const Self> ConstPointer;
00106
00107
00108 typedef ImageJointDomainTraits< TImage > ImageJointDomainTraitsType;
00109
00110 typedef typename ImageJointDomainTraitsType::MeasurementVectorType
00111 MeasurementVectorType;
00112
00113 typedef typename ImageJointDomainTraitsType::MeasurementType
00114 MeasurementType;
00115
00116 typedef typename ImageJointDomainTraitsType::RangeDomainMeasurementType
00117 RangeDomainMeasurementType;
00118
00119 typedef typename ImageJointDomainTraitsType::PointType PointType;
00120
00121 typedef typename ImageJointDomainTraitsType::CoordinateRepType
00122 CoordinateRepType;
00124 itkTypeMacro(JointDomainImageToListSampleAdaptor, ListSample);
00125
00127 itkNewMacro(Self);
00128
00130 itkStaticConstMacro(MeasurementVectorSize,
00131 unsigned int,
00132 ImageJointDomainTraitsType::Dimension);
00133
00134 itkSuperclassTraitMacro( MeasurementVectorSizeType )
00135
00136
00138 itkSuperclassTraitMacro( AbsoluteFrequencyType )
00139 itkSuperclassTraitMacro( TotalAbsoluteFrequencyType )
00140 itkSuperclassTraitMacro( InstanceIdentifier )
00141
00143 typedef TImage ImageType;
00144 typedef ImageRegionIterator< ImageType > ImageIteratorType;
00145 typedef ImageRegionConstIterator< ImageType > ImageConstIteratorType;
00146
00147 typedef typename ImageType::Pointer ImagePointer;
00148 typedef typename ImageType::ConstPointer ImageConstPointer;
00149 typedef typename ImageType::PixelType PixelType;
00150 typedef typename ImageType::PixelContainerConstPointer PixelContainerConstPointer;
00151 typedef typename ImageType::IndexType ImageIndexType;
00152 typedef typename ImageType::IndexType::IndexValueType ImageIndexValueType;
00153 typedef typename ImageType::SizeType ImageSizeType;
00154 typedef typename ImageType::RegionType ImageRegionType;
00155 typedef MeasurementVectorType ValueType;
00156
00158 void SetImage(const TImage* image);
00159
00161 const TImage* GetImage() const;
00162
00164 InstanceIdentifier Size() const;
00165
00167 AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const;
00168
00170 TotalAbsoluteFrequencyType GetTotalFrequency() const;
00171
00172 itkStaticConstMacro(RangeDomainDimension,
00173 unsigned int,
00174 itk::PixelTraits<
00175 typename TImage::PixelType >::Dimension);
00176
00177 typedef FixedArray< RangeDomainMeasurementType,
00178 itkGetStaticConstMacro( RangeDomainDimension ) >
00179 RangeDomainMeasurementVectorType;
00180
00181 typedef std::vector< InstanceIdentifier > InstanceIdentifierVectorType;
00182
00183 typedef FixedArray< float, itkGetStaticConstMacro(MeasurementVectorSize) >
00184 NormalizationFactorsType;
00185
00187 void SetNormalizationFactors(NormalizationFactorsType& factors);
00188
00191 const MeasurementVectorType & GetMeasurementVector( InstanceIdentifier id) const;
00192
00194 itkSetMacro( UsePixelContainer, bool );
00195 itkGetConstMacro( UsePixelContainer, bool );
00196 itkBooleanMacro( UsePixelContainer );
00198
00199
00200
00202 class ConstIterator
00203 {
00204 friend class JointDomainImageToListSampleAdaptor;
00205 public:
00206
00207 ConstIterator( const JointDomainImageToListSampleAdaptor * adaptor )
00208 {
00209 *this = adaptor->Begin();
00210 }
00211
00212 ConstIterator(const ConstIterator &iter)
00213 {
00214 m_InstanceIdentifier = iter.m_InstanceIdentifier;
00215 m_Adaptor = iter.m_Adaptor;
00216 }
00217
00218 ConstIterator& operator=( const ConstIterator & iter )
00219 {
00220 m_InstanceIdentifier = iter.m_InstanceIdentifier;
00221 return *this;
00222 }
00223
00224 AbsoluteFrequencyType GetFrequency() const
00225 {
00226 return 1;
00227 }
00228
00229 const MeasurementVectorType & GetMeasurementVector() const
00230 {
00231 m_MeasurementVectorCache = m_Adaptor->GetMeasurementVector( m_InstanceIdentifier );
00232 return this->m_MeasurementVectorCache;
00233 }
00234
00235 InstanceIdentifier GetInstanceIdentifier() const
00236 {
00237 return m_InstanceIdentifier;
00238 }
00239
00240 ConstIterator& operator++()
00241 {
00242 ++m_InstanceIdentifier;
00243 return *this;
00244 }
00245
00246 bool operator!=(const ConstIterator &it)
00247 {
00248 return (m_InstanceIdentifier != it.m_InstanceIdentifier);
00249 }
00250
00251 bool operator==(const ConstIterator &it)
00252 {
00253 return (m_InstanceIdentifier == it.m_InstanceIdentifier);
00254 }
00255
00256 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
00257 protected:
00258 #endif
00259
00260 ConstIterator(
00261 const JointDomainImageToListSampleAdaptor * adaptor,
00262 InstanceIdentifier iid)
00263 {
00264 m_Adaptor = adaptor;
00265 m_InstanceIdentifier = iid;
00266 }
00267
00268
00269 ConstIterator();
00270
00271 private:
00272 mutable MeasurementVectorType m_MeasurementVectorCache;
00273 InstanceIdentifier m_InstanceIdentifier;
00274 const JointDomainImageToListSampleAdaptor * m_Adaptor;
00275 };
00276
00277 class Iterator : public ConstIterator
00278 {
00279
00280 friend class JointDomainImageToListSampleAdaptor;
00281
00282 public:
00283
00284 Iterator(Self * adaptor):ConstIterator(adaptor)
00285 {
00286 }
00287
00288 Iterator(const Iterator &iter):ConstIterator( iter )
00289 {
00290 }
00291
00292 Iterator& operator =(const Iterator & iter)
00293 {
00294 this->ConstIterator::operator=( iter );
00295 return *this;
00296 }
00297
00298 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
00299 protected:
00300 #endif
00301
00302
00303 Iterator();
00304 Iterator(const Self * adaptor);
00305 Iterator(const ConstIterator & it);
00306 ConstIterator& operator=(const ConstIterator& it);
00307 Iterator(
00308 const JointDomainImageToListSampleAdaptor * adaptor,
00309 InstanceIdentifier iid):ConstIterator( adaptor, iid )
00310 {
00311 }
00312
00313 private:
00314 };
00315
00316
00318 Iterator Begin()
00319 {
00320 Iterator iter(this, 0);
00321 return iter;
00322 }
00324
00326 Iterator End()
00327 {
00328 Iterator iter(this, m_Image->GetPixelContainer()->Size());
00329 return iter;
00330 }
00332
00334 ConstIterator Begin() const
00335 {
00336 ConstIterator iter(this, 0);
00337 return iter;
00338 }
00340
00342 ConstIterator End() const
00343 {
00344 ConstIterator iter(this, m_Image->GetPixelContainer()->Size());
00345 return iter;
00346 }
00348
00349
00350 protected:
00351 JointDomainImageToListSampleAdaptor();
00352 virtual ~JointDomainImageToListSampleAdaptor() {}
00353 void PrintSelf(std::ostream& os, Indent indent) const;
00354
00355 private:
00356 JointDomainImageToListSampleAdaptor(const Self&);
00357 void operator=(const Self&);
00358
00359 NormalizationFactorsType m_NormalizationFactors;
00360 mutable MeasurementVectorType m_TempVector;
00361 mutable PointType m_TempPoint;
00362 mutable ImageIndexType m_TempIndex;
00363 mutable RangeDomainMeasurementVectorType m_TempRangeVector;
00364 ImageConstPointer m_Image;
00365 bool m_UsePixelContainer;
00366
00367 PixelContainerConstPointer m_PixelContainer;
00368
00369 };
00370
00371 }
00372 }
00373
00374 #ifndef ITK_MANUAL_INSTANTIATION
00375 #include "itkJointDomainImageToListSampleAdaptor.txx"
00376 #endif
00377
00378 #endif
00379