Salome HOME
cherry-pick between a669 and 19a96 of V7_main
[tools/medcoupling.git] / src / INTERP_KERNEL / MeshUtils.hxx
index 1b4b404d8f25eea8debd0788037b6557b7d76fc4..61d2e9cfda2ce240100ac0a7db881826e1e38f8e 100644 (file)
@@ -1,21 +1,22 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2013  CEA/DEN, EDF R&D
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #ifndef __MESHUTILS_HXX__
 #define __MESHUTILS_HXX__
 
@@ -29,7 +30,7 @@ namespace INTERP_KERNEL
    * @param      node       the node for which the global number is sought (ALWAYS in C mode)
    * @param      element    an element of the mesh (in numPol policy)
    * @param      mesh       a mesh
-   * @return    the node's global number so that (its coordinates in the coordinates array are at [SPACEDIM*globalNumber, SPACEDIM*globalNumber + 2]
+   * @return    the node's global number so that (its coordinates in the coordinates array are at [SPACEDIM*globalNumber, SPACEDIM*globalNumber + SPACEDIM]
    */
   template<class MyMeshType>
   inline typename MyMeshType::MyConnType getGlobalNumberOfNode(typename MyMeshType::MyConnType node, typename MyMeshType::MyConnType element, const MyMeshType& mesh)
@@ -37,7 +38,20 @@ namespace INTERP_KERNEL
     typedef typename MyMeshType::MyConnType ConnType;
     const NumberingPolicy numPol=MyMeshType::My_numPol;
     const ConnType elemIdx=OTT<ConnType,numPol>::conn2C(mesh.getConnectivityIndexPtr()[OTT<ConnType,numPol>::ind2C(element)]);
-    return OTT<ConnType,numPol>::coo2C(mesh.getConnectivityPtr()[elemIdx + node]);
+    if(mesh.getTypeOfElement(element)!=INTERP_KERNEL::NORM_POLYHED)
+      return OTT<ConnType,numPol>::coo2C(mesh.getConnectivityPtr()[elemIdx + node]);
+    else
+      {
+        const ConnType *startNodalConnOfElem=mesh.getConnectivityPtr()+elemIdx;
+        ConnType ptr=0,ret=0;
+        while(startNodalConnOfElem[ret]==-1 || ptr!=node)
+          {
+            ret++;
+            if(startNodalConnOfElem[ret]!=-1)
+              ptr++;
+          }
+        return OTT<ConnType,numPol>::coo2C(startNodalConnOfElem[ret]);
+      }
   }
 
   /**
@@ -53,7 +67,8 @@ namespace INTERP_KERNEL
   {
     typedef typename MyMeshType::MyConnType ConnType;
     const ConnType connIdx = getGlobalNumberOfNode(node, element, mesh);
-    return mesh.getCoordinatesPtr()+MyMeshType::MY_SPACEDIM*connIdx;
+    const double *ret=mesh.getCoordinatesPtr()+MyMeshType::MY_SPACEDIM*connIdx;
+    return ret;
   }
 
   /**
@@ -88,7 +103,6 @@ namespace INTERP_KERNEL
                                         double*                         barycentricCoords)
   {
     std::vector<const double*> nodes( NB_NODES );
-    typedef typename MyMeshType::MyConnType ConnType;
     for ( int node = 0; node < NB_NODES; ++node )
       {
         nodes[ node ] = getCoordsOfNode( node, element, mesh );