DGtal  1.5.beta
DGtal::LpMetric< TSpace > Class Template Reference

Aim: implements l_p metrics. More...

#include <DGtal/geometry/volumes/distance/LpMetric.h>

Public Types

typedef TSpace Space
 Copy the space type. More...
 
typedef Space::RealPoint Point
 Type for points (RealPoint for this class) More...
 
typedef double Value
 Type for distance values. More...
 
typedef double RawValue
 Type for raw distance values. More...
 

Public Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CSpace< TSpace >))
 
 LpMetric (const double anExponent)
 
 ~LpMetric ()
 
 LpMetric (const LpMetric &other)
 
LpMetricoperator= (const LpMetric &other)
 
Value operator() (const Point &aP, const Point &aQ) const
 
RawValue rawDistance (const Point &aP, const Point &aQ) const
 
Closest closest (const Point &origin, const Point &first, const Point &second) const
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 

Private Attributes

Value myExponent
 Exponent value. More...
 

Detailed Description

template<typename TSpace>
class DGtal::LpMetric< TSpace >

Aim: implements l_p metrics.

Description of template class 'LpMetric'

Given a parameter p, the class implements classical l_p metric as a model of CMetricSpace. Hence, given two points \( x=(x_0...x_{n-1})\), \( y=(y_0...y_{n-1})\), we define a metric as:

\( distance(x,y)= \left( \sum_{i=0}^{n-1} |x_i-y_i|^p\right)^{1/p}\)

This class performs all computations on C++ double converting the digital points to Space::RealPoint

The exponent p is specifed at the constructor.

Template Parameters
TSpacethe model of CSpace on which the metric is defined.

Definition at line 74 of file LpMetric.h.

Member Typedef Documentation

◆ Point

template<typename TSpace >
typedef Space::RealPoint DGtal::LpMetric< TSpace >::Point

Type for points (RealPoint for this class)

Definition at line 84 of file LpMetric.h.

◆ RawValue

template<typename TSpace >
typedef double DGtal::LpMetric< TSpace >::RawValue

Type for raw distance values.

Definition at line 88 of file LpMetric.h.

◆ Space

template<typename TSpace >
typedef TSpace DGtal::LpMetric< TSpace >::Space

Copy the space type.

Definition at line 80 of file LpMetric.h.

◆ Value

template<typename TSpace >
typedef double DGtal::LpMetric< TSpace >::Value

Type for distance values.

Definition at line 86 of file LpMetric.h.

Constructor & Destructor Documentation

◆ LpMetric() [1/2]

template<typename TSpace >
DGtal::LpMetric< TSpace >::LpMetric ( const double  anExponent)
inline

Constructor.

Parameters
anExponentthe exponent (p) of the lp metric.

Definition at line 95 of file LpMetric.h.

95  : myExponent(anExponent)
96  {}
Value myExponent
Exponent value.
Definition: LpMetric.h:207

◆ ~LpMetric()

template<typename TSpace >
DGtal::LpMetric< TSpace >::~LpMetric ( )
inline

Destructor.

Definition at line 102 of file LpMetric.h.

103  {}

◆ LpMetric() [2/2]

template<typename TSpace >
DGtal::LpMetric< TSpace >::LpMetric ( const LpMetric< TSpace > &  other)
inline

Copy constructor.

Parameters
otherthe object to clone.

Definition at line 109 of file LpMetric.h.

110  {
111  myExponent = other.myExponent;
112  }

References DGtal::LpMetric< TSpace >::myExponent.

Member Function Documentation

◆ BOOST_CONCEPT_ASSERT()

template<typename TSpace >
DGtal::LpMetric< TSpace >::BOOST_CONCEPT_ASSERT ( (concepts::CSpace< TSpace >)  )

◆ closest()

template<typename TSpace >
Closest DGtal::LpMetric< TSpace >::closest ( const Point origin,
const Point first,
const Point second 
) const
inline

Given an origin and two points, this method decides which one is closest to the origin. This method should be faster than comparing distance values.

Parameters
originthe origin
firstthe first point
secondthe second point
Returns
a Closest enum: FIRST, SECOND or BOTH.

Definition at line 170 of file LpMetric.h.

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  }
RawValue rawDistance(const Point &aP, const Point &aQ) const
Definition: LpMetric.h:150
@ ClosestBOTH
Definition: Common.h:146
@ ClosestSECOND
Definition: Common.h:146
@ ClosestFIRST
Definition: Common.h:146

References DGtal::ClosestBOTH, DGtal::ClosestFIRST, DGtal::ClosestSECOND, and DGtal::LpMetric< TSpace >::rawDistance().

Referenced by TEST_CASE().

◆ isValid()

template<typename TSpace >
bool DGtal::LpMetric< TSpace >::isValid ( ) const
inline

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

Definition at line 198 of file LpMetric.h.

199  {
200  return true;
201  }

◆ operator()()

template<typename TSpace >
Value DGtal::LpMetric< TSpace >::operator() ( const Point aP,
const Point aQ 
) const
inline

Compute the distance between aP and aQ.

Parameters
aPa first point.
aQa second point.
Returns
the distance between aP and aQ.

Definition at line 137 of file LpMetric.h.

138  {
139  return std::pow( rawDistance(aP,aQ), 1.0/myExponent);
140  }

References DGtal::LpMetric< TSpace >::myExponent, and DGtal::LpMetric< TSpace >::rawDistance().

◆ operator=()

template<typename TSpace >
LpMetric& DGtal::LpMetric< TSpace >::operator= ( const LpMetric< TSpace > &  other)
inline

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'.

Definition at line 119 of file LpMetric.h.

120  {
121  myExponent = other.myExponent;
122  return *this;
123  }

References DGtal::LpMetric< TSpace >::myExponent.

◆ rawDistance()

template<typename TSpace >
RawValue DGtal::LpMetric< TSpace >::rawDistance ( const Point aP,
const Point aQ 
) const
inline

Compute the raw distance between aP and aQ.

Parameters
aPa first point.
aQa second point.
Returns
the distance between aP and aQ.

Definition at line 150 of file LpMetric.h.

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  }
double RawValue
Type for raw distance values.
Definition: LpMetric.h:88
DGtal::Dimension Dimension
Copy of the dimension type.
Definition: PointVector.h:623
static double castToDouble(const std::decay< T >::type &aT)
Cast method to double (for I/O or board export uses only).
Definition: NumberTraits.h:164

References DGtal::LpMetric< TSpace >::myExponent, and DGtal::PointVector< dim, TEuclideanRing, TContainer >::size().

Referenced by DGtal::LpMetric< TSpace >::closest(), DGtal::LpMetric< TSpace >::operator()(), and TEST_CASE().

◆ selfDisplay()

template<typename TSpace >
void DGtal::LpMetric< TSpace >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.

Definition at line 189 of file LpMetric.h.

190  {
191  out << "[LpMetric] Lp Metric exponent=" << myExponent ;
192  }

References DGtal::LpMetric< TSpace >::myExponent.

Field Documentation

◆ myExponent


The documentation for this class was generated from the following file: