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_FastDiscretFace_HeaderFile
15 #define _BRepMesh_FastDiscretFace_HeaderFile
17 #include <Standard.hxx>
18 #include <Standard_DefineHandle.hxx>
19 #include <BRepMesh_FastDiscretFace.hxx>
20 #include <BRepMesh_DataStructureOfDelaun.hxx>
21 #include <BRepMesh.hxx>
22 #include <BRepMesh_FaceAttribute.hxx>
23 #include <Standard_Transient.hxx>
24 #include <TopTools_MutexForShapeProvider.hxx>
25 #include <Handle_BRepAdaptor_HSurface.hxx>
26 #include <Handle_Poly_Triangulation.hxx>
27 #include <BRepMesh_Delaun.hxx>
28 #include <BRepMesh_Triangle.hxx>
29 #include <BRepMesh_Classifier.hxx>
32 class BRepMesh_DataStructureOfDelaun;
33 class BRepMesh_FaceAttribute;
35 class TopTools_DataMapOfShapeReal;
37 class BRepAdaptor_HSurface;
39 class Poly_Triangulation;
40 class TopLoc_Location;
44 class BRepMesh_Vertex;
47 //! Algorithm to mesh a face with respect of the frontier
48 //! the deflection and by option the shared components.
49 class BRepMesh_FastDiscretFace : public Standard_Transient
54 //! @param theAngle deviation angle to be used for surface tessellation.
55 //! @param isInternalVerticesMode flag enabling/disabling internal
57 //! @param isControlSurfaceDeflection enables/disables adaptive
58 //! reconfiguration of mesh.
59 Standard_EXPORT BRepMesh_FastDiscretFace(
60 const Standard_Real theAngle,
61 const Standard_Real theMinSize,
62 const Standard_Boolean isInternalVerticesMode,
63 const Standard_Boolean isControlSurfaceDeflection);
65 Standard_EXPORT void Perform(const Handle(BRepMesh_FaceAttribute)& theAttribute);
67 DEFINE_STANDARD_RTTI(BRepMesh_FastDiscretFace)
71 void add(const Handle(BRepMesh_FaceAttribute)& theAttribute);
72 void add(const TopoDS_Vertex& theVertex);
74 Standard_Real control(BRepMesh::ListOfVertex& theNewVertices,
75 BRepMesh_Delaun& theMeshBuilder,
76 const Standard_Boolean theIsFirst);
78 //! Registers the given nodes in mesh data structure and
79 //! performs refinement of existing mesh.
80 //! @param theVertices nodes to be inserted.
81 //! @param theMeshBuilder initialized tool refining mesh
82 //! in respect to inserting nodes.
83 //! @return TRUE if vertices were been inserted, FALSE elewhere.
84 Standard_Boolean addVerticesToMesh(
85 const BRepMesh::ListOfVertex& theVertices,
86 BRepMesh_Delaun& theMeshBuilder);
88 //! Calculates nodes lying on face's surface and inserts them to a mesh.
89 //! @param theNewVertices list of vertices to be extended and added to mesh.
90 //! @param theMeshBuilder initialized tool refining mesh
91 //! in respect to inserting nodes.
92 void insertInternalVertices(BRepMesh::ListOfVertex& theNewVertices,
93 BRepMesh_Delaun& theMeshBuilder);
95 //! Calculates nodes lying on spherical surface.
96 //! @param theNewVertices list of vertices to be extended and added to mesh.
97 void insertInternalVerticesSphere(BRepMesh::ListOfVertex& theNewVertices);
99 //! Calculates nodes lying on cylindrical surface.
100 //! @param theNewVertices list of vertices to be extended and added to mesh.
101 void insertInternalVerticesCylinder(BRepMesh::ListOfVertex& theNewVertices);
103 //! Calculates nodes lying on conical surface.
104 //! @param theNewVertices list of vertices to be extended and added to mesh.
105 void insertInternalVerticesCone(BRepMesh::ListOfVertex& theNewVertices);
107 //! Calculates nodes lying on toroidal surface.
108 //! @param theNewVertices list of vertices to be extended and added to mesh.
109 void insertInternalVerticesTorus(BRepMesh::ListOfVertex& theNewVertices);
111 //! Calculates nodes lying on Bezier/BSpline surface.
112 //! @param theNewVertices list of vertices to be extended and added to mesh.
113 void insertInternalVerticesBSpline(BRepMesh::ListOfVertex& theNewVertices);
115 //! Calculates nodes lying on custom-type surface.
116 //! @param theNewVertices list of vertices to be extended and added to mesh.
117 void insertInternalVerticesOther(BRepMesh::ListOfVertex& theNewVertices);
119 //! Template method trying to insert new internal vertex corresponded to
120 //! the given 2d point. Calculates 3d position analytically using the given
122 //! @param thePnt2d 2d point to be inserted to the list.
123 //! @param theAnalyticSurface analytic surface to calculate 3d point.
124 //! @param[out] theVertices list of vertices to be updated.
125 template<class AnalyticSurface>
126 void tryToInsertAnalyticVertex(const gp_Pnt2d& thePnt2d,
127 const AnalyticSurface& theAnalyticSurface,
128 BRepMesh::ListOfVertex& theVertices)
130 const BRepMesh::HClassifier& aClassifier = myAttribute->ChangeClassifier();
131 if (aClassifier->Perform(thePnt2d) != TopAbs_IN)
135 ElSLib::D0(thePnt2d.X(), thePnt2d.Y(), theAnalyticSurface, aPnt);
136 insertVertex(aPnt, thePnt2d.Coord(), theVertices);
139 //! Creates new vertex with the given parameters.
140 //! @param thePnt3d 3d point corresponded to the vertex.
141 //! @param theUV UV point corresponded to the vertex.
142 //! @param[out] theVertices list of vertices to be updated.
143 void insertVertex(const gp_Pnt& thePnt3d,
145 BRepMesh::ListOfVertex& theVertices);
147 //! Stores mesh into the face (without internal edges).
148 void commitSurfaceTriangulation();
150 //! Performs initialization of data structure using existing data.
151 void initDataStructure();
153 //! Adds new link to the mesh data structure.
154 //! Movability of the link and order of nodes depend on orientation parameter.
155 void addLinkToMesh(const Standard_Integer theFirstNodeId,
156 const Standard_Integer theLastNodeId,
157 const TopAbs_Orientation theOrientation);
159 //! Inserts new node into a mesh in case if smoothed region build
160 //! using the given node has better deflection metrics than source state.
161 //! @param thePnt3d 3d point corresponded to the vertex.
162 //! @param theUV UV point corresponded to the vertex.
163 //! @param isDeflectionCheckOnly if TRUE new node will not be added to a mesh
164 //! even if deflection parameter is better.
165 //! @param theTriangleDeflection deflection of a triangle from real geometry.
166 //! @param theFaceDeflection deflection to be achieved.
167 //! @param theCircleTool tool used for fast extraction of triangles
168 //! touched by the given point.
169 //! @param[out] theVertices list of vertices to be updated.
170 //! @param[in out] theMaxTriangleDeflection maximal deflection of a mesh.
171 //! @return TRUE in case if the given deflection of triangle is fine and
172 //! there is no necessity to insert new node or new node was being inserted
173 //! successfully, FALSE in case if new configuration is better but
174 //! isDeflectionCheckOnly flag is set.
175 Standard_Boolean checkDeflectionAndInsert(
176 const gp_Pnt& thePnt3d,
178 const Standard_Boolean isDeflectionCheckOnly,
179 const Standard_Real theTriangleDeflection,
180 const Standard_Real theFaceDeflection,
181 const BRepMesh_CircleTool& theCircleTool,
182 BRepMesh::ListOfVertex& theVertices,
183 Standard_Real& theMaxTriangleDeflection);
187 Standard_Real myAngle;
188 Standard_Boolean myInternalVerticesMode;
189 BRepMesh::IMapOfReal myUParam;
190 BRepMesh::IMapOfReal myVParam;
192 // Fast access to attributes of current face
193 Handle(BRepMesh_FaceAttribute) myAttribute;
194 Handle(BRepMesh_DataStructureOfDelaun) myStructure;
196 Standard_Real myMinSize;
197 Standard_Boolean myIsControlSurfaceDeflection;
200 DEFINE_STANDARD_HANDLE (BRepMesh_FastDiscretFace, Standard_Transient)