ITK  5.0.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  static constexpr unsigned int ImageDimension = TImage::ImageDimension;
46  static constexpr unsigned int Dimension = TImage::ImageDimension + PixelTraitsType::Dimension;
47 
48  using CoordinateRepType = float;
52 
53  using MeasurementVectorType =
55 }; // end of ImageJointDomainTraits
56 
87 template< typename TImage >
88 class ITK_TEMPLATE_EXPORT JointDomainImageToListSampleAdaptor:
89  public ListSample< typename ImageJointDomainTraits< TImage >::MeasurementVectorType >
90 {
91 public:
92  ITK_DISALLOW_COPY_AND_ASSIGN(JointDomainImageToListSampleAdaptor);
93 
96 
97  using Superclass = ListSample<
99 
102 
104 
110 
113 
115  itkNewMacro(Self);
116 
118  static constexpr unsigned int MeasurementVectorSize = ImageJointDomainTraitsType::Dimension;
119 
120  using MeasurementVectorSizeType = typename Superclass::MeasurementVectorSizeType;
121 
124  using AbsoluteFrequencyType = typename Superclass::AbsoluteFrequencyType;
125  using TotalAbsoluteFrequencyType = typename Superclass::TotalAbsoluteFrequencyType;
126  using InstanceIdentifier = typename Superclass::InstanceIdentifier;
127 
129  using ImageType = TImage;
132 
133  using ImagePointer = typename ImageType::Pointer;
134  using ImageConstPointer = typename ImageType::ConstPointer;
135  using PixelType = typename ImageType::PixelType;
136  using PixelContainerConstPointer = typename ImageType::PixelContainerConstPointer;
141 
143  void SetImage(const TImage *image);
144 
146  const TImage * GetImage() const;
147 
149  InstanceIdentifier Size() const override;
150 
152  AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const override;
153 
155  TotalAbsoluteFrequencyType GetTotalFrequency() const override;
156 
157  static constexpr unsigned int RangeDomainDimension = itk::PixelTraits< typename TImage::PixelType >::Dimension;
158 
160  Self::RangeDomainDimension >;
161 
162  using InstanceIdentifierVectorType = std::vector< InstanceIdentifier >;
164 
166  void SetNormalizationFactors(NormalizationFactorsType & factors);
167 
170  const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const override;
171 
173  itkSetMacro(UsePixelContainer, bool);
174  itkGetConstMacro(UsePixelContainer, bool);
175  itkBooleanMacro(UsePixelContainer);
177 
178  // void PrintSelf(std::ostream& os, Indent indent) const override;
179 
185  {
187 
188 public:
189 
191  {
192  *this = adaptor->Begin();
193  }
194 
196  {
197  m_InstanceIdentifier = iter.m_InstanceIdentifier;
198  m_Adaptor = iter.m_Adaptor;
199  }
200 
202  {
203  m_InstanceIdentifier = iter.m_InstanceIdentifier;
204  return *this;
205  }
206 
208  {
209  return 1;
210  }
211 
213  {
214  m_MeasurementVectorCache = m_Adaptor->GetMeasurementVector(m_InstanceIdentifier);
215  return this->m_MeasurementVectorCache;
216  }
217 
219  {
220  return m_InstanceIdentifier;
221  }
222 
224  {
225  ++m_InstanceIdentifier;
226  return *this;
227  }
228 
229  bool operator!=(const ConstIterator & it)
230  {
231  return ( m_InstanceIdentifier != it.m_InstanceIdentifier );
232  }
233 
234  bool operator==(const ConstIterator & it)
235  {
236  return ( m_InstanceIdentifier == it.m_InstanceIdentifier );
237  }
238 
239 protected:
240  // This method should only be available to the ListSample class
243  InstanceIdentifier iid)
244  {
245  m_Adaptor = adaptor;
246  m_InstanceIdentifier = iid;
247  }
248 
249 private:
250  ConstIterator() = delete;
254  };
255 
260  class Iterator:public ConstIterator
261  {
263 
264 public:
265 
266  Iterator(Self *adaptor):ConstIterator(adaptor)
267  {}
268 
269  Iterator(const Iterator & iter):ConstIterator(iter)
270  {}
271 
272  Iterator & operator=(const Iterator & iter)
273  {
274  this->ConstIterator::operator=(iter);
275  return *this;
276  }
277 
278 protected:
281  InstanceIdentifier iid):ConstIterator(adaptor, iid)
282  {}
283 
284 private:
285  // To ensure const-correctness these method must not be in the public API.
286  // The are purposly not implemented, since they should never be called.
287  Iterator() = delete;
288  Iterator(const Self *adaptor) = delete;
289  Iterator(const ConstIterator & it) = delete;
290  ConstIterator & operator=(const ConstIterator & it) = delete;
291 
292  };
293 
296  {
297  Iterator iter(this, 0);
298 
299  return iter;
300  }
301 
304  {
305  Iterator iter( this, m_Image->GetPixelContainer()->Size() );
306 
307  return iter;
308  }
309 
312  {
313  ConstIterator iter(this, 0);
314 
315  return iter;
316  }
317 
320  {
321  ConstIterator iter( this, m_Image->GetPixelContainer()->Size() );
322 
323  return iter;
324  }
325 
326 protected:
328  ~JointDomainImageToListSampleAdaptor() override = default;
329  void PrintSelf(std::ostream & os, Indent indent) const override;
330 
331 private:
339 
341 }; // end of class JointDomainImageToListSampleAdaptor
342 } // end of namespace Statistics
343 } // end of namespace itk
344 
345 #ifndef ITK_MANUAL_INSTANTIATION
346 #include "itkJointDomainImageToListSampleAdaptor.hxx"
347 #endif
348 
349 #endif
typename ImageJointDomainTraitsType::CoordinateRepType CoordinateRepType
typename PixelTraitsType::ValueType RangeDomainMeasurementType
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:51
Traits for a pixel that define the dimension and component type.
typename TPixelType::ValueType ValueType
typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
typename ImageType::PixelContainerConstPointer PixelContainerConstPointer
Trait to determine what datatype is needed if the specified pixel types are &quot;joined&quot; into a single ve...
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:68
static constexpr unsigned int Dimension
Iterator(const JointDomainImageToListSampleAdaptor *adaptor, InstanceIdentifier iid)
typename ImageJointDomainTraitsType::RangeDomainMeasurementType RangeDomainMeasurementType
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
typename ImageJointDomainTraitsType::MeasurementType MeasurementType
typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType
Base class for most ITK classes.
Definition: itkObject.h:60
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
typename ImageJointDomainTraitsType::MeasurementVectorType MeasurementVectorType
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)