]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/INTERP_KERNEL/MeshUtils.hxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[tools/medcoupling.git] / src / INTERP_KERNEL / MeshUtils.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #ifndef __MESHUTILS_HXX__
20 #define __MESHUTILS_HXX__
21
22 #include "InterpolationUtils.hxx"
23
24 namespace INTERP_KERNEL
25 {
26   /**
27    * Returns the global number of the node of an element.
28    *
29    * @param      node       the node for which the global number is sought (ALWAYS in C mode)
30    * @param      element    an element of the mesh (in numPol policy)
31    * @param      mesh       a mesh
32    * @return    the node's global number so that (its coordinates in the coordinates array are at [SPACEDIM*globalNumber, SPACEDIM*globalNumber + 2]
33    */
34   template<class MyMeshType>
35   inline typename MyMeshType::MyConnType getGlobalNumberOfNode(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh)
36   {
37     typedef typename MyMeshType::MyConnType ConnType;
38     const NumberingPolicy numPol=MyMeshType::My_numPol;
39     const ConnType elemIdx=OTT<ConnType,numPol>::conn2C(mesh.getConnectivityIndexPtr()[OTT<ConnType,numPol>::ind2C(element)]);
40     return OTT<ConnType,numPol>::coo2C(mesh.getConnectivityPtr()[elemIdx + node]);
41   }
42
43   /**
44    * Returns the coordinates of a node of an element
45    *
46    * @param      node       the node for which the coordinates are sought. In C mode.
47    * @param      element    an element of the mesh. In mesh policy.
48    * @param      mesh       a mesh
49    * @return    pointer to an array of 3 doubles containing the coordinates of the node
50    */
51   template<class MyMeshType>
52   inline const double* getCoordsOfNode(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh)
53   {
54     typedef typename MyMeshType::MyConnType ConnType;
55     const ConnType connIdx = getGlobalNumberOfNode(node, element, mesh);
56     return mesh.getCoordinatesPtr()+MyMeshType::MY_SPACEDIM*connIdx;
57   }
58
59   /**
60    * Returns the coordinates of a node of an element
61    *
62    * @param      node       the node for which the coordinates are sought. In C mode.
63    * @param      element    an element of the mesh. In mesh policy.
64    * @param      mesh       a mesh
65    * @param      nodeId     globale nodeId in whole mesh point of view in C mode.
66    * @return    pointer to an array of 3 doubles containing the coordinates of the node
67    */
68   template<class MyMeshType>
69   inline const double* getCoordsOfNode2(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh, typename MyMeshType::MyConnType& nodeId)
70   {
71     typedef typename MyMeshType::MyConnType ConnType;
72     nodeId= getGlobalNumberOfNode(node, element, mesh);
73     return mesh.getCoordinatesPtr()+MyMeshType::MY_SPACEDIM*nodeId;
74   }
75
76   /**
77    * Returns the barycentric coordinates of a point within a triangle or tetrahedron
78    *
79    * @param      point       the point for which the barycentric coordinates are sought
80    * @param      element    an element of the mesh
81    * @param      mesh       a mesh
82    * @param     barycentricCoords an array of 3 doubles containing the coordinates of the node
83    */
84   template<class MyMeshType, int NB_NODES>
85   inline void getBarycentricCoordinates(const double*                   point,
86                                         typename MyMeshType::MyConnType element,
87                                         const MyMeshType&               mesh,
88                                         double*                         barycentricCoords)
89   {
90     std::vector<const double*> nodes( NB_NODES );
91     typedef typename MyMeshType::MyConnType ConnType;
92     for ( int node = 0; node < NB_NODES; ++node )
93       {
94         nodes[ node ] = getCoordsOfNode( node, element, mesh );
95       }
96     barycentric_coords( nodes, point, barycentricCoords );
97   }
98     
99 }
100
101 #endif