Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / MEDMEM / MEDNormalizedUnstructuredMesh.txx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
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 __MEDNORMALIZEDUNSTRUCTUREDMESH_TXX__
20 #define __MEDNORMALIZEDUNSTRUCTUREDMESH_TXX__
21
22 #include "MEDNormalizedUnstructuredMesh.hxx"
23 #include "InterpKernelException.hxx"
24
25 #include "MEDMEM_Mesh.hxx"
26
27 template<int SPACEDIM,int MESHDIM>
28 MEDNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::MEDNormalizedUnstructuredMesh(const MEDMEM::MESH *mesh):_meshInMedMode(mesh),
29                                                                                                          _conn_for_interp(0),
30                                                                                                          _own_conn_for_interp(false),
31                                                                                                          _conn_index_for_interp(0),
32                                                                                                          _own_conn_index_for_interp(false)
33 {
34   prepare();
35 }
36
37 template<int SPACEDIM,int MESHDIM>
38 MEDNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::~MEDNormalizedUnstructuredMesh()
39 {
40   releaseTempArrays();
41 }
42
43 template<int SPACEDIM,int MESHDIM>
44 void MEDNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getBoundingBox(double *boundingBox) const
45 {
46   vector< vector<double> > ret=_meshInMedMode->getBoundingBox();
47   //low left corner
48   int i;
49   for(i=0;i<SPACEDIM;i++)
50     boundingBox[i]=ret[0][i];
51   for(i=0;i<SPACEDIM;i++)
52     boundingBox[i+SPACEDIM]=ret[1][i];
53 }
54
55 template<int SPACEDIM,int MESHDIM>
56 INTERP_KERNEL::NormalizedCellType MEDNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getTypeOfElement(int eltId) const
57 {
58   MED_EN::medGeometryElement type=_meshInMedMode->getElementType(MED_EN::MED_CELL,eltId);
59   if(type==MED_EN::MED_POLYGON)
60     return INTERP_KERNEL::NORM_POLYGON;
61   if(type==MED_EN::MED_POLYHEDRA)
62     return INTERP_KERNEL::NORM_POLYHED;
63   return (INTERP_KERNEL::NormalizedCellType)(((unsigned long)type/100-2)*10+((unsigned long)type%100));
64 }
65
66 template<int SPACEDIM,int MESHDIM>
67 unsigned char MEDNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodesOfElement(int eltId) const
68 {
69   if(_meshInMedMode->getElementType(MED_EN::MED_CELL,eltId)!=MED_EN::MED_POLYHEDRA)
70     return (unsigned char) (_conn_index_for_interp[eltId]-_conn_index_for_interp[eltId-1]);
71   else
72     {
73       return (unsigned char)(_conn_index_for_interp[eltId]-_conn_index_for_interp[eltId-1])-
74         std::count(_conn_for_interp+_conn_index_for_interp[eltId-1]-1,_conn_for_interp+_conn_index_for_interp[eltId]-1,-1);
75     }
76 }
77
78 template<int SPACEDIM,int MESHDIM>
79 unsigned long MEDNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfElements() const
80 {
81   return _meshInMedMode->getNumberOfElements(MED_EN::MED_CELL, MED_EN::MED_ALL_ELEMENTS);
82 }
83
84 template<int SPACEDIM,int MESHDIM>
85 unsigned long MEDNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodes() const
86 {
87   return _meshInMedMode->getNumberOfNodes();
88 }
89
90 template<int SPACEDIM,int MESHDIM>
91 const int *MEDNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityPtr() const
92 {
93   return _conn_for_interp;
94 }
95
96 template<int SPACEDIM,int MESHDIM>
97 const double *MEDNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getCoordinatesPtr() const
98 {
99   return _meshInMedMode->getCoordinates(MED_EN::MED_FULL_INTERLACE);
100 }
101
102 template<int SPACEDIM,int MESHDIM>
103 const int *MEDNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityIndexPtr() const
104 {
105   return _conn_index_for_interp;
106 }
107
108 template<int SPACEDIM,int MESHDIM>
109 void MEDNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::releaseTempArrays()
110 {
111   if(_own_conn_for_interp)
112     delete [] _conn_for_interp;
113   if(_own_conn_index_for_interp)
114     delete [] _conn_index_for_interp;
115   _conn_for_interp=0;
116   _conn_index_for_interp=0;
117   _own_conn_for_interp=false;
118   _own_conn_index_for_interp=false;
119 }
120
121 template<int SPACEDIM,int MESHDIM>
122 void MEDNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::prepare()
123 {
124   releaseTempArrays();
125   _conn_for_interp=(int *)_meshInMedMode->getConnectivity(MED_EN::MED_NODAL,MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS);
126   _own_conn_for_interp=false;
127   _conn_index_for_interp=(int *)_meshInMedMode->getConnectivityIndex(MED_EN::MED_NODAL, MED_EN::MED_CELL);
128   _own_conn_index_for_interp=false;
129 }
130
131 #endif