DGtal  1.3.beta
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
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). More...
 

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

Private Attributes

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

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

◆ Dimension

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

Definition at line 332 of file HyperRectDomain_Iterator.h.

◆ Point

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

Definition at line 330 of file HyperRectDomain_Iterator.h.

◆ Self

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

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

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

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

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

442  {
443  pos += n;
444  if (n > 0)
445  {
446  myPoint[mySubDomain[0]] += n;
447  for ( Dimension i = 0; myPoint[mySubDomain[i]] > myupper[mySubDomain[i]] && i < mySubDomain.size() - 1; ++i )
448  {
449  auto const ii = mySubDomain[i];
450  typename Point::Component const shift = myPoint[ii] - mylower[ii];
451  typename Point::Component const length = myupper[ii] - mylower[ii] + 1;
452  myPoint[mySubDomain[i+1]] += shift / length;
453  myPoint[ii] = mylower[ii] + (shift % length);
454  }
455  }
456  else if (n < 0)
457  {
458  myPoint[mySubDomain[0]] += n;
459  for ( Dimension i = 0; myPoint[mySubDomain[i]] < mylower[mySubDomain[i]] && i < mySubDomain.size() - 1; ++i )
460  {
461  auto const ii = mySubDomain[i];
462  typename Point::Component const shift = myupper[ii] - myPoint[ii];
463  typename Point::Component const length = myupper[ii] - mylower[ii] + 1;
464  myPoint[mySubDomain[i+1]] -= shift / length;
465  myPoint[ii] = myupper[ii] - (shift % length);
466  }
467  }
468  }

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

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

427  {
428  --pos;
429  --myPoint[mySubDomain[0]];
430  for ( Dimension i = 0; myPoint[mySubDomain[i]] < mylower[mySubDomain[i]] && i < mySubDomain.size() - 1; ++i )
431  {
432  --myPoint[mySubDomain[i+1]];
434  }
435  }

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

◆ dereference()

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

Dereference.

Definition at line 381 of file HyperRectDomain_Iterator.h.

382  {
383  ASSERT_MSG( // we must be between [begin,end]
384  mylower.isLower(myPoint) && myPoint.isLower(myupper),
385  "The iterator points outside the domain."
386  );
387 
388  return myPoint;
389 
390  }

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

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

475  {
476  ASSERT_MSG( // we should only compare iterators on the same domain and same dimensions
477  mylower == other.mylower && myupper == other.myupper && mySubDomain == other.mySubDomain,
478  "The compared iterators iterate on different domains or different dimensions."
479  );
480 
481  return other.pos - pos;
482  }

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

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

397  {
398  ASSERT_MSG( // we should only compare iterators on the same domain and same dimensions
399  mylower == other.mylower && myupper == other.myupper && mySubDomain == other.mySubDomain,
400  "The compared iterators iterate on different domains or different dimensions."
401  );
402 
403  return pos == other.pos;
404  }

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

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

412  {
413  ++pos;
414  ++myPoint[mySubDomain[0]];
415  for ( Dimension i = 0; myPoint[mySubDomain[i]] > myupper[mySubDomain[i]] && i < mySubDomain.size() - 1; ++i )
416  {
417  ++myPoint[mySubDomain[i+1]];
419  }
420  }

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

Friends And Related Function Documentation

◆ boost::iterator_core_access

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

Definition at line 378 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

◆ mySubDomain

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

◆ myupper

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

◆ pos

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

The documentation for this class was generated from the following file:
DGtal::HyperRectDomain_subIterator::DifferenceType
typename std::iterator_traits< Self >::difference_type DifferenceType
Type of the difference between two iterators (usually std::ptrdiff_t except for BigInteger).
Definition: HyperRectDomain_Iterator.h:333
lower
Vector lower(const Vector &z, unsigned int k)
Definition: viewDualSurface.cpp:190
DGtal::HyperRectDomain_subIterator::myupper
TPoint myupper
Definition: HyperRectDomain_Iterator.h:489
DGtal::HyperRectDomain_subIterator::mySubDomain
std::vector< Dimension > mySubDomain
Definition: HyperRectDomain_Iterator.h:494
DGtal::HyperRectDomain_subIterator::mylower
TPoint mylower
Copies of the Domain limits.
Definition: HyperRectDomain_Iterator.h:489
DGtal::HyperRectDomain_subIterator::Dimension
typename Point::Dimension Dimension
Definition: HyperRectDomain_Iterator.h:332
upper
Vector upper(const Vector &z, unsigned int k)
Definition: viewDualSurface.cpp:197
DGtal::HyperRectDomain_subIterator::myPoint
TPoint myPoint
Current Point in the domain.
Definition: HyperRectDomain_Iterator.h:486
DGtal::HyperRectDomain_subIterator::pos
DifferenceType pos
Iterator position in the current sequence.
Definition: HyperRectDomain_Iterator.h:497