DGtal  0.9.2
ImageContainerByITKImage.h
1 
17 #pragma once
18 
32 #if defined(ImageContainerByITKImage_RECURSES)
33 #error Recursive header files inclusion detected in ImageContainerByITKImage.h
34 #else // defined(ImageContainerByITKImage_RECURSES)
35 
36 #define ImageContainerByITKImage_RECURSES
37 
38 #if !defined ImageContainerByITKImage_h
39 
40 #define ImageContainerByITKImage_h
41 
43 // Inclusions
44 #include "DGtal/base/Common.h"
45 #include "DGtal/base/CLabel.h"
46 #include "DGtal/kernel/domains/CDomain.h"
47 #include "DGtal/kernel/domains/CDomain.h"
48 #include "DGtal/images/DefaultConstImageRange.h"
49 #include "DGtal/images/DefaultImageRange.h"
50 
51 #if defined(__GNUG__)
52 #pragma GCC diagnostic push
53 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
54 #endif
55 #if defined(__clang__)
56 #pragma clang diagnostic push
57 #pragma clang diagnostic ignored "-Wdocumentation"
58 #endif
59 #include <itkImage.h>
60 #include <itkImageRegionConstIterator.h>
61 #include <itkImageRegionIterator.h>
62 #include <iostream>
63 #if defined(__clang__)
64 #pragma clang diagnostic pop
65 #endif
66 #if defined(__GNUG__)
67 #endif
68 #pragma GCC diagnostic pop
69 
71 namespace DGtal
72 {
73 
75  // template class ImageContainerByITKImage
89  template <typename TDomain, typename TValue>
91  {
92  // ----------------------- Standard services ------------------------------
93  public:
94 
97 
98  typedef TValue Value;
99  typedef TDomain Domain;
101 
102  // static constants
103  static const typename Domain::Dimension dimension = Domain::dimension;
104 
105  typedef typename Domain::Point Point;
106  typedef typename Domain::Vector Vector;
107  typedef typename Domain::Dimension Dimension;
108  typedef typename Domain::Integer Integer;
109  typedef typename Domain::Size Size;
110  typedef Point Vertex;
111 
112  typedef typename itk::Image< TValue, dimension> ITKImage;
113  typedef typename ITKImage::Pointer ITKImagePointer;
114  typedef typename itk::ImageRegionConstIterator< ITKImage > ConstIterator;
115  typedef typename itk::ImageRegionIterator< ITKImage > Iterator;
116 
119 
125  ImageContainerByITKImage(const Domain& aDomain);
126 
132  ImageContainerByITKImage(const ITKImagePointer &aRef);
133 
141 
149 
154 
155  // ----------------------- Interface --------------------------------------
156  public:
157 
164  void updateDomain();
165 
170  ConstRange constRange() const
171  {
172  return ConstRange(*this);
173  }
174 
179  Range range()
180  {
181  return Range(*this);
182  }
183 
190  Value operator()(const Point &aPoint) const;
191 
198  Value operator()(const ConstIterator &it) const;
199 
206  Value operator()(const Iterator &it) const;
207 
214  void setValue(const Point &aPoint, const Value &aValue);
215 
222  void setValue(Iterator &it, const Value &V);
223 
224  // ------------------------- methods ------------------------------
225 
226 
230  const Domain& domain() const
231  {
232  return myDomain;
233  }
234 
238  inline
239  ITKImagePointer getITKImagePointer() const
240  {
241  return myITKImagePointer;
242  }
243 
244  // ------------------------- stream ------------------------------
245 
250  void selfDisplay ( std::ostream & out ) const;
251 
256  bool isValid() const;
257 
258  // ------------------------- Iterators ------------------------------
263  inline
264  ConstIterator begin() const
265  {
266  ConstIterator iter = ConstIterator(myITKImagePointer, myITKImagePointer->GetLargestPossibleRegion());
267  iter.GoToBegin();
268  return iter;
269  }
270 
275  inline
276  Iterator begin()
277  {
278  Iterator iter = Iterator(myITKImagePointer, myITKImagePointer->GetLargestPossibleRegion());
279  iter.GoToBegin();
280  return iter;
281  }
282 
287  inline
288  const ConstIterator end() const
289  {
290  ConstIterator iter = ConstIterator(myITKImagePointer, myITKImagePointer->GetLargestPossibleRegion());
291  iter.GoToEnd();
292  return iter;
293  }
294 
299  inline
300  Iterator end()
301  {
302  Iterator iter = Iterator(myITKImagePointer, myITKImagePointer->GetLargestPossibleRegion());
303  iter.GoToEnd();
304  return iter;
305  }
306 
307  // ------------------------- Private Datas --------------------------------
308  private:
309 
310  // ------------------------- Hidden services ------------------------------
311  protected:
312 
318 
319  // ------------------------- Internals ------------------------------------
320  private:
321 
322  ITKImagePointer myITKImagePointer;
323  Domain myDomain; // cached from myITKImagePointer region. updated when calling update().
324  }; // end of class ImageContainerByITKImage
325 
332  template <typename T, typename TV>
333  std::ostream&
334  operator<< ( std::ostream & out, const ImageContainerByITKImage<T, TV> & object );
335 
336 }
338 // Includes inline functions.
339 #include "DGtal/images/ImageContainerByITKImage.ih"
340 
341 //
343 
344 #endif // !defined ImageContainerByITKImage_h
345 
346 #undef ImageContainerByITKImage_RECURSES
347 #endif // else defined(ImageContainerByITKImage_RECURSES)
void selfDisplay(std::ostream &out) const
Aim: model of CConstBidirectionalRangeFromPoint that adapts the domain of an image in order to iterat...
Aim: Define the concept of DGtal labels. Models of CLabel can be default-constructible, assignable and equality comparable.
Definition: CLabel.h:91
ImageContainerByITKImage< TDomain, TValue > Self
Aim: model of CConstBidirectionalRangeFromPoint and CBidirectionalRangeWithWritableIteratorFromPoint ...
itk::ImageRegionIterator< ITKImage > Iterator
static const Domain::Dimension dimension
DefaultConstImageRange< Self > ConstRange
ITKImagePointer getITKImagePointer() const
ImageContainerByITKImage & operator=(const ImageContainerByITKImage &other)
Space::Dimension Dimension
Aim: This concept represents a digital domain, i.e. a non mutable subset of points of the given digit...
Definition: CDomain.h:129
Value operator()(const Point &aPoint) const
void setValue(const Point &aPoint, const Value &aValue)
itk::ImageRegionConstIterator< ITKImage > ConstIterator
BOOST_CONCEPT_ASSERT((concepts::CLabel< TValue >))
itk::Image< TValue, dimension > ITKImage
DGtal is the top-level namespace which contains all DGtal functions and types.
const ConstIterator end() const
Aim: implements a model of CImageContainer using a ITK Image.