DGtal  1.3.beta
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
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 
156  MyIntegerComputer & ic() const;
157 
162  ConstIterator begin() const;
163 
168  ConstIterator end() const;
169 
174  Iterator begin();
175 
180  Iterator end();
181 
185  bool empty() const;
186 
190  Size size() const;
191 
196  Size max_size() const;
197 
201  void clear();
202 
208  Iterator erase( Iterator it );
209 
214  Domain boundingBoxDomain() const;
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 
372  HalfSpace halfSpace( ConstIterator it ) const;
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 
429  bool getFirstPointsOfHull( Vector & v,
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)
DGtal::LatticePolytope2D::computeConvexHullBorder
OutputIterator computeConvexHullBorder(OutputIterator itOut, const Point &pointRefC1, const Point &pointRefC3, const HalfSpace &hs1, const HalfSpace &hs2, const HalfSpace &hs3) const
DGtal::LatticePolytope2D::erase
Iterator erase(Iterator it)
DGtal::LatticePolytope2D::cut
bool cut(const HalfSpace &hs)
DGtal::LatticePolytope2D::pushBack
void pushBack(const Point &K)
DGtal::LatticePolytope2D::reference
ClockwiseVertexSequence::reference reference
Definition: LatticePolytope2D.h:101
DGtal::LatticePolytope2D::difference_type
ClockwiseVertexSequence::difference_type difference_type
Definition: LatticePolytope2D.h:107
DGtal::LatticePolytope2D::iterator
ClockwiseVertexSequence::iterator iterator
Definition: LatticePolytope2D.h:103
DGtal::LatticePolytope2D::insertBefore
Iterator insertBefore(const Iterator &pos, const Point &K)
DGtal::HyperRectDomain< Space >
DGtal::concepts::CSpace
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:105
DGtal::LatticePolytope2D::Vector3I
MyIntegerComputer::Vector3I Vector3I
Definition: LatticePolytope2D.h:123
DGtal::LatticePolytope2D::ConstIterator
ClockwiseVertexSequence::const_iterator ConstIterator
Definition: LatticePolytope2D.h:111
DGtal::LatticePolytope2D::className
std::string className() const
DGtal::LatticePolytope2D
Aim: Represents a 2D polytope, i.e. a convex polygon, in the two-dimensional digital plane....
Definition: LatticePolytope2D.h:82
DGtal::LatticePolytope2D::size
Size size() const
DGtal::IntegerComputer< Integer >
DGtal::LatticePolytope2D::Space
TSpace Space
Definition: LatticePolytope2D.h:92
DGtal::LatticePolytope2D::twiceArea
const Integer & twiceArea() const
DGtal::LatticePolytope2D::_outPts
std::vector< Point > _outPts
Definition: LatticePolytope2D.h:538
DGtal::LatticePolytope2D::_N
Vector _N
Definition: LatticePolytope2D.h:537
DGtal::LatticePolytope2D::operator=
Self & operator=(const Self &other)
DGtal::LatticePolytope2D::boundingBoxDomain
Domain boundingBoxDomain() const
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::LatticePolytope2D::getFirstPointsOfHull
bool getFirstPointsOfHull(Vector &v, Point &inPt, Point &outPt, const HalfSpace &hs1, const HalfSpace &hs2) const
DGtal::LatticePolytope2D::findCut
SizeCouple findCut(Iterator &it_next_is_outside, Iterator &it_next_is_inside, const HalfSpace &hs)
DGtal::LatticePolytope2D::clear
void clear()
DGtal::LatticePolytope2D::_A2
Point _A2
Definition: LatticePolytope2D.h:536
DGtal::LatticePolytope2D::_DV
Vector _DV
Definition: LatticePolytope2D.h:537
DGtal::LatticePolytope2D::_A
Point _A
Definition: LatticePolytope2D.h:536
DGtal::LatticePolytope2D::SizeCouple
std::pair< Size, Size > SizeCouple
Definition: LatticePolytope2D.h:113
DGtal::LatticePolytope2D::const_reference
ClockwiseVertexSequence::const_reference const_reference
Definition: LatticePolytope2D.h:102
DGtal::LatticePolytope2D::swap
void swap(LatticePolytope2D &other)
DGtal::LatticePolytope2D::_fl
Integer _fl
Definition: LatticePolytope2D.h:535
DGtal::LatticePolytope2D::Size
std::size_t Size
Definition: LatticePolytope2D.h:112
DGtal::LatticePolytope2D::_v
Vector _v
Definition: LatticePolytope2D.h:537
DGtal::LatticePolytope2D::end
ConstIterator end() const
DGtal::LatticePolytope2D::Vector2I
MyIntegerComputer::Vector2I Vector2I
Definition: LatticePolytope2D.h:121
DGtal::LatticePolytope2D::_g
Integer _g
Definition: LatticePolytope2D.h:535
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::LatticePolytope2D::Value
ClockwiseVertexSequence::value_type Value
Definition: LatticePolytope2D.h:109
DGtal::LatticePolytope2D::~LatticePolytope2D
~LatticePolytope2D()
DGtal::LatticePolytope2D::Domain
HyperRectDomain< Space > Domain
Definition: LatticePolytope2D.h:97
DGtal::LatticePolytope2D::_u
Vector _u
Definition: LatticePolytope2D.h:537
DGtal::LatticePolytope2D::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::LatticePolytope2D::Self
LatticePolytope2D< TSpace, TSequence > Self
Definition: LatticePolytope2D.h:89
DGtal::LatticePolytope2D::MyIntegerComputer
IntegerComputer< Integer > MyIntegerComputer
Definition: LatticePolytope2D.h:96
DGtal::LatticePolytope2D::myVertices
ClockwiseVertexSequence myVertices
Definition: LatticePolytope2D.h:527
DGtal::LatticePolytope2D::_c
Integer _c
Definition: LatticePolytope2D.h:535
DGtal::LatticePolytope2D::_a
Integer _a
Definition: LatticePolytope2D.h:535
DGtal::LatticePolytope2D::Point3I
MyIntegerComputer::Point3I Point3I
Definition: LatticePolytope2D.h:122
DGtal::LatticePolytope2D::begin
ConstIterator begin() const
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::LatticePolytope2D::max_size
Size max_size() const
DGtal::LatticePolytope2D::getIncludedDigitalPoints
void getIncludedDigitalPoints(DigitalSet &aSet) const
DGtal::LatticePolytope2D::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
DGtal::LatticePolytope2D::getAllPointsOfHull
void getAllPointsOfHull(std::vector< Point > &inPts, std::vector< Point > &outPts, const Vector &BV, const HalfSpace &hs2, const HalfSpace &hs3) const
DGtal::LatticePolytope2D::halfSpace
HalfSpace halfSpace(ConstIterator it) const
DGtal::LatticePolytope2D::purge
void purge()
DGtal::IntegerComputer< Integer >::Vector2I
SpaceND< 2, Integer >::Vector Vector2I
Definition: IntegerComputer.h:94
DGtal::LatticePolytope2D::HalfSpace
ClosedIntegerHalfPlane< Space > HalfSpace
Definition: LatticePolytope2D.h:98
DGtal::LatticePolytope2D::_ic
MyIntegerComputer _ic
Definition: LatticePolytope2D.h:534
DGtal::LatticePolytope2D::Iterator
ClockwiseVertexSequence::iterator Iterator
Definition: LatticePolytope2D.h:110
DGtal::LatticePolytope2D::_ce
Integer _ce
Definition: LatticePolytope2D.h:535
DGtal::LatticePolytope2D::value_type
ClockwiseVertexSequence::value_type value_type
Definition: LatticePolytope2D.h:100
DGtal::LatticePolytope2D::_A1
Point _A1
Definition: LatticePolytope2D.h:536
boost::Sequence
Go to http://www.sgi.com/tech/stl/Sequence.html.
Definition: Boost.dox:128
DGtal::LatticePolytope2D::_c3
Integer _c3
Definition: LatticePolytope2D.h:535
DGtal::concepts::ConceptUtils::SameType
Definition: ConceptUtils.h:106
DGtal::ClosedIntegerHalfPlane
Aim: A half-space specified by a vector N and a constant c. The half-space is the set .
Definition: ClosedIntegerHalfPlane.h:63
DGtal::LatticePolytope2D::numberBoundaryPoints
Integer numberBoundaryPoints() const
DGtal::LatticePolytope2D::_B
Point _B
Definition: LatticePolytope2D.h:536
DGtal::LatticePolytope2D::BOOST_STATIC_ASSERT
BOOST_STATIC_ASSERT((TSpace::dimension==2))
DGtal::LatticePolytope2D::Point2I
MyIntegerComputer::Point2I Point2I
Definition: LatticePolytope2D.h:120
DGtal::LatticePolytope2D::empty
bool empty() const
DGtal::LatticePolytope2D::push_back
void push_back(const Point &K)
DGtal::LatticePolytope2D::Integer
Space::Integer Integer
Definition: LatticePolytope2D.h:93
DGtal::LatticePolytope2D::Vector
Space::Vector Vector
Definition: LatticePolytope2D.h:95
DGtal::PointVector< dim, Integer >
DGtal::LatticePolytope2D::pushFront
void pushFront(const Point &K)
DGtal::LatticePolytope2D::size_type
ClockwiseVertexSequence::size_type size_type
Definition: LatticePolytope2D.h:106
DGtal::LatticePolytope2D::const_pointer
ClockwiseVertexSequence::const_pointer const_pointer
Definition: LatticePolytope2D.h:105
DGtal::LatticePolytope2D::const_iterator
ClockwiseVertexSequence::const_iterator const_iterator
Definition: LatticePolytope2D.h:104
DGtal::LatticePolytope2D::_b
Integer _b
Definition: LatticePolytope2D.h:535
DGtal::LatticePolytope2D::_den
Integer _den
Definition: LatticePolytope2D.h:535
DGtal::LatticePolytope2D::centroid
Point3I centroid() const
DGtal::IntegerComputer< Integer >::Point2I
SpaceND< 2, Integer >::Point Point2I
Definition: IntegerComputer.h:93
DGtal::LatticePolytope2D::_c1
Integer _c1
Definition: LatticePolytope2D.h:535
DGtal::LatticePolytope2D::_B1
Point _B1
Definition: LatticePolytope2D.h:536
DGtal::LatticePolytope2D::Point
Space::Point Point
Definition: LatticePolytope2D.h:94
DGtal::LatticePolytope2D::_B2
Point _B2
Definition: LatticePolytope2D.h:536
DGtal::LatticePolytope2D::ic
MyIntegerComputer & ic() const
DGtal::LatticePolytope2D::LatticePolytope2D
LatticePolytope2D()
DGtal::LatticePolytope2D::isValid
bool isValid() const
DGtal::LatticePolytope2D::push_front
void push_front(const Point &K)
DGtal::SpaceND::Integer
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
DGtal::LatticePolytope2D::numberInteriorPoints
Integer numberInteriorPoints() const
DGtal::LatticePolytope2D::_inPts
std::vector< Point > _inPts
Definition: LatticePolytope2D.h:538
DGtal::DigitalSetByAssociativeContainer
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Definition: DigitalSetByAssociativeContainer.h:89
DGtal::LatticePolytope2D::ClockwiseVertexSequence
TSequence ClockwiseVertexSequence
Definition: LatticePolytope2D.h:90