DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 
105  // static constants
106  static const typename Space::Dimension dimension = Space::dimension;
107 
109  typedef typename Space::Point Point;
110  typedef typename Space::Integer Integer;
111  typedef typename Space::Vector Vector;
112  typedef typename Space::Dimension Dimension;
113  typedef typename Space::Size Size;
114  typedef typename Point::Coordinate Coordinate; // TODO REVOIR LES NOMS.... RECUPERER DANS SPACE
115 
121 
123 
127  HyperRectDomain();
128 
134  HyperRectDomain ( const Point &aPointA, const Point &aPointB );
135 
136 
141 
147  HyperRectDomain ( const HyperRectDomain & other );
148 
149 
156  HyperRectDomain & operator= ( const HyperRectDomain & other );
157 
158  /*
159  * begin method.
160  * @return ConstIterator on the beginning of the range.
161  */
162  const ConstIterator& begin() const
163  { return myIteratorBegin; }
164 
165  /*
166  * begin method from a given point.
167  * @param aPoint the initial point.
168  * @return a ConstIterator initialized to aPoint.
169  * @pre aPoint must belong to the range.
170  */
171  ConstIterator begin(const Point& aPoint) const
172  { ASSERT(isInside(aPoint));
173  return ConstIterator(aPoint,
175 
176  /*
177  * end method.
178  * @return ConstIterator on the end of the range.
179  */
180  const ConstIterator& end() const
181  { return myIteratorEnd; }
182 
183  /*
184  * reverse begin method.
185  * @return ConstIterator on the beginning of the reverse range.
186  */
188  { return ConstReverseIterator(end()); }
189 
190  /*
191  * reverse begin method from a given point.
192  * @param aPoint the initial point.
193  * @return a ConstIterator initialized to aPoint.
194  * @pre aPoint must belong to the range.
195  */
196  ConstReverseIterator rbegin(const Point& aPoint) const
197  { ASSERT(isInside(aPoint));
198  ConstIterator it(begin(aPoint)); ++it;
199  return ConstReverseIterator(it); }
200 
201  /*
202  * reverse end method.
203  * @return ConstIterator on the end of the reverse range.
204  */
206  { return ConstReverseIterator(begin()); }
207 
217  {
220 
230  const std::vector<Dimension> & permutation,
231  const Point & startingPoint)
232  : myLowerBound(domain.myLowerBound),
233  myUpperBound(domain.myUpperBound),
234  myStartingPoint(startingPoint)
235  {
236  myPermutation.reserve( permutation.size() );
237  std::copy(permutation.begin(),permutation.end(),
238  std::back_inserter(myPermutation));
241  }
242 
243 #ifdef CPP11_INITIALIZER_LIST
244 
253  std::initializer_list<Dimension> permutation,
254  const Point & startingPoint)
255  : myLowerBound(domain.myLowerBound),
256  myUpperBound(domain.myUpperBound),
257  myStartingPoint(startingPoint)
258  {
259  myPermutation.reserve( permutation.size() );
260  for ( const unsigned int *c = permutation.begin();
261  c != permutation.end(); ++c )
262  {
263  myPermutation.push_back( *c );
264  }
267  }
268 #endif
269 
278  Dimension adim,
279  const Point & startingPoint)
280  : myLowerBound(domain.myLowerBound),
281  myUpperBound(domain.myUpperBound),
282  myStartingPoint(startingPoint)
283  {
284  myPermutation.push_back( adim );
287  }
288 
298  Dimension adim1, Dimension adim2,
299  const Point & startingPoint)
300  : myLowerBound(domain.myLowerBound),
301  myUpperBound(domain.myUpperBound),
302  myStartingPoint(startingPoint)
303  {
304  myPermutation.push_back( adim1 );
305  myPermutation.push_back( adim2 );
308  }
309 
320  Dimension adim1, Dimension adim2, Dimension adim3,
321  const Point & startingPoint)
322  : myLowerBound(domain.myLowerBound),
323  myUpperBound(domain.myUpperBound),
324  myStartingPoint(startingPoint)
325  {
326  myPermutation.push_back( adim1 );
327  myPermutation.push_back( adim2 );
328  myPermutation.push_back( adim3 );
331  }
332 
333  /*
334  * begin method.
335  * @return ConstIterator on the beginning of the range.
336  */
340 
341  /*
342  * begin method from a given point.
343  * @param aPoint the initial point.
344  * @return a ConstIterator initialized to aPoint.
345  * @pre aPoint must belong to the range.
346  */
347  ConstIterator begin(const Point& aPoint) const
348  {
349  ASSERT(aPoint.partialEqualInv(myLowerBound, myPermutation) );
350  ASSERT(myLowerBound<=aPoint && aPoint<=myUpperBound);
351  return ConstIterator(aPoint, myLowerBound,
353  }
354 
355  /*
356  * end method.
357  * @return ConstIterator on the end of the range.
358  */
360  {
363  ++it;
364  return it;
365  }
366 
367  /*
368  * reverse begin method.
369  * @return ConstIterator on the beginning of the reverse range.
370  */
372  { return ConstReverseIterator(end()); }
373 
374  /*
375  * reverse begin method from a given point.
376  * @param aPoint the initial point.
377  * @return a ConstIterator initialized to aPoint.
378  * @pre aPoint must belong to the range.
379  */
380  ConstReverseIterator rbegin(const Point& aPoint) const
381  { ConstIterator it(begin(aPoint)); ++it;
382  return ConstReverseIterator(it); }
383 
384  /*
385  * reverse end method.
386  * @return ConstIterator on the end of the reverse range.
387  */
389  { return ConstReverseIterator(begin()); }
390 
391  private:
399  std::vector<Dimension> myPermutation;
400  };
401 
408  ConstSubRange subRange(const std::vector<Dimension> & permutation) const
409  { return ConstSubRange(*this, permutation, myLowerBound); }
410 
419  ConstSubRange subRange(const std::vector<Dimension> & permutation,
420  const Point & startingPoint) const
421  { return ConstSubRange(*this, permutation, startingPoint); }
422 
431  const Point & startingPoint) const
432  { return ConstSubRange(*this, adim, startingPoint); }
433 
443  const Point & startingPoint) const
444  { return ConstSubRange(*this, adim1, adim2, startingPoint); }
445 
456  const Point & startingPoint) const
457  { return ConstSubRange(*this, adim1, adim2, adim3, startingPoint); }
458 
459 #ifdef CPP11_INITIALIZER_LIST
460 
466  ConstSubRange subRange(std::initializer_list<Dimension> permutation)
467  { return ConstSubRange(*this, permutation, myLowerBound); }
468 
477  ConstSubRange subRange(std::initializer_list<Dimension> permutation,
478  const Point & startingPoint)
479  { return ConstSubRange(*this, permutation, startingPoint); }
480 #endif
481 
482  // ----------------------- Interface --------------------------------------
483  public:
488  Vector extent() const
489  {
490  Point p = Point::diagonal(1);
491  return (myUpperBound - myLowerBound) + p;
492  }
493 
498  Size size() const
499  {
500  Size res = 1;
501  Vector e = this->extent();
502  typename Vector::ConstIterator it, itEnd;
503  for ( it = e.begin(), itEnd = e.end();
504  it != itEnd; ++it)
505  {
506  res *= *it;
507  }
508  return res;
509  }
510 
515  const Point &lowerBound() const;
516 
521  const Point &upperBound() const ;
522 
527  bool isInside( const Point & p ) const;
528 
536  const Predicate & predicate() const;
537 
538  // ------------------------- Private Datas --------------------------------
539  private:
540 
541 
542 
543  // --------------- CDrawableWithBoard2D realization --------------------
544  public:
545 
550  //DrawableWithBoard2D* defaultStyle( std::string mode = "" ) const;
551 
555  std::string className() const;
556 
557 
562  void selfDisplay ( std::ostream & out ) const;
563 
568  bool isValid() const;
569 
570 
571 
572  // ------------------------- Hidden services ------------------------------
573  //private:
578 
579  private:
580 
583 
588  }; // end of class HyperRectDomain
589 
590 
597  template<typename TSpace>
598  std::ostream&
599  operator<< ( std::ostream& out, const HyperRectDomain<TSpace> & object );
600 
601 
602 } // namespace DGtal
603 
604 
606 // Includes inline functions.
607 #include "DGtal/kernel/domains/HyperRectDomain.ih"
608 
609 // //
611 
612 #endif // !defined HyperRectDomain_h
613 
614 #undef HyperRectDomain_RECURSES
615 #endif // else defined(HyperRectDomain_RECURSES)