0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[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;
43class BRepAdaptor_HSurface;
44class Geom2d_Curve;
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
ceb418e1 157 //! Gives face attribute.
158 Standard_EXPORT Standard_Boolean GetFaceAttribute
159 ( const TopoDS_Face& theFace, Handle(BRepMesh_FaceAttribute)& theAttribute ) const;
160
161 //! Remove face attribute as useless to free locate memory.
162 Standard_EXPORT void RemoveFaceAttribute( const TopoDS_Face& theFace );
163
164 //! Returns number of boundary 3d points.
165 inline Standard_Integer NbBoundaryPoints() const
166 {
848fa7e3 167 return myBoundaryPoints->Extent();
ceb418e1 168 }
fc9b36d6 169
92efcf78 170 DEFINE_STANDARD_RTTIEXT(BRepMesh_FastDiscret,Standard_Transient)
fc9b36d6 171
ceb418e1 172private:
173
174 //! Auxiliary class used to extract geometrical parameters of TopoDS_Vertex.
175 class TopoDSVExplorer
176 {
177 public:
178 TopoDSVExplorer(
179 const TopoDS_Vertex& theVertex,
180 const Standard_Boolean isSameUV,
181 const TopoDS_Vertex& theSameVertex)
182 : myVertex(theVertex),
183 myIsSameUV(isSameUV),
184 mySameVertex(theSameVertex)
185 {
186 }
bcf50875 187 virtual ~TopoDSVExplorer() {
188 }
ceb418e1 189 const TopoDS_Vertex& Vertex() const
190 {
191 return myVertex;
192 }
193
194 Standard_Boolean IsSameUV() const
195 {
196 return myIsSameUV;
197 }
198
199 const TopoDS_Vertex& SameVertex() const
200 {
201 return mySameVertex;
202 }
203
204 virtual gp_Pnt Point() const
205 {
206 return BRep_Tool::Pnt(myVertex);
207 }
208
209 private:
210
211 void operator =(const TopoDSVExplorer& /*theOther*/)
212 {
213 }
214
215 private:
216 const TopoDS_Vertex& myVertex;
217 Standard_Boolean myIsSameUV;
218 const TopoDS_Vertex& mySameVertex;
219 };
220
221
222 //! Auxiliary class used to extract polygonal parameters of TopoDS_Vertex.
223 class PolyVExplorer : public TopoDSVExplorer
224 {
225 public:
226 PolyVExplorer(
227 const TopoDS_Vertex& theVertex,
228 const Standard_Boolean isSameUV,
229 const TopoDS_Vertex& theSameVertex,
230 const Standard_Integer theVertexIndex,
231 const TColgp_Array1OfPnt& thePolygon,
232 const TopLoc_Location& theLoc)
233 : TopoDSVExplorer(theVertex, isSameUV, theSameVertex),
234 myVertexIndex(theVertexIndex),
235 myPolygon(thePolygon),
236 myLoc(theLoc)
237 {
238 }
239
240 virtual gp_Pnt Point() const
241 {
242 return BRepMesh_ShapeTool::UseLocation(myPolygon(myVertexIndex), myLoc);
243 }
244
245 private:
246
247 void operator =(const PolyVExplorer& /*theOther*/)
248 {
249 }
250
251 private:
252 Standard_Integer myVertexIndex;
253 const TColgp_Array1OfPnt& myPolygon;
254 const TopLoc_Location myLoc;
255 };
256
257 //! Structure keeps common parameters of edge
258 //! used for tessellation.
259 struct EdgeAttributes
260 {
848fa7e3 261 TopoDS_Vertex FirstVertex;
262 TopoDS_Vertex LastVertex;
ceb418e1 263
848fa7e3 264 Standard_Real FirstParam;
265 Standard_Real LastParam;
ceb418e1 266
848fa7e3 267 gp_Pnt2d FirstUV;
268 gp_Pnt2d LastUV;
ceb418e1 269
848fa7e3 270 Standard_Boolean IsSameUV;
271 Standard_Real MinDist;
ceb418e1 272
848fa7e3 273 NCollection_Handle<TopoDSVExplorer> FirstVExtractor;
274 NCollection_Handle<TopoDSVExplorer> LastVExtractor;
ceb418e1 275 };
276
277 //! Structure keeps geometrical parameters of edge's PCurve.
278 //! Used for caching.
279 struct EdgePCurve
280 {
281 Handle(Geom2d_Curve) Curve2d;
282 Standard_Real FirstParam;
283 Standard_Real LastParam;
284 };
285
286 //! Fills structure of by attributes of the given edge.
287 //! @return TRUE on success, FALSE elsewhere.
288 Standard_Boolean getEdgeAttributes(
289 const TopoDS_Edge& theEdge,
290 const EdgePCurve& thePCurve,
291 const Standard_Real theDefEdge,
292 EdgeAttributes& theAttributes) const;
293
294 //! Registers end vertices of the edge in mesh data
295 //! structure of currently processed face.
296 void registerEdgeVertices(
297 EdgeAttributes& theAttributes,
298 Standard_Integer& ipf,
299 Standard_Integer& ivf,
300 Standard_Integer& isvf,
301 Standard_Integer& ipl,
302 Standard_Integer& ivl,
303 Standard_Integer& isvl);
304
305 //! Adds tessellated representation of the given edge to
306 //! mesh data structure of currently processed face.
307 void add(const TopoDS_Edge& theEdge,
308 const EdgePCurve& theCurve2D,
309 const Standard_Real theEdgeDeflection);
310
311 //! Updates tessellated representation of the given edge.
312 //! If edge already has a polygon which deflection satisfies
313 //! the given value, retrieves tessellation from polygon.
314 //! Computes tessellation using edge's geometry elsewhere.
315 void update(
316 const TopoDS_Edge& theEdge,
317 const Handle(Geom2d_Curve)& theCurve2D,
318 const Standard_Real theEdgeDeflection,
319 EdgeAttributes& theAttributes);
320
ceb418e1 321 //! Stores polygonal model of the given edge.
322 //! @param theEdge edge which polygonal model is stored.
323 //! @param thePolygon polygonal model of the edge.
324 //! @param theDeflection deflection with which polygonalization is performed.
325 //! This value is stored inside the polygon.
326 void storePolygon(
327 const TopoDS_Edge& theEdge,
328 Handle(Poly_PolygonOnTriangulation)& thePolygon,
329 const Standard_Real theDeflection);
330
331 //! Caches polygonal model of the given edge to be used in further.
332 //! @param theEdge edge which polygonal data is stored.
333 //! @param thePolygon shared polygonal data of the edge.
334 //! @param theDeflection deflection with which polygonalization is performed.
335 //! This value is stored inside the polygon.
336 void storePolygonSharedData(
337 const TopoDS_Edge& theEdge,
338 Handle(Poly_PolygonOnTriangulation)& thePolygon,
339 const Standard_Real theDeflection);
fc9b36d6 340
2caff0b3 341 //! Resets temporary data structure used to collect unique nodes.
342 void resetDataStructure();
343
fc9b36d6 344private:
345
848fa7e3 346 TopoDS_Face myFace;
e71669c6 347
848fa7e3 348 BRepMesh::DMapOfShapePairOfPolygon myEdges;
349 BRepMesh::DMapOfFaceAttribute myAttributes;
848fa7e3 350 TopTools_DataMapOfShapeReal myMapdefle;
ceb418e1 351
352 // Data shared for whole shape
848fa7e3 353 BRepMesh::HDMapOfVertexInteger myBoundaryVertices;
354 BRepMesh::HDMapOfIntegerPnt myBoundaryPoints;
ceb418e1 355
356 // Fast access to attributes of current face
848fa7e3 357 Handle(BRepMesh_FaceAttribute) myAttribute;
848fa7e3 358 TopTools_IndexedDataMapOfShapeListOfShape mySharedFaces;
74da0216 359
e71669c6 360 Parameters myParameters;
361
362 Standard_Real myDtotale;
fc9b36d6 363};
364
365DEFINE_STANDARD_HANDLE(BRepMesh_FastDiscret, Standard_Transient)
366
367#endif