DGtal  1.5.beta
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)
35 #define ChamferNorm2D_RECURSES
36 
37 #if !defined ChamferNorm2D_h
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)
Integer Component
Type for Vector elements.
Definition: PointVector.h:614
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
Definition: SpaceND.h:102
Aim: implements a model of CSeparableMetric for Chamfer and path based norms.
Definition: ChamferNorm2D.h:87
BOOST_STATIC_ASSERT(TSpace::dimension==2)
Abscissa getLowerRayIntersection(const Vector &aP, const Vector &aQ, const Point &Lmin, const Point &Lmax, const Dimension aDimension) const
BOOST_STATIC_CONSTANT(Abscissa, myInfinity=32562)
Static constant.
Vector getNormalFromCone(ConstIterator aCone) const
ConstIterator getCone(const Vector &aDirection) const
Directions::const_iterator ConstIterator
double Value
Value type for embedded distance evaluation.
Abscissa getLowerVoronoiEdgeAbscissa(const Point &u, const Point &v, const Point &startingPoint, const Point &endPoint, const Dimension dim) const
DGtal::Closest closest(const Point &origin, const Point &first, const Point &second) const
ChamferNorm2D(const unsigned int aN)
bool hiddenBy(const Point &u, const Point &v, const Point &w, const Point &startingPoint, const Point &endPoint, const Dimension dim) 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
Vector canonicalRay(const Vector &aRay) const
ChamferNorm2D(const Directions &aDirectionSet, const Directions &aNormalDirectionSet, const Value norm=1.0)
ChamferNorm2D< Space > & operator=(const ChamferNorm2D< Space > &other)
Directions myNormals
Normal to cone container.
Value operator()(const Point &P, const Point &Q) const
void selfDisplay(std::ostream &out) const
Space::Point Point
Type for points.
RawValue rawDistance(const Point &P, const Point &Q) const
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
TSpace Space
Underlying Space.
Definition: ChamferNorm2D.h:95
LessThanAngular myLessThanAngular
Instance of comparator functor.
ConstIterator getCone(const Vector &aDirection, ConstIterator aBegin, ConstIterator aEnd) const
Directions myDirections
Mask container.
ChamferNorm2D(const ChamferNorm2D &other)
std::vector< Vector > Directions
Container for set of directions.
Space::Vector Vector
Type for vectors.
Definition: ChamferNorm2D.h:98
Abscissa getUpperRayIntersection(const Vector &aP, const Vector &aQ, const Point &Lmin, const Point &Lmax, const Dimension aDimension) const
Value myNorm
Normalization factor.
Space::Integer RawValue
Value type for exact distance evaluation.
Vector::Component Abscissa
Vector components type.
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 is the top-level namespace which contains all DGtal functions and types.
Closest
Definition: Common.h:146
@ ClosestBOTH
Definition: Common.h:146
@ ClosestSECOND
Definition: Common.h:146
@ ClosestFIRST
Definition: Common.h:146
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::uint32_t Dimension
Definition: Common.h:136
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:106
bool operator()(const Vector &a, const Vector &b) const
bool operator()(const Vector &a, const Vector &b) const
unsigned int dim(const Vector &z)