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::L2SecondOrderLocalDistance< 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))
 L2SecondOrderLocalDistance (Image &aImg, TSet &aSet)
 L2SecondOrderLocalDistance (const L2SecondOrderLocalDistance &other)
L2SecondOrderLocalDistanceoperator= (const L2SecondOrderLocalDistance &other)
 ~L2SecondOrderLocalDistance ()
Value operator() (const Point &aPoint)
void selfDisplay (std::ostream &out) const

Data Fields

ImagemyImgPtr
SetmySetPtr

Private Types

typedef std::pair< double, ValueCoeffValue
typedef std::vector< CoeffValueList

Private Member Functions

Value compute (List &aList) const
Value getValue (const Value &aValue1, const Value &aValue2) const

Detailed Description

template<typename TImage, typename TSet>
class DGtal::L2SecondOrderLocalDistance< 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 neighborhood of p, such that only one of their coordinate differ from the coordinates of p by at most two.

Description of template class 'L2SecondOrderLocalDistance'

Like L2FirstOrderLocalDistance, the computed value is such that the upwind gradient of the distance map is one, but instead of using first-order accurate forward and backward differences, L2SecondOrderLocalDistance uses second-order accurate forward and backward difference whenever there are enough points whose distance values are known in order to evaluate these differences.

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 227 of file FMMPointFunctors.h.


Member Typedef Documentation

template<typename TImage, typename TSet>
typedef std::pair<double, Value> DGtal::L2SecondOrderLocalDistance< TImage, TSet >::CoeffValue
private

Definition at line 247 of file FMMPointFunctors.h.

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

Definition at line 236 of file FMMPointFunctors.h.

template<typename TImage, typename TSet>
typedef std::vector<CoeffValue> DGtal::L2SecondOrderLocalDistance< TImage, TSet >::List
private

Definition at line 248 of file FMMPointFunctors.h.

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

Definition at line 237 of file FMMPointFunctors.h.

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

Definition at line 242 of file FMMPointFunctors.h.

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

Definition at line 238 of file FMMPointFunctors.h.


Constructor & Destructor Documentation

template<typename TImage , typename TSet>
DGtal::L2SecondOrderLocalDistance< TImage, TSet >::L2SecondOrderLocalDistance ( 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 251 of file FMMPointFunctors.ih.

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

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 261 of file FMMPointFunctors.ih.

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

Destructor. Does nothing.

Definition at line 288 of file FMMPointFunctors.ih.

{
}

Member Function Documentation

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

image

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

set

template<typename TImage, typename TSet>
DGtal::L2SecondOrderLocalDistance< TImage, TSet >::BOOST_STATIC_ASSERT ( (boost::is_same< Point, typename TSet::Point >::value)  )
template<typename TImage , typename TSet >
DGtal::L2SecondOrderLocalDistance< TImage, TSet >::Value DGtal::L2SecondOrderLocalDistance< TImage, TSet >::compute ( List aList) const
inlineprivate

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

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

Definition at line 400 of file FMMPointFunctors.ih.

{
ASSERT(aList.size() > 0);
if ( aList.size() == 1 )
{
CoeffValue pair = aList.back();
if (pair.second >= 0)
return ( (pair.second + 1.0)/(pair.first) );
else
return ( (pair.second - 1.0)/(pair.first) );
}
else
{ //resolution
double a = 0;
double b = 0;
double c = -1;
for (typename List::iterator it = aList.begin();
it != aList.end(); ++it)
{
double coeff = it->first;
Value v = it->second;
a += (coeff*coeff);
b -= 2 * coeff * static_cast<double>(v);
c += static_cast<double>(v*v);
}
//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::L2SecondOrderLocalDistance< TImage, TSet >::Value DGtal::L2SecondOrderLocalDistance< TImage, TSet >::getValue ( const Value aValue1,
const Value aValue2 
) const
inlineprivate

Returns the combination of two distance values for the second-order accurate difference

Parameters:
aValue1
aValue2
Returns:
the resulting value.

Definition at line 445 of file FMMPointFunctors.ih.

{
return (2.0*aValue1 - aValue2/2.0);
}
template<typename TImage , typename TSet >
DGtal::L2SecondOrderLocalDistance< TImage, TSet >::Value DGtal::L2SecondOrderLocalDistance< 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.

first-order

second-order

Definition at line 297 of file FMMPointFunctors.ih.

References DGtal::findAndGetValue().

{
//distance values
List l;
l.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;
double coeff = 1.0;
++(*it1);
--(*it2);
Value d, d1, d2 = 0;
bool flag1 = findAndGetValue( *myImgPtr, *mySetPtr, neighbor1, d1 );
bool flag2 = findAndGetValue( *myImgPtr, *mySetPtr, neighbor2, d2 );
if ( flag1 || flag2 )
{
++(*it1);
--(*it2);
Value d12, d22 = 0;
bool flag12 = findAndGetValue( *myImgPtr, *mySetPtr, neighbor1, d12 );
bool flag22 = findAndGetValue( *myImgPtr, *mySetPtr, neighbor2, d22 );
if ( flag1 && flag2 )
{
if ( flag12 && flag22 )
{ //take the minimal value
d1 = getValue( d1, d12 );
d2 = getValue( d2, d22 );
if (std::abs(d1) < std::abs(d2))
d = d1;
else
d = d2;
coeff = 1.5;
}
else
{ //like first-order accurate case
//take the minimal value
if (std::abs(d1) < std::abs(d2))
d = d1;
else
d = d2;
}
}
else //if not flag1 AND flag2 both true
{
if (flag1)
{
if ( flag12 )
{
d1 = getValue( d1, d12 );
coeff = 1.5;
}
d = d1;
}
if (flag2)
{
if ( flag22 )
{
d2 = getValue( d2, d22 );
coeff = 1.5;
}
d = d2;
}
}
l.push_back( CoeffValue( coeff, d ) );
} //end if flag1 or flag2
*it1 = c;
*it2 = c;
} //end for each dimension
//computation of the new value
return this->compute(l);
}
template<typename TImage , typename TSet >
DGtal::L2SecondOrderLocalDistance< TImage, TSet > & DGtal::L2SecondOrderLocalDistance< TImage, TSet >::operator= ( const L2SecondOrderLocalDistance< TImage, TSet > &  other)
inline

Assignment.

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

Definition at line 272 of file FMMPointFunctors.ih.

References DGtal::L2SecondOrderLocalDistance< TImage, TSet >::myImgPtr, and DGtal::L2SecondOrderLocalDistance< 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::L2SecondOrderLocalDistance< 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 455 of file FMMPointFunctors.ih.

{
out << "L2";
}

Field Documentation

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

Aliasing pointer on the underlying image.

Definition at line 253 of file FMMPointFunctors.h.

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

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

Aliasing pointer on the underlying set.

Definition at line 255 of file FMMPointFunctors.h.

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


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