1 // Copyright (c) 2013 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _BRepMesh_FastDiscret_HeaderFile
15 #define _BRepMesh_FastDiscret_HeaderFile
17 #include <Standard.hxx>
18 #include <Standard_Type.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.hxx>
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>
40 class BRepMesh_DataStructureOfDelaun;
45 class BRepAdaptor_HSurface;
48 class BRepMesh_Vertex;
50 class BRepMesh_FaceAttribute;
52 //! Algorithm to mesh a shape with respect of the <br>
53 //! frontier the deflection and by option the shared <br>
55 class BRepMesh_FastDiscret : public Standard_Transient
59 Standard_EXPORT BRepMesh_FastDiscret(
60 const Standard_Real defle,
61 const Standard_Real angle,
63 const Standard_Boolean withShare = Standard_True,
64 const Standard_Boolean inshape = Standard_False,
65 const Standard_Boolean relative = Standard_False,
66 const Standard_Boolean shapetrigu = Standard_False,
67 const Standard_Boolean isInParallel = Standard_False,
68 const Standard_Real theMinSize = Precision::Confusion(),
69 const Standard_Boolean isInternalVerticesMode = Standard_True,
70 const Standard_Boolean isControlSurfaceDeflection = Standard_True);
72 //! if the boolean <relative> is True, the <br>
73 //! deflection used for the polygonalisation of <br>
74 //! each edge will be <defle> * Size of Edge. <br>
75 //! the deflection used for the faces will be the maximum <br>
76 //! deflection of their edges. <br>
78 //! if <shapetrigu> is True, the triangulation, if exists <br>
79 //! with a correct deflection, can be used to re-triangulate <br>
82 //! if <inshape> is True, the calculated <br>
83 //! triangulation will be stored in the shape. <br>
84 Standard_EXPORT BRepMesh_FastDiscret(
85 const TopoDS_Shape& shape,
86 const Standard_Real defle,
87 const Standard_Real angle,
89 const Standard_Boolean withShare = Standard_True,
90 const Standard_Boolean inshape = Standard_False,
91 const Standard_Boolean relative = Standard_False,
92 const Standard_Boolean shapetrigu = Standard_False,
93 const Standard_Boolean isInParallel = Standard_False,
94 const Standard_Real theMinSize = Precision::Confusion(),
95 const Standard_Boolean isInternalVerticesMode = Standard_True,
96 const Standard_Boolean isControlSurfaceDeflection = Standard_True);
98 //! Build triangulation on the whole shape.
99 Standard_EXPORT void Perform(const TopoDS_Shape& shape);
101 //! Record a face for further processing.
102 //! @return status flags collected during discretization
103 //! of boundaries of the given face.
104 Standard_EXPORT Standard_Integer Add(const TopoDS_Face& face);
106 //! Triangulate a face previously recorded for
107 //! processing by call to Add(). Can be executed in
108 //! parallel threads.
109 Standard_EXPORT void Process(const TopoDS_Face& face) const;
111 void operator ()(const TopoDS_Face& face) const
116 //! Request algorithm to launch in multiple threads <br>
117 //! to improve performance (should be supported by plugin). <br>
118 inline void SetParallel(const Standard_Boolean theInParallel)
120 myInParallel = theInParallel;
123 //! Returns the multi-threading usage flag. <br>
124 inline Standard_Boolean IsParallel() const
129 //! returns the deflection value. <br>
130 inline Standard_Real GetDeflection() const
135 //! returns the deflection value. <br>
136 inline Standard_Real GetAngle() const
141 inline Standard_Boolean WithShare() const
146 inline Standard_Boolean InShape() const
151 inline Standard_Boolean ShapeTrigu() const
156 Standard_EXPORT void InitSharedFaces(const TopoDS_Shape& theShape);
158 inline const TopTools_IndexedDataMapOfShapeListOfShape& SharedFaces() const
160 return mySharedFaces;
163 //! Gives face attribute.
164 Standard_EXPORT Standard_Boolean GetFaceAttribute
165 ( const TopoDS_Face& theFace, Handle(BRepMesh_FaceAttribute)& theAttribute ) const;
167 //! Remove face attribute as useless to free locate memory.
168 Standard_EXPORT void RemoveFaceAttribute( const TopoDS_Face& theFace );
170 //! Returns number of boundary 3d points.
171 inline Standard_Integer NbBoundaryPoints() const
173 return myBoundaryPoints->Extent();
176 DEFINE_STANDARD_RTTI(BRepMesh_FastDiscret, Standard_Transient)
180 //! Auxiliary class used to extract geometrical parameters of TopoDS_Vertex.
181 class 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)
193 virtual ~TopoDSVExplorer() {
195 const TopoDS_Vertex& Vertex() const
200 Standard_Boolean IsSameUV() const
205 const TopoDS_Vertex& SameVertex() const
210 virtual gp_Pnt Point() const
212 return BRep_Tool::Pnt(myVertex);
217 void operator =(const TopoDSVExplorer& /*theOther*/)
222 const TopoDS_Vertex& myVertex;
223 Standard_Boolean myIsSameUV;
224 const TopoDS_Vertex& mySameVertex;
228 //! Auxiliary class used to extract polygonal parameters of TopoDS_Vertex.
229 class PolyVExplorer : public TopoDSVExplorer
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),
246 virtual gp_Pnt Point() const
248 return BRepMesh_ShapeTool::UseLocation(myPolygon(myVertexIndex), myLoc);
253 void operator =(const PolyVExplorer& /*theOther*/)
258 Standard_Integer myVertexIndex;
259 const TColgp_Array1OfPnt& myPolygon;
260 const TopLoc_Location myLoc;
263 //! Structure keeps common parameters of edge
264 //! used for tessellation.
265 struct EdgeAttributes
267 TopoDS_Vertex FirstVertex;
268 TopoDS_Vertex LastVertex;
270 Standard_Real FirstParam;
271 Standard_Real LastParam;
276 Standard_Boolean IsSameUV;
277 Standard_Real MinDist;
279 NCollection_Handle<TopoDSVExplorer> FirstVExtractor;
280 NCollection_Handle<TopoDSVExplorer> LastVExtractor;
283 //! Structure keeps geometrical parameters of edge's PCurve.
284 //! Used for caching.
287 Handle(Geom2d_Curve) Curve2d;
288 Standard_Real FirstParam;
289 Standard_Real LastParam;
292 //! Fills structure of by attributes of the given edge.
293 //! @return TRUE on success, FALSE elsewhere.
294 Standard_Boolean getEdgeAttributes(
295 const TopoDS_Edge& theEdge,
296 const EdgePCurve& thePCurve,
297 const Standard_Real theDefEdge,
298 EdgeAttributes& theAttributes) const;
300 //! Registers end vertices of the edge in mesh data
301 //! structure of currently processed face.
302 void registerEdgeVertices(
303 EdgeAttributes& theAttributes,
304 Standard_Integer& ipf,
305 Standard_Integer& ivf,
306 Standard_Integer& isvf,
307 Standard_Integer& ipl,
308 Standard_Integer& ivl,
309 Standard_Integer& isvl);
311 //! Adds tessellated representation of the given edge to
312 //! mesh data structure of currently processed face.
313 void add(const TopoDS_Edge& theEdge,
314 const EdgePCurve& theCurve2D,
315 const Standard_Real theEdgeDeflection);
317 //! Updates tessellated representation of the given edge.
318 //! If edge already has a polygon which deflection satisfies
319 //! the given value, retrieves tessellation from polygon.
320 //! Computes tessellation using edge's geometry elsewhere.
322 const TopoDS_Edge& theEdge,
323 const Handle(Geom2d_Curve)& theCurve2D,
324 const Standard_Real theEdgeDeflection,
325 EdgeAttributes& theAttributes);
327 //! Stores polygonal model of the given edge.
328 //! @param theEdge edge which polygonal model is stored.
329 //! @param thePolygon polygonal model of the edge.
330 //! @param theDeflection deflection with which polygonalization is performed.
331 //! This value is stored inside the polygon.
333 const TopoDS_Edge& theEdge,
334 Handle(Poly_PolygonOnTriangulation)& thePolygon,
335 const Standard_Real theDeflection);
337 //! Caches polygonal model of the given edge to be used in further.
338 //! @param theEdge edge which polygonal data is stored.
339 //! @param thePolygon shared polygonal data of the edge.
340 //! @param theDeflection deflection with which polygonalization is performed.
341 //! This value is stored inside the polygon.
342 void storePolygonSharedData(
343 const TopoDS_Edge& theEdge,
344 Handle(Poly_PolygonOnTriangulation)& thePolygon,
345 const Standard_Real theDeflection);
347 //! Resets temporary data structure used to collect unique nodes.
348 void resetDataStructure();
353 Standard_Real myAngle;
354 Standard_Real myDeflection;
355 Standard_Real myDtotale;
356 Standard_Boolean myWithShare;
357 Standard_Boolean myInParallel;
358 BRepMesh::DMapOfShapePairOfPolygon myEdges;
359 BRepMesh::DMapOfFaceAttribute myAttributes;
360 Standard_Boolean myRelative;
361 Standard_Boolean myShapetrigu;
362 Standard_Boolean myInshape;
363 TopTools_DataMapOfShapeReal myMapdefle;
365 // Data shared for whole shape
366 BRepMesh::HDMapOfVertexInteger myBoundaryVertices;
367 BRepMesh::HDMapOfIntegerPnt myBoundaryPoints;
369 // Fast access to attributes of current face
370 Handle(BRepMesh_FaceAttribute) myAttribute;
371 TopTools_IndexedDataMapOfShapeListOfShape mySharedFaces;
373 Standard_Real myMinSize;
374 Standard_Boolean myInternalVerticesMode;
375 Standard_Boolean myIsControlSurfaceDeflection;
378 DEFINE_STANDARD_HANDLE(BRepMesh_FastDiscret, Standard_Transient)