DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
DGtal::VoronoiMap< TSpace, TPointPredicate, p > Class Template Reference

#include <VoronoiMap.h>

Collaboration diagram for DGtal::VoronoiMap< TSpace, TPointPredicate, p >:
Collaboration graph
[legend]

Public Types

typedef TSpace Space
typedef TPointPredicate PointPredicate
typedef HyperRectDomain< SpaceDomain
typedef DGtal::int64_t IntegerLong
typedef Space::Vector Vector
typedef Space::Point Point
typedef Space::Dimension Dimension
typedef Space::Size Size
typedef Space::Point::Coordinate Abscissa
typedef SeparableMetricHelper
< Point, IntegerLong, p > 
SeparableMetric
typedef
ImageContainerBySTLVector
< Domain, Point
OutputImage

Public Member Functions

 BOOST_CONCEPT_ASSERT ((CSpace< TSpace >))
 BOOST_CONCEPT_ASSERT ((CPointPredicate< TPointPredicate >))
 BOOST_STATIC_ASSERT ((boost::is_same< typename TSpace::Point, typename TPointPredicate::Point >::value))
 VoronoiMap (const Domain &aDomain, const PointPredicate &predicate)
 ~VoronoiMap ()
OutputImage compute ()

Protected Member Functions

 VoronoiMap ()

Private Member Functions

void computeOtherSteps (OutputImage &output, const Dimension dim) const
void computeOtherStep1D (OutputImage &output, const Point &row, const Size dim, std::vector< Point > &Sites) const

Private Attributes

SeparableMetric myMetric
const DomainmyDomain
const PointPredicatemyPointPredicate
Point myLowerBoundCopy
Point myUpperBoundCopy
Point myInfinity

Detailed Description

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
class DGtal::VoronoiMap< TSpace, TPointPredicate, p >

Aim: Implementation of the linear in time Voronoi map construction.

Description of template class 'VoronoiMap'

The algorithm uses a sperable process to construct partial Voronoi maps which has been described in:

Maurer, C., Qi, R., & Raghavan, V. (2003). A Linear Time Algorithm
 for Computing Exact Euclidean Distance Transforms of Binary Images in
 Arbitrary Dimensions. IEEE Trans. Pattern Analysis and Machine
 Intelligence, 25pp265-270.

and

 Coeurjolly, D. (2002). Algorithmique et géométrie discrète pour
 la caractérisation des courbes et des surfaces. PhD Thesis,
 Université Lumière Lyon 2.

Given a domain and a point predicate, the compute() method returns, for each point in the domain, the closest point for which the predicate if false. Following Computational Geometry terminoliogy, points for which the predicate is false are "sites" for the Voronoi map construction.

The metric is specified by the p template parameter which defines a l_p separable metric.

If a point is equi-distant to two sites (e.g. if the digital point belong to a Voronoi cell boundary in the Euclidean space), this Voronoi map construction will only keep one of them.

Hence, the result is given as a map (point from the domain, closest site) implemented using an ImageContainerBySTLVector whose value type is the type of Point of the predicate.

Template Parameters:
TSpacetype of Digital Space (model of CSpace).
TPointPredicatepoint predicate returning true for points from which we compute the distance (model of CPointPredicate)
pthe static integer value to define the l_p metric.
IntegerLong(optional) type used to represent exact distance value according to p (default: DGtal::uint64_t)

Definition at line 109 of file VoronoiMap.h.


Member Typedef Documentation

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
typedef Space::Point::Coordinate DGtal::VoronoiMap< TSpace, TPointPredicate, p >::Abscissa

Definition at line 136 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
typedef Space::Dimension DGtal::VoronoiMap< TSpace, TPointPredicate, p >::Dimension

Definition at line 134 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
typedef HyperRectDomain<Space> DGtal::VoronoiMap< TSpace, TPointPredicate, p >::Domain

Definition of the underlying domain type.

Definition at line 127 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
typedef DGtal::int64_t DGtal::VoronoiMap< TSpace, TPointPredicate, p >::IntegerLong

Large integer type for SeparableMetricHelper construction.

Definition at line 130 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
typedef ImageContainerBySTLVector< Domain, Point > DGtal::VoronoiMap< TSpace, TPointPredicate, p >::OutputImage

Type of resulting image.

Definition at line 143 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
typedef Space::Point DGtal::VoronoiMap< TSpace, TPointPredicate, p >::Point

Definition at line 133 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
typedef TPointPredicate DGtal::VoronoiMap< TSpace, TPointPredicate, p >::PointPredicate

Copy of the point predicate type.

Definition at line 124 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
typedef SeparableMetricHelper< Point , IntegerLong , p > DGtal::VoronoiMap< TSpace, TPointPredicate, p >::SeparableMetric

We construct the type associated to the separable metric.

Definition at line 139 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
typedef Space::Size DGtal::VoronoiMap< TSpace, TPointPredicate, p >::Size

Definition at line 135 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
typedef TSpace DGtal::VoronoiMap< TSpace, TPointPredicate, p >::Space

Copy of the space type.

Definition at line 121 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
typedef Space::Vector DGtal::VoronoiMap< TSpace, TPointPredicate, p >::Vector

Definition at line 132 of file VoronoiMap.h.


Constructor & Destructor Documentation

template<typename S , typename P , DGtal::uint32_t p>
DGtal::VoronoiMap< S, P, p >::VoronoiMap ( const Domain aDomain,
const PointPredicate aPredicate 
)
inline

Constructor

Constructor.

Definition at line 47 of file VoronoiMap.ih.

:
myDomain(aDomain), myPointPredicate(aPredicate)
{
}
template<typename S , typename P , DGtal::uint32_t p>
DGtal::VoronoiMap< S, P, p >::~VoronoiMap ( )
inline

Default destructor

Destructor.

Definition at line 59 of file VoronoiMap.ih.

{
}
template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
DGtal::VoronoiMap< TSpace, TPointPredicate, p >::VoronoiMap ( )
protected

Default Constructor.


Member Function Documentation

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
DGtal::VoronoiMap< TSpace, TPointPredicate, p >::BOOST_CONCEPT_ASSERT ( (CSpace< TSpace >)  )
template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
DGtal::VoronoiMap< TSpace, TPointPredicate, p >::BOOST_CONCEPT_ASSERT ( (CPointPredicate< TPointPredicate >)  )
template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
DGtal::VoronoiMap< TSpace, TPointPredicate, p >::BOOST_STATIC_ASSERT ( (boost::is_same< typename TSpace::Point, typename TPointPredicate::Point >::value)  )

Both Space points and PointPredicate points must be the same.

template<typename S , typename P , DGtal::uint32_t p>
DGtal::VoronoiMap< S, P, p >::OutputImage DGtal::VoronoiMap< S, P, p >::compute ( )
inline

Compute the Voronoi Map of a set of point sites using a SeparableMetric metric. The method associates to each point satisfying the foreground predicate, the closest site for which the predicate is false. This algorithm is O(d.|domain size|).

Returns:
the Voronoi map image.

Definition at line 66 of file VoronoiMap.ih.

References DGtal::ImageContainerBySTLVector< TDomain, TValue >::setValue().

{
//We copy the image extent and translate the image domains to (0,..0)x(Upper-Lower)
OutputImage output ( myDomain );
//Point outside the domain
myInfinity = myDomain.upperBound() + Point::diagonal(1);
//Init
for(typename Domain::ConstIterator it = myDomain.begin(), itend = myDomain.end();
it != itend;
++it)
if ( myPointPredicate( *it))
output.setValue ( *it, myInfinity );
else
output.setValue ( *it, *it );
//We process the remaining dimensions
for ( Dimension dim = 0; dim < S::dimension ; dim++ )
computeOtherSteps ( output, dim );
return output;
}
template<typename S , typename P , DGtal::uint32_t p>
void DGtal::VoronoiMap< S, P, p >::computeOtherStep1D ( OutputImage output,
const Point row,
const Size  dim,
std::vector< Point > &  Sites 
) const
private

Given a voronoi map valid at dimension dim-1, this method updates the map to make it consistent at dimension dim along the 1D span starting at row along the dimension dim.

Parameters:
outputthe Voronoi map to update.
rowstarting point of the 1D process.
dimdimension of the update.
Sitesstack of sites (pass as an argument for performance purposes).

Definition at line 138 of file VoronoiMap.ih.

References DGtal::ImageContainerBySTLVector< TDomain, TValue >::setValue().

{
Point point = startingPoint;
Point endpoint = startingPoint;
Point psite;
int nbSites = -1;
//endpoint of the 1D row
endpoint[dim] = myUpperBoundCopy[dim];
//Pruning the list of sites (dim=0 implies no hibben sites)
if (dim==0)
{
for(Abscissa i = myLowerBoundCopy[dim] ; i <= myUpperBoundCopy[dim] ; i++)
{
psite = output(point);
if ( psite != myInfinity )
{
nbSites++;
Sites[nbSites] = psite;
}
point[dim] ++;
}
}
else
{
//Pruning the list of sites
for(Abscissa i = myLowerBoundCopy[dim] ; i <= myUpperBoundCopy[dim] ; i++)
{
psite = output(point);
if ( psite != myInfinity )
{
while ((nbSites >= 1) &&
( myMetric.hiddenBy(Sites[nbSites-1], Sites[nbSites] ,
psite, startingPoint, endpoint, dim) ))
{
nbSites --;
}
nbSites++;
Sites[nbSites] = psite;
}
point[dim] ++;
}
}
//No sites found
if (nbSites == -1)
return;
int k = 0;
//Rewriting
point[dim] = myLowerBoundCopy[dim];
for(Abscissa i = myLowerBoundCopy[dim] ; i <= myUpperBoundCopy[dim] ; i++)
{
while ( (k < nbSites) &&
( myMetric.closest(point, Sites[k], Sites[k+1])
k++;
output.setValue(point, Sites[k]);
point[dim]++;
}
}
template<typename S , typename P , DGtal::uint32_t p>
void DGtal::VoronoiMap< S, P, p >::computeOtherSteps ( OutputImage output,
const Dimension  dim 
) const
inlineprivate

Compute the other steps of the separable Voronoi map.

Parameters:
outputthe output map
dimthe dimension to process

Definition at line 99 of file VoronoiMap.ih.

References DGtal::HyperRectDomain< TSpace >::ConstSubRange::begin(), DGtal::Trace::beginBlock(), DGtal::HyperRectDomain< TSpace >::ConstSubRange::end(), DGtal::Trace::endBlock(), DGtal::HyperRectDomain< TSpace >::subRange(), and DGtal::trace.

{
std::string title = "Voro dimension " + boost::lexical_cast<string>( dim ) ;
trace.beginBlock ( title );
typedef typename Domain::ConstSubRange::ConstIterator ConstDomIt;
//We setup the subdomain iterator
//the iterator will scan dimension using the order:
// {n-1, n-2, ... 1} (we skip the '0' dimension).
std::vector<Size> subdomain;
subdomain.reserve(S::dimension - 1);
for (unsigned int k = 0; k < S::dimension ; k++)
if ( (S::dimension - 1 - k) != dim)
subdomain.push_back( S::dimension - 1 - k );
//We pre-init the stack site
std::vector<Point> Sites(myUpperBoundCopy[dim] - myLowerBoundCopy[dim], myInfinity);
//We process the dimensions to construct a Point
for (ConstDomIt it = localDomain.subRange( subdomain ).begin(),
itend = localDomain.subRange( subdomain ).end();
it != itend; ++it)
{
computeOtherStep1D ( output, (*it), dim, Sites);
}
}

Field Documentation

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
const Domain& DGtal::VoronoiMap< TSpace, TPointPredicate, p >::myDomain
private

Copy of the computation domain.

Definition at line 214 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
Point DGtal::VoronoiMap< TSpace, TPointPredicate, p >::myInfinity
private

Value to act as a +infinity value.

Definition at line 226 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
Point DGtal::VoronoiMap< TSpace, TPointPredicate, p >::myLowerBoundCopy
private

Copy of the image lower bound.

Definition at line 220 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
SeparableMetric DGtal::VoronoiMap< TSpace, TPointPredicate, p >::myMetric
private

The separable metric instance.

Definition at line 211 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
const PointPredicate& DGtal::VoronoiMap< TSpace, TPointPredicate, p >::myPointPredicate
private

Copy of the computation domain.

Definition at line 217 of file VoronoiMap.h.

template<typename TSpace, typename TPointPredicate, DGtal::uint32_t p>
Point DGtal::VoronoiMap< TSpace, TPointPredicate, p >::myUpperBoundCopy
private

Copy of the image lower bound.

Definition at line 223 of file VoronoiMap.h.


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