DGtal  0.9.2
DigitalMetricAdapter.h
1 
17 #pragma once
18 
31 #if defined(DigitalMetricAdapter_RECURSES)
32 #error Recursive header files inclusion detected in DigitalMetricAdapter.h
33 #else // defined(DigitalMetricAdapter_RECURSES)
34 
35 #define DigitalMetricAdapter_RECURSES
36 
37 #if !defined DigitalMetricAdapter_h
38 
39 #define DigitalMetricAdapter_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/geometry/volumes/distance/CMetricSpace.h"
46 #include "DGtal/kernel/CInteger.h"
47 #include "DGtal/base/ConstAlias.h"
48 #include "DGtal/kernel/NumberTraits.h"
50 
51 namespace DGtal
52 {
53 
55  // template class DigitalMetricAdapter
70  template <typename TMetric, typename TInteger = typename TMetric::Space::Integer>
72  {
73  // ----------------------- Standard services ------------------------------
74  public:
75 
77  typedef TMetric Metric;
79 
81  typedef TInteger Value;
83 
84  // ----------------------- CDigitalMetric------------------------------------
86  typedef typename Metric::Point Point;
87 
89  typedef typename Metric::Space Space;
90 
92  typedef Value RawValue;
93 
94 
101  myMetric(&aMetric) {}
102 
103 
110  {
111  if (this != &anotherMetric)
112  this->myMetric = anotherMetric.myMetric;
113  }
114 
115 
120 
121  // ----------------------- Interface --------------------------------------
122  public:
123 
124  // ----------------------- CDigitalMetricSpace --------------------------------------
125 
132  {
133  myMetric = other.myMetric;
134  return *this;
135  }
136 
144  Value operator() (const Point &p, const Point &q) const
145  {
146  return static_cast<Value>( std::ceil ( NumberTraits<typename Metric::Value>::castToDouble( myMetric->operator()(p,q))));
147  }
148 
156  Value rawDistance(const Point &p, const Point &q) const
157  {
158  return this->operator()(p,q);
159  }
160 
169  DGtal::Closest closest(const Point &a,
170  const Point &p,
171  const Point &q) const
172  {
173  if (this->operator()(a,p) < this->operator()(a,q))
174  return DGtal::ClosestFIRST;
175  if (this->operator()(a,p) > this->operator()(a,q))
176  return DGtal::ClosestSECOND;
177  return DGtal::ClosestBOTH;
178  }
179 
180 
181 
186  void selfDisplay ( std::ostream & out ) const
187  {
188  out << "[DigitalMetricAdapter] adapted from "<< *myMetric;
189  }
190 
195  bool isValid() const { return (myMetric != NULL); }
196 
197  // ------------------------- Protected Datas ------------------------------
198  private:
199  // ------------------------- Private Datas --------------------------------
200  private:
201 
202  const Metric *myMetric;
203 
204  // ------------------------- Hidden services ------------------------------
205  protected:
206 
212 
213  // ------------------------- Internals ------------------------------------
214  private:
215 
216  }; // end of class DigitalMetricAdapter
217 
218 
225  template <typename T>
226  std::ostream&
227  operator<< ( std::ostream & out, const DigitalMetricAdapter<T> & object );
228 
229 } // namespace DGtal
230 
231 // //
233 
234 #endif // !defined DigitalMetricAdapter_h
235 
236 #undef DigitalMetricAdapter_RECURSES
237 #endif // else defined(DigitalMetricAdapter_RECURSES)
DigitalMetricAdapter(const DigitalMetricAdapter &anotherMetric)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
Value rawDistance(const Point &p, const Point &q) const
DigitalMetricAdapter & operator=(const DigitalMetricAdapter &other)
void selfDisplay(std::ostream &out) const
DGtal::Closest closest(const Point &a, const Point &p, const Point &q) const
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:87
BOOST_CONCEPT_ASSERT((concepts::CMetricSpace< Metric >))
DigitalMetricAdapter(ConstAlias< Metric > aMetric)
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:69
Aim: simple adapter class which adapts any models of concepts::CMetricSpace to a model of concepts::C...
Metric::Point Point
Point type.
DGtal is the top-level namespace which contains all DGtal functions and types.
Metric::Space Space
Space type.
Aim: defines the concept of metric spaces.
Definition: CMetricSpace.h:124
TMetric Metric
Input metric type.
TInteger Value
Values are integer numbers.
Value operator()(const Point &p, const Point &q) const
Closest
Definition: Common.h:123