1
/***************************************************************************
2
* Copyright (c) Berthold Grupp 2005 *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#ifndef MESH_SETOPERATIONS_H
25
#define MESH_SETOPERATIONS_H
31
#include "MeshKernel.h"
36
#include <Base/Builder3D.h>
38
// forward declarations
49
class MeshFacetIterator;
52
* The MeshAlgorithm class provides algorithms base on meshes.
54
class MeshExport SetOperations
57
enum OperationType { Union, Intersect, Difference, Inner, Outer };
60
SetOperations (const MeshKernel &cutMesh1, const MeshKernel &cutMesh2, MeshKernel &result, OperationType opType, float minDistanceToPoint = 1e-5f);
62
virtual ~SetOperations (void);
66
/** Cut this mesh with another one. The result is a list of polylines
67
* If the distance of the polyline to one of the points is less than minDistanceToPoint the polyline goes direct to the point
72
const MeshKernel &_cutMesh0; /** Mesh for set operations source 1 */
73
const MeshKernel &_cutMesh1; /** Mesh for set operations source 2 */
74
MeshKernel &_resultMesh; /** Result mesh */
75
OperationType _operationType; /** Set Operation Type */
76
float _minDistanceToPoint; /** Minimal distance to facet corner points */
77
float _saveMinMeshDistance;
80
// Helper class cutting edge to his two attached facets
84
MeshPoint pt1, pt2; // edge
90
Edge (MeshPoint p1, MeshPoint p2)
104
bool operator == (const Edge &edge) const
106
return (pt1 == edge.pt1) && (pt2 == edge.pt2);
109
bool operator < (const Edge &edge) const
111
return (pt1 == edge.pt1) ? (pt2 < edge.pt2) : (pt1 < edge.pt1);
118
int fcounter[2]; // counter of facets attacted to the edge
119
MeshGeomFacet facets[2][2]; // Geom-Facets attached to the edge
120
unsigned long facet[2]; // underlying Facet-Index
129
//class CollectFacetVisitor : public MeshFacetVisitor
132
// std::vector<unsigned long> &_facets;
133
// MeshKernel &_mesh;
134
// std::map<Edge, EdgeInfo> &_edges;
137
// int _addFacets; // 0: add facets to the result 1: do not add facets to the result
138
// Base::Builder3D& _builder;
140
// CollectFacetVisitor (MeshKernel& mesh, std::vector<unsigned long>& facets, std::map<Edge, EdgeInfo>& edges, int side, float mult, Base::Builder3D& builder);
141
// bool Visit (MeshFacet &rclFacet, const MeshFacet &rclFrom, unsigned long ulFInd, unsigned long ulLevel);
142
// bool AllowVisit (MeshFacet& rclFacet, MeshFacet& rclFrom, unsigned long ulFInd, unsigned long ulLevel, unsigned short neighbourIndex);
145
class CollectFacetVisitor : public MeshFacetVisitor
148
std::vector<unsigned long> &_facets;
149
const MeshKernel &_mesh;
150
std::map<Edge, EdgeInfo> &_edges;
153
int _addFacets; // 0: add facets to the result 1: do not add facets to the result
154
Base::Builder3D& _builder;
156
CollectFacetVisitor (const MeshKernel& mesh, std::vector<unsigned long>& facets, std::map<Edge, EdgeInfo>& edges, int side, float mult, Base::Builder3D& builder);
157
bool Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, unsigned long ulFInd, unsigned long ulLevel);
158
bool AllowVisit (const MeshFacet& rclFacet, const MeshFacet& rclFrom, unsigned long ulFInd, unsigned long ulLevel, unsigned short neighbourIndex);
161
/** all points from cut */
162
std::set<MeshPoint> _cutPoints;
164
std::map<Edge, EdgeInfo> _edges;
165
/** map from facet index to his cutted points (mesh 1 and mesh 2) Key: Facet-Index Value: List of iterators of set<MeshPoint> */
166
std::map<unsigned long, std::list<std::set<MeshPoint>::iterator> > _facet2points[2];
167
/** Facets collected from region growing */
168
std::vector<MeshGeomFacet> _facetsOf[2];
170
std::vector<MeshGeomFacet> _newMeshFacets[2];
172
/** Cut mesh 1 with mesh 2 */
173
void Cut (std::set<unsigned long>& facetsNotCuttingEdge0, std::set<unsigned long>& facetsCuttingEdge1);
174
/** Trianglute each facets cutted with his cutting points */
175
void TriangulateMesh (const MeshKernel &cutMesh, int side);
176
/** search facets for adding (with region growing) */
177
void CollectFacets (int side, float mult);
178
/** close gap in the mesh */
179
void CloseGaps (MeshBuilder& meshBuilder);
181
/** visual debugger */
182
Base::Builder3D _builder;
187
}; // namespace MeshCore
189
#endif // MESH_SETOPERATIONS_H