DGtal  0.9.2
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 
145  ~ChamferNorm2D();
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 
223  Vector getNormalFromCone(ConstIterator aCone) const;
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 
329  Abscissa getLowerRayIntersection(const Vector &aP, const Vector &aQ,
330  const Point &Lmin, const Point &Lmax,
331  const Dimension aDimension) const ;
332 
351  Abscissa getUpperRayIntersection(const Vector &aP, const Vector &aQ,
352  const Point &Lmin, const Point &Lmax,
353  const Dimension aDimension) const ;
354 
355 
356 
381  ConstIterator shrinkPSubMask(ConstIterator aBegin,
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 
411  ConstIterator shrinkP(ConstIterator aBegin,
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 
433  Abscissa getLowerVoronoiEdgeAbscissa(const Point &u,
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 ------------------------------
466  ConstIterator begin()
467  {
468  return myDirections.begin();
469  }
470 
474  ConstIterator end()
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 
509  ChamferNorm2D();
510 
511  // ------------------------- Internals ------------------------------------
512  private:
513 
515  Directions myDirections;
516 
518  Directions myNormals;
519 
522 
524  BOOST_STATIC_CONSTANT(Abscissa, myInfinity = 32562);
525 
527  Value myNorm;
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)
ChamferNorm2D< Space > & operator=(const ChamferNorm2D< Space > &other)
Directions myNormals
Normal to cone container.
Value myNorm
Normalization factor.
Space::Integer RawValue
Value type for exact distance evaluation.
Space::Vector Vector
Type for vectors.
Definition: ChamferNorm2D.h:98
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::uint32_t Dimension
Definition: Common.h:113
Vector::Component Abscissa
Vector components type.
ConstIterator getCone(const Vector &aDirection, ConstIterator aBegin, ConstIterator aEnd) const
void selfDisplay(std::ostream &out) const
bool operator()(const Vector &a, const Vector &b) const
DGtal::Closest closest(const Point &origin, const Point &first, const Point &second) const
Abscissa getUpperRayIntersection(const Vector &aP, const Vector &aQ, const Point &Lmin, const Point &Lmax, const Dimension aDimension) const
Directions::const_iterator ConstIterator
Directions myDirections
Mask container.
RawValue rawDistance(const Point &P, const Point &Q) const
TSpace Space
Underlying Space.
Definition: ChamferNorm2D.h:95
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
BOOST_STATIC_CONSTANT(Abscissa, myInfinity=32562)
Static constant.
double Value
Value type for embedded distance evaluation.
bool operator()(const Vector &a, const Vector &b) const
Aim: implements a model of CSeparableMetric for Chamfer and path based norms.
Definition: ChamferNorm2D.h:86
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines...
Definition: CSpace.h:105
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
LessThanAngular myLessThanAngular
Instance of comparator functor.
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
BOOST_STATIC_ASSERT(TSpace::dimension==2)
Space::Point Point
Type for points.
std::vector< Vector > Directions
Container for set of directions.
DGtal is the top-level namespace which contains all DGtal functions and types.
bool hiddenBy(const Point &u, const Point &v, const Point &w, const Point &startingPoint, const Point &endPoint, const Dimension dim) const
Abscissa getLowerRayIntersection(const Vector &aP, const Vector &aQ, const Point &Lmin, const Point &Lmax, const Dimension aDimension) const
Vector canonicalRay(const Vector &aRay) const
Value operator()(const Point &P, const Point &Q) const
ChamferNorm2D(const ChamferNorm2D &other)
Abscissa getLowerVoronoiEdgeAbscissa(const Point &u, const Point &v, const Point &startingPoint, const Point &endPoint, const Dimension dim) const
Vector getNormalFromCone(ConstIterator aCone) const
ConstIterator getCone(const Vector &aDirection) const
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
Integer Component
Type for Vector elements.
Definition: PointVector.h:155
Closest
Definition: Common.h:123