DGtal  1.0.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)
35 
36 #define HyperRectDomain_RECURSES
37 
38 #if !defined HyperRectDomain_h
39 
40 #define HyperRectDomain_h
41 
43 // Inclusions
44 #include <iostream>
45 
46 #include "DGtal/base/Common.h"
47 #include "DGtal/kernel/CSpace.h"
48 #include "DGtal/kernel/BasicPointPredicates.h"
49 #include "DGtal/kernel/domains/CDomain.h"
50 #include "DGtal/kernel/domains/HyperRectDomain_Iterator.h"
51 #include "DGtal/kernel/NumberTraits.h"
52 #include "DGtal/base/CConstBidirectionalRange.h"
53 
54 namespace DGtal
55 {
57  // class HyperRectDomain
91  template<typename TSpace>
93  {
95 
96  // ----------------------- Standard services ------------------------------
97  public:
98 
100 
101  // typedef TSpace DigitalSpace;
102  // typedef TSpace Space;
103  typedef TSpace Space;
104 
106  typedef typename Space::Point Point;
107  typedef typename Space::Integer Integer;
108  typedef typename Space::Vector Vector;
109  typedef typename Space::Dimension Dimension;
110  typedef typename Space::Size Size;
111  typedef typename Point::Coordinate Coordinate; // TODO REVOIR LES NOMS.... RECUPERER DANS SPACE
112 
114 
120 
122 
126  HyperRectDomain();
127 
132  HyperRectDomain ( const Point &lowerPoint, const Point &upperPoint );
133 
141  HyperRectDomain ( const typename Space::RealPoint &lowerPoint,
142  const typename Space::RealPoint &upperPoint );
143 
148 
154  HyperRectDomain ( const HyperRectDomain & other );
155 
156 
163  HyperRectDomain & operator= ( const HyperRectDomain & other );
164 
169  const ConstIterator& begin() const
170  {
171  return myIteratorBegin;
172  }
173 
181  {
182  ASSERT_MSG(
184  "The point must be inside the domain or be equal to one of his bound."
185  );
186 
188  }
189 
194  const ConstIterator& end() const
195  {
196  return myIteratorEnd;
197  }
198 
204  {
205  return ConstReverseIterator(end());
206  }
207 
215  {
216  ASSERT_MSG(
218  "The point must be inside the domain or be equal to one of his bound."
219  );
220 
221  ConstIterator it(begin(aPoint)); ++it;
222  return ConstReverseIterator(it);
223  }
224 
230  {
231  return ConstReverseIterator(begin());
232  }
233 
243  {
246 
256  const std::vector<Dimension> & permutation,
257  const Point & startingPoint)
260  myStartingPoint(startingPoint)
261  {
262  ASSERT_MSG(
263  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
264  "The point must be inside the given domain or be equal to one of his bound."
265  );
266 
267  myPermutation.reserve( permutation.size() );
268  std::copy(permutation.begin(), permutation.end(), std::back_inserter(myPermutation));
271  }
272 
282  std::initializer_list<Dimension> permutation,
283  const Point & startingPoint)
286  myStartingPoint(startingPoint)
287  {
288  ASSERT_MSG(
289  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
290  "The point must be inside the given domain or be equal to one of his bound."
291  );
292 
293  myPermutation.reserve( permutation.size() );
294  for ( const unsigned int *c = permutation.begin(); c != permutation.end(); ++c )
295  {
296  myPermutation.push_back( *c );
297  }
300  }
301 
310  Dimension adim,
311  const Point & startingPoint)
314  myStartingPoint(startingPoint)
315  {
316  ASSERT_MSG(
317  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
318  "The point must be inside the given domain or be equal to one of his bound."
319  );
320 
321  myPermutation.push_back( adim );
324  }
325 
335  Dimension adim1, Dimension adim2,
336  const Point & startingPoint)
339  myStartingPoint(startingPoint)
340  {
341  ASSERT_MSG(
342  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
343  "The point must be inside the given domain or be equal to one of his bound."
344  );
345 
346  myPermutation.push_back( adim1 );
347  myPermutation.push_back( adim2 );
350  }
351 
362  Dimension adim1, Dimension adim2, Dimension adim3,
363  const Point & startingPoint)
366  myStartingPoint(startingPoint)
367  {
368  ASSERT_MSG(
369  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
370  "The point must be inside the given domain or be equal to one of his bound."
371  );
372 
373  myPermutation.push_back( adim1 );
374  myPermutation.push_back( adim2 );
375  myPermutation.push_back( adim3 );
378  }
379 
385  {
387  }
388 
396  {
397  ASSERT(aPoint.partialEqualInv(myLowerBound, myPermutation) );
398  ASSERT_MSG(
400  "The point must be inside the given domain or be equal to one of his bound."
401  );
402 
404  }
405 
411  {
413  ++it;
414  return it;
415  }
416 
422  {
423  return ConstReverseIterator(end());
424  }
425 
433  {
435  ++it;
436  return ConstReverseIterator(it);
437  }
438 
444  {
445  return ConstReverseIterator(begin());
446  }
447 
448  private:
456  std::vector<Dimension> myPermutation;
457  }; // ConstSubRange
458 
465  ConstSubRange subRange(const std::vector<Dimension> & permutation) const
466  {
467  return ConstSubRange(*this, permutation, myLowerBound);
468  }
469 
478  ConstSubRange subRange(const std::vector<Dimension> & permutation,
479  const Point & startingPoint) const
480  {
481  return ConstSubRange(*this, permutation, startingPoint);
482  }
483 
491  ConstSubRange subRange(Dimension adim,
492  const Point & startingPoint) const
493  {
494  return ConstSubRange(*this, adim, startingPoint);
495  }
496 
505  ConstSubRange subRange(Dimension adim1, Dimension adim2,
506  const Point & startingPoint) const
507  {
508  return ConstSubRange(*this, adim1, adim2, startingPoint);
509  }
510 
520  ConstSubRange subRange(Dimension adim1, Dimension adim2, Dimension adim3,
521  const Point & startingPoint) const
522  {
523  return ConstSubRange(*this, adim1, adim2, adim3, startingPoint);
524  }
525 
532  ConstSubRange subRange(std::initializer_list<Dimension> permutation)
533  {
534  return ConstSubRange(*this, permutation, myLowerBound);
535  }
536 
545  ConstSubRange subRange(std::initializer_list<Dimension> permutation,
546  const Point & startingPoint)
547  {
548  return ConstSubRange(*this, permutation, startingPoint);
549  }
550 
551  // ----------------------- Interface --------------------------------------
552  public:
553 
558  Size size() const
559  {
560  Size res = 1;
561  Point p = Point::diagonal(1);
562  Vector e = (myUpperBound - myLowerBound) + p;
563  typename Vector::ConstIterator it, itEnd;
564  for ( it = e.begin(), itEnd = e.end(); it != itEnd; ++it)
565  {
566  res *= *it;
567  }
568  return res;
569  }
570 
575  const Point &lowerBound() const;
576 
581  const Point &upperBound() const ;
582 
587  bool isInside( const Point & p ) const;
588 
592  bool isEmpty() const;
593 
601  const Predicate & predicate() const;
602 
603  // ------------------------- Private Datas --------------------------------
604  private:
605 
606 
607 
608  // --------------- CDrawableWithBoard2D realization --------------------
609  public:
610 
615  //DrawableWithBoard2D* defaultStyle( std::string mode = "" ) const;
616 
620  std::string className() const;
621 
622 
627  void selfDisplay ( std::ostream & out ) const;
628 
633  bool isValid() const;
634 
635 
636 
637  // ------------------------- Hidden services ------------------------------
638  //private:
643 
644  private:
645 
648 
653  }; // end of class HyperRectDomain
654 
655 
662  template<typename TSpace>
663  std::ostream&
664  operator<< ( std::ostream& out, const HyperRectDomain<TSpace> & object );
665 
666 
667 } // namespace DGtal
668 
669 
671 // Includes inline functions.
672 #include "DGtal/kernel/domains/HyperRectDomain.ih"
673 
674 // //
676 
677 #endif // !defined HyperRectDomain_h
678 
679 #undef HyperRectDomain_RECURSES
680 #endif // else defined(HyperRectDomain_RECURSES)
const Point aPoint(3, 4)
const ConstIterator & end() const
ConstReverseIterator rend() const
static const Dimension dimension
static constants to store the dimension.
Definition: SpaceND.h:132
ConstSubRange subRange(const std::vector< Dimension > &permutation) const
Component Coordinate
Type for Point elements.
Definition: PointVector.h:617
static Self diagonal(Component val=1)
ConstReverseIterator rbegin(const Point &aPoint) const
HyperRectDomain_Iterator< Point > Iterator
Typedef of domain iterators.
ConstIterator myIteratorEnd
End iterator.
ConstSubRange subRange(std::initializer_list< Dimension > permutation, const Point &startingPoint)
ConstIterator begin(const Point &aPoint) const
functors::IsWithinPointPredicate< Point > Predicate
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
const Point & upperBound() const
Point::Coordinate Coordinate
ConstIterator myIteratorBegin
Begin iterator.
HyperRectDomain_subIterator< Point > ConstIterator
Domain domain
ConstReverseIterator rbegin() const
HyperRectDomain< TSpace > Self
Space::Dimension Dimension
bool isInside(const Point &p) const
DGtal::Dimension Dimension
Copy of the type used for the dimension.
Definition: SpaceND.h:129
Point myLowerBound
Lower bound of the subrange.
ConstSubRange subRange(Dimension adim1, Dimension adim2, Dimension adim3, const Point &startingPoint) const
ConstReverseIterator rend() const
Predicate myPredicate
"IsInside" predicate.
ConstSubRange(const HyperRectDomain< TSpace > &domain, Dimension adim1, Dimension adim2, Dimension adim3, const Point &startingPoint)
ConstSubRange subRange(Dimension adim, const Point &startingPoint) const
const Predicate & predicate() const
ConstSubRange subRange(const std::vector< Dimension > &permutation, const Point &startingPoint) const
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
ConstSubRange(const HyperRectDomain< TSpace > &domain, Dimension adim, const Point &startingPoint)
ReverseIterator ConstReverseIterator
std::vector< Dimension > myPermutation
Permutation on dimensions used in the subrange.
ConstReverseIterator rbegin() const
Aim: range through some subdomain of all the points in the domain. Defines a constructor taking a dom...
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:105
Point myUpperBound
Upper bound of the subrange.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
ConstIterator begin(const Point &aPoint) const
const ConstIterator & begin() const
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
bool isLower(const PointVector< dim, OtherComponent, OtherStorage > &p) const
Return true if this point is below a given point.
ConstSubRange subRange(std::initializer_list< Dimension > permutation)
std::string className() const
Container::const_iterator ConstIterator
Constant iterator type.
Definition: PointVector.h:641
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
UnsignedInteger Size
Type used to represent sizes in the digital space.
Definition: SpaceND.h:107
myreverse_iterator< ConstIterator > ConstReverseIterator
HyperRectDomain< Space > Domain
HyperRectDomain & operator=(const HyperRectDomain &other)
Point myStartingPoint
Starting point of the subrange.
void selfDisplay(std::ostream &out) const
ConstSubRange subRange(Dimension adim1, Dimension adim2, const Point &startingPoint) const
myreverse_iterator< Iterator > ReverseIterator
BOOST_STATIC_CONSTANT(Dimension, dimension=Space::dimension)
Point myUpperBound
The highest point of the space diagonal.
const Point & lowerBound() const
Self & partialCopyInv(const PointVector< dim, OtherComponent, OtherContainer > &pv, const std::vector< Dimension > &dimensions)
Partial copy of a given PointVector.
ConstSubRange(const HyperRectDomain< TSpace > &domain, Dimension adim1, Dimension adim2, const Point &startingPoint)
ConstReverseIterator rbegin(const Point &aPoint) const
ConstSubRange(const HyperRectDomain< TSpace > &domain, const std::vector< Dimension > &permutation, const Point &startingPoint)
Point myLowerBound
The lowest point of the space diagonal.
ConstSubRange(const HyperRectDomain< TSpace > &domain, std::initializer_list< Dimension > permutation, const Point &startingPoint)