Salome HOME
Update copyright information
[modules/visu.git] / src / CONVERTOR / VISU_MedConvertor.hxx
1 // Copyright (C) 2007-2012  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
23 //  File   : VISU_MedConvertor.hxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26 //
27 #ifndef VISU_MedConvertor_HeaderFile
28 #define VISU_MedConvertor_HeaderFile
29
30 #include "VISUConvertor.hxx"
31 #include "VISU_Convertor_impl.hxx"
32 #include "VISU_Structures_impl.hxx"
33 #include "VISU_PointCoords.hxx"
34 #include "VISU_MeshValue.hxx"
35
36 #include "MED_Wrapper.hxx"
37 #include "MED_Common.hxx"
38 #include "MED_Structures.hxx"
39 #include "MED_GaussUtils.hxx"
40
41 #include <boost/thread/mutex.hpp>
42
43 namespace VISU
44 {
45   //---------------------------------------------------------------
46   struct VISU_CONVERTOR_EXPORT TMEDCoordHolder: TCoordHolder<MED::PNodeCoord>
47   {
48     virtual
49     const TCoord*
50     GetPointer() const
51     {
52       return &(*myCoord)[0];
53     }
54
55     virtual
56     TCoord*
57     GetPointer()
58     {
59       return &(*myCoord)[0];
60     }
61   };
62
63
64   //---------------------------------------------------------------
65   struct VISU_CONVERTOR_EXPORT TMEDGaussCoordHolder: TCoordHolderBase
66   {
67     MED::PGaussCoord myGaussCoord;
68
69     //! To initilize the instance
70     void
71     Init(const MED::PGaussCoord& theGaussCoord)
72     {
73       MED::TInt aNbGauss = theGaussCoord->GetNbGauss();
74       MED::TInt aNbElem = theGaussCoord->GetNbElem();
75       MED::TInt aDim = theGaussCoord->GetDim();
76       MED::TInt aNbCells = aNbElem * aNbGauss;
77       TCoordHolderBase::Init(aNbCells, aDim);
78       myGaussCoord = theGaussCoord;
79     }
80
81     //! Get slice of coordinates for defined node (const version)
82     virtual
83     TCCoordSlice
84     GetCoordSlice(vtkIdType theNodeId) const
85     {
86       MED::TInt anElemId = theNodeId / myGaussCoord->GetNbGauss();
87       MED::TCCoordSliceArr aCoordSliceArr = myGaussCoord->GetCoordSliceArr(anElemId);
88       MED::TInt aGaussId = theNodeId % myGaussCoord->GetNbGauss();
89       return aCoordSliceArr[aGaussId];
90     }
91
92     //! Get slice of coordinates for defined node
93     virtual
94     TCoordSlice 
95     GetCoordSlice(vtkIdType theNodeId)
96     {
97       MED::TInt anElemId = theNodeId / myGaussCoord->GetNbGauss();
98       MED::TCoordSliceArr aCoordSliceArr = myGaussCoord->GetCoordSliceArr(anElemId);
99       MED::TInt aGaussId = theNodeId % myGaussCoord->GetNbGauss();
100       return aCoordSliceArr[aGaussId];
101     }
102
103     virtual
104     unsigned char*
105     GetValuePtr()
106     {
107       return myGaussCoord->GetValuePtr();
108     }
109   };
110
111
112   //---------------------------------------------------------------
113   template<class TValueType>
114   struct VISU_CONVERTOR_EXPORT TTMEDMeshValue: TTMeshValueHolder<TValueType, 
115                                            MED::SharedPtr<MED::TTMeshValue<MED::TVector<TValueType> > > >
116   {
117     virtual
118     const TValueType*
119     GetPointer() const
120     {
121       return this->myContainer->GetPointer();
122     }
123
124     virtual
125     TValueType*
126     GetPointer()
127     {
128       return this->myContainer->GetPointer();
129     }
130   };
131
132
133   //---------------------------------------------------------------
134   typedef std::map<vtkIdType, vtkIdType> TObj2VTKID;
135
136   class TMEDNamedPointCoords: public virtual TNamedPointCoords
137   {
138     MED::EBooleen myIsElemNum; //!< Keeps whether the numeration exists or not
139     MED::PElemNum myElemNum; //!< Keeps objects numeration
140     mutable TObj2VTKID myObj2VTKID; //!< Keeps mapping from object number to VTK one
141
142     MED::EVersion myVersion;
143     MED::PString myElemNames; //!< Keeps whether the names exists or not
144     MED::EBooleen myIsElemNames; //!< Keeps objects names
145
146   public:
147     TMEDNamedPointCoords():
148       myIsElemNum(MED::eFAUX),
149       myIsElemNames(MED::eFAUX)
150     {}
151
152     void
153     Init(const MED::PNodeInfo& theNodeInfo,
154          MED::EVersion theVersion);
155
156     void
157     Init(const MED::PGrilleInfo& theGrilleInfo);
158
159     //! Get object number for node by its VTK one
160     virtual
161     vtkIdType
162     GetObjID(vtkIdType theID) const;
163
164     //! Get VTK number for node by its object one
165     virtual
166     vtkIdType
167     GetVTKID(vtkIdType theID) const;
168
169     //! Get name of node by its object number
170     virtual
171     std::string 
172     GetNodeName(vtkIdType theObjID) const;
173
174     //! Gets memory size used by the instance (bytes).
175     virtual
176     unsigned long int
177     GetMemorySize();
178   };
179   typedef MED::SharedPtr<TMEDNamedPointCoords> PMEDNamedPointCoords;
180
181
182   //---------------------------------------------------------------
183   struct VISU_CONVERTOR_EXPORT TMEDMesh: virtual TMeshImpl
184   {
185     MED::PMeshInfo myMeshInfo;
186     MED::TEntityInfo myEntityInfo;
187   };
188   typedef MED::SharedPtr<TMEDMesh> PMEDMesh;
189
190
191   //---------------------------------------------------------------
192   struct VISU_CONVERTOR_EXPORT TMEDSubProfile: virtual TSubProfileImpl
193   {
194     MED::EGeometrieElement myMGeom;
195
196     TMEDSubProfile():
197       myIsElemNum(MED::eFAUX)
198     {}
199
200     MED::EBooleen myIsElemNum;
201     MED::PElemNum myElemNum;
202
203     virtual 
204     vtkIdType 
205     GetElemObjID(vtkIdType theID) const;
206     
207     //! Reimplement the TSubProfileImpl::GetElemVTKID
208     virtual 
209     vtkIdType 
210     GetElemVTKID(vtkIdType theID) const;
211
212     //! Gets memory size used by the instance (bytes).
213     virtual
214     unsigned long int
215     GetMemorySize();
216   };
217   typedef MED::SharedPtr<TMEDSubProfile> PMEDSubProfile;
218
219
220   //---------------------------------------------------------------
221   struct VISU_CONVERTOR_EXPORT TMEDProfile: virtual TProfileImpl
222   {};
223   typedef MED::SharedPtr<TMEDProfile> PMEDProfile;
224
225
226   //---------------------------------------------------------------
227   struct VISU_CONVERTOR_EXPORT TMEDGauss: virtual TGaussImpl
228   {
229     MED::PGaussInfo myGaussInfo;
230
231     //! To define a way to implement more detail comparision of the TGaussSubMesh instances
232     virtual
233     void
234     LessThan(const PGaussImpl& theGauss,
235              bool& theResult) const;
236   };
237   typedef MED::SharedPtr<TMEDGauss> PMEDGauss;
238
239
240   //---------------------------------------------------------------
241   struct VISU_CONVERTOR_EXPORT TMEDGaussSubMesh: virtual TGaussSubMeshImpl
242   {
243     TMEDGaussSubMesh():
244       myIsElemNum(MED::eFAUX)
245     {}
246
247     MED::EBooleen myIsElemNum;
248     MED::PElemNum myElemNum;
249
250     virtual
251     TGaussPointID
252     GetObjID(vtkIdType theID) const;
253     
254     virtual
255     vtkIdType
256     GetVTKID( const TGaussPointID& theID ) const;  
257
258     //! Gets memory size used by the instance (bytes).
259     virtual
260     unsigned long int
261     GetMemorySize();
262   };
263   typedef MED::SharedPtr<TMEDGaussSubMesh> PMEDGaussSubMesh;
264
265
266   //---------------------------------------------------------------
267   struct VISU_CONVERTOR_EXPORT TMEDGaussMesh: virtual TGaussMeshImpl
268   {};
269   typedef MED::SharedPtr<TMEDGaussMesh> PMEDGaussMesh;
270
271
272   //---------------------------------------------------------------
273   struct VISU_CONVERTOR_EXPORT TMEDSubMesh: virtual TSubMeshImpl
274   {
275     TMEDSubMesh():
276       myIsElemNum(MED::eFAUX),
277       myIsElemNames(MED::eFAUX)
278     {}
279
280     MED::EBooleen myIsElemNum;
281     MED::PElemNum myElemNum;
282
283     MED::EVersion myVersion;
284     MED::PString myElemNames;
285     MED::EBooleen myIsElemNames;
286
287     void
288     Init(const MED::PElemInfo& theElemInfo,
289          MED::EVersion theVersion);
290
291     void
292     Init(const MED::PGrilleInfo& theGrilleInfo);
293
294     virtual 
295     vtkIdType 
296     GetElemObjID(vtkIdType theID) const;
297
298     virtual
299     std::string 
300     GetElemName(vtkIdType theObjID) const;
301
302     //! Gets memory size used by the instance (bytes).
303     virtual
304     unsigned long int
305     GetMemorySize();
306   };
307   typedef MED::SharedPtr<TMEDSubMesh> PMEDSubMesh;
308
309
310   //---------------------------------------------------------------
311   typedef std::map<vtkIdType,vtkIdType> TFamilyID2CellsSize;
312
313   typedef std::map<vtkIdType,vtkIdType> TElemID2FamilyID;
314   typedef std::map<MED::EGeometrieElement,TElemID2FamilyID> TGeom2ElemID2FamilyID;
315
316   struct VISU_CONVERTOR_EXPORT TMEDMeshOnEntity: virtual TMeshOnEntityImpl
317   {
318     TFamilyID2CellsSize myFamilyID2CellsSize;
319     TGeom2ElemID2FamilyID myGeom2ElemID2FamilyID;
320     MED::TGeom2Size myGeom2Size;
321   };
322   typedef MED::SharedPtr<TMEDMeshOnEntity> PMEDMeshOnEntity;
323
324
325   //---------------------------------------------------------------
326   struct VISU_CONVERTOR_EXPORT TMEDFamily: virtual TFamilyImpl
327   {};
328   typedef MED::SharedPtr<TMEDFamily> PMEDFamily;
329   
330
331   //---------------------------------------------------------------
332   struct VISU_CONVERTOR_EXPORT TMEDGroup: virtual TGroupImpl
333   {};
334   typedef MED::SharedPtr<TMEDGroup> PMEDGroup;
335
336
337   //---------------------------------------------------------------
338   struct VISU_CONVERTOR_EXPORT TMEDField: virtual TFieldImpl
339   {};
340   typedef MED::SharedPtr<TMEDField> PMEDField;
341
342
343   //---------------------------------------------------------------
344   struct VISU_CONVERTOR_EXPORT TMEDValForTime: virtual TValForTimeImpl
345   {};
346   typedef MED::SharedPtr<TMEDValForTime> PMEDValForTime;
347
348 }
349
350 class VISU_MedConvertor: public VISU_Convertor_impl
351 {  
352   VISU_MedConvertor();
353   VISU_MedConvertor(const VISU_MedConvertor&);
354   
355   bool myIsEntitiesDone;
356   bool myIsFieldsDone;
357   bool myIsGroupsDone;
358   bool myIsMinMaxDone;
359
360 public:
361   VISU_MedConvertor(const std::string& theFileName, MED::PWrapper theMed);
362
363   virtual
364   VISU_Convertor* 
365   BuildEntities();
366
367   virtual
368   VISU_Convertor* 
369   BuildFields();
370
371   virtual
372   VISU_Convertor* 
373   BuildMinMax();
374
375   virtual
376   VISU_Convertor* 
377   BuildGroups();
378
379 protected:
380   MED::PWrapper myMed; // mpv : bug 13568: one med per converter
381
382   virtual
383   int
384   LoadMeshOnEntity(VISU::PMeshImpl theMesh,
385                    VISU::PMeshOnEntityImpl theMeshOnEntity);
386   
387   virtual
388   int
389   LoadFamilyOnEntity(VISU::PMeshImpl theMesh,
390                      VISU::PMeshOnEntityImpl theMeshOnEntity, 
391                      VISU::PFamilyImpl theFamily);
392
393   virtual
394   int
395   LoadMeshOnGroup(VISU::PMeshImpl theMesh, 
396                   const VISU::TFamilySet& theFamilySet);
397   
398   virtual
399   int
400   LoadValForTimeOnMesh(VISU::PMeshImpl theMesh, 
401                        VISU::PMeshOnEntityImpl theMeshOnEntity, 
402                        VISU::PFieldImpl theField, 
403                        VISU::PValForTimeImpl theValForTime);
404   
405   virtual 
406   int
407   LoadValForTimeOnGaussPts(VISU::PMeshImpl theMesh, 
408                            VISU::PMeshOnEntityImpl theMeshOnEntity, 
409                            VISU::PFieldImpl theField, 
410                            VISU::PValForTimeImpl theValForTime);
411
412   int
413   LoadPoints(const MED::PWrapper& theMed,
414              const VISU::PMEDMesh theMesh);
415   
416   int
417   LoadPointsOnFamily(const MED::PWrapper& theMed,
418                      const VISU::PMEDMesh theMesh, 
419                      const VISU::PMEDFamily theFamily);
420   
421   int
422   LoadCellsOnEntity(const MED::PWrapper& theMed,
423                     const VISU::PMEDMesh theMesh,
424                     const VISU::PMEDMeshOnEntity theMeshOnEntity);
425   
426   int
427   LoadCellsOnFamily(const MED::PWrapper& theMed,
428                     const VISU::PMEDMesh theMesh,
429                     const VISU::PMEDMeshOnEntity theMeshOnEntity,
430                     const VISU::PMEDFamily theFamily);
431   
432   int
433   LoadValForTimeOnMesh(const MED::PWrapper& theMed,
434                        VISU::PMEDMesh theMesh,
435                        VISU::PMEDMeshOnEntity theMeshOnEntity,
436                        VISU::PMEDField theField, 
437                        VISU::PMEDValForTime theValForTime);
438   
439   int
440   LoadValForTimeOnGaussPts(const MED::PWrapper& theMed,
441                            VISU::PMEDMesh theMesh,
442                            VISU::PMEDMeshOnEntity theMeshOnEntity,
443                            VISU::PMEDField theField, 
444                            VISU::PMEDValForTime theValForTime);
445 };
446
447 #endif