DGtal 1.4.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 159 of file HyperRectDomain_Iterator.h.

◆ Dimension

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

Definition at line 158 of file HyperRectDomain_Iterator.h.

◆ Point

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

Definition at line 156 of file HyperRectDomain_Iterator.h.

◆ Self

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

Definition at line 157 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 171 of file HyperRectDomain_Iterator.h.

172 : myPoint( p ), mylower( lower ), myupper( upper )
173 {
174 ASSERT_MSG( // For an empty domain, lower = upper + diag(1) so that begin() == end().
175 lower.isLower(upper) || lower == upper + TPoint::diagonal(1),
176 "The lower bound must be lower than the upper bound or, for an empty domain, be equal to the upper bound + diagonal(1)."
177 );
178
179 ASSERT_MSG(
180 ( lower.isLower(p) && p.isLower(upper) ) || p == lower || p == upper,
181 "The point must be inside the domain or be equal to one of his bound."
182 );
183
184 // Calculating iterator position in the sequence
185 pos = 0;
186 DifferenceType delta = 1;
187 for ( Dimension i = 0; i < Point::dimension; ++i )
188 {
189 pos += delta * (myPoint[i] - mylower[i]);
190 delta *= myupper[i] - mylower[i] + 1;
191 }
192 }
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 257 of file HyperRectDomain_Iterator.h.

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

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 242 of file HyperRectDomain_Iterator.h.

243 {
244 --pos;
245 --myPoint[0];
246 for ( Dimension i = 0; myPoint[i] < mylower[i] && i < Point::dimension - 1; ++i )
247 {
248 --myPoint[i+1];
249 myPoint[i] = myupper[i];
250 }
251 }

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 198 of file HyperRectDomain_Iterator.h.

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

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 287 of file HyperRectDomain_Iterator.h.

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

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 213 of file HyperRectDomain_Iterator.h.

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

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 227 of file HyperRectDomain_Iterator.h.

228 {
229 ++pos;
230 ++myPoint[0];
231 for ( Dimension i = 0; myPoint[i] > myupper[i] && i < Point::dimension - 1; ++i )
232 {
233 ++myPoint[i+1];
234 myPoint[i] = mylower[i];
235 }
236 }

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 195 of file HyperRectDomain_Iterator.h.

Field Documentation

◆ mylower

◆ myPoint

◆ myupper

◆ pos


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