DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Static Public Member Functions
DGtal::FrechetShortcut< TIterator, TInteger >::Tools Struct Reference

#include <FrechetShortcut.h>

Static Public Member Functions

static bool isBetween (double i, double a, double b, double n)
static int circle_circle_intersection (double x0, double y0, double r0, double x1, double y1, double r1, double *xi, double *yi, double *xi_prime, double *yi_prime)
static int circleTangentPoints (double x, double y, double x1, double y1, double r1, double *xi, double *yi, double *xi_prime, double *yi_prime)
static double computeAngle (double x0, double y0, double x1, double y1)
static double angleVectVect (Vector u, Vector v)
static int computeChainCode (Point p, Point q)
static int computeQuadrant (Point p, Point q)
static int rot (int d, int quad)
static Vector chainCode2Vect (int d)

Detailed Description

template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
struct DGtal::FrechetShortcut< TIterator, TInteger >::Tools

Definition at line 331 of file FrechetShortcut.h.


Member Function Documentation

template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static double DGtal::FrechetShortcut< TIterator, TInteger >::Tools::angleVectVect ( Vector  u,
Vector  v 
)
inlinestatic

Angle between two vectors

Parameters:
twovectors
Returns:
an angle

Definition at line 517 of file FrechetShortcut.h.

References DGtal::IntegerComputer< TInteger >::dotProduct().

Referenced by DGtal::FrechetShortcut< TIterator, TInteger >::Backpath::updateIntervals(), and DGtal::FrechetShortcut< TIterator, TInteger >::Backpath::updateOcculters().

{
return acos((double)ic.dotProduct(u,v)/(u.norm()*v.norm()));
}
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static Vector DGtal::FrechetShortcut< TIterator, TInteger >::Tools::chainCode2Vect ( int  d)
inlinestatic

Converts a chain code into a vector

Parameters:
anint
Returns:
a vector

Definition at line 628 of file FrechetShortcut.h.

Referenced by DGtal::FrechetShortcut< TIterator, TInteger >::Backpath::updateIntervals(), and DGtal::FrechetShortcut< TIterator, TInteger >::Backpath::updateOcculters().

{
Vector v;
switch(d){
case 0:{
v[0] = 1;
v[1] = 0;
break;
}
case 1:{
v[0] = 1;
v[1] = 1;
break;
}
case 2:{
v[0] = 0;
v[1] = 1;
break;
}
case 3:{
v[0] = -1;
v[1] = 1;
break;
}
case 4:{
v[0] = -1;
v[1] = 0;
break;
}
case 5:{
v[0] = -1;
v[1] = -1;
break;
}
case 6:{
v[0] = 0;
v[1] = -1;
break;
}
case 7:{
v[0] = 1;
v[1] = -1;
break;
}
}
return v;
}
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static int DGtal::FrechetShortcut< TIterator, TInteger >::Tools::circle_circle_intersection ( double  x0,
double  y0,
double  r0,
double  x1,
double  y1,
double  r1,
double *  xi,
double *  yi,
double *  xi_prime,
double *  yi_prime 
)
inlinestatic

Determine the points where two circles in a common plane intersect

Parameters:
threedoubles per circle (center, radius), pointers to the two intersection points
Returns:
0 if the circles do not intersect each other, 1 otherwise

Definition at line 385 of file FrechetShortcut.h.

Referenced by DGtal::FrechetShortcut< TIterator, TInteger >::Tools::circleTangentPoints().

{
double a, dx, dy, d, h, rx, ry;
double x2, y2;
/* dx and dy are the vertical and horizontal distances between
* the circle centers.
*/
dx = x1 - x0;
dy = y1 - y0;
/* Determine the straight-line distance between the centers. */
//d = sqrt((dy*dy) + (dx*dx));
d = hypot(dx,dy); // Suggested by Keith Briggs
/* Check for solvability. */
if (d > (r0 + r1))
{
/* no solution. circles do not intersect. */
std::cerr << "Warning : the two circles do not intersect -> should never happen" << std::endl;
return 0; //I. Sivignon 05/2010 should never happen for our specific use.
}
if (d < fabs(r0 - r1))
{
/* no solution. one circle is contained in the other */
return 0;
}
/* 'point 2' is the point where the line through the circle
* intersection points crosses the line between the circle
* centers.
*/
/* Determine the distance from point 0 to point 2. */
a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;
/* Determine the coordinates of point 2. */
x2 = x0 + (dx * a/d);
y2 = y0 + (dy * a/d);
/* Determine the distance from point 2 to either of the
* intersection points.
*/
h = sqrt((r0*r0) - (a*a));
/* Now determine the offsets of the intersection points from
* point 2.
*/
rx = -dy * (h/d);
ry = dx * (h/d);
/* Determine the absolute intersection points. */
*xi = x2 + rx;
*xi_prime = x2 - rx;
*yi = y2 + ry;
*yi_prime = y2 - ry;
return 1;
}
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static int DGtal::FrechetShortcut< TIterator, TInteger >::Tools::circleTangentPoints ( double  x,
double  y,
double  x1,
double  y1,
double  r1,
double *  xi,
double *  yi,
double *  xi_prime,
double *  yi_prime 
)
inlinestatic

Given a point X and a circle of center X1, compute the two points Xi and Xi' of the circle the tangent of which go through X. Since the triangle XXiX1 is a right triangle on Xi, the middle point M between X and X1 is equidistant to X, X1 and Xi. Thus, Xi belongs to the intersection of the circle (X1,r1) and the circle of center M and radius ||XX1||/2.

Parameters:
apoint (x,y), a circle of center (x1,y1) and a radius r1, pointers to the intersection points
Returns:
result of the call to circle_circle_intersection

Definition at line 461 of file FrechetShortcut.h.

References DGtal::FrechetShortcut< TIterator, TInteger >::Tools::circle_circle_intersection().

{
double x0 = (x+x1)/2;
double y0 = (y+y1)/2;
double r0 = sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1))/2;
int res =
circle_circle_intersection(x0,y0,r0,x1,y1,r1,xi,yi,xi_prime,yi_prime);
return res;
}
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static double DGtal::FrechetShortcut< TIterator, TInteger >::Tools::computeAngle ( double  x0,
double  y0,
double  x1,
double  y1 
)
inlinestatic

Compute the angle of the line passing through two points. Angle in [0,2pi]

Parameters:
twopoints (x0,y0) and (x1,y1)
Returns:
an angle

Definition at line 482 of file FrechetShortcut.h.

References M_PI, and M_PI_2.

Referenced by DGtal::FrechetShortcut< TIterator, TInteger >::Cone::Cone().

{
double x = x1-x0;
double y = y1-y0;
if(x!=0)
{
double alpha = y/x;
if(x>0 && y>=0)
return atan(alpha);
else
if(x>0 && y<0)
return atan(alpha)+2*M_PI;
else
if(x<0)
return atan(alpha)+M_PI;
}
else
{
if(y>0)
return M_PI_2;
else
return 3*M_PI_2;
}
return -1;
}
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static int DGtal::FrechetShortcut< TIterator, TInteger >::Tools::computeChainCode ( Point  p,
Point  q 
)
inlinestatic

Computes the chain code between two 8-connected pixels

Parameters:
twopoints
Returns:
an int

Definition at line 528 of file FrechetShortcut.h.

{
int d;
Coordinate x2 = q[0];
Coordinate y2 = q[1];
Coordinate x1 = p[0];
Coordinate y1 = p[1];
if(x2-x1==0)
if(y2-y1==1)
d=2;
else
d=6;
else
if(x2-x1==1)
if(y2-y1==0)
d=0;
else
if(y2-y1==1)
d=1;
else
d=7;
else
if(y2-y1==0)
d=4;
else
if(y2-y1==1)
d=3;
else
d=5;
return d;
}
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static int DGtal::FrechetShortcut< TIterator, TInteger >::Tools::computeQuadrant ( Point  p,
Point  q 
)
inlinestatic

Computes the octant of the direction pq

Parameters:
twopoints
Returns:
an int

Definition at line 566 of file FrechetShortcut.h.

References DGtal::abs().

{
int d;
Coordinate x = q[0]-p[0];
Coordinate y = q[1]-p[1];
if(x>=0)
{
if(y>=0)
{
if(x>y)
d=0; // 0 <= y < x
else
if(x!=0)
d=1; // 0 <= x <= y
}
else
{
if(x>=abs(y))
d=7; // 0 < abs(y) <= x
else
d=6; // 0 <= x < abs(y)
}
}
if(x<=0)
{
if(y>0)
if(abs(x)>=y)
d=3; //
else
d=2;
else
{
if(abs(x)>abs(y))
d=4;
else
if(x!=0)
d=5;
}
}
return d;
}
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static bool DGtal::FrechetShortcut< TIterator, TInteger >::Tools::isBetween ( double  i,
double  a,
double  b,
double  n 
)
inlinestatic

Determines if i is between a and b in the oriented toric space modulo n

Parameters:
fourintegers
Returns:
true if i is between a anb d, false otherwise

Definition at line 339 of file FrechetShortcut.h.

Referenced by DGtal::FrechetShortcut< TIterator, TInteger >::Cone::intersectConesSimple().

{
// if a<=b, a simple comparison enables to conclude
if(a<=b)
if(i>=a && i<=b)
return true;
else
return false;
else
{
//otherwise, translate the points such that a->0
int tmp = a;
a = fmod(a+n-tmp,n);
b = fmod(b+n-tmp,n);
i = fmod(i+n-tmp,n);
return isBetween(i,a,b,n);
}
}
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static int DGtal::FrechetShortcut< TIterator, TInteger >::Tools::rot ( int  d,
int  quad 
)
inlinestatic

Rotate the chain code d to put it in the frame where the octant 'quad' is treated as the first octant.

Parameters:
da chain code
quadthe octant
Returns:
an int (the new chain code)

Definition at line 618 of file FrechetShortcut.h.

{
return (d-quad+8)%8;
}

The documentation for this struct was generated from the following file: