ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkJointDomainImageToListSampleAdaptor_h 00019 #define __itkJointDomainImageToListSampleAdaptor_h 00020 00021 #include "itkPoint.h" 00022 #include "itkPixelTraits.h" 00023 #include "itkImageRegionConstIteratorWithIndex.h" 00024 #include "itkImageRegionIterator.h" 00025 #include "itkListSample.h" 00026 00027 namespace itk 00028 { 00029 namespace Statistics 00030 { 00039 template< class TImage > 00040 struct ImageJointDomainTraits { 00041 typedef ImageJointDomainTraits Self; 00042 typedef PixelTraits< typename TImage::PixelType > PixelTraitsType; 00043 typedef typename PixelTraitsType::ValueType RangeDomainMeasurementType; 00044 00045 itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension); 00046 itkStaticConstMacro(Dimension, 00047 unsigned int, 00048 TImage::ImageDimension 00049 + PixelTraitsType::Dimension); 00050 00051 typedef float CoordinateRepType; 00052 typedef Point< CoordinateRepType, itkGetStaticConstMacro(ImageDimension) > PointType; 00053 typedef JoinTraits< RangeDomainMeasurementType, CoordinateRepType > JoinTraitsType; 00054 typedef typename JoinTraitsType::ValueType MeasurementType; 00055 00056 typedef FixedArray< MeasurementType, itkGetStaticConstMacro(Dimension) > 00057 MeasurementVectorType; 00058 }; // end of ImageJointDomainTraits 00059 00090 template< class TImage > 00091 class ITK_EXPORT JointDomainImageToListSampleAdaptor: 00092 public ListSample< typename ImageJointDomainTraits< TImage >::MeasurementVectorType > 00093 { 00094 public: 00095 00097 typedef JointDomainImageToListSampleAdaptor Self; 00098 00099 typedef ListSample< 00100 typename ImageJointDomainTraits< TImage >::MeasurementVectorType > Superclass; 00101 00102 typedef SmartPointer< Self > Pointer; 00103 typedef SmartPointer< const Self > ConstPointer; 00104 00105 typedef ImageJointDomainTraits< TImage > ImageJointDomainTraitsType; 00106 00107 typedef typename ImageJointDomainTraitsType::MeasurementVectorType MeasurementVectorType; 00108 typedef typename ImageJointDomainTraitsType::MeasurementType MeasurementType; 00109 typedef typename ImageJointDomainTraitsType::RangeDomainMeasurementType RangeDomainMeasurementType; 00110 typedef typename ImageJointDomainTraitsType::PointType PointType; 00111 typedef typename ImageJointDomainTraitsType::CoordinateRepType CoordinateRepType; 00112 00114 itkTypeMacro(JointDomainImageToListSampleAdaptor, ListSample); 00115 00117 itkNewMacro(Self); 00118 00120 itkStaticConstMacro(MeasurementVectorSize, unsigned int, 00121 ImageJointDomainTraitsType::Dimension); 00122 00123 typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType; 00124 00127 typedef typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType; 00128 typedef typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType; 00129 typedef typename Superclass::InstanceIdentifier InstanceIdentifier; 00130 00132 typedef TImage ImageType; 00133 typedef ImageRegionIterator< ImageType > ImageIteratorType; 00134 typedef ImageRegionConstIterator< ImageType > ImageConstIteratorType; 00135 00136 typedef typename ImageType::Pointer ImagePointer; 00137 typedef typename ImageType::ConstPointer ImageConstPointer; 00138 typedef typename ImageType::PixelType PixelType; 00139 typedef typename ImageType::PixelContainerConstPointer PixelContainerConstPointer; 00140 typedef typename ImageType::IndexType ImageIndexType; 00141 typedef typename ImageType::SizeType ImageSizeType; 00142 typedef typename ImageType::RegionType ImageRegionType; 00143 typedef MeasurementVectorType ValueType; 00144 00146 void SetImage(const TImage *image); 00147 00149 const TImage * GetImage() const; 00150 00152 InstanceIdentifier Size() const; 00153 00155 AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const; 00156 00158 TotalAbsoluteFrequencyType GetTotalFrequency() const; 00159 00160 itkStaticConstMacro(RangeDomainDimension, unsigned int, 00161 itk::PixelTraits< typename TImage::PixelType >::Dimension); 00162 00163 typedef FixedArray< RangeDomainMeasurementType, 00164 itkGetStaticConstMacro(RangeDomainDimension) > RangeDomainMeasurementVectorType; 00165 00166 typedef std::vector< InstanceIdentifier > InstanceIdentifierVectorType; 00167 typedef FixedArray< float, itkGetStaticConstMacro(MeasurementVectorSize) > NormalizationFactorsType; 00168 00170 void SetNormalizationFactors(NormalizationFactorsType & factors); 00171 00174 const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const; 00175 00177 itkSetMacro(UsePixelContainer, bool); 00178 itkGetConstMacro(UsePixelContainer, bool); 00179 itkBooleanMacro(UsePixelContainer); 00181 00182 // void PrintSelf(std::ostream& os, Indent indent) const; 00183 00188 class ConstIterator 00189 { 00190 friend class JointDomainImageToListSampleAdaptor; 00191 public: 00192 00193 ConstIterator(const JointDomainImageToListSampleAdaptor *adaptor) 00194 { 00195 *this = adaptor->Begin(); 00196 } 00197 00198 ConstIterator(const ConstIterator & iter) 00199 { 00200 m_InstanceIdentifier = iter.m_InstanceIdentifier; 00201 m_Adaptor = iter.m_Adaptor; 00202 } 00203 00204 ConstIterator & operator=(const ConstIterator & iter) 00205 { 00206 m_InstanceIdentifier = iter.m_InstanceIdentifier; 00207 return *this; 00208 } 00209 00210 AbsoluteFrequencyType GetFrequency() const 00211 { 00212 return 1; 00213 } 00214 00215 const MeasurementVectorType & GetMeasurementVector() const 00216 { 00217 m_MeasurementVectorCache = m_Adaptor->GetMeasurementVector(m_InstanceIdentifier); 00218 return this->m_MeasurementVectorCache; 00219 } 00220 00221 InstanceIdentifier GetInstanceIdentifier() const 00222 { 00223 return m_InstanceIdentifier; 00224 } 00225 00226 ConstIterator & operator++() 00227 { 00228 ++m_InstanceIdentifier; 00229 return *this; 00230 } 00231 00232 bool operator!=(const ConstIterator & it) 00233 { 00234 return ( m_InstanceIdentifier != it.m_InstanceIdentifier ); 00235 } 00236 00237 bool operator==(const ConstIterator & it) 00238 { 00239 return ( m_InstanceIdentifier == it.m_InstanceIdentifier ); 00240 } 00241 00242 protected: 00243 // This method should only be available to the ListSample class 00244 ConstIterator( 00245 const JointDomainImageToListSampleAdaptor *adaptor, 00246 InstanceIdentifier iid) 00247 { 00248 m_Adaptor = adaptor; 00249 m_InstanceIdentifier = iid; 00250 } 00251 00252 // This method is purposely not implemented 00253 ConstIterator(); 00254 private: 00255 mutable MeasurementVectorType m_MeasurementVectorCache; 00256 InstanceIdentifier m_InstanceIdentifier; 00257 const JointDomainImageToListSampleAdaptor *m_Adaptor; 00258 }; 00259 00264 class Iterator:public ConstIterator 00265 { 00266 friend class JointDomainImageToListSampleAdaptor; 00267 public: 00268 00269 Iterator(Self *adaptor):ConstIterator(adaptor) 00270 {} 00271 00272 Iterator(const Iterator & iter):ConstIterator(iter) 00273 {} 00274 00275 Iterator & operator=(const Iterator & iter) 00276 { 00277 this->ConstIterator::operator=(iter); 00278 return *this; 00279 } 00280 00281 protected: 00282 // To ensure const-correctness these method must not be in the public API. 00283 // The are purposly not implemented, since they should never be called. 00284 Iterator(); 00285 Iterator(const Self *adaptor); 00286 Iterator(const ConstIterator & it); 00287 ConstIterator & operator=(const ConstIterator & it); 00288 00289 Iterator( 00290 const JointDomainImageToListSampleAdaptor *adaptor, 00291 InstanceIdentifier iid):ConstIterator(adaptor, iid) 00292 {} 00293 00294 private: 00295 }; 00296 00298 Iterator Begin() 00299 { 00300 Iterator iter(this, 0); 00301 00302 return iter; 00303 } 00304 00306 Iterator End() 00307 { 00308 Iterator iter( this, m_Image->GetPixelContainer()->Size() ); 00309 00310 return iter; 00311 } 00312 00314 ConstIterator Begin() const 00315 { 00316 ConstIterator iter(this, 0); 00317 00318 return iter; 00319 } 00320 00322 ConstIterator End() const 00323 { 00324 ConstIterator iter( this, m_Image->GetPixelContainer()->Size() ); 00325 00326 return iter; 00327 } 00328 00329 protected: 00330 JointDomainImageToListSampleAdaptor(); 00331 virtual ~JointDomainImageToListSampleAdaptor() {} 00332 void PrintSelf(std::ostream & os, Indent indent) const; 00333 00334 private: 00335 JointDomainImageToListSampleAdaptor(const Self &); //purposely not implemented 00336 void operator=(const Self &); //purposely not implemented 00337 00338 NormalizationFactorsType m_NormalizationFactors; 00339 mutable MeasurementVectorType m_TempVector; 00340 mutable PointType m_TempPoint; 00341 mutable ImageIndexType m_TempIndex; 00342 mutable RangeDomainMeasurementVectorType m_TempRangeVector; 00343 ImageConstPointer m_Image; 00344 bool m_UsePixelContainer; 00345 00346 PixelContainerConstPointer m_PixelContainer; 00347 }; // end of class JointDomainImageToListSampleAdaptor 00348 } // end of namespace Statistics 00349 } // end of namespace itk 00350 00351 #ifndef ITK_MANUAL_INSTANTIATION 00352 #include "itkJointDomainImageToListSampleAdaptor.hxx" 00353 #endif 00354 00355 #endif 00356