DGtal  0.9.2
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 
113  BOOST_STATIC_CONSTANT(Dimension, dimension = Space::dimension);
114 
118  typedef Iterator ConstIterator;
119  typedef ReverseIterator ConstReverseIterator;
120 
122 
126  HyperRectDomain();
127 
133  HyperRectDomain ( const Point &aPointA, const Point &aPointB );
134 
135 
140 
146  HyperRectDomain ( const HyperRectDomain & other );
147 
148 
155  HyperRectDomain & operator= ( const HyperRectDomain & other );
156 
161  const ConstIterator& begin() const
162  {
163  return myIteratorBegin;
164  }
165 
172  ConstIterator begin(const Point& aPoint) const
173  {
174  ASSERT_MSG(
175  isInside(aPoint) || aPoint == myLowerBound || aPoint == myUpperBound,
176  "The point must be inside the domain or be equal to one of his bound."
177  );
178 
179  return ConstIterator(aPoint, myLowerBound, myUpperBound);
180  }
181 
186  const ConstIterator& end() const
187  {
188  return myIteratorEnd;
189  }
190 
195  ConstReverseIterator rbegin() const
196  {
197  return ConstReverseIterator(end());
198  }
199 
206  ConstReverseIterator rbegin(const Point& aPoint) const
207  {
208  ASSERT_MSG(
209  isInside(aPoint) || aPoint == myLowerBound || aPoint == myUpperBound,
210  "The point must be inside the domain or be equal to one of his bound."
211  );
212 
213  ConstIterator it(begin(aPoint)); ++it;
214  return ConstReverseIterator(it);
215  }
216 
221  ConstReverseIterator rend() const
222  {
223  return ConstReverseIterator(begin());
224  }
225 
235  {
238 
248  const std::vector<Dimension> & permutation,
249  const Point & startingPoint)
250  : myLowerBound(domain.myLowerBound),
251  myUpperBound(domain.myUpperBound),
252  myStartingPoint(startingPoint)
253  {
254  ASSERT_MSG(
255  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
256  "The point must be inside the given domain or be equal to one of his bound."
257  );
258 
259  myPermutation.reserve( permutation.size() );
260  std::copy(permutation.begin(), permutation.end(), std::back_inserter(myPermutation));
263  }
264 
274  std::initializer_list<Dimension> permutation,
275  const Point & startingPoint)
276  : myLowerBound(domain.myLowerBound),
277  myUpperBound(domain.myUpperBound),
278  myStartingPoint(startingPoint)
279  {
280  ASSERT_MSG(
281  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
282  "The point must be inside the given domain or be equal to one of his bound."
283  );
284 
285  myPermutation.reserve( permutation.size() );
286  for ( const unsigned int *c = permutation.begin(); c != permutation.end(); ++c )
287  {
288  myPermutation.push_back( *c );
289  }
292  }
293 
302  Dimension adim,
303  const Point & startingPoint)
304  : myLowerBound(domain.myLowerBound),
305  myUpperBound(domain.myUpperBound),
306  myStartingPoint(startingPoint)
307  {
308  ASSERT_MSG(
309  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
310  "The point must be inside the given domain or be equal to one of his bound."
311  );
312 
313  myPermutation.push_back( adim );
316  }
317 
327  Dimension adim1, Dimension adim2,
328  const Point & startingPoint)
329  : myLowerBound(domain.myLowerBound),
330  myUpperBound(domain.myUpperBound),
331  myStartingPoint(startingPoint)
332  {
333  ASSERT_MSG(
334  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
335  "The point must be inside the given domain or be equal to one of his bound."
336  );
337 
338  myPermutation.push_back( adim1 );
339  myPermutation.push_back( adim2 );
342  }
343 
354  Dimension adim1, Dimension adim2, Dimension adim3,
355  const Point & startingPoint)
356  : myLowerBound(domain.myLowerBound),
357  myUpperBound(domain.myUpperBound),
358  myStartingPoint(startingPoint)
359  {
360  ASSERT_MSG(
361  domain.isInside(startingPoint) || startingPoint == myLowerBound || startingPoint == myUpperBound,
362  "The point must be inside the given domain or be equal to one of his bound."
363  );
364 
365  myPermutation.push_back( adim1 );
366  myPermutation.push_back( adim2 );
367  myPermutation.push_back( adim3 );
370  }
371 
376  ConstIterator begin() const
377  {
379  }
380 
387  ConstIterator begin(const Point& aPoint) const
388  {
389  ASSERT(aPoint.partialEqualInv(myLowerBound, myPermutation) );
390  ASSERT_MSG(
391  ( myLowerBound.isLower(aPoint) && aPoint.isLower(myUpperBound) ) || aPoint == myLowerBound || aPoint == myUpperBound,
392  "The point must be inside the given domain or be equal to one of his bound."
393  );
394 
396  }
397 
402  ConstIterator end() const
403  {
405  ++it;
406  return it;
407  }
408 
413  ConstReverseIterator rbegin() const
414  {
415  return ConstReverseIterator(end());
416  }
417 
424  ConstReverseIterator rbegin(const Point& aPoint) const
425  {
426  ConstIterator it(begin(aPoint));
427  ++it;
428  return ConstReverseIterator(it);
429  }
430 
435  ConstReverseIterator rend() const
436  {
437  return ConstReverseIterator(begin());
438  }
439 
440  private:
448  std::vector<Dimension> myPermutation;
449  }; // ConstSubRange
450 
457  ConstSubRange subRange(const std::vector<Dimension> & permutation) const
458  {
459  return ConstSubRange(*this, permutation, myLowerBound);
460  }
461 
470  ConstSubRange subRange(const std::vector<Dimension> & permutation,
471  const Point & startingPoint) const
472  {
473  return ConstSubRange(*this, permutation, startingPoint);
474  }
475 
483  ConstSubRange subRange(Dimension adim,
484  const Point & startingPoint) const
485  {
486  return ConstSubRange(*this, adim, startingPoint);
487  }
488 
497  ConstSubRange subRange(Dimension adim1, Dimension adim2,
498  const Point & startingPoint) const
499  {
500  return ConstSubRange(*this, adim1, adim2, startingPoint);
501  }
502 
512  ConstSubRange subRange(Dimension adim1, Dimension adim2, Dimension adim3,
513  const Point & startingPoint) const
514  {
515  return ConstSubRange(*this, adim1, adim2, adim3, startingPoint);
516  }
517 
524  ConstSubRange subRange(std::initializer_list<Dimension> permutation)
525  {
526  return ConstSubRange(*this, permutation, myLowerBound);
527  }
528 
537  ConstSubRange subRange(std::initializer_list<Dimension> permutation,
538  const Point & startingPoint)
539  {
540  return ConstSubRange(*this, permutation, startingPoint);
541  }
542 
543  // ----------------------- Interface --------------------------------------
544  public:
545 
550  Size size() const
551  {
552  Size res = 1;
553  Point p = Point::diagonal(1);
554  Vector e = (myUpperBound - myLowerBound) + p;
555  typename Vector::ConstIterator it, itEnd;
556  for ( it = e.begin(), itEnd = e.end(); it != itEnd; ++it)
557  {
558  res *= *it;
559  }
560  return res;
561  }
562 
567  const Point &lowerBound() const;
568 
573  const Point &upperBound() const ;
574 
579  bool isInside( const Point & p ) const;
580 
584  bool isEmpty() const;
585 
593  const Predicate & predicate() const;
594 
595  // ------------------------- Private Datas --------------------------------
596  private:
597 
598 
599 
600  // --------------- CDrawableWithBoard2D realization --------------------
601  public:
602 
607  //DrawableWithBoard2D* defaultStyle( std::string mode = "" ) const;
608 
612  std::string className() const;
613 
614 
619  void selfDisplay ( std::ostream & out ) const;
620 
625  bool isValid() const;
626 
627 
628 
629  // ------------------------- Hidden services ------------------------------
630  //private:
635 
636  private:
637 
639  Predicate myPredicate;
640 
642  ConstIterator myIteratorBegin;
644  ConstIterator myIteratorEnd;
645  }; // end of class HyperRectDomain
646 
647 
654  template<typename TSpace>
655  std::ostream&
656  operator<< ( std::ostream& out, const HyperRectDomain<TSpace> & object );
657 
658 
659 } // namespace DGtal
660 
661 
663 // Includes inline functions.
664 #include "DGtal/kernel/domains/HyperRectDomain.ih"
665 
666 // //
668 
669 #endif // !defined HyperRectDomain_h
670 
671 #undef HyperRectDomain_RECURSES
672 #endif // else defined(HyperRectDomain_RECURSES)
ConstReverseIterator rend() const
static const Dimension dimension
static constants to store the dimension.
Definition: SpaceND.h:132
const ConstIterator & begin() const
ConstReverseIterator rbegin() const
const ConstIterator & end() const
ConstReverseIterator rbegin() const
Component Coordinate
Type for Point elements.
Definition: PointVector.h:158
static Self diagonal(Component val=1)
ConstIterator begin(const Point &aPoint) const
HyperRectDomain_Iterator< Point > Iterator
Typedef of domain iterators.
bool partialEqualInv(const Self &pv, const std::vector< Dimension > &dimensions) const
bool isLower(const Self &p) const
ConstIterator myIteratorEnd
End iterator.
ConstSubRange subRange(std::initializer_list< Dimension > permutation, const Point &startingPoint)
bool isEmpty() const
functors::IsWithinPointPredicate< Point > Predicate
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Point::Coordinate Coordinate
const Predicate & predicate() const
ConstIterator myIteratorBegin
Begin iterator.
ConstReverseIterator rbegin(const Point &aPoint) const
HyperRectDomain_subIterator< Point > ConstIterator
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.
ConstReverseIterator rend() const
std::string className() const
void selfDisplay(std::ostream &out) const
bool isValid() const
Predicate myPredicate
"IsInside" predicate.
ConstSubRange(const HyperRectDomain< TSpace > &domain, Dimension adim1, Dimension adim2, Dimension adim3, const Point &startingPoint)
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
ConstSubRange(const HyperRectDomain< TSpace > &domain, Dimension adim, const Point &startingPoint)
ReverseIterator ConstReverseIterator
ConstSubRange subRange(const std::vector< Dimension > &permutation, const Point &startingPoint) const
std::vector< Dimension > myPermutation
Permutation on dimensions used in the subrange.
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.
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
ConstSubRange subRange(std::initializer_list< Dimension > permutation)
ConstReverseIterator rbegin(const Point &aPoint) const
ConstSubRange subRange(const std::vector< Dimension > &permutation) const
const Point & upperBound() const
ConstSubRange subRange(Dimension adim1, Dimension adim2, const Point &startingPoint) const
Container::const_iterator ConstIterator
Definition: PointVector.h:182
DGtal is the top-level namespace which contains all DGtal functions and types.
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.
myreverse_iterator< Iterator > ReverseIterator
BOOST_STATIC_CONSTANT(Dimension, dimension=Space::dimension)
ConstSubRange subRange(Dimension adim, const Point &startingPoint) const
Point myUpperBound
The highest point of the space diagonal.
ConstSubRange(const HyperRectDomain< TSpace > &domain, Dimension adim1, Dimension adim2, const Point &startingPoint)
ConstSubRange(const HyperRectDomain< TSpace > &domain, const std::vector< Dimension > &permutation, const Point &startingPoint)
PointVector< dim, Integer > Point
Points in DGtal::SpaceND.
Definition: SpaceND.h:110
Point myLowerBound
The lowest point of the space diagonal.
const Point & lowerBound() const
Self & partialCopyInv(const Self &pv, std::initializer_list< Dimension > dimensions)
ConstIterator begin(const Point &aPoint) const
ConstSubRange subRange(Dimension adim1, Dimension adim2, Dimension adim3, const Point &startingPoint) const
ConstSubRange(const HyperRectDomain< TSpace > &domain, std::initializer_list< Dimension > permutation, const Point &startingPoint)