Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
DGtal::HyperRectDomain_subIterator< TPoint > Class Template Reference

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

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

Public Types

using Point = TPoint
using Self = HyperRectDomain_subIterator<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_subIterator (const TPoint &p, const TPoint &lower, const TPoint &upper, const std::vector< Dimension > &subDomain)

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 (by using the subDomain order given by the user).
void decrement ()
 Decrements the iterator in order to scan the domain points dimension by dimension (by using the subDomain order given by the user).
void advance (DifferenceType const &n)
 Advances the iterator in order to scan the domain points dimension by dimension (by using the subDomain order given by the user).
DifferenceType distance_to (const Self &other) const
 Distance between two iterators on the same domain (by using the subDomain order given by the user).

Private Attributes

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

Friends

class boost::iterator_core_access

Detailed Description

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

Description of class 'HyperRectDomain_subIterator'

Aim:

Definition at line 312 of file HyperRectDomain_Iterator.h.

Member Typedef Documentation

◆ DifferenceType

template<typename TPoint>
using DGtal::HyperRectDomain_subIterator< 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 325 of file HyperRectDomain_Iterator.h.

◆ Dimension

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

Definition at line 324 of file HyperRectDomain_Iterator.h.

◆ Point

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

Definition at line 322 of file HyperRectDomain_Iterator.h.

◆ Self

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

Definition at line 323 of file HyperRectDomain_Iterator.h.

Constructor & Destructor Documentation

◆ HyperRectDomain_subIterator()

template<typename TPoint>
DGtal::HyperRectDomain_subIterator< TPoint >::HyperRectDomain_subIterator ( const TPoint & p,
const TPoint & lower,
const TPoint & upper,
const std::vector< Dimension > & subDomain )
inline

Definition at line 327 of file HyperRectDomain_Iterator.h.

330 : myPoint( p ), mylower( lower ), myupper( upper )
331 {
332 ASSERT_MSG( // For an empty domain, lower = upper + diag(1) so that begin() == end().
333 lower.isLower(upper) || lower == upper + TPoint::diagonal(0).partialCopy( TPoint::diagonal(1), subDomain ),
334 "The lower bound must be lower than the upper bound or, for an empty domain, be equal to the upper bound + diagonal(1)."
335 );
336
338 ( lower.isLower(p) && p.isLower(upper) ) || p == lower || p == upper,
339 "The point must be inside the domain or be equal to one of his bound."
340 );
341
344 "The sub-range cannot have more dimensions than the ambiant space."
345 );
346
347 mySubDomain.reserve( subDomain.size() );
348 for ( typename std::vector<Dimension>::const_iterator it = subDomain.begin();
349 it != subDomain.end(); ++it )
350 {
353 "Invalid dimension in the sub-range."
354 );
355 mySubDomain.push_back( *it );
356 }
357
358 // Calculating iterator position in the sequence
359 pos = 0;
361 for ( Dimension i = 0; i < mySubDomain.size(); ++i )
362 {
363 auto const ii = mySubDomain[i];
364 pos += delta * (myPoint[ii] - mylower[ii]);
365 delta *= myupper[ii] - mylower[ii] + 1;
366 }
367 }
TPoint mylower
Copies of the Domain limits.
DifferenceType pos
Iterator position in the current sequence.
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.

Member Function Documentation

◆ advance()

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

Advances the iterator in order to scan the domain points dimension by dimension (by using the subDomain order given by the user).

Definition at line 433 of file HyperRectDomain_Iterator.h.

434 {
435 pos += n;
436 if (n > 0)
437 {
438 myPoint[mySubDomain[0]] += n;
439 for ( Dimension i = 0; myPoint[mySubDomain[i]] > myupper[mySubDomain[i]] && i < mySubDomain.size() - 1; ++i )
440 {
441 auto const ii = mySubDomain[i];
442 typename Point::Component const shift = myPoint[ii] - mylower[ii];
443 typename Point::Component const length = myupper[ii] - mylower[ii] + 1;
445 myPoint[ii] = mylower[ii] + (shift % length);
446 }
447 }
448 else if (n < 0)
449 {
450 myPoint[mySubDomain[0]] += n;
451 for ( Dimension i = 0; myPoint[mySubDomain[i]] < mylower[mySubDomain[i]] && i < mySubDomain.size() - 1; ++i )
452 {
453 auto const ii = mySubDomain[i];
454 typename Point::Component const shift = myupper[ii] - myPoint[ii];
455 typename Point::Component const length = myupper[ii] - mylower[ii] + 1;
457 myPoint[ii] = myupper[ii] - (shift % length);
458 }
459 }
460 }

◆ decrement()

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

Decrements the iterator in order to scan the domain points dimension by dimension (by using the subDomain order given by the user).

Definition at line 418 of file HyperRectDomain_Iterator.h.

419 {
420 --pos;
421 --myPoint[mySubDomain[0]];
422 for ( Dimension i = 0; myPoint[mySubDomain[i]] < mylower[mySubDomain[i]] && i < mySubDomain.size() - 1; ++i )
423 {
424 --myPoint[mySubDomain[i+1]];
426 }
427 }

◆ dereference()

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

Dereference.

Definition at line 373 of file HyperRectDomain_Iterator.h.

374 {
375 ASSERT_MSG( // we must be between [begin,end]
376 mylower.isLower(myPoint) && myPoint.isLower(myupper),
377 "The iterator points outside the domain."
378 );
379
380 return myPoint;
381
382 }

◆ distance_to()

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

Distance between two iterators on the same domain (by using the subDomain order given by the user).

Definition at line 466 of file HyperRectDomain_Iterator.h.

467 {
468 ASSERT_MSG( // we should only compare iterators on the same domain and same dimensions
470 "The compared iterators iterate on different domains or different dimensions."
471 );
472
473 return other.pos - pos;
474 }

◆ equal()

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

Compare iterators.

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

Definition at line 388 of file HyperRectDomain_Iterator.h.

389 {
390 ASSERT_MSG( // we should only compare iterators on the same domain and same dimensions
392 "The compared iterators iterate on different domains or different dimensions."
393 );
394
395 return pos == other.pos;
396 }

◆ increment()

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

Increments the iterator in order to scan the domain points dimension by dimension (by using the subDomain order given by the user).

Definition at line 403 of file HyperRectDomain_Iterator.h.

404 {
405 ++pos;
406 ++myPoint[mySubDomain[0]];
407 for ( Dimension i = 0; myPoint[mySubDomain[i]] > myupper[mySubDomain[i]] && i < mySubDomain.size() - 1; ++i )
408 {
409 ++myPoint[mySubDomain[i+1]];
411 }
412 }

◆ boost::iterator_core_access

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

Definition at line 370 of file HyperRectDomain_Iterator.h.

Field Documentation

◆ mylower

template<typename TPoint>
TPoint DGtal::HyperRectDomain_subIterator< TPoint >::mylower
private

◆ myPoint

template<typename TPoint>
TPoint DGtal::HyperRectDomain_subIterator< TPoint >::myPoint
private

Current Point in the domain.

Definition at line 478 of file HyperRectDomain_Iterator.h.

◆ mySubDomain

template<typename TPoint>
std::vector<Dimension> DGtal::HyperRectDomain_subIterator< TPoint >::mySubDomain
private

Vector of subDomain on dimension, to fix the order in which dimensions are considered.

Definition at line 486 of file HyperRectDomain_Iterator.h.

Referenced by DGtal::HyperRectDomain_subIterator< Point >::distance_to(), and DGtal::HyperRectDomain_subIterator< Point >::equal().

◆ myupper

◆ pos

template<typename TPoint>
DifferenceType DGtal::HyperRectDomain_subIterator< TPoint >::pos
private

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