DGtal  0.9.2
DGtal::SeparableMetricAdapter< TMetric > Class Template Reference

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

## Public Types

typedef TMetric Metric

typedef Metric::Point Point

typedef Point::Coordinate Abscissa

typedef Metric::Value Value

typedef Metric::RawValue RawValue

typedef Metric::Vector Vector

typedef Metric::Space Space

## Public Member Functions

BOOST_CONCEPT_ASSERT ((concepts::CMetricSpace< TMetric >))

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

bool hiddenBy (const Point &u, const Point &v, const Point &w, const Point &startingPoint, const Point &endPoint, const typename Point::UnsignedComponent dim) const

void selfDisplay (std::ostream &out) const

bool isValid () const

Abscissa binarySearchHidden (const Point &u, const Point &v, const typename Point::UnsignedComponent dim, const Point &lower, const Point &upper) const

## Private Attributes

const MetricmyMetric

## Detailed Description

### template<typename TMetric> class DGtal::SeparableMetricAdapter< TMetric >

Aim: Adapts any model of CMetric to construct a separable metric (model of CSeparableMetric).

The adapted metric can thus be used in separable algorithms such as VoronoiMap or PowerMap. The adapted metric makes sense only if the input metric as the monotinicity propertery (see [35] or [45]): In dimension 2, consider two points $$p(x,y)$$, $$q(x',y')$$ with $$x<x'$$. Let $$r( x'',0)$$ be a point on the x-axis such that $$d(p,r) = d(q,r)$$ and $$s(u,0)$$ be another point on the x-axis. A metric $$d$$ is monotonic if

$u < x'' \implies d(p,s) \leq d(q,s)$

and

$u > x'' \implies d(p,s) \geq d(q,s)$

If the metric distance evaluation is in $$O(m)$$, the hiddenBy() method is in $$O(m\log n)$$.

Template Parameters
 TMetric the type of input metric (model of CMetric)

Definition at line 79 of file SeparableMetricAdapter.h.

## Member Typedef Documentation

template<typename TMetric >

Type for point abscissa.

Definition at line 92 of file SeparableMetricAdapter.h.

template<typename TMetric >

Copy the space type.

Definition at line 86 of file SeparableMetricAdapter.h.

template<typename TMetric >

Type for points.

Definition at line 90 of file SeparableMetricAdapter.h.

template<typename TMetric >

Type for raw values.

Definition at line 96 of file SeparableMetricAdapter.h.

template<typename TMetric >

Type for Space.

Definition at line 100 of file SeparableMetricAdapter.h.

template<typename TMetric >

Type for values.

Definition at line 94 of file SeparableMetricAdapter.h.

template<typename TMetric >

Type for vectors.

Definition at line 98 of file SeparableMetricAdapter.h.

## Constructor & Destructor Documentation

template<typename TMetric >
inline

Constructor from a CMetric model instance. The metric is aliased in this class.

Parameters
 [in] aMetric any model of CMetric which is monotonic.

Definition at line 108 of file SeparableMetricAdapter.h.

108  : myMetric(&aMetric)
109  {}
template<typename TMetric >
inline

Destructor.

Definition at line 114 of file SeparableMetricAdapter.h.

114 {};
template<typename TMetric >
inline

Copy constructor. (CopyConstruticle concept)

Parameters
 other the object to clone.

Definition at line 120 of file SeparableMetricAdapter.h.

120 : myMetric(other.myMetric) {}

## Member Function Documentation

template<typename TMetric >
 Abscissa DGtal::SeparableMetricAdapter< TMetric >::binarySearchHidden ( const Point & u, const Point & v, const typename Point::UnsignedComponent dim, const Point & lower, const Point & upper ) const

Perform a binary search on the interval [lower,upper] to detect the mid-point between u and v .

Precondition
udim < vdim
Parameters
 u a point v a point dim direction of the straight line lower starting point of the segment upper end point of the segment
Returns
the u Voronoi cell greatest point coordinates along dimension dim.
template<typename TMetric >
 DGtal::SeparableMetricAdapter< TMetric >::BOOST_CONCEPT_ASSERT ( (concepts::CMetricSpace< TMetric >) )
template<typename TMetric >
 Closest DGtal::SeparableMetricAdapter< TMetric >::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
 origin the origin first the first point second the second point
Returns
a Closest enum: ClosestFIRST, ClosestSECOND or ClosestBOTH.

Definition at line 173 of file SeparableMetricAdapter.h.

176  {
177  return myMetric->closest(origin,first,second);
178  }
template<typename TMetric >
 bool DGtal::SeparableMetricAdapter< TMetric >::hiddenBy ( const Point & u, const Point & v, const Point & w, const Point & startingPoint, const Point & endPoint, const typename Point::UnsignedComponent dim ) const

Given three sites (u,v,w) and a straight segment [startingPoint,endPoint] along dimension dim, we detect if the voronoi cells of u and w strictly hide the voronoi cell of v on the straight line.

If operator()(p,q) of the underlying metric is in $$O(m)$$, the cost of this method is $$O(mlog(n))$$ (b being the number of points in [startingPoint,endPoint]).

Precondition
u,v and w must be such that u[dim] < v[dim] < w[dim]
Parameters
 u a site v a site w a site startingPoint starting point of the segment endPoint end point of the segment dim direction of the straight line
Returns
true if (u,w) hides v (strictly).
template<typename TMetric >
 bool DGtal::SeparableMetricAdapter< TMetric >::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 219 of file SeparableMetricAdapter.h.

220  {
221  return myMetric->isValid();
222  }
template<typename TMetric >
 Value DGtal::SeparableMetricAdapter< TMetric >::operator() ( const Point & aP, const Point & aQ ) const
inline

Compute the distance between aP and aQ.

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

Definition at line 145 of file SeparableMetricAdapter.h.

146  {
147  return myMetric->operator()(aP,aQ);
148  }
template<typename TMetric >
inline

Assignment. (Assignable concept)

Parameters
 other the object to copy.
Returns
a reference on 'this'.

Definition at line 127 of file SeparableMetricAdapter.h.

128  {
129  myMetric = other.myMetric;
130  return *this;
131  }
template<typename TMetric >
 RawValue DGtal::SeparableMetricAdapter< TMetric >::rawDistance ( const Point & aP, const Point & aQ ) const
inline

Compute the raw distance between aP and aQ.

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

Definition at line 158 of file SeparableMetricAdapter.h.

159  {
160  return myMetric->rawDistance(aP,aQ);
161  }
template<typename TMetric >
 void DGtal::SeparableMetricAdapter< TMetric >::selfDisplay ( std::ostream & out ) const

Writes/Displays the object on an output stream.

Parameters
 out the output stream where the object is written.

## Field Documentation

template<typename TMetric >