Salome HOME
MEDReader : End of debugging session.
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingNormalizedUnstructuredMesh.txx
1 // Copyright (C) 2007-2013  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 // Author : Anthony Geay (CEA/DEN)
20 #ifndef __MEDCOUPLINGNORMALIZEDUNSTRUCTUREDMESH_TXX__
21 #define __MEDCOUPLINGNORMALIZEDUNSTRUCTUREDMESH_TXX__
22
23 #include "MEDCouplingNormalizedUnstructuredMesh.hxx"
24
25 #include "MEDCouplingUMesh.hxx"
26 #include "MEDCouplingMemArray.hxx"
27
28 #include <limits>
29
30 template<int SPACEDIM,int MESHDIM>
31 MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::MEDCouplingNormalizedUnstructuredMesh(const ParaMEDMEM::MEDCouplingUMesh *mesh):_mesh(mesh)
32 {
33   if(_mesh)
34     _mesh->incrRef();
35   prepare();
36 }
37
38 template<int SPACEDIM,int MESHDIM>
39 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getBoundingBox(double *boundingBox) const
40 {
41   for(int i=0;i<SPACEDIM;i++)
42     {
43       boundingBox[i]=std::numeric_limits<double>::max();
44       boundingBox[SPACEDIM+i]=-std::numeric_limits<double>::max();
45     }
46   const ParaMEDMEM::DataArrayDouble *array=_mesh->getCoords();
47   const double *ptr=array->getConstPointer();
48   int nbOfPts=array->getNbOfElems()/SPACEDIM;
49   for(int j=0;j<SPACEDIM;j++)
50     {
51       const double *work=ptr+j;
52       for(int i=0;i<nbOfPts;i++,work+=SPACEDIM)
53         {
54           if(boundingBox[j]>*work)
55             boundingBox[j]=*work;
56           if(boundingBox[j+SPACEDIM]<*work)
57             boundingBox[j+SPACEDIM]=*work;
58         }
59     }
60 }
61
62 template<int SPACEDIM,int MESHDIM>
63 INTERP_KERNEL::NormalizedCellType MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getTypeOfElement(int eltId) const
64 {
65   return _mesh->getTypeOfCell(eltId);
66 }
67
68 template<int SPACEDIM,int MESHDIM>
69 unsigned char MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodesOfElement(int eltId) const
70 {
71   return _mesh->getNumberOfNodesInCell(eltId);
72 }
73
74 template<int SPACEDIM,int MESHDIM>
75 unsigned long MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfElements() const
76 {
77   return _mesh->getNumberOfCells();
78 }
79
80 template<int SPACEDIM,int MESHDIM>
81 unsigned long MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodes() const
82 {
83   return _mesh->getNumberOfNodes();
84 }
85
86 template<int SPACEDIM,int MESHDIM>
87 const int *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityPtr() const
88 {
89   return _conn_for_interp;
90 }
91
92 template<int SPACEDIM,int MESHDIM>
93 const double *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getCoordinatesPtr() const
94 {
95   const ParaMEDMEM::DataArrayDouble *array=_mesh->getCoords();
96   return array->getConstPointer();
97 }
98
99 template<int SPACEDIM,int MESHDIM>
100 const int *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityIndexPtr() const
101 {
102   return _conn_index_for_interp;
103 }
104
105 template<int SPACEDIM,int MESHDIM>
106 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::releaseTempArrays()
107 {
108   delete [] _conn_for_interp;
109   delete [] _conn_index_for_interp;
110   _conn_for_interp=0;
111   _conn_index_for_interp=0;
112 }
113
114 template<int SPACEDIM,int MESHDIM>
115 MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::~MEDCouplingNormalizedUnstructuredMesh()
116 {
117   if(_mesh)
118     _mesh->decrRef();
119   releaseTempArrays();
120 }
121
122 template<int SPACEDIM,int MESHDIM>
123 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::prepare()
124 {
125   int nbOfCell=_mesh->getNumberOfCells();
126   int initialConnSize=_mesh->getNodalConnectivity()->getNbOfElems();
127   _conn_for_interp=new int[initialConnSize-nbOfCell];
128   _conn_index_for_interp=new int[nbOfCell+1];
129   _conn_index_for_interp[0]=0;
130   const int *work_conn=_mesh->getNodalConnectivity()->getConstPointer()+1;
131   const int *work_conn_index=_mesh->getNodalConnectivityIndex()->getConstPointer();
132   int *work_conn_for_interp=_conn_for_interp;
133   int *work_conn_index_for_interp=_conn_index_for_interp;
134   for(int i=0;i<nbOfCell;i++)
135     {
136       int nbOfValsToCopy=work_conn_index[1]-work_conn_index[0]-1;
137       work_conn_for_interp=std::copy(work_conn,work_conn+nbOfValsToCopy,work_conn_for_interp);
138       work_conn_index_for_interp[1]=work_conn_index_for_interp[0]+nbOfValsToCopy;
139       work_conn_index++;
140       work_conn+=nbOfValsToCopy+1;
141       work_conn_index_for_interp++;
142     }
143 }
144
145 #endif