$search
00001 /**********************************************************************/ 00002 /************ HEADER FILE FOR TRIANGULATE.H ***************************/ 00003 /**********************************************************************/ 00004 00005 00006 #ifndef TRIANGULATE_H 00007 00008 #define TRIANGULATE_H 00009 00010 /*****************************************************************/ 00023 /*****************************************************************/ 00024 00025 00026 #include <vector> // Include STL vector class. 00027 00028 namespace bmtk { 00029 00030 class Vector2d 00031 { 00032 public: 00033 Vector2d(float x,float y) 00034 { 00035 Set(x,y); 00036 }; 00037 00038 float GetX(void) const { return mX; }; 00039 00040 float GetY(void) const { return mY; }; 00041 00042 void Set(float x,float y) 00043 { 00044 mX = x; 00045 mY = y; 00046 }; 00047 private: 00048 float mX; 00049 float mY; 00050 }; 00051 00052 // Typedef an STL vector of vertices which are used to represent 00053 // a polygon/contour and a series of triangles. 00054 typedef std::vector< Vector2d > Vector2dVector; 00055 typedef std::vector<int> VertexList; 00056 00057 00058 class Triangulate 00059 { 00060 public: 00061 00062 // triangulate a contour/polygon, places results in STL vector 00063 // as series of triangles. 00064 static bool Process(const Vector2dVector &contour, 00065 VertexList &result); 00066 00067 // compute area of a contour/polygon 00068 static float Area(const Vector2dVector &contour); 00069 00070 // decide if point Px/Py is inside triangle defined by 00071 // (Ax,Ay) (Bx,By) (Cx,Cy) 00072 static bool InsideTriangle(float Ax, float Ay, 00073 float Bx, float By, 00074 float Cx, float Cy, 00075 float Px, float Py); 00076 00077 00078 private: 00079 static bool Snip(const Vector2dVector &contour, 00080 int u,int v,int w,int n,int *V); 00081 }; 00082 00083 } // namespace bmtk 00084 00085 #endif