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_Type.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 <TopTools_DataMapOfShapeReal.hxx>
26 #include <BRepMesh_Delaun.hxx>
27 #include <BRepMesh_Triangle.hxx>
28 #include <BRepMesh_Classifier.hxx>
31 class BRepMesh_DataStructureOfDelaun;
32 class BRepMesh_FaceAttribute;
35 class BRepAdaptor_HSurface;
37 class Poly_Triangulation;
38 class TopLoc_Location;
42 class BRepMesh_Vertex;
45 //! Algorithm to mesh a face with respect of the frontier
46 //! the deflection and by option the shared components.
47 class BRepMesh_FastDiscretFace : public Standard_Transient
52 //! @param theAngle deviation angle to be used for surface tessellation.
53 //! @param isInternalVerticesMode flag enabling/disabling internal
55 //! @param isControlSurfaceDeflection enables/disables adaptive
56 //! reconfiguration of mesh.
57 Standard_EXPORT BRepMesh_FastDiscretFace(
58 const Standard_Real theAngle,
59 const Standard_Real theMinSize,
60 const Standard_Boolean isInternalVerticesMode,
61 const Standard_Boolean isControlSurfaceDeflection);
63 Standard_EXPORT void Perform(const Handle(BRepMesh_FaceAttribute)& theAttribute);
65 DEFINE_STANDARD_RTTIEXT(BRepMesh_FastDiscretFace,Standard_Transient)
69 void add(const Handle(BRepMesh_FaceAttribute)& theAttribute);
70 void add(const TopoDS_Vertex& theVertex);
72 Standard_Real control(BRepMesh_Delaun& theMeshBuilder,
73 const Standard_Boolean theIsFirst);
75 //! Registers the given nodes in mesh data structure and
76 //! performs refinement of existing mesh.
77 //! @param theVertices nodes to be inserted.
78 //! @param theMeshBuilder initialized tool refining mesh
79 //! in respect to inserting nodes.
80 //! @return TRUE if vertices were been inserted, FALSE elewhere.
81 Standard_Boolean addVerticesToMesh(
82 const BRepMesh::ListOfVertex& theVertices,
83 BRepMesh_Delaun& theMeshBuilder);
85 //! Calculates nodes lying on face's surface and inserts them to a mesh.
86 //! @param theMeshBuilder initialized tool refining mesh
87 //! in respect to inserting nodes.
88 void insertInternalVertices(BRepMesh_Delaun& theMeshBuilder);
90 //! Calculates nodes lying on spherical surface.
91 //! @param theNewVertices list of vertices to be extended and added to mesh.
92 void insertInternalVerticesSphere(BRepMesh::ListOfVertex& theNewVertices);
94 //! Calculates nodes lying on cylindrical surface.
95 //! @param theNewVertices list of vertices to be extended and added to mesh.
96 void insertInternalVerticesCylinder(BRepMesh::ListOfVertex& theNewVertices);
98 //! Calculates nodes lying on conical surface.
99 //! @param theNewVertices list of vertices to be extended and added to mesh.
100 void insertInternalVerticesCone(BRepMesh::ListOfVertex& theNewVertices);
102 //! Calculates nodes lying on toroidal surface.
103 //! @param theNewVertices list of vertices to be extended and added to mesh.
104 void insertInternalVerticesTorus(BRepMesh::ListOfVertex& theNewVertices);
106 //! Calculates nodes lying on custom-type surface.
107 //! @param theNewVertices list of vertices to be extended and added to mesh.
108 void insertInternalVerticesOther(BRepMesh::ListOfVertex& theNewVertices);
110 //! Template method trying to insert new internal vertex corresponded to
111 //! the given 2d point. Calculates 3d position analytically using the given
113 //! @param thePnt2d 2d point to be inserted to the list.
114 //! @param theAnalyticSurface analytic surface to calculate 3d point.
115 //! @param[out] theVertices list of vertices to be updated.
116 template<class AnalyticSurface>
117 void tryToInsertAnalyticVertex(const gp_Pnt2d& thePnt2d,
118 const AnalyticSurface& theAnalyticSurface,
119 BRepMesh::ListOfVertex& theVertices)
121 const BRepMesh::HClassifier& aClassifier = myAttribute->ChangeClassifier();
122 if (aClassifier->Perform(thePnt2d) != TopAbs_IN)
126 ElSLib::D0(thePnt2d.X(), thePnt2d.Y(), theAnalyticSurface, aPnt);
127 insertVertex(aPnt, thePnt2d.Coord(), theVertices);
130 //! Creates new vertex with the given parameters.
131 //! @param thePnt3d 3d point corresponded to the vertex.
132 //! @param theUV UV point corresponded to the vertex.
133 //! @param[out] theVertices list of vertices to be updated.
134 void insertVertex(const gp_Pnt& thePnt3d,
136 BRepMesh::ListOfVertex& theVertices);
138 //! Stores mesh into the face (without internal edges).
139 void commitSurfaceTriangulation();
141 //! Performs initialization of data structure using existing data.
142 void initDataStructure();
144 //! Adds new link to the mesh data structure.
145 //! Movability of the link and order of nodes depend on orientation parameter.
146 void addLinkToMesh(const Standard_Integer theFirstNodeId,
147 const Standard_Integer theLastNodeId,
148 const TopAbs_Orientation theOrientation);
150 //! Inserts new node into a mesh in case if smoothed region build
151 //! using the given node has better deflection metrics than source state.
152 //! @param thePnt3d 3d point corresponded to the vertex.
153 //! @param theUV UV point corresponded to the vertex.
154 //! @param isDeflectionCheckOnly if TRUE new node will not be added to a mesh
155 //! even if deflection parameter is better.
156 //! @param theTriangleDeflection deflection of a triangle from real geometry.
157 //! @param theFaceDeflection deflection to be achieved.
158 //! @param theCircleTool tool used for fast extraction of triangles
159 //! touched by the given point.
160 //! @param[out] theVertices list of vertices to be updated.
161 //! @param[in out] theMaxTriangleDeflection maximal deflection of a mesh.
162 //! @return TRUE in case if the given deflection of triangle is fine and
163 //! there is no necessity to insert new node or new node was being inserted
164 //! successfully, FALSE in case if new configuration is better but
165 //! isDeflectionCheckOnly flag is set.
166 Standard_Boolean checkDeflectionAndInsert(
167 const gp_Pnt& thePnt3d,
169 const Standard_Boolean isDeflectionCheckOnly,
170 const Standard_Real theTriangleDeflection,
171 const Standard_Real theFaceDeflection,
172 const BRepMesh_CircleTool& theCircleTool,
173 BRepMesh::ListOfVertex& theVertices,
174 Standard_Real& theMaxTriangleDeflection,
175 const Handle(NCollection_IncAllocator)& theTempAlloc);
179 Standard_Real myAngle;
180 Standard_Boolean myInternalVerticesMode;
181 BRepMesh::IMapOfReal myUParam;
182 BRepMesh::IMapOfReal myVParam;
184 // Fast access to attributes of current face
185 Handle(BRepMesh_FaceAttribute) myAttribute;
186 Handle(BRepMesh_DataStructureOfDelaun) myStructure;
188 Standard_Real myMinSize;
189 Standard_Boolean myIsControlSurfaceDeflection;
192 DEFINE_STANDARD_HANDLE (BRepMesh_FastDiscretFace, Standard_Transient)