DGtal  0.9.2
GridCurve.h
1 
17 #pragma once
18 
34 #if defined(GridCurve_RECURSES)
35 #error Recursive header files inclusion detected in GridCurve.h
36 #else // defined(GridCurve_RECURSES)
37 
38 #define GridCurve_RECURSES
39 
40 #if !defined GridCurve_h
41 
42 #define GridCurve_h
43 
45 // Inclusions
46 #include <iostream>
47 #include <sstream>
48 #include <vector>
49 #include <iterator>
50 #include <cstddef>
51 #include <utility>
52 
53 #include "DGtal/base/Common.h"
54 #include "DGtal/io/readers/PointListReader.h"
55 #include "DGtal/base/ConstAlias.h"
56 
57 #include "DGtal/base/BasicFunctors.h"
58 #include "DGtal/base/Circulator.h"
59 #include "DGtal/base/ConstRangeAdapter.h"
60 #include "DGtal/base/ConstIteratorAdapter.h"
61 
62 #include "DGtal/topology/CCellularGridSpaceND.h"
63 #include "DGtal/topology/KhalimskySpaceND.h"
64 #include "DGtal/topology/SCellsFunctors.h"
65 #include "DGtal/topology/CanonicSCellEmbedder.h"
66 
68 
69 namespace DGtal
70 {
71 
72 
73 
75  // class GridCurve
77 
171  template <typename TKSpace = KhalimskySpaceND<2> >
172  class GridCurve
173  {
174 
175  public:
176  typedef TKSpace KSpace;
178 
179  typedef typename KSpace::Point Point;
180  typedef typename KSpace::Point Vector;
181 
182  typedef typename KSpace::SCell SCell;
183  typedef typename std::vector<SCell> Storage;
184 
185  // ----------------------- Standard services ------------------------------
186  public:
187 
191  ~GridCurve();
192 
197  GridCurve( ConstAlias<KSpace> aKSpace);
198 
203  GridCurve();
204 
209  GridCurve( const GridCurve & other );
210 
216  GridCurve & operator=( const GridCurve & other );
217 
218  // ----------------------- common ------------------------------
219 
223  std::string className() const;
224 
229  void selfDisplay ( std::ostream & out ) const;
230 
235  bool isValid() const;
236 
237  // ----------------------- streams ------------------------------
238 
243  bool initFromVectorStream(std::istream & in );
244 
249  void writeVectorToStream( std::ostream & out );
250 
251  // ----------------------- Initializations ------------------------------
252 
259  bool initFromVector( const std::vector<Point>& aVectorOfPoints );
260 
266  bool initFromPointsVector( const std::vector<Point>& aVectorOfPoints );
267 
273  template <typename TIterator>
274  bool initFromPointsRange( const TIterator& itb, const TIterator& ite );
275 
281  bool initFromSCellsVector( const std::vector<SCell>& aVectorOfSCells );
282 
288  template <typename TIterator>
289  bool initFromSCellsRange( const TIterator& itb, const TIterator& ite );
290 
291 
292  // ----------------------- open/closed ------------------------------
293 
294 
303  bool isClosed() const;
304 
309  bool isOpen() const;
310 
311  // ----------------------- container interface ------------------------------
312 
313  typedef typename Storage::const_iterator const_iterator;
314  typedef typename Storage::const_iterator ConstIterator;
315  typedef typename Storage::const_reverse_iterator const_reverse_iterator;
316  typedef typename Storage::const_reverse_iterator ConstReverseIterator;
317 
321  ConstIterator begin() const;
322 
326  ConstIterator end() const;
327 
331  ConstReverseIterator rbegin() const;
332 
336  ConstReverseIterator rend() const;
337 
341  SCell back() const;
342 
349  void push_back(const SCell& aSCell);
350 
355  void pushBack(const SCell& aSCell);
356 
360  typename Storage::size_type size() const;
361 
362  // ------------------------- private Datas --------------------------------
363  private:
367  const KSpace* myKPtr;
373 
377  Storage mySCells;
378 
379 
380  // ------------------------- Public Datas --------------------------------
381  public:
382 
383 
384 
385  // ------------------------- Internal --------------------------------
386  private:
387 
394  SCell PointVectorTo1SCell(const Point& aPoint, const Vector& aVector);
400  bool isInside(const SCell& aSCell) const;
401 
402 
403 
404  // ------------------------- inner classes --------------------------------
405 
406  public:
407 
409 
411 
415  SCellsRange getSCellsRange() const {
416  return SCellsRange(mySCells.begin(), mySCells.end(), new functors::Identity() );
417  }
418 
420 
422 
426  PointsRange getPointsRange() const {
427  return PointsRange(mySCells.begin(), mySCells.end(), new functors::SCellToPoint<KSpace>(*myKPtr) );
428  }
429 
431 
433  typename KSpace::Space::RealPoint > MidPointsRange;
434 
438  MidPointsRange getMidPointsRange() const {
439  return MidPointsRange(mySCells.begin(), mySCells.end(), new CanonicSCellEmbedder<KSpace>(*myKPtr) );
440  }
441 
443 
445  std::pair<Point,Vector> > ArrowsRange;
446 
450  ArrowsRange getArrowsRange() const {
451  return ArrowsRange(mySCells.begin(), mySCells.end(), new functors::SCellToArrow<KSpace>(*myKPtr) );
452  }
453 
455 
458 
462  InnerPointsRange getInnerPointsRange() const {
463  return InnerPointsRange(mySCells.begin(), mySCells.end(), new functors::SCellToInnerPoint<KSpace>(*myKPtr) );
464  }
465 
467 
470 
474  OuterPointsRange getOuterPointsRange() const {
475  return OuterPointsRange(mySCells.begin(), mySCells.end(), new functors::SCellToOuterPoint<KSpace>(*myKPtr) );
476  }
477 
479 
481  std::pair<Point, Point> > IncidentPointsRange;
482 
486  IncidentPointsRange getIncidentPointsRange() const {
487  return IncidentPointsRange(mySCells.begin(), mySCells.end(), new functors::SCellToIncidentPoints<KSpace>(*myKPtr) );
488  }
490 
492 
497  return CodesRange( mySCells.begin(), mySCells.end(), new functors::SCellToCode<KSpace>(*myKPtr) );
498  }
499 
500  }; // end of class GridCurve
501 
502 
503 
510  template<typename TKSpace>
511  std::ostream&
512  operator<< ( std::ostream & out, const GridCurve<TKSpace> & object );
513 
514 
515 } // namespace DGtal
516 
517 
519 // Includes inline functions/methods.
520 #include "DGtal/geometry/curves/GridCurve.ih"
521 
522 // //
524 
525 #endif // !defined GridCurve_h
526 
527 #undef GridCurve_RECURSES
528 #endif // else defined(GridCurve_RECURSES)
PointsRange getPointsRange() const
Definition: GridCurve.h:426
InnerPointsRange getInnerPointsRange() const
Definition: GridCurve.h:462
MidPointsRange getMidPointsRange() const
Definition: GridCurve.h:438
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToPoint< KSpace >, Point > PointsRange
Definition: GridCurve.h:421
ConstIterator end() const
void selfDisplay(std::ostream &out) const
const KSpace * myKPtr
Definition: GridCurve.h:367
Storage::const_reverse_iterator const_reverse_iterator
Definition: GridCurve.h:315
KSpace::SCell SCell
Definition: GridCurve.h:182
TKSpace KSpace
Definition: GridCurve.h:176
std::vector< SCell > Storage
Definition: GridCurve.h:183
GridCurve::CodesRange getCodesRange() const
Definition: GridCurve.h:496
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToOuterPoint< KSpace >, Point > OuterPointsRange
Definition: GridCurve.h:469
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
ArrowsRange getArrowsRange() const
Definition: GridCurve.h:450
ConstReverseIterator rend() const
ConstRangeAdapter< typename Storage::const_iterator, CanonicSCellEmbedder< KSpace >, typename KSpace::Space::RealPoint > MidPointsRange
Definition: GridCurve.h:433
Storage::const_iterator const_iterator
Definition: GridCurve.h:313
Storage::const_reverse_iterator ConstReverseIterator
Definition: GridCurve.h:316
bool isValid() const
bool isClosed() const
bool initFromPointsRange(const TIterator &itb, const TIterator &ite)
BOOST_CONCEPT_ASSERT((concepts::CCellularGridSpaceND< KSpace >))
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToIncidentPoints< KSpace >, std::pair< Point, Point > > IncidentPointsRange
Definition: GridCurve.h:481
Aim: Define a simple default functor that just returns its argument.
std::string className() const
Aim: transforms a signed cell into an arrow, ie. a pair point-vector.
bool isOpen() const
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
ConstReverseIterator rbegin() const
ConstRangeAdapter< typename Storage::const_iterator, functors::Identity, SCell > SCellsRange
Definition: GridCurve.h:410
IncidentPointsRange getIncidentPointsRange() const
Definition: GridCurve.h:486
Aim: transforms a scell into a point.
Aim: transforms a 2d signed cell, basically a linel, into a code (0,1,2 or 3),.
KSpace::Point Vector
Definition: GridCurve.h:180
Storage::const_iterator ConstIterator
Definition: GridCurve.h:314
SCell PointVectorTo1SCell(const Point &aPoint, const Vector &aVector)
SCellsRange getSCellsRange() const
Definition: GridCurve.h:415
Storage::size_type size() const
bool isInside(const SCell &aSCell) const
void pushBack(const SCell &aSCell)
bool initFromSCellsRange(const TIterator &itb, const TIterator &ite)
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
bool initFromVectorStream(std::istream &in)
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToInnerPoint< KSpace >, Point > InnerPointsRange
Definition: GridCurve.h:457
Aim: This concept describes a cellular grid space in nD. In these spaces obtained by cartesian produc...
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToArrow< KSpace >, std::pair< Point, Vector > > ArrowsRange
Definition: GridCurve.h:445
KSpace::Point Point
Definition: GridCurve.h:179
void push_back(const SCell &aSCell)
bool initFromPointsVector(const std::vector< Point > &aVectorOfPoints)
Storage mySCells
Definition: GridCurve.h:377
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:172
ConstIterator begin() const
bool initFromSCellsVector(const std::vector< SCell > &aVectorOfSCells)
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
OuterPointsRange getOuterPointsRange() const
Definition: GridCurve.h:474
SCell back() const
GridCurve & operator=(const GridCurve &other)
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToCode< KSpace >, char > CodesRange
Definition: GridCurve.h:491
void writeVectorToStream(std::ostream &out)
Aim: transforms a signed cell c into a pair of points corresponding to the signed cells of greater di...