DGtal 1.3.0
Loading...
Searching...
No Matches
LpMetric.h
1
17#pragma once
18
30#if defined(LpMetric_RECURSES)
31#error Recursive header files inclusion detected in LpMetric.h
32#else // defined(LpMetric_RECURSES)
34#define LpMetric_RECURSES
35
36#if !defined LpMetric_h
38#define LpMetric_h
39
41// Inclusions
42#include <iostream>
43#include <cmath>
44#include "DGtal/base/Common.h"
45#include "DGtal/kernel/CSpace.h"
46#include "DGtal/kernel/CEuclideanRing.h"
48
49namespace DGtal
50{
51
53// template class LpMetric
73 template <typename TSpace>
75 {
76 // ----------------------- Standard services ------------------------------
77 public:
78
80 typedef TSpace Space;
82
84 typedef typename Space::RealPoint Point;
86 typedef double Value;
88 typedef double RawValue;
89
95 LpMetric( const double anExponent): myExponent(anExponent)
96 {}
97
98
103 {}
104
109 LpMetric ( const LpMetric & other )
110 {
111 myExponent = other.myExponent;
112 }
113
119 LpMetric & operator= ( const LpMetric & other )
120 {
121 myExponent = other.myExponent;
122 return *this;
123 }
124
125 // ----------------------- Interface --------------------------------------
126 public:
127
128 // ----------------------- CMetric --------------------------------------
137 Value operator()(const Point & aP, const Point &aQ) const
138 {
139 return std::pow( rawDistance(aP,aQ), 1.0/myExponent);
140 }
141
150 RawValue rawDistance(const Point & aP, const Point &aQ) const
151 {
152 RawValue tmp=0.0;
153 for(typename Point::Dimension i = 0; i < aP.size(); ++i)
154 tmp += static_cast<RawValue>(std::pow(NumberTraits<typename Point::Coordinate>::castToDouble(std::abs(aP[i] - aQ[i])),
155 myExponent));
156 return tmp;
157 }
158
170 Closest closest(const Point &origin,
171 const Point &first,
172 const Point &second) const
173 {
174 auto dfirst = rawDistance(origin,first);
175 auto dsecond = rawDistance(origin,second);
176 if (dfirst < dsecond)
177 return ClosestFIRST;
178 else
179 if (dfirst > dsecond)
180 return ClosestSECOND;
181
182 return ClosestBOTH;
183 }
184
189 void selfDisplay ( std::ostream & out ) const
190 {
191 out << "[LpMetric] Lp Metric exponent=" << myExponent ;
192 }
193
198 bool isValid() const
199 {
200 return true;
201 }
202
203 // ------------------------- Private Datas --------------------------------
204 private:
205
208
209 }; // end of class LpMetric
210
217 template <typename T>
218 std::ostream&
219 operator<< ( std::ostream & out, const LpMetric<T> & object )
220 {
221 object.selfDisplay( out );
222 return out;
223 }
224
225} // namespace DGtal
226
227// //
229
230#endif // !defined LpMetric_h
231
232#undef LpMetric_RECURSES
233#endif // else defined(LpMetric_RECURSES)
Aim: implements l_p metrics.
Definition: LpMetric.h:75
Closest closest(const Point &origin, const Point &first, const Point &second) const
Definition: LpMetric.h:170
double RawValue
Type for raw distance values.
Definition: LpMetric.h:88
LpMetric & operator=(const LpMetric &other)
Definition: LpMetric.h:119
LpMetric(const double anExponent)
Definition: LpMetric.h:95
TSpace Space
Copy the space type.
Definition: LpMetric.h:80
void selfDisplay(std::ostream &out) const
Definition: LpMetric.h:189
Space::RealPoint Point
Type for points (RealPoint for this class)
Definition: LpMetric.h:84
bool isValid() const
Definition: LpMetric.h:198
RawValue rawDistance(const Point &aP, const Point &aQ) const
Definition: LpMetric.h:150
double Value
Type for distance values.
Definition: LpMetric.h:86
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
Value operator()(const Point &aP, const Point &aQ) const
Definition: LpMetric.h:137
Value myExponent
Exponent value.
Definition: LpMetric.h:207
LpMetric(const LpMetric &other)
Definition: LpMetric.h:109
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
static Dimension size()
DGtal::Dimension Dimension
Copy of the dimension type.
Definition: PointVector.h:623
DGtal is the top-level namespace which contains all DGtal functions and types.
Closest
Definition: Common.h:147
@ ClosestBOTH
Definition: Common.h:147
@ ClosestSECOND
Definition: Common.h:147
@ ClosestFIRST
Definition: Common.h:147
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:564
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:106