SetOperations.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
00081 class Edge
00082 {
00083 public:
00084 MeshPoint pt1, pt2;
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];
00119 MeshGeomFacet facets[2][2];
00120 unsigned long facet[2];
00121
00122 EdgeInfo ()
00123 {
00124 fcounter[0] = 0;
00125 fcounter[1] = 0;
00126 }
00127 };
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
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;
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 };
00188
00189 #endif // MESH_SETOPERATIONS_H