DGtal  1.4.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)
36 #define LatticePolytope2D_RECURSES
37 
38 #if !defined LatticePolytope2D_h
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
80  template < typename TSpace,
81  typename TSequence = std::list< typename TSpace::Point > >
83  {
85  BOOST_STATIC_ASSERT(( TSpace::dimension == 2 ));
87 
88  public:
90  typedef TSequence ClockwiseVertexSequence;
91 
92  typedef TSpace Space;
93  typedef typename Space::Integer Integer;
94  typedef typename Space::Point Point;
95  typedef typename Space::Vector Vector;
99 
100  typedef typename ClockwiseVertexSequence::value_type value_type;
101  typedef typename ClockwiseVertexSequence::reference reference;
102  typedef typename ClockwiseVertexSequence::const_reference const_reference;
103  typedef typename ClockwiseVertexSequence::iterator iterator;
104  typedef typename ClockwiseVertexSequence::const_iterator const_iterator;
105  typedef typename ClockwiseVertexSequence::const_pointer const_pointer;
106  typedef typename ClockwiseVertexSequence::size_type size_type;
107  typedef typename ClockwiseVertexSequence::difference_type difference_type;
108 
109  typedef typename ClockwiseVertexSequence::value_type Value;
110  typedef typename ClockwiseVertexSequence::iterator Iterator;
111  typedef typename ClockwiseVertexSequence::const_iterator ConstIterator;
112  typedef typename std::size_t Size;
113  typedef std::pair<Size,Size> SizeCouple;
114 
115  // The sequence must contain points.
118 
119  // Point2I and Point should be the same type.
126 
127  // ----------------------- Standard services ------------------------------
128  public:
129 
134 
139 
144  LatticePolytope2D ( const Self & other );
145 
151  Self & operator= ( const Self & other );
152 
157 
163 
169 
175 
181 
185  bool empty() const;
186 
190  Size size() const;
191 
196  Size max_size() const;
197 
201  void clear();
202 
209 
215 
220  void purge();
221 
231  Iterator insertBefore( const Iterator & pos, const Point & K );
232 
240  void pushBack( const Point & K );
241 
250  void pushFront( const Point & K );
251 
260  void push_back( const Point & K );
261 
270  void push_front( const Point & K );
271 
275  const Integer & twiceArea() const;
276 
290  Point3I centroid() const;
291 
308  Point3I centroid( const Integer & twice_area ) const;
309 
316 
326 
327  // ----------------------- halfspace services -------------------------------
328  public:
329 
348  SizeCouple findCut( Iterator & it_next_is_outside, Iterator & it_next_is_inside,
349  const HalfSpace & hs );
350 
360  bool cut( const HalfSpace & hs );
361 
373 
387  HalfSpace halfSpace( const Point & A, const Point & B, const Point & inP ) const;
388 
389 
400  template <typename DigitalSet>
401  void getIncludedDigitalPoints( DigitalSet & aSet ) const;
402 
403  // ----------------------- Helper methods ----------------------------------
404 
430  Point & inPt, // must belong to hs1.
431  Point & outPt,
432  const HalfSpace & hs1,
433  const HalfSpace & hs2 ) const;
434 
455  void getAllPointsOfHull( std::vector<Point> & inPts,
456  std::vector<Point> & outPts,
457  const Vector & BV,
458  const HalfSpace & hs2,
459  const HalfSpace & hs3 ) const;
460 
488  template <typename OutputIterator>
489  OutputIterator computeConvexHullBorder( OutputIterator itOut,
490  const Point & pointRefC1,
491  const Point & pointRefC3,
492  const HalfSpace & hs1,
493  const HalfSpace & hs2,
494  const HalfSpace & hs3 ) const;
495 
500  void swap( LatticePolytope2D & other );
501 
502  // ----------------------- Interface --------------------------------------
503  public:
504 
509  void selfDisplay ( std::ostream & out ) const;
510 
515  bool isValid() const;
516 
520  std::string className() const;
521 
522 
523  // ------------------------- Protected Datas ------------------------------
524  protected:
525  // The (circular) sequence of vertices along the lattice polytope.
526  // The vertices are ordered \b clockwise.
528 
529  // ------------------------- Private Datas --------------------------------
530  private:
535  mutable Integer _a, _b, _c, _c1, _c3, _den, _g, _fl, _ce;
536  mutable Point _A, _B, _A1, _B1, _A2, _B2;
537  mutable Vector _N, _DV, _u, _v;
538  mutable std::vector<Point> _inPts, _outPts;
539 
540  // ------------------------- Hidden services ------------------------------
541  protected:
542 
543  // ------------------------- Internals ------------------------------------
544  private:
545 
546  }; // end of class LatticePolytope2D
547 
548 
555  template <typename TSpace, typename TSequence>
556  std::ostream&
557  operator<< ( std::ostream & out,
558  const LatticePolytope2D<TSpace,TSequence> & object );
559 
560 } // namespace DGtal
561 
562 
564 // Includes inline functions.
565 #include "DGtal/arithmetic/LatticePolytope2D.ih"
566 
567 // //
569 
570 #endif // !defined LatticePolytope2D_h
571 
572 #undef LatticePolytope2D_RECURSES
573 #endif // else defined(LatticePolytope2D_RECURSES)
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
SpaceND< 2, Integer >::Vector Vector2I
SpaceND< 2, Integer >::Point Point2I
Aim: Represents a 2D polytope, i.e. a convex polygon, in the two-dimensional digital plane....
BOOST_STATIC_ASSERT((concepts::ConceptUtils::SameType< Point2I, Point >::value))
ClockwiseVertexSequence myVertices
void push_front(const Point &K)
void swap(LatticePolytope2D &other)
ClockwiseVertexSequence::reference reference
ClosedIntegerHalfPlane< Space > HalfSpace
ClockwiseVertexSequence::value_type value_type
MyIntegerComputer::Point3I Point3I
Self & operator=(const Self &other)
Iterator insertBefore(const Iterator &pos, const Point &K)
Integer numberBoundaryPoints() const
std::vector< Point > _outPts
ClockwiseVertexSequence::const_iterator ConstIterator
ClockwiseVertexSequence::size_type size_type
void pushFront(const Point &K)
Domain boundingBoxDomain() const
Integer numberInteriorPoints() const
Point3I centroid() const
void push_back(const Point &K)
BOOST_STATIC_ASSERT((TSpace::dimension==2))
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
std::vector< Point > _inPts
Iterator erase(Iterator it)
BOOST_CONCEPT_ASSERT((boost::Sequence< TSequence >))
std::string className() const
MyIntegerComputer::Point2I Point2I
std::pair< Size, Size > SizeCouple
void getAllPointsOfHull(std::vector< Point > &inPts, std::vector< Point > &outPts, const Vector &BV, const HalfSpace &hs2, const HalfSpace &hs3) const
LatticePolytope2D< TSpace, TSequence > Self
IntegerComputer< Integer > MyIntegerComputer
ClockwiseVertexSequence::difference_type difference_type
MyIntegerComputer::Vector2I Vector2I
ClockwiseVertexSequence::value_type Value
BOOST_STATIC_ASSERT((concepts::ConceptUtils::SameType< Vector2I, Vector >::value))
ClockwiseVertexSequence::const_reference const_reference
LatticePolytope2D(const Self &other)
HyperRectDomain< Space > Domain
ClockwiseVertexSequence::const_iterator const_iterator
const Integer & twiceArea() const
void selfDisplay(std::ostream &out) const
ClockwiseVertexSequence::const_pointer const_pointer
MyIntegerComputer::Vector3I Vector3I
HalfSpace halfSpace(const Point &A, const Point &B, const Point &inP) const
bool getFirstPointsOfHull(Vector &v, Point &inPt, Point &outPt, const HalfSpace &hs1, const HalfSpace &hs2) const
ConstIterator end() const
HalfSpace halfSpace(ConstIterator it) const
bool cut(const HalfSpace &hs)
ClockwiseVertexSequence::iterator iterator
ClockwiseVertexSequence::iterator Iterator
BOOST_STATIC_ASSERT((concepts::ConceptUtils::SameType< Value, Point >::value))
Point3I centroid(const Integer &twice_area) const
ConstIterator begin() const
void pushBack(const Point &K)
void getIncludedDigitalPoints(DigitalSet &aSet) const
MyIntegerComputer & ic() const
OutputIterator computeConvexHullBorder(OutputIterator itOut, const Point &pointRefC1, const Point &pointRefC3, const HalfSpace &hs1, const HalfSpace &hs2, const HalfSpace &hs3) const
SizeCouple findCut(Iterator &it_next_is_outside, Iterator &it_next_is_inside, const HalfSpace &hs)
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
Aim: A half-space specified by a vector N and a constant c. The half-space is the set .
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:106
Go to http://www.sgi.com/tech/stl/Sequence.html.
Definition: Boost.dox:128
KSpace K