DGtal  1.5.beta
ArrayImageIterator.h
1 
17 #pragma once
18 
29 #if defined(ArrayImageIterator_RECURSES)
30 #error Recursive header files inclusion detected in ArrayImageIterator.h
31 #else // defined(ArrayImageIterator_RECURSES)
33 #define ArrayImageIterator_RECURSES
34 
35 #if !defined ArrayImageIterator_h
37 #define ArrayImageIterator_h
38 
40 // Inclusions
41 #include <ostream>
42 #include <type_traits>
43 #include <boost/iterator/iterator_facade.hpp>
44 #include <DGtal/kernel/domains/Linearizer.h>
46 
47 namespace DGtal
48 {
49 
51 
72  template <
73  typename TIterableClass
74  >
76  : public boost::iterator_facade <
77  ArrayImageIterator<TIterableClass>,
78  typename TIterableClass::Value,
79  std::random_access_iterator_tag,
80  decltype( ((new TIterableClass))->dereference( TIterableClass::Point::diagonal(0), typename TIterableClass::Point::Coordinate(0) ) )
81  >
82  {
83  // ----------------------- Standard services ------------------------------
84  public:
85 
86  // Typedefs
88  using IterableClass = TIterableClass;
89  using Domain = typename IterableClass::Domain;
90  using Point = typename Domain::Point;
92  using Reference = decltype( ((new IterableClass)->dereference( Point::diagonal(0), typename Point::Coordinate(0) ) ));
93 
96 
104  ArrayImageIterator( IterableClass* anIterableClassPtr, Domain const& aFullDomain, Domain const& aViewDomain, Point const& aPoint );
105 
112  ArrayImageIterator( IterableClass* anIterableClassPtr, Domain const& aFullDomain, Domain const& aViewDomain );
113 
119  ArrayImageIterator( IterableClass* anIterableClassPtr, Domain const& aFullDomain );
120 
127  ArrayImageIterator( IterableClass* anIterableClassPtr, Domain const& aFullDomain, Domain const& aViewDomain, bool /* last */ );
128 
134  ArrayImageIterator( IterableClass* anIterableClassPtr, Domain const& aFullDomain, bool /* last */ );
135 
140  template < typename TOtherIterableClass >
143  typename std::enable_if< std::is_convertible<TOtherIterableClass*, IterableClass*>::value >::type* = 0
144  );
145 
150  template < typename TOtherIterableClass >
153  typename std::enable_if< std::is_convertible<TOtherIterableClass*, IterableClass*>::value >::type* = 0
154  ) noexcept;
155 
158 
165  template < typename TOtherIterableClass >
166  typename std::enable_if<
167  std::is_convertible<TOtherIterableClass*, IterableClass*>::value,
168  Self& >::type
169  operator= (
170  ArrayImageIterator<TOtherIterableClass> const& other
171  );
172 
179  template < typename TOtherIterableClass >
180  typename std::enable_if<
181  std::is_convertible<TOtherIterableClass*, IterableClass*>::value,
182  Self& >::type
183  operator= (
184  ArrayImageIterator<TOtherIterableClass> && other
185  );
186 
187 
188  // ----------------------- Interface --------------------------------------
189  public:
190 
194  inline Point const& getPoint() const noexcept;
195 
200  inline
201  std::ptrdiff_t distance_to( Point const& aPoint ) const noexcept;
202 
207  void selfDisplay ( std::ostream & out ) const;
208 
213  bool isValid() const;
214 
215  // ------------------------- Private Datas --------------------------------
216  private:
223  typename Point::Coordinate myFullIndex;
224 
225  // ------------------------- Hidden services ------------------------------
226  private:
227 
228  // Friendship
229  template <class> friend class ArrayImageIterator;
230  friend class boost::iterator_core_access;
231 
233  void increment();
234 
236  void decrement();
237 
241  inline
242  bool equal( Self const& other ) const;
243 
245  inline
247 
252  inline
253  std::ptrdiff_t distance_to( Self const& other ) const ;
254 
259  void advance( std::ptrdiff_t n );
260 
261  }; // end of class ArrayImageIterator
262 
263 
270  template <typename TIterableClass>
271  std::ostream&
272  operator<< ( std::ostream & out, const ArrayImageIterator<TIterableClass> & object );
273 
274 } // namespace DGtal
275 
276 
278 // Includes inline functions.
279 #include "DGtal/images/ArrayImageIterator.ih"
280 
281 // //
283 
284 #endif // !defined ArrayImageIterator_h
285 
286 #undef ArrayImageIterator_RECURSES
287 #endif // else defined(ArrayImageIterator_RECURSES)
288 
Aim: Random access iterator over an image given his definition domain and viewable domain.
Point myViewExtent
Extent of the viewable domain.
ArrayImageIterator()
Default constructor.
bool equal(Self const &other) const
void selfDisplay(std::ostream &out) const
void decrement()
Decrement of one step.
Point const & getPoint() const noexcept
TIterableClass IterableClass
Iterable class type.
Point::Coordinate myFullIndex
Linearized index of the current point.
IterableClass * myIterableClassPtr
Pointer to the iterable class.
ArrayImageIterator(IterableClass *anIterableClassPtr, Domain const &aFullDomain, bool)
ArrayImageIterator(IterableClass *anIterableClassPtr, Domain const &aFullDomain, Domain const &aViewDomain, Point const &aPoint)
ArrayImageIterator(IterableClass *anIterableClassPtr, Domain const &aFullDomain)
std::ptrdiff_t distance_to(Point const &aPoint) const noexcept
ArrayImageIterator(IterableClass *anIterableClassPtr, Domain const &aFullDomain, Domain const &aViewDomain)
void increment()
Increment of one step.
typename Domain::Point Point
Point type.
Domain myFullDomain
Full domain of the image.
ArrayImageIterator(ArrayImageIterator< TOtherIterableClass > &&other, typename std::enable_if< std::is_convertible< TOtherIterableClass *, IterableClass * >::value >::type *=0) noexcept
ArrayImageIterator(IterableClass *anIterableClassPtr, Domain const &aFullDomain, Domain const &aViewDomain, bool)
Point myFullExtent
Extent of the full domain.
Reference dereference() const
Dereference.
Point myPoint
Current point where the iterator point to.
decltype(((new IterableClass) ->dereference(Point::diagonal(0), typename Point::Coordinate(0)))) Reference
Return type when dereferencing this iterator.
void advance(std::ptrdiff_t n)
Domain myViewDomain
Iterable (viewable) domain of the image.
typename IterableClass::Domain Domain
Domain type.
ArrayImageIterator(ArrayImageIterator< TOtherIterableClass > const &other, typename std::enable_if< std::is_convertible< TOtherIterableClass *, IterableClass * >::value >::type *=0)
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: Boost.dox:28
Aim: Linearization and de-linearization interface for domains.
Definition: Linearizer.h:78
MyPointD Point
Definition: testClone2.cpp:383
const Point aPoint(3, 4)
HyperRectDomain< Space > Domain