DGtal  0.9.2
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)
32 
33 #define ArrayImageIterator_RECURSES
34 
35 #if !defined ArrayImageIterator_h
36 
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( ((TIterableClass*)nullptr)->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( ((IterableClass*)nullptr)->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
246  Reference dereference() const;
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 
Domain myFullDomain
Full domain of the image.
Domain myViewDomain
Iterable (viewable) domain of the image.
Definition: Boost.dox:28
Reference dereference() const
Dereference.
Point myFullExtent
Extent of the full domain.
void decrement()
Decrement of one step.
TIterableClass IterableClass
Iterable class type.
typename Domain::Point Point
Point type.
Aim: Random access iterator over an image given his definition domain and viewable domain...
Point myViewExtent
Extent of the viewable domain.
STL namespace.
decltype(((IterableClass *) nullptr) ->dereference(Point::diagonal(0), typename Point::Coordinate(0))) Reference
Return type when dereferencing this iterator.
typename IterableClass::Domain Domain
Domain type.
void selfDisplay(std::ostream &out) const
std::ptrdiff_t distance_to(Point const &aPoint) const noexcept
IterableClass * myIterableClassPtr
Pointer to the iterable class.
bool equal(Self const &other) const
Point const & getPoint() const noexcept
Aim: Linearization and de-linearization interface for domains.
Definition: Linearizer.h:78
DGtal is the top-level namespace which contains all DGtal functions and types.
void advance(std::ptrdiff_t n)
Point::Coordinate myFullIndex
Linearized index of the current point.
ArrayImageIterator()
Default constructor.
void increment()
Increment of one step.
Point myPoint
Current point where the iterator point to.