DGtal  0.9.2
DSLSubsegment.h
1 
17 #pragma once
18 
29 #if defined(DSLSubsegment_RECURSES)
30 #error Recursive header files inclusion detected in DSLSubsegment.h
31 #else // defined(DSLSubsegment_RECURSES)
32 
33 #define DSLSubsegment_RECURSES
34 
35 #if !defined DSLSubsegment_h
36 
37 #define DSLSubsegment_h
38 
40 // Inclusions
41 #include <iostream>
42 #include <exception>
43 #include <iomanip>
44 #include "DGtal/base/Common.h"
46 
47 #include "DGtal/arithmetic/IntegerComputer.h"
48 
49 namespace DGtal
50 {
51 
53 // class DSLSubsegment
68 
71 
73 
74  template <typename TInteger, typename TNumber>
76  {
77  // ----------------------- Standard services ------------------------------
78  public:
79 
84 
85  // ----------------------- Interface --------------------------------------
86  public:
87 
92  void selfDisplay ( std::ostream & out ) const;
93 
98  bool isValid() const;
99 
103  typedef TNumber Number;
104  typedef TInteger Integer;
105  typedef long double LongDoubleType;
106 
107 
113 
118 
123 
128 
133 
140 
141  protected:
147  Integer myA;
148 
154  Integer myB;
155 
161  Integer myMu;
162 
167  Number myPrecision;
168 
169  public:
184  DSLSubsegment(Number a, Number b, Number mu, Point &A, Point &B, std::string type);
185 
198  DSLSubsegment(Number alpha, Number beta, Point &A, Point &B, Number precision = 1e-10);
199 
200 
201  protected:
211  void DSLSubsegmentFareyFan(Number a, Number b, Number mu, Point &A, Point &B);
212 
222  void DSLSubsegmentLocalCH(Number a, Number b, Number mu, Point &A, Point &B);
223 
228  DSLSubsegment();
229 
230 
234  class RayC
235  {
236  public :
237 
242  Integer x;
243 
247  Integer y;
248 
253  RayC();
254 
260  RayC(const Integer x0, const Integer y0);
261 
270  RayC(const Integer p, const Integer q, const Integer r, const Integer slope);
271 
272  ~RayC();
273 
274  };
275 
279  typedef enum Position
280  {
284  } Position;
285 
286 
297  Integer intersectionVertical(Point &P, Vector &v, Integer n);
298 
299 
311  Integer intersection(Point &P, Vector &v, Vector &aL, Integer r);
312 
323  Integer intersection(Point &P, Vector &v, Number s);
324 
335  void update(Vector &u, Point &A, Vector &l, Integer r, Vector *v);
336 
347  void update(Vector &u, Point &A, Number s, Vector *v);
348 
365  void lowerConvexHull(Vector &l, Integer mu, Point &A, Point &B,
366  Point *prevInfL, Point *infL, Point *infR, Point *prevInfR);
367 
380  void convexHullApprox(Vector &l, Integer r, Integer n, Point *inf, Point *sup);
381 
391  void convexHullApprox(Number s, Integer n, Point *inf, Point *sup);
392 
409  void convexHullApproxTwoPoints(Vector &l, Integer r, Integer n,
410  Point *inf, Point *sup, Point *prevInf, Point *prevSup, bool inv);
411 
412 
424  void convexHullHarPeled(Vector &l, Integer n, Point *inf, Point *sup);
425 
426 
434  Point nextTermInFareySeriesEuclid(Integer fp, Integer fq, Integer n);
435 
436 
449  RayC rayOfHighestSlope(Integer p, Integer q, Integer r, Integer smallestSlope, Integer n);
450 
465  Integer slope(Integer p, Integer q, Integer r, Number a, Number b, Number mu);
466 
480  Integer slope(Integer p, Integer q, Integer r, Number alpha, Number beta);
481 
482 
492  Position positionWrtRay(RayC &r, Number a, Number b, Number mu);
493 
494 
503  Position positionWrtRay(RayC &r, Number alpha, Number beta);
504 
519  RayC smartRayOfSmallestSlope(Integer fp, Integer fq, Integer gp, Integer gq, Integer r);
520 
521 
552  Integer smartFirstDichotomy(Integer fp, Integer fq, Integer gp, Integer gq,
553  Number a, Number b, Number mu, Integer n, bool *flagRayFound);
554 
583  Integer smartFirstDichotomy(Integer fp, Integer fq, Integer gp, Integer gq,
584  Number alpha, Number beta, Integer n, bool *flagRayFound);
585 
586 
587 
606  RayC localizeRay(Integer fp, Integer fq, Integer gp, Integer gq,
607  Integer r, Number a, Number b, Number mu, Integer n);
608 
609 
627  RayC localizeRay(Integer fp, Integer fq, Integer gp, Integer gq,
628  Integer r, Number alpha, Number beta, Integer n);
629 
630 
641  RayC raySup(Integer fp, Integer fq, RayC r);
642 
643 
672  void findSolutionWithoutFractions(Integer fp, Integer fq, Integer gp, Integer gq,
673  RayC r, Integer n, Integer *resAlphaP,
674  Integer *resAlphaQ, Integer *resBetaP, bool found); // resBetaQ = resAlphaQ
675 
696  void shortFindSolution(Integer fp, Integer fq, Integer gp, Integer gq,
697  RayC r, Integer n, Integer *resAlphaP, Integer *resAlphaQ,
698  Integer *resBetaP); // resBetaQ = resAlphaQ
699 
700 
701  public :
702  Integer computeMinRemainder(Number a, Number b, Number mu, Point A, Point B);
703  Integer computeMaxRemainder(Number a, Number b, Number mu, Point A, Point B);
704 
705 
706  // ------------------------- Accessors ------------------------------
707 
708  public:
709 
713  Integer getA() const;
717  Integer getB() const;
721  Integer getMu() const;
722 
723 
724  };
725 
726 
727 }// namespace DGtal
728 
729 
730 
731  //Includes inline functions.
732 #include "DSLSubsegment.ih"
733 
734 
735 // //
737 
738 #endif // !defined DSLSubsegment_h
739 
740 #undef DSLSubsegment_RECURSES
741 #endif // else defined(DSLSubsegment_RECURSES)
void DSLSubsegmentFareyFan(Number a, Number b, Number mu, Point &A, Point &B)
void shortFindSolution(Integer fp, Integer fq, Integer gp, Integer gq, RayC r, Integer n, Integer *resAlphaP, Integer *resAlphaQ, Integer *resBetaP)
Point nextTermInFareySeriesEuclid(Integer fp, Integer fq, Integer n)
void convexHullHarPeled(Vector &l, Integer n, Point *inf, Point *sup)
bool isValid() const
void convexHullApproxTwoPoints(Vector &l, Integer r, Integer n, Point *inf, Point *sup, Point *prevInf, Point *prevSup, bool inv)
void convexHullApprox(Vector &l, Integer r, Integer n, Point *inf, Point *sup)
Integer smartFirstDichotomy(Integer fp, Integer fq, Integer gp, Integer gq, Number a, Number b, Number mu, Integer n, bool *flagRayFound)
Integer getB() const
Integer getA() const
DGtal::PointVector< 2, Number > VectorF
Position positionWrtRay(RayC &r, Number a, Number b, Number mu)
Aim: Given a Digital Straight line and two endpoints A and B on this line, compute the minimal charac...
Definition: DSLSubsegment.h:75
Integer slope(Integer p, Integer q, Integer r, Number a, Number b, Number mu)
void lowerConvexHull(Vector &l, Integer mu, Point &A, Point &B, Point *prevInfL, Point *infL, Point *infR, Point *prevInfR)
Integer intersectionVertical(Point &P, Vector &v, Integer n)
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:87
Integer computeMaxRemainder(Number a, Number b, Number mu, Point A, Point B)
Integer computeMinRemainder(Number a, Number b, Number mu, Point A, Point B)
Aim: Defines the mathematical concept equivalent to a unitary commutative ring with a division operat...
void findSolutionWithoutFractions(Integer fp, Integer fq, Integer gp, Integer gq, RayC r, Integer n, Integer *resAlphaP, Integer *resAlphaQ, Integer *resBetaP, bool found)
Integer intersection(Point &P, Vector &v, Vector &aL, Integer r)
RayC raySup(Integer fp, Integer fq, RayC r)
RayC rayOfHighestSlope(Integer p, Integer q, Integer r, Integer smallestSlope, Integer n)
Integer getMu() const
DGtal is the top-level namespace which contains all DGtal functions and types.
void DSLSubsegmentLocalCH(Number a, Number b, Number mu, Point &A, Point &B)
DGtal::PointVector< 2, Integer > Ray
RayC smartRayOfSmallestSlope(Integer fp, Integer fq, Integer gp, Integer gq, Integer r)
void selfDisplay(std::ostream &out) const
void update(Vector &u, Point &A, Vector &l, Integer r, Vector *v)
DGtal::PointVector< 2, Integer > Point
DGtal::PointVector< 2, Number > PointF
RayC localizeRay(Integer fp, Integer fq, Integer gp, Integer gq, Integer r, Number a, Number b, Number mu, Integer n)
long double LongDoubleType
BOOST_CONCEPT_ASSERT((concepts::CEuclideanRing< Number >))
DGtal::PointVector< 2, Integer > Vector