DGtal 1.3.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
458 bool isKSubconvex( const Point& a, const Point& b,
459 const CellGeometry& C, const Dimension k ) const;
460
477 bool isFullySubconvex( const Point& a, const Point& b,
478 const CellGeometry& C ) const;
479
492 bool isFullySubconvex( const Point& a, const Point& b,
493 const LatticeSet& StarX ) const;
494
505 {
506 return makePolytope( X );
507 }
508
519 PointRange ExtrCvxH( const PointRange& X ) const;
520
538 Dimension axis = dimension ) const;
539
546 Integer sizeStarCvxH( const PointRange& X ) const;
547
564 Dimension axis = dimension ) const;
565
582 Dimension axis = dimension ) const;
583
588 PointRange Extr( const PointRange& C ) const;
589
594 PointRange Extr( const LatticeSet& C ) const;
595
600 LatticeSet Skel( const LatticeSet& C ) const;
601
606 PointRange ExtrSkel( const LatticeSet& C ) const;
607
623 Dimension axis = dimension ) const;
624
632
634
635 // ----------------------- Convex envelope services -----------------------------
636 public:
639
643 { DIRECT ,
645 };
646
652 FC( const PointRange& Z,
654
669
686
702 template <typename Predicate>
704 relativeEnvelope( const PointRange& Z, const Predicate& PredY,
706
711
713
714 // ----------------------- Convexity services for lattice polytopes --------------
715 public:
718
723
731 bool isKConvex( const LatticePolytope& P, const Dimension k ) const;
732
738
746 bool isFullyConvex( const LatticePolytope& P ) const;
747
753
758 bool isKSubconvex( const LatticePolytope& P, const CellGeometry& C, const Dimension k ) const;
759
765
772 bool isFullySubconvex( const LatticePolytope& P, const CellGeometry& C ) const;
773
781 bool isFullySubconvex( const LatticePolytope& P, const LatticeSet& StarX ) const;
782
783
785
786 // ----------------------- Convexity services for rational polytopes ----------------
787 public:
790
795
803 bool isKConvex( const RationalPolytope& P, const Dimension k ) const;
804
810
818 bool isFullyConvex( const RationalPolytope& P ) const;
819
825
830 bool isKSubconvex( const RationalPolytope& P, const CellGeometry& C, const Dimension k ) const;
831
837
844 bool isFullySubconvex( const RationalPolytope& P, const CellGeometry& C ) const;
845
847
848 // ----------------------- Interface --------------------------------------
849 public:
852
857 void selfDisplay ( std::ostream & out ) const;
858
865 bool isValid() const;
866
868
869 // ------------------------- Protected Datas ------------------------------
870 protected:
873
877 bool mySafe;
878
881
882 // ------------------------- Private Datas --------------------------------
883 private:
884
885
886 // ------------------------- Internals ------------------------------------
887 private:
888
892 PointRange FC_direct( const PointRange& Z ) const;
893
898
904 static void eraseInterval( Interval I, std::vector< Interval > & V );
905
913 template <typename Predicate>
914 static PointRange filter( const PointRange& E, const Predicate& Pred );
915
916 }; // end of class DigitalConvexity
917
920
927 template <typename TKSpace>
928 std::ostream&
929 operator<< ( std::ostream & out,
930 const DigitalConvexity<TKSpace> & object );
931
933
934} // namespace DGtal
935
936
938// Includes inline functions.
939#include "DigitalConvexity.ih"
940
941// //
943
944#endif // !defined DigitalConvexity_h
945
946#undef DigitalConvexity_RECURSES
947#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:267
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)
PointRange Extr(const LatticeSet &C) const
static bool isSimplexFullDimensional(std::initializer_list< Point > l)
LatticeSet toLatticeSet(const PointRange &X, Dimension axis=dimension) 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)
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)
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 >))
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
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
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)
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:137
Aim: This concept describes a cellular grid space in nD. In these spaces obtained by cartesian produc...
KSpace K