DGtal 1.4.2
Loading...
Searching...
No Matches
BoundedLatticePolytope.h
1
17#pragma once
18
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;
87#ifdef WITH_BIGINTEGER
89#else
91#endif
92 static const Dimension dimension = Space::dimension;
93
98 struct UnitSegment {
100 UnitSegment( Dimension d ) : k( d ) {}
101 };
102
111
120
129
135 struct UnitCell {
136 std::vector<Dimension> dims;
137 UnitCell( std::initializer_list<Dimension> l )
138 : dims( l.begin(), l.end() ) {}
139
146 friend std::ostream&
147 operator<< ( std::ostream & out,
148 const UnitCell & object )
149 {
150 out << "{";
151 for ( Dimension i = 0; i < object.dims.size(); ++i ) out << object.dims[ i ];
152 out << "}";
153 return out;
154 }
155 };
156
163 std::vector<Dimension> dims;
164 RightStrictUnitCell( std::initializer_list<Dimension> l )
165 : dims( l.begin(), l.end() ) {}
166
173 friend std::ostream&
174 operator<< ( std::ostream & out,
175 const RightStrictUnitCell & object )
176 {
177 out << "{";
178 for ( Dimension i = 0; i < object.dims.size(); ++i ) out << object.dims[ i ];
179 out << "}";
180 return out;
181 }
182 };
183
190 std::vector<Dimension> dims;
191 LeftStrictUnitCell( std::initializer_list<Dimension> l )
192 : dims( l.begin(), l.end() ) {}
193
200 friend std::ostream&
201 operator<< ( std::ostream & out,
202 const LeftStrictUnitCell & object )
203 {
204 out << "{";
205 for ( Dimension i = 0; i < object.dims.size(); ++i ) out << object.dims[ i ];
206 out << "}";
207 return out;
208 }
209 };
210
217 std::vector<Dimension> dims;
218 StrictUnitCell( std::initializer_list<Dimension> l )
219 : dims( l.begin(), l.end() ) {}
220
227 friend std::ostream&
228 operator<< ( std::ostream & out,
229 const StrictUnitCell & object )
230 {
231 out << "{";
232 for ( Dimension i = 0; i < object.dims.size(); ++i ) out << object.dims[ i ];
233 out << "}";
234 return out;
235 }
236 };
237
240
245
250
255 BoundedLatticePolytope ( const Self & other ) = default;
256
257
264 BoundedLatticePolytope( std::initializer_list<Point> l );
265
274 template <typename PointIterator>
275 BoundedLatticePolytope( PointIterator itB, PointIterator itE );
276
296 template <typename HalfSpaceIterator>
298 HalfSpaceIterator itB, HalfSpaceIterator itE,
299 bool valid_edge_constraints = false,
300 bool check_duplicate_constraints = false );
301
321 template <typename HalfSpaceIterator>
322 void init( const Domain& domain,
323 HalfSpaceIterator itB, HalfSpaceIterator itE,
324 bool valid_edge_constraints = false,
325 bool check_duplicate_constraints = false );
326
327
340 template <typename PointIterator>
341 bool init( PointIterator itB, PointIterator itE );
342
348 Self & operator= ( const Self & other ) = default;
349
351 void clear();
352
356
360
362
363 // ----------------------- Accessor services ------------------------------
364 public:
367
369 const Domain& getDomain() const;
370
372 unsigned int nbHalfSpaces() const;
373
379 const Vector& getA( unsigned int i ) const;
380
386 Integer getB( unsigned int i ) const;
387
393 bool isLarge( unsigned int i ) const;
394
399 void setLarge( unsigned int i );
400
405 void setStrict( unsigned int i );
406
408 const InequalityMatrix& getA() const;
409
411 const InequalityVector& getB() const;
415 const std::vector<bool>& getI() const;
416
421 bool canBeSummed() const;
422
424
425 // ----------------------- Check point services ------------------------------
426 public:
427
430
435 bool isInside( const Point& p ) const;
436
443 bool isDomainPointInside( const Point& p ) const;
444
449 bool isInterior( const Point& p ) const;
450
455 bool isBoundary( const Point& p ) const;
456
458
459 // ----------------------- Modification services ------------------------------
460 public:
461
464
465
478 unsigned int cut( Dimension k, bool pos, Integer b, bool large = true );
479
497 unsigned int cut( const Vector& a, Integer b, bool large = true,
498 bool valid_edge_constraint = false );
499
516 unsigned int cut( const HalfSpace & hs, bool large = true,
517 bool valid_edge_constraint = false );
518
524
525
532
540
548
556
564
572
580
588
597
598 // ----------------------- Enumeration services ------------------------------
599 public:
600
603
612 Integer count() const;
613
626
639
651 Integer countWithin( Point low, Point hi ) const;
652
671
681 void getPoints( std::vector<Point>& pts ) const;
682
697 void getKPoints( std::vector<Point>& pts, const Point& alpha_shift ) const;
698
708 void getInteriorPoints( std::vector<Point>& pts ) const;
709
719 void getBoundaryPoints( std::vector<Point>& pts ) const;
720
732 template <typename PointSet>
733 void insertPoints( PointSet& pts_set ) const;
734
751 template <typename PointSet>
752 void insertKPoints( PointSet& pts_set, const Point& alpha_shift ) const;
753
755
756 // -------------- Enumeration services (old methods by scanning ) --------------
757 public:
758
761
770
782
794
806
824
833 void getPointsByScanning( std::vector<Point>& pts ) const;
834
843 void getInteriorPointsByScanning( std::vector<Point>& pts ) const;
844
853 void getBoundaryPointsByScanning( std::vector<Point>& pts ) const;
854
865 template <typename PointSet>
866 void insertPointsByScanning( PointSet& pts_set ) const;
867
869
870
871 // ----------------------- Interface --------------------------------------
872 public:
875
880 void selfDisplay ( std::ostream & out ) const;
881
888 bool isValid() const;
889
893 std::string className() const;
894
896
897 // ------------------------- Protected Datas ------------------------------
898 protected:
906 std::vector<bool> I;
909
910 // ------------------------- Private Datas --------------------------------
911 private:
912
913
914 // ------------------------- Internals ------------------------------------
915 private:
923
930
937
938 }; // end of class BoundedLatticePolytope
939
940 namespace detail {
949 template <DGtal::Dimension N, typename TInteger>
951 typedef TInteger Integer;
953 typedef typename Space::Point Point;
954 typedef typename Space::Vector Vector;
957
970 static void
971 addEdgeConstraint( Polytope& , unsigned int , unsigned int ,
972 const std::vector<Point>& )
973 {
974 trace.error() << "[BoundedLatticePolytopeHelper::addEdgeConstraint]"
975 << " this method is only implemented in 3D." << std::endl;
976 }
977
980 static
981 Vector crossProduct( const Vector& , const Vector& )
982 {
983 trace.error() << "[BoundedLatticePolytopeHelper::crossProduct]"
984 << " this method is only implemented in 3D." << std::endl;
985 return Vector::zero;
986 }
987 };
988
996 template <typename TInteger>
998 typedef TInteger Integer;
1000 typedef typename Space::Point Point;
1001 typedef typename Space::Vector Vector;
1004
1014 static void
1015 addEdgeConstraint( Polytope& P, unsigned int i, unsigned int j,
1016 const std::vector<Point>& pts )
1017 {
1018 Vector ab = pts[ i ] - pts[ j ];
1019 for ( int s = 0; s < 2; s++ )
1020 for ( Dimension k = 0; k < dimension; ++k )
1021 {
1022 Vector n = ab.crossProduct( Point::base( k, (s == 0) ? 1 : -1 ) );
1023 Integer b = n.dot( pts[ i ] );
1024 std::size_t nb_in = 0;
1025 for ( auto p : pts ) {
1026 Integer v = n.dot( p );
1027 if ( v < b ) nb_in++;
1028 }
1029 if ( nb_in == pts.size() - 2 ) {
1030 P.cut( n, b, true, true );
1031 }
1032 }
1033 }
1038 static
1039 Vector crossProduct( const Vector& v1, const Vector& v2 )
1040 {
1041 return v1.crossProduct( v2 );
1042 }
1043 };
1044 }
1045
1048
1055 template <typename TSpace>
1056 std::ostream&
1057 operator<< ( std::ostream & out,
1058 const BoundedLatticePolytope<TSpace> & object );
1059
1060
1066 template <typename TSpace>
1070
1071
1079 template <typename TSpace>
1083
1091 template <typename TSpace>
1095
1103 template <typename TSpace>
1107
1115 template <typename TSpace>
1119
1127 template <typename TSpace>
1131
1139 template <typename TSpace>
1143
1151 template <typename TSpace>
1155
1163 template <typename TSpace>
1167
1169
1170} // namespace DGtal
1171
1172
1174// Includes inline functions.
1175#include "BoundedLatticePolytope.ih"
1176
1177// //
1179
1180#endif // !defined BoundedLatticePolytope_h
1181
1182#undef BoundedLatticePolytope_RECURSES
1183#endif // else defined(BoundedLatticePolytope_RECURSES)
Aim: Represents an nD lattice polytope, i.e. a convex polyhedron bounded with vertices with integer c...
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)
std::vector< bool > I
Are inequalities large ?
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
Self & operator+=(StrictUnitCell c)
void setStrict(unsigned int i)
Integer countWithinByScanning(Point low, Point hi) const
InequalityMatrix A
The matrix A in the polytope representation .
Self & operator+=(StrictUnitSegment s)
bool isBoundary(const Point &p) const
const Domain & getDomain() const
void getPointsByScanning(std::vector< Point > &pts) const
void setLarge(unsigned int i)
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)
bool myValidEdgeConstraints
Indicates if Minkowski sums with segments will be valid.
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
InequalityVector B
The vector B in the polytope representation .
static Self base(Dimension k, Component val=1)
auto crossProduct(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::crossProduct(*this, v))
Cross product with a PointVector.
static Self zero
Static const for zero PointVector.
static const Dimension dimension
static constants to store the dimension.
Definition SpaceND.h:132
std::ostream & error()
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)
boost::int64_t int64_t
signed 94-bit integer.
Definition BasicTypes.h:74
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
Circulator< TIterator > operator+(typename IteratorCirculatorTraits< TIterator >::Difference d, Circulator< TIterator > &object)
Definition Circulator.h:453
DGtal::uint32_t Dimension
Definition Common.h:136
Trace trace
Definition Common.h:153
mpz_class BigInteger
Multi-precision integer with GMP implementation.
Definition BasicTypes.h:79
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)
StrictUnitCell(std::initializer_list< Dimension > l)
friend std::ostream & operator<<(std::ostream &out, const StrictUnitCell &object)
friend std::ostream & operator<<(std::ostream &out, const UnitCell &object)
UnitCell(std::initializer_list< Dimension > l)
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
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