0025310: Regressions in visualization
[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.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   Standard_EXPORT BRepMesh_FastDiscretFace(
54     const Standard_Real    theAngle,
55     const Standard_Boolean theWithShare = Standard_True);
56
57   Standard_EXPORT void Add(const Handle(BRepMesh_FaceAttribute)& theAttribute);
58   Standard_EXPORT void Perform(const Handle(BRepMesh_FaceAttribute)& theAttribute);
59
60   DEFINE_STANDARD_RTTI(BRepMesh_FastDiscretFace)
61
62 private:
63
64   void add(const TopoDS_Vertex& theVertex);
65
66   Standard_Real control(BRepMesh::ListOfVertex&  theNewVertices,
67                         BRepMesh_Delaun&         theMeshBuilder,
68                         const Standard_Boolean   theIsFirst);
69
70   //! Registers the given nodes in mesh data structure and
71   //! performs refinement of existing mesh.
72   //! @param theVertices nodes to be inserted.
73   //! @param theMeshBuilder initialized tool refining mesh 
74   //! in respect to inserting nodes.
75   //! @return TRUE if vertices were been inserted, FALSE elewhere.
76   Standard_Boolean addVerticesToMesh(
77     const BRepMesh::ListOfVertex& theVertices,
78     BRepMesh_Delaun&              theMeshBuilder);
79
80   //! Calculates nodes lying on face's surface and inserts them to a mesh.
81   //! @param theNewVertices list of vertices to be extended and added to mesh.
82   //! @param theMeshBuilder initialized tool refining mesh 
83   //! in respect to inserting nodes.
84   void insertInternalVertices(BRepMesh::ListOfVertex&  theNewVertices,
85                               BRepMesh_Delaun&         theMeshBuilder);
86
87   //! Calculates nodes lying on spherical surface.
88   //! @param theNewVertices list of vertices to be extended and added to mesh.
89   void insertInternalVerticesSphere(BRepMesh::ListOfVertex& theNewVertices);
90
91   //! Calculates nodes lying on cylindrical surface.
92   //! @param theNewVertices list of vertices to be extended and added to mesh.
93   void insertInternalVerticesCylinder(BRepMesh::ListOfVertex& theNewVertices);
94
95   //! Calculates nodes lying on conical surface.
96   //! @param theNewVertices list of vertices to be extended and added to mesh.
97   void insertInternalVerticesCone(BRepMesh::ListOfVertex& theNewVertices);
98
99   //! Calculates nodes lying on toroidal surface.
100   //! @param theNewVertices list of vertices to be extended and added to mesh.
101   void insertInternalVerticesTorus(BRepMesh::ListOfVertex& theNewVertices);
102
103   //! Calculates nodes lying on Bezier/BSpline surface.
104   //! @param theNewVertices list of vertices to be extended and added to mesh.
105   void insertInternalVerticesBSpline(BRepMesh::ListOfVertex& theNewVertices);
106
107   //! Calculates nodes lying on custom-type surface.
108   //! @param theNewVertices list of vertices to be extended and added to mesh.
109   void insertInternalVerticesOther(BRepMesh::ListOfVertex& theNewVertices);
110   
111   //! Template method trying to insert new internal vertex corresponded to
112   //! the given 2d point. Calculates 3d position analytically using the given
113   //! surface.
114   //! @param thePnt2d 2d point to be inserted to the list.
115   //! @param theAnalyticSurface analytic surface to calculate 3d point.
116   //! @param[out] theVertices list of vertices to be updated.
117   template<class AnalyticSurface>
118   void tryToInsertAnalyticVertex(const gp_Pnt2d&         thePnt2d,
119                                  const AnalyticSurface&  theAnalyticSurface,
120                                  BRepMesh::ListOfVertex& theVertices)
121   {
122     if (!myClassifier->Perform(thePnt2d) == TopAbs_IN)
123       return;
124
125     gp_Pnt aPnt;
126     ElSLib::D0(thePnt2d.X(), thePnt2d.Y(), theAnalyticSurface, aPnt);
127     insertVertex(aPnt, thePnt2d.Coord(), theVertices);
128   }
129
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,
135                     const gp_XY&            theUV,
136                     BRepMesh::ListOfVertex& theVertices);
137
138   //! Stores mesh into the face (without internal edges).
139   void commitSurfaceTriangulation();
140
141 private:
142
143   Standard_Real                          myAngle;
144   Standard_Boolean                       myWithShare;
145   Standard_Boolean                       myInternalVerticesMode;
146   BRepMesh::IMapOfReal                   myUParam;
147   BRepMesh::IMapOfReal                   myVParam;
148   Handle(NCollection_IncAllocator)       myAllocator;
149
150   // Fast access to attributes of current face
151   Handle(BRepMesh_FaceAttribute)         myAttribute;
152   Handle(BRepMesh_DataStructureOfDelaun) myStructure;
153   BRepMesh::HIMapOfInteger               myVertexEdgeMap;
154   BRepMesh::HClassifier                  myClassifier;
155   BRepMesh::HDMapOfIntegerPnt            mySurfacePoints;
156 };
157
158 DEFINE_STANDARD_HANDLE (BRepMesh_FastDiscretFace, Standard_Transient)
159
160 #endif