SetOperations.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Berthold Grupp          2005                            *
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_SETOPERATIONS_H
00025 #define MESH_SETOPERATIONS_H
00026 
00027 #include <list>
00028 #include <map>
00029 #include <set>
00030 
00031 #include "MeshKernel.h"
00032 #include "Elements.h"
00033 #include "Iterator.h"
00034 #include "Visitor.h"
00035 
00036 #include <Base/Builder3D.h>
00037 
00038 // forward declarations
00039 
00040 namespace MeshCore
00041 {
00042 
00043 class MeshGeomFacet;
00044 class MeshGeomEdge;
00045 class MeshBuilder;
00046 class MeshKernel;
00047 class MeshFacetGrid;
00048 class MeshFacetArray;
00049 class MeshFacetIterator;
00050 
00054 class MeshExport SetOperations
00055 {
00056 public:
00057   enum OperationType { Union, Intersect, Difference, Inner, Outer };
00058 
00060   SetOperations (const MeshKernel &cutMesh1, const MeshKernel &cutMesh2, MeshKernel &result, OperationType opType, float minDistanceToPoint = 1e-5f);
00062   virtual ~SetOperations (void);
00063 
00064 public:
00065 
00069   void Do ();
00070 
00071 protected:
00072   const MeshKernel   &_cutMesh0;             
00073   const MeshKernel   &_cutMesh1;             
00074   MeshKernel         &_resultMesh;           
00075   OperationType       _operationType;        
00076   float               _minDistanceToPoint;   
00077   float               _saveMinMeshDistance;
00078 
00079 private:
00080   // Helper class cutting edge to his two attached facets
00081   class Edge
00082   {
00083     public:
00084       MeshPoint         pt1, pt2;              // edge
00085 
00086       Edge ()
00087       {
00088       }
00089 
00090       Edge (MeshPoint p1, MeshPoint p2)
00091       {
00092         if (p1 < p2)
00093         {
00094           pt1 = p1;
00095           pt2 = p2;
00096         }
00097         else
00098         {
00099           pt2 = p1;
00100           pt1 = p2;
00101         }
00102       }
00103 
00104       bool operator == (const Edge &edge) const
00105       {
00106         return (pt1 == edge.pt1) && (pt2 == edge.pt2);
00107       }
00108 
00109       bool operator < (const Edge &edge) const
00110       {
00111         return (pt1 == edge.pt1) ? (pt2 < edge.pt2) : (pt1 < edge.pt1);
00112       }
00113   };
00114 
00115   class EdgeInfo
00116   {
00117     public:
00118       int               fcounter[2];           // counter of facets attacted to the edge
00119       MeshGeomFacet     facets[2][2];          // Geom-Facets attached to the edge
00120       unsigned long     facet[2];              // underlying Facet-Index
00121 
00122       EdgeInfo ()
00123       {
00124         fcounter[0] = 0;
00125         fcounter[1] = 0;
00126       }
00127   };
00128 
00129   //class CollectFacetVisitor : public MeshFacetVisitor
00130   //{
00131   //  public:
00132   //    std::vector<unsigned long> &_facets;
00133   //    MeshKernel                 &_mesh;
00134   //    std::map<Edge, EdgeInfo>   &_edges;
00135   //    int                         _side;
00136   //    float                       _mult;
00137   //    int                         _addFacets; // 0: add facets to the result 1: do not add facets to the result
00138   //    Base::Builder3D& _builder;
00139 
00140   //    CollectFacetVisitor (MeshKernel& mesh, std::vector<unsigned long>& facets, std::map<Edge, EdgeInfo>& edges, int side, float mult, Base::Builder3D& builder);
00141   //    bool Visit (MeshFacet &rclFacet, const MeshFacet &rclFrom, unsigned long ulFInd, unsigned long ulLevel);
00142   //    bool AllowVisit (MeshFacet& rclFacet, MeshFacet& rclFrom, unsigned long ulFInd, unsigned long ulLevel, unsigned short neighbourIndex);
00143   //};
00144 
00145   class CollectFacetVisitor : public MeshFacetVisitor
00146   {
00147     public:
00148       std::vector<unsigned long> &_facets;
00149       const MeshKernel           &_mesh;
00150       std::map<Edge, EdgeInfo>   &_edges;
00151       int                         _side;
00152       float                       _mult;
00153       int                         _addFacets; // 0: add facets to the result 1: do not add facets to the result
00154       Base::Builder3D& _builder;
00155 
00156       CollectFacetVisitor (const MeshKernel& mesh, std::vector<unsigned long>& facets, std::map<Edge, EdgeInfo>& edges, int side, float mult, Base::Builder3D& builder);
00157       bool Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, unsigned long ulFInd, unsigned long ulLevel);
00158       bool AllowVisit (const MeshFacet& rclFacet, const MeshFacet& rclFrom, unsigned long ulFInd, unsigned long ulLevel, unsigned short neighbourIndex);
00159   };
00160 
00162   std::set<MeshPoint>       _cutPoints;
00164   std::map<Edge, EdgeInfo>  _edges;
00166   std::map<unsigned long, std::list<std::set<MeshPoint>::iterator> > _facet2points[2];
00168   std::vector<MeshGeomFacet> _facetsOf[2];
00169 
00170   std::vector<MeshGeomFacet> _newMeshFacets[2];
00171 
00173   void Cut (std::set<unsigned long>& facetsNotCuttingEdge0, std::set<unsigned long>& facetsCuttingEdge1);
00175   void TriangulateMesh (const MeshKernel &cutMesh, int side);
00177   void CollectFacets (int side, float mult);
00179   void CloseGaps (MeshBuilder& meshBuilder);
00180 
00182   Base::Builder3D _builder;
00183 
00184 };
00185 
00186 
00187 }; // namespace MeshCore
00188 
00189 #endif  // MESH_SETOPERATIONS_H

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