37 #ifndef VIGRA_MULTI_HIERARCHICAL_ITERATOR_HXX
38 #define VIGRA_MULTI_HIERARCHICAL_ITERATOR_HXX
40 #include <sys/types.h>
41 #include "multi_fwd.hxx"
42 #include "iteratortags.hxx"
43 #include "multi_handle.hxx"
57 template <
unsigned int N,
60 class HierarchicalIterator
62 :
public HierarchicalIterator<N, HANDLES, DIMENSION-1>
67 typedef HierarchicalIterator<N, HANDLES, DIMENSION-1> base_type;
68 static const int level = DIMENSION;
69 typedef typename base_type::value_type value_type;
70 typedef typename base_type::reference reference;
71 typedef typename base_type::const_reference const_reference;
72 typedef typename base_type::pointer pointer;
73 typedef typename base_type::const_pointer const_pointer;
74 typedef typename base_type::difference_type difference_type;
75 typedef typename base_type::shape_type shape_type;
77 explicit HierarchicalIterator(HANDLES
const & handles = HANDLES())
83 this->handles_.template increment<level>();
88 this->handles_.template decrement<level>();
91 HierarchicalIterator operator++ (
int)
93 HierarchicalIterator ret = *
this;
98 HierarchicalIterator operator-- (
int)
100 HierarchicalIterator ret = *
this;
105 HierarchicalIterator &
operator+= (difference_type n)
107 this->handles_.addDim(level, n);
111 HierarchicalIterator &
operator+= (shape_type
const & d)
117 HierarchicalIterator &
operator-= (difference_type n)
119 this->handles_.addDim(level, -n);
129 HierarchicalIterator
operator+ (difference_type n)
const
131 return HierarchicalIterator(*
this) += n;
141 difference_type
operator- (HierarchicalIterator
const & d)
const
143 return this->point()[level] - d.point()[level];
146 HierarchicalIterator
operator- (difference_type n)
const
148 return HierarchicalIterator(*
this) -= n;
158 bool operator== (
const HierarchicalIterator &rhs)
const
160 return this->point()[level] == rhs.point()[level];
163 bool operator!= (
const HierarchicalIterator &rhs)
const
165 return this->point()[level] != rhs.point()[level];
168 bool operator< (
const HierarchicalIterator &rhs)
const
170 return this->point()[level] < rhs.point()[level];
173 bool operator<= (
const HierarchicalIterator &rhs)
const
175 return this->point()[level] <= rhs.point()[level];
178 bool operator> (
const HierarchicalIterator &rhs)
const
180 return this->point()[level] > rhs.point()[level];
183 bool operator>= (
const HierarchicalIterator &rhs)
const
185 return this->point()[level] >= rhs.point()[level];
188 base_type begin ()
const
193 base_type end ()
const
195 return base_type(*
this) += this->shape()[level-1] - this->point()[level-1];
198 HierarchicalIterator getEndIterator()
const
200 return HierarchicalIterator(*
this) += this->shape() - this->point();
211 HierarchicalIterator<N, HANDLES, K> &
218 HierarchicalIterator<N, HANDLES, K>
const &
227 template <
unsigned int N,
229 class HierarchicalIterator<N, HANDLES, 0>
232 static const int level = 0;
234 typedef CoupledHandleTraits<HANDLES> HandleTraits;
235 typedef typename HandleTraits::value_type value_type;
236 typedef typename HandleTraits::reference reference;
237 typedef typename HandleTraits::const_reference const_reference;
238 typedef typename HandleTraits::pointer pointer;
239 typedef typename HandleTraits::const_pointer const_pointer;
241 typedef typename MultiArrayShape<N>::type shape_type;
242 typedef HierarchicalIterator<N, HANDLES, 0> iterator;
243 typedef std::random_access_iterator_tag iterator_category;
249 explicit HierarchicalIterator(HANDLES
const & handles = HANDLES())
255 handles_.template increment<level>();
260 handles_.template decrement<level>();
263 HierarchicalIterator operator++ (
int)
265 HierarchicalIterator ret = *
this;
270 HierarchicalIterator operator-- (
int)
272 HierarchicalIterator ret = *
this;
277 HierarchicalIterator &
operator+= (difference_type n)
279 handles_.addDim(level, n);
283 HierarchicalIterator &
operator+= (shape_type
const & d)
286 handles_.scanOrderIndex_ += detail::CoordinateToScanOrder<N>::exec(shape(), d);
290 HierarchicalIterator &
operator-= (difference_type n)
292 handles_.addDim(level, -n);
302 HierarchicalIterator
operator+ (difference_type n)
const
304 return HierarchicalIterator(*
this) += n;
314 difference_type
operator- (HierarchicalIterator
const & d)
const
316 return point()[level] - d.point()[level];
319 HierarchicalIterator
operator- (difference_type n)
const
321 return HierarchicalIterator(*
this) -= n;
341 reference operator* ()
343 return HandleTraits::dereference(handles_);
346 const_reference operator* ()
const
348 return HandleTraits::dereference(handles_);
351 template <
unsigned int TARGET_INDEX>
352 typename CoupledHandleCast<TARGET_INDEX, HANDLES>::reference
355 return handles_.template get<TARGET_INDEX>();
358 template <
unsigned int TARGET_INDEX>
359 typename CoupledHandleCast<TARGET_INDEX, HANDLES>::const_reference
362 return handles_.template get<TARGET_INDEX>();
367 return &HandleTraits::dereference(handles_);
370 const_pointer operator->()
const
372 return &HandleTraits::dereference(handles_);
375 bool operator== (
const HierarchicalIterator &rhs)
const
377 return point()[level] == rhs.point()[level];
380 bool operator!= (
const HierarchicalIterator &rhs)
const
382 return point()[level] != rhs.point()[level];
385 bool operator< (
const HierarchicalIterator &rhs)
const
387 return point()[level] < rhs.point()[level];
390 bool operator<= (
const HierarchicalIterator &rhs)
const
392 return point()[level] <= rhs.point()[level];
395 bool operator> (
const HierarchicalIterator &rhs)
const
397 return point()[level] > rhs.point()[level];
400 bool operator>= (
const HierarchicalIterator &rhs)
const
402 return point()[level] >= rhs.point()[level];
413 HierarchicalIterator getEndIterator()
const
415 return HierarchicalIterator(*
this) += shape() - point();
418 shape_type
const & point()
const
420 return handles_.point();
423 shape_type
const & shape()
const
425 return handles_.shape();
428 difference_type scanOrderIndex()
const
430 return handles_.scanOrderIndex();
433 HANDLES
const & handles()
const
439 HierarchicalIterator<N, HANDLES, 0> &
446 HierarchicalIterator<N, HANDLES, 0>
const &
463 template <
unsigned int N,
class T1=
void,
class T2=
void,
class T3=
void,
class T4=
void,
class T5=
void>
467 typedef typename CoupledHandleType<N, T1, T2, T3, T4, T5>::type
HandleType;
470 typedef HierarchicalIterator<HandleType::dimensions, HandleType>
IteratorType;
484 typename HierarchicalIteratorType<N>::type
487 typedef typename CoupledHandleType<N>::type P0;
488 typedef HierarchicalIterator<N, P0> IteratorType;
490 return IteratorType(P0(shape));
495 template <
unsigned int N1,
class T1,
class S1>
496 typename HierarchicalIteratorType<N1, T1>::type
499 typedef typename CoupledHandleType<N1, T1>::type P1;
500 typedef typename P1::base_type P0;
501 typedef HierarchicalIterator<P1::dimensions, P1> IteratorType;
503 return IteratorType(P1(m1,
509 template <
unsigned int N1,
class T1,
class S1,
510 unsigned int N2,
class T2,
class S2>
511 typename HierarchicalIteratorType<N1, T1, T2>::type
515 typedef typename CoupledHandleType<N1, T1, T2>::type P2;
516 typedef typename P2::base_type P1;
517 typedef typename P1::base_type P0;
518 typedef HierarchicalIterator<P2::dimensions, P2> IteratorType;
520 return IteratorType(P2(m2,
527 template <
unsigned int N1,
class T1,
class S1,
528 unsigned int N2,
class T2,
class S2,
529 unsigned int N3,
class T3,
class S3>
530 typename HierarchicalIteratorType<N1, T1, T2, T3>::type
535 typedef typename CoupledHandleType<N1, T1, T2, T3>::type P3;
536 typedef typename P3::base_type P2;
537 typedef typename P2::base_type P1;
538 typedef typename P1::base_type P0;
539 typedef HierarchicalIterator<P3::dimensions, P3> IteratorType;
541 return IteratorType(P3(m3,
549 template <
unsigned int N1,
class T1,
class S1,
550 unsigned int N2,
class T2,
class S2,
551 unsigned int N3,
class T3,
class S3,
552 unsigned int N4,
class T4,
class S4>
553 typename HierarchicalIteratorType<N1, T1, T2, T3, T4>::type
559 typedef typename CoupledHandleType<N1, T1, T2, T3, T4>::type P4;
560 typedef typename P4::base_type P3;
561 typedef typename P3::base_type P2;
562 typedef typename P2::base_type P1;
563 typedef typename P1::base_type P0;
564 typedef HierarchicalIterator<P4::dimensions, P4> IteratorType;
566 return IteratorType(P4(m4,
575 template <
unsigned int N1,
class T1,
class S1,
576 unsigned int N2,
class T2,
class S2,
577 unsigned int N3,
class T3,
class S3,
578 unsigned int N4,
class T4,
class S4,
579 unsigned int N5,
class T5,
class S5>
580 typename HierarchicalIteratorType<N1, T1, T2, T3, T4, T5>::type
587 typedef typename CoupledHandleType<N1, T1, T2, T3, T4, T5>::type P5;
588 typedef typename P5::base_type P4;
589 typedef typename P4::base_type P3;
590 typedef typename P3::base_type P2;
591 typedef typename P2::base_type P1;
592 typedef typename P1::base_type P0;
593 typedef HierarchicalIterator<P5::dimensions, P5> IteratorType;
595 return IteratorType(P5(m5,
600 P0(m1.
shape())))))));
604 template <
unsigned int N,
class A,
class B>
605 HierarchicalIterator<N, typename ZipCoupledHandles<A, B>::type>
606 zip(HierarchicalIterator<N, A>
const & a, HierarchicalIterator<N, B>
const & b)
608 vigra_precondition(a.shape() == b.shape() && a.scanOrderIndex() == b.scanOrderIndex(),
609 "zip(HierarchicalIterator): iterators must have identical shape and position.");
611 typedef typename ZipCoupledHandles<A, B>::type Handle;
612 typedef HierarchicalIterator<N, Handle> IteratorType;
613 return IteratorType(ZipCoupledHandles<A, B>::construct(a.handles(), b.handles()));
631 #endif // VIGRA_MULTI_HIERARCHICAL_ITERATOR_HXX
Diff2D operator-(Diff2D const &a, Diff2D const &b)
Definition: diff2d.hxx:711
const difference_type & shape() const
Definition: multi_array.hxx:1648
Diff2D operator+(Diff2D const &a, Diff2D const &b)
Definition: diff2d.hxx:739
std::ptrdiff_t MultiArrayIndex
Definition: multi_fwd.hxx:60
HierarchicalIteratorType< N >::type createHierarchicalIterator(TinyVector< MultiArrayIndex, N > const &shape)
Definition: multi_hierarchical_iterator.hxx:485
FFTWComplex< R > & operator-=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
subtract-assignment
Definition: fftw3.hxx:867
bool operator<=(FixedPoint< IntBits1, FracBits1 > l, FixedPoint< IntBits2, FracBits2 > r)
less or equal
Definition: fixedpoint.hxx:521
FFTWComplex< R > & operator+=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
add-assignment
Definition: fftw3.hxx:859
bool operator!=(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
not equal
Definition: fftw3.hxx:841
bool operator==(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
equal
Definition: fftw3.hxx:825
Class for fixed size vectors.This class contains an array of size SIZE of the specified VALUETYPE...
Definition: accessor.hxx:940
CoupledHandleType< N, T1, T2, T3, T4, T5 >::type HandleType
Definition: multi_hierarchical_iterator.hxx:467
HierarchicalIterator< HandleType::dimensions, HandleType > IteratorType
Definition: multi_hierarchical_iterator.hxx:470
bool operator<(FixedPoint< IntBits1, FracBits1 > l, FixedPoint< IntBits2, FracBits2 > r)
less than
Definition: fixedpoint.hxx:512
bool operator>=(FixedPoint< IntBits1, FracBits1 > l, FixedPoint< IntBits2, FracBits2 > r)
greater or equal
Definition: fixedpoint.hxx:539
Base class for, and view to, vigra::MultiArray.
Definition: multi_array.hxx:704
bool operator>(FixedPoint< IntBits1, FracBits1 > l, FixedPoint< IntBits2, FracBits2 > r)
greater
Definition: fixedpoint.hxx:530
Definition: multi_hierarchical_iterator.hxx:464