DGtal 2.1.0
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;
88 static const Dimension dimension = Space::dimension;
89
94 struct UnitSegment {
96 UnitSegment( Dimension d ) : k( d ) {}
97 };
98
107
116
125
131 struct UnitCell {
132 std::vector<Dimension> dims;
133 UnitCell( std::initializer_list<Dimension> l )
134 : dims( l.begin(), l.end() ) {}
135
142 friend std::ostream&
143 operator<< ( std::ostream & out,
144 const UnitCell & object )
145 {
146 out << "{";
147 for ( Dimension i = 0; i < object.dims.size(); ++i ) out << object.dims[ i ];
148 out << "}";
149 return out;
150 }
151 };
152
159 std::vector<Dimension> dims;
160 RightStrictUnitCell( std::initializer_list<Dimension> l )
161 : dims( l.begin(), l.end() ) {}
162
169 friend std::ostream&
170 operator<< ( std::ostream & out,
171 const RightStrictUnitCell & object )
172 {
173 out << "{";
174 for ( Dimension i = 0; i < object.dims.size(); ++i ) out << object.dims[ i ];
175 out << "}";
176 return out;
177 }
178 };
179
186 std::vector<Dimension> dims;
187 LeftStrictUnitCell( std::initializer_list<Dimension> l )
188 : dims( l.begin(), l.end() ) {}
189
196 friend std::ostream&
197 operator<< ( std::ostream & out,
198 const LeftStrictUnitCell & object )
199 {
200 out << "{";
201 for ( Dimension i = 0; i < object.dims.size(); ++i ) out << object.dims[ i ];
202 out << "}";
203 return out;
204 }
205 };
206
213 std::vector<Dimension> dims;
214 StrictUnitCell( std::initializer_list<Dimension> l )
215 : dims( l.begin(), l.end() ) {}
216
223 friend std::ostream&
224 operator<< ( std::ostream & out,
225 const StrictUnitCell & object )
226 {
227 out << "{";
228 for ( Dimension i = 0; i < object.dims.size(); ++i ) out << object.dims[ i ];
229 out << "}";
230 return out;
231 }
232 };
233
236
241
246
251 BoundedLatticePolytope ( const Self & other ) = default;
252
253
260 BoundedLatticePolytope( std::initializer_list<Point> l );
261
270 template <typename PointIterator>
271 BoundedLatticePolytope( PointIterator itB, PointIterator itE );
272
292 template <typename HalfSpaceIterator>
294 HalfSpaceIterator itB, HalfSpaceIterator itE,
295 bool valid_edge_constraints = false,
296 bool check_duplicate_constraints = false );
297
317 template <typename HalfSpaceIterator>
318 void init( const Domain& domain,
319 HalfSpaceIterator itB, HalfSpaceIterator itE,
320 bool valid_edge_constraints = false,
321 bool check_duplicate_constraints = false );
322
323
336 template <typename PointIterator>
337 bool init( PointIterator itB, PointIterator itE );
338
344 Self & operator= ( const Self & other ) = default;
345
347 void clear();
348
352
356
358
359 // ----------------------- Accessor services ------------------------------
360 public:
363
365 const Domain& getDomain() const;
366
368 unsigned int nbHalfSpaces() const;
369
375 const Vector& getA( unsigned int i ) const;
376
382 Integer getB( unsigned int i ) const;
383
389 bool isLarge( unsigned int i ) const;
390
395 void setLarge( unsigned int i );
396
401 void setStrict( unsigned int i );
402
404 const InequalityMatrix& getA() const;
405
407 const InequalityVector& getB() const;
411 const std::vector<bool>& getI() const;
412
417 bool canBeSummed() const;
418
420
421 // ----------------------- Check point services ------------------------------
422 public:
423
426
431 bool isInside( const Point& p ) const;
432
439 bool isDomainPointInside( const Point& p ) const;
440
445 bool isInterior( const Point& p ) const;
446
451 bool isBoundary( const Point& p ) const;
452
454
455 // ----------------------- Modification services ------------------------------
456 public:
457
460
461
474 unsigned int cut( Dimension k, bool pos, Integer b, bool large = true );
475
493 unsigned int cut( const Vector& a, Integer b, bool large = true,
494 bool valid_edge_constraint = false );
495
512 unsigned int cut( const HalfSpace & hs, bool large = true,
513 bool valid_edge_constraint = false );
514
520
521
528
536
544
552
560
568
576
584
593
594 // ----------------------- Enumeration services ------------------------------
595 public:
596
599
608 Integer count() const;
609
622
635
647 Integer countWithin( Point low, Point hi ) const;
648
667
677 void getPoints( std::vector<Point>& pts ) const;
678
693 void getKPoints( std::vector<Point>& pts, const Point& alpha_shift ) const;
694
704 void getInteriorPoints( std::vector<Point>& pts ) const;
705
715 void getBoundaryPoints( std::vector<Point>& pts ) const;
716
728 template <typename PointSet>
729 void insertPoints( PointSet& pts_set ) const;
730
747 template <typename PointSet>
748 void insertKPoints( PointSet& pts_set, const Point& alpha_shift ) const;
749
751
752 // -------------- Enumeration services (old methods by scanning ) --------------
753 public:
754
757
766
778
790
802
820
829 void getPointsByScanning( std::vector<Point>& pts ) const;
830
839 void getInteriorPointsByScanning( std::vector<Point>& pts ) const;
840
849 void getBoundaryPointsByScanning( std::vector<Point>& pts ) const;
850
861 template <typename PointSet>
862 void insertPointsByScanning( PointSet& pts_set ) const;
863
865
866
867 // ----------------------- Interface --------------------------------------
868 public:
871
876 void selfDisplay ( std::ostream & out ) const;
877
884 bool isValid() const;
885
889 std::string className() const;
890
892
893 // ------------------------- Protected Datas ------------------------------
894 protected:
902 std::vector<bool> I;
905
906 // ------------------------- Private Datas --------------------------------
907 private:
908
909
910 // ------------------------- Internals ------------------------------------
911 private:
919
926
933
934 }; // end of class BoundedLatticePolytope
935
936 namespace detail {
945 template <DGtal::Dimension N, typename TInteger>
947 typedef TInteger Integer;
949 typedef typename Space::Point Point;
950 typedef typename Space::Vector Vector;
953
966 static void
967 addEdgeConstraint( Polytope& , unsigned int , unsigned int ,
968 const std::vector<Point>& )
969 {
970 trace.error() << "[BoundedLatticePolytopeHelper::addEdgeConstraint]"
971 << " this method is only implemented in 3D." << std::endl;
972 }
973
976 static
977 Vector crossProduct( const Vector& , const Vector& )
978 {
979 trace.error() << "[BoundedLatticePolytopeHelper::crossProduct]"
980 << " this method is only implemented in 3D." << std::endl;
981 return Vector::zero;
982 }
983 };
984
992 template <typename TInteger>
994 typedef TInteger Integer;
996 typedef typename Space::Point Point;
997 typedef typename Space::Vector Vector;
1000
1010 static void
1011 addEdgeConstraint( Polytope& P, unsigned int i, unsigned int j,
1012 const std::vector<Point>& pts )
1013 {
1014 Vector ab = pts[ i ] - pts[ j ];
1015 for ( int s = 0; s < 2; s++ )
1016 for ( Dimension k = 0; k < dimension; ++k )
1017 {
1018 Vector n = ab.crossProduct( Point::base( k, (s == 0) ? 1 : -1 ) );
1019 Integer b = n.dot( pts[ i ] );
1020 std::size_t nb_in = 0;
1021 for ( auto p : pts ) {
1022 Integer v = n.dot( p );
1023 if ( v < b ) nb_in++;
1024 }
1025 if ( nb_in == pts.size() - 2 ) {
1026 P.cut( n, b, true, true );
1027 }
1028 }
1029 }
1034 static
1035 Vector crossProduct( const Vector& v1, const Vector& v2 )
1036 {
1037 return v1.crossProduct( v2 );
1038 }
1039 };
1040 }
1041
1044
1051 template <typename TSpace>
1052 std::ostream&
1053 operator<< ( std::ostream & out,
1054 const BoundedLatticePolytope<TSpace> & object );
1055
1056
1062 template <typename TSpace>
1066
1067
1075 template <typename TSpace>
1079
1087 template <typename TSpace>
1091
1099 template <typename TSpace>
1103
1111 template <typename TSpace>
1115
1123 template <typename TSpace>
1127
1135 template <typename TSpace>
1139
1147 template <typename TSpace>
1151
1159 template <typename TSpace>
1163
1165
1166} // namespace DGtal
1167
1168
1170// Includes inline functions.
1171#include "BoundedLatticePolytope.ih"
1172
1173// //
1175
1176#endif // !defined BoundedLatticePolytope_h
1177
1178#undef BoundedLatticePolytope_RECURSES
1179#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 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.
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)
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)
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