DGtal  1.1.0
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 
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)
DGtal::ConstAlias
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
DGtal::DigitalMetricAdapter
Aim: simple adapter class which adapts any models of concepts::CMetricSpace to a model of concepts::C...
Definition: DigitalMetricAdapter.h:72
DGtal::concepts::CInteger
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:88
DGtal::NumberTraits
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:533
DGtal::DigitalMetricAdapter::closest
DGtal::Closest closest(const Point &a, const Point &p, const Point &q) const
Definition: DigitalMetricAdapter.h:169
DGtal::DigitalMetricAdapter::selfDisplay
void selfDisplay(std::ostream &out) const
Definition: DigitalMetricAdapter.h:186
DGtal::DigitalMetricAdapter::DigitalMetricAdapter
DigitalMetricAdapter(ConstAlias< Metric > aMetric)
Definition: DigitalMetricAdapter.h:100
DGtal::Closest
Closest
Definition: Common.h:143
DGtal::DigitalMetricAdapter::myMetric
const Metric * myMetric
Definition: DigitalMetricAdapter.h:202
DGtal::ClosestBOTH
@ ClosestBOTH
Definition: Common.h:143
DGtal::DigitalMetricAdapter::operator=
DigitalMetricAdapter & operator=(const DigitalMetricAdapter &other)
Definition: DigitalMetricAdapter.h:131
DGtal::DigitalMetricAdapter::Point
Metric::Point Point
Point type.
Definition: DigitalMetricAdapter.h:86
DGtal::DigitalMetricAdapter::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CMetricSpace< Metric >))
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::DigitalMetricAdapter::DigitalMetricAdapter
DigitalMetricAdapter()
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::DigitalMetricAdapter::Space
Metric::Space Space
Space type.
Definition: DigitalMetricAdapter.h:89
DGtal::ClosestFIRST
@ ClosestFIRST
Definition: Common.h:143
DGtal::concepts::CMetricSpace
Aim: defines the concept of metric spaces.
Definition: CMetricSpace.h:125
DGtal::DigitalMetricAdapter::Metric
TMetric Metric
Input metric type.
Definition: DigitalMetricAdapter.h:77
DGtal::DigitalMetricAdapter::operator()
Value operator()(const Point &p, const Point &q) const
Definition: DigitalMetricAdapter.h:144
DGtal::DigitalMetricAdapter::isValid
bool isValid() const
Definition: DigitalMetricAdapter.h:195
Space
SpaceND< 2 > Space
Definition: testSimpleRandomAccessRangeFromPoint.cpp:42
DGtal::DigitalMetricAdapter::~DigitalMetricAdapter
~DigitalMetricAdapter()
Definition: DigitalMetricAdapter.h:119
DGtal::ClosestSECOND
@ ClosestSECOND
Definition: Common.h:143
DGtal::DigitalMetricAdapter::RawValue
Value RawValue
RawValue type.
Definition: DigitalMetricAdapter.h:92
DGtal::DigitalMetricAdapter::Value
TInteger Value
Values are integer numbers.
Definition: DigitalMetricAdapter.h:81
DGtal::DigitalMetricAdapter::DigitalMetricAdapter
DigitalMetricAdapter(const DigitalMetricAdapter &anotherMetric)
Definition: DigitalMetricAdapter.h:109
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::DigitalMetricAdapter::rawDistance
Value rawDistance(const Point &p, const Point &q) const
Definition: DigitalMetricAdapter.h:156
DGtal::DigitalMetricAdapter::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CInteger< Value >))