Salome HOME
8d04f506af62d5fcc9c9b2be9c2921b343124fc6
[modules/smesh.git] / src / SMESHUtils / SMESH_Delaunay.hxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File      : SMESH_Delaunay.hxx
23 // Created   : Wed Apr 19 15:42:54 2017
24 // Author    : Edward AGAPOV (eap)
25
26
27 #ifndef __SMESH_Delaunay_HXX__
28 #define __SMESH_Delaunay_HXX__
29
30 #include "SMESH_TypeDefs.hxx"
31
32 #include <BRepMesh_DataStructureOfDelaun.hxx>
33
34 /*!
35  * \brief Create a Delaunay triangulation of nodes on a face boundary
36  *        and provide exploration of nodes shared by elements lying on
37  *        the face. For a returned node, also return a Delaunay triangle
38  *        the node lies in and its Barycentric Coordinates within the triangle.
39  *        Only non-marked nodes are visited. Boundary nodes given at the construction
40  *        are not returned.
41  *
42  *        For usage, this class needs to be subclassed to implement getNodeUV();
43  */
44 class SMESHUtils_EXPORT SMESH_Delaunay
45 {
46  public:
47
48   // construct a Delaunay triangulation of given boundary nodes
49   SMESH_Delaunay(const std::vector< const UVPtStructVec* > & boundaryNodes,
50                  const TopoDS_Face&                          face,
51                  const int                                   faceID);
52
53   virtual ~SMESH_Delaunay() {}
54
55   // prepare to the exploration of nodes
56   void InitTraversal(const int nbNodesToVisit = -1);
57
58   // return a node with its Barycentric Coordinates within the triangle
59   // defined by its node indices (zero based)
60   const SMDS_MeshNode* NextNode( double bc[3], int triaNodes[3] );
61
62   // return nb of nodes returned by NextNode()
63   int NbVisitedNodes() const { return _nbVisitedNodes; }
64
65
66   // find a triangle containing an UV, starting from a given triangle;
67   // return barycentric coordinates of the UV and the found triangle (indices are zero based).
68   const BRepMesh_Triangle* FindTriangle( const gp_XY&             uv,
69                                          const BRepMesh_Triangle* bmTria,
70                                          double                   bc[3],
71                                          int                      triaNodes[3]);
72
73   // return any Delaunay triangle neighboring a given boundary node (zero based)
74   const BRepMesh_Triangle* GetTriangleNear( int iBndNode );
75
76   // return source boundary nodes
77   const std::vector< const SMDS_MeshNode* >& GetBndNodes() const { return _bndNodes; }
78
79   // return UV of the i-th source boundary node (zero based)
80   gp_XY GetBndUV(const int iNode) const;
81
82   // return scale factor to convert real UV to/from UV used for Delauney meshing:
83   // delauney_UV = real_UV * scale
84   const gp_XY& GetScale() const { return _scale; }
85
86
87  protected:
88
89   // container of a node and a triangle serving as a start while searching a
90   // triangle including the node UV
91   typedef std::list< std::pair< const SMDS_MeshNode*, const BRepMesh_Triangle* > > TNodeTriaList;
92
93   // return UV of a node on the face
94   virtual gp_XY getNodeUV( const TopoDS_Face& face, const SMDS_MeshNode* node ) const = 0;
95
96   // add non-marked nodes surrounding a given one to a queue
97   static void addCloseNodes( const SMDS_MeshNode*     node,
98                              const BRepMesh_Triangle* bmTria,
99                              const int                faceID,
100                              TNodeTriaList &          noTriQueue );
101
102   const TopoDS_Face&                     _face;
103   int                                    _faceID;
104   std::vector< const SMDS_MeshNode* >    _bndNodes;
105   gp_XY                                  _scale;
106   Handle(BRepMesh_DataStructureOfDelaun) _triaDS;
107   size_t                                 _nbNodesToVisit, _nbVisitedNodes, _iBndNode;
108   TNodeTriaList                          _noTriQueue;
109
110 };
111
112 #endif