DGtal  1.2.0
HyperRectDomain.h
1 
17 #pragma once
18 
32 #if defined(HyperRectDomain_RECURSES)
33 #error Recursive header files inclusion detected in HyperRectDomain.h
34 #else // defined(HyperRectDomain_RECURSES)
36 #define HyperRectDomain_RECURSES
37 
38 #if !defined HyperRectDomain_h
40 #define HyperRectDomain_h
41 
43 // Inclusions
44 #include <iostream>
45 #include <iterator>
46 
47 #include "DGtal/base/Common.h"
48 #include "DGtal/kernel/CSpace.h"
49 #include "DGtal/kernel/BasicPointPredicates.h"
50 #include "DGtal/kernel/domains/CDomain.h"
51 #include "DGtal/kernel/domains/HyperRectDomain_Iterator.h"
52 #include "DGtal/kernel/NumberTraits.h"
53 #include "DGtal/base/CConstBidirectionalRange.h"
54 
55 namespace DGtal
56 {
58  // class HyperRectDomain
98  template<typename TSpace>
100  {
102 
103  // ----------------------- Standard services ------------------------------
104  public:
105 
107 
108  // typedef TSpace DigitalSpace;
109  // typedef TSpace Space;
110  typedef TSpace Space;
111 
113  typedef typename Space::Point Point;
114  typedef typename Space::Integer Integer;
115  typedef typename Space::Vector Vector;
116  typedef typename Space::Dimension Dimension;
117  typedef typename Space::Size Size;
118  typedef typename Point::Coordinate Coordinate; // TODO REVOIR LES NOMS.... RECUPERER DANS SPACE
119 
120  BOOST_STATIC_CONSTANT(Dimension, dimension = Space::dimension);
121 
127 
129 
134 
139  HyperRectDomain ( const Point &lowerPoint, const Point &upperPoint );
140 
148  HyperRectDomain ( const typename Space::RealPoint &lowerPoint,
149  const typename Space::RealPoint &upperPoint );
150 
155 
161  HyperRectDomain ( const HyperRectDomain & other );
162 
163 
171 
176  const ConstIterator& begin() const
177  {
178  return myIteratorBegin;
179  }
180 
188  {
189  ASSERT_MSG(
191  "The point must be inside the domain or be equal to one of his bound."
192  );
193 
195  }
196 
201  const ConstIterator& end() const
202  {
203  return myIteratorEnd;
204  }
205 
211  {
212  return ConstReverseIterator(end());
213  }
214 
222  {
223  ASSERT_MSG(
225  "The point must be inside the domain or be equal to one of his bound."
226  );
227 
228  ConstIterator it(begin(aPoint)); ++it;
229  return ConstReverseIterator(it);
230  }
231 
237  {
238  return ConstReverseIterator(begin());
239  }
240 
250  {
253 
263  const std::vector<Dimension> & permutation,
264  const Point & startingPoint)
267  myStartingPoint(startingPoint)
268  {
269  ASSERT_MSG(
270  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
271  "The point must be inside the given domain or be equal to one of his bound."
272  );
273 
274  myPermutation.reserve( permutation.size() );
275  std::copy(permutation.begin(), permutation.end(), std::back_inserter(myPermutation));
278  }
279 
289  std::initializer_list<Dimension> permutation,
290  const Point & startingPoint)
293  myStartingPoint(startingPoint)
294  {
295  ASSERT_MSG(
296  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
297  "The point must be inside the given domain or be equal to one of his bound."
298  );
299 
300  myPermutation.reserve( permutation.size() );
301  for ( const unsigned int *c = permutation.begin(); c != permutation.end(); ++c )
302  {
303  myPermutation.push_back( *c );
304  }
307  }
308 
317  Dimension adim,
318  const Point & startingPoint)
321  myStartingPoint(startingPoint)
322  {
323  ASSERT_MSG(
324  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
325  "The point must be inside the given domain or be equal to one of his bound."
326  );
327 
328  myPermutation.push_back( adim );
331  }
332 
342  Dimension adim1, Dimension adim2,
343  const Point & startingPoint)
346  myStartingPoint(startingPoint)
347  {
348  ASSERT_MSG(
349  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
350  "The point must be inside the given domain or be equal to one of his bound."
351  );
352 
353  myPermutation.push_back( adim1 );
354  myPermutation.push_back( adim2 );
357  }
358 
369  Dimension adim1, Dimension adim2, Dimension adim3,
370  const Point & startingPoint)
373  myStartingPoint(startingPoint)
374  {
375  ASSERT_MSG(
376  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
377  "The point must be inside the given domain or be equal to one of his bound."
378  );
379 
380  myPermutation.push_back( adim1 );
381  myPermutation.push_back( adim2 );
382  myPermutation.push_back( adim3 );
385  }
386 
392  {
394  }
395 
403  {
404  ASSERT(aPoint.partialEqualInv(myLowerBound, myPermutation) );
405  ASSERT_MSG(
407  "The point must be inside the given domain or be equal to one of his bound."
408  );
409 
411  }
412 
418  {
420  ++it;
421  return it;
422  }
423 
429  {
430  return ConstReverseIterator(end());
431  }
432 
440  {
442  ++it;
443  return ConstReverseIterator(it);
444  }
445 
451  {
452  return ConstReverseIterator(begin());
453  }
454 
455  private:
463  std::vector<Dimension> myPermutation;
464  }; // ConstSubRange
465 
472  ConstSubRange subRange(const std::vector<Dimension> & permutation) const
473  {
474  return ConstSubRange(*this, permutation, myLowerBound);
475  }
476 
485  ConstSubRange subRange(const std::vector<Dimension> & permutation,
486  const Point & startingPoint) const
487  {
488  return ConstSubRange(*this, permutation, startingPoint);
489  }
490 
499  const Point & startingPoint) const
500  {
501  return ConstSubRange(*this, adim, startingPoint);
502  }
503 
513  const Point & startingPoint) const
514  {
515  return ConstSubRange(*this, adim1, adim2, startingPoint);
516  }
517 
528  const Point & startingPoint) const
529  {
530  return ConstSubRange(*this, adim1, adim2, adim3, startingPoint);
531  }
532 
539  ConstSubRange subRange(std::initializer_list<Dimension> permutation)
540  {
541  return ConstSubRange(*this, permutation, myLowerBound);
542  }
543 
552  ConstSubRange subRange(std::initializer_list<Dimension> permutation,
553  const Point & startingPoint)
554  {
555  return ConstSubRange(*this, permutation, startingPoint);
556  }
557 
558  // ----------------------- Interface --------------------------------------
559  public:
560 
565  Size size() const
566  {
567  Size res = 1;
568  Point p = Point::diagonal(1);
569  Vector e = (myUpperBound - myLowerBound) + p;
570  typename Vector::ConstIterator it, itEnd;
571  for ( it = e.begin(), itEnd = e.end(); it != itEnd; ++it)
572  {
573  res *= *it;
574  }
575  return res;
576  }
577 
582  const Point &lowerBound() const;
583 
588  const Point &upperBound() const ;
589 
594  bool isInside( const Point & p ) const;
595 
599  bool isEmpty() const;
600 
608  const Predicate & predicate() const;
609 
610  // ------------------------- Private Datas --------------------------------
611  private:
612 
613 
614 
615  // --------------- CDrawableWithBoard2D realization --------------------
616  public:
617 
622  //DrawableWithBoard2D* defaultStyle( std::string mode = "" ) const;
623 
627  std::string className() const;
628 
629 
634  void selfDisplay ( std::ostream & out ) const;
635 
640  bool isValid() const;
641 
642 
643 
644  // ------------------------- Hidden services ------------------------------
645  //private:
650 
651  private:
652 
655 
660  }; // end of class HyperRectDomain
661 
662 
669  template<typename TSpace>
670  std::ostream&
671  operator<< ( std::ostream& out, const HyperRectDomain<TSpace> & object );
672 
673 
674 } // namespace DGtal
675 
676 
678 // Includes inline functions.
679 #include "DGtal/kernel/domains/HyperRectDomain.ih"
680 
681 // //
683 
684 #endif // !defined HyperRectDomain_h
685 
686 #undef HyperRectDomain_RECURSES
687 #endif // else defined(HyperRectDomain_RECURSES)
Iterator for HyperRectDomain.
Reverse iterator for HyperRectDomain.
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Point myUpperBound
The highest point of the space diagonal.
Point myLowerBound
The lowest point of the space diagonal.
HyperRectDomain(const typename Space::RealPoint &lowerPoint, const typename Space::RealPoint &upperPoint)
HyperRectDomain< Space > Domain
BOOST_STATIC_CONSTANT(Dimension, dimension=Space::dimension)
ConstSubRange subRange(Dimension adim1, Dimension adim2, Dimension adim3, const Point &startingPoint) const
bool isInside(const Point &p) const
ConstSubRange subRange(const std::vector< Dimension > &permutation, const Point &startingPoint) const
functors::IsWithinPointPredicate< Point > Predicate
const ConstIterator & end() const
const ConstIterator & begin() const
ReverseIterator ConstReverseIterator
ConstSubRange subRange(std::initializer_list< Dimension > permutation)
const Point & lowerBound() const
ConstReverseIterator rbegin() const
ConstIterator myIteratorBegin
Begin iterator.
const Predicate & predicate() const
ConstSubRange subRange(Dimension adim, const Point &startingPoint) const
HyperRectDomain(const Point &lowerPoint, const Point &upperPoint)
const Point & upperBound() const
ConstSubRange subRange(const std::vector< Dimension > &permutation) const
HyperRectDomain & operator=(const HyperRectDomain &other)
HyperRectDomain_ReverseIterator< Iterator > ReverseIterator
void selfDisplay(std::ostream &out) const
ConstIterator begin(const Point &aPoint) const
ConstReverseIterator rend() const
Predicate myPredicate
"IsInside" predicate.
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
std::string className() const
HyperRectDomain_Iterator< Point > Iterator
Typedef of domain iterators.
HyperRectDomain(const HyperRectDomain &other)
Point::Coordinate Coordinate
ConstSubRange subRange(std::initializer_list< Dimension > permutation, const Point &startingPoint)
Space::Dimension Dimension
ConstReverseIterator rbegin(const Point &aPoint) const
HyperRectDomain< TSpace > Self
ConstSubRange subRange(Dimension adim1, Dimension adim2, const Point &startingPoint) const
ConstIterator myIteratorEnd
End iterator.
bool isLower(const PointVector< dim, OtherComponent, OtherStorage > &p) const
Return true if this point is below a given point.
Component Coordinate
Type for Point elements.
Definition: PointVector.h:617
Self & partialCopyInv(const PointVector< dim, OtherComponent, OtherContainer > &pv, const std::vector< Dimension > &dimensions)
Partial copy of a given PointVector.
static Self diagonal(Component val=1)
Container::const_iterator ConstIterator
Constant iterator type.
Definition: PointVector.h:641
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
UnsignedInteger Size
Type used to represent sizes in the digital space.
Definition: SpaceND.h:107
DGtal::Dimension Dimension
Copy of the type used for the dimension.
Definition: SpaceND.h:129
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
Aim: range through some subdomain of all the points in the domain. Defines a constructor taking a dom...
Point myStartingPoint
Starting point of the subrange.
ConstSubRange(const HyperRectDomain< TSpace > &domain, Dimension adim, const Point &startingPoint)
ConstSubRange(const HyperRectDomain< TSpace > &domain, const std::vector< Dimension > &permutation, const Point &startingPoint)
Point myUpperBound
Upper bound of the subrange.
ConstIterator begin(const Point &aPoint) const
HyperRectDomain_subIterator< Point > ConstIterator
ConstReverseIterator rbegin() const
ConstReverseIterator rbegin(const Point &aPoint) const
ConstSubRange(const HyperRectDomain< TSpace > &domain, Dimension adim1, Dimension adim2, const Point &startingPoint)
ConstSubRange(const HyperRectDomain< TSpace > &domain, std::initializer_list< Dimension > permutation, const Point &startingPoint)
ConstReverseIterator rend() const
ConstSubRange(const HyperRectDomain< TSpace > &domain, Dimension adim1, Dimension adim2, Dimension adim3, const Point &startingPoint)
HyperRectDomain_ReverseIterator< ConstIterator > ConstReverseIterator
Point myLowerBound
Lower bound of the subrange.
std::vector< Dimension > myPermutation
Permutation on dimensions used in the subrange.
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:106
Domain domain
const Point aPoint(3, 4)