DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
LpMetric.h
1
16
17
#pragma once
18
29
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
49
namespace
DGtal
50
{
51
53
// template class LpMetric
73
template
<
typename
TSpace>
74
class
LpMetric
75
{
76
// ----------------------- Standard services ------------------------------
77
public
:
78
80
typedef
TSpace
Space
;
81
BOOST_CONCEPT_ASSERT
((
concepts::CSpace<TSpace>
));
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
102
~LpMetric
()
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 Data --------------------------------
204
private
:
205
207
Value
myExponent
;
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)
DGtal::LpMetric
Aim: implements l_p metrics.
Definition
LpMetric.h:75
DGtal::LpMetric::closest
Closest closest(const Point &origin, const Point &first, const Point &second) const
Definition
LpMetric.h:170
DGtal::LpMetric::RawValue
double RawValue
Type for raw distance values.
Definition
LpMetric.h:88
DGtal::LpMetric::operator=
LpMetric & operator=(const LpMetric &other)
Definition
LpMetric.h:119
DGtal::LpMetric::LpMetric
LpMetric(const double anExponent)
Definition
LpMetric.h:95
DGtal::LpMetric::Space
TSpace Space
Copy the space type.
Definition
LpMetric.h:80
DGtal::LpMetric::selfDisplay
void selfDisplay(std::ostream &out) const
Definition
LpMetric.h:189
DGtal::LpMetric::Point
Space::RealPoint Point
Type for points (RealPoint for this class).
Definition
LpMetric.h:84
DGtal::LpMetric::isValid
bool isValid() const
Definition
LpMetric.h:198
DGtal::LpMetric::rawDistance
RawValue rawDistance(const Point &aP, const Point &aQ) const
Definition
LpMetric.h:150
DGtal::LpMetric::Value
double Value
Type for distance values.
Definition
LpMetric.h:86
DGtal::LpMetric::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
DGtal::LpMetric::~LpMetric
~LpMetric()
Definition
LpMetric.h:102
DGtal::LpMetric::operator()
Value operator()(const Point &aP, const Point &aQ) const
Definition
LpMetric.h:137
DGtal::LpMetric::myExponent
Value myExponent
Exponent value.
Definition
LpMetric.h:207
DGtal::LpMetric::LpMetric
LpMetric(const LpMetric &other)
Definition
LpMetric.h:109
DGtal::PointVector::size
static Dimension size()
DGtal::PointVector< dim, double >::Dimension
DGtal::Dimension Dimension
Definition
PointVector.h:623
DGtal::SpaceND< 3, Integer >::RealPoint
PointVector< dim, double > RealPoint
Definition
SpaceND.h:117
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::Closest
Closest
Definition
Common.h:129
DGtal::ClosestBOTH
@ ClosestBOTH
Definition
Common.h:129
DGtal::ClosestSECOND
@ ClosestSECOND
Definition
Common.h:129
DGtal::ClosestFIRST
@ ClosestFIRST
Definition
Common.h:129
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::NumberTraitsImpl< std::decay< T >::type >::castToDouble
static double castToDouble(const T &aT)
Definition
NumberTraits.h:164
DGtal::concepts::CSpace
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition
CSpace.h:106
src
DGtal
geometry
volumes
distance
LpMetric.h
Generated on
for DGtal by
1.18.0