]> SALOME platform Git repositories - modules/visu.git/blob - src/CONVERTOR/VISU_MedConvertor.hxx
Salome HOME
216e8a15044b0a63c6dfd53073bb1cdf32fb49b0
[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   typedef std::map<vtkIdType,vtkIdType> TElemID2FamilyID;
313   typedef std::map<MED::EGeometrieElement,TElemID2FamilyID> TGeom2ElemID2FamilyID;
314
315   struct VISU_CONVERTOR_EXPORT TMEDMeshOnEntity: virtual TMeshOnEntityImpl
316   {
317     TFamilyID2CellsSize myFamilyID2CellsSize;
318     TGeom2ElemID2FamilyID myGeom2ElemID2FamilyID;
319     MED::TGeom2Size myGeom2Size;
320   };
321   typedef MED::SharedPtr<TMEDMeshOnEntity> PMEDMeshOnEntity;
322
323
324   //---------------------------------------------------------------
325   struct VISU_CONVERTOR_EXPORT TMEDFamily: virtual TFamilyImpl
326   {};
327   typedef MED::SharedPtr<TMEDFamily> PMEDFamily;
328   
329
330   //---------------------------------------------------------------
331   struct VISU_CONVERTOR_EXPORT TMEDGroup: virtual TGroupImpl
332   {};
333   typedef MED::SharedPtr<TMEDGroup> PMEDGroup;
334
335
336   //---------------------------------------------------------------
337   struct VISU_CONVERTOR_EXPORT TMEDField: virtual TFieldImpl
338   {};
339   typedef MED::SharedPtr<TMEDField> PMEDField;
340
341
342   //---------------------------------------------------------------
343   struct VISU_CONVERTOR_EXPORT TMEDValForTime: virtual TValForTimeImpl
344   {};
345   typedef MED::SharedPtr<TMEDValForTime> PMEDValForTime;
346
347 }
348
349 class VISU_MedConvertor: public VISU_Convertor_impl
350 {  
351   VISU_MedConvertor();
352   VISU_MedConvertor(const VISU_MedConvertor&);
353   
354   bool myIsEntitiesDone;
355   bool myIsFieldsDone;
356   bool myIsGroupsDone;
357   bool myIsMinMaxDone;
358
359 public:
360   VISU_MedConvertor(const std::string& theFileName, MED::PWrapper theMed);
361
362   virtual
363   VISU_Convertor* 
364   BuildEntities();
365
366   virtual
367   VISU_Convertor* 
368   BuildFields();
369
370   virtual
371   VISU_Convertor* 
372   BuildMinMax();
373
374   virtual
375   VISU_Convertor* 
376   BuildGroups();
377
378 protected:
379   MED::PWrapper myMed; // mpv : bug 13568: one med per converter
380
381   virtual
382   int
383   LoadMeshOnEntity(VISU::PMeshImpl theMesh,
384                    VISU::PMeshOnEntityImpl theMeshOnEntity);
385   
386   virtual
387   int
388   LoadFamilyOnEntity(VISU::PMeshImpl theMesh,
389                      VISU::PMeshOnEntityImpl theMeshOnEntity, 
390                      VISU::PFamilyImpl theFamily);
391
392   virtual
393   int
394   LoadMeshOnGroup(VISU::PMeshImpl theMesh, 
395                   const VISU::TFamilySet& theFamilySet);
396   
397   virtual
398   int
399   LoadValForTimeOnMesh(VISU::PMeshImpl theMesh, 
400                        VISU::PMeshOnEntityImpl theMeshOnEntity, 
401                        VISU::PFieldImpl theField, 
402                        VISU::PValForTimeImpl theValForTime);
403   
404   virtual 
405   int
406   LoadValForTimeOnGaussPts(VISU::PMeshImpl theMesh, 
407                            VISU::PMeshOnEntityImpl theMeshOnEntity, 
408                            VISU::PFieldImpl theField, 
409                            VISU::PValForTimeImpl theValForTime);
410
411   int
412   LoadPoints(const MED::PWrapper& theMed,
413              const VISU::PMEDMesh theMesh);
414   
415   int
416   LoadPointsOnFamily(const MED::PWrapper& theMed,
417                      const VISU::PMEDMesh theMesh, 
418                      const VISU::PMEDFamily theFamily);
419   
420   int
421   LoadCellsOnEntity(const MED::PWrapper& theMed,
422                     const VISU::PMEDMesh theMesh,
423                     const VISU::PMEDMeshOnEntity theMeshOnEntity);
424   
425   int
426   LoadCellsOnFamily(const MED::PWrapper& theMed,
427                     const VISU::PMEDMesh theMesh,
428                     const VISU::PMEDMeshOnEntity theMeshOnEntity,
429                     const VISU::PMEDFamily theFamily);
430   
431   int
432   LoadValForTimeOnMesh(const MED::PWrapper& theMed,
433                        VISU::PMEDMesh theMesh,
434                        VISU::PMEDMeshOnEntity theMeshOnEntity,
435                        VISU::PMEDField theField, 
436                        VISU::PMEDValForTime theValForTime);
437   
438   int
439   LoadValForTimeOnGaussPts(const MED::PWrapper& theMed,
440                            VISU::PMEDMesh theMesh,
441                            VISU::PMEDMeshOnEntity theMeshOnEntity,
442                            VISU::PMEDField theField, 
443                            VISU::PMEDValForTime theValForTime);
444 };
445
446 #endif