Alphabetical Class Index  Class Hierarchy   File Members   Compound Members   File List  

GeomUtilities.h

00001 #pragma once
00002 
00003 // -- Code from Sketchup SDK sample --
00004 
00005 //This module defines geometric classes that are usefull in processing
00006 //the objects coming from Sketchup.
00007 
00008 
00009 //Utility Methods-------------------------------------
00010 const double DivideByZeroTol = 1.0e-10;
00011 const double DivideByZeroTolSq = DivideByZeroTol * DivideByZeroTol;
00012 
00013 const double EqualTol = 1.0e-3;
00014 const double EqualTolSq = EqualTol * EqualTol;
00015 
00016 inline bool AreEqual(double val1, double val2, double tol = EqualTol)
00017 {
00018     double diff = val1 - val2;
00019     return diff <= tol && diff >= -tol;
00020 }
00021 
00022 
00023 //Vector Class----------------------------------------
00024 class CVector3d
00025 {
00026 public:
00027 
00028     CVector3d(): m_x(0.0), m_y(0.0), m_z(0.0) {}
00029     CVector3d(double x, double y, double z): m_x(x), m_y(y), m_z(z) {}
00030     CVector3d(CComPtr<ISkpVector3d> vec);
00031     ~CVector3d() {}
00032 
00033     void SetDirection(double x, double y, double z){m_x=x; m_y=y; m_z=z;}
00034 
00035     double X() const {return m_x;}
00036     double Y() const {return m_y;}
00037     double Z() const {return m_z;}
00038 
00039     void SetX(double x) { m_x = x; }
00040     void SetY(double y) { m_y = y; }
00041     void SetZ(double z) { m_z = z; }
00042 
00043     CVector3d operator+(const CVector3d& vec) const;
00044     CVector3d operator-(const CVector3d& vec) const;
00045     void operator+=(const CVector3d& vec);
00046     void operator-=(const CVector3d& vec);
00047 
00048     CVector3d operator*(double scale) const;
00049     CVector3d operator/(double scale) const;
00050     void operator*=(double scale);
00051     void operator/=(double scale);
00052 
00053     bool operator==(const CVector3d& vec) const;
00054     bool operator!=(const CVector3d& vec) const;
00055 
00056 protected:
00057 
00058     double m_x;
00059     double m_y;
00060     double m_z;
00061 
00062 };
00063 
00064 
00065 //Point Class----------------------------------------
00066 class CPoint3d
00067 {
00068 public:
00069 
00070     CPoint3d(): m_x(0.0), m_y(0.0), m_z(0.0) {}
00071     CPoint3d(double x, double y, double z): m_x(x), m_y(y), m_z(z) {}
00072     CPoint3d(CComPtr<ISkpPoint3d> point);
00073     ~CPoint3d() {}
00074 
00075     void SetLocation(double x, double y, double z){m_x=x; m_y=y; m_z=z;}
00076 
00077     double X() const {return m_x;}
00078     double Y() const {return m_y;}
00079     double Z() const {return m_z;}
00080 
00081     void SetX(double x) { m_x = x; }
00082     void SetY(double y) { m_y = y; }
00083     void SetZ(double z) { m_z = z; }
00084 
00085     void operator+=(const CVector3d &vec);
00086     void operator-=(const CVector3d &vec);
00087 
00088     CPoint3d operator+(const CVector3d& vec) const;
00089     CPoint3d operator+(const CPoint3d& pt) const;
00090     CPoint3d operator-(const CVector3d& vec) const;
00091     CVector3d operator-(const CPoint3d& pt) const;
00092 
00093     CPoint3d operator* (double scale) const {return CPoint3d (m_x * scale, m_y * scale, m_z * scale);}
00094     void operator*= (double scale) {*this = *this * scale;}
00095     CPoint3d operator/ (double invScale) const {return *this * (1.0 / invScale);}
00096     void operator/= (double invScale) {*this = *this / invScale;}
00097 
00098 protected:
00099 
00100     double m_x;
00101     double m_y;
00102     double m_z;
00103 
00104 };
00105 
00106 
00107 //Transformation Class--------------------------------
00108 class CTransform
00109 {
00110 public:
00111 
00112     CTransform();
00113     CTransform(double m[16]);
00114     ~CTransform(void);
00115 
00116     void SetMatrix(double m[16]);
00117     void SetToIdenity();
00118 
00119     CPoint3d operator* (const CPoint3d& pt) const;
00120     CVector3d operator* (const CVector3d& vec) const;
00121     CTransform operator* (const CTransform& t) const;
00122 
00123 
00124 
00125 protected: // data
00126 
00127     double m_t[16];
00128 
00129 };
00130