Biarc.h

00001 #ifndef _BIARC_H_
00002 #define _BIARC_H_
00003 
00004 #include "Vector3.h"
00005 #include "Matrix3.h"
00006 
00007 // FIXME : is there a nice way to check for inflection points
00008 // and straight line segments. So far dot product between
00009 // start and end tangent is checked not to be close to one
00010 // up to the StraightSegTol
00011 #define StraightSegTol   1e-7
00012 
00013 template<class Vector>
00014 class Curve;
00015 
00016 template<class Vector>
00017 class Biarc {
00018 
00019   int _BIARC_;
00020 
00021   Vector _Point, _Tangent;
00022   Vector _MidPoint, _MidTangent;
00023   Vector _BezierPoint0, _BezierPoint1;
00024 
00025   // each Biarc has global knowledge of where it is in a curve!
00026   int _BiarcInCurve;
00027   Curve< Vector > *_Curve;
00028 
00029   // Biarc<Vector> *_Next,*_Previous;
00030 
00031   float _Radius0, _Radius1;
00032   float _ArcLength0, _ArcLength1;
00033   float _Length;
00034 
00035   float _radius(const Vector &q0, const Vector &q1, const Vector &t0) const;
00036   float _radius0() const;
00037   float _radius1() const;
00038   float _angle(const Vector &q0, const Vector &q1, const Vector &t0) const;
00039   float _angle0() const;
00040   float _angle1() const;
00041 
00042   float _arclength0() const;
00043   float _arclength1() const;
00044   float _biarclength() const;
00045 
00046   Vector a(const Vector &b0,const Vector &b1,const Vector &b2,float tau) const;
00047   void cache();
00048 
00049  public:
00050 
00051   Biarc() ;
00052   Biarc(const Vector &p,const Vector &t);
00053   Biarc(const Biarc<Vector>& b);
00054   ~Biarc();
00055 
00056   const Vector& getPoint() const;
00057   const Vector& getTangent() const;
00058   const Vector& getMidPoint() const;
00059   const Vector& getMidTangent() const;
00060   void setPoint(const Vector &p);
00061   // void setPoint(float &p0,float &p1,float &p2);
00062 
00063   // These functions should update cached values (i.e. radius,angles...)
00064   void setMidPoint(const Vector &p);
00065   // void setMidPoint(float &p0,float &p1,float &p2);
00066   void setMidTangent(const Vector &p);
00067   // void setMidTangent(float &p0,float &p1,float &p2);
00068 
00069   void setTangentUnnormalized(const Vector &t);
00070   void setTangent(const Vector &t);
00071   // void setTangent(float &t0,float &t1,float &t2);
00072   void get(Vector& p, Vector& t) const;
00073   void set(const Vector& p, const Vector& t);
00074   void clear();
00075   
00076   void reverse();
00077   int isProper() const;
00078   int isBiarc() const;
00079   void setBiarc();
00080 
00081   // FIXME : wrap around if closed and we're at the end
00082   //         using global knowledge about position in curve
00083   void make(float Gamma);
00084   
00085   float arclength0() const;
00086   float arclength1() const;
00087   float biarclength() const;
00088 
00089   float radius0() const;
00090   float radius1() const;
00091 
00092   int id() const;
00093   // FIXME : these functions should not be available to the user.
00094   //         friends?
00095   void setId(const int i);
00096   void setCurve(Curve<Vector>* c);
00097   const Curve<Vector>* getCurve();
00098   void setIdAndCurve(const int i, Curve<Vector>* c);
00099   Vector pointOnArc0(float s) const;
00100   Vector pointOnArc1(float s) const;
00101   Vector pointOnBiarc(float arclength) const;
00102   Vector tangentOnBiarc(float arclength) const;
00103 
00104   // replace & by * and set & explicitly when call
00105   void getBezierArc0(Vector& b0, Vector& b1, Vector& b2) const;
00106   void getBezierArc1(Vector& b0,Vector& b1,Vector& b2) const;
00107   void getBezier(Vector& b0_0, Vector& b1_0, Vector& b2_0,
00108                  Vector& b0_1, Vector& b1_1, Vector& b2_1) const;
00109   Vector a0(float tau) const;
00110   Vector a1(float tau) const;
00111 
00112   const Biarc<Vector>& getNext() const;
00113   const Biarc<Vector>& getPrevious() const;
00114   void setNext(const Biarc<Vector> &b);
00115   void setPrevious(const Biarc<Vector> &b);
00116   void setNextNULL();
00117   void setPreviousNULL();
00118 
00119   Biarc<Vector> operator*(const float s) const;
00120   /*
00121   friend Biarc operator *(Biarc & b, float d);
00122   friend Biarc operator *(float d, Biarc & b);
00123   friend Biarc operator /(Biarc & b, float d);
00124   */
00125   Biarc<Vector> operator+(const Vector &v) const;
00126   Biarc<Vector> operator-(const Vector &v) const;
00127   Biarc<Vector> &operator=(const Biarc<Vector> &b);
00128   Biarc<Vector> &operator+=(const Vector &v);
00129   Biarc<Vector> &operator-=(const Vector &v);
00130   Biarc<Vector> &operator/=(const float d);
00131   Biarc<Vector> &operator*=(const float d);
00132 
00133   void print(ostream &out) const ;
00134   int operator==(const Biarc<Vector> &b) const;
00135   int operator!=(const Biarc<Vector> &b) const;
00136 
00137 //  friend ostream& operator << (ostream &out, const Biarc<Vector>& b);
00138 
00139 };
00140 
00141 template<class Vector>
00142 inline ostream& operator << (ostream &out, const Biarc<Vector>& b) {
00143   b.print(out);
00144   return out;
00145 }
00146 
00147 // Templates need all code in the same file
00148 // that's why we include here the source file!!!
00149 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00150 #include "../lib/Biarc.cpp"
00151 #endif
00152 
00153 #endif // _BIARC_H_

Generated on Mon Feb 8 17:22:35 2010 for libbiarc by  doxygen 1.5.6