DGtal 1.3.0
Loading...
Searching...
No Matches
Static Public Member Functions
DGtal::FrechetShortcut< TIterator, TInteger >::Tools Struct Reference

#include <DGtal/geometry/curves/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 computeOctant (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 351 of file FrechetShortcut.h.

Member Function Documentation

◆ angleVectVect()

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
uand
vtwo vectors
Returns
an angle

Definition at line 540 of file FrechetShortcut.h.

541 {
542 IntegerComputer<Integer> ic;
543 return acos((double)ic.dotProduct(u,v)/(u.norm()*v.norm()));
544 }

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

◆ chainCode2Vect()

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
dan int
Returns
a vector

Definition at line 651 of file FrechetShortcut.h.

652 {
653 Vector v;
654 switch(d){
655
656 case 0:{
657 v[0] = 1;
658 v[1] = 0;
659 break;
660 }
661 case 1:{
662 v[0] = 1;
663 v[1] = 1;
664 break;
665 }
666 case 2:{
667 v[0] = 0;
668 v[1] = 1;
669 break;
670 }
671 case 3:{
672 v[0] = -1;
673 v[1] = 1;
674 break;
675 }
676 case 4:{
677 v[0] = -1;
678 v[1] = 0;
679 break;
680 }
681 case 5:{
682 v[0] = -1;
683 v[1] = -1;
684 break;
685 }
686 case 6:{
687 v[0] = 0;
688 v[1] = -1;
689 break;
690 }
691 case 7:{
692 v[0] = 1;
693 v[1] = -1;
694 break;
695 }
696
697 }
698
699 return v;
700 }
FreemanChain< int >::Vector Vector

◆ circle_circle_intersection()

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: three doubles 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 397 of file FrechetShortcut.h.

401 {
402 double a, dx, dy, d, h, rx, ry;
403 double x2, y2;
404
405 /* dx and dy are the vertical and horizontal distances between
406 * the circle centers.
407 */
408 dx = x1 - x0;
409 dy = y1 - y0;
410
411 /* Determine the straight-line distance between the centers. */
412 //d = sqrt((dy*dy) + (dx*dx));
413 d = hypot(dx,dy); // Suggested by Keith Briggs
414
415 /* Check for solvability. */
416 if (d > (r0 + r1))
417 {
418 /* no solution. circles do not intersect. */
419 std::cerr << "Warning : the two circles do not intersect -> should never happen" << std::endl;
420 return 0; //I. Sivignon 05/2010 should never happen for our specific use.
421 }
422 if (d < fabs(r0 - r1))
423 {
424 /* no solution. one circle is contained in the other */
425 return 0;
426 }
427
428 /* 'point 2' is the point where the line through the circle
429 * intersection points crosses the line between the circle
430 * centers.
431 */
432
433 /* Determine the distance from point 0 to point 2. */
434 a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;
435
436 /* Determine the coordinates of point 2. */
437 x2 = x0 + (dx * a/d);
438 y2 = y0 + (dy * a/d);
439
440 /* Determine the distance from point 2 to either of the
441 * intersection points.
442 */
443 h = sqrt((r0*r0) - (a*a));
444
445 /* Now determine the offsets of the intersection points from
446 * point 2.
447 */
448 rx = -dy * (h/d);
449 ry = dx * (h/d);
450
451 /* Determine the absolute intersection points. */
452 *xi = x2 + rx;
453 *xi_prime = x2 - rx;
454 *yi = y2 + ry;
455 *yi_prime = y2 - ry;
456
457 return 1;
458 }

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

◆ circleTangentPoints()

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
[in]xthe first coordinate of X.
[in]ythe second coordinate of X.
[in]x1the first coordinate of the circle center X1.
[in]y1the second coordinate of the circle center X1.
[in]r1the circle radius.
[out]xipointer to the first coordinate of the first intersection point.
[out]yipointer to the second coordinate of the first intersection point.
[out]xi_primepointer to the first coordinate of the second intersection point.
[out]yi_primepointer to the second coordinate of the second intersection point.
Returns
result of the call to circle_circle_intersection

Definition at line 481 of file FrechetShortcut.h.

483 {
484 double x0 = (x+x1)/2;
485 double y0 = (y+y1)/2;
486 double r0 = sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1))/2;
487
488 int res =
489 circle_circle_intersection(x0,y0,r0,x1,y1,r1,xi,yi,xi_prime,yi_prime);
490
491 return res;
492
493 }
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)

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

◆ computeAngle()

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
x0x0
y0y0
x1x1
y1y1
Returns
an angle

Definition at line 505 of file FrechetShortcut.h.

506 {
507 double x = x1-x0;
508 double y = y1-y0;
509
510 if(x!=0)
511 {
512 double alpha = y/x;
513
514 if(x>0 && y>=0)
515 return atan(alpha);
516 else
517 if(x>0 && y<0)
518 return atan(alpha)+2*M_PI;
519 else
520 if(x<0)
521 return atan(alpha)+M_PI;
522 }
523 else
524 {
525 if(y>0)
526 return M_PI_2;
527 else
528 return 3*M_PI_2;
529 }
530 return -1;
531 }

◆ computeChainCode()

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
pand
qtwo points
Returns
an int

Definition at line 551 of file FrechetShortcut.h.

552 {
553 int d;
554 Coordinate x2 = q[0];
555 Coordinate y2 = q[1];
556 Coordinate x1 = p[0];
557 Coordinate y1 = p[1];
558
559 if(x2-x1==0)
560 if(y2-y1==1)
561 d=2;
562 else
563 d=6;
564 else
565 if(x2-x1==1)
566 if(y2-y1==0)
567 d=0;
568 else
569 if(y2-y1==1)
570 d=1;
571 else
572 d=7;
573 else
574 if(y2-y1==0)
575 d=4;
576 else
577 if(y2-y1==1)
578 d=3;
579 else
580 d=5;
581 return d;
582 }
Vector::Coordinate Coordinate

◆ computeOctant()

template<typename TIterator , typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static int DGtal::FrechetShortcut< TIterator, TInteger >::Tools::computeOctant ( Point  p,
Point  q 
)
inlinestatic

Computes the octant of the direction pq

Parameters
pand
qtwo points
Returns
an int

Definition at line 589 of file FrechetShortcut.h.

590 {
591 int d = 0;
592 Coordinate x = q[0]-p[0];
593 Coordinate y = q[1]-p[1];
594
595 if(x>=0)
596 {
597 if(y>=0)
598 {
599 if(x>y)
600 d=0; // 0 <= y < x
601 else
602 if(x!=0)
603 d=1; // 0 <= x <= y
604 }
605 else
606 {
607 if(x>=abs(y))
608 d=7; // 0 < abs(y) <= x
609 else
610 d=6; // 0 <= x < abs(y)
611 }
612 }
613 if(x<=0)
614 {
615 if(y>0)
616 if(abs(x)>=y)
617 d=3; //
618 else
619 d=2;
620 else
621 {
622 if(abs(x)>abs(y))
623 d=4;
624 else
625 if(x!=0)
626 d=5;
627 }
628 }
629 return d;
630
631 }

◆ isBetween()

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
ii
aa
bb
nn
Returns
true if i is between a anb d, false otherwise

Definition at line 362 of file FrechetShortcut.h.

363 {
364 if(a<=b)
365 return (i>=a && i<=b);
366 else
367 return ((i>=a && i<=n) || (i>=0 && i<=b));
368 }

◆ rot()

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 641 of file FrechetShortcut.h.

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

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