DGtal  0.9.3beta
Public Types | Public Member Functions | Private Attributes
DGtal::HyperRectDomain_subIterator< TPoint > Class Template Reference

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

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

Public Types

typedef std::bidirectional_iterator_tag iterator_category
 
typedef TPoint value_type
 
typedef ptrdiff_t difference_type
 
typedef TPoint * pointer
 
typedef TPoint & reference
 
typedef TPoint::Dimension Dimension
 

Public Member Functions

 HyperRectDomain_subIterator (const TPoint &p, const TPoint &lower, const TPoint &upper, std::initializer_list< Dimension > subDomain)
 
 HyperRectDomain_subIterator (const TPoint &p, const TPoint &lower, const TPoint &upper, const std::vector< Dimension > &subDomain)
 
const TPoint & operator* () const
 
TPoint & operator* ()
 
bool operator== (const HyperRectDomain_subIterator< TPoint > &it) const
 
bool operator!= (const HyperRectDomain_subIterator< TPoint > &aIt) const
 
void nextSubDomainOrder ()
 
HyperRectDomain_subIterator< TPoint > & operator++ ()
 
HyperRectDomain_subIterator< TPoint > operator++ (int)
 
void prevSubDomainOrder ()
 
HyperRectDomain_subIterator< TPoint > & operator-- ()
 
HyperRectDomain_subIterator< TPoint > operator-- (int)
 

Private Attributes

TPoint myPoint
 
TPoint mylower
 
TPoint myupper
 
std::vector< DimensionmySubDomain
 

Detailed Description

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

Description of class 'HyperRectDomain_subIterator'

Aim:

Definition at line 321 of file HyperRectDomain_Iterator.h.

Member Typedef Documentation

template<typename TPoint>
typedef ptrdiff_t DGtal::HyperRectDomain_subIterator< TPoint >::difference_type

Definition at line 326 of file HyperRectDomain_Iterator.h.

template<typename TPoint>
typedef TPoint::Dimension DGtal::HyperRectDomain_subIterator< TPoint >::Dimension

Definition at line 329 of file HyperRectDomain_Iterator.h.

template<typename TPoint>
typedef std::bidirectional_iterator_tag DGtal::HyperRectDomain_subIterator< TPoint >::iterator_category

Definition at line 324 of file HyperRectDomain_Iterator.h.

template<typename TPoint>
typedef TPoint* DGtal::HyperRectDomain_subIterator< TPoint >::pointer

Definition at line 327 of file HyperRectDomain_Iterator.h.

template<typename TPoint>
typedef TPoint& DGtal::HyperRectDomain_subIterator< TPoint >::reference

Definition at line 328 of file HyperRectDomain_Iterator.h.

template<typename TPoint>
typedef TPoint DGtal::HyperRectDomain_subIterator< TPoint >::value_type
Todo:
construct a RANDOM-ACCESS iterator

Definition at line 325 of file HyperRectDomain_Iterator.h.

Constructor & Destructor Documentation

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

Definition at line 331 of file HyperRectDomain_Iterator.h.

References DGtal::HyperRectDomain_subIterator< TPoint >::mySubDomain.

334  : myPoint( p ), mylower( lower ), myupper( upper )
335  {
336  ASSERT_MSG( // For an empty domain, lower = upper + diag(1) so that begin() == end().
337  lower.isLower(upper) || lower == upper + TPoint::diagonal(0).partialCopy( TPoint::diagonal(1), subDomain),
338  "The lower bound must be lower than the upper bound or, for an empty domain, be equal to the upper bound + diagonal(1)."
339  );
340 
341  ASSERT_MSG(
342  ( lower.isLower(p) && p.isLower(upper) ) || p == lower || p == upper,
343  "The point must be inside the domain or be equal to one of his bound."
344  );
345 
346  ASSERT_MSG(
347  subDomain.size() <= TPoint::dimension,
348  "The sub-range cannot have more dimensions than the ambiant space."
349  );
350 
351  mySubDomain.reserve( subDomain.size() );
352  for ( const unsigned int *c = subDomain.begin();
353  c != subDomain.end(); ++c )
354  {
355  ASSERT_MSG(
356  *c <= TPoint::dimension,
357  "Invalid dimension in the sub-range."
358  );
359 
360  mySubDomain.push_back( *c );
361  }
362 
363  // TODO: check the validity of the subDomain ?
364  }
TPoint mylower
Copies of the Domain limits.
TPoint myPoint
Current Point in the domain.
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 366 of file HyperRectDomain_Iterator.h.

References DGtal::HyperRectDomain_subIterator< TPoint >::mySubDomain.

369  : myPoint( p ), mylower( lower ), myupper( upper )
370  {
371  ASSERT_MSG( // For an empty domain, lower = upper + diag(1) so that begin() == end().
372  lower.isLower(upper) || lower == upper + TPoint::diagonal(0).partialCopy( TPoint::diagonal(1), subDomain ),
373  "The lower bound must be lower than the upper bound or, for an empty domain, be equal to the upper bound + diagonal(1)."
374  );
375 
376  ASSERT_MSG(
377  ( lower.isLower(p) && p.isLower(upper) ) || p == lower || p == upper,
378  "The point must be inside the domain or be equal to one of his bound."
379  );
380 
381  ASSERT_MSG(
382  subDomain.size() <= TPoint::dimension,
383  "The sub-range cannot have more dimensions than the ambiant space."
384  );
385 
386  mySubDomain.reserve( subDomain.size() );
387  for ( typename std::vector<Dimension>::const_iterator it = subDomain.begin();
388  it != subDomain.end(); ++it )
389  {
390  ASSERT_MSG(
391  *it <= TPoint::dimension,
392  "Invalid dimension in the sub-range."
393  );
394  mySubDomain.push_back( *it );
395  }
396 
397  // TODO: check the validity of the subDomain ?
398  }
TPoint mylower
Copies of the Domain limits.
TPoint myPoint
Current Point in the domain.

Member Function Documentation

template<typename TPoint>
void DGtal::HyperRectDomain_subIterator< TPoint >::nextSubDomainOrder ( )
inline

Implements the next() method to scan the domain points dimension by dimension (by using the subDomain order given by the user).

Definition at line 447 of file HyperRectDomain_Iterator.h.

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

Referenced by DGtal::HyperRectDomain_subIterator< TPoint >::operator++().

448  {
449  ASSERT( mySubDomain.size() > 0 );
450  ++myPoint[ mySubDomain[0] ];
451 
452  if ( mySubDomain.size() > 1 &&
453  myPoint[ mySubDomain[0] ] >
454  myupper[ mySubDomain[0] ] )
455  {
456  Dimension current_pos = 0;
457  do
458  {
459  myPoint[ mySubDomain[current_pos] ] =
460  mylower[ mySubDomain[current_pos] ];
461  ++current_pos;
462  if ( current_pos < mySubDomain.size() )
463  ++myPoint[ mySubDomain[current_pos] ];
464  }
465  while (( current_pos + 1 < mySubDomain.size() ) &&
466  ( myPoint[ mySubDomain[current_pos] ] >
467  myupper[ mySubDomain[current_pos] ] ) );
468  }
469  }
TPoint mylower
Copies of the Domain limits.
TPoint myPoint
Current Point in the domain.
template<typename TPoint>
bool DGtal::HyperRectDomain_subIterator< TPoint >::operator!= ( const HyperRectDomain_subIterator< TPoint > &  aIt) const
inline

Operator !=

Definition at line 438 of file HyperRectDomain_Iterator.h.

References DGtal::HyperRectDomain_subIterator< TPoint >::operator==().

439  {
440  return !operator==(aIt);
441  }
bool operator==(const HyperRectDomain_subIterator< TPoint > &it) const
template<typename TPoint>
const TPoint& DGtal::HyperRectDomain_subIterator< TPoint >::operator* ( ) const
inline

Definition at line 401 of file HyperRectDomain_Iterator.h.

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

402  {
403  ASSERT_MSG( // we must be between [begin,end]
404  mylower.isLower(myPoint) && myPoint.isLower(myupper),
405  "The iterator points outside the domain."
406  );
407 
408  return myPoint;
409  }
TPoint mylower
Copies of the Domain limits.
TPoint myPoint
Current Point in the domain.
template<typename TPoint>
TPoint& DGtal::HyperRectDomain_subIterator< TPoint >::operator* ( )
inline

Definition at line 411 of file HyperRectDomain_Iterator.h.

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

412  {
413  ASSERT_MSG( // we must be between [begin,end]
414  mylower.isLower(myPoint) && myPoint.isLower(myupper),
415  "The iterator points outside the domain."
416  );
417 
418  return myPoint;
419  }
TPoint mylower
Copies of the Domain limits.
TPoint myPoint
Current Point in the domain.
template<typename TPoint>
HyperRectDomain_subIterator<TPoint>& DGtal::HyperRectDomain_subIterator< TPoint >::operator++ ( )
inline

Operator ++ (++it)

Definition at line 474 of file HyperRectDomain_Iterator.h.

References DGtal::HyperRectDomain_subIterator< TPoint >::nextSubDomainOrder().

475  {
477  return *this;
478  }
template<typename TPoint>
HyperRectDomain_subIterator<TPoint> DGtal::HyperRectDomain_subIterator< TPoint >::operator++ ( int  )
inline

Operator ++ (it++)

Definition at line 484 of file HyperRectDomain_Iterator.h.

References DGtal::HyperRectDomain_subIterator< TPoint >::nextSubDomainOrder().

485  {
486  HyperRectDomain_subIterator<TPoint> tmp = *this;
488  return tmp;
489  }
template<typename TPoint>
HyperRectDomain_subIterator<TPoint>& DGtal::HyperRectDomain_subIterator< TPoint >::operator-- ( )
inline

Operator – (–it)

Definition at line 523 of file HyperRectDomain_Iterator.h.

References DGtal::HyperRectDomain_subIterator< TPoint >::prevSubDomainOrder().

524  {
526  return *this;
527  }
template<typename TPoint>
HyperRectDomain_subIterator<TPoint> DGtal::HyperRectDomain_subIterator< TPoint >::operator-- ( int  )
inline

Operator – (it–)

Definition at line 532 of file HyperRectDomain_Iterator.h.

References DGtal::HyperRectDomain_subIterator< TPoint >::prevSubDomainOrder().

533  {
534  HyperRectDomain_subIterator<TPoint> tmp = *this;
536  return tmp;
537  }
template<typename TPoint>
bool DGtal::HyperRectDomain_subIterator< TPoint >::operator== ( const HyperRectDomain_subIterator< TPoint > &  it) const
inline

Operator ==

Definition at line 425 of file HyperRectDomain_Iterator.h.

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

Referenced by DGtal::HyperRectDomain_subIterator< TPoint >::operator!=().

426  {
427  for (unsigned int i=0; i<mySubDomain.size(); ++i)
428  if ( myPoint[mySubDomain[i]]!=it.myPoint[mySubDomain[i]])
429  return false;
430 
431  return true;
432  }
TPoint myPoint
Current Point in the domain.
template<typename TPoint>
void DGtal::HyperRectDomain_subIterator< TPoint >::prevSubDomainOrder ( )
inline

Implements the prev() method to scan the domain points dimension by dimension (subDomain order).

Definition at line 495 of file HyperRectDomain_Iterator.h.

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

Referenced by DGtal::HyperRectDomain_subIterator< TPoint >::operator--().

496  {
497  ASSERT( mySubDomain.size() > 0 );
498  --myPoint[ mySubDomain[0] ];
499 
500  if ( mySubDomain.size() > 1 &&
501  myPoint[ mySubDomain[0] ] <
502  mylower[ mySubDomain[0] ] )
503  {
504  Dimension current_pos = 0;
505  do
506  {
507  myPoint[ mySubDomain[current_pos] ] =
508  myupper[ mySubDomain[current_pos] ];
509  ++current_pos;
510  if ( current_pos < mySubDomain.size() )
511  --myPoint[ mySubDomain[current_pos] ];
512  }
513  while (( current_pos + 1 < mySubDomain.size() ) &&
514  ( myPoint[ mySubDomain[current_pos] ] <
515  mylower[ mySubDomain[current_pos] ] ) );
516  }
517  }
TPoint mylower
Copies of the Domain limits.
TPoint myPoint
Current Point in the domain.

Field Documentation

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

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