0026106: BRepMesh - revision of data model
[occt.git] / src / BRepMesh / BRepMesh_BaseMeshAlgo.hxx
1 // Created on: 2016-07-07
2 // Copyright (c) 2016 OPEN CASCADE SAS
3 // Created by: Oleg AGASHIN
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _BRepMesh_BaseMeshAlgo_HeaderFile
17 #define _BRepMesh_BaseMeshAlgo_HeaderFile
18
19 #include <IMeshTools_MeshAlgo.hxx>
20 #include <NCollection_Shared.hxx>
21 #include <IMeshTools_Parameters.hxx>
22 #include <BRepMesh_DegreeOfFreedom.hxx>
23 #include <Poly_Triangulation.hxx>
24
25 class BRepMesh_DataStructureOfDelaun;
26 class BRepMesh_Delaun;
27
28 //! Class provides base fuctionality for algorithms building face triangulation.
29 //! Performs initialization of BRepMesh_DataStructureOfDelaun and nodes map structures.
30 class BRepMesh_BaseMeshAlgo : public IMeshTools_MeshAlgo
31 {
32 public:
33
34   typedef NCollection_Shared<NCollection_Vector<gp_Pnt> > VectorOfPnt;
35
36   //! Constructor.
37   Standard_EXPORT BRepMesh_BaseMeshAlgo();
38
39   //! Destructor.
40   Standard_EXPORT virtual ~BRepMesh_BaseMeshAlgo();
41
42   //! Performs processing of the given face.
43   Standard_EXPORT virtual void Perform(
44     const IMeshData::IFaceHandle& theDFace,
45     const IMeshTools_Parameters&  theParameters) Standard_OVERRIDE;
46
47   DEFINE_STANDARD_RTTI_INLINE(BRepMesh_BaseMeshAlgo, IMeshTools_MeshAlgo)
48
49 protected:
50
51   //! Gets discrete face.
52   inline const IMeshData::IFaceHandle& getDFace() const
53   {
54     return myDFace;
55   }
56
57   //! Gets meshing parameters.
58   inline const IMeshTools_Parameters& getParameters() const
59   {
60     return myParameters;
61   }
62
63   //! Gets common allocator.
64   inline const Handle(NCollection_IncAllocator)& getAllocator() const
65   {
66     return myAllocator;
67   }
68
69   //! Gets mesh structure.
70   inline const Handle(BRepMesh_DataStructureOfDelaun)& getStructure() const
71   {
72     return myStructure;
73   }
74
75   //! Gets 3d nodes map.
76   inline const Handle(VectorOfPnt)& getNodesMap() const
77   {
78     return myNodesMap;
79   }
80
81 protected:
82
83   //! Registers the given point in vertex map and adds 2d point to mesh data structure.
84   //! Returns index of node in the structure.
85   Standard_EXPORT virtual Standard_Integer registerNode(
86     const gp_Pnt&                  thePoint,
87     const gp_Pnt2d&                thePoint2d,
88     const BRepMesh_DegreeOfFreedom theMovability,
89     const Standard_Boolean         isForceAdd);
90
91   //! Adds the given 2d point to mesh data structure.
92   //! Returns index of node in the structure.
93   Standard_EXPORT virtual Standard_Integer addNodeToStructure(
94     const gp_Pnt2d&                thePoint,
95     const Standard_Integer         theLocation3d,
96     const BRepMesh_DegreeOfFreedom theMovability,
97     const Standard_Boolean         isForceAdd);
98
99   //! Returns 2d point associated to the given vertex.
100   Standard_EXPORT virtual gp_Pnt2d getNodePoint2d(const BRepMesh_Vertex& theVertex) const;
101
102   //! Performs initialization of data structure using existing model data.
103   Standard_EXPORT virtual Standard_Boolean initDataStructure();
104
105   //! Generates mesh for the contour stored in data structure.
106   Standard_EXPORT virtual void generateMesh() = 0;
107
108 private:
109
110   //! If the given edge has another pcurve for current face coinsiding with specified one,
111   //! returns TopAbs_INTERNAL flag. Elsewhere returns orientation of specified pcurve.
112   TopAbs_Orientation fixSeamEdgeOrientation(
113     const IMeshData::IEdgeHandle&   theDEdge,
114     const IMeshData::IPCurveHandle& thePCurve) const;
115
116   //! Adds new link to the mesh data structure.
117   //! Movability of the link and order of nodes depend on orientation parameter.
118   Standard_Integer addLinkToMesh(
119     const Standard_Integer   theFirstNodeId,
120     const Standard_Integer   theLastNodeId,
121     const TopAbs_Orientation theOrientation);
122
123   //! Commits generated triangulation to TopoDS face.
124   void commitSurfaceTriangulation();
125
126   //! Collects triangles to output data.
127   Handle(Poly_Triangulation) collectTriangles();
128
129   //! Collects nodes to output data.
130   void collectNodes(const Handle(Poly_Triangulation)& theTriangulation);
131
132 private:
133   typedef NCollection_Shared<NCollection_DataMap<Standard_Integer, Standard_Integer> > DMapOfIntegerInteger;
134
135   IMeshData::IFaceHandle                 myDFace;
136   IMeshTools_Parameters                  myParameters;
137   Handle(NCollection_IncAllocator)       myAllocator;
138   Handle(BRepMesh_DataStructureOfDelaun) myStructure;
139   Handle(VectorOfPnt)                    myNodesMap;
140   Handle(DMapOfIntegerInteger)           myUsedNodes;
141 };
142
143 #endif