Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
BoundedLatticePolytope.h
1
16
17#pragma once
18
30
31#if defined(BoundedLatticePolytope_RECURSES)
32#error Recursive header files inclusion detected in BoundedLatticePolytope.h
33#else // defined(BoundedLatticePolytope_RECURSES)
35#define BoundedLatticePolytope_RECURSES
36
37#if !defined BoundedLatticePolytope_h
39#define BoundedLatticePolytope_h
40
42// Inclusions
43#include <iostream>
44#include <list>
45#include <vector>
46#include <string>
47#include "DGtal/base/Common.h"
48#include "DGtal/kernel/CSpace.h"
49#include "DGtal/kernel/domains/HyperRectDomain.h"
50#include "DGtal/arithmetic/IntegerComputer.h"
51#include "DGtal/arithmetic/ClosedIntegerHalfPlane.h"
53
54namespace DGtal
55{
57 // template class BoundedLatticePolytope
72 template < typename TSpace >
74 {
76
77 public:
79 typedef TSpace Space;
80 typedef typename Space::Integer Integer;
81 typedef typename Space::Point Point;
82 typedef typename Space::Vector Vector;
83 typedef std::vector<Vector> InequalityMatrix;
84 typedef std::vector<Integer> InequalityVector;
89
94 struct UnitSegment {
96 UnitSegment( Dimension d ) : k( d ) {}
97 };
98
107
116
122 struct UnitCell {
123 std::vector<Dimension> dims;
124 UnitCell( std::initializer_list<Dimension> l )
125 : dims( l.begin(), l.end() ) {}
126
133 friend std::ostream&
134 operator<< ( std::ostream & out,
135 const UnitCell & object )
136 {
137 out << "{";
138 for ( Dimension i = 0; i < object.dims.size(); ++i ) out << object.dims[ i ];
139 out << "}";
140 return out;
141 }
142 };
143
150 std::vector<Dimension> dims;
151 RightStrictUnitCell( std::initializer_list<Dimension> l )
152 : dims( l.begin(), l.end() ) {}
153
160 friend std::ostream&
161 operator<< ( std::ostream & out,
162 const RightStrictUnitCell & object )
163 {
164 out << "{";
165 for ( Dimension i = 0; i < object.dims.size(); ++i ) out << object.dims[ i ];
166 out << "}";
167 return out;
168 }
169 };
170
177 std::vector<Dimension> dims;
178 LeftStrictUnitCell( std::initializer_list<Dimension> l )
179 : dims( l.begin(), l.end() ) {}
180
187 friend std::ostream&
188 operator<< ( std::ostream & out,
189 const LeftStrictUnitCell & object )
190 {
191 out << "{";
192 for ( Dimension i = 0; i < object.dims.size(); ++i ) out << object.dims[ i ];
193 out << "}";
194 return out;
195 }
196 };
197
200
205
210
215 BoundedLatticePolytope ( const Self & other ) = default;
216
217
224 BoundedLatticePolytope( std::initializer_list<Point> l );
225
234 template <typename PointIterator>
235 BoundedLatticePolytope( PointIterator itB, PointIterator itE );
236
256 template <typename HalfSpaceIterator>
258 HalfSpaceIterator itB, HalfSpaceIterator itE,
259 bool valid_edge_constraints = false,
260 bool check_duplicate_constraints = false );
261
281 template <typename HalfSpaceIterator>
282 void init( const Domain& domain,
283 HalfSpaceIterator itB, HalfSpaceIterator itE,
284 bool valid_edge_constraints = false,
285 bool check_duplicate_constraints = false );
286
287
300 template <typename PointIterator>
301 bool init( PointIterator itB, PointIterator itE );
302
308 Self & operator= ( const Self & other ) = default;
309
311 void clear();
312
316
320
322
323 // ----------------------- Accessor services ------------------------------
324 public:
327
329 const Domain& getDomain() const;
330
332 unsigned int nbHalfSpaces() const;
333
339 const Vector& getA( unsigned int i ) const;
340
346 Integer getB( unsigned int i ) const;
347
353 bool isLarge( unsigned int i ) const;
354
356 const InequalityMatrix& getA() const;
357
359 const InequalityVector& getB() const;
363 const std::vector<bool>& getI() const;
364
369 bool canBeSummed() const;
370
372
373 // ----------------------- Check point services ------------------------------
374 public:
375
378
383 bool isInside( const Point& p ) const;
384
391 bool isDomainPointInside( const Point& p ) const;
392
397 bool isInterior( const Point& p ) const;
398
403 bool isBoundary( const Point& p ) const;
404
406
407 // ----------------------- Modification services ------------------------------
408 public:
409
412
413
426 unsigned int cut( Dimension k, bool pos, Integer b, bool large = true );
427
445 unsigned int cut( const Vector& a, Integer b, bool large = true,
446 bool valid_edge_constraint = false );
447
464 unsigned int cut( const HalfSpace & hs, bool large = true,
465 bool valid_edge_constraint = false );
466
472
473
480
487 Self& operator+=( UnitSegment s );
488
495 Self& operator+=( UnitCell c );
496
503 Self& operator+=( RightStrictUnitSegment s );
504
511 Self& operator+=( RightStrictUnitCell c );
512
519 Self& operator+=( LeftStrictUnitSegment s );
520
527 Self& operator+=( LeftStrictUnitCell c );
529
530 // ----------------------- Enumeration services ------------------------------
531 public:
532
535
544 Integer count() const;
545
558
571
583 Integer countWithin( Point low, Point hi ) const;
584
603
613 void getPoints( std::vector<Point>& pts ) const;
614
629 void getKPoints( std::vector<Point>& pts, const Point& alpha_shift ) const;
630
640 void getInteriorPoints( std::vector<Point>& pts ) const;
641
651 void getBoundaryPoints( std::vector<Point>& pts ) const;
652
664 template <typename PointSet>
665 void insertPoints( PointSet& pts_set ) const;
666
683 template <typename PointSet>
684 void insertKPoints( PointSet& pts_set, const Point& alpha_shift ) const;
685
687
688 // -------------- Enumeration services (old methods by scanning ) --------------
689 public:
690
693
702
714
726
738
756
765 void getPointsByScanning( std::vector<Point>& pts ) const;
766
775 void getInteriorPointsByScanning( std::vector<Point>& pts ) const;
776
785 void getBoundaryPointsByScanning( std::vector<Point>& pts ) const;
786
797 template <typename PointSet>
798 void insertPointsByScanning( PointSet& pts_set ) const;
799
801
802
803 // ----------------------- Interface --------------------------------------
804 public:
807
812 void selfDisplay ( std::ostream & out ) const;
813
820 bool isValid() const;
821
825 std::string className() const;
826
828
829 // ------------------------- Protected Datas ------------------------------
830 protected:
838 std::vector<bool> I;
841
842 // ------------------------- Private Datas --------------------------------
843 private:
844
845
846 // ------------------------- Internals ------------------------------------
847 private:
855
862
869
870 }; // end of class BoundedLatticePolytope
871
872 namespace detail {
881 template <DGtal::Dimension N, typename TInteger>
883 typedef TInteger Integer;
885 typedef typename Space::Point Point;
886 typedef typename Space::Vector Vector;
889
902 static void
903 addEdgeConstraint( Polytope& , unsigned int , unsigned int ,
904 const std::vector<Point>& )
905 {
906 trace.error() << "[BoundedLatticePolytopeHelper::addEdgeConstraint]"
907 << " this method is only implemented in 3D." << std::endl;
908 }
909
912 static
913 Vector crossProduct( const Vector& , const Vector& )
914 {
915 trace.error() << "[BoundedLatticePolytopeHelper::crossProduct]"
916 << " this method is only implemented in 3D." << std::endl;
917 return Vector::zero;
918 }
919 };
920
928 template <typename TInteger>
930 typedef TInteger Integer;
932 typedef typename Space::Point Point;
933 typedef typename Space::Vector Vector;
936
946 static void
947 addEdgeConstraint( Polytope& P, unsigned int i, unsigned int j,
948 const std::vector<Point>& pts )
949 {
950 Vector ab = pts[ i ] - pts[ j ];
951 for ( int s = 0; s < 2; s++ )
952 for ( Dimension k = 0; k < dimension; ++k )
953 {
954 Vector n = ab.crossProduct( Point::base( k, (s == 0) ? 1 : -1 ) );
955 Integer b = n.dot( pts[ i ] );
956 std::size_t nb_in = 0;
957 for ( auto p : pts ) {
958 Integer v = n.dot( p );
959 if ( v < b ) nb_in++;
960 }
961 if ( nb_in == pts.size() - 2 ) {
962 P.cut( n, b, true, true );
963 }
964 }
965 }
966
970 static
971 Vector crossProduct( const Vector& v1, const Vector& v2 )
972 {
973 return v1.crossProduct( v2 );
974 }
975 };
976 }
977
980
987 template <typename TSpace>
988 std::ostream&
989 operator<< ( std::ostream & out,
990 const BoundedLatticePolytope<TSpace> & object );
991
992
998 template <typename TSpace>
1002
1003
1011 template <typename TSpace>
1015
1023 template <typename TSpace>
1027
1035 template <typename TSpace>
1039
1047 template <typename TSpace>
1051
1059 template <typename TSpace>
1063
1071 template <typename TSpace>
1075
1077
1078} // namespace DGtal
1079
1080
1082// Includes inline functions.
1083#include "BoundedLatticePolytope.ih"
1084
1085// //
1087
1088#endif // !defined BoundedLatticePolytope_h
1089
1090#undef BoundedLatticePolytope_RECURSES
1091#endif // else defined(BoundedLatticePolytope_RECURSES)
void init(const Domain &domain, HalfSpaceIterator itB, HalfSpaceIterator itE, bool valid_edge_constraints=false, bool check_duplicate_constraints=false)
Self & operator*=(Integer t)
Integer countWithin(Point low, Point hi) const
void getInteriorPoints(std::vector< Point > &pts) const
unsigned int nbHalfSpaces() const
BoundedLatticePolytope(PointIterator itB, PointIterator itE)
void getInteriorPointsByScanning(std::vector< Point > &pts) const
bool isInside(const Point &p) const
Integer countByScanning() const
BoundedLatticePolytope(const Domain &domain, HalfSpaceIterator itB, HalfSpaceIterator itE, bool valid_edge_constraints=false, bool check_duplicate_constraints=false)
Integer getB(unsigned int i) const
BoundedLatticePolytope(const Self &other)=default
Self & operator+=(UnitCell c)
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
Integer countInteriorByScanning() const
void getKPoints(std::vector< Point > &pts, const Point &alpha_shift) const
void clear()
Clears the polytope.
unsigned int cut(Dimension k, bool pos, Integer b, bool large=true)
ClosedIntegerHalfPlane< Space > HalfSpace
Integer countUpToByScanning(Integer max) const
void swap(BoundedLatticePolytope &other)
bool isLarge(unsigned int i) const
unsigned int cut(const Vector &a, Integer b, bool large=true, bool valid_edge_constraint=false)
bool init(PointIterator itB, PointIterator itE)
bool internalInitFromSegment2D(Point a, Point b)
const InequalityVector & getB() const
Self & operator+=(LeftStrictUnitCell c)
BoundedLatticePolytope interiorPolytope() const
unsigned int cut(const HalfSpace &hs, bool large=true, bool valid_edge_constraint=false)
Integer countBoundaryByScanning() const
std::vector< Integer > InequalityVector
BoundedLatticePolytope< TSpace > Self
bool internalInitFromTriangle3D(Point a, Point b, Point c)
void getBoundaryPoints(std::vector< Point > &pts) const
Integer countWithinByScanning(Point low, Point hi) const
bool isBoundary(const Point &p) const
const Domain & getDomain() const
void getPointsByScanning(std::vector< Point > &pts) const
void selfDisplay(std::ostream &out) const
Self & operator+=(RightStrictUnitCell c)
const Vector & getA(unsigned int i) const
const std::vector< bool > & getI() const
void insertKPoints(PointSet &pts_set, const Point &alpha_shift) const
void getBoundaryPointsByScanning(std::vector< Point > &pts) const
std::string className() const
bool internalInitFromSegment3D(Point a, Point b)
Integer countUpTo(Integer max) const
Self & operator+=(RightStrictUnitSegment s)
bool isDomainPointInside(const Point &p) const
Self & operator+=(LeftStrictUnitSegment s)
Self & operator+=(UnitSegment s)
BoundedLatticePolytope(std::initializer_list< Point > l)
const InequalityMatrix & getA() const
Self & operator=(const Self &other)=default
BoundedLatticePolytope closurePolytope() const
bool isInterior(const Point &p) const
void insertPointsByScanning(PointSet &pts_set) const
void insertPoints(PointSet &pts_set) const
void getPoints(std::vector< Point > &pts) const
static Self base(Dimension k, Component val=1)
auto dot(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::dotProduct(*this, v))
Dot product with a PointVector.
auto crossProduct(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::crossProduct(*this, v))
Cross product with a PointVector.
PointVector< dim, Integer > Point
Definition SpaceND.h:110
static const Dimension dimension
Definition SpaceND.h:132
PointVector< dim, Integer > Vector
Definition SpaceND.h:113
detail namespace gathers internal classes and functions.
DGtal is the top-level namespace which contains all DGtal functions and types.
KForm< Calculus, order, duality > operator*(const typename Calculus::Scalar &scalar, const KForm< Calculus, order, duality > &form)
Circulator< TIterator > operator+(typename IteratorCirculatorTraits< TIterator >::Difference d, Circulator< TIterator > &object)
Definition Circulator.h:453
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::uint32_t Dimension
Definition Common.h:119
Trace trace
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>, boost::multiprecision::et_off > BigInteger
Definition BasicTypes.h:75
friend std::ostream & operator<<(std::ostream &out, const LeftStrictUnitCell &object)
LeftStrictUnitCell(std::initializer_list< Dimension > l)
RightStrictUnitCell(std::initializer_list< Dimension > l)
friend std::ostream & operator<<(std::ostream &out, const RightStrictUnitCell &object)
friend std::ostream & operator<<(std::ostream &out, const UnitCell &object)
UnitCell(std::initializer_list< Dimension > l)
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition CSpace.h:106
static void addEdgeConstraint(Polytope &P, unsigned int i, unsigned int j, const std::vector< Point > &pts)
static Vector crossProduct(const Vector &v1, const Vector &v2)
Aim: It is just a helper class for BoundedLatticePolytope to add dimension specific static methods.
static Vector crossProduct(const Vector &, const Vector &)
static void addEdgeConstraint(Polytope &, unsigned int, unsigned int, const std::vector< Point > &)
int max(int a, int b)
Domain domain