DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Data Fields | Private Types | Private Member Functions
DGtal::L2FirstOrderLocalDistance< TImage, TSet > Class Template Reference

#include <FMMPointFunctors.h>

Public Types

typedef TImage Image
typedef Image::Point Point
typedef Image::Value Value
typedef TSet Set

Public Member Functions

 BOOST_CONCEPT_ASSERT ((CImage< TImage >))
 BOOST_CONCEPT_ASSERT ((CDigitalSet< TSet >))
 BOOST_STATIC_ASSERT ((boost::is_same< Point, typename TSet::Point >::value))
 L2FirstOrderLocalDistance (Image &aImg, TSet &aSet)
 L2FirstOrderLocalDistance (const L2FirstOrderLocalDistance &other)
L2FirstOrderLocalDistanceoperator= (const L2FirstOrderLocalDistance &other)
 ~L2FirstOrderLocalDistance ()
Value operator() (const Point &aPoint)
void selfDisplay (std::ostream &out) const

Data Fields

ImagemyImgPtr
SetmySetPtr

Private Types

typedef std::vector< ValueValues

Private Member Functions

Value compute (Values &aValueList) const
Value gradientNorm (const Value &aValue, const Values &aValueList) const

Detailed Description

template<typename TImage, typename TSet>
class DGtal::L2FirstOrderLocalDistance< TImage, TSet >

Aim: Class for the computation of the Euclidean distance at some point p, from the available distance values of some points lying in the 1-neighborhood of p (ie. points at a L1-distance to p equal to 1).

Description of template class 'L2FirstOrderLocalDistance' <p>
The computed value is such that the upwind gradient of the 
distance map is one, ie. it is the minimum solution \form#156 
over all quadrants, verifying the following quadratic equation:

\( \sum_{i = 1 \ldots d } ( \Phi - \Phi_i )^2 \) where \( \Phi_i \) is the distance value of the point preceeding or following p along the \( i \) axis.

Note:
This class deals with positive or negative distance values (0 is arbitrarily considered as a positive value, ie. starting with a seed of null value, you must get positive values). However, the behavior is undefined when there are both positive and negative distance values in the neighborhood of p.

It is a model of CPointFunctor.

Template Parameters:
TImagemodel of CImage used for the mapping point-distance value
TSetmodel of CDigitalSet for storing points whose distance value is known
See also:
FMM

Definition at line 92 of file FMMPointFunctors.h.


Member Typedef Documentation

template<typename TImage, typename TSet>
typedef TImage DGtal::L2FirstOrderLocalDistance< TImage, TSet >::Image

Definition at line 101 of file FMMPointFunctors.h.

template<typename TImage, typename TSet>
typedef Image::Point DGtal::L2FirstOrderLocalDistance< TImage, TSet >::Point

Definition at line 102 of file FMMPointFunctors.h.

template<typename TImage, typename TSet>
typedef TSet DGtal::L2FirstOrderLocalDistance< TImage, TSet >::Set

Definition at line 107 of file FMMPointFunctors.h.

template<typename TImage, typename TSet>
typedef Image::Value DGtal::L2FirstOrderLocalDistance< TImage, TSet >::Value

Definition at line 103 of file FMMPointFunctors.h.

template<typename TImage, typename TSet>
typedef std::vector<Value> DGtal::L2FirstOrderLocalDistance< TImage, TSet >::Values
private

Definition at line 112 of file FMMPointFunctors.h.


Constructor & Destructor Documentation

template<typename TImage , typename TSet>
DGtal::L2FirstOrderLocalDistance< TImage, TSet >::L2FirstOrderLocalDistance ( Image aImg,
TSet &  aSet 
)
inline

Constructor from an image and a set. NB: only pointers are stored

Parameters:
aImgany distance map
aSetany digital set

Definition at line 67 of file FMMPointFunctors.ih.

: myImgPtr(&aImg), mySetPtr(&aSet)
{
ASSERT( myImgPtr );
ASSERT( mySetPtr );
}
template<typename TImage , typename TSet>
DGtal::L2FirstOrderLocalDistance< TImage, TSet >::L2FirstOrderLocalDistance ( const L2FirstOrderLocalDistance< TImage, TSet > &  other)
inline

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 77 of file FMMPointFunctors.ih.

: myImgPtr(other.myImgPtr), mySetPtr(other.mySetPtr)
{
ASSERT( myImgPtr );
ASSERT( mySetPtr );
}
template<typename TImage , typename TSet >
DGtal::L2FirstOrderLocalDistance< TImage, TSet >::~L2FirstOrderLocalDistance ( )
inline

Destructor. Does nothing.

Definition at line 104 of file FMMPointFunctors.ih.

{
}

Member Function Documentation

template<typename TImage, typename TSet>
DGtal::L2FirstOrderLocalDistance< TImage, TSet >::BOOST_CONCEPT_ASSERT ( (CImage< TImage >)  )

image

template<typename TImage, typename TSet>
DGtal::L2FirstOrderLocalDistance< TImage, TSet >::BOOST_CONCEPT_ASSERT ( (CDigitalSet< TSet >)  )

set

template<typename TImage, typename TSet>
DGtal::L2FirstOrderLocalDistance< TImage, TSet >::BOOST_STATIC_ASSERT ( (boost::is_same< Point, typename TSet::Point >::value)  )
template<typename TImage , typename TSet >
DGtal::L2FirstOrderLocalDistance< TImage, TSet >::Value DGtal::L2FirstOrderLocalDistance< TImage, TSet >::compute ( Values aValueList) const
inlineprivate

Returns an approximation of the Euclidean distance at some point, knowing the distance of its neighbors

Parameters:
aValueListthe distance of (some of) the neighbors
Returns:
the computed distance.

Definition at line 170 of file FMMPointFunctors.ih.

{
ASSERT(aValueList.size() > 0);
if ( aValueList.size() == 1 )
{
Value d = aValueList.back();
if (d >= 0) return d + 1.0;
else return d - 1.0;
}
else
{
//function computation
typename Values::iterator itMax =
std::max_element( aValueList.begin(), aValueList.end(), absComparator<Value> );
if ( gradientNorm( *itMax, aValueList ) > 1 )
{
aValueList.erase( itMax );
return this->compute(aValueList);
}
else
{ //resolution
double a = 0;
double b = 0;
double c = -1;
for (typename Values::iterator it = aValueList.begin();
it != aValueList.end(); ++it)
{
Value d = *it;
a += 1;
b -= static_cast<double>(2*d);
c += static_cast<double>(d*d);
}
//discriminant
double disc = b*b - 4*a*c;
ASSERT(disc >= 0);
if ( b < 0 )
return static_cast<Value>( ( -b + std::sqrt(disc) ) / (2*a) );
else
return static_cast<Value>( ( -b - std::sqrt(disc) ) / (2*a) );
}
}
}
template<typename TImage , typename TSet >
DGtal::L2FirstOrderLocalDistance< TImage, TSet >::Value DGtal::L2FirstOrderLocalDistance< TImage, TSet >::gradientNorm ( const Value aValue,
const Values aValueList 
) const
inlineprivate

Returns the squared euclidean norm of the gradient of the distance map

Parameters:
aValuethe distance value of the point where the gradient is computed
aValueListthe distance value of (some of) the neighbors
Returns:
the computed gradient norm.

Definition at line 224 of file FMMPointFunctors.ih.

{
Value sum = 0;
for (typename Values::const_iterator it = aValueList.begin();
it != aValueList.end(); ++it)
{
Value d = (aValue - *it);
sum += (d*d);
}
return sum;
}
template<typename TImage , typename TSet >
DGtal::L2FirstOrderLocalDistance< TImage, TSet >::Value DGtal::L2FirstOrderLocalDistance< TImage, TSet >::operator() ( const Point aPoint)
inline

Euclidean distance computation at aPoint , from the available distance values of the 1-neighbors of aPoint .

Parameters:
aPointthe point for which the distance is computed
Returns:
the distance value at aPoint.

Definition at line 113 of file FMMPointFunctors.ih.

References DGtal::findAndGetValue().

{
//distance values
Values v;
v.reserve(Point::dimension);
//two 1-neighbors
Point neighbor1 = aPoint;
Point neighbor2 = aPoint;
typename Point::Iterator it1 = neighbor1.begin();
typename Point::Iterator it2 = neighbor2.begin();
typename Point::ConstIterator it = aPoint.begin();
typename Point::ConstIterator itEnd = aPoint.end();
for ( ; it != itEnd; ++it, ++it1, ++it2)
{//for each dimension
typename Point::Coordinate c = *it;
*it1 = (c+1);
*it2 = (c-1);
//neighboring values
Value d, d1, d2 = 0;
bool flag1 = findAndGetValue( *myImgPtr, *mySetPtr, neighbor1, d1 );
bool flag2 = findAndGetValue( *myImgPtr, *mySetPtr, neighbor2, d2 );
if ( flag1 || flag2 )
{
if ( flag1 && flag2 )
{ //take the minimal value
if (std::abs(d1) < std::abs(d2))
d = d1;
else
d = d2;
} else
{
if (flag1) d = d1;
if (flag2) d = d2;
}
v.push_back(d);
}
*it1 = c;
*it2 = c;
} //end for each dimension
//computation of the new value
return this->compute(v);
}
template<typename TImage , typename TSet >
DGtal::L2FirstOrderLocalDistance< TImage, TSet > & DGtal::L2FirstOrderLocalDistance< TImage, TSet >::operator= ( const L2FirstOrderLocalDistance< TImage, TSet > &  other)
inline

Assignment.

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

Definition at line 88 of file FMMPointFunctors.ih.

References DGtal::L2FirstOrderLocalDistance< TImage, TSet >::myImgPtr, and DGtal::L2FirstOrderLocalDistance< TImage, TSet >::mySetPtr.

{
if( this != &other)
{
myImgPtr = other.myImgPtr;
mySetPtr = other.mySetPtr;
ASSERT( myImgPtr );
ASSERT( mySetPtr );
}
return *this;
}
template<typename TImage , typename TSet >
void DGtal::L2FirstOrderLocalDistance< TImage, TSet >::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 241 of file FMMPointFunctors.ih.

{
out << "L2";
}

Field Documentation

template<typename TImage, typename TSet>
Image* DGtal::L2FirstOrderLocalDistance< TImage, TSet >::myImgPtr

Aliasing pointer on the underlying image.

Definition at line 117 of file FMMPointFunctors.h.

Referenced by DGtal::L2FirstOrderLocalDistance< TImage, TSet >::operator=().

template<typename TImage, typename TSet>
Set* DGtal::L2FirstOrderLocalDistance< TImage, TSet >::mySetPtr

Aliasing pointer on the underlying set.

Definition at line 119 of file FMMPointFunctors.h.

Referenced by DGtal::L2FirstOrderLocalDistance< TImage, TSet >::operator=().


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