DGtal  1.4.beta
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)
38 #define GridCurve_RECURSES
39 
40 #if !defined GridCurve_h
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 
192 
198 
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 
322 
326  ConstIterator end() const;
327 
332 
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 
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 
416  return SCellsRange(mySCells.begin(), mySCells.end(), new functors::Identity() );
417  }
418 
420 
422 
427  return PointsRange(mySCells.begin(), mySCells.end(), new functors::SCellToPoint<KSpace>(*myKPtr) );
428  }
429 
431 
434 
439  return MidPointsRange(mySCells.begin(), mySCells.end(), new CanonicSCellEmbedder<KSpace>(*myKPtr) );
440  }
441 
443 
445  std::pair<Point,Vector> > ArrowsRange;
446 
451  return ArrowsRange(mySCells.begin(), mySCells.end(), new functors::SCellToArrow<KSpace>(*myKPtr) );
452  }
453 
455 
458 
464  }
465 
467 
470 
476  }
477 
479 
481  std::pair<Point, Point> > IncidentPointsRange;
482 
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)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:173
bool initFromPointsVector(const std::vector< Point > &aVectorOfPoints)
SCell PointVectorTo1SCell(const Point &aPoint, const Vector &aVector)
Storage::const_reverse_iterator ConstReverseIterator
Definition: GridCurve.h:316
ConstRangeAdapter< typename Storage::const_iterator, functors::Identity, SCell > SCellsRange
Definition: GridCurve.h:410
SCell back() const
ConstIterator begin() const
Storage::const_reverse_iterator const_reverse_iterator
Definition: GridCurve.h:315
SCellsRange getSCellsRange() const
Definition: GridCurve.h:415
MidPointsRange getMidPointsRange() const
Definition: GridCurve.h:438
std::string className() const
bool initFromVectorStream(std::istream &in)
void selfDisplay(std::ostream &out) const
PointsRange getPointsRange() const
Definition: GridCurve.h:426
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToCode< KSpace >, char > CodesRange
Definition: GridCurve.h:491
ConstRangeAdapter< typename Storage::const_iterator, CanonicSCellEmbedder< KSpace >, typename KSpace::Space::RealPoint > MidPointsRange
Definition: GridCurve.h:433
KSpace::Point Vector
Definition: GridCurve.h:180
void pushBack(const SCell &aSCell)
Storage::const_iterator const_iterator
Definition: GridCurve.h:313
ConstReverseIterator rbegin() const
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToPoint< KSpace >, Point > PointsRange
Definition: GridCurve.h:421
const KSpace * myKPtr
Definition: GridCurve.h:367
std::vector< SCell > Storage
Definition: GridCurve.h:183
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToInnerPoint< KSpace >, Point > InnerPointsRange
Definition: GridCurve.h:457
IncidentPointsRange getIncidentPointsRange() const
Definition: GridCurve.h:486
KSpace::SCell SCell
Definition: GridCurve.h:182
bool initFromSCellsVector(const std::vector< SCell > &aVectorOfSCells)
GridCurve(ConstAlias< KSpace > aKSpace)
void writeVectorToStream(std::ostream &out)
ArrowsRange getArrowsRange() const
Definition: GridCurve.h:450
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToIncidentPoints< KSpace >, std::pair< Point, Point > > IncidentPointsRange
Definition: GridCurve.h:481
ConstIterator end() const
OuterPointsRange getOuterPointsRange() const
Definition: GridCurve.h:474
bool isOpen() const
bool isInside(const SCell &aSCell) const
bool initFromPointsRange(const TIterator &itb, const TIterator &ite)
Storage::size_type size() const
InnerPointsRange getInnerPointsRange() const
Definition: GridCurve.h:462
GridCurve(const GridCurve &other)
Storage mySCells
Definition: GridCurve.h:377
bool initFromSCellsRange(const TIterator &itb, const TIterator &ite)
KSpace::Point Point
Definition: GridCurve.h:179
ConstReverseIterator rend() const
GridCurve::CodesRange getCodesRange() const
Definition: GridCurve.h:496
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToArrow< KSpace >, std::pair< Point, Vector > > ArrowsRange
Definition: GridCurve.h:445
Storage::const_iterator ConstIterator
Definition: GridCurve.h:314
bool isValid() const
BOOST_CONCEPT_ASSERT((concepts::CCellularGridSpaceND< KSpace >))
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToOuterPoint< KSpace >, Point > OuterPointsRange
Definition: GridCurve.h:469
GridCurve & operator=(const GridCurve &other)
TKSpace KSpace
Definition: GridCurve.h:176
bool isClosed() const
void push_back(const SCell &aSCell)
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
PointVector< dim, double > RealPoint
Definition: SpaceND.h:117
Aim: transforms a signed cell into an arrow, ie. a pair point-vector.
Aim: transforms a 2d signed cell, basically a linel, into a code (0,1,2 or 3),.
Aim: transforms a signed cell c into a pair of points corresponding to the signed cells of greater di...
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
Aim: transforms a scell into a point.
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: This concept describes a cellular grid space in nD. In these spaces obtained by cartesian produc...
Aim: Define a simple default functor that just returns its argument.
const Point aPoint(3, 4)