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