0025936: Reusable data structure for 2D tesselation (3- and 4-nodal mesh)
[occt.git] / src / BRepMesh / BRepMesh_FastDiscretFace.hxx
CommitLineData
fc9b36d6 1// Copyright (c) 2013 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
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.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#ifndef _BRepMesh_FastDiscretFace_HeaderFile
15#define _BRepMesh_FastDiscretFace_HeaderFile
16
17#include <Standard.hxx>
18#include <Standard_DefineHandle.hxx>
19#include <BRepMesh_FastDiscretFace.hxx>
20#include <BRepMesh_DataStructureOfDelaun.hxx>
848fa7e3 21#include <BRepMesh.hxx>
fc9b36d6 22#include <BRepMesh_FaceAttribute.hxx>
23#include <Standard_Transient.hxx>
24#include <TopTools_MutexForShapeProvider.hxx>
25#include <Handle_BRepAdaptor_HSurface.hxx>
6c1f47fd 26#include <Poly_Triangulation.hxx>
fc9b36d6 27#include <BRepMesh_Delaun.hxx>
28#include <BRepMesh_Triangle.hxx>
ceb418e1 29#include <BRepMesh_Classifier.hxx>
30#include <ElSLib.hxx>
fc9b36d6 31
32class BRepMesh_DataStructureOfDelaun;
33class BRepMesh_FaceAttribute;
34class TopoDS_Face;
35class TopTools_DataMapOfShapeReal;
36class TopoDS_Vertex;
37class BRepAdaptor_HSurface;
38class TopoDS_Edge;
fc9b36d6 39class TopLoc_Location;
40class gp_XY;
41class gp_Pnt2d;
42class BRepMesh_Edge;
43class BRepMesh_Vertex;
44class gp_Pnt;
45
46//! Algorithm to mesh a face with respect of the frontier
ceb418e1 47//! the deflection and by option the shared components.
fc9b36d6 48class BRepMesh_FastDiscretFace : public Standard_Transient
49{
50public:
848fa7e3 51
a319f03f 52 //! Constructor.
53 //! @param theAngle deviation angle to be used for surface tessellation.
54 //! @param isInternalVerticesMode flag enabling/disabling internal
55 //! vertices mode.
f43eff9f 56 //! @param isControlSurfaceDeflection enables/disables adaptive
57 //! reconfiguration of mesh.
848fa7e3 58 Standard_EXPORT BRepMesh_FastDiscretFace(
a319f03f 59 const Standard_Real theAngle,
74da0216 60 const Standard_Real theMinSize,
f43eff9f 61 const Standard_Boolean isInternalVerticesMode,
62 const Standard_Boolean isControlSurfaceDeflection);
ceb418e1 63
fcf15f5c 64 Standard_EXPORT void Perform(const Handle(BRepMesh_FaceAttribute)& theAttribute);
fc9b36d6 65
ceb418e1 66 DEFINE_STANDARD_RTTI(BRepMesh_FastDiscretFace)
fc9b36d6 67
ceb418e1 68private:
fc9b36d6 69
2caff0b3 70 void add(const Handle(BRepMesh_FaceAttribute)& theAttribute);
ceb418e1 71 void add(const TopoDS_Vertex& theVertex);
fc9b36d6 72
848fa7e3 73 Standard_Real control(BRepMesh::ListOfVertex& theNewVertices,
74 BRepMesh_Delaun& theMeshBuilder,
75 const Standard_Boolean theIsFirst);
fc9b36d6 76
ceb418e1 77 //! Registers the given nodes in mesh data structure and
78 //! performs refinement of existing mesh.
79 //! @param theVertices nodes to be inserted.
80 //! @param theMeshBuilder initialized tool refining mesh
81 //! in respect to inserting nodes.
82 //! @return TRUE if vertices were been inserted, FALSE elewhere.
83 Standard_Boolean addVerticesToMesh(
848fa7e3 84 const BRepMesh::ListOfVertex& theVertices,
85 BRepMesh_Delaun& theMeshBuilder);
ceb418e1 86
87 //! Calculates nodes lying on face's surface and inserts them to a mesh.
88 //! @param theNewVertices list of vertices to be extended and added to mesh.
89 //! @param theMeshBuilder initialized tool refining mesh
90 //! in respect to inserting nodes.
848fa7e3 91 void insertInternalVertices(BRepMesh::ListOfVertex& theNewVertices,
92 BRepMesh_Delaun& theMeshBuilder);
ceb418e1 93
94 //! Calculates nodes lying on spherical surface.
95 //! @param theNewVertices list of vertices to be extended and added to mesh.
848fa7e3 96 void insertInternalVerticesSphere(BRepMesh::ListOfVertex& theNewVertices);
ceb418e1 97
98 //! Calculates nodes lying on cylindrical surface.
99 //! @param theNewVertices list of vertices to be extended and added to mesh.
848fa7e3 100 void insertInternalVerticesCylinder(BRepMesh::ListOfVertex& theNewVertices);
ceb418e1 101
102 //! Calculates nodes lying on conical surface.
103 //! @param theNewVertices list of vertices to be extended and added to mesh.
848fa7e3 104 void insertInternalVerticesCone(BRepMesh::ListOfVertex& theNewVertices);
ceb418e1 105
106 //! Calculates nodes lying on toroidal surface.
107 //! @param theNewVertices list of vertices to be extended and added to mesh.
848fa7e3 108 void insertInternalVerticesTorus(BRepMesh::ListOfVertex& theNewVertices);
ceb418e1 109
110 //! Calculates nodes lying on Bezier/BSpline surface.
111 //! @param theNewVertices list of vertices to be extended and added to mesh.
848fa7e3 112 void insertInternalVerticesBSpline(BRepMesh::ListOfVertex& theNewVertices);
ceb418e1 113
114 //! Calculates nodes lying on custom-type surface.
115 //! @param theNewVertices list of vertices to be extended and added to mesh.
848fa7e3 116 void insertInternalVerticesOther(BRepMesh::ListOfVertex& theNewVertices);
fc9b36d6 117
ceb418e1 118 //! Template method trying to insert new internal vertex corresponded to
119 //! the given 2d point. Calculates 3d position analytically using the given
120 //! surface.
121 //! @param thePnt2d 2d point to be inserted to the list.
122 //! @param theAnalyticSurface analytic surface to calculate 3d point.
123 //! @param[out] theVertices list of vertices to be updated.
124 template<class AnalyticSurface>
848fa7e3 125 void tryToInsertAnalyticVertex(const gp_Pnt2d& thePnt2d,
126 const AnalyticSurface& theAnalyticSurface,
127 BRepMesh::ListOfVertex& theVertices)
ceb418e1 128 {
2caff0b3 129 const BRepMesh::HClassifier& aClassifier = myAttribute->ChangeClassifier();
130 if (aClassifier->Perform(thePnt2d) != TopAbs_IN)
ceb418e1 131 return;
132
133 gp_Pnt aPnt;
134 ElSLib::D0(thePnt2d.X(), thePnt2d.Y(), theAnalyticSurface, aPnt);
135 insertVertex(aPnt, thePnt2d.Coord(), theVertices);
136 }
137
138 //! Creates new vertex with the given parameters.
139 //! @param thePnt3d 3d point corresponded to the vertex.
140 //! @param theUV UV point corresponded to the vertex.
141 //! @param[out] theVertices list of vertices to be updated.
848fa7e3 142 void insertVertex(const gp_Pnt& thePnt3d,
143 const gp_XY& theUV,
144 BRepMesh::ListOfVertex& theVertices);
fc9b36d6 145
fcf15f5c 146 //! Stores mesh into the face (without internal edges).
147 void commitSurfaceTriangulation();
148
2caff0b3 149 //! Performs initialization of data structure using existing data.
150 void initDataStructure();
151
152 //! Adds new link to the mesh data structure.
153 //! Movability of the link and order of nodes depend on orientation parameter.
154 void addLinkToMesh(const Standard_Integer theFirstNodeId,
155 const Standard_Integer theLastNodeId,
156 const TopAbs_Orientation theOrientation);
157
74da0216 158 //! Inserts new node into a mesh in case if smoothed region build
159 //! using the given node has better deflection metrics than source state.
160 //! @param thePnt3d 3d point corresponded to the vertex.
161 //! @param theUV UV point corresponded to the vertex.
162 //! @param isDeflectionCheckOnly if TRUE new node will not be added to a mesh
163 //! even if deflection parameter is better.
164 //! @param theTriangleDeflection deflection of a triangle from real geometry.
165 //! @param theFaceDeflection deflection to be achieved.
166 //! @param theCircleTool tool used for fast extraction of triangles
167 //! touched by the given point.
168 //! @param[out] theVertices list of vertices to be updated.
169 //! @param[in out] theMaxTriangleDeflection maximal deflection of a mesh.
170 //! @return TRUE in case if the given deflection of triangle is fine and
171 //! there is no necessity to insert new node or new node was being inserted
172 //! successfully, FALSE in case if new configuration is better but
173 //! isDeflectionCheckOnly flag is set.
174 Standard_Boolean checkDeflectionAndInsert(
175 const gp_Pnt& thePnt3d,
176 const gp_XY& theUV,
177 const Standard_Boolean isDeflectionCheckOnly,
178 const Standard_Real theTriangleDeflection,
179 const Standard_Real theFaceDeflection,
180 const BRepMesh_CircleTool& theCircleTool,
181 BRepMesh::ListOfVertex& theVertices,
182 Standard_Real& theMaxTriangleDeflection);
183
fc9b36d6 184private:
ceb418e1 185
848fa7e3 186 Standard_Real myAngle;
848fa7e3 187 Standard_Boolean myInternalVerticesMode;
188 BRepMesh::IMapOfReal myUParam;
189 BRepMesh::IMapOfReal myVParam;
ceb418e1 190
191 // Fast access to attributes of current face
848fa7e3 192 Handle(BRepMesh_FaceAttribute) myAttribute;
193 Handle(BRepMesh_DataStructureOfDelaun) myStructure;
74da0216 194
195 Standard_Real myMinSize;
f43eff9f 196 Standard_Boolean myIsControlSurfaceDeflection;
fc9b36d6 197};
198
199DEFINE_STANDARD_HANDLE (BRepMesh_FastDiscretFace, Standard_Transient)
200
201#endif