DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 
56 #include "DGtal/base/BasicFunctors.h"
57 #include "DGtal/base/Circulator.h"
58 #include "DGtal/base/ConstRangeAdapter.h"
59 #include "DGtal/base/ConstIteratorAdapter.h"
60 
61 #include "DGtal/topology/CCellularGridSpaceND.h"
62 #include "DGtal/topology/KhalimskySpaceND.h"
63 #include "DGtal/topology/SCellsFunctors.h"
64 
66 
67 namespace DGtal
68 {
69 
70 
71 
73  // class GridCurve
75 
169  template <typename TKSpace = KhalimskySpaceND<2> >
170  class GridCurve
171  {
172 
173  public:
174  typedef TKSpace KSpace;
176 
177  typedef typename KSpace::Point Point;
178  typedef typename KSpace::Point Vector;
179 
180  typedef typename KSpace::SCell SCell;
181  typedef typename std::vector<SCell> Storage;
182 
183  // ----------------------- Standard services ------------------------------
184  public:
185 
189  ~GridCurve();
190 
195  GridCurve(const KSpace& aKSpace);
196 
201  GridCurve();
202 
207  GridCurve( const GridCurve & other );
208 
214  GridCurve & operator=( const GridCurve & other );
215 
216  // ----------------------- common ------------------------------
217 
221  std::string className() const;
222 
227  void selfDisplay ( std::ostream & out ) const;
228 
233  bool isValid() const;
234 
235  // ----------------------- streams ------------------------------
236 
241  bool initFromVectorStream(std::istream & in );
242 
247  void writeVectorToStream( std::ostream & out );
248 
249  // ----------------------- Initializations ------------------------------
250 
257  bool initFromVector( const std::vector<Point>& aVectorOfPoints );
258 
264  bool initFromPointsVector( const std::vector<Point>& aVectorOfPoints );
265 
271  template <typename TIterator>
272  bool initFromPointsRange( const TIterator& itb, const TIterator& ite );
273 
279  bool initFromSCellsVector( const std::vector<SCell>& aVectorOfSCells );
280 
286  template <typename TIterator>
287  bool initFromSCellsRange( const TIterator& itb, const TIterator& ite );
288 
289 
290  // ----------------------- open/closed ------------------------------
291 
292 
301  bool isClosed() const;
302 
307  bool isOpen() const;
308 
309  // ----------------------- container interface ------------------------------
310 
311  typedef typename Storage::const_iterator const_iterator;
312  typedef typename Storage::const_iterator ConstIterator;
313  typedef typename Storage::const_reverse_iterator const_reverse_iterator;
314  typedef typename Storage::const_reverse_iterator ConstReverseIterator;
315 
319  ConstIterator begin() const;
320 
324  ConstIterator end() const;
325 
329  ConstReverseIterator rbegin() const;
330 
334  ConstReverseIterator rend() const;
335 
339  SCell back() const;
340 
347  void push_back(const SCell& aSCell);
348 
353  void pushBack(const SCell& aSCell);
354 
358  typename Storage::size_type size() const;
359 
360  // ------------------------- private Datas --------------------------------
361  private:
365  const KSpace* myKPtr;
371 
376 
377 
378  // ------------------------- Public Datas --------------------------------
379  public:
380 
381 
382 
383  // ------------------------- Internal --------------------------------
384  private:
385 
392  SCell PointVectorTo1SCell(const Point& aPoint, const Vector& aVector);
398  bool isInside(const SCell& aSCell) const;
399 
400 
401 
402  // ------------------------- inner classes --------------------------------
403 
404  public:
405 
407 
409 
414  return SCellsRange(mySCells.begin(), mySCells.end(), new DefaultFunctor() );
415  }
416 
418 
420 
425  return PointsRange(mySCells.begin(), mySCells.end(), new SCellToPoint<KSpace>(*myKPtr) );
426  }
427 
429 
431  typename KSpace::Space::RealPoint > MidPointsRange;
432 
437  return MidPointsRange(mySCells.begin(), mySCells.end(), new SCellToMidPoint<KSpace>(*myKPtr) );
438  }
439 
441 
443  std::pair<Point,Vector> > ArrowsRange;
444 
449  return ArrowsRange(mySCells.begin(), mySCells.end(), new SCellToArrow<KSpace>(*myKPtr) );
450  }
451 
453 
456 
461  return InnerPointsRange(mySCells.begin(), mySCells.end(), new SCellToInnerPoint<KSpace>(*myKPtr) );
462  }
463 
465 
468 
473  return OuterPointsRange(mySCells.begin(), mySCells.end(), new SCellToOuterPoint<KSpace>(*myKPtr) );
474  }
475 
477 
479  std::pair<Point, Point> > IncidentPointsRange;
480 
485  return IncidentPointsRange(mySCells.begin(), mySCells.end(), new SCellToIncidentPoints<KSpace>(*myKPtr) );
486  }
488 
490 
495  return CodesRange( mySCells.begin(), mySCells.end(), new SCellToCode<KSpace>(*myKPtr) );
496  }
497 
498  }; // end of class GridCurve
499 
500 
501 
508  template<typename TKSpace>
509  std::ostream&
510  operator<< ( std::ostream & out, const GridCurve<TKSpace> & object );
511 
512 
513 } // namespace DGtal
514 
515 
517 // Includes inline functions/methods.
518 #include "DGtal/geometry/curves/GridCurve.ih"
519 
520 // //
522 
523 #endif // !defined GridCurve_h
524 
525 #undef GridCurve_RECURSES
526 #endif // else defined(GridCurve_RECURSES)