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_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>
35 class BRepMesh_DataStructureOfDelaun;
39 class TopTools_IndexedDataMapOfShapeListOfShape;
41 class BRepAdaptor_HSurface;
45 class BRepMesh_Vertex;
47 class BRepMesh_FaceAttribute;
48 class TopTools_DataMapOfShapeReal;
51 //! Algorithm to mesh a shape with respect of the <br>
52 //! frontier the deflection and by option the shared <br>
54 class BRepMesh_FastDiscret : public Standard_Transient
58 Standard_EXPORT BRepMesh_FastDiscret(const Standard_Real defle,
59 const Standard_Real angle,
61 const Standard_Boolean withShare = Standard_True,
62 const Standard_Boolean inshape = Standard_False,
63 const Standard_Boolean relative = Standard_False,
64 const Standard_Boolean shapetrigu = Standard_False,
65 const Standard_Boolean isInParallel = Standard_False);
67 //! if the boolean <relative> is True, the <br>
68 //! deflection used for the polygonalisation of <br>
69 //! each edge will be <defle> * Size of Edge. <br>
70 //! the deflection used for the faces will be the maximum <br>
71 //! deflection of their edges. <br>
73 //! if <shapetrigu> is True, the triangulation, if exists <br>
74 //! with a correct deflection, can be used to re-triangulate <br>
77 //! if <inshape> is True, the calculated <br>
78 //! triangulation will be stored in the shape. <br>
79 Standard_EXPORT BRepMesh_FastDiscret(const TopoDS_Shape& shape,
80 const Standard_Real defle,
81 const Standard_Real angle,
83 const Standard_Boolean withShare = Standard_True,
84 const Standard_Boolean inshape = Standard_False,
85 const Standard_Boolean relative = Standard_False,
86 const Standard_Boolean shapetrigu = Standard_False,
87 const Standard_Boolean isInParallel = Standard_False);
89 //! Build triangulation on the whole shape <br>
90 Standard_EXPORT void Perform(const TopoDS_Shape& shape);
92 //! Record a face for further processing. <br>
93 Standard_EXPORT void Add(const TopoDS_Face& face,
94 const TopTools_IndexedDataMapOfShapeListOfShape& ancestor) ;
96 //! Triangulate a face previously recorded for <br>
97 //! processing by call to Add(). Can be executed in <br>
98 //! parallel threads. <br>
99 Standard_EXPORT void Process(const TopoDS_Face& face) const;
101 void operator ()(const TopoDS_Face& face) const
106 Standard_EXPORT BRepMesh_Status CurrentFaceStatus() const;
108 //! Request algorithm to launch in multiple threads <br>
109 //! to improve performance (should be supported by plugin). <br>
110 Standard_EXPORT void SetParallel(const Standard_Boolean theInParallel);
112 //! Returns the multi-threading usage flag. <br>
113 Standard_EXPORT Standard_Boolean IsParallel() const;
115 //! Creates mutexes for each sub-shape of type theType in theShape. <br>
116 //! Used to avoid data races. <br>
117 Standard_EXPORT void CreateMutexesForSubShapes(const TopoDS_Shape& theShape,
118 const TopAbs_ShapeEnum theType);
120 //! Removes all created mutexes <br>
121 Standard_EXPORT void RemoveAllMutexes();
123 //! Gives the number of built triangles. <br>
124 Standard_EXPORT Standard_Integer NbTriangles() const;
126 //! Gives the triangle of <Index>. <br>
127 Standard_EXPORT const BRepMesh_Triangle& Triangle(const Standard_Integer Index) const;
129 //! Gives the number of built Edges <br>
130 Standard_EXPORT Standard_Integer NbEdges() const;
132 //! Gives the edge of index <Index>. <br>
133 Standard_EXPORT const BRepMesh_Edge& Edge(const Standard_Integer Index) const;
135 //! Gives the number of built Vertices. <br>
136 Standard_EXPORT Standard_Integer NbVertices() const;
138 //! Gives the vertex of <Index>. <br>
139 Standard_EXPORT const BRepMesh_Vertex& Vertex(const Standard_Integer Index) const;
141 //! Gives the nodes of triangle with the given index.
142 Standard_EXPORT void TriangleNodes(const Standard_Integer theIndex,
143 Standard_Integer (&theNodes)[3]) const
145 myStructure->ElementNodes(Triangle(theIndex), theNodes);
148 //! Gives the location3d of the vertex of <Index>. <br>
149 Standard_EXPORT const gp_Pnt& Pnt(const Standard_Integer Index) const;
151 //! Gives the list of indices of the vertices <br>
152 Standard_EXPORT void VerticesOfDomain(BRepMeshCol::MapOfInteger& Indices) const;
154 //! Gives the list of indices of the edges <br>
155 inline void EdgesOfDomain(BRepMeshCol::MapOfInteger& Indices) const
157 Indices = myStructure->LinksOfDomain();
160 //! Gives the list of indices of the triangles <br>
161 inline void TrianglesOfDomain(BRepMeshCol::MapOfInteger& Indices) const
163 Indices = myStructure->ElementsOfDomain();
166 //! Gives the number of different location in 3d space.
167 //! It is different of the number of vertices if there
168 //! is more than one surface. <br>
169 //! Even for one surface, the number can be different
170 //! if an edge is shared. <br>
171 inline Standard_Integer NbPoint3d() const
176 //! Gives the 3d space location of the vertex <Index>. <br>
177 inline const gp_Pnt& Point3d(const Standard_Integer Index) const
179 return myLocation3d(Index);
182 //! returns the deflection value. <br>
183 inline Standard_Real GetDeflection() const
188 //! returns the deflection value. <br>
189 inline Standard_Real GetAngle() const
194 inline Standard_Boolean WithShare() const
199 inline Standard_Boolean InShape() const
204 inline Standard_Boolean ShapeTrigu() const
209 //! returns the face deflection value. <br>
210 Standard_EXPORT Standard_Boolean GetFaceAttribute(const TopoDS_Face& face,Handle(BRepMesh_FaceAttribute)& fattrib) const;
212 //! remove face attribute as useless to free locate memory <br>
213 Standard_EXPORT void RemoveFaceAttribute(const TopoDS_Face& face);
215 inline const TopTools_DataMapOfShapeReal& GetMapOfDefEdge() const
221 DEFINE_STANDARD_RTTI(BRepMesh_FastDiscret)
225 void Add(const TopoDS_Edge& edge,
226 const TopoDS_Face& face,
227 const Handle(BRepAdaptor_HSurface)& S,
228 const Handle(Geom2d_Curve)& C,
229 const TopTools_IndexedDataMapOfShapeListOfShape& ancestor,
230 const Standard_Real defedge,
231 const Standard_Real first,
232 const Standard_Real last);
234 void Add(const TopoDS_Vertex& theVert,
235 const TopoDS_Face& face,
236 const Handle(BRepAdaptor_HSurface)& S);
238 Standard_Boolean Update(const TopoDS_Edge& Edge,
239 const TopoDS_Face& Face,
240 const Handle(Geom2d_Curve)& C,
241 const Standard_Real defedge,
242 const Standard_Real first,
243 const Standard_Real last);
245 void InternalVertices(const Handle(BRepAdaptor_HSurface)& caro,
246 BRepMeshCol::ListOfVertex& inter,
247 const Standard_Real defedge,
248 const BRepMeshCol::HClassifier& classifier);
250 Standard_Real Control(const Handle(BRepAdaptor_HSurface)& caro,
251 const Standard_Real defface,
252 BRepMeshCol::ListOfVertex& inter,
253 BRepMeshCol::ListOfInteger& badTri,
254 BRepMeshCol::ListOfInteger& nulTri,
255 BRepMesh_Delaun& trigu,
256 const Standard_Boolean isfirst);
258 void AddInShape(const TopoDS_Face& face,
259 const Standard_Real defedge);
263 Standard_Real myAngle;
264 Standard_Real myDeflection;
265 Standard_Real myDtotale;
266 Standard_Boolean myWithShare;
267 Standard_Boolean myInParallel;
268 BRepMeshCol::DMapOfVertexInteger myVertices;
269 BRepMeshCol::DMapOfShapePairOfPolygon myEdges;
270 BRepMeshCol::DMapOfShapePairOfPolygon myInternaledges;
271 Standard_Integer myNbLocat;
272 BRepMeshCol::DMapOfIntegerPnt myLocation3d;
273 Handle_BRepMesh_DataStructureOfDelaun myStructure;
274 BRepMeshCol::DMapOfFaceAttribute myMapattrib;
275 TColStd_IndexedMapOfInteger myVemap;
276 BRepMeshCol::DMapOfIntegerListOfXY myLocation2d;
277 Standard_Boolean myRelative;
278 Standard_Boolean myShapetrigu;
279 Standard_Boolean myInshape;
280 BRepMesh_Status myFacestate;
281 TopTools_DataMapOfShapeReal myMapdefle;
282 TopTools_ListOfShape myNottriangulated;
283 BRepMeshCol::Allocator myAllocator;
284 TopTools_MutexForShapeProvider myMutexProvider;
287 DEFINE_STANDARD_HANDLE(BRepMesh_FastDiscret, Standard_Transient)