00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 #ifndef WM4QUADRICSURFACE_H
00018 #define WM4QUADRICSURFACE_H
00019 
00020 #include "Wm4FoundationLIB.h"
00021 #include "Wm4ImplicitSurface.h"
00022 #include "Wm4RVector3.h"
00023 
00024 namespace Wm4
00025 {
00026 
00027 template <class Real>
00028 class WM4_FOUNDATION_ITEM QuadricSurface : public ImplicitSurface<Real>
00029 {
00030 public:
00031     
00032     
00033     
00034     
00035     
00036     
00037     
00038     
00039     
00040     
00041     
00042 
00043     QuadricSurface ();  
00044     QuadricSurface (const Real afCoeff[10]);
00045 
00046     
00047     const Real* GetCoefficients () const;
00048     const Matrix3<Real>& GetA () const;
00049     const Vector3<Real>& GetB () const;
00050     Real GetC () const;
00051 
00052     
00053     virtual Real F (const Vector3<Real>& rkP) const;
00054 
00055     
00056     virtual Real FX (const Vector3<Real>& rkP) const;
00057     virtual Real FY (const Vector3<Real>& rkP) const;
00058     virtual Real FZ (const Vector3<Real>& rkP) const;
00059 
00060     
00061     virtual Real FXX (const Vector3<Real>& rkP) const;
00062     virtual Real FXY (const Vector3<Real>& rkP) const;
00063     virtual Real FXZ (const Vector3<Real>& rkP) const;
00064     virtual Real FYY (const Vector3<Real>& rkP) const;
00065     virtual Real FYZ (const Vector3<Real>& rkP) const;
00066     virtual Real FZZ (const Vector3<Real>& rkP) const;
00067 
00068     enum  
00069     {
00070         QT_NONE,
00071         QT_POINT,
00072         QT_LINE,
00073         QT_PLANE,
00074         QT_TWO_PLANES,
00075         QT_PARABOLIC_CYLINDER,
00076         QT_ELLIPTIC_CYLINDER,
00077         QT_HYPERBOLIC_CYLINDER,
00078         QT_ELLIPTIC_PARABOLOID,
00079         QT_HYPERBOLIC_PARABOLOID,
00080         QT_ELLIPTIC_CONE,
00081         QT_HYPERBOLOID_ONE_SHEET,
00082         QT_HYPERBOLOID_TWO_SHEETS,
00083         QT_ELLIPSOID
00084     };
00085 
00086     
00087     int GetType () const;
00088 
00089 protected:
00090     Real m_afCoeff[10];
00091     Matrix3<Real> m_kA;
00092     Vector3<Real> m_kB;
00093     Real m_fC;
00094 
00095 private:
00096     typedef TRational<4*sizeof(Real)> Rational;
00097     typedef RVector3<4*sizeof(Real)> QSVector;
00098 
00099     class RReps
00100     {
00101     public:
00102         RReps (const Real afCoeff[10])
00103         {
00104             Rational kOneHalf(1,2);
00105 
00106             c = Rational(afCoeff[0]);
00107             b0 = Rational(afCoeff[1]);
00108             b1 = Rational(afCoeff[2]);
00109             b2 = Rational(afCoeff[3]);
00110             a00 = Rational(afCoeff[4]);
00111             a01 = kOneHalf*Rational(afCoeff[5]);
00112             a02 = kOneHalf*Rational(afCoeff[6]);
00113             a11 = Rational(afCoeff[7]);
00114             a12 = kOneHalf*Rational(afCoeff[8]);
00115             a22 = Rational(afCoeff[9]);
00116 
00117             Sub00 = a11*a22 - a12*a12;
00118             Sub01 = a01*a22 - a12*a02;
00119             Sub02 = a01*a12 - a02*a11;
00120             Sub11 = a00*a22 - a02*a02;
00121             Sub12 = a00*a12 - a02*a01;
00122             Sub22 = a00*a11 - a01*a01;
00123             c0 = a00*Sub00 - a01*Sub01 + a02*Sub02;
00124             c1 = Sub00 + Sub11 + Sub22;
00125             c2 = a00 + a11 + a22;
00126         }
00127 
00128         
00129         Rational a00, a01, a02, a11, a12, a22, b0, b1, b2, c;
00130 
00131         
00132         Rational Sub00, Sub01, Sub02, Sub11, Sub12, Sub22;
00133 
00134         
00135         Rational c0, c1, c2;
00136 
00137         
00138         Rational c3, c4, c5;
00139     };
00140 
00141     static void GetRootSigns (RReps& rkReps, int& riPositiveRoots,
00142         int& riNegativeRoots, int& riZeroRoots);
00143     static int GetSignChanges (int iQuantity, const Rational* akValue);
00144     static int ClassifyZeroRoots0 (const RReps& rkReps, int iPositiveRoots);
00145     static int ClassifyZeroRoots1 (const RReps& rkReps, int iPositiveRoots);
00146     static int ClassifyZeroRoots1 (const RReps& rkReps, int iPositiveRoots,
00147         const QSVector& rkP0, const QSVector& rkP1, const QSVector& rkP2);
00148     static int ClassifyZeroRoots2 (const RReps& rkReps, int iPositiveRoots);
00149     static int ClassifyZeroRoots2 (const RReps& rkReps, int iPositiveRoots,
00150         const QSVector& rkP0, const QSVector& rkP1, const QSVector& rkP2);
00151     static int ClassifyZeroRoots3 (const RReps& rkReps);
00152 };
00153 
00154 typedef QuadricSurface<float> QuadricSurfacef;
00155 typedef QuadricSurface<double> QuadricSurfaced;
00156 
00157 }
00158 
00159 #endif