ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkJointDomainImageToListSampleAdaptor.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkJointDomainImageToListSampleAdaptor_h
19 #define itkJointDomainImageToListSampleAdaptor_h
20 
21 #include "itkPoint.h"
22 #include "itkPixelTraits.h"
24 #include "itkImageRegionIterator.h"
25 #include "itkListSample.h"
26 
27 namespace itk
28 {
29 namespace Statistics
30 {
39 template< typename TImage >
44 
45  itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
46  itkStaticConstMacro(Dimension,
47  unsigned int,
48  TImage::ImageDimension
50 
51  typedef float CoordinateRepType;
55 
58 }; // end of ImageJointDomainTraits
59 
90 template< typename TImage >
91 class ITK_TEMPLATE_EXPORT JointDomainImageToListSampleAdaptor:
92  public ListSample< typename ImageJointDomainTraits< TImage >::MeasurementVectorType >
93 {
94 public:
95 
98 
99  typedef ListSample<
101 
104 
106 
112 
115 
117  itkNewMacro(Self);
118 
120  itkStaticConstMacro(MeasurementVectorSize, unsigned int,
122 
123  typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
124 
127  typedef typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType;
128  typedef typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType;
129  typedef typename Superclass::InstanceIdentifier InstanceIdentifier;
130 
132  typedef TImage ImageType;
135 
136  typedef typename ImageType::Pointer ImagePointer;
137  typedef typename ImageType::ConstPointer ImageConstPointer;
138  typedef typename ImageType::PixelType PixelType;
139  typedef typename ImageType::PixelContainerConstPointer PixelContainerConstPointer;
142  typedef typename ImageType::RegionType ImageRegionType;
144 
146  void SetImage(const TImage *image);
147 
149  const TImage * GetImage() const;
150 
152  InstanceIdentifier Size() const ITK_OVERRIDE;
153 
155  AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const ITK_OVERRIDE;
156 
158  TotalAbsoluteFrequencyType GetTotalFrequency() const ITK_OVERRIDE;
159 
160  itkStaticConstMacro(RangeDomainDimension, unsigned int,
161  itk::PixelTraits< typename TImage::PixelType >::Dimension);
162 
164  itkGetStaticConstMacro(RangeDomainDimension) > RangeDomainMeasurementVectorType;
165 
167  typedef FixedArray< float, itkGetStaticConstMacro(MeasurementVectorSize) > NormalizationFactorsType;
168 
170  void SetNormalizationFactors(NormalizationFactorsType & factors);
171 
174  const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const ITK_OVERRIDE;
175 
177  itkSetMacro(UsePixelContainer, bool);
178  itkGetConstMacro(UsePixelContainer, bool);
179  itkBooleanMacro(UsePixelContainer);
181 
182  // void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
183 
189  {
191 
192 public:
193 
195  {
196  *this = adaptor->Begin();
197  }
198 
199  ConstIterator(const ConstIterator & iter)
200  {
201  m_InstanceIdentifier = iter.m_InstanceIdentifier;
202  m_Adaptor = iter.m_Adaptor;
203  }
204 
205  ConstIterator & operator=(const ConstIterator & iter)
206  {
207  m_InstanceIdentifier = iter.m_InstanceIdentifier;
208  return *this;
209  }
210 
212  {
213  return 1;
214  }
215 
217  {
218  m_MeasurementVectorCache = m_Adaptor->GetMeasurementVector(m_InstanceIdentifier);
219  return this->m_MeasurementVectorCache;
220  }
221 
223  {
224  return m_InstanceIdentifier;
225  }
226 
227  ConstIterator & operator++()
228  {
229  ++m_InstanceIdentifier;
230  return *this;
231  }
232 
233  bool operator!=(const ConstIterator & it)
234  {
235  return ( m_InstanceIdentifier != it.m_InstanceIdentifier );
236  }
237 
238  bool operator==(const ConstIterator & it)
239  {
240  return ( m_InstanceIdentifier == it.m_InstanceIdentifier );
241  }
242 
243 protected:
244  // This method should only be available to the ListSample class
247  InstanceIdentifier iid)
248  {
249  m_Adaptor = adaptor;
250  m_InstanceIdentifier = iid;
251  }
252 
253 private:
254  ConstIterator() ITK_DELETED_FUNCTION;
255  mutable MeasurementVectorType m_MeasurementVectorCache;
256  InstanceIdentifier m_InstanceIdentifier;
258  };
259 
264  class Iterator:public ConstIterator
265  {
267 
268 public:
269 
270  Iterator(Self *adaptor):ConstIterator(adaptor)
271  {}
272 
273  Iterator(const Iterator & iter):ConstIterator(iter)
274  {}
275 
276  Iterator & operator=(const Iterator & iter)
277  {
278  this->ConstIterator::operator=(iter);
279  return *this;
280  }
281 
282 protected:
285  InstanceIdentifier iid):ConstIterator(adaptor, iid)
286  {}
287 
288 private:
289  // To ensure const-correctness these method must not be in the public API.
290  // The are purposly not implemented, since they should never be called.
291  Iterator() ITK_DELETED_FUNCTION;
292  Iterator(const Self *adaptor) ITK_DELETED_FUNCTION;
293  Iterator(const ConstIterator & it) ITK_DELETED_FUNCTION;
294  ConstIterator & operator=(const ConstIterator & it) ITK_DELETED_FUNCTION;
295 
296  };
297 
299  Iterator Begin()
300  {
301  Iterator iter(this, 0);
302 
303  return iter;
304  }
305 
308  {
309  Iterator iter( this, m_Image->GetPixelContainer()->Size() );
310 
311  return iter;
312  }
313 
315  ConstIterator Begin() const
316  {
317  ConstIterator iter(this, 0);
318 
319  return iter;
320  }
321 
323  ConstIterator End() const
324  {
325  ConstIterator iter( this, m_Image->GetPixelContainer()->Size() );
326 
327  return iter;
328  }
329 
330 protected:
332  virtual ~JointDomainImageToListSampleAdaptor() ITK_OVERRIDE {}
333  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
334 
335 private:
336  ITK_DISALLOW_COPY_AND_ASSIGN(JointDomainImageToListSampleAdaptor);
337 
338  NormalizationFactorsType m_NormalizationFactors;
342  mutable RangeDomainMeasurementVectorType m_TempRangeVector;
345 
347 }; // end of class JointDomainImageToListSampleAdaptor
348 } // end of namespace Statistics
349 } // end of namespace itk
350 
351 #ifndef ITK_MANUAL_INSTANTIATION
352 #include "itkJointDomainImageToListSampleAdaptor.hxx"
353 #endif
354 
355 #endif
Point< CoordinateRepType, itkGetStaticConstMacro(ImageDimension) > PointType
TPixelType::ValueType ValueType
Represent the size (bounds) of a n-dimensional image.
Definition: itkSize.h:52
JoinTraits< RangeDomainMeasurementType, CoordinateRepType > JoinTraitsType
ImageJointDomainTraitsType::MeasurementVectorType MeasurementVectorType
ImageJointDomainTraitsType::RangeDomainMeasurementType RangeDomainMeasurementType
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
Traits for a pixel that define the dimension and component type.
FixedArray< MeasurementType, itkGetStaticConstMacro(Dimension) > MeasurementVectorType
Trait to determine what datatype is needed if the specified pixel types are &quot;joined&quot; into a single ve...
Iterator(const JointDomainImageToListSampleAdaptor *adaptor, InstanceIdentifier iid)
ListSample< typename ImageJointDomainTraits< TImage >::MeasurementVectorType > Superclass
This adaptor returns measurement vectors composed of an image pixel&#39;s range domain value (pixel value...
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
Control indentation during Print() invocation.
Definition: itkIndent.h:49
PixelTraits< typename TImage::PixelType > PixelTraitsType
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
static const unsigned int Dimension
This class provides the type definition for the measurement vector in the joint domain (range domain ...
Base class for all data objects in ITK.
A multi-dimensional iterator templated over image type that walks a region of pixels.
ConstIterator(const JointDomainImageToListSampleAdaptor *adaptor, InstanceIdentifier iid)