DGtal  1.1.0
ChamferNorm2D.h
1 
17 #pragma once
18 
31 #if defined(ChamferNorm2D_RECURSES)
32 #error Recursive header files inclusion detected in ChamferNorm2D.h
33 #else // defined(ChamferNorm2D_RECURSES)
34 
35 #define ChamferNorm2D_RECURSES
36 
37 #if !defined ChamferNorm2D_h
38 
39 #define ChamferNorm2D_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <vector>
45 #include <algorithm>
46 #include "DGtal/base/Common.h"
47 #include "DGtal/kernel/CSpace.h"
49 
50 namespace DGtal
51 {
52  namespace experimental
53  {
55  // template class ChamferNorm2D
85  template <typename TSpace>
87  {
88  // ----------------------- Standard services ------------------------------
89  public:
90 
92  BOOST_STATIC_ASSERT( TSpace::dimension == 2 );
93 
95  typedef TSpace Space;
96 
98  typedef typename Space::Vector Vector;
100  typedef typename Space::Point Point;
101 
103  typedef std::vector< Vector > Directions;
104  typedef typename Directions::const_iterator ConstIterator;
105 
107  typedef double Value;
109  typedef typename Space::Integer RawValue;
110 
112  typedef typename Vector::Component Abscissa;
113 
114 
123  ChamferNorm2D(const unsigned int aN);
124 
138  ChamferNorm2D(const Directions &aDirectionSet,
139  const Directions &aNormalDirectionSet,
140  const Value norm = 1.0 );
141 
146 
147  /****
148  * @brief Vector comparator (1st quadrant)
149  */
151  {
152  bool operator() (const Vector& a, const Vector& b) const
153  {
154  return (( a[0]*b[1] - a[1]*b[0] ) > 0);
155  }
156  };
157 
158 
159  /****
160  * @brief Vector comparator (1st quadrant)
161  */
163  {
164  bool operator() (const Vector& a, const Vector& b) const
165  {
166  return (( a[0]*b[1] - a[1]*b[0] ) >= 0);
167  }
168  };
169 
170 
171  // ----------------------- Interface --------------------------------------
172  public:
173 
193  ConstIterator getCone(const Vector &aDirection,
194  ConstIterator aBegin ,
195  ConstIterator aEnd ) const;
196 
197 
213  ConstIterator getCone(const Vector &aDirection) const
214  {
215  return getCone(aDirection, myDirections.begin(), myDirections.end());
216  }
217 
224 
225 
234  Vector canonicalRay(const Vector &aRay) const;
235 
236  // ----------------------- CMetricSpace concept -----------------------------------
245  Value operator()(const Point &P, const Point &Q) const;
246 
257  RawValue rawDistance(const Point &P, const Point &Q) const;
258 
259 
271  DGtal::Closest closest(const Point &origin,
272  const Point &first,
273  const Point &second) const
274  {
275  Value a = this->operator()(origin,first),
276  b = this->operator()(origin,second);
277  if (a<b)
278  return ClosestFIRST;
279  else
280  if (a>b)
281  return ClosestSECOND;
282  else
283  return ClosestBOTH;
284  }
285 
290  ChamferNorm2D ( const ChamferNorm2D & other )
291  {
292  this->myDirections = other.myDirections;
293  this->myNormals = other.myNormals;
294  }
295 
296 
303  {
304  this->myDirections = other.myDirections;
305  this->myNormals = other.myNormals;
306  return *this;
307  }
308 
309  // ----------- CSeparableMetric concept -----------------------------------
310 
330  const Point &Lmin, const Point &Lmax,
331  const Dimension aDimension) const ;
332 
352  const Point &Lmin, const Point &Lmax,
353  const Dimension aDimension) const ;
354 
355 
356 
382  ConstIterator aEnd,
383  const Point &aP, const Point &aQ,
384  const Point &Lmin, const Point &Lmax,
385  const Dimension aDimension,
386  Point &midPoint,
387  Point &nextMidPoint) const ;
388 
389 
412  ConstIterator aEnd,
413  const Point &aP, const Point &aQ,
414  const Point &Lmin, const Point &Lmax,
415  const Dimension aDimension,
416  Point &midPoint,
417  Point &nextMidPoint) const ;
418 
419 
420 
434  const Point &v,
435  const Point &startingPoint,
436  const Point &endPoint,
437  const Dimension dim) const;
438 
439 
440 
453  bool hiddenBy(const Point &u,
454  const Point &v,
455  const Point &w,
456  const Point &startingPoint,
457  const Point &endPoint,
458  const Dimension dim) const;
459 
460 
461 
462  // ------------------------- Directions iterators ------------------------------
467  {
468  return myDirections.begin();
469  }
470 
475  {
476  return myDirections.end();
477  }
478 
482  inline
483  unsigned int size() const
484  {
485  return myDirections.size();
486  }
487 
488  // ------------------------- Other services ------------------------------
493  void selfDisplay ( std::ostream & out ) const;
494 
499  bool isValid() const;
500 
501 
502  // ------------------------- Hidden services ------------------------------
503  protected:
504 
510 
511  // ------------------------- Internals ------------------------------------
512  private:
513 
516 
519 
522 
524  BOOST_STATIC_CONSTANT(Abscissa, myInfinity = 32562);
525 
528 
529  }; // end of class ChamferNorm2D
530 
531  }//namespace experimental
532 
539  template <typename T>
540  std::ostream&
541  operator<< ( std::ostream & out,
542  const experimental::ChamferNorm2D<T> & object );
543 
544 } // namespace DGtal
545 
546 
548 // Includes inline functions.
549 #include "DGtal/geometry/volumes/distance//ChamferNorm2D.ih"
550 
551 // //
553 
554 #endif // !defined ChamferNorm2D_h
555 
556 #undef ChamferNorm2D_RECURSES
557 #endif // else defined(ChamferNorm2D_RECURSES)
DGtal::experimental::ChamferNorm2D::shrinkPSubMask
ConstIterator shrinkPSubMask(ConstIterator aBegin, ConstIterator aEnd, const Point &aP, const Point &aQ, const Point &Lmin, const Point &Lmax, const Dimension aDimension, Point &midPoint, Point &nextMidPoint) const
DGtal::experimental::ChamferNorm2D::~ChamferNorm2D
~ChamferNorm2D()
DGtal::experimental::ChamferNorm2D::operator=
ChamferNorm2D< Space > & operator=(const ChamferNorm2D< Space > &other)
Definition: ChamferNorm2D.h:302
DGtal::concepts::CSpace
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:106
DGtal::experimental::ChamferNorm2D
Aim: implements a model of CSeparableMetric for Chamfer and path based norms.
Definition: ChamferNorm2D.h:87
DGtal::experimental::ChamferNorm2D::LessOrEqThanAngular
Definition: ChamferNorm2D.h:163
DGtal::experimental::ChamferNorm2D::begin
ConstIterator begin()
Definition: ChamferNorm2D.h:466
DGtal::experimental::ChamferNorm2D::myDirections
Directions myDirections
Mask container.
Definition: ChamferNorm2D.h:515
DGtal::experimental::ChamferNorm2D::ChamferNorm2D
ChamferNorm2D(const ChamferNorm2D &other)
Definition: ChamferNorm2D.h:290
DGtal::Dimension
DGtal::uint32_t Dimension
Definition: Common.h:133
DGtal::experimental::ChamferNorm2D::LessOrEqThanAngular::operator()
bool operator()(const Vector &a, const Vector &b) const
Definition: ChamferNorm2D.h:164
dim
unsigned int dim(const Vector &z)
Definition: viewDualSurface.cpp:174
DGtal::experimental::ChamferNorm2D::Point
Space::Point Point
Type for points.
Definition: ChamferNorm2D.h:100
DGtal::experimental::ChamferNorm2D::getCone
ConstIterator getCone(const Vector &aDirection) const
Definition: ChamferNorm2D.h:213
DGtal::Closest
Closest
Definition: Common.h:143
DGtal::experimental::ChamferNorm2D::Vector
Space::Vector Vector
Type for vectors.
Definition: ChamferNorm2D.h:98
DGtal::experimental::ChamferNorm2D::myNorm
Value myNorm
Normalization factor.
Definition: ChamferNorm2D.h:527
DGtal::experimental::ChamferNorm2D::getLowerRayIntersection
Abscissa getLowerRayIntersection(const Vector &aP, const Vector &aQ, const Point &Lmin, const Point &Lmax, const Dimension aDimension) const
DGtal::experimental::ChamferNorm2D::end
ConstIterator end()
Definition: ChamferNorm2D.h:474
DGtal::experimental::ChamferNorm2D::Directions
std::vector< Vector > Directions
Container for set of directions.
Definition: ChamferNorm2D.h:103
DGtal::experimental::ChamferNorm2D::myNormals
Directions myNormals
Normal to cone container.
Definition: ChamferNorm2D.h:518
DGtal::ClosestBOTH
@ ClosestBOTH
Definition: Common.h:143
DGtal::PointVector< dim, Integer >::Component
Integer Component
Type for Vector elements.
Definition: PointVector.h:614
DGtal::experimental::ChamferNorm2D::LessThanAngular::operator()
bool operator()(const Vector &a, const Vector &b) const
Definition: ChamferNorm2D.h:152
DGtal::experimental::ChamferNorm2D::getLowerVoronoiEdgeAbscissa
Abscissa getLowerVoronoiEdgeAbscissa(const Point &u, const Point &v, const Point &startingPoint, const Point &endPoint, const Dimension dim) const
DGtal::experimental::ChamferNorm2D::getUpperRayIntersection
Abscissa getUpperRayIntersection(const Vector &aP, const Vector &aQ, const Point &Lmin, const Point &Lmax, const Dimension aDimension) const
DGtal::experimental::ChamferNorm2D::LessThanAngular
Definition: ChamferNorm2D.h:151
DGtal::experimental::ChamferNorm2D::Value
double Value
Value type for embedded distance evaluation.
Definition: ChamferNorm2D.h:107
DGtal::experimental::ChamferNorm2D::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(Abscissa, myInfinity=32562)
Static constant.
DGtal::experimental::ChamferNorm2D::Abscissa
Vector::Component Abscissa
Vector components type.
Definition: ChamferNorm2D.h:112
DGtal::experimental::ChamferNorm2D::Space
TSpace Space
Underlying Space.
Definition: ChamferNorm2D.h:95
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::experimental::ChamferNorm2D::rawDistance
RawValue rawDistance(const Point &P, const Point &Q) const
DGtal::experimental::ChamferNorm2D::isValid
bool isValid() const
DGtal::experimental::ChamferNorm2D::hiddenBy
bool hiddenBy(const Point &u, const Point &v, const Point &w, const Point &startingPoint, const Point &endPoint, const Dimension dim) const
DGtal::experimental::ChamferNorm2D::operator()
Value operator()(const Point &P, const Point &Q) const
DGtal::experimental::ChamferNorm2D::BOOST_STATIC_ASSERT
BOOST_STATIC_ASSERT(TSpace::dimension==2)
DGtal::experimental::ChamferNorm2D::getCone
ConstIterator getCone(const Vector &aDirection, ConstIterator aBegin, ConstIterator aEnd) const
DGtal::experimental::ChamferNorm2D::RawValue
Space::Integer RawValue
Value type for exact distance evaluation.
Definition: ChamferNorm2D.h:109
DGtal::experimental::ChamferNorm2D::canonicalRay
Vector canonicalRay(const Vector &aRay) const
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::ClosestFIRST
@ ClosestFIRST
Definition: Common.h:143
DGtal::experimental::ChamferNorm2D::myLessThanAngular
LessThanAngular myLessThanAngular
Instance of comparator functor.
Definition: ChamferNorm2D.h:521
DGtal::experimental::ChamferNorm2D::ChamferNorm2D
ChamferNorm2D()
DGtal::experimental::ChamferNorm2D::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
DGtal::experimental::ChamferNorm2D::ChamferNorm2D
ChamferNorm2D(const Directions &aDirectionSet, const Directions &aNormalDirectionSet, const Value norm=1.0)
DGtal::PointVector< dim, Integer >
DGtal::experimental::ChamferNorm2D::size
unsigned int size() const
Definition: ChamferNorm2D.h:483
DGtal::ClosestSECOND
@ ClosestSECOND
Definition: Common.h:143
DGtal::experimental::ChamferNorm2D::shrinkP
ConstIterator shrinkP(ConstIterator aBegin, ConstIterator aEnd, const Point &aP, const Point &aQ, const Point &Lmin, const Point &Lmax, const Dimension aDimension, Point &midPoint, Point &nextMidPoint) const
DGtal::experimental::ChamferNorm2D::closest
DGtal::Closest closest(const Point &origin, const Point &first, const Point &second) const
Definition: ChamferNorm2D.h:271
DGtal::experimental::ChamferNorm2D::ConstIterator
Directions::const_iterator ConstIterator
Definition: ChamferNorm2D.h:104
DGtal::SpaceND::Integer
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
DGtal::experimental::ChamferNorm2D::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::experimental::ChamferNorm2D::ChamferNorm2D
ChamferNorm2D(const unsigned int aN)
DGtal::experimental::ChamferNorm2D::getNormalFromCone
Vector getNormalFromCone(ConstIterator aCone) const