DGtal  1.5.beta
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 
59 namespace 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;
94  typedef std::vector<Point> PointRange;
95  typedef std::unordered_set<Point> PointSet;
97  typedef typename Counter::Interval Interval;
99 
100  static const Dimension dimension = KSpace::dimension;
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,
239  DEGENERATED,
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 
458 
476  bool isKSubconvex( const Point& a, const Point& b,
477  const CellGeometry& C, const Dimension k ) const;
478 
495  bool isFullySubconvex( const Point& a, const Point& b,
496  const CellGeometry& C ) const;
497 
510  bool isFullySubconvex( const Point& a, const Point& b,
511  const LatticeSet& StarX ) const;
512 
522  LatticePolytope CvxH( const PointRange& X ) const
523  {
524  return makePolytope( X );
525  }
526 
537  PointRange ExtrCvxH( const PointRange& X ) const;
538 
556  Dimension axis = dimension ) const;
557 
579  LatticeSet StarCvxH( const Point& a, const Point& b, const Point& c,
580  Dimension axis = dimension ) const;
581 
588  Integer sizeStarCvxH( const PointRange& X ) const;
589 
606  Dimension axis = dimension ) const;
607 
624  Dimension axis = dimension ) const;
625 
630  PointRange Extr( const PointRange& C ) const;
631 
636  PointRange Extr( const LatticeSet& C ) const;
637 
642  LatticeSet Skel( const LatticeSet& C ) const;
643 
648  PointRange ExtrSkel( const LatticeSet& C ) const;
649 
665  Dimension axis = dimension ) const;
666 
673  PointRange toPointRange( const LatticeSet& L ) const;
674 
676 
677  // ----------------------- Convex envelope services -----------------------------
678  public:
681 
684  enum class EnvelopeAlgorithm
685  { DIRECT ,
686  LATTICE_SET
687  };
688 
693  PointRange
694  FC( const PointRange& Z,
696 
708  PointRange
709  envelope( const PointRange& Z,
711 
725  PointRange
728 
744  template <typename Predicate>
745  PointRange
746  relativeEnvelope( const PointRange& Z, const Predicate& PredY,
748 
753 
755 
756  // ----------------------- Convexity services for lattice polytopes --------------
757  public:
760 
765 
773  bool isKConvex( const LatticePolytope& P, const Dimension k ) const;
774 
780 
788  bool isFullyConvex( const LatticePolytope& P ) const;
789 
795 
800  bool isKSubconvex( const LatticePolytope& P, const CellGeometry& C, const Dimension k ) const;
801 
807 
814  bool isFullySubconvex( const LatticePolytope& P, const CellGeometry& C ) const;
815 
823  bool isFullySubconvex( const LatticePolytope& P, const LatticeSet& StarX ) const;
824 
825 
827 
828  // ----------------------- Convexity services for rational polytopes ----------------
829  public:
832 
837 
845  bool isKConvex( const RationalPolytope& P, const Dimension k ) const;
846 
852 
860  bool isFullyConvex( const RationalPolytope& P ) const;
861 
867 
872  bool isKSubconvex( const RationalPolytope& P, const CellGeometry& C, const Dimension k ) const;
873 
879 
886  bool isFullySubconvex( const RationalPolytope& P, const CellGeometry& C ) const;
887 
889 
890  // ----------------------- Interface --------------------------------------
891  public:
894 
899  void selfDisplay ( std::ostream & out ) const;
900 
907  bool isValid() const;
908 
910 
911  // ------------------------- Protected Datas ------------------------------
912  protected:
915 
919  bool mySafe;
920 
923 
924  // ------------------------- Private Datas --------------------------------
925  private:
926 
927 
928  // ------------------------- Internals ------------------------------------
929  private:
930 
934  PointRange FC_direct( const PointRange& Z ) const;
935 
940 
946  static void eraseInterval( Interval I, std::vector< Interval > & V );
947 
955  template <typename Predicate>
956  static PointRange filter( const PointRange& E, const Predicate& Pred );
957 
958  }; // end of class DigitalConvexity
959 
962 
969  template <typename TKSpace>
970  std::ostream&
971  operator<< ( std::ostream & out,
972  const DigitalConvexity<TKSpace> & object );
973 
975 
976 } // namespace DGtal
977 
978 
980 // Includes inline functions.
981 #include "DigitalConvexity.ih"
982 
983 // //
985 
986 #endif // !defined DigitalConvexity_h
987 
988 #undef DigitalConvexity_RECURSES
989 #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)
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 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
Self & operator=(const Self &other)=default
static void eraseInterval(Interval I, std::vector< Interval > &V)
bool isFullySubconvex(const Point &a, const Point &b, const Point &c, const LatticeSet &StarX) 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)
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
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
const KSpace & space() const
KSpace myK
The cellular grid space where computations are done.
Size depthLastEnvelope() const
DGtal::BoundedLatticePolytopeCounter< Space > Counter
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.
std::vector< Point > PointRange
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::uint32_t Dimension
Definition: Common.h:136
Aim: This concept describes a cellular grid space in nD. In these spaces obtained by cartesian produc...
KSpace K