Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metric concepts #791

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 12 additions & 16 deletions src/DGtal/geometry/doc/moduleVolumetric.dox
Expand Up @@ -10,7 +10,7 @@
* This file is part of the DGtal library.
*/

/*
/*
* Useful to avoid writing DGtal:: in front of every class.
* Do not forget to add an entry in src/DGtal/base/Config.h.in !
*/
Expand All @@ -33,7 +33,7 @@ axis extraction.

For decades, distance transformation (DT) and geometrical skeleton
extraction have been classic tools for shape analysis
@cite Rosenfeld1966
@cite Rosenfeld1966
@cite Rosenfeld1968 . The DT of a shape consists in
labelling object grid points with the distance to the closest
background pixel. From the DT values, we thus have information on the
Expand Down Expand Up @@ -68,7 +68,7 @@ tools can be used on a wider class of metrics (see @cite Hirata1996 or
@cite Maurer2003PAMI). For instance, all weighted \f$l_p\f$ metrics defined in
@f$R^n@f$ by
\f[ d_{L_p} (u,v) = \left ( \sum_{i=0}^n w_i|u_i-v_i |^p \right )^{\frac{1}{p}}\f]
can be considered.
can be considered.

In DGtal, we have chosen to implement such volumetric tools such
that the underlying metric could be specified independently.
Expand Down Expand Up @@ -126,7 +126,7 @@ predicate definition domain.
Once the VoronoiMap object is created, the voronoi map is computed and
the class itself is a model of CConstImage. In other words, you can
access to the VoronoiMap value at a point @a p and iterate of values
using image ranges (see @ref moduleImages). For example
using image ranges (see @ref moduleImages). For example

@code
VoronoiMap<....> myVoronoiMap( .... ); //object construction
Expand Down Expand Up @@ -207,7 +207,7 @@ As discussed earlier, the distance transformation is given by
computing distances once the Voronoi map is obtained. In DGtal, the
class DistanceTransformation simply adapts the VoronoiMap class in
order to override output image getters to return the distance for the
given metric to the closest site instead of the vector.
given metric to the closest site instead of the vector.

As a consequence, the DistanceTransformation class simply inherits from the
VoronoiMap class and overrides methods required by
Expand Down Expand Up @@ -278,7 +278,7 @@ belonging to the union @f$ \bigcup \{B_i\}@f$ (see @cite dcoeurjo_pami_RDMA).

ReverseDistanceTransformation can thus be used to reconstructed a
binary shape from a given Medial Axis or any set of balls. Another
consequence is that given a binary shape, the pipeline
consequence is that given a binary shape, the pipeline
@f[ Shape \rightarrow DT \rightarrow ReverseDT \rightarrow \text{ strictly negative values }@f]
for the same metric/power metric, returns the input binary shape.

Expand All @@ -302,23 +302,19 @@ terms of concepts:

@dot
digraph metric_concepts_2_vor {
CLocalPremetric [ label="CLocalPremetric" URL="\ref CLocalPremetric" ];
CMetric [label="CMetric" URL="@ref CMetric"];
CSeparableMetric [label="CSeparableMetric" URL="@ref CSeparableMetric"];
CPowerMetric [label="CPowerMetric" URL="@ref CPowerMetric"];
CPowerSeparableMetric [label="CPowerSeparableMetric" URL="@ref CPowerSeparableMetric"];

CMetric -> CLocalPremetric;
CSeparableMetric -> CMetric;
CPowerSeparableMetric -> CPowerMetric;

label="Main metric concepts";
}
@enddot

For instance, CLocalPremetric models only requires that a local metric
is defined (@e i.e. between a point and a neighboring point in a given
direction). CMetric requires to have a binary operator to compute the
For instance, CMetric requires to have a binary operator to compute the
distance between any two points of the digital space. Furthermore, it
requires to have a method he @a closest(p,q) which returns the closest
point from @a p and @a q to the origin. Such closest method can be
Expand All @@ -333,8 +329,8 @@ to @a closest() requests.

The Separable metric concept is a refinement of the CMetric
(resp. CPowerMetric) concept in which we require models to implement a
method
@a hiddenBy(u,v,w,startingPoint,endPoint,dim): given three digital points
method
@a hiddenBy(u,v,w,startingPoint,endPoint,dim): given three digital points
@a u, @a v, @a w and an isothetic segment defined by the pair
[@a startingPoint, @a endPoint] along the dimension @a dim, such method
returns true if Voronoi cells of @a u and @a w @e hide the Voronoi
Expand All @@ -351,7 +347,7 @@ crucial for separable VoronoiMap/DistanceTransformation algorithms. The next sec
CPowerSeparableMetric concepts is a similar refinement of the CPowerMetric concept. Indeed, CPowerSeparableMetric models must implement an @a hiddenByPower(u, wu,v,wv,w,ww,startingPoint,endPoint,dim) on triplet of weighted points {(u,wu),(v,wv),(w,ww)}.


The class of metrics for which such @a hiddenBy method can be defined and for which the VoronoiMap will be exact is quite large. This class contains
The class of metrics for which such @a hiddenBy method can be defined and for which the VoronoiMap will be exact is quite large. This class contains

- all @f$ l_p @f$ metrics (ExactPredicateLpSeparableMetric and InexactPredicateLpSeparableMetric)
- all local metric inducing a norm (chamfer norms, some of the neighborhood sequences, ...) (see @cite Hirata1996 for more details).
Expand All @@ -363,7 +359,7 @@ algorithms. In dimension 2, consider two points @f$ p(x,y)@f$,
@f$q(x',y')@f$ with @f$x<x'@f$. Let @f$r( x'',0)@f$ be a point on the
x-axis such that @f$d(p,r) = d(q,r)@f$ and @f$ s(u,0)@f$ be another
point on the x-axis. A metric @f$ d@f$ is @e monotonic if

@f[ u < x'' \implies d(p,s) \leq d(q,s) @f]
and
@f[ u > x'' \implies d(p,s) \geq d(q,s) @f]
Expand All @@ -374,7 +370,7 @@ monotonic to a model of CSeparableMetric. Please refer to the
following table for computational costs.


@section CostSec Computational Costs
@section CostSec Computational Costs


As discussed, both VoronoiMap and PowerMap (and their associated
Expand Down
9 changes: 4 additions & 5 deletions src/DGtal/geometry/doc/packageGeometryConcepts.dox
Expand Up @@ -64,14 +64,11 @@ subgraph cluster_concepts_2 {
color=lightgrey;
node [style=filled,color=white];

CLocalPremetric [ label="CLocalPremetric" URL="\ref CLocalPremetric" ];
CMetric [label="CMetric" URL="@ref CMetric"];
CSeparableMetric [label="CSeparableMetric" URL="@ref CSeparableMetric"];
CPowerMetric [label="CPowerMetric" URL="@ref CPowerMetric"];
CPowerSeparableMetric [label="CPowerSeparableMetric" URL="@ref CPowerSeparableMetric"];

CPowerMetric -> CMetric;
CMetric -> CLocalPremetric;
CSeparableMetric -> CMetric;
CPowerSeparableMetric -> CPowerMetric;

Expand All @@ -92,8 +89,10 @@ subgraph cluster_concepts_2 {
}


CLocalPremetric -> boost_CopyConstructible;
CLocalPremetric -> boost_Assignable;
CMetric -> boost_CopyConstructible;
CMetric -> boost_Assignable;
CPowerMetric -> boost_CopyConstructible;
CPowerMetric -> boost_Assignable;

CSegment -> boost_CopyConstructible ;
CSegment -> boost_DefaultConstructible;
Expand Down
143 changes: 0 additions & 143 deletions src/DGtal/geometry/volumes/distance/CLocalPremetric.h

This file was deleted.

37 changes: 28 additions & 9 deletions src/DGtal/geometry/volumes/distance/CMetric.h
Expand Up @@ -42,7 +42,8 @@
// Inclusions
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/geometry/volumes/distance/CLocalPremetric.h"
#include "DGtal/kernel/CSpace.h"
#include "DGtal/base/CQuantity.h"
//////////////////////////////////////////////////////////////////////////////

namespace DGtal
Expand All @@ -55,20 +56,34 @@ Description of \b concept '\b CMetric' <p>
@ingroup Concepts
@brief Aim: defines the concept of metrics.

In addition to CLocalPremetric requirements (non-negativity and coincidence axiom), CMetric models should
Models of such concept should implement a distance method which
returns positive values for the distance between @a aPoint and @a
aPoint + @a aDirection. Models should be such that the distance at a point
in a given direction is equal to zero if and only if the direction is
a null vector.
In addition, CMetric models should
implement a distance function on points satisfying the metric
conditions:

- d(x,y) == d(y,x) (symmetry)
- d(x,y) <= d(x,z) + d(z,y) (triangle inequality)

For performance purposes, we ask the model to implement a closest() method to decide given two points which one is closer to a third one. This method can simply be implemented as a test "d(aOrigin,aP)<d(aOrigin,aQ)" (see below) but fast implementation can be expected without computing the distances.
For performance purposes, we ask the model to implement a closest()
method to decide given two points which one is closer to a third
one. This method can simply be implemented as a test
"d(aOrigin,aP)<d(aOrigin,aQ)" (see below) but fast implementation can
be expected without computing the distances.


### Refinement of
- boost::CopyConstructible
- boost::Assignable


### Refinement of CLocalPremetric

### Associated types :

Inherited from CLocalPremetric:
- @e Space: type of space on which the premetric is defined (model of CSpace)
- @e Point: type of points associated with the underlying metric space.
- @e Vector: type of vectors associated with the underlying metric space.
- @e Value: the value type of the metric (model of CQuantity)
Expand All @@ -86,7 +101,7 @@ Inherited from CLocalPremetric:
|-------|------------|-------------------|---------------|--------------|-----------|----------------|------------|
| distance computation | x(aPoint,anotherPoint) | @a aPoint and @a anotherPoint of type @a Point | a value of type @a Value | | compute the distance between two points | | - |
| closest point test | closest(aOrigin, aP, aQ) | @a aOrigin, @a aP,@a aQ of type @a aPoint | a value of type Closest | | decide between @a aP and @a aQ which one is closer to the origin. This functions returns either DGtal::ClosestFIRST if @a aP is closer, DGtal::ClosestSECOND if @a aQ is closer and DGtal::ClosestBOTH if both are equidistant.| | - |


### Invariants

Expand All @@ -99,19 +114,23 @@ ExactPredicateLpSeparableMetric, InexactPredicateLpSeparableMetric
@tparam T the type that should be a model of CMetric.
*/
template <typename T>
struct CMetric: CLocalPremetric<T>
struct CMetric: boost::CopyConstructible<T>, boost::Assignable<T>
{
// ----------------------- Concept checks ------------------------------
public:
typedef typename T::Point Point;
typedef typename T::Space Space;
typedef typename T::Vector Vector;
typedef typename T::Value Value;


BOOST_CONCEPT_ASSERT(( CSpace< Space > ));
BOOST_CONCEPT_ASSERT(( CQuantity< Value > ));

BOOST_CONCEPT_USAGE( CMetric )
{
checkConstConstraints();
}

void checkConstConstraints() const
{
// const method dummyConst should take parameter myA of type A and return
Expand Down