TopoAlgorithm.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2005 Imetric 3D GmbH                                    *
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_TOPOALGORITHM_H
00025 #define MESH_TOPOALGORITHM_H
00026 
00027 #include <map>
00028 #include <vector>
00029 
00030 #include "Definitions.h"
00031 #include "Iterator.h"
00032 #include "MeshKernel.h"
00033 #include "Elements.h"
00034 #include "Visitor.h"
00035 #include "Algorithm.h"
00036 
00037 #include <Base/Vector3D.h>
00038 #include <Base/Sequencer.h>
00039 
00040 namespace MeshCore {
00041 class AbstractPolygonTriangulator;
00042 
00049 class MeshExport MeshTopoAlgorithm
00050 {
00051 public:
00052     // construction/destruction
00053     MeshTopoAlgorithm (MeshKernel &rclM);
00054     virtual ~MeshTopoAlgorithm (void);
00055 
00056 public:
00064     bool InsertVertex(unsigned long ulFacetPos, const Base::Vector3f&  rclPoint);
00074     bool InsertVertexAndSwapEdge(unsigned long ulFacetPos, const Base::Vector3f&  rclPoint,
00075                                  float fMaxAngle);
00084     void SwapEdge(unsigned long ulFacetPos, unsigned long ulNeighbour);
00092     bool SplitEdge(unsigned long ulFacetPos, unsigned long ulNeighbour, 
00093                    const Base::Vector3f& rP);
00100     void SplitOpenEdge(unsigned long ulFacetPos, unsigned short uSide,
00101                        const Base::Vector3f& rP);
00110     void SplitFacet(unsigned long ulFacetPos, const Base::Vector3f& rP1,
00111                     const Base::Vector3f& rP2);
00134     bool CollapseEdge(unsigned long ulFacetPos, unsigned long ulNeighbour);
00152     bool CollapseFacet(unsigned long ulFacetPos);
00154 
00165     void OptimizeTopology(float fMaxAngle);
00166     void OptimizeTopology();
00172     void DelaunayFlip(float fMaxAngle);
00177     int DelaunayFlip();
00184     void AdjustEdgesToCurvatureDirection();
00186 
00195     bool SnapVertex(unsigned long ulFacetPos, const Base::Vector3f& rP);
00202     bool IsSwapEdgeLegal(unsigned long ulFacetPos, unsigned long ulNeighbour) const;
00209     bool ShouldSwapEdge(unsigned long ulFacetPos, unsigned long ulNeighbour,
00210                         float fMaxAngle) const;
00212     float SwapEdgeBenefit(unsigned long f, int e) const;
00216     void Cleanup();
00221     void RemoveDegeneratedFacet(unsigned long index);
00226     void RemoveCorruptedFacet(unsigned long index);
00232     void FillupHoles(unsigned long length, int level,
00233         AbstractPolygonTriangulator&,
00234         std::list<std::vector<unsigned long> >& aFailed);
00239     void FillupHoles(int level, AbstractPolygonTriangulator&,
00240         const std::list<std::vector<unsigned long> >& aBorders,
00241         std::list<std::vector<unsigned long> >& aFailed);
00245     void FindHoles(unsigned long length,
00246         std::list<std::vector<unsigned long> >& aBorders) const;
00251     void FindComponents(unsigned long count, std::vector<unsigned long>& aInds);
00255     void RemoveComponents(unsigned long count);
00259     void HarmonizeNormals (void);
00263     void FlipNormals (void);
00267     void BeginCache();
00268     void EndCache();
00269 
00270 private:
00274     void SplitNeighbourFacet(unsigned long ulFacetPos, unsigned short uSide,
00275                              const Base::Vector3f rPoint);
00280     std::vector<unsigned long> GetFacetsToPoint(unsigned long uFacetPos,
00281                                                 unsigned long uPointPos) const;
00283     unsigned long GetOrAddIndex (const MeshPoint &rclPoint);
00284 
00285 private:
00286     MeshKernel& _rclMesh;
00287     bool _needsCleanup;
00288 
00289     struct Vertex_Less  : public std::binary_function<const Base::Vector3f&,
00290                                                       const Base::Vector3f&, bool>
00291     {
00292         bool operator()(const Base::Vector3f& x, const Base::Vector3f& y) const;
00293     };
00294 
00295     // cache
00296     typedef std::map<Base::Vector3f,unsigned long,Vertex_Less> tCache;
00297     tCache* _cache;
00298 };
00299 
00306 class MeshExport MeshComponents
00307 {
00308 public:
00309     enum TMode {OverEdge, OverPoint};
00310 
00311     MeshComponents( const MeshKernel& rclMesh );
00312     ~MeshComponents();
00313 
00319     void SearchForComponents(TMode tMode, std::vector<std::vector<unsigned long> >& aclT) const;
00320 
00325     void SearchForComponents(TMode tMode, const std::vector<unsigned long>& aSegment,
00326                              std::vector<std::vector<unsigned long> >& aclT) const;
00327 
00328 protected:
00329     // for sorting of elements
00330     struct CNofFacetsCompare : public std::binary_function<const std::vector<unsigned long>&, 
00331                                                            const std::vector<unsigned long>&, bool>
00332     {
00333         bool operator () (const std::vector<unsigned long> &rclC1, 
00334                           const std::vector<unsigned long> &rclC2)
00335         {
00336             return rclC1.size() > rclC2.size();
00337         }
00338     };
00339 protected:
00340     const MeshKernel& _rclMesh;
00341 };
00342 
00343 } // namespace MeshCore
00344 
00345 #endif // MESH_TOPOALGORITHM_H

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