00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "csutil/dirtyaccessarray.h"
00020 #include "csgeom/trimesh.h"
00021 #include "csgeom/vector3.h"
00022 #include "ivaria/reporter.h"
00023 #include "csgeom/plane3.h"
00024
00025 #ifndef __CS_GEOM_TRIANGULATE_3D_H_
00026 #define __CS_GEOM_TRIANGULATE_3D_H_
00027
00028 namespace CS
00029 {
00030 namespace Geometry
00031 {
00032 typedef csDirtyAccessArray< csVector3 > csContour3;
00033
00034 typedef csDirtyAccessArray< size_t > csVertexSet;
00035
00050 class CS_CRYSTALSPACE_EXPORT csEarClipper
00051 {
00052 private:
00053
00055 csContour3 clipPoly;
00056
00058 csDirtyAccessArray<size_t> originalIndices;
00059
00061 csDirtyAccessArray<bool> isVertexReflex;
00062
00064 csDirtyAccessArray<size_t> ears;
00065
00067 void ClassifyVertices();
00068
00070 bool IsConvex(int x);
00071
00072 public:
00073
00079 csEarClipper(csContour3 polygon);
00080 ~csEarClipper() {}
00081
00083 bool IsFinished();
00084
00086 csVertexSet ClipEar();
00087
00089 size_t GetOriginalIndex(size_t at) { return originalIndices[at]; }
00090
00091 };
00092
00100 class CS_CRYSTALSPACE_EXPORT Triangulate3D
00101 {
00102 public:
00103 Triangulate3D() {};
00104 ~Triangulate3D() {};
00105
00122 static bool Process(csContour3& polygon, csTriangleMesh& result);
00123
00124 private:
00125
00126 static csContour3 MapToPlanar(const csContour3& poly, csVector3& normal);
00127 static bool FindVertexGroups(csContour3& poly, csArray<bool>& isReflex, csArray<size_t>& ears);
00128 static bool IsConvex(const csContour3& polygon, const int index);
00129 static bool IsContained(const csVector3& testVertex, const csVector3& a, const csVector3& b, const csVector3& c);
00130 static bool IsSameSide(const csVector3& p1, const csVector3& p2, const csVector3& a, const csVector3& b);
00131
00132
00133 };
00134
00135 }
00136 }
00137
00138 #endif // __CS_GEOM_TRIANGULATE_3D_H_
00139
00140