DGtal 2.0.0
Loading...
Searching...
No Matches
DGtal::HyperRectDomain_Iterator< TPoint > Class Template Reference

Iterator for HyperRectDomain. More...

#include <DGtal/kernel/domains/HyperRectDomain_Iterator.h>

Inheritance diagram for DGtal::HyperRectDomain_Iterator< TPoint >:
[legend]

Public Types

using Point = TPoint
 
using Self = HyperRectDomain_Iterator< TPoint >
 
using Dimension = typename Point::Dimension
 
using DifferenceType = typename std::iterator_traits< Self >::difference_type
 Type of the difference between two iterators (usually std::ptrdiff_t except for BigInteger).
 

Public Member Functions

 HyperRectDomain_Iterator (const Point &p, const Point &lower, const Point &upper)
 HyperRectDomain iterator constructor.
 

Private Member Functions

const Pointdereference () const
 Dereference.
 
bool equal (const Self &other) const
 Compare iterators.
 
void increment ()
 Increments the iterator in order to scan the domain points dimension by dimension (lexicographic order).
 
void decrement ()
 Decrements the iterator in order to scan the domain points dimension by dimension (lexicographic order).
 
void advance (DifferenceType const &n)
 Advances the iterator in order to scan the domain points dimension by dimension (lexicographic order).
 
DifferenceType distance_to (const Self &other) const
 Distance between two iterators on the same domain (lexicographic order).
 

Private Attributes

TPoint myPoint
 Current Point in the domain.
 
TPoint mylower
 Copies of the Domain limits.
 
TPoint myupper
 
DifferenceType pos
 Iterator position in the current sequence.
 

Friends

class boost::iterator_core_access
 

Detailed Description

template<typename TPoint>
class DGtal::HyperRectDomain_Iterator< TPoint >

Iterator for HyperRectDomain.

Template Parameters
TPointPoint type.
Examples
geometry/volumes/distance/distancetransform3D.cpp, io/viewDualSurface.cpp, io/viewers/viewer3D-9-3Dimages.cpp, and tutorial-examples/volDTGranulo.cpp.

Definition at line 142 of file HyperRectDomain_Iterator.h.

Member Typedef Documentation

◆ DifferenceType

template<typename TPoint >
using DGtal::HyperRectDomain_Iterator< TPoint >::DifferenceType = typename std::iterator_traits<Self>::difference_type

Type of the difference between two iterators (usually std::ptrdiff_t except for BigInteger).

Definition at line 155 of file HyperRectDomain_Iterator.h.

◆ Dimension

template<typename TPoint >
using DGtal::HyperRectDomain_Iterator< TPoint >::Dimension = typename Point::Dimension

Definition at line 154 of file HyperRectDomain_Iterator.h.

◆ Point

template<typename TPoint >
using DGtal::HyperRectDomain_Iterator< TPoint >::Point = TPoint

Definition at line 152 of file HyperRectDomain_Iterator.h.

◆ Self

template<typename TPoint >
using DGtal::HyperRectDomain_Iterator< TPoint >::Self = HyperRectDomain_Iterator<TPoint>

Definition at line 153 of file HyperRectDomain_Iterator.h.

Constructor & Destructor Documentation

◆ HyperRectDomain_Iterator()

template<typename TPoint >
DGtal::HyperRectDomain_Iterator< TPoint >::HyperRectDomain_Iterator ( const Point p,
const Point lower,
const Point upper 
)
inline

HyperRectDomain iterator constructor.

Parameters
pThe point pointed by this iterator
lowerLower bound of the iterated domain
upperUpper bound of the iterated domain
Precondition
p must lie inside the given bounds or be equal to one of its bound
the bounds must describe a valid (possibly empty) domain

Definition at line 167 of file HyperRectDomain_Iterator.h.

168 : myPoint( p ), mylower( lower ), myupper( upper )
169 {
170 ASSERT_MSG( // For an empty domain, lower = upper + diag(1) so that begin() == end().
171 lower.isLower(upper) || lower == upper + TPoint::diagonal(1),
172 "The lower bound must be lower than the upper bound or, for an empty domain, be equal to the upper bound + diagonal(1)."
173 );
174
175 ASSERT_MSG(
176 ( lower.isLower(p) && p.isLower(upper) ) || p == lower || p == upper,
177 "The point must be inside the domain or be equal to one of his bound."
178 );
179
180 // Calculating iterator position in the sequence
181 pos = 0;
182 DifferenceType delta = 1;
183 for ( Dimension i = 0; i < Point::dimension; ++i )
184 {
185 pos += delta * (myPoint[i] - mylower[i]);
186 delta *= myupper[i] - mylower[i] + 1;
187 }
188 }
DifferenceType pos
Iterator position in the current sequence.
TPoint mylower
Copies of the Domain limits.
typename std::iterator_traits< Self >::difference_type DifferenceType
Type of the difference between two iterators (usually std::ptrdiff_t except for BigInteger).
TPoint myPoint
Current Point in the domain.
Vector lower(const Vector &z, unsigned int k)
Vector upper(const Vector &z, unsigned int k)

References lower(), DGtal::HyperRectDomain_Iterator< TPoint >::mylower, DGtal::HyperRectDomain_Iterator< TPoint >::myPoint, DGtal::HyperRectDomain_Iterator< TPoint >::myupper, DGtal::HyperRectDomain_Iterator< TPoint >::pos, and upper().

Member Function Documentation

◆ advance()

template<typename TPoint >
void DGtal::HyperRectDomain_Iterator< TPoint >::advance ( DifferenceType const &  n)
inlineprivate

Advances the iterator in order to scan the domain points dimension by dimension (lexicographic order).

Definition at line 253 of file HyperRectDomain_Iterator.h.

254 {
255 pos += n;
256 if (n > 0)
257 {
258 myPoint[0] += n;
259 for ( Dimension i = 0; myPoint[i] > myupper[i] && i < Point::dimension - 1; ++i )
260 {
261 typename Point::Component const shift = myPoint[i] - mylower[i];
262 typename Point::Component const length = myupper[i] - mylower[i] + 1;
263 myPoint[i+1] += shift / length;
264 myPoint[i] = mylower[i] + (shift % length);
265 }
266 }
267 else if (n < 0)
268 {
269 myPoint[0] += n;
270 for ( Dimension i = 0; myPoint[i] < mylower[i] && i < Point::dimension - 1; ++i )
271 {
272 typename Point::Component const shift = myupper[i] - myPoint[i];
273 typename Point::Component const length = myupper[i] - mylower[i] + 1;
274 myPoint[i+1] -= shift / length;
275 myPoint[i] = myupper[i] - (shift % length);
276 }
277 }
278 }

References DGtal::HyperRectDomain_Iterator< TPoint >::mylower, DGtal::HyperRectDomain_Iterator< TPoint >::myPoint, DGtal::HyperRectDomain_Iterator< TPoint >::myupper, and DGtal::HyperRectDomain_Iterator< TPoint >::pos.

◆ decrement()

template<typename TPoint >
void DGtal::HyperRectDomain_Iterator< TPoint >::decrement ( )
inlineprivate

Decrements the iterator in order to scan the domain points dimension by dimension (lexicographic order).

Definition at line 238 of file HyperRectDomain_Iterator.h.

239 {
240 --pos;
241 --myPoint[0];
242 for ( Dimension i = 0; myPoint[i] < mylower[i] && i < Point::dimension - 1; ++i )
243 {
244 --myPoint[i+1];
245 myPoint[i] = myupper[i];
246 }
247 }

References DGtal::HyperRectDomain_Iterator< TPoint >::mylower, DGtal::HyperRectDomain_Iterator< TPoint >::myPoint, DGtal::HyperRectDomain_Iterator< TPoint >::myupper, and DGtal::HyperRectDomain_Iterator< TPoint >::pos.

◆ dereference()

template<typename TPoint >
const Point & DGtal::HyperRectDomain_Iterator< TPoint >::dereference ( ) const
inlineprivate

Dereference.

Definition at line 194 of file HyperRectDomain_Iterator.h.

195 {
196 ASSERT_MSG( // we must be between [begin,end]
197 mylower.isLower(myPoint) && myPoint.isLower(myupper),
198 "The iterator points outside the domain."
199 );
200
201 return myPoint;
202
203 }

References DGtal::HyperRectDomain_Iterator< TPoint >::mylower, DGtal::HyperRectDomain_Iterator< TPoint >::myPoint, and DGtal::HyperRectDomain_Iterator< TPoint >::myupper.

◆ distance_to()

template<typename TPoint >
DifferenceType DGtal::HyperRectDomain_Iterator< TPoint >::distance_to ( const Self other) const
inlineprivate

Distance between two iterators on the same domain (lexicographic order).

Definition at line 283 of file HyperRectDomain_Iterator.h.

284 {
285 ASSERT_MSG( // we should only compare iterators on the same domain
286 mylower == other.mylower && myupper == other.myupper,
287 "The compared iterators iterate on different domains."
288 );
289
290 return other.pos - pos;
291 }

References DGtal::HyperRectDomain_Iterator< TPoint >::mylower, DGtal::HyperRectDomain_Iterator< TPoint >::myupper, and DGtal::HyperRectDomain_Iterator< TPoint >::pos.

◆ equal()

template<typename TPoint >
bool DGtal::HyperRectDomain_Iterator< TPoint >::equal ( const Self other) const
inlineprivate

Compare iterators.

Note
compare only the pointed point, not the iterated domain.

Definition at line 209 of file HyperRectDomain_Iterator.h.

210 {
211 ASSERT_MSG( // we should only compare iterators on the same domain
212 mylower == other.mylower && myupper == other.myupper,
213 "The compared iterators iterate on different domains."
214 );
215
216 return pos == other.pos;
217 }

References DGtal::HyperRectDomain_Iterator< TPoint >::mylower, DGtal::HyperRectDomain_Iterator< TPoint >::myupper, and DGtal::HyperRectDomain_Iterator< TPoint >::pos.

◆ increment()

template<typename TPoint >
void DGtal::HyperRectDomain_Iterator< TPoint >::increment ( )
inlineprivate

Increments the iterator in order to scan the domain points dimension by dimension (lexicographic order).

Definition at line 223 of file HyperRectDomain_Iterator.h.

224 {
225 ++pos;
226 ++myPoint[0];
227 for ( Dimension i = 0; myPoint[i] > myupper[i] && i < Point::dimension - 1; ++i )
228 {
229 ++myPoint[i+1];
230 myPoint[i] = mylower[i];
231 }
232 }

References DGtal::HyperRectDomain_Iterator< TPoint >::mylower, DGtal::HyperRectDomain_Iterator< TPoint >::myPoint, DGtal::HyperRectDomain_Iterator< TPoint >::myupper, and DGtal::HyperRectDomain_Iterator< TPoint >::pos.

Friends And Related Symbol Documentation

◆ boost::iterator_core_access

template<typename TPoint >
friend class boost::iterator_core_access
friend

Definition at line 191 of file HyperRectDomain_Iterator.h.

Field Documentation

◆ mylower

◆ myPoint

◆ myupper

◆ pos


The documentation for this class was generated from the following file: