DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions
DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue > Class Template Reference

#include <BinomialConvolver.h>

Collaboration diagram for DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >:
Collaboration graph
[legend]

Public Types

typedef TValue Value
typedef TConstIteratorOnPoints ConstIteratorOnPoints
typedef
ConstIteratorOnPoints::value_type 
Point

Public Member Functions

 BinomialConvolver (unsigned int n=1)
 ~BinomialConvolver ()
void setSize (unsigned int n)
unsigned int size () const
void init (const double h, const ConstIteratorOnPoints &itb, const ConstIteratorOnPoints &ite, const bool isClosed)
int index (const ConstIteratorOnPoints &it) const
std::pair< Value, Valuex (int i) const
std::pair< Value, Valuedx (int i) const
std::pair< Value, Valued2x (int i) const
std::pair< Value, Valuetangent (int i) const
Value curvature (int i) const
void selfDisplay (std::ostream &out) const
bool isValid () const

Static Public Member Functions

static unsigned int suggestedSize (const double h, const ConstIteratorOnPoints &itb, const ConstIteratorOnPoints &ite)

Protected Attributes

unsigned int myN
double myH
Signal< ValuemyX
Signal< ValuemyY
Signal< ValuemyDX
Signal< ValuemyDY
Signal< ValuemyDDX
Signal< ValuemyDDY
ConstIteratorOnPoints myBegin
ConstIteratorOnPoints myEnd
std::map
< ConstIteratorOnPoints, int > 
myMapIt2Idx

Private Member Functions

 BinomialConvolver (const BinomialConvolver &other)
BinomialConvolveroperator= (const BinomialConvolver &other)

Detailed Description

template<typename TConstIteratorOnPoints, typename TValue = double>
class DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >

Aim: This class represents a 2D contour convolved by some binomial. It computes first and second order derivatives so as to be able to estimate tangent and curvature. In particular, it smoothes digital contours but could be used for other kind of contours.

Description of template class 'BinomialConvolver'.

Template Parameters:
TConstIteratorOnPointsthe type that represents an iterator in a sequence of points. Each component of Point must be convertible into a double.
TValuethe type for storing the convolved versions of the contour (double as default).
See also:
testBinomialConvolver.cpp

Definition at line 73 of file BinomialConvolver.h.


Member Typedef Documentation

template<typename TConstIteratorOnPoints, typename TValue = double>
typedef TConstIteratorOnPoints DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::ConstIteratorOnPoints

Definition at line 78 of file BinomialConvolver.h.

template<typename TConstIteratorOnPoints, typename TValue = double>
typedef ConstIteratorOnPoints::value_type DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::Point

Definition at line 79 of file BinomialConvolver.h.

template<typename TConstIteratorOnPoints, typename TValue = double>
typedef TValue DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::Value

Definition at line 77 of file BinomialConvolver.h.


Constructor & Destructor Documentation

template<typename TConstIteratorOnPoints , typename TValue >
DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::BinomialConvolver ( unsigned int  n = 1)
inline

Constructor. The object is not valid.

Parameters:
nthe parameter for the size of the binomial kernel (which is then 2^n).
See also:
init

Definition at line 51 of file BinomialConvolver.ih.

{
setSize( n );
}
template<typename TConstIteratorOnPoints , typename TValue >
DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::~BinomialConvolver ( )
inline

Destructor.

Definition at line 44 of file BinomialConvolver.ih.

{
}
template<typename TConstIteratorOnPoints, typename TValue = double>
DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::BinomialConvolver ( const BinomialConvolver< TConstIteratorOnPoints, TValue > &  other)
private

Copy constructor.

Parameters:
otherthe object to clone. Forbidden by default.

Member Function Documentation

template<typename TConstIteratorOnPoints , typename TValue >
TValue DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::curvature ( int  i) const
inline
Parameters:
iany index.
Returns:
the curvature of the signal (0 is the first point).

NB: depends on the gridstep.

Definition at line 172 of file BinomialConvolver.ih.

{
Value denom = pow( myDX[ i ] * myDX[ i ] + myDY[ i ] * myDY[ i ], 1.5 );
return ( denom != TValue( 0.0 ) )
? ( myDDX[ i ] * myDY[ i ] - myDDY[ i ] * myDX[ i ] ) / denom / myH
: TValue( 0.0 );
}
template<typename TConstIteratorOnPoints , typename TValue >
std::pair< TValue, TValue > DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::d2x ( int  i) const
inline
Parameters:
iany index.
Returns:
the second derivative of the position (x''[ i ],y''[ i ]) (0 is the first point).

Definition at line 152 of file BinomialConvolver.ih.

{
return std::make_pair( myDDX[ i ], myDDY[ i ] );
}
template<typename TConstIteratorOnPoints , typename TValue >
std::pair< TValue, TValue > DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::dx ( int  i) const
inline
Parameters:
iany index.
Returns:
the derivative of the position (x'[ i ],y'[ i ]) (0 is the first point).

Definition at line 143 of file BinomialConvolver.ih.

{
return std::make_pair( myDX[ i ], myDY[ i ] );
}
template<typename TConstIteratorOnPoints , typename TValue >
int DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::index ( const ConstIteratorOnPoints it) const
inline

Given a valid iterator [it], return the corresponding index position in the binomial convolver in logarithmic time. The method init should have been called before.

See also:
init
Parameters:
itany valid iterator
Returns:
its index for accessing geometric data.

Definition at line 78 of file BinomialConvolver.ih.

{
typename std::map<ConstIteratorOnPoints,int>::const_iterator
map_it = myMapIt2Idx.find( it );
if ( map_it != myMapIt2Idx.end() )
return map_it->second;
ASSERT( false );
return 0;
}
template<typename TConstIteratorOnPoints , typename TValue >
void DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::init ( const double  h,
const ConstIteratorOnPoints itb,
const ConstIteratorOnPoints ite,
const bool  isClosed 
)
inline

Initializes the convolver with some sequence of points.

Parameters:
hgrid size (must be >0).
itb,beginiterator
ite,enditerator
isClosedtrue if the input range is viewed as closed.

The object is then valid.

Definition at line 93 of file BinomialConvolver.ih.

{
myMapIt2Idx.clear();
myH = h;
myBegin = itb;
myEnd = ite;
unsigned int aSize = 0;
for ( ConstIteratorOnPoints it = itb; it != ite; ++it )
{
myMapIt2Idx[ it ] = aSize;
++aSize;
}
myX.init( aSize, 0, isClosed, 0.0 );
myY.init( aSize, 0, isClosed, 0.0 );
aSize = 0;
for ( ConstIteratorOnPoints it = itb; it != ite; ++it, ++aSize )
{
/* myX[ size ] = it->operator[]( 0 );
myY[ size ] = it->operator[]( 1 );*/
// TRIS ConstIterator may have no -> operator
Point p(*it);
myX[ aSize ] = p[0];
myY[ aSize ] = p[1];
}
Signal<double> G = Signal<double>::G2n( myN );
myX = myX * G;
myY = myY * G;
myDX = myX * Signal<double>::Delta();
myDY = myY * Signal<double>::Delta();
myDDX = myDX * Signal<double>::Delta();
myDDY = myDY * Signal<double>::Delta();
}
template<typename TConstIteratorOnPoints , typename TValue >
bool DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 242 of file BinomialConvolver.ih.

{
return true;
}
template<typename TConstIteratorOnPoints, typename TValue = double>
BinomialConvolver& DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::operator= ( const BinomialConvolver< TConstIteratorOnPoints, TValue > &  other)
private

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'. Forbidden by default.
template<typename TConstIteratorOnPoints , typename TValue >
void DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::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 230 of file BinomialConvolver.ih.

{
out << "[BinomialConvolver]";
}
template<typename TConstIteratorOnPoints , typename TValue >
void DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::setSize ( unsigned int  n)
inline
Parameters:
nthe parameter for the size of the binomial kernel (which is then 2^n).

Definition at line 60 of file BinomialConvolver.ih.

{
myN = n;
}
template<typename TConstIteratorOnPoints , typename TValue >
unsigned int DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::size ( ) const
inline
Returns:
the parameter for the size of the binomial kernel (which is then 2^n).

Definition at line 69 of file BinomialConvolver.ih.

{
return myN;
}
template<typename TConstIteratorOnPoints , typename TValue >
unsigned int DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::suggestedSize ( const double  h,
const ConstIteratorOnPoints itb,
const ConstIteratorOnPoints ite 
)
inlinestatic
Returns:
the suggested size for the binomial convolver as ceil( d / pow( h, 1.0/3.0 ) ), with d the diameter of the contour.

Definition at line 190 of file BinomialConvolver.ih.

{
Point p(*itb);
TValue xmin = p[ 0 ];
TValue ymin = p[ 1 ];
TValue xmax = p[ 0 ];
TValue ymax = p[ 1 ];
for ( ConstIteratorOnPoints it = itb; it != ite; ++it )
{
/* TValue x = it->operator[]( 0 );
TValue y = it->operator[]( 1 );*/
// TRIS ConstIterator may have no -> operator
Point pp(*it);
TValue x = pp[0];
TValue y = pp[1];
if ( x < xmin ) xmin = x;
if ( x > xmax ) xmax = x;
if ( y < ymin ) ymin = y;
if ( y > ymax ) ymax = y;
}
TValue diameter = ( xmax - xmin ) > ( ymax - ymin )
? ( xmax - xmin )
: ( ymax - ymin );
// return (unsigned int) ceil( 0.5 / pow( h / diameter, 4.0/3.0 ) );
//TRIS (diameter*h is the diameter of the shape)
return (unsigned int) ceil( diameter / pow( h, 1.0/3.0 ) );
}
template<typename TConstIteratorOnPoints , typename TValue >
std::pair< TValue, TValue > DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::tangent ( int  i) const
inline
Parameters:
iany index.
Returns:
the normalized tangent vector (x'[ i ],y'[ i ]) (0 is the first point).

Definition at line 161 of file BinomialConvolver.ih.

{
Value n = sqrt( myDX[ i ] * myDX[ i ] +
myDY[ i ] * myDY[ i ] );
return std::make_pair( -myDX[ i ] / n, -myDY[ i ] / n );
}
template<typename TConstIteratorOnPoints , typename TValue >
std::pair< TValue, TValue > DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::x ( int  i) const
inline
Parameters:
iany index.
Returns:
the position vector (x[ i ],y[ i ]) (0 is the first point).

Definition at line 134 of file BinomialConvolver.ih.

{
return std::make_pair( myX[ i ], myY[ i ] );
}

Field Documentation

template<typename TConstIteratorOnPoints, typename TValue = double>
ConstIteratorOnPoints DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::myBegin
protected

Copy of the begin iterator.

Definition at line 213 of file BinomialConvolver.h.

template<typename TConstIteratorOnPoints, typename TValue = double>
Signal<Value> DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::myDDX
protected

Definition at line 209 of file BinomialConvolver.h.

template<typename TConstIteratorOnPoints, typename TValue = double>
Signal<Value> DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::myDDY
protected

Definition at line 210 of file BinomialConvolver.h.

template<typename TConstIteratorOnPoints, typename TValue = double>
Signal<Value> DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::myDX
protected

Definition at line 207 of file BinomialConvolver.h.

template<typename TConstIteratorOnPoints, typename TValue = double>
Signal<Value> DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::myDY
protected

Definition at line 208 of file BinomialConvolver.h.

template<typename TConstIteratorOnPoints, typename TValue = double>
ConstIteratorOnPoints DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::myEnd
protected

Copy of the end iterator.

Definition at line 216 of file BinomialConvolver.h.

template<typename TConstIteratorOnPoints, typename TValue = double>
double DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::myH
protected

Definition at line 204 of file BinomialConvolver.h.

template<typename TConstIteratorOnPoints, typename TValue = double>
std::map<ConstIteratorOnPoints,int> DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::myMapIt2Idx
protected

Definition at line 219 of file BinomialConvolver.h.

template<typename TConstIteratorOnPoints, typename TValue = double>
unsigned int DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::myN
protected

Definition at line 203 of file BinomialConvolver.h.

template<typename TConstIteratorOnPoints, typename TValue = double>
Signal<Value> DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::myX
protected

Definition at line 205 of file BinomialConvolver.h.

template<typename TConstIteratorOnPoints, typename TValue = double>
Signal<Value> DGtal::BinomialConvolver< TConstIteratorOnPoints, TValue >::myY
protected

Definition at line 206 of file BinomialConvolver.h.


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