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