Salome HOME
Merge from BR_imps_2013 14/01/2014
[modules/smesh.git] / src / SMESHUtils / SMESH_MeshAlgos.hxx
1 // Copyright (C) 2007-2013  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.
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_MeshAlgos.hxx
23 // Created   : Tue Apr 30 18:00:36 2013
24 // Author    : Edward AGAPOV (eap)
25
26 // This file holds some low level algorithms extracted from SMESH_MeshEditor
27 // to make them accessible from Controls package
28
29
30 #ifndef __SMESH_MeshAlgos_HXX__
31 #define __SMESH_MeshAlgos_HXX__
32
33 #include "SMESH_Utils.hxx"
34
35 #include "SMDSAbs_ElementType.hxx"
36 #include "SMDS_ElemIterator.hxx"
37 #include "SMESH_TypeDefs.hxx"
38
39 #include <TopAbs_State.hxx>
40 #include <vector>
41
42 class gp_Pnt;
43 class gp_Ax1;
44 class SMDS_MeshNode;
45 class SMDS_MeshElement;
46 class SMDS_Mesh;
47
48 //=======================================================================
49 /*!
50  * \brief Searcher for the node closest to a point
51  */
52 //=======================================================================
53
54 struct SMESHUtils_EXPORT SMESH_NodeSearcher
55 {
56   virtual const SMDS_MeshNode* FindClosestTo( const gp_Pnt& pnt ) = 0;
57   virtual void MoveNode( const SMDS_MeshNode* node, const gp_Pnt& toPnt ) = 0;
58 };
59
60 //=======================================================================
61 /*!
62  * \brief Searcher for elements
63  */
64 //=======================================================================
65
66 struct SMESHUtils_EXPORT SMESH_ElementSearcher
67 {
68   /*!
69    * \brief Find elements of given type where the given point is IN or ON.
70    *        Returns nb of found elements and elements them-selves.
71    *
72    * 'ALL' type means elements of any type excluding nodes and 0D elements
73    */
74   virtual int FindElementsByPoint(const gp_Pnt&                           point,
75                                   SMDSAbs_ElementType                     type,
76                                   std::vector< const SMDS_MeshElement* >& foundElems) = 0;
77   /*!
78    * \brief Return an element most close to the given point
79    */
80   virtual const SMDS_MeshElement* FindClosestTo( const gp_Pnt&       point,
81                                                  SMDSAbs_ElementType type) = 0;
82   /*!
83    * \brief Return elements possibly intersecting the line
84    */
85   virtual void GetElementsNearLine( const gp_Ax1&                           line,
86                                     SMDSAbs_ElementType                     type,
87                                     std::vector< const SMDS_MeshElement* >& foundElems) = 0;
88   /*!
89    * \brief Find out if the given point is out of closed 2D mesh.
90    */
91   virtual TopAbs_State GetPointState(const gp_Pnt& point) = 0;
92   virtual ~SMESH_ElementSearcher();
93 };
94
95 namespace SMESH_MeshAlgos
96 {
97   /*!
98    * \brief Return true if the point is IN or ON of the element
99    */
100   SMESHUtils_EXPORT
101   bool IsOut( const SMDS_MeshElement* element, const gp_Pnt& point, double tol );
102
103   SMESHUtils_EXPORT
104   double GetDistance( const SMDS_MeshFace* face, const gp_Pnt& point );
105
106   SMESHUtils_EXPORT
107   void GetBarycentricCoords( const gp_XY& point,
108                              const gp_XY& t0, const gp_XY& t1, const gp_XY& t2,
109                              double &    bc0, double &    bc1);
110
111   /*!
112    * Return a face having linked nodes n1 and n2 and which is
113    * - not in avoidSet,
114    * - in elemSet provided that !elemSet.empty()
115    * i1 and i2 optionally returns indices of n1 and n2
116    */
117   SMESHUtils_EXPORT
118   const SMDS_MeshElement* FindFaceInSet(const SMDS_MeshNode*    n1,
119                                         const SMDS_MeshNode*    n2,
120                                         const TIDSortedElemSet& elemSet,
121                                         const TIDSortedElemSet& avoidSet,
122                                         int*                    i1=0,
123                                         int*                    i2=0);
124   /*!
125    * \brief Calculate normal of a mesh face
126    */
127   SMESHUtils_EXPORT
128   bool FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized=true);
129
130   /*!
131    * \brief Return nodes common to two elements
132    */
133   SMESHUtils_EXPORT
134   std::vector< const SMDS_MeshNode*> GetCommonNodes(const SMDS_MeshElement* e1,
135                                                     const SMDS_MeshElement* e2);
136
137   /*!
138    * \brief Return SMESH_NodeSearcher. The caller is responsible for deleteing it
139    */
140   SMESHUtils_EXPORT
141   SMESH_NodeSearcher* GetNodeSearcher( SMDS_Mesh& mesh );
142
143   /*!
144    * \brief Return SMESH_ElementSearcher. The caller is responsible for deleting it
145    */
146   SMESHUtils_EXPORT
147   SMESH_ElementSearcher* GetElementSearcher( SMDS_Mesh& mesh );
148   SMESHUtils_EXPORT
149   SMESH_ElementSearcher* GetElementSearcher( SMDS_Mesh& mesh,
150                                              SMDS_ElemIteratorPtr elemIt );
151 }
152
153 #endif