DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
LatticePolytope2D.h
1 
17 #pragma once
18 
32 #if defined(LatticePolytope2D_RECURSES)
33 #error Recursive header files inclusion detected in LatticePolytope2D.h
34 #else // defined(LatticePolytope2D_RECURSES)
35 
36 #define LatticePolytope2D_RECURSES
37 
38 #if !defined LatticePolytope2D_h
39 
40 #define LatticePolytope2D_h
41 
43 // Inclusions
44 #include <iostream>
45 #include <list>
46 #include <vector>
47 #include <string>
48 #include "DGtal/base/Common.h"
49 #include "DGtal/kernel/CSpace.h"
50 #include "DGtal/kernel/domains/HyperRectDomain.h"
51 #include "DGtal/arithmetic/IntegerComputer.h"
52 #include "DGtal/arithmetic/ClosedIntegerHalfPlane.h"
54 
55 namespace DGtal
56 {
57 
59  // template class LatticePolytope2D
81  template < typename TSpace,
82  typename TSequence = std::list< typename TSpace::Point > >
84  {
86  BOOST_STATIC_ASSERT(( TSpace::dimension == 2 ));
87  BOOST_CONCEPT_ASSERT(( boost::Sequence< TSequence > ));
88 
89  public:
91  typedef TSequence ClockwiseVertexSequence;
92 
93  typedef TSpace Space;
94  typedef typename Space::Integer Integer;
95  typedef typename Space::Point Point;
96  typedef typename Space::Vector Vector;
100 
101  typedef typename ClockwiseVertexSequence::value_type value_type;
102  typedef typename ClockwiseVertexSequence::reference reference;
103  typedef typename ClockwiseVertexSequence::const_reference const_reference;
104  typedef typename ClockwiseVertexSequence::iterator iterator;
105  typedef typename ClockwiseVertexSequence::const_iterator const_iterator;
106  typedef typename ClockwiseVertexSequence::const_pointer const_pointer;
107  typedef typename ClockwiseVertexSequence::size_type size_type;
108  typedef typename ClockwiseVertexSequence::difference_type difference_type;
109 
110  typedef typename ClockwiseVertexSequence::value_type Value;
111  typedef typename ClockwiseVertexSequence::iterator Iterator;
112  typedef typename ClockwiseVertexSequence::const_iterator ConstIterator;
113  typedef typename std::size_t Size;
114  typedef std::pair<Size,Size> SizeCouple;
115 
116  // The sequence must contain points.
119 
120  // Point2I and Point should be the same type.
127 
128  // ----------------------- Standard services ------------------------------
129  public:
130 
135 
140 
145  LatticePolytope2D ( const Self & other );
146 
152  Self & operator= ( const Self & other );
153 
157  MyIntegerComputer & ic() const;
158 
163  ConstIterator begin() const;
164 
169  ConstIterator end() const;
170 
175  Iterator begin();
176 
181  Iterator end();
182 
186  bool empty() const;
187 
191  Size size() const;
192 
197  Size max_size() const;
198 
202  void clear();
203 
209  Iterator erase( Iterator it );
210 
215  Domain boundingBoxDomain() const;
216 
221  void purge();
222 
232  Iterator insertBefore( const Iterator & pos, const Point & K );
233 
241  void pushBack( const Point & K );
242 
251  void pushFront( const Point & K );
252 
261  void push_back( const Point & K );
262 
271  void push_front( const Point & K );
272 
276  const Integer & twiceArea() const;
277 
291  Point3I centroid() const;
292 
309  Point3I centroid( const Integer & twice_area ) const;
310 
317 
327 
328  // ----------------------- halfspace services -------------------------------
329  public:
330 
347  SizeCouple findCut( Iterator & it_next_is_outside, Iterator & it_next_is_inside,
348  const HalfSpace & hs );
349 
359  bool cut( const HalfSpace & hs );
360 
371  HalfSpace halfSpace( ConstIterator it ) const;
372 
386  HalfSpace halfSpace( const Point & A, const Point & B, const Point & inP ) const;
387 
388 
399  template <typename DigitalSet>
400  void getIncludedDigitalPoints( DigitalSet & aSet ) const;
401 
402  // ----------------------- Helper methods ----------------------------------
403 
425  bool getFirstPointsOfHull( Vector & v,
426  Point & inPt, // must belong to hs1.
427  Point & outPt,
428  const HalfSpace & hs1,
429  const HalfSpace & hs2 ) const;
430 
451  void getAllPointsOfHull( std::vector<Point> & inPts,
452  std::vector<Point> & outPts,
453  const Vector & BV,
454  const HalfSpace & hs2,
455  const HalfSpace & hs3 ) const;
456 
477  template <typename OutputIterator>
478  OutputIterator computeConvexHullBorder( OutputIterator itOut,
479  const Point & pointRefC1,
480  const Point & pointRefC3,
481  const HalfSpace & hs1,
482  const HalfSpace & hs2,
483  const HalfSpace & hs3 ) const;
484 
489  void swap( LatticePolytope2D & other );
490 
491  // ----------------------- Interface --------------------------------------
492  public:
493 
498  void selfDisplay ( std::ostream & out ) const;
499 
504  bool isValid() const;
505 
509  std::string className() const;
510 
511 
512  // ------------------------- Protected Datas ------------------------------
513  protected:
514  // The (circular) sequence of vertices along the lattice polytope.
515  // The vertices are ordered \b clockwise.
517 
518  // ------------------------- Private Datas --------------------------------
519  private:
524  mutable Integer _a, _b, _c, _c1, _c3, _den, _g, _fl, _ce;
525  mutable Point _A, _B, _A1, _B1, _A2, _B2;
526  mutable Vector _N, _DV, _u, _v;
527  mutable std::vector<Point> _inPts, _outPts;
528 
529  // ------------------------- Hidden services ------------------------------
530  protected:
531 
532  // ------------------------- Internals ------------------------------------
533  private:
534 
535  }; // end of class LatticePolytope2D
536 
537 
544  template <typename TSpace, typename TSequence>
545  std::ostream&
546  operator<< ( std::ostream & out,
547  const LatticePolytope2D<TSpace,TSequence> & object );
548 
549 } // namespace DGtal
550 
551 
553 // Includes inline functions.
554 #include "DGtal/arithmetic/LatticePolytope2D.ih"
555 
556 // //
558 
559 #endif // !defined LatticePolytope2D_h
560 
561 #undef LatticePolytope2D_RECURSES
562 #endif // else defined(LatticePolytope2D_RECURSES)