0027362: Meshing performance
[occt.git] / src / BRepMesh / BRepMesh_FastDiscret.hxx
CommitLineData
fc9b36d6 1// Copyright (c) 2013 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#ifndef _BRepMesh_FastDiscret_HeaderFile
15#define _BRepMesh_FastDiscret_HeaderFile
16
17#include <Standard.hxx>
ec357c5c 18#include <Standard_Type.hxx>
fc9b36d6 19#include <BRepMesh_FastDiscret.hxx>
20#include <BRepMesh_DataStructureOfDelaun.hxx>
21#include <TColStd_IndexedMapOfInteger.hxx>
22#include <BRepMesh_Status.hxx>
23#include <TopTools_DataMapOfShapeReal.hxx>
24#include <TopTools_ListOfShape.hxx>
25#include <TopTools_MutexForShapeProvider.hxx>
26#include <Standard_Transient.hxx>
fc9b36d6 27#include <BRepMesh_Delaun.hxx>
28#include <TopAbs_ShapeEnum.hxx>
29#include <BRepMesh_Triangle.hxx>
30#include <BRepMesh_FaceAttribute.hxx>
848fa7e3 31#include <BRepMesh.hxx>
ceb418e1 32#include <TColgp_Array1OfPnt.hxx>
33#include <BRep_Tool.hxx>
34#include <BRepMesh_ShapeTool.hxx>
35#include <TopoDS_Vertex.hxx>
36#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
fc9b36d6 37
38class BRepMesh_DataStructureOfDelaun;
39class Bnd_Box;
40class TopoDS_Shape;
41class TopoDS_Face;
fc9b36d6 42class TopoDS_Edge;
81093856 43class Geom2dAdaptor_HCurve;
fc9b36d6 44class BRepAdaptor_HSurface;
fc9b36d6 45class BRepMesh_Edge;
46class BRepMesh_Vertex;
47class gp_Pnt;
48class BRepMesh_FaceAttribute;
fc9b36d6 49
50//! Algorithm to mesh a shape with respect of the <br>
51//! frontier the deflection and by option the shared <br>
52//! components. <br>
53class BRepMesh_FastDiscret : public Standard_Transient
54{
55public:
e71669c6 56
57
58 //! Structure storing meshing parameters
59 struct Parameters {
60
61 //! Default constructor
62 Parameters()
63 :
64 Angle(0.1),
65 Deflection(0.001),
66 MinSize(Precision::Confusion()),
67 InParallel(Standard_False),
68 Relative(Standard_False),
69 AdaptiveMin(Standard_False),
70 InternalVerticesMode(Standard_True),
71 ControlSurfaceDeflection(Standard_True)
72 {
73 }
74
75 //! Angular deflection
76 Standard_Real Angle;
77
78 //! Deflection
79 Standard_Real Deflection;
80
81 //! Minimal allowed size of mesh element
82 Standard_Real MinSize;
83
84 //! Switches on/off multy thread computation
85 Standard_Boolean InParallel;
86
87 //! Switches on/off relative computation of edge tolerance<br>
88 //! If trur, deflection used for the polygonalisation of each edge will be
89 //! <defle> * Size of Edge. The deflection used for the faces will be the
90 //! maximum deflection of their edges.
91 Standard_Boolean Relative;
92
93 //! Adaptive parametric tolerance flag. <br>
94 //! If this flag is set to true the minimal parametric tolerance
95 //! is computed taking minimal parametric distance between vertices
96 //! into account
97 Standard_Boolean AdaptiveMin;
98
99 //! Mode to take or ont to take internal face vertices into account
100 //! in triangulation process
101 Standard_Boolean InternalVerticesMode;
102
103 //! Prameter to check the deviation of triangulation and interior of
104 //! the face
105 Standard_Boolean ControlSurfaceDeflection;
106 };
107
108public:
109
fc9b36d6 110
e71669c6 111 //! Constructor.
112 //! Sets the meshing parameters and updates
113 //! relative defletion according to bounding box
114 //! @param B - bounding box encompasing shape
115 //! @param theParams - meshing algo parameters
116 Standard_EXPORT BRepMesh_FastDiscret (const Bnd_Box& B,
117 const Parameters& theParams);
fc9b36d6 118
ceb418e1 119 //! Build triangulation on the whole shape.
fc9b36d6 120 Standard_EXPORT void Perform(const TopoDS_Shape& shape);
121
ceb418e1 122 //! Record a face for further processing.
123 //! @return status flags collected during discretization
124 //! of boundaries of the given face.
125 Standard_EXPORT Standard_Integer Add(const TopoDS_Face& face);
fc9b36d6 126
ceb418e1 127 //! Triangulate a face previously recorded for
128 //! processing by call to Add(). Can be executed in
129 //! parallel threads.
fc9b36d6 130 Standard_EXPORT void Process(const TopoDS_Face& face) const;
131
e71669c6 132 void operator () (const TopoDS_Face& face) const
fc9b36d6 133 {
134 Process(face);
135 }
136
e71669c6 137 //! Returns parameters of meshing
138 inline const Parameters& MeshParameters() const
ceb418e1 139 {
e71669c6 140 return myParameters;
fc9b36d6 141 }
142
e71669c6 143 //! Returns modificable mesh parameters
144 inline Parameters& ChangeMeshParameters()
fc9b36d6 145 {
e71669c6 146 return myParameters;
fc9b36d6 147 }
e71669c6 148
fc9b36d6 149
ceb418e1 150 Standard_EXPORT void InitSharedFaces(const TopoDS_Shape& theShape);
fc9b36d6 151
ceb418e1 152 inline const TopTools_IndexedDataMapOfShapeListOfShape& SharedFaces() const
fc9b36d6 153 {
ceb418e1 154 return mySharedFaces;
fc9b36d6 155 }
156
0a2a7b46 157 //! Returns attribute descriptor for the given face.
158 //! @param theFace face the attribute should be returned for.
159 //! @param[out] theAttribute attribute found for the specified face.
160 //! @param isForceCreate if True creates new attribute in case if there
161 //! is no data for the given face.
162 Standard_EXPORT Standard_Boolean GetFaceAttribute (
163 const TopoDS_Face& theFace,
164 Handle(BRepMesh_FaceAttribute)& theAttribute,
165 const Standard_Boolean isForceCreate = Standard_False) const;
ceb418e1 166
167 //! Remove face attribute as useless to free locate memory.
168 Standard_EXPORT void RemoveFaceAttribute( const TopoDS_Face& theFace );
169
170 //! Returns number of boundary 3d points.
171 inline Standard_Integer NbBoundaryPoints() const
172 {
848fa7e3 173 return myBoundaryPoints->Extent();
ceb418e1 174 }
fc9b36d6 175
92efcf78 176 DEFINE_STANDARD_RTTIEXT(BRepMesh_FastDiscret,Standard_Transient)
fc9b36d6 177
ceb418e1 178private:
179
180 //! Auxiliary class used to extract geometrical parameters of TopoDS_Vertex.
181 class TopoDSVExplorer
182 {
183 public:
184 TopoDSVExplorer(
185 const TopoDS_Vertex& theVertex,
186 const Standard_Boolean isSameUV,
187 const TopoDS_Vertex& theSameVertex)
188 : myVertex(theVertex),
189 myIsSameUV(isSameUV),
190 mySameVertex(theSameVertex)
191 {
192 }
bcf50875 193 virtual ~TopoDSVExplorer() {
194 }
ceb418e1 195 const TopoDS_Vertex& Vertex() const
196 {
197 return myVertex;
198 }
199
200 Standard_Boolean IsSameUV() const
201 {
202 return myIsSameUV;
203 }
204
205 const TopoDS_Vertex& SameVertex() const
206 {
207 return mySameVertex;
208 }
209
210 virtual gp_Pnt Point() const
211 {
212 return BRep_Tool::Pnt(myVertex);
213 }
214
215 private:
216
217 void operator =(const TopoDSVExplorer& /*theOther*/)
218 {
219 }
220
221 private:
222 const TopoDS_Vertex& myVertex;
223 Standard_Boolean myIsSameUV;
224 const TopoDS_Vertex& mySameVertex;
225 };
226
227
228 //! Auxiliary class used to extract polygonal parameters of TopoDS_Vertex.
229 class PolyVExplorer : public TopoDSVExplorer
230 {
231 public:
232 PolyVExplorer(
233 const TopoDS_Vertex& theVertex,
234 const Standard_Boolean isSameUV,
235 const TopoDS_Vertex& theSameVertex,
236 const Standard_Integer theVertexIndex,
237 const TColgp_Array1OfPnt& thePolygon,
238 const TopLoc_Location& theLoc)
239 : TopoDSVExplorer(theVertex, isSameUV, theSameVertex),
240 myVertexIndex(theVertexIndex),
241 myPolygon(thePolygon),
242 myLoc(theLoc)
243 {
244 }
245
246 virtual gp_Pnt Point() const
247 {
248 return BRepMesh_ShapeTool::UseLocation(myPolygon(myVertexIndex), myLoc);
249 }
250
251 private:
252
253 void operator =(const PolyVExplorer& /*theOther*/)
254 {
255 }
256
257 private:
258 Standard_Integer myVertexIndex;
259 const TColgp_Array1OfPnt& myPolygon;
260 const TopLoc_Location myLoc;
261 };
262
263 //! Structure keeps common parameters of edge
264 //! used for tessellation.
265 struct EdgeAttributes
266 {
848fa7e3 267 TopoDS_Vertex FirstVertex;
268 TopoDS_Vertex LastVertex;
ceb418e1 269
848fa7e3 270 Standard_Real FirstParam;
271 Standard_Real LastParam;
ceb418e1 272
848fa7e3 273 gp_Pnt2d FirstUV;
274 gp_Pnt2d LastUV;
ceb418e1 275
81093856 276 Standard_Real Deflection;
848fa7e3 277 Standard_Boolean IsSameUV;
ceb418e1 278
848fa7e3 279 NCollection_Handle<TopoDSVExplorer> FirstVExtractor;
280 NCollection_Handle<TopoDSVExplorer> LastVExtractor;
ceb418e1 281 };
282
ceb418e1 283 //! Fills structure of by attributes of the given edge.
284 //! @return TRUE on success, FALSE elsewhere.
285 Standard_Boolean getEdgeAttributes(
286 const TopoDS_Edge& theEdge,
81093856 287 const Handle(Geom2dAdaptor_HCurve)& thePCurve,
ceb418e1 288 const Standard_Real theDefEdge,
289 EdgeAttributes& theAttributes) const;
290
291 //! Registers end vertices of the edge in mesh data
292 //! structure of currently processed face.
293 void registerEdgeVertices(
294 EdgeAttributes& theAttributes,
295 Standard_Integer& ipf,
296 Standard_Integer& ivf,
297 Standard_Integer& isvf,
298 Standard_Integer& ipl,
299 Standard_Integer& ivl,
300 Standard_Integer& isvl);
301
302 //! Adds tessellated representation of the given edge to
303 //! mesh data structure of currently processed face.
304 void add(const TopoDS_Edge& theEdge,
81093856 305 const Handle(Geom2dAdaptor_HCurve)& theCurve2D,
ceb418e1 306 const Standard_Real theEdgeDeflection);
307
308 //! Updates tessellated representation of the given edge.
309 //! If edge already has a polygon which deflection satisfies
310 //! the given value, retrieves tessellation from polygon.
311 //! Computes tessellation using edge's geometry elsewhere.
312 void update(
313 const TopoDS_Edge& theEdge,
81093856 314 const Handle(Geom2dAdaptor_HCurve)& theCurve2D,
ceb418e1 315 const Standard_Real theEdgeDeflection,
316 EdgeAttributes& theAttributes);
317
ceb418e1 318 //! Stores polygonal model of the given edge.
319 //! @param theEdge edge which polygonal model is stored.
320 //! @param thePolygon polygonal model of the edge.
321 //! @param theDeflection deflection with which polygonalization is performed.
322 //! This value is stored inside the polygon.
323 void storePolygon(
324 const TopoDS_Edge& theEdge,
325 Handle(Poly_PolygonOnTriangulation)& thePolygon,
326 const Standard_Real theDeflection);
327
328 //! Caches polygonal model of the given edge to be used in further.
329 //! @param theEdge edge which polygonal data is stored.
330 //! @param thePolygon shared polygonal data of the edge.
331 //! @param theDeflection deflection with which polygonalization is performed.
332 //! This value is stored inside the polygon.
333 void storePolygonSharedData(
334 const TopoDS_Edge& theEdge,
335 Handle(Poly_PolygonOnTriangulation)& thePolygon,
336 const Standard_Real theDeflection);
fc9b36d6 337
2caff0b3 338 //! Resets temporary data structure used to collect unique nodes.
339 void resetDataStructure();
340
fc9b36d6 341private:
342
848fa7e3 343 TopoDS_Face myFace;
e71669c6 344
848fa7e3 345 BRepMesh::DMapOfShapePairOfPolygon myEdges;
0a2a7b46 346 mutable BRepMesh::DMapOfFaceAttribute myAttributes;
848fa7e3 347 TopTools_DataMapOfShapeReal myMapdefle;
ceb418e1 348
349 // Data shared for whole shape
848fa7e3 350 BRepMesh::HDMapOfVertexInteger myBoundaryVertices;
351 BRepMesh::HDMapOfIntegerPnt myBoundaryPoints;
ceb418e1 352
353 // Fast access to attributes of current face
848fa7e3 354 Handle(BRepMesh_FaceAttribute) myAttribute;
848fa7e3 355 TopTools_IndexedDataMapOfShapeListOfShape mySharedFaces;
74da0216 356
e71669c6 357 Parameters myParameters;
358
359 Standard_Real myDtotale;
fc9b36d6 360};
361
362DEFINE_STANDARD_HANDLE(BRepMesh_FastDiscret, Standard_Transient)
363
364#endif