74fdc90340b7a77ec45f0b3596c3d80004cd4359
[occt.git] / src / BRepMesh / BRepMesh_FastDiscretFace.hxx
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>
21 #include <BRepMesh_Collections.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>
30 #include <ElSLib.hxx>
31
32 class BRepMesh_DataStructureOfDelaun;
33 class BRepMesh_FaceAttribute;
34 class TopoDS_Face;
35 class TopTools_DataMapOfShapeReal;
36 class TopoDS_Vertex;
37 class BRepAdaptor_HSurface;
38 class TopoDS_Edge;
39 class Poly_Triangulation;
40 class TopLoc_Location;
41 class gp_XY;
42 class gp_Pnt2d;
43 class BRepMesh_Edge;
44 class BRepMesh_Vertex;
45 class gp_Pnt;
46
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 
50 {
51 public:
52
53
54   Standard_EXPORT BRepMesh_FastDiscretFace(const Standard_Real theAngle,
55                                            const Standard_Boolean theWithShare = Standard_True);
56
57   Standard_EXPORT void Add(const Handle(BRepMesh_FaceAttribute)& theAttribute);
58
59   //! Gives the triangle of <Index>. <br>
60   Standard_EXPORT const BRepMesh_Triangle& Triangle(const Standard_Integer theIndex) const;
61
62   DEFINE_STANDARD_RTTI(BRepMesh_FastDiscretFace)
63
64 private:
65
66   void add(const TopoDS_Vertex& theVertex);
67
68   Standard_Real control(BRepMeshCol::ListOfVertex&  theNewVertices,
69                         BRepMesh_Delaun&            theMeshBuilder,
70                         const Standard_Boolean      theIsFirst);
71
72   //! Registers the given nodes in mesh data structure and
73   //! performs refinement of existing mesh.
74   //! @param theVertices nodes to be inserted.
75   //! @param theMeshBuilder initialized tool refining mesh 
76   //! in respect to inserting nodes.
77   //! @return TRUE if vertices were been inserted, FALSE elewhere.
78   Standard_Boolean addVerticesToMesh(
79     const BRepMeshCol::ListOfVertex& theVertices,
80     BRepMesh_Delaun&                 theMeshBuilder);
81
82   //! Calculates nodes lying on face's surface and inserts them to a mesh.
83   //! @param theNewVertices list of vertices to be extended and added to mesh.
84   //! @param theMeshBuilder initialized tool refining mesh 
85   //! in respect to inserting nodes.
86   void insertInternalVertices(BRepMeshCol::ListOfVertex&  theNewVertices,
87                               BRepMesh_Delaun&            theMeshBuilder);
88
89   //! Calculates nodes lying on spherical surface.
90   //! @param theNewVertices list of vertices to be extended and added to mesh.
91   void insertInternalVerticesSphere(BRepMeshCol::ListOfVertex& theNewVertices);
92
93   //! Calculates nodes lying on cylindrical surface.
94   //! @param theNewVertices list of vertices to be extended and added to mesh.
95   void insertInternalVerticesCylinder(BRepMeshCol::ListOfVertex& theNewVertices);
96
97   //! Calculates nodes lying on conical surface.
98   //! @param theNewVertices list of vertices to be extended and added to mesh.
99   void insertInternalVerticesCone(BRepMeshCol::ListOfVertex& theNewVertices);
100
101   //! Calculates nodes lying on toroidal surface.
102   //! @param theNewVertices list of vertices to be extended and added to mesh.
103   void insertInternalVerticesTorus(BRepMeshCol::ListOfVertex& theNewVertices);
104
105   //! Calculates nodes lying on Bezier/BSpline surface.
106   //! @param theNewVertices list of vertices to be extended and added to mesh.
107   void insertInternalVerticesBSpline(BRepMeshCol::ListOfVertex& theNewVertices);
108
109   //! Calculates nodes lying on custom-type surface.
110   //! @param theNewVertices list of vertices to be extended and added to mesh.
111   void insertInternalVerticesOther(BRepMeshCol::ListOfVertex& theNewVertices);
112   
113   //! Template method trying to insert new internal vertex corresponded to
114   //! the given 2d point. Calculates 3d position analytically using the given
115   //! surface.
116   //! @param thePnt2d 2d point to be inserted to the list.
117   //! @param theAnalyticSurface analytic surface to calculate 3d point.
118   //! @param[out] theVertices list of vertices to be updated.
119   template<class AnalyticSurface>
120   void tryToInsertAnalyticVertex(const gp_Pnt2d&            thePnt2d,
121                                  const AnalyticSurface&     theAnalyticSurface,
122                                  BRepMeshCol::ListOfVertex& theVertices)
123   {
124     if (!myClassifier->Perform(thePnt2d) == TopAbs_IN)
125       return;
126
127     gp_Pnt aPnt;
128     ElSLib::D0(thePnt2d.X(), thePnt2d.Y(), theAnalyticSurface, aPnt);
129     insertVertex(aPnt, thePnt2d.Coord(), theVertices);
130   }
131
132   //! Creates new vertex with the given parameters.
133   //! @param thePnt3d 3d point corresponded to the vertex.
134   //! @param theUV UV point corresponded to the vertex.
135   //! @param[out] theVertices list of vertices to be updated.
136   void insertVertex(const gp_Pnt&              thePnt3d,
137                     const gp_XY&               theUV,
138                     BRepMeshCol::ListOfVertex& theVertices);
139
140 private:
141
142   Standard_Real                             myAngle;
143   Standard_Boolean                          myWithShare;
144   Standard_Boolean                          myInternalVerticesMode;
145   BRepMeshCol::IMapOfReal                   myUParam;
146   BRepMeshCol::IMapOfReal                   myVParam;
147   BRepMeshCol::Allocator                    myAllocator;
148
149   // Fast access to attributes of current face
150   Handle(BRepMesh_FaceAttribute)            myAttribute;
151   Handle(BRepMesh_DataStructureOfDelaun)    myStructure;
152   BRepMeshCol::HIMapOfInteger               myVertexEdgeMap;
153   BRepMeshCol::HClassifier                  myClassifier;
154   BRepMeshCol::HDMapOfIntegerPnt            mySurfacePoints;
155 };
156
157 DEFINE_STANDARD_HANDLE (BRepMesh_FastDiscretFace, Standard_Transient)
158
159 #endif