DGtal 2.1.0
Loading...
Searching...
No Matches
DigitalConvexity.h
1
17#pragma once
18
31#if defined(DigitalConvexity_RECURSES)
32#error Recursive header files inclusion detected in DigitalConvexity.h
33#else // defined(DigitalConvexity_RECURSES)
35#define DigitalConvexity_RECURSES
36
37#if !defined DigitalConvexity_h
39#define DigitalConvexity_h
40
42// Inclusions
43#include <iostream>
44#include <list>
45#include <vector>
46#include <string>
47#include <unordered_set>
48#include "DGtal/base/Common.h"
49#include "DGtal/base/Clone.h"
50#include "DGtal/kernel/LatticeSetByIntervals.h"
51#include "DGtal/topology/CCellularGridSpaceND.h"
52#include "DGtal/topology/KhalimskySpaceND.h"
53#include "DGtal/geometry/volumes/BoundedLatticePolytope.h"
54#include "DGtal/geometry/volumes/BoundedLatticePolytopeCounter.h"
55#include "DGtal/geometry/volumes/BoundedRationalPolytope.h"
56#include "DGtal/geometry/volumes/CellGeometry.h"
58
59namespace DGtal
60{
61
63 // template class DigitalConvexity
76 template < typename TKSpace >
78 {
80
81 public:
83 typedef TKSpace KSpace;
84 typedef typename KSpace::Integer Integer;
85 typedef typename KSpace::Point Point;
86 typedef typename KSpace::Vector Vector;
87 typedef typename KSpace::Cell Cell;
88 typedef typename KSpace::Space Space;
89 typedef std::size_t Size;
90 typedef DGtal::BoundedLatticePolytope < Space > Polytope;
91 typedef DGtal::BoundedLatticePolytope < Space > LatticePolytope;
94 typedef std::vector<Point> PointRange;
95 typedef std::unordered_set<Point> PointSet;
97 typedef typename Counter::Interval Interval;
99
101
102
105
109 ~DigitalConvexity() = default;
110
114 DigitalConvexity() = default;
115
120 DigitalConvexity ( const Self & other ) = default;
121
129 DigitalConvexity( Clone<KSpace> K, bool safe = false );
130
139 DigitalConvexity( Point lo, Point hi, bool safe = false );
140
146 Self & operator= ( const Self & other ) = default;
147
149 const KSpace& space() const;
150
152
153 // ----------------------- Simplex services --------------------------------------
154 public:
157
167 template <typename PointIterator>
168 static
169 LatticePolytope makeSimplex( PointIterator itB, PointIterator itE );
170
178 static
179 LatticePolytope makeSimplex( std::initializer_list<Point> l );
180
195 template <typename PointIterator>
196 static
198 PointIterator itB, PointIterator itE );
199
210 static
211 RationalPolytope makeRationalSimplex( std::initializer_list<Point> l );
212
222 template <typename PointIterator>
223 static
224 bool isSimplexFullDimensional( PointIterator itB, PointIterator itE );
225
233 static
234 bool isSimplexFullDimensional( std::initializer_list<Point> l );
235
237 enum class SimplexType{
238 INVALID,
240 UNITARY,
241 COMMON
242 };
243
254 template <typename PointIterator>
255 static
256 SimplexType simplexType( PointIterator itB, PointIterator itE );
257
265 static
266 SimplexType simplexType( std::initializer_list<Point> l );
267
277 template <typename PointIterator>
278 static
279 void displaySimplex( std::ostream& out, PointIterator itB, PointIterator itE );
280
288 static
289 void displaySimplex( std::ostream& out, std::initializer_list<Point> l );
290
292
293 // ----------------------- Polytope services --------------------------------------
294 public:
297
300 static
302
305 static
307
310 static
312
315 static
317
319
320
321 // ----------------------- Cell geometry services -----------------------------------
322 public:
325
334 template <typename PointIterator>
335 CellGeometry makeCellCover( PointIterator itB, PointIterator itE,
336 Dimension i = 0,
337 Dimension k = KSpace::dimension ) const;
338
347 Dimension i = 0,
348 Dimension k = KSpace::dimension ) const;
349
358 Dimension i = 0,
359 Dimension k = KSpace::dimension ) const;
361
362 // ----------------------- Morphological services --------------------------------
363 public:
366
380 bool make_minkowski_summable = false ) const;
381
388 PointRange U( Dimension i, const PointRange& X ) const;
389
397 bool is0Convex( const PointRange& X ) const;
398
411 bool isFullyConvex( const PointRange& X, bool convex0 = false ) const;
412
425 bool isFullyConvexFast( const PointRange& X ) const;
426
439 bool isFullySubconvex( const PointRange& Y, const LatticeSet& StarX ) const;
440
441
455 bool isFullySubconvex( const Point& a, const Point& b, const Point& c,
456 const LatticeSet& StarX ) const;
457
472 bool isFullyCovered( const Point& a, const Point& b, const Point& c,
473 const LatticeSet& cells ) const;
474
488 bool isFullyCovered( const Point& a, const Point& b,
489 const LatticeSet& cells ) const;
490
491
506 bool isOpenTriangleFullySubconvex( const Point& a, const Point& b, const Point& c,
507 const LatticeSet& StarX ) const;
508
509
527 bool isKSubconvex( const Point& a, const Point& b,
528 const CellGeometry& C, const Dimension k ) const;
529
546 bool isFullySubconvex( const Point& a, const Point& b,
547 const CellGeometry& C ) const;
548
561 bool isFullySubconvex( const Point& a, const Point& b,
562 const LatticeSet& StarX ) const;
563
574 {
575 return makePolytope( X );
576 }
577
588 PointRange ExtrCvxH( const PointRange& X ) const;
589
607 Dimension axis = dimension ) const;
608
630 LatticeSet StarCvxH( const Point& a, const Point& b, const Point& c,
631 Dimension axis = dimension ) const;
632
655 LatticeSet StarOpenTriangle( const Point& a, const Point& b, const Point& c,
656 Dimension axis = dimension ) const;
657
658
665 Integer sizeStarCvxH( const PointRange& X ) const;
666
683 Dimension axis = dimension ) const;
684
701 Dimension axis = dimension ) const;
702
707 PointRange Extr( const PointRange& C ) const;
708
713 PointRange Extr( const LatticeSet& C ) const;
714
719 LatticeSet Skel( const LatticeSet& C ) const;
720
725 PointRange ExtrSkel( const LatticeSet& C ) const;
726
751 LatticeSet CoverCvxH( const Point& a, const Point& b,
752 Dimension axis = dimension ) const;
753
779 LatticeSet CoverCvxH( const Point& a, const Point& b, const Point& c,
780 Dimension axis = dimension ) const;
781
782
798 Dimension axis = dimension ) const;
799
807
809
810 // ----------------------- Convex envelope services -----------------------------
811 public:
814
818 { DIRECT ,
820 };
821
827 FC( const PointRange& Z,
829
844
861
877 template <typename Predicate>
879 relativeEnvelope( const PointRange& Z, const Predicate& PredY,
881
886
888
889 // ----------------------- Convexity services for lattice polytopes --------------
890 public:
893
898
906 bool isKConvex( const LatticePolytope& P, const Dimension k ) const;
907
913
921 bool isFullyConvex( const LatticePolytope& P ) const;
922
928
933 bool isKSubconvex( const LatticePolytope& P, const CellGeometry& C, const Dimension k ) const;
934
940
947 bool isFullySubconvex( const LatticePolytope& P, const CellGeometry& C ) const;
948
956 bool isFullySubconvex( const LatticePolytope& P, const LatticeSet& StarX ) const;
957
958
960
961 // ----------------------- Convexity services for rational polytopes ----------------
962 public:
965
970
978 bool isKConvex( const RationalPolytope& P, const Dimension k ) const;
979
985
993 bool isFullyConvex( const RationalPolytope& P ) const;
994
1000
1005 bool isKSubconvex( const RationalPolytope& P, const CellGeometry& C, const Dimension k ) const;
1006
1012
1019 bool isFullySubconvex( const RationalPolytope& P, const CellGeometry& C ) const;
1020
1022
1023 // ----------------------- Interface --------------------------------------
1024 public:
1027
1032 void selfDisplay ( std::ostream & out ) const;
1033
1040 bool isValid() const;
1041
1043
1044 // ------------------------- Protected Datas ------------------------------
1045 protected:
1048
1053
1056
1057 // ------------------------- Private Datas --------------------------------
1058 private:
1059
1060
1061 // ------------------------- Internals ------------------------------------
1062 private:
1063
1068
1073
1079 static void eraseInterval( Interval I, std::vector< Interval > & V );
1080
1088 template <typename Predicate>
1089 static PointRange filter( const PointRange& E, const Predicate& Pred );
1090
1115 template <typename TPolytope>
1116 LatticeSet CoverPolytope( const TPolytope& P,
1117 Dimension axis = dimension ) const;
1118
1119
1120
1121 }; // end of class DigitalConvexity
1122
1125
1132 template <typename TKSpace>
1133 std::ostream&
1134 operator<< ( std::ostream & out,
1135 const DigitalConvexity<TKSpace> & object );
1136
1138
1139} // namespace DGtal
1140
1141
1143// Includes inline functions.
1144#include "DigitalConvexity.ih"
1145
1146// //
1148
1149#endif // !defined DigitalConvexity_h
1150
1151#undef DigitalConvexity_RECURSES
1152#endif // else defined(DigitalConvexity_RECURSES)
Aim: Useful to compute quickly the lattice points within a polytope, i.e. a convex polyhedron.
Aim: Represents an nD lattice polytope, i.e. a convex polyhedron bounded with vertices with integer c...
Aim: Represents an nD rational polytope, i.e. a convex polyhedron bounded by vertices with rational c...
Aim: This class encapsulates its parameter class to indicate that the given parameter is required to ...
Definition Clone.h:266
Aim: A helper class to build polytopes from digital sets and to check digital k-convexity and full co...
static PointRange insidePoints(const LatticePolytope &polytope)
static RationalPolytope makeRationalSimplex(Integer d, PointIterator itB, PointIterator itE)
LatticeSet StarCvxH(const Point &a, const Point &b, const Point &c, Dimension axis=dimension) const
PointRange Extr(const LatticeSet &C) const
static bool isSimplexFullDimensional(std::initializer_list< Point > l)
LatticeSet toLatticeSet(const PointRange &X, Dimension axis=dimension) const
bool isFullyCovered(const Point &a, const Point &b, const Point &c, const LatticeSet &cells) const
bool isFullyConvex(const RationalPolytope &P) const
PointRange FC(const PointRange &Z, EnvelopeAlgorithm algo=EnvelopeAlgorithm::DIRECT) const
bool isKConvex(const LatticePolytope &P, const Dimension k) const
static bool isSimplexFullDimensional(PointIterator itB, PointIterator itE)
static LatticePolytope makeSimplex(PointIterator itB, PointIterator itE)
LatticeSet Star(const PointRange &X, Dimension axis=dimension) const
LatticeSet StarCells(const PointRange &C, Dimension axis=dimension) const
PointRange U(Dimension i, const PointRange &X) const
SimplexType
The possible types for simplices.
@ UNITARY
When its edges form a unit parallelotope (det = +/- 1)
@ INVALID
When there are not the right number of vertices.
@ DEGENERATED
When the points of the simplex are not in general position.
Integer sizeStarCvxH(const PointRange &X) const
static SimplexType simplexType(std::initializer_list< Point > l)
PointRange FC_LatticeSet(const PointRange &Z) const
static void displaySimplex(std::ostream &out, PointIterator itB, PointIterator itE)
bool isFullyConvexFast(const PointRange &X) const
LatticePolytope CvxH(const PointRange &X) const
bool isFullyConvex(const PointRange &X, bool convex0=false) const
DigitalConvexity(const Self &other)=default
PointRange ExtrCvxH(const PointRange &X) const
bool isFullySubconvex(const Point &a, const Point &b, const CellGeometry &C) const
static LatticePolytope makeSimplex(std::initializer_list< Point > l)
bool is0Convex(const PointRange &X) const
static void eraseInterval(Interval I, std::vector< Interval > &V)
bool isFullySubconvex(const Point &a, const Point &b, const Point &c, const LatticeSet &StarX) const
bool isFullyCovered(const Point &a, const Point &b, const LatticeSet &cells) const
PointRange Extr(const PointRange &C) const
Size myDepthLastFCE
The number of iterations of the last FullyConvexEnvelope operation.
CellGeometry makeCellCover(const RationalPolytope &P, Dimension i=0, Dimension k=KSpace::dimension) const
static RationalPolytope makeRationalSimplex(std::initializer_list< Point > l)
std::vector< Point > PointRange
Counter::Interval Interval
DigitalConvexity(Clone< KSpace > K, bool safe=false)
LatticeSet StarOpenTriangle(const Point &a, const Point &b, const Point &c, Dimension axis=dimension) const
DGtal::BoundedRationalPolytope< Space > RationalPolytope
bool isFullySubconvex(const Point &a, const Point &b, const LatticeSet &StarX) const
bool isFullyConvex(const LatticePolytope &P) const
DGtal::CellGeometry< KSpace > CellGeometry
bool isKSubconvex(const RationalPolytope &P, const CellGeometry &C, const Dimension k) const
static PointRange interiorPoints(const RationalPolytope &polytope)
PointRange relativeEnvelope(const PointRange &Z, const Predicate &PredY, EnvelopeAlgorithm algo=EnvelopeAlgorithm::DIRECT) const
static const Dimension dimension
bool isKSubconvex(const LatticePolytope &P, const CellGeometry &C, const Dimension k) const
PointRange envelope(const PointRange &Z, EnvelopeAlgorithm algo=EnvelopeAlgorithm::DIRECT) const
CellGeometry makeCellCover(const LatticePolytope &P, Dimension i=0, Dimension k=KSpace::dimension) const
static PointRange insidePoints(const RationalPolytope &polytope)
bool isFullySubconvex(const RationalPolytope &P, const CellGeometry &C) const
BOOST_CONCEPT_ASSERT((concepts::CCellularGridSpaceND< TKSpace >))
LatticeSet CoverPolytope(const TPolytope &P, Dimension axis=dimension) const
PointRange relativeEnvelope(const PointRange &Z, const PointRange &Y, EnvelopeAlgorithm algo=EnvelopeAlgorithm::DIRECT) const
bool isKSubconvex(const Point &a, const Point &b, const CellGeometry &C, const Dimension k) const
DigitalConvexity< TKSpace > Self
bool isKConvex(const RationalPolytope &P, const Dimension k) const
Self & operator=(const Self &other)=default
PointRange toPointRange(const LatticeSet &L) const
static PointRange filter(const PointRange &E, const Predicate &Pred)
DGtal::LatticeSetByIntervals< Space > LatticeSet
DigitalConvexity(Point lo, Point hi, bool safe=false)
DGtal::BoundedLatticePolytope< Space > LatticePolytope
bool isFullySubconvex(const LatticePolytope &P, const LatticeSet &StarX) const
LatticeSet Skel(const LatticeSet &C) const
LatticeSet CoverCvxH(const Point &a, const Point &b, Dimension axis=dimension) const
bool isFullySubconvex(const LatticePolytope &P, const CellGeometry &C) const
void selfDisplay(std::ostream &out) const
std::unordered_set< Point > PointSet
bool isFullySubconvex(const PointRange &Y, const LatticeSet &StarX) const
LatticeSet StarCvxH(const PointRange &X, Dimension axis=dimension) const
LatticeSet CoverCvxH(const Point &a, const Point &b, const Point &c, Dimension axis=dimension) const
PointRange ExtrSkel(const LatticeSet &C) const
static void displaySimplex(std::ostream &out, std::initializer_list< Point > l)
PointRange FC_direct(const PointRange &Z) const
KSpace myK
The cellular grid space where computations are done.
Size depthLastEnvelope() const
DGtal::BoundedLatticePolytopeCounter< Space > Counter
const KSpace & space() const
DGtal::BoundedLatticePolytope< Space > Polytope
LatticePolytope makePolytope(const PointRange &X, bool make_minkowski_summable=false) const
CellGeometry makeCellCover(PointIterator itB, PointIterator itE, Dimension i=0, Dimension k=KSpace::dimension) const
static SimplexType simplexType(PointIterator itB, PointIterator itE)
bool isOpenTriangleFullySubconvex(const Point &a, const Point &b, const Point &c, const LatticeSet &StarX) const
static PointRange interiorPoints(const LatticePolytope &polytope)
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
static const constexpr Dimension dimension
std::vector< Point > PointRange
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::uint32_t Dimension
Definition Common.h:119
Aim: This concept describes a cellular grid space in nD. In these spaces obtained by cartesian produc...
KSpace K