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_IncrementalMesh_HeaderFile
15 #define _BRepMesh_IncrementalMesh_HeaderFile
17 #include <Standard.hxx>
18 #include <Standard_DefineHandle.hxx>
20 #include <BRepMesh_FastDiscret.hxx>
21 #include <TopTools_MapOfShape.hxx>
22 #include <TopTools_DataMapOfShapeReal.hxx>
23 #include <BRepMesh_DiscretRoot.hxx>
24 #include <Handle_Poly_Triangulation.hxx>
25 #include <BRepMesh.hxx>
29 class Poly_Triangulation;
34 //! Builds the mesh of a shape with respect of their
35 //! correctly triangulated parts
36 class BRepMesh_IncrementalMesh : public BRepMesh_DiscretRoot
38 public: //! @name mesher API
40 //! Default constructor
41 Standard_EXPORT BRepMesh_IncrementalMesh();
44 Standard_EXPORT virtual ~BRepMesh_IncrementalMesh();
47 //! Automatically calls method Perform.
48 //! @param theShape shape to be meshed.
49 //! @param theLinDeflection linear deflection.
50 //! @param isRelative if TRUE deflection used for discretization of
51 //! each edge will be <theLinDeflection> * <size of edge>. Deflection
52 //! used for the faces will be the maximum deflection of their edges.
53 //! @param theAngDeflection angular deflection.
54 //! @param isInParallel if TRUE shape will be meshed in parallel.
55 Standard_EXPORT BRepMesh_IncrementalMesh(
56 const TopoDS_Shape& theShape,
57 const Standard_Real theLinDeflection,
58 const Standard_Boolean isRelative = Standard_False,
59 const Standard_Real theAngDeflection = 0.5,
60 const Standard_Boolean isInParallel = Standard_False);
62 //! Performs meshing ot the shape.
63 Standard_EXPORT virtual void Perform();
65 public: //! @name accessing to parameters.
67 //! Enables using relative deflection.
68 //! @param isRelative if TRUE deflection used for discretization of
69 //! each edge will be <theLinDeflection> * <size of edge>. Deflection
70 //! used for the faces will be the maximum deflection of their edges.
71 inline void SetRelative(const Standard_Boolean isRelative)
73 myRelative = isRelative;
76 //! Returns relative deflection flag.
77 inline Standard_Boolean IsRelative() const
82 //! Returns modified flag.
83 inline Standard_Boolean IsModified() const
88 //! Returns accumulated status flags faced during meshing.
89 inline Standard_Integer GetStatusFlags() const
94 //! Request algorithm to launch in multiple threads to improve performance.
95 inline void SetParallel(const Standard_Boolean isInParallel)
97 myInParallel = isInParallel;
100 //! Returns the multi-threading usage flag.
101 inline Standard_Boolean IsParallel() const
106 public: //! @name plugin API
108 //! Plugin interface for the Mesh Factories.
109 //! Initializes meshing algorithm with the given parameters.
110 //! @param theShape shape to be meshed.
111 //! @param theLinDeflection linear deflection.
112 //! @param theAngDeflection angular deflection.
113 //! @param[out] theAlgo pointer to initialized algorithm.
114 Standard_EXPORT static Standard_Integer Discret(const TopoDS_Shape& theShape,
115 const Standard_Real theLinDeflection,
116 const Standard_Real theAngDeflection,
117 BRepMesh_DiscretRoot* &theAlgo);
119 //! Returns multi-threading usage flag set by default in
120 //! Discret() static method (thus applied only to Mesh Factories).
121 Standard_EXPORT static Standard_Boolean IsParallelDefault();
123 //! Setup multi-threading usage flag set by default in
124 //! Discret() static method (thus applied only to Mesh Factories).
125 Standard_EXPORT static void SetParallelDefault(const Standard_Boolean isInParallel);
127 //! Returns mesh tool storing mesh data.
128 inline const Handle(BRepMesh_FastDiscret)& Mesh() const
133 DEFINE_STANDARD_RTTI(BRepMesh_IncrementalMesh)
137 Standard_EXPORT virtual void init();
141 //! Checks is the shape to be meshed has correct poly data,
142 //! i.e. PolygonOnTriangulation of particular edge connected
143 //! to the same Triangulation data structure as stored inside
145 //! @return TRUE on success, FALSE in case of inconsistencies.
146 Standard_Boolean isCorrectPolyData();
148 //! Builds the incremental mesh for the shape.
151 //! Checks triangulation of the given face for consistency
152 //! with the chosen tolerance. If some edge of face has no
153 //! discrete representation triangulation will be calculated.
154 //! @param theFace face to be checked.
155 void update(const TopoDS_Face& theFace);
157 //! Checks discretization of the given edge for consistency
158 //! with the chosen tolerance.
159 //! @param theEdge edge to be checked.
160 void update(const TopoDS_Edge& theEdge);
162 //! Collects faces suitable for meshing.
165 //! Discretizes edges that have no associations with faces.
166 void discretizeFreeEdges();
168 //! Returns deflection of the given edge.
169 //! @param theEdge edge which tolerance should be taken.
170 Standard_Real edgeDeflection(const TopoDS_Edge& theEdge);
172 //! Returns deflection of the given face.
173 //! If relative flag is set, calculates relative deflection of the face
174 //! as an average value of relative deflection regarding face's edges.
175 //! Returns value of deflection set by user elsewhere.
176 Standard_Real faceDeflection(const TopoDS_Face& theFace);
178 //! Prepares the given face for meshing.
179 //! Nullifies triangulation of face and polygons of face's edges.
180 //! @param theFace face to be checked.
181 //! @param isWithCheck if TRUE, checks parameters of triangulation
182 //! existing in face. If its deflection satisfies the given value and
183 //! each edge of face has polygon corresponded to this triangulation,
184 //! method return FALSE.
185 //! @return TRUE in case if the given face should be meshed.
186 Standard_Boolean toBeMeshed(const TopoDS_Face& theFace,
187 const Standard_Boolean isWithCheck);
189 //! Stores mesh to the shape.
192 //! Stores mesh of internal edges to the face.
193 void commitEdges(const TopoDS_Face& theFace);
197 Standard_Boolean myRelative;
198 Standard_Boolean myInParallel;
199 BRepMesh::DMapOfEdgeListOfTriangulation myEmptyEdges;
200 Handle(BRepMesh_FastDiscret) myMesh;
201 Standard_Boolean myModified;
202 TopTools_DataMapOfShapeReal myEdgeDeflection;
203 Standard_Real myMaxShapeSize;
204 Standard_Integer myStatus;
205 std::vector<TopoDS_Face> myFaces;
208 DEFINE_STANDARD_HANDLE(BRepMesh_IncrementalMesh,BRepMesh_DiscretRoot)