DGtal  1.3.beta
ImageContainerByITKImage.h
1 
17 #pragma once
18 
33 #if defined(ImageContainerByITKImage_RECURSES)
34 #error Recursive header files inclusion detected in ImageContainerByITKImage.h
35 #else // defined(ImageContainerByITKImage_RECURSES)
36 
37 #define ImageContainerByITKImage_RECURSES
38 
39 #if !defined ImageContainerByITKImage_h
40 
41 #define ImageContainerByITKImage_h
42 
44 // Inclusions
45 #include "DGtal/base/Common.h"
46 #include "DGtal/base/CLabel.h"
47 #include "DGtal/kernel/domains/CDomain.h"
48 #include "DGtal/kernel/domains/CDomain.h"
49 #include "DGtal/kernel/PointVector.h"
50 #include "DGtal/images/DefaultConstImageRange.h"
51 #include "DGtal/images/DefaultImageRange.h"
52 
53 #if defined(__GNUG__)
54 #pragma GCC diagnostic push
55 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
56 #pragma GCC diagnostic ignored "-Wpedantic"
57 #endif
58 #if defined(__clang__)
59 #pragma clang diagnostic push
60 #pragma clang diagnostic ignored "-Wdocumentation"
61 #endif
62 #include <itkImage.h>
63 #include <itkImageRegionConstIterator.h>
64 #include <itkImageRegionIterator.h>
65 #include <iostream>
66 #if defined(__clang__)
67 #pragma clang diagnostic pop
68 #endif
69 #if defined(__GNUG__)
70 #pragma GCC diagnostic pop
71 #endif
72 
74 namespace DGtal
75 {
76 
78  // template class ImageContainerByITKImage
92  template <typename TDomain, typename TValue>
94  {
95  // ----------------------- Standard services ------------------------------
96  public:
97 
100 
101  typedef TValue Value;
102  typedef TDomain Domain;
104 
105  // static constants
106  static const typename Domain::Dimension dimension = Domain::dimension;
107 
108  typedef typename Domain::Point Point;
109  typedef typename Domain::Vector Vector;
110  typedef typename Domain::Dimension Dimension;
111  typedef typename Domain::Integer Integer;
112  typedef typename Domain::Size Size;
113  typedef Point Vertex;
116 
117  typedef typename itk::Image< TValue, dimension> ITKImage;
118  typedef typename itk::ImageBase<dimension>::SpacingValueType ITKSpacingValueType;
120  typedef typename ITKImage::Pointer ITKImagePointer;
121  typedef typename ITKImage::PixelContainer Container;
122  typedef typename itk::ImageRegionConstIterator< ITKImage > ConstIterator;
123  typedef typename itk::ImageRegionIterator< ITKImage > Iterator;
124 
127 
133  ImageContainerByITKImage(const Domain& aDomain);
134 
141 
149 
157 
162 
163  // ----------------------- Interface --------------------------------------
164  public:
165 
176  void updateDomain(const Point & inputDomainShift = Point());
177 
183  {
184  return ConstRange(*this);
185  }
186 
192  {
193  return Range(*this);
194  }
195 
200  const Container & container() const
201  {
202  return *(myITKImagePointer->GetPixelContainer());
203  }
209  {
210  return *(myITKImagePointer->GetPixelContainer());
211  }
212 
219  Value operator()(const Point &domainPoint) const;
220 
227  Value operator()(const ConstIterator &it) const;
228 
235  Value operator()(const Iterator &it) const;
236 
243  void setValue(const Point &domainPoint, const Value &aValue);
244 
251  void setValue(Iterator &it, const Value &V);
252 
253  // ------------------------- methods ------------------------------
254 
255 
259  const Domain& domain() const
260  {
261  return myDomain;
262  }
263 
267  inline
269  {
270  return myITKImagePointer;
271  }
272 
273  inline
274  const Point & getDomainShift() const
275  {
276  return myDomainShift;
277  }
278 
279  // ------------------------- stream ------------------------------
280 
285  void selfDisplay ( std::ostream & out ) const;
286 
291  bool isValid() const;
292 
293  // ------------------------- Iterators ------------------------------
298  inline
300  {
301  ConstIterator iter = ConstIterator(myITKImagePointer, myITKImagePointer->GetLargestPossibleRegion());
302  iter.GoToBegin();
303  return iter;
304  }
305 
310  inline
312  {
313  Iterator iter = Iterator(myITKImagePointer, myITKImagePointer->GetLargestPossibleRegion());
314  iter.GoToBegin();
315  return iter;
316  }
317 
322  inline
323  const ConstIterator end() const
324  {
325  ConstIterator iter = ConstIterator(myITKImagePointer, myITKImagePointer->GetLargestPossibleRegion());
326  iter.GoToEnd();
327  return iter;
328  }
329 
334  inline
336  {
337  Iterator iter = Iterator(myITKImagePointer, myITKImagePointer->GetLargestPossibleRegion());
338  iter.GoToEnd();
339  return iter;
340  }
341 
342  // ----------------- DomainPoint to/from IndexPoint interface -------------
343 
352  inline Point getDomainPointFromIndex(const Point &indexPoint) const;
353 
354  inline Point getIndexFromDomainPoint(const Point &domainPoint) const;
355 
363  inline Point getDomainPointFromItkIndex(const typename ITKImage::IndexType &itkIndexPoint) const;
364 
365  inline typename ITKImage::IndexType getItkIndexFromDomainPoint(const Point &domainPoint) const;
366 
367 
368  // ------------------------- PhysicalPoint interface ----------------------
369 
381  inline PhysicalPoint getPhysicalPointFromDomainPoint(const Point &domainPoint) const;
382 
383  inline Point getDomainPointFromPhysicalPoint(const PhysicalPoint &physicalPoint) const;
384 
401  inline ImageSpacing getImageSpacing() const;
406  inline void setImageSpacing(const ImageSpacing& s) const;
407 
408  // ------------------------- Private Datas --------------------------------
409  private:
410 
411  // ------------------------- Hidden services ------------------------------
412  protected:
413 
419 
420  // ------------------------- Internals ------------------------------------
421  private:
422 
424  Domain myDomain; // cached from myITKImagePointer region. updated when calling update().
425 
443  }; // end of class ImageContainerByITKImage
444 
451  template <typename T, typename TV>
452  std::ostream&
453  operator<< ( std::ostream & out, const ImageContainerByITKImage<T, TV> & object );
454 
455 }
457 // Includes inline functions.
458 #include "DGtal/images/ImageContainerByITKImage.ih"
459 
460 //
462 
463 #endif // !defined ImageContainerByITKImage_h
464 
465 #undef ImageContainerByITKImage_RECURSES
466 #endif // else defined(ImageContainerByITKImage_RECURSES)
DGtal::ImageContainerByITKImage::Self
ImageContainerByITKImage< TDomain, TValue > Self
Definition: ImageContainerByITKImage.h:103
DGtal::ImageContainerByITKImage::selfDisplay
void selfDisplay(std::ostream &out) const
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::HyperRectDomain::Dimension
Space::Dimension Dimension
Definition: HyperRectDomain.h:116
DGtal::ImageContainerByITKImage::getUpperBoundAsPhysicalPoint
PhysicalPoint getUpperBoundAsPhysicalPoint() const
DGtal::ImageContainerByITKImage::getDomainShift
const Point & getDomainShift() const
Definition: ImageContainerByITKImage.h:274
DGtal::ImageContainerByITKImage::getDomainPointFromIndex
Point getDomainPointFromIndex(const Point &indexPoint) const
DGtal::ImageContainerByITKImage::updateDomain
void updateDomain(const Point &inputDomainShift=Point())
DGtal::ImageContainerByITKImage::end
Iterator end()
Definition: ImageContainerByITKImage.h:335
DGtal::ImageContainerByITKImage::getDomainPointFromItkIndex
Point getDomainPointFromItkIndex(const typename ITKImage::IndexType &itkIndexPoint) const
DGtal::ImageContainerByITKImage
Aim: implements a model of CImageContainer using a ITK Image.
Definition: ImageContainerByITKImage.h:93
DGtal::ImageContainerByITKImage::Container
ITKImage::PixelContainer Container
Definition: ImageContainerByITKImage.h:121
DGtal::ImageContainerByITKImage::myITKImagePointer
ITKImagePointer myITKImagePointer
Definition: ImageContainerByITKImage.h:423
DGtal::ImageContainerByITKImage::Vector
Domain::Vector Vector
Definition: ImageContainerByITKImage.h:109
DGtal::ImageContainerByITKImage::getITKImagePointer
ITKImagePointer getITKImagePointer() const
Definition: ImageContainerByITKImage.h:268
DGtal::ImageContainerByITKImage::container
Container & container()
Definition: ImageContainerByITKImage.h:208
DGtal::ImageContainerByITKImage::myDomain
Domain myDomain
Definition: ImageContainerByITKImage.h:424
DGtal::ImageContainerByITKImage::operator=
ImageContainerByITKImage & operator=(const ImageContainerByITKImage &other)
DGtal::ImageContainerByITKImage::ITKImagePointer
ITKImage::Pointer ITKImagePointer
Definition: ImageContainerByITKImage.h:120
DGtal::ImageContainerByITKImage::setImageSpacing
void setImageSpacing(const ImageSpacing &s) const
DGtal::ImageContainerByITKImage::Size
Domain::Size Size
Definition: ImageContainerByITKImage.h:112
DGtal::ImageContainerByITKImage::constRange
ConstRange constRange() const
Definition: ImageContainerByITKImage.h:182
DGtal::ImageContainerByITKImage::range
Range range()
Definition: ImageContainerByITKImage.h:191
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::HyperRectDomain< Space >::Size
Space::Size Size
Definition: HyperRectDomain.h:117
DGtal::DefaultConstImageRange
Aim: model of CConstBidirectionalRangeFromPoint that adapts the domain of an image in order to iterat...
Definition: DefaultConstImageRange.h:76
DGtal::ImageContainerByITKImage::myDomainShift
Point myDomainShift
Definition: ImageContainerByITKImage.h:442
DGtal::DefaultImageRange
Aim: model of CConstBidirectionalRangeFromPoint and CBidirectionalRangeWithWritableIteratorFromPoint ...
Definition: DefaultImageRange.h:76
DGtal::ImageContainerByITKImage::begin
Iterator begin()
Definition: ImageContainerByITKImage.h:311
DGtal::ImageContainerByITKImage::setValue
void setValue(const Point &domainPoint, const Value &aValue)
DGtal::concepts::CDomain
Aim: This concept represents a digital domain, i.e. a non mutable subset of points of the given digit...
Definition: CDomain.h:129
DGtal::ImageContainerByITKImage::begin
ConstIterator begin() const
Definition: ImageContainerByITKImage.h:299
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::ImageContainerByITKImage::RealPoint
PointVector< dimension, double > RealPoint
Definition: ImageContainerByITKImage.h:114
DGtal::ImageContainerByITKImage::Range
DefaultImageRange< Self > Range
Definition: ImageContainerByITKImage.h:126
DGtal::ImageContainerByITKImage::getImageSpacing
ImageSpacing getImageSpacing() const
DGtal::ImageContainerByITKImage::ImageContainerByITKImage
ImageContainerByITKImage()
DGtal::ImageContainerByITKImage::container
const Container & container() const
Definition: ImageContainerByITKImage.h:200
DGtal::ImageContainerByITKImage::~ImageContainerByITKImage
~ImageContainerByITKImage()
DGtal::ImageContainerByITKImage::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CLabel< TValue >))
DGtal::ImageContainerByITKImage::dimension
static const Domain::Dimension dimension
Definition: ImageContainerByITKImage.h:106
DGtal::ImageContainerByITKImage::ConstIterator
itk::ImageRegionConstIterator< ITKImage > ConstIterator
Definition: ImageContainerByITKImage.h:122
DGtal::ImageContainerByITKImage::getDomainPointFromPhysicalPoint
Point getDomainPointFromPhysicalPoint(const PhysicalPoint &physicalPoint) const
DGtal::concepts::CLabel
Aim: Define the concept of DGtal labels. Models of CLabel can be default-constructible,...
Definition: CLabel.h:91
DGtal::ImageContainerByITKImage::ConstRange
DefaultConstImageRange< Self > ConstRange
Definition: ImageContainerByITKImage.h:125
DGtal::ImageContainerByITKImage::ITKImage
itk::Image< TValue, dimension > ITKImage
Definition: ImageContainerByITKImage.h:117
DGtal::ImageContainerByITKImage::operator()
Value operator()(const Point &domainPoint) const
DGtal::ImageContainerByITKImage::getItkIndexFromDomainPoint
ITKImage::IndexType getItkIndexFromDomainPoint(const Point &domainPoint) const
DGtal::ImageContainerByITKImage::end
const ConstIterator end() const
Definition: ImageContainerByITKImage.h:323
DGtal::HyperRectDomain< Space >::Integer
Space::Integer Integer
Definition: HyperRectDomain.h:114
DGtal::PointVector< dim, Integer >
DGtal::ImageContainerByITKImage::Domain
TDomain Domain
Definition: ImageContainerByITKImage.h:102
DGtal::ImageContainerByITKImage::Iterator
itk::ImageRegionIterator< ITKImage > Iterator
Definition: ImageContainerByITKImage.h:123
DGtal::ImageContainerByITKImage::Value
TValue Value
Definition: ImageContainerByITKImage.h:101
DGtal::ImageContainerByITKImage::Dimension
Domain::Dimension Dimension
Definition: ImageContainerByITKImage.h:110
DGtal::ImageContainerByITKImage::getLowerBoundAsPhysicalPoint
PhysicalPoint getLowerBoundAsPhysicalPoint() const
DGtal::ImageContainerByITKImage::Integer
Domain::Integer Integer
Definition: ImageContainerByITKImage.h:111
DGtal::ImageContainerByITKImage::Vertex
Point Vertex
Definition: ImageContainerByITKImage.h:113
DGtal::ImageContainerByITKImage::isValid
bool isValid() const
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::ImageContainerByITKImage::ImageSpacing
RealPoint ImageSpacing
Definition: ImageContainerByITKImage.h:119
DGtal::ImageContainerByITKImage::Point
Domain::Point Point
Definition: ImageContainerByITKImage.h:108
DGtal::ImageContainerByITKImage::domain
const Domain & domain() const
Definition: ImageContainerByITKImage.h:259
DGtal::ImageContainerByITKImage::ITKSpacingValueType
itk::ImageBase< dimension >::SpacingValueType ITKSpacingValueType
Definition: ImageContainerByITKImage.h:118
DGtal::ImageContainerByITKImage::PhysicalPoint
RealPoint PhysicalPoint
Definition: ImageContainerByITKImage.h:115
DGtal::ImageContainerByITKImage::getIndexFromDomainPoint
Point getIndexFromDomainPoint(const Point &domainPoint) const
Value
double Value
Definition: testSimpleRandomAccessRangeFromPoint.cpp:38
DGtal::ImageContainerByITKImage::getPhysicalPointFromDomainPoint
PhysicalPoint getPhysicalPointFromDomainPoint(const Point &domainPoint) const