DGtal  0.9.2
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 ));
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 
316  Integer numberBoundaryPoints() const;
317 
326  Integer numberInteriorPoints() const;
327 
328  // ----------------------- halfspace services -------------------------------
329  public:
330 
349  SizeCouple findCut( Iterator & it_next_is_outside, Iterator & it_next_is_inside,
350  const HalfSpace & hs );
351 
361  bool cut( const HalfSpace & hs );
362 
373  HalfSpace halfSpace( ConstIterator it ) const;
374 
388  HalfSpace halfSpace( const Point & A, const Point & B, const Point & inP ) const;
389 
390 
401  template <typename DigitalSet>
402  void getIncludedDigitalPoints( DigitalSet & aSet ) const;
403 
404  // ----------------------- Helper methods ----------------------------------
405 
430  bool getFirstPointsOfHull( Vector & v,
431  Point & inPt, // must belong to hs1.
432  Point & outPt,
433  const HalfSpace & hs1,
434  const HalfSpace & hs2 ) const;
435 
456  void getAllPointsOfHull( std::vector<Point> & inPts,
457  std::vector<Point> & outPts,
458  const Vector & BV,
459  const HalfSpace & hs2,
460  const HalfSpace & hs3 ) const;
461 
489  template <typename OutputIterator>
490  OutputIterator computeConvexHullBorder( OutputIterator itOut,
491  const Point & pointRefC1,
492  const Point & pointRefC3,
493  const HalfSpace & hs1,
494  const HalfSpace & hs2,
495  const HalfSpace & hs3 ) const;
496 
501  void swap( LatticePolytope2D & other );
502 
503  // ----------------------- Interface --------------------------------------
504  public:
505 
510  void selfDisplay ( std::ostream & out ) const;
511 
516  bool isValid() const;
517 
521  std::string className() const;
522 
523 
524  // ------------------------- Protected Datas ------------------------------
525  protected:
526  // The (circular) sequence of vertices along the lattice polytope.
527  // The vertices are ordered \b clockwise.
528  ClockwiseVertexSequence myVertices;
529 
530  // ------------------------- Private Datas --------------------------------
531  private:
535  mutable MyIntegerComputer _ic;
536  mutable Integer _a, _b, _c, _c1, _c3, _den, _g, _fl, _ce;
537  mutable Point _A, _B, _A1, _B1, _A2, _B2;
538  mutable Vector _N, _DV, _u, _v;
539  mutable std::vector<Point> _inPts, _outPts;
540 
541  // ------------------------- Hidden services ------------------------------
542  protected:
543 
544  // ------------------------- Internals ------------------------------------
545  private:
546 
547  }; // end of class LatticePolytope2D
548 
549 
556  template <typename TSpace, typename TSequence>
557  std::ostream&
558  operator<< ( std::ostream & out,
559  const LatticePolytope2D<TSpace,TSequence> & object );
560 
561 } // namespace DGtal
562 
563 
565 // Includes inline functions.
566 #include "DGtal/arithmetic/LatticePolytope2D.ih"
567 
568 // //
570 
571 #endif // !defined LatticePolytope2D_h
572 
573 #undef LatticePolytope2D_RECURSES
574 #endif // else defined(LatticePolytope2D_RECURSES)
void push_front(const Point &K)
ClockwiseVertexSequence::difference_type difference_type
bool getFirstPointsOfHull(Vector &v, Point &inPt, Point &outPt, const HalfSpace &hs1, const HalfSpace &hs2) const
ConstIterator begin() const
Domain boundingBoxDomain() const
IntegerComputer< Integer > MyIntegerComputer
ConstIterator end() const
ClosedIntegerHalfPlane< Space > HalfSpace
OutputIterator computeConvexHullBorder(OutputIterator itOut, const Point &pointRefC1, const Point &pointRefC3, const HalfSpace &hs1, const HalfSpace &hs2, const HalfSpace &hs3) const
ClockwiseVertexSequence::iterator Iterator
BOOST_STATIC_ASSERT((TSpace::dimension==2))
void selfDisplay(std::ostream &out) const
Go to http://www.sgi.com/tech/stl/Sequence.html.
Definition: Boost.dox:128
MyIntegerComputer::Vector2I Vector2I
bool cut(const HalfSpace &hs)
std::vector< Point > _inPts
Point3I centroid() const
void push_back(const Point &K)
SpaceND< 2, Integer >::Point Point2I
Integer numberBoundaryPoints() const
MyIntegerComputer::Point3I Point3I
void getAllPointsOfHull(std::vector< Point > &inPts, std::vector< Point > &outPts, const Vector &BV, const HalfSpace &hs2, const HalfSpace &hs3) const
Iterator insertBefore(const Iterator &pos, const Point &K)
std::pair< Size, Size > SizeCouple
SizeCouple findCut(Iterator &it_next_is_outside, Iterator &it_next_is_inside, const HalfSpace &hs)
MyIntegerComputer::Vector3I Vector3I
ClockwiseVertexSequence::value_type value_type
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines...
Definition: CSpace.h:105
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
void pushBack(const Point &K)
Self & operator=(const Self &other)
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
void pushFront(const Point &K)
ClockwiseVertexSequence::iterator iterator
ClockwiseVertexSequence::const_iterator ConstIterator
HyperRectDomain< Space > Domain
MyIntegerComputer & ic() const
std::vector< Point > _outPts
DGtal is the top-level namespace which contains all DGtal functions and types.
void getIncludedDigitalPoints(DigitalSet &aSet) const
Iterator erase(Iterator it)
MyIntegerComputer::Point2I Point2I
ClockwiseVertexSequence::size_type size_type
Aim: A half-space specified by a vector N and a constant c. The half-space is the set ...
ClockwiseVertexSequence::reference reference
const Integer & twiceArea() const
HalfSpace halfSpace(ConstIterator it) const
ClockwiseVertexSequence myVertices
ClockwiseVertexSequence::const_pointer const_pointer
void swap(LatticePolytope2D &other)
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
std::string className() const
SpaceND< 2, Integer >::Vector Vector2I
ClockwiseVertexSequence::const_reference const_reference
Aim: Represents a 2D polytope, i.e. a convex polygon, in the two-dimensional digital plane...
LatticePolytope2D< TSpace, TSequence > Self
ClockwiseVertexSequence::const_iterator const_iterator
Integer numberInteriorPoints() const
ClockwiseVertexSequence::value_type Value