Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Triangulate.h
1 //
2 // Triangulate.h
3 //
4 // Two different methods for triangulating polygons.
5 //
6 // Copyright (c) 2006-2008 Virtual Terrain Project
7 // Free for all uses, see license.txt for details.
8 //
9 
10 // ** THIS IS A CODE SNIPPET WHICH WILL EFFICIENTLY TRIANGULATE ANY
11 // ** POLYGON/CONTOUR (without holes) AS A STATIC CLASS.
12 // ** SUBMITTED BY JOHN W. RATCLIFF (jratcliff@verant.com) July 22, 2000
13 
14 #ifndef TRIANGULATE_H
15 #define TRIANGULATE_H
16 
17 /* This code snippet was submitted to FlipCode.com by
18  * John W. Ratcliff (jratcliff@verant.com) on July 22, 2000
19  * I did not write the original code/algorithm for this
20  * this triangulator, in fact, I can't even remember where I
21  * found it in the first place. However, I did rework it into
22  * the following black-box static class so you can make easy
23  * use of it in your own code.
24  */
25 
26 #include "MathTypes.h"
27 
35 {
36 public:
39  static bool Process(const FLine2 &contour, FLine2 &result);
40  static bool Process(const FLine3 &contour, FLine3 &result);
41  static bool Process(const FLine3 &contour, vtArray<int> &result);
42 
44  static float Area(const FLine2 &contour);
45  static float Area(const FLine3 &contour);
46 
48  static bool InsideTriangle(float Ax, float Ay,
49  float Bx, float By,
50  float Cx, float Cy,
51  float Px, float Py);
52 private:
53  static bool Snip(const FLine2 &contour,int u,int v,int w,int n,int *V);
54  static bool Snip(const FLine3 &contour,int u,int v,int w,int n,int *V);
55 };
56 
65 {
66 public:
69  static bool Process(const DLine2 &contour, DLine2 &result);
70 
72  static double Area(const DLine2 &contour);
73 
75  static bool InsideTriangle(double Ax, double Ay,
76  double Bx, double By,
77  double Cx, double Cy,
78  double Px, double Py);
79 private:
80  static bool Snip(const DLine2 &contour,int u,int v,int w,int n,int *V);
81 };
82 
87 void CallTriangle(const DLine2 &contour, DLine2 &result);
88 void CallTriangle(const DPolygon2 &contour, DLine2 &result);
89 
93 void CallPoly2Tri(const DLine2 &contour, DLine2 &result);
94 void CallPoly2Tri(const DPolygon2 &contour, DLine2 &result);
95 
96 #endif // TRIANGULATE_H
97