Triangulation.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #ifndef MESH_TRIANGULATION_H
00025 #define MESH_TRIANGULATION_H
00026 
00027 #include "Elements.h"
00028 #include <Base/Vector3D.h>
00029 
00030 namespace MeshCore
00031 {
00032 class MeshKernel;
00033 
00034 class MeshExport AbstractPolygonTriangulator
00035 {
00036 public:
00037     AbstractPolygonTriangulator();
00038     virtual ~AbstractPolygonTriangulator();
00039 
00041     void SetPolygon(const std::vector<Base::Vector3f>& raclPoints);
00045     std::vector<Base::Vector3f> GetPolygon() const;
00052     std::vector<Base::Vector3f> AddedPoints() const;
00056     Base::Matrix4D GetTransformToFitPlane() const;
00060     std::vector<Base::Vector3f> ProjectToFitPlane();
00064     bool TriangulatePolygon();
00068     virtual void ProjectOntoSurface(const std::vector<Base::Vector3f>&);
00070     const std::vector<MeshGeomFacet>& GetTriangles() const { return _triangles;}
00072     const std::vector<MeshFacet>& GetFacets() const { return _facets;}
00074     float GetLength() const;
00079     std::vector<unsigned long> GetInfo() const;
00080     void Discard();
00081 
00082 protected:
00086     virtual bool Triangulate() = 0;
00087     void Done();
00088 
00089 protected:
00090     bool                        _discard;
00091     Base::Matrix4D              _inverse;
00092     std::vector<Base::Vector3f> _points;
00093     std::vector<Base::Vector3f> _newpoints;
00094     std::vector<MeshGeomFacet>  _triangles;
00095     std::vector<MeshFacet>      _facets;
00096     std::vector<unsigned long>  _info;
00097 };
00098 
00103 class MeshExport EarClippingTriangulator : public AbstractPolygonTriangulator
00104 {
00105 public:
00106     EarClippingTriangulator();
00107     ~EarClippingTriangulator();
00108 
00109 protected:
00110     bool Triangulate();
00111 
00112 private:
00122     class Triangulate
00123     {
00124     public:
00125         // triangulate a contour/polygon, places results in STL vector
00126         // as series of triangles.indicating the points
00127         static bool Process(const std::vector<Base::Vector3f> &contour,
00128             std::vector<unsigned long> &result);
00129 
00130         // compute area of a contour/polygon
00131         static float Area(const std::vector<Base::Vector3f> &contour);
00132 
00133         // decide if point Px/Py is inside triangle defined by
00134         // (Ax,Ay) (Bx,By) (Cx,Cy)
00135         static bool InsideTriangle(float Ax, float Ay, float Bx, float By,
00136             float Cx, float Cy, float Px, float Py);
00137 
00138         static bool _invert;
00139     private:
00140         static bool Snip(const std::vector<Base::Vector3f> &contour,
00141             int u,int v,int w,int n,int *V);
00142     };
00143 };
00144 
00145 class MeshExport QuasiDelaunayTriangulator : public EarClippingTriangulator
00146 {
00147 public:
00148     QuasiDelaunayTriangulator();
00149     ~QuasiDelaunayTriangulator();
00150 
00151 protected:
00152     bool Triangulate();
00153 };
00154 
00155 class MeshExport DelaunayTriangulator : public AbstractPolygonTriangulator
00156 {
00157 public:
00158     DelaunayTriangulator();
00159     ~DelaunayTriangulator();
00160 
00161 protected:
00162     bool Triangulate();
00163 };
00164 
00165 class MeshExport FlatTriangulator : public AbstractPolygonTriangulator
00166 {
00167 public:
00168     FlatTriangulator();
00169     ~FlatTriangulator();
00170 
00171     void ProjectOntoSurface(const std::vector<Base::Vector3f>&);
00172 
00173 protected:
00174     bool Triangulate();
00175 };
00176 
00177 class MeshExport ConstraintDelaunayTriangulator : public AbstractPolygonTriangulator
00178 {
00179 public:
00180     ConstraintDelaunayTriangulator(float area);
00181     ~ConstraintDelaunayTriangulator();
00182 
00183 protected:
00184     bool Triangulate();
00185 
00186 private:
00187     float fMaxArea;
00188 };
00189 
00190 class MeshExport Triangulator : public AbstractPolygonTriangulator
00191 {
00192 public:
00193     Triangulator(const MeshKernel&);
00194     ~Triangulator();
00195 
00196 protected:
00197     bool Triangulate();
00198 
00199     const MeshKernel& _kernel;
00200 };
00201 
00202 } // namespace MeshCore
00203 
00204 
00205 #endif  // MESH_TRIANGULATION_H 

Generated on Wed Nov 23 19:00:51 2011 for FreeCAD by  doxygen 1.6.1