CrystalSpace

Public API Reference

csgeom/triangulate3d.h
00001 /*
00002     Copyright (C) 2007-2008 by Scott Johnson
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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     }; // End class csEarClipper
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       //static bool Snip(csContour3& polygon, csArray<size_t>& ears, const size_t earPoint, csTriangleMesh& addTo);
00132 
00133     }; /* End class Triangulate3D */
00134 
00135   } // namespace Geometry
00136 } // namespace CS
00137 
00138 #endif // __CS_GEOM_TRIANGULATE_3D_H_
00139 
00140 

Generated for Crystal Space 2.0 by doxygen 1.7.6.1