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 //! Sets min size parameter.
107 inline void SetMinSize(const Standard_Real theMinSize)
109 myMinSize = Max(theMinSize, Precision::Confusion());
112 //! Returns min size parameter.
113 inline Standard_Real GetMinSize() const
118 //! Enables/disables internal vertices mode (enabled by default).
119 inline void SetInternalVerticesMode(const Standard_Boolean isEnabled)
121 myInternalVerticesMode = isEnabled;
124 //! Returns flag indicating is internal vertices mode enabled/disabled.
125 inline Standard_Boolean IsInternalVerticesMode() const
127 return myInternalVerticesMode;
130 //! Enables/disables control of deflection of mesh from real surface
131 //! (enabled by default).
132 inline void SetControlSurfaceDeflection(const Standard_Boolean isEnabled)
134 myIsControlSurfaceDeflection = isEnabled;
137 //! Returns flag indicating is adaptive reconfiguration
138 //! of mesh enabled/disabled.
139 inline Standard_Boolean IsControlSurfaceDeflection() const
141 return myIsControlSurfaceDeflection;
144 public: //! @name plugin API
146 //! Plugin interface for the Mesh Factories.
147 //! Initializes meshing algorithm with the given parameters.
148 //! @param theShape shape to be meshed.
149 //! @param theLinDeflection linear deflection.
150 //! @param theAngDeflection angular deflection.
151 //! @param[out] theAlgo pointer to initialized algorithm.
152 Standard_EXPORT static Standard_Integer Discret(const TopoDS_Shape& theShape,
153 const Standard_Real theLinDeflection,
154 const Standard_Real theAngDeflection,
155 BRepMesh_DiscretRoot* &theAlgo);
157 //! Returns multi-threading usage flag set by default in
158 //! Discret() static method (thus applied only to Mesh Factories).
159 Standard_EXPORT static Standard_Boolean IsParallelDefault();
161 //! Setup multi-threading usage flag set by default in
162 //! Discret() static method (thus applied only to Mesh Factories).
163 Standard_EXPORT static void SetParallelDefault(const Standard_Boolean isInParallel);
165 DEFINE_STANDARD_RTTI(BRepMesh_IncrementalMesh)
169 Standard_EXPORT virtual void init();
173 //! Builds the incremental mesh for the shape.
176 //! Checks triangulation of the given face for consistency
177 //! with the chosen tolerance. If some edge of face has no
178 //! discrete representation triangulation will be calculated.
179 //! @param theFace face to be checked.
180 void update(const TopoDS_Face& theFace);
182 //! Checks discretization of the given edge for consistency
183 //! with the chosen tolerance.
184 //! @param theEdge edge to be checked.
185 void update(const TopoDS_Edge& theEdge);
187 //! Collects faces suitable for meshing.
190 //! Discretizes edges that have no associations with faces.
191 void discretizeFreeEdges();
193 //! Returns deflection of the given edge.
194 //! @param theEdge edge which tolerance should be taken.
195 Standard_Real edgeDeflection(const TopoDS_Edge& theEdge);
197 //! Returns deflection of the given face.
198 //! If relative flag is set, calculates relative deflection of the face
199 //! as an average value of relative deflection regarding face's edges.
200 //! Returns value of deflection set by user elsewhere.
201 Standard_Real faceDeflection(const TopoDS_Face& theFace);
203 //! Prepares the given face for meshing.
204 //! Nullifies triangulation of face and polygons of face's edges.
205 //! @param theFace face to be checked.
206 //! @param isWithCheck if TRUE, checks parameters of triangulation
207 //! existing in face. If its deflection satisfies the given value and
208 //! each edge of face has polygon corresponded to this triangulation,
209 //! method return FALSE.
210 //! @return TRUE in case if the given face should be meshed.
211 Standard_Boolean toBeMeshed(const TopoDS_Face& theFace,
212 const Standard_Boolean isWithCheck);
214 //! Stores mesh to the shape.
217 //! Stores mesh of internal edges to the face.
218 void commitEdges(const TopoDS_Face& theFace);
220 //! Clears internal data structures.
225 Standard_Boolean myRelative;
226 Standard_Boolean myInParallel;
227 BRepMesh::DMapOfEdgeListOfTriangulationBool myEdges;
228 Handle(BRepMesh_FastDiscret) myMesh;
229 Standard_Boolean myModified;
230 TopTools_DataMapOfShapeReal myEdgeDeflection;
231 Standard_Real myMaxShapeSize;
232 Standard_Integer myStatus;
233 NCollection_Vector<TopoDS_Face> myFaces;
234 Standard_Real myMinSize;
235 Standard_Boolean myInternalVerticesMode;
236 Standard_Boolean myIsControlSurfaceDeflection;
239 DEFINE_STANDARD_HANDLE(BRepMesh_IncrementalMesh,BRepMesh_DiscretRoot)