0023106: BRepMesh_IncrementalMesh returns wrong status
[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>
18#include <Standard_DefineHandle.hxx>
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>
27#include <Handle_BRepAdaptor_HSurface.hxx>
28#include <Handle_Geom2d_Curve.hxx>
29#include <BRepMesh_Delaun.hxx>
30#include <TopAbs_ShapeEnum.hxx>
31#include <BRepMesh_Triangle.hxx>
32#include <BRepMesh_FaceAttribute.hxx>
33#include <BRepMesh_Collections.hxx>
ceb418e1 34#include <TColgp_Array1OfPnt.hxx>
35#include <BRep_Tool.hxx>
36#include <BRepMesh_ShapeTool.hxx>
37#include <TopoDS_Vertex.hxx>
38#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
fc9b36d6 39
40class BRepMesh_DataStructureOfDelaun;
41class Bnd_Box;
42class TopoDS_Shape;
43class TopoDS_Face;
fc9b36d6 44class TopoDS_Edge;
45class BRepAdaptor_HSurface;
46class Geom2d_Curve;
fc9b36d6 47class BRepMesh_Edge;
48class BRepMesh_Vertex;
49class gp_Pnt;
50class BRepMesh_FaceAttribute;
51class TopTools_DataMapOfShapeReal;
52
53
54//! Algorithm to mesh a shape with respect of the <br>
55//! frontier the deflection and by option the shared <br>
56//! components. <br>
57class BRepMesh_FastDiscret : public Standard_Transient
58{
59public:
60
61 Standard_EXPORT BRepMesh_FastDiscret(const Standard_Real defle,
62 const Standard_Real angle,
63 const Bnd_Box& B,
64 const Standard_Boolean withShare = Standard_True,
65 const Standard_Boolean inshape = Standard_False,
66 const Standard_Boolean relative = Standard_False,
67 const Standard_Boolean shapetrigu = Standard_False,
68 const Standard_Boolean isInParallel = Standard_False);
69
70 //! if the boolean <relative> is True, the <br>
71 //! deflection used for the polygonalisation of <br>
72 //! each edge will be <defle> * Size of Edge. <br>
73 //! the deflection used for the faces will be the maximum <br>
74 //! deflection of their edges. <br>
75 //! <br>
76 //! if <shapetrigu> is True, the triangulation, if exists <br>
77 //! with a correct deflection, can be used to re-triangulate <br>
78 //! the shape. <br>
79 //! <br>
80 //! if <inshape> is True, the calculated <br>
81 //! triangulation will be stored in the shape. <br>
82 Standard_EXPORT BRepMesh_FastDiscret(const TopoDS_Shape& shape,
83 const Standard_Real defle,
84 const Standard_Real angle,
85 const Bnd_Box& B,
86 const Standard_Boolean withShare = Standard_True,
87 const Standard_Boolean inshape = Standard_False,
88 const Standard_Boolean relative = Standard_False,
89 const Standard_Boolean shapetrigu = Standard_False,
90 const Standard_Boolean isInParallel = Standard_False);
91
ceb418e1 92 //! Build triangulation on the whole shape.
fc9b36d6 93 Standard_EXPORT void Perform(const TopoDS_Shape& shape);
94
ceb418e1 95 //! Record a face for further processing.
96 //! @return status flags collected during discretization
97 //! of boundaries of the given face.
98 Standard_EXPORT Standard_Integer Add(const TopoDS_Face& face);
fc9b36d6 99
ceb418e1 100 //! Triangulate a face previously recorded for
101 //! processing by call to Add(). Can be executed in
102 //! parallel threads.
fc9b36d6 103 Standard_EXPORT void Process(const TopoDS_Face& face) const;
104
105 void operator ()(const TopoDS_Face& face) const
106 {
107 Process(face);
108 }
109
fc9b36d6 110 //! Request algorithm to launch in multiple threads <br>
111 //! to improve performance (should be supported by plugin). <br>
ceb418e1 112 inline void SetParallel(const Standard_Boolean theInParallel)
113 {
114 myInParallel = theInParallel;
115 }
fc9b36d6 116
117 //! Returns the multi-threading usage flag. <br>
ceb418e1 118 inline Standard_Boolean IsParallel() const
fc9b36d6 119 {
ceb418e1 120 return myInParallel;
fc9b36d6 121 }
ceb418e1 122
fc9b36d6 123 //! Gives the list of indices of the vertices <br>
124 Standard_EXPORT void VerticesOfDomain(BRepMeshCol::MapOfInteger& Indices) const;
125
fc9b36d6 126 //! returns the deflection value. <br>
127 inline Standard_Real GetDeflection() const
128 {
129 return myDeflection;
130 }
131
132 //! returns the deflection value. <br>
133 inline Standard_Real GetAngle() const
134 {
135 return myAngle;
136 }
137
138 inline Standard_Boolean WithShare() const
139 {
140 return myWithShare;
141 }
142
143 inline Standard_Boolean InShape() const
144 {
145 return myInshape;
146 }
147
148 inline Standard_Boolean ShapeTrigu() const
149 {
150 return myShapetrigu;
151 }
152
ceb418e1 153 Standard_EXPORT void InitSharedFaces(const TopoDS_Shape& theShape);
fc9b36d6 154
ceb418e1 155 inline const TopTools_IndexedDataMapOfShapeListOfShape& SharedFaces() const
fc9b36d6 156 {
ceb418e1 157 return mySharedFaces;
fc9b36d6 158 }
159
ceb418e1 160 //! Gives face attribute.
161 Standard_EXPORT Standard_Boolean GetFaceAttribute
162 ( const TopoDS_Face& theFace, Handle(BRepMesh_FaceAttribute)& theAttribute ) const;
163
164 //! Remove face attribute as useless to free locate memory.
165 Standard_EXPORT void RemoveFaceAttribute( const TopoDS_Face& theFace );
166
167 //! Returns number of boundary 3d points.
168 inline Standard_Integer NbBoundaryPoints() const
169 {
170 return myBoundaryPoints.Extent();
171 }
fc9b36d6 172
173 DEFINE_STANDARD_RTTI(BRepMesh_FastDiscret)
174
ceb418e1 175private:
176
177 //! Auxiliary class used to extract geometrical parameters of TopoDS_Vertex.
178 class TopoDSVExplorer
179 {
180 public:
181 TopoDSVExplorer(
182 const TopoDS_Vertex& theVertex,
183 const Standard_Boolean isSameUV,
184 const TopoDS_Vertex& theSameVertex)
185 : myVertex(theVertex),
186 myIsSameUV(isSameUV),
187 mySameVertex(theSameVertex)
188 {
189 }
190
191 const TopoDS_Vertex& Vertex() const
192 {
193 return myVertex;
194 }
195
196 Standard_Boolean IsSameUV() const
197 {
198 return myIsSameUV;
199 }
200
201 const TopoDS_Vertex& SameVertex() const
202 {
203 return mySameVertex;
204 }
205
206 virtual gp_Pnt Point() const
207 {
208 return BRep_Tool::Pnt(myVertex);
209 }
210
211 private:
212
213 void operator =(const TopoDSVExplorer& /*theOther*/)
214 {
215 }
216
217 private:
218 const TopoDS_Vertex& myVertex;
219 Standard_Boolean myIsSameUV;
220 const TopoDS_Vertex& mySameVertex;
221 };
222
223
224 //! Auxiliary class used to extract polygonal parameters of TopoDS_Vertex.
225 class PolyVExplorer : public TopoDSVExplorer
226 {
227 public:
228 PolyVExplorer(
229 const TopoDS_Vertex& theVertex,
230 const Standard_Boolean isSameUV,
231 const TopoDS_Vertex& theSameVertex,
232 const Standard_Integer theVertexIndex,
233 const TColgp_Array1OfPnt& thePolygon,
234 const TopLoc_Location& theLoc)
235 : TopoDSVExplorer(theVertex, isSameUV, theSameVertex),
236 myVertexIndex(theVertexIndex),
237 myPolygon(thePolygon),
238 myLoc(theLoc)
239 {
240 }
241
242 virtual gp_Pnt Point() const
243 {
244 return BRepMesh_ShapeTool::UseLocation(myPolygon(myVertexIndex), myLoc);
245 }
246
247 private:
248
249 void operator =(const PolyVExplorer& /*theOther*/)
250 {
251 }
252
253 private:
254 Standard_Integer myVertexIndex;
255 const TColgp_Array1OfPnt& myPolygon;
256 const TopLoc_Location myLoc;
257 };
258
259 //! Structure keeps common parameters of edge
260 //! used for tessellation.
261 struct EdgeAttributes
262 {
263 TopoDS_Vertex FirstVertex;
264 TopoDS_Vertex LastVertex;
265
266 Standard_Real FirstParam;
267 Standard_Real LastParam;
268
269 gp_Pnt2d FirstUV;
270 gp_Pnt2d LastUV;
271
272 Standard_Boolean IsSameUV;
273 Standard_Real MinDist;
274
275 N_HANDLE<TopoDSVExplorer> FirstVExtractor;
276 N_HANDLE<TopoDSVExplorer> LastVExtractor;
277 };
278
279 //! Structure keeps geometrical parameters of edge's PCurve.
280 //! Used for caching.
281 struct EdgePCurve
282 {
283 Handle(Geom2d_Curve) Curve2d;
284 Standard_Real FirstParam;
285 Standard_Real LastParam;
286 };
287
288 //! Fills structure of by attributes of the given edge.
289 //! @return TRUE on success, FALSE elsewhere.
290 Standard_Boolean getEdgeAttributes(
291 const TopoDS_Edge& theEdge,
292 const EdgePCurve& thePCurve,
293 const Standard_Real theDefEdge,
294 EdgeAttributes& theAttributes) const;
295
296 //! Registers end vertices of the edge in mesh data
297 //! structure of currently processed face.
298 void registerEdgeVertices(
299 EdgeAttributes& theAttributes,
300 Standard_Integer& ipf,
301 Standard_Integer& ivf,
302 Standard_Integer& isvf,
303 Standard_Integer& ipl,
304 Standard_Integer& ivl,
305 Standard_Integer& isvl);
306
307 //! Adds tessellated representation of the given edge to
308 //! mesh data structure of currently processed face.
309 void add(const TopoDS_Edge& theEdge,
310 const EdgePCurve& theCurve2D,
311 const Standard_Real theEdgeDeflection);
312
313 //! Updates tessellated representation of the given edge.
314 //! If edge already has a polygon which deflection satisfies
315 //! the given value, retrieves tessellation from polygon.
316 //! Computes tessellation using edge's geometry elsewhere.
317 void update(
318 const TopoDS_Edge& theEdge,
319 const Handle(Geom2d_Curve)& theCurve2D,
320 const Standard_Real theEdgeDeflection,
321 EdgeAttributes& theAttributes);
322
323 //! Adds new link to the mesh data structure.
324 //! Movability of the link and order of nodes depend on orientation parameter.
325 void addLinkToMesh(const Standard_Integer theFirstNodeId,
326 const Standard_Integer theLastNodeId,
327 const TopAbs_Orientation theOrientation);
328
329 //! Stores polygonal model of the given edge.
330 //! @param theEdge edge which polygonal model is stored.
331 //! @param thePolygon polygonal model of the edge.
332 //! @param theDeflection deflection with which polygonalization is performed.
333 //! This value is stored inside the polygon.
334 void storePolygon(
335 const TopoDS_Edge& theEdge,
336 Handle(Poly_PolygonOnTriangulation)& thePolygon,
337 const Standard_Real theDeflection);
338
339 //! Caches polygonal model of the given edge to be used in further.
340 //! @param theEdge edge which polygonal data is stored.
341 //! @param thePolygon shared polygonal data of the edge.
342 //! @param theDeflection deflection with which polygonalization is performed.
343 //! This value is stored inside the polygon.
344 void storePolygonSharedData(
345 const TopoDS_Edge& theEdge,
346 Handle(Poly_PolygonOnTriangulation)& thePolygon,
347 const Standard_Real theDeflection);
fc9b36d6 348
349private:
350
ceb418e1 351 TopoDS_Face myFace;
352 Standard_Real myAngle;
353 Standard_Real myDeflection;
354 Standard_Real myDtotale;
355 Standard_Boolean myWithShare;
356 Standard_Boolean myInParallel;
357 BRepMeshCol::DMapOfShapePairOfPolygon myEdges;
358 BRepMeshCol::DMapOfFaceAttribute myAttributes;
359 Standard_Boolean myRelative;
360 Standard_Boolean myShapetrigu;
361 Standard_Boolean myInshape;
362 TopTools_DataMapOfShapeReal myMapdefle;
363
364 // Data shared for whole shape
365 BRepMeshCol::DMapOfVertexInteger myBoundaryVertices;
366 BRepMeshCol::DMapOfIntegerPnt myBoundaryPoints;
367
368 // Fast access to attributes of current face
369 Handle(BRepMesh_FaceAttribute) myAttribute;
370 Handle(BRepMesh_DataStructureOfDelaun) myStructure;
371 BRepMeshCol::HIMapOfInteger myVertexEdgeMap;
372 BRepMeshCol::HDMapOfShapePairOfPolygon myInternalEdges;
373 TopTools_IndexedDataMapOfShapeListOfShape mySharedFaces;
fc9b36d6 374};
375
376DEFINE_STANDARD_HANDLE(BRepMesh_FastDiscret, Standard_Transient)
377
378#endif