DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Private Member Functions | Private Attributes
DGtal::MeasureOfStraightLines Class Reference

#include <MeasureOfStraightLines.h>

Public Member Functions

 MeasureOfStraightLines ()
 ~MeasureOfStraightLines ()
void selfDisplay (std::ostream &out) const
bool isValid () const
double computeMeasure (const std::vector< double > &a, const std::vector< double > &b)
double computeCentroidA (const std::vector< double > &a, const std::vector< double > &b)
double computeCentroidB (const std::vector< double > &a, const std::vector< double > &b)
void setEpsilon (const double aValue)

Private Member Functions

 MeasureOfStraightLines (const MeasureOfStraightLines &other)
MeasureOfStraightLinesoperator= (const MeasureOfStraightLines &other)
double computeMeasureEdge (double a0, double b0, double a1, double b1)
double computeCentroidEdge_a (double a0, double b0, double a1, double b1)
double computeCentroidEdge_b (double a0, double b0, double a1, double b1)
double __computeCentroidTriApprox_b (double a0, double b0, double a1, double b1)
double __computeCentroidEdgeApprox_b (double a0, double b0, double a1, double b1)
double __computeCentroidSquare_b (double x1, double y1, double x2, double y2)
int sign (const double a)

Private Attributes

double myEpsilon

Detailed Description

The aim of this class is to compute the measure in the Lebesgues sense of the set of straight lines associated to domains defined as polygons in the (a,b)-parameter space. This parameter space maps the line $ax-y+b=0$ to the point $(a,b)$.

Description of class 'MeasureOfStraightLines'

Aim:

   * @inproceedings{COEURJOLLY:2009:HAL-00432711:1,
   *   title = { {M}easure of {S}traight {L}ines and its {A}pplications in {D}igital {G}eometry},
   *   author = {{C}oeurjolly, {D}avid and {S}ivignon, {I}sabelle},
   *   booktitle = {13th {I}nternational {W}orkshop on {C}ombinatorial {I}mage {A}nalysis 13th {I}nternational {W}orkshop on {C}ombinatorial {I}mage {A}nalysis },
   *   publisher = {{R}esearch {P}ublishing {S}ervices },
   *   pages = {1-12 },
   *   address = {{C}ancun {M}exique },
   *   audience = {internationale },
   *   year = {2009},
   *   URL = {http://hal.archives-ouvertes.fr/hal-00432711/PDF/mesure.pdf},
   * }
   * 
See also:
testMeasure.cpp
Todo:
Create a vector<Point> interface

Definition at line 79 of file MeasureOfStraightLines.h.


Constructor & Destructor Documentation

DGtal::MeasureOfStraightLines::MeasureOfStraightLines ( )
inline

Constructor.

Default value

Definition at line 50 of file MeasureOfStraightLines.ih.

References myEpsilon.

{
myEpsilon = 0.0005;
}
DGtal::MeasureOfStraightLines::~MeasureOfStraightLines ( )
inline

Destructor.

Definition at line 61 of file MeasureOfStraightLines.ih.

{
}
DGtal::MeasureOfStraightLines::MeasureOfStraightLines ( const MeasureOfStraightLines other)
private

Copy constructor.

Parameters:
otherthe object to clone. Forbidden by default.

Member Function Documentation

double DGtal::MeasureOfStraightLines::__computeCentroidEdgeApprox_b ( double  a0,
double  b0,
double  a1,
double  b1 
)
inlineprivate

Approximate the centroid on 'b' on the trapezioid (a0,0)-(a0,b0)-(a1,b1)-(a1,0) (internal function)

Parameters:
a0abscissa first point.
b0ordinate of the first point.
a1abscissa of the second point.
b1ordinate of the second point.

Approximate the centroid on 'b' on the trapezioid (a0,0)-(a0,b0)-(a1,b1)-(a1,0) (internal function)

A0 -> A1

Definition at line 245 of file MeasureOfStraightLines.ih.

{
double measure,y2;
unsigned int nb_step;
if ( a1 < a0 )
{
double tmp = a0;
a0 = a1;
a1 = tmp;
tmp = b0;
b0 = b1;
b1 = tmp;
}
measure = 0;
nb_step = ( unsigned int ) floor ( fabs ( a1-a0 ) /myEpsilon );
double slope = ( b1-b0 ) / ( a1-a0 );
double decal = b1 - ( b1-b0 ) / ( a1-a0 ) *a1;
if ( slope == 0 )
return __computeCentroidSquare_b ( a0, 0, a1, b0 );
for ( unsigned int i=0; i < nb_step ; i++ )
{
y2 = ( b1-b0 ) / ( a1-a0 ) * ( a0+ ( i+1 ) *myEpsilon ) + decal;
if ( y2>0 )
measure += __computeCentroidSquare_b ( a0+i*myEpsilon, 0, a0+ ( i+1 ) *myEpsilon, y2 );
else
measure += __computeCentroidSquare_b ( a0+i*myEpsilon, y2, a0+ ( i+1 ) *myEpsilon, 0 );
}
return measure;
}
double DGtal::MeasureOfStraightLines::__computeCentroidSquare_b ( double  x1,
double  y1,
double  x2,
double  y2 
)
inlineprivate

Compute the centroid on 'b' on the rectangular domain with vertices (x1,,y1) - (x2,y2)

Precondition:
y1<y2
Parameters:
x1abscissa first point.
y1ordinate of the first point.
x2abscissa of the second point.
y2ordinate of the second point.

Compute the centroid on 'b' on the rectangular domain with vertices (x1,,y1) - (x2,y2) PRECONDITION: y1<y2

Definition at line 218 of file MeasureOfStraightLines.ih.

{
double val;
val = ( ( -1.0* ( sqrt ( 1.0 + pow ( x1,2 ) ) *x2 ) + x1*sqrt ( 1 + pow ( x2,2 ) ) ) * ( pow ( y1,2 ) - pow ( y2,2 ) ) ) / ( 2.0*sqrt ( ( 1.0 + pow ( x1,2 ) ) * ( 1.0 + pow ( x2,2 ) ) ) );
ASSERT ( val>=0 );
return val;
}
double DGtal::MeasureOfStraightLines::__computeCentroidTriApprox_b ( double  a0,
double  b0,
double  a1,
double  b1 
)
inlineprivate

Approximate the centroid on 'b' on the triangle (0,0)-(a0,b0)-(a1,b1) (internal function)

Parameters:
a0abscissa first point.
b0ordinate of the first point.
a1abscissa of the second point.
b1ordinate of the second point.

Approximate the centroid on 'b' on the triangle (0,0)-(a0,b0)-(a1,b1) (internal function)

Definition at line 285 of file MeasureOfStraightLines.ih.

{
int signe = sign ( a0*b1 - a1*b0 );
double measure = 0;
double m_A0A1=0, m_0A0=0, m_0A1=0;
if ( ( b0 != 0 ) && ( a0 != 0 ) )
m_0A0 = __computeCentroidEdgeApprox_b ( 0,0,a0,b0 );
if ( ( b1 != 0 ) && ( a1 != 0 ) )
m_0A1 = __computeCentroidEdgeApprox_b ( 0,0,a1,b1 );
if ( ( a1 != a0 ) )
m_A0A1 = __computeCentroidEdgeApprox_b ( a0,b0,a1,b1 );
ASSERT ( m_0A0>=0 );
ASSERT ( m_0A1>=0 );
ASSERT ( m_A0A1>=0 );
if ( a0 < a1 )
{
double det = ( a1 * ( b0 - b1 ) - b1* ( a0 - a1 ) );
if ( det >0 )
measure = m_0A0 + m_A0A1 - m_0A1;
else
measure = m_0A1 - m_0A0 - m_A0A1;
}
else
{
double det = ( a0 * ( b1 - b0 ) - b0* ( a1 - a0 ) );
if ( det >0 )
measure = m_0A1 + m_A0A1 - m_0A0;
else
measure = m_0A0 - m_0A1 - m_A0A1;
}
ASSERT ( measure>=0 );
return signe*measure;
}
double DGtal::MeasureOfStraightLines::computeCentroidA ( const std::vector< double > &  a,
const std::vector< double > &  b 
)
inline

Compute the abscissa of the centroid of the polygon {(a_i,b_i)} in the (a,b)-parameter space with respect to the measure of lines.

REQUIREMENTS:

  • The polygon is given counter-clockwise
  • a_i > 0
Parameters:
athe a-value of polygon vertices
bthe b-value of polygon vertices
Returns:
the measure value (positive value)

Compute the abscissa of the centroid of the polygon {(a_i,b_i)} in the (a,b)-parameter space

Parameters:
athe a-value of polygon vertices
bthe b-value of polygon vertices
Returns:
the measure value (positive value)

Definition at line 164 of file MeasureOfStraightLines.ih.

{
double measure = 0;
double C_a = 0;
ASSERT(a.size() == b.size());
for (unsigned int i=0 ; i < a.size() ; i++)
{
measure += computeMeasureEdge( a[i], b[i],
a[ ( i+1 ) % a.size()],b[ ( i+1 ) %a.size()] );
C_a += computeCentroidEdge_a ( a[i], b[i],
a[ ( i+1 ) % a.size()],b[ ( i+1 ) %a.size()] );
}
return C_a/measure;
}
double DGtal::MeasureOfStraightLines::computeCentroidB ( const std::vector< double > &  a,
const std::vector< double > &  b 
)
inline

Compute the ordinate of the centroid of the polygon {(a_i,b_i)} in the (a,b)-parameter space with respect to the measure of lines. Note that there is a numerical approximation is performed.

REQUIREMENTS:

  • The polygon is given counter-clockwise
  • a_i > 0
Parameters:
athe a-value of polygon vertices
bthe b-value of polygon vertices
Returns:
the measure value (positive value)

Compute the abscissa of the centroid of the polygon {(a_i,b_i)} in the (a,b)-parameter space

Parameters:
athe a-value of polygon vertices
bthe b-value of polygon vertices
Returns:
the measure value (positive value)

Definition at line 191 of file MeasureOfStraightLines.ih.

{
double measure = 0;
double C_b = 0;
ASSERT(a.size() == b.size());
for (unsigned int i=0 ; i < a.size() ; i++)
{
measure += computeMeasureEdge( a[i], b[i],
a[ ( i+1 ) % a.size()],b[ ( i+1 ) %a.size()] );
C_b += computeCentroidEdge_b ( a[i], b[i],
a[ ( i+1 ) % a.size()],b[ ( i+1 ) %a.size()] );
}
return C_b/measure;
}
double DGtal::MeasureOfStraightLines::computeCentroidEdge_a ( double  a0,
double  b0,
double  a1,
double  b1 
)
inlineprivate

Compute the abscissa of the centroid associated to an edge (a0,b0)-(a1,b1) It returns the measure of the triangle defined by the origin and the edge.

Parameters:
a0abscissa first point.
b0ordinate of the first point.
a1abscissa of the second point.
b1ordinate of the second point.
Returns:
the measure

Compute the centroid on 'a' on the triangle (0,0)-(a0,b0)-(a1,b1)

Definition at line 356 of file MeasureOfStraightLines.ih.

{
//double measure=0;
double delta= ( a0*b1 - a1*b0 );
if ( ( b0 == 0 ) && ( b1 == 0 ) )
return 0;
if ( ( a0 == 0 ) && ( a1 == 0 ) )
return 0;
if ( a0 == 0 )
return delta* ( a1 - boost::math::asinh ( a1 ) ) / ( a1*a1 );
if ( a1 == 0 )
return delta* ( a0 - boost::math::asinh ( a0 ) ) / ( a0*a0 );
if ( a0 == a1 )
return delta* ( ( -sqrt ( 1 + pow ( a1,-2 ) ) - 1.0/ ( a1*sqrt ( 1 + pow ( a1,2 ) ) ) + a1/sqrt ( 1 + pow ( a1,2 ) ) +
( 2*boost::math::asinh ( a1 ) ) /pow ( a1,2 ) ) /2. );
return delta* ( ( - ( a1*boost::math::asinh ( a0 ) ) + a0*boost::math::asinh ( a1 ) ) / ( a0* ( a0 - a1 ) *a1 ) );
}
double DGtal::MeasureOfStraightLines::computeCentroidEdge_b ( double  a0,
double  b0,
double  a1,
double  b1 
)
inlineprivate

Compute the ordinate of the centroid associated to an edge (a0,b0)-(a1,b1) It returns the measure of the triangle defined by the origin and the edge.

Parameters:
a0abscissa first point.
b0ordinate of the first point.
a1abscissa of the second point.
b1ordinate of the second point.
Returns:
the measure

Compute the centroid on 'b' on the triangle (0,0)-(a0,b0)-(a1,b1)

Definition at line 327 of file MeasureOfStraightLines.ih.

{
//double measure=0;
double delta= ( a0*b1 - a1*b0 );
if ( ( b0 == 0 ) && ( b1 == 0 ) )
return 0;
if ( ( a0 == 0 ) && ( a1 == 0 ) )
return 0;
if ( a0 == 0 )
return delta* ( a1* ( ( -2 + sqrt ( 1 + a1*a1 ) ) *b0 + 2*b1 ) + ( b0 - 2*b1 ) *boost::math::asinh ( a1 ) ) / ( 2*a1*a1*a1 );
if ( a1 == 0 )
return delta* ( a0* ( 2*b0 + ( -2 + sqrt ( 1 + a0*a0 ) ) *b1 ) + ( -2*b0 + b1 ) *boost::math::asinh ( a0 ) ) / ( 2*a0*a0*a0 );
if ( a0 == a1 )
return delta* ( ( - ( ( a1* ( b0 + a1* ( -a1 + sqrt ( 1 + pow ( a1,-2 ) ) *sqrt ( 1 + pow ( a1,2 ) ) ) *
b1 ) ) /sqrt ( 1.0 + pow ( a1,2 ) ) ) + ( b0 + b1 ) *boost::math::asinh ( a1 ) ) /
( 2.*pow ( a1,3 ) ) );
return __computeCentroidTriApprox_b ( a0,b0,a1,b1 );
}
double DGtal::MeasureOfStraightLines::computeMeasure ( const std::vector< double > &  a,
const std::vector< double > &  b 
)
inline

Compute the measure of the polygon {(a_i,b_i)} in the (a,b)-parameter space

REQUIREMENTS:

  • The polygon is given counter-clockwise
  • a_i > 0
Parameters:
athe a-value of polygon vertices
bthe b-value of polygon vertices
Returns:
the measure value (positive value)

Compute the measure of the polygon {(a_i,b_i)} in the (a,b)-parameter space

Parameters:
athe a-value of polygon vertices
bthe b-value of polygon vertices
Returns:
the measure value (positive value)

Definition at line 140 of file MeasureOfStraightLines.ih.

{
double measure = 0;
ASSERT(a.size() == b.size());
for (unsigned int i=0 ; i < a.size() ; i++)
{
measure += computeMeasureEdge ( a[i], b[i],
a[ ( i+1 ) % a.size()],b[ ( i+1 ) %a.size()] );
}
return measure;
}
double DGtal::MeasureOfStraightLines::computeMeasureEdge ( double  a0,
double  b0,
double  a1,
double  b1 
)
inlineprivate

Compute the measure associated to an edge (a0,b0)-(a1,b1) It returns the measure of the triangle defined by the origin and the edge.

Parameters:
a0abscissa first point.
b0ordinate of the first point.
a1abscissa of the second point.
b1ordinate of the second point.
Returns:
the measure

Compute the measure associated to the Edge (a0,b0) – (a1,b1) in the (a,b)-space

Definition at line 91 of file MeasureOfStraightLines.ih.

{
//double measure=0;
//Aligned with the 'b' axis
if ( ( b0 == 0 ) && ( b1 == 0 ) )
return 0;
//Aligned with the 'b' axis
if ( ( a0 == 0 ) && ( a1 == 0 ) )
return 0;
double delta = ( a0*b1 - a1*b0 );
if ( a0 == 0 )
return delta * ( 1.0/ ( 1.0 + sqrt ( 1 + pow ( a1,2 ) ) ) );
if ( a1 == 0 )
return delta * ( ( -1.0 + sqrt ( 1.0 + pow ( a0,2 ) ) ) /pow ( a0,2 ) );
if ( a0 != a1 )
{
return delta * ( ( a0 - a1 + sqrt ( 1 + pow ( a0,2 ) ) *a1 - a0*sqrt ( 1 + pow ( a1,2 ) ) ) / ( pow ( a0,2 ) *a1 - a0*pow ( a1,2 ) ) );
}
else
return delta * a1/ ( a0* ( 1 + pow ( a1,2 ) + sqrt ( 1 + pow ( a1,2 ) ) ) );
}
bool DGtal::MeasureOfStraightLines::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 82 of file MeasureOfStraightLines.ih.

{
return true;
}
MeasureOfStraightLines& DGtal::MeasureOfStraightLines::operator= ( const MeasureOfStraightLines other)
private

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'. Forbidden by default.
void DGtal::MeasureOfStraightLines::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 71 of file MeasureOfStraightLines.ih.

{
out << "[MeasureOfStraightLines]";
}
void DGtal::MeasureOfStraightLines::setEpsilon ( const double  aValue)
inline

Set the internal Epsilon threshold for the numerical approximation.

Parameters:
aValuethe new epsilon value

Set the epsilon threshold in the numerical approximation.

Parameters:
aValuethe new epsilon value

Definition at line 124 of file MeasureOfStraightLines.ih.

{
myEpsilon = aValue;
}
int DGtal::MeasureOfStraightLines::sign ( const double  a)
inlineprivate
Parameters:
aa value
Returns:
the sign of a number (1 or -1)

Definition at line 230 of file MeasureOfStraightLines.ih.

{
if ( a>=0 )
return 1;
else
return -1;
}

Field Documentation

double DGtal::MeasureOfStraightLines::myEpsilon
private

Definition at line 171 of file MeasureOfStraightLines.h.

Referenced by MeasureOfStraightLines().


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