Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/visu.git] / src / CONVERTOR / VISU_MedConvertor.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  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.cxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27
28 #include "VISU_MedConvertor.hxx"
29 #include "VISU_Convertor.hxx"
30 #include "VISU_ConvertorUtils.hxx"
31
32 #include "MED_Factory.hxx"
33 #include "MED_Algorithm.hxx"
34 #include "MED_GaussUtils.hxx"
35 #include "MED_Utilities.hxx"
36
37 #include "CASCatch.hxx"
38
39 #include <vtkCellType.h>
40
41 using namespace std;
42 using namespace VISU;
43
44 using MED::TInt;
45 using MED::TFloat;
46 using MED::EBooleen;
47
48 #ifdef _DEBUG_
49 static int MYDEBUG = 0;
50 static int MYVALUEDEBUG = 0;
51 static int MY_FAMILY_DEBUG = 0;
52 static int MY_GROUP_DEBUG = 0;
53 //#define _DEXCEPT_
54 #else
55 static int MYDEBUG = 0;
56 static int MYVALUEDEBUG = 0;
57 static int MY_FAMILY_DEBUG = 0;
58 static int MY_GROUP_DEBUG = 0;
59 #endif
60
61 #define _LOAD_FAMILIES_
62 #define _EDF_NODE_IDS_
63
64 namespace
65 {
66   //---------------------------------------------------------------
67   vtkIdType
68   MEDGeom2NbNodes(MED::EGeometrieElement theMEDGeomType)
69   { 
70     return theMEDGeomType % 100;
71   }
72
73
74   //---------------------------------------------------------------
75   VISU::EGeometry
76   MEDGeom2VISU(MED::EGeometrieElement theGeom)
77   { 
78     switch(theGeom){
79     case MED::ePOINT1: return VISU::ePOINT1;
80     case MED::eSEG2: return VISU::eSEG2;
81     case MED::eTRIA3: return VISU::eTRIA3;
82     case MED::eQUAD4: return VISU::eQUAD4;
83     case MED::eTETRA4: return VISU::eTETRA4;
84     case MED::eHEXA8: return VISU::eHEXA8;
85     case MED::ePENTA6: return VISU::ePENTA6;
86     case MED::ePYRA5: return VISU::ePYRA5;
87
88     case MED::eSEG3: return VISU::eSEG3;
89     case MED::eTRIA6: return VISU::eTRIA6;
90     case MED::eQUAD8: return VISU::eQUAD8;
91     case MED::eTETRA10: return VISU::eTETRA10;
92     case MED::eHEXA20: return VISU::eHEXA20;
93     case MED::ePENTA15: return VISU::ePENTA15;
94     case MED::ePYRA13: return VISU::ePYRA13;
95
96     case MED::ePOLYGONE: return VISU::ePOLYGONE;
97     case MED::ePOLYEDRE: return VISU::ePOLYEDRE;
98     }
99     return VISU::eNONE;
100   }
101
102
103   //---------------------------------------------------------------
104   MED::EGeometrieElement 
105   VISUGeom2MED(int theGeom)
106   { 
107     switch(theGeom){
108     case VISU::ePOINT1: return MED::ePOINT1;
109     case VISU::eSEG2: return MED::eSEG2;
110     case VISU::eTRIA3: return MED::eTRIA3;
111     case VISU::eQUAD4: return MED::eQUAD4;
112     case VISU::eTETRA4: return MED::eTETRA4;
113     case VISU::eHEXA8: return MED::eHEXA8;
114     case VISU::ePENTA6: return MED::ePENTA6;
115     case VISU::ePYRA5: return MED::ePYRA5;
116
117     case VISU::eSEG3: return MED::eSEG3;
118     case VISU::eTRIA6: return MED::eTRIA6;
119     case VISU::eQUAD8: return MED::eQUAD8;
120     case VISU::eTETRA10: return MED::eTETRA10;
121     case VISU::eHEXA20: return MED::eHEXA20;
122     case VISU::ePENTA15: return MED::ePENTA15;
123     case VISU::ePYRA13: return MED::ePYRA13;
124
125     case VISU::ePOLYGONE: return MED::ePOLYGONE;
126     case VISU::ePOLYEDRE: return MED::ePOLYEDRE;
127     }
128     return MED::EGeometrieElement(-1);
129   }
130
131
132   //---------------------------------------------------------------
133   VISU::TEntity
134   MEDEntityToVTK(MED::EEntiteMaillage theMEDEntity)
135   {
136     switch(theMEDEntity){
137     case MED::eNOEUD: return NODE_ENTITY;
138     case MED::eARETE: return EDGE_ENTITY;
139     case MED::eFACE: return FACE_ENTITY;
140     case MED::eMAILLE: return CELL_ENTITY;
141     }
142     return VISU::TEntity(-1);
143   }
144
145
146   //---------------------------------------------------------------
147   MED::EEntiteMaillage 
148   VTKEntityToMED(TEntity theVTKEntity)
149   {
150     switch(theVTKEntity){
151     case NODE_ENTITY: return MED::eNOEUD;
152     case EDGE_ENTITY: return MED::eARETE;
153     case FACE_ENTITY: return MED::eFACE;
154     case CELL_ENTITY: return MED::eMAILLE;
155     }
156     return MED::EEntiteMaillage(-1);
157   }
158
159
160   //---------------------------------------------------------------
161   PMEDSubProfile
162   CrSubProfile(const MED::PWrapper& theMEDWrapper,
163                const MED::PMeshInfo& theMeshInfo,
164                MED::EEntiteMaillage theMEntity,
165                MED::EGeometrieElement theMGeom,
166                const MED::TGeom2Size& theGeom2Size,
167                const MED::TGeom2Profile& theGeom2Profile)
168   {
169     VISU::EGeometry aEGeom = MEDGeom2VISU(theMGeom);
170     vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
171
172     PMEDSubProfile aSubProfile(new TMEDSubProfile());
173     aSubProfile->myGeom = aEGeom;
174     aSubProfile->myMGeom = theMGeom;
175     aSubProfile->myStatus = eAddAll;
176
177     MED::TGeom2Size::const_iterator aTimeStampIter = theGeom2Size.find(theMGeom);
178     if(aTimeStampIter == theGeom2Size.end())
179       aSubProfile->myStatus = eRemoveAll;
180     else{
181       MED::TGeom2Profile::const_iterator aProfileIter = theGeom2Profile.find(theMGeom);
182       if(aProfileIter != theGeom2Profile.end()){
183         MED::PProfileInfo aProfileInfo = aProfileIter->second;
184
185         aSubProfile->myName = aProfileInfo->GetName();
186         aSubProfile->myStatus = eAddPart;
187
188         const MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
189         TInt aNbElem = anElemNum.size();
190         aSubProfile->myNbCells = aNbElem;
191         switch(theMGeom){
192         case MED::ePOLYGONE: {
193           MED::PPolygoneInfo aPolygoneInfo = 
194             theMEDWrapper->GetPPolygoneInfo(theMeshInfo,theMEntity,theMGeom);
195           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
196             TInt aNbConn = aPolygoneInfo->GetNbConn(anElemNum[anElemId]);
197             aSubProfile->myCellsSize += aNbConn;
198           }
199           break;
200         }
201         case MED::ePOLYEDRE: {
202           MED::PPolyedreInfo aPolyedreInfo = 
203             theMEDWrapper->GetPPolyedreInfo(theMeshInfo,theMEntity,theMGeom);
204           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
205             MED::TCConnSliceArr aConnSliceArr = 
206               aPolyedreInfo->GetConnSliceArr(anElemNum[anElemId]);
207             TInt aNbFaces = aConnSliceArr.size();
208             TInt aCellSize = 0;
209             for(TInt iFace = 0; iFace < aNbFaces; iFace++){
210               MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
211               TInt aNbConn = aConnSlice.size();
212               aCellSize += aNbConn;
213             }
214             aSubProfile->myCellsSize += aCellSize;
215           }
216           break;
217         }
218         default: {
219           aSubProfile->myCellsSize = aSubProfile->myNbCells*aVNbNodes;
220         }}
221       }else{
222         TInt aNbElem = aTimeStampIter->second;
223         aSubProfile->myNbCells = aNbElem;
224         switch(theMGeom){
225         case MED::ePOLYGONE: {
226           MED::PPolygoneInfo aPolygoneInfo = 
227             theMEDWrapper->GetPPolygoneInfo(theMeshInfo,theMEntity,theMGeom);
228           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
229             TInt aNbConn = aPolygoneInfo->GetNbConn(anElemId);
230             aSubProfile->myCellsSize += aNbConn;
231           }
232           break;
233         }
234         case MED::ePOLYEDRE: {
235           MED::PPolyedreInfo aPolyedreInfo = 
236             theMEDWrapper->GetPPolyedreInfo(theMeshInfo,theMEntity,theMGeom);
237           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
238             MED::TCConnSliceArr aConnSliceArr = 
239               aPolyedreInfo->GetConnSliceArr(anElemId);
240             TInt aNbFaces = aConnSliceArr.size();
241             TInt aCellSize = 0;
242             for(TInt iFace = 0; iFace < aNbFaces; iFace++){
243               MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
244               TInt aNbConn = aConnSlice.size();
245               aCellSize += aNbConn;
246             }
247             aSubProfile->myCellsSize += aCellSize;
248           }
249           break;
250         }
251         default: {
252           aSubProfile->myCellsSize = aSubProfile->myNbCells*aVNbNodes;
253         }}
254       }
255     }
256     INITMSG(MYDEBUG,
257             "- aMGeom = "<<theMGeom<<
258             "; aEGeom = "<<aEGeom<<
259             "; aName = '"<<aSubProfile->myName<<"'"<<
260             "; aStatus = "<<aSubProfile->myStatus<<
261             "; aNbCells = "<<aSubProfile->myNbCells<<
262             "; aCellsSize = "<<aSubProfile->myCellsSize<<
263             endl);
264     
265     return aSubProfile;
266   }
267
268
269   //---------------------------------------------------------------
270   TProfileKey
271   GetProfileKey(const MED::PWrapper& theMEDWrapper,
272                 const MED::PMeshInfo& theMeshInfo,
273                 const MED::TTimeStampVal& theTimeStampVal,
274                 const VISU::TMEDMeshOnEntity& theMeshOnEntity,
275                 MED::EEntiteMaillage theMEntity,
276                 const MED::TGeom2Size& theGeom2Size)
277   {
278     INITMSG(MYDEBUG,"GetProfileKey"<<endl);
279     
280     TProfileKey aProfileKey;
281     const MED::TGeom2Profile& aGeom2Profile = theTimeStampVal.GetGeom2Profile();
282
283     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity.myGeom2Size;
284     MED::TGeom2Size::const_iterator anIter = aGeom2Size.begin();
285     for(; anIter != aGeom2Size.end(); anIter++){
286       MED::EGeometrieElement aMGeom = anIter->first;
287       PSubProfile aSubProfile = CrSubProfile(theMEDWrapper,
288                                              theMeshInfo,
289                                              theMEntity,
290                                              aMGeom,
291                                              theGeom2Size,
292                                              aGeom2Profile);
293       aProfileKey.insert(aSubProfile);
294     }
295     
296     return aProfileKey;
297   }
298   
299
300   //---------------------------------------------------------------
301   void
302   InitProfile(const MED::PWrapper& theMEDWrapper,
303               const MED::PMeshInfo& theMeshInfo,
304               MED::TTimeStampVal& theTimeStampVal,
305               VISU::TMEDMeshOnEntity& theMeshOnEntity,
306               MED::EEntiteMaillage theMEntity,
307               const MED::TGeom2Size& theGeom2Size,
308               VISU::TMEDValForTime& theValForTime)
309   {
310     TTimerLog aTimerLog(MYDEBUG,"InitProfile");
311     INITMSG(MYDEBUG,"InitProfile"<<endl);
312     
313     TProfileMap& aProfileMap = theMeshOnEntity.myProfileMap;
314     
315     TProfileKey aProfileKey = GetProfileKey(theMEDWrapper,
316                                             theMeshInfo,
317                                             theTimeStampVal,
318                                             theMeshOnEntity,
319                                             theMEntity,
320                                             theGeom2Size);
321     
322     TProfileMap::const_iterator anIter = aProfileMap.find(aProfileKey);
323     if(anIter != aProfileMap.end()){
324       theValForTime.myProfile = anIter->second;
325       INITMSG(MYDEBUG,"aProfileMap.find(aProfileKey)"<<endl);
326     }else{
327       PMEDProfile aProfile(new TMEDProfile());
328       TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
329       
330       TProfileKey::const_iterator anIter = aProfileKey.begin();
331       for(; anIter != aProfileKey.end(); anIter++){
332         PMEDSubProfile aSubProfile(*anIter);
333
334         if(aProfile->myIsAll && aSubProfile->myStatus != eAddAll)
335           aProfile->myIsAll = false;
336
337         VISU::EGeometry aEGeom = aSubProfile->myGeom;
338         aGeom2SubProfile[aEGeom] = aSubProfile;
339       }
340
341       aProfileMap[aProfileKey] = aProfile;
342       theValForTime.myProfile = aProfile;
343     }
344   }
345
346
347   //---------------------------------------------------------------
348   TGaussKey
349   GetGaussKey(const MED::TTimeStampVal& theTimeStampVal,
350               const VISU::TMEDMeshOnEntity& theMeshOnEntity,
351               const MED::TGeom2Size& theGeom2Size,
352               VISU::TMEDValForTime& theValForTime)
353   {
354     TTimerLog aTimerLog(MYDEBUG,"GetGaussKey");
355     INITMSG(MYDEBUG,"GetGaussKey"<<endl);
356
357     TGaussKey aGaussKey;
358     PMEDProfile aProfile = theValForTime.myProfile;
359     TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
360
361     const MED::TTimeStampInfo& aTimeStampInfo = theTimeStampVal.GetTimeStampInfo();
362     const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo.GetGeom2Gauss();
363
364     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity.myGeom2Size;
365     MED::TGeom2Size::const_iterator anIter = aGeom2Size.begin();
366     for(; anIter != aGeom2Size.end(); anIter++){
367       MED::EGeometrieElement aMGeom = anIter->first;
368       VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
369
370       TGeom2SubProfile::iterator anIter2 = aGeom2SubProfile.find(aEGeom);
371       if(anIter2 == aGeom2SubProfile.end()){
372         INITMSG(MYDEBUG,"anIter2 == aGeom2SubProfile.end!!"<<endl);
373         continue;
374       }
375       PMEDSubProfile aSubProfile = anIter2->second;
376
377       MED::TGeom2Size::const_iterator aTimeStampIter = theGeom2Size.find(aMGeom);
378       if(aTimeStampIter != theGeom2Size.end()){
379         TInt aNbCells = aTimeStampIter->second;
380         if(aSubProfile->myStatus == eAddPart)
381           aNbCells = aSubProfile->myNbCells;
382
383         PMEDGaussSubMesh aGaussSubMesh(new TMEDGaussSubMesh());
384         aGaussSubMesh->mySubProfile = aSubProfile;
385         aGaussSubMesh->myStatus = aSubProfile->myStatus;
386           
387         PMEDGauss aGauss(new TMEDGauss());
388         aGaussSubMesh->myGauss = aGauss;
389         aGauss->myGeom = aEGeom;
390         aGauss->myNbPoints = 1;
391
392         MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom);
393         if(aGaussIter != aGeom2Gauss.end()){
394           MED::PGaussInfo aGaussInfo = aGaussIter->second;
395           aGauss->myGaussInfo = aGaussInfo;
396           aGauss->myName = aGaussInfo->GetName();
397           aGauss->myNbPoints = aGaussInfo->GetNbGauss();
398         }
399         
400         aGaussSubMesh->myNbCells = aNbCells*aGauss->myNbPoints;
401         aGaussSubMesh->myCellsSize = aGaussSubMesh->myNbCells*2;
402
403         aGaussKey.insert(aGaussSubMesh);
404
405         INITMSGA(MYDEBUG,0,
406                  "- aEGeom = "<<aGauss->myGeom<<
407                  "; aName = '"<<aGauss->myName<<"'"<<
408                  "; aNbGauss = "<<aGauss->myNbPoints<<
409                  "; aStatus = "<<aGaussSubMesh->myStatus<<
410                  "; aNbCells = "<<aGaussSubMesh->myNbCells<<
411                  "; aCellsSize = "<<aGaussSubMesh->myCellsSize<<
412                  endl);
413       }
414     }
415
416     return aGaussKey;
417   }
418
419
420   //---------------------------------------------------------------
421   void
422   InitGaussMesh(MED::TTimeStampVal& theTimeStampVal,
423                 VISU::TMEDMeshOnEntity& theMeshOnEntity,
424                 const MED::TGeom2Size& theGeom2Size,
425                 VISU::TMEDValForTime& theValForTime)
426   {
427     TTimerLog aTimerLog(MYDEBUG,"InitGaussMesh");
428     INITMSG(MYDEBUG,"InitGaussMesh"<<endl);
429
430     if(theMeshOnEntity.myEntity == NODE_ENTITY)
431       return;
432
433     TGaussMeshMap& aGaussMeshMap = theMeshOnEntity.myGaussMeshMap;
434     
435     TGaussKey aGaussKey = GetGaussKey(theTimeStampVal,
436                                       theMeshOnEntity,
437                                       theGeom2Size,
438                                       theValForTime);
439
440     TGaussMeshMap::const_iterator anIter = aGaussMeshMap.find(aGaussKey);
441     if(anIter != aGaussMeshMap.end()){
442       theValForTime.myGaussMesh = anIter->second;
443       INITMSG(MYDEBUG,"aGaussMeshMap.find(aGaussKey)"<<endl);
444     }else{
445       PMEDGaussMesh aGaussMesh(new TMEDGaussMesh());
446       TGeom2GaussSubMesh& aGeom2GaussSubMesh = aGaussMesh->myGeom2GaussSubMesh;
447       {
448         TGaussKey::const_iterator anIter = aGaussKey.begin();
449         for(; anIter != aGaussKey.end(); anIter++){
450           PMEDGaussSubMesh aGaussSubMesh(*anIter);
451           PMEDGauss aGauss = aGaussSubMesh->myGauss;
452           VISU::EGeometry aEGeom = aGauss->myGeom;
453           aGeom2GaussSubMesh[aEGeom] = aGaussSubMesh;
454         }
455       }
456       {
457         TGaussSubMeshArr& aGaussSubMeshArr = aGaussMesh->myGaussSubMeshArr;
458         aGaussSubMeshArr.resize(aGeom2GaussSubMesh.size());
459         TGeom2GaussSubMesh::const_iterator anIter = aGeom2GaussSubMesh.begin();
460         for(TInt anID = 0; anIter != aGeom2GaussSubMesh.end(); anIter++, anID++){
461           const PGaussSubMeshImpl& aGaussSubMesh = anIter->second;
462           aGaussSubMeshArr[anID] = aGaussSubMesh;
463         }
464       }
465       INITMSG(MYDEBUG,"aGaussMeshMap[aGaussKey] = aGaussMesh"<<endl);
466       aGaussMeshMap[aGaussKey] = aGaussMesh;
467       theValForTime.myGaussMesh = aGaussMesh;
468     }
469   }
470
471
472   //---------------------------------------------------------------
473   void
474   InitGaussProfile(const MED::PWrapper& theMEDWrapper,
475                    const MED::PMeshInfo& theMeshInfo,
476                    MED::TTimeStampVal& theTimeStampVal,
477                    VISU::TMEDMeshOnEntity& theMeshOnEntity,
478                    MED::EEntiteMaillage theMEntity,
479                    const MED::TGeom2Size& theGeom2Size,
480                    VISU::TMEDValForTime& theValForTime)
481   {
482     TTimerLog aTimerLog(MYDEBUG,"InitGaussProfile");
483     INITMSG(MYDEBUG,"InitGaussProfile"<<endl);
484
485     // The order of the function calls is important
486     InitProfile(theMEDWrapper,
487                 theMeshInfo,
488                 theTimeStampVal,
489                 theMeshOnEntity,
490                 theMEntity,
491                 theGeom2Size,
492                 theValForTime);
493
494     InitGaussMesh(theTimeStampVal,
495                   theMeshOnEntity,
496                   theGeom2Size,
497                   theValForTime);
498   }
499
500
501   //---------------------------------------------------------------
502   void
503   BuildMeshOnEntityMap(PMEDMesh theMesh,
504                        const MED::TEntityInfo& theEntityInfo,
505                        const MED::PNodeInfo& theNodeInfo,
506                        const MED::PWrapper& theMEDWrapper)
507   {
508     TTimerLog aTimerLog(MYDEBUG,"BuildMeshOnEntityMap");
509     INITMSG(MYDEBUG,"BuildMeshOnEntityMap"<<endl);
510
511     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
512     const std::string& aMeshName = theMesh->myName;
513     TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
514     MED::TEntityInfo::const_iterator anEntityIter = theEntityInfo.begin();
515     for(; anEntityIter != theEntityInfo.end(); anEntityIter++){
516       const MED::EEntiteMaillage& aMEntity = anEntityIter->first;
517       const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
518       
519       TEntity aVEntity = MEDEntityToVTK(aMEntity);
520       PMEDMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new TMEDMeshOnEntity());
521       aMeshOnEntity->myEntity = aVEntity;
522       aMeshOnEntity->myMeshName = aMeshName;
523       aMeshOnEntity->myGeom2Size = aGeom2Size;
524       TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize;
525
526       INITMSG(MYDEBUG,
527               "- aMEntity = "<<aMEntity<<
528               "; aVEntity = "<<aVEntity<<
529               endl);
530       
531       if(aMEntity == MED::eNOEUD){
532         aMeshOnEntity->myNbCells = theMesh->myNbPoints;
533         aMeshOnEntity->myCellsSize = 2*theMesh->myNbPoints;
534         
535         for(TInt iElem = 0; iElem < theMesh->myNbPoints; iElem++){
536           TInt aFamId = theNodeInfo->GetFamNum(iElem);
537           if(aFamId != 0)
538             aFamilyID2CellsSize[aFamId] += 2;
539         }
540         
541         INITMSG(MYDEBUG,
542                 "- myNbCells = "<<aMeshOnEntity->myNbCells<<
543                 "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
544                 endl);;
545         
546       }else{
547         MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
548         aMeshOnEntity->myNbCells = 0;
549         aMeshOnEntity->myCellsSize = 0;
550         for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
551           const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
552           
553           switch(aMGeom){
554           case MED::ePOLYGONE: {
555             MED::PPolygoneInfo aPolygoneInfo = theMEDWrapper->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom);
556             TInt aNbElem = aPolygoneInfo->GetNbElem();
557             
558             INITMSG(MYDEBUG,
559                     "- aMGeom = "<<aMGeom<<
560                     "; aNbElem = "<<aNbElem<<
561                     endl);
562             
563             aMeshOnEntity->myNbCells += aNbElem;      
564             for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
565               TInt aNbConn = aPolygoneInfo->GetNbConn(anElemId);
566               aMeshOnEntity->myCellsSize += aNbConn;
567               TInt aFamId = aPolygoneInfo->GetFamNum(anElemId);
568               if(aFamId != 0)
569                 aFamilyID2CellsSize[aFamId] += aNbConn + 1;
570             }
571             break;
572           }
573           case MED::ePOLYEDRE: {
574             MED::PPolyedreInfo aPolyedreInfo = theMEDWrapper->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom);
575             TInt aNbElem = aPolyedreInfo->GetNbElem();
576             
577             INITMSG(MYDEBUG,
578                     "- aMGeom = "<<aMGeom<<
579                     "; aNbElem = "<<aNbElem<<
580                     endl);
581             
582             aMeshOnEntity->myNbCells += aNbElem;
583             for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
584               MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(anElemId);
585               TInt aNbFaces = aConnSliceArr.size();
586               TInt aCellSize = 0;
587               for(TInt iFace = 0; iFace < aNbFaces; iFace++){
588                 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
589                 TInt aNbConn = aConnSlice.size();
590                 aCellSize += aNbConn;
591               }
592               aMeshOnEntity->myCellsSize += aCellSize;
593               TInt aFamId = aPolyedreInfo->GetFamNum(anElemId);
594               if(aFamId != 0)
595                 aFamilyID2CellsSize[aFamId] += aCellSize + 1;
596             }
597             break;
598           }
599           default: {
600             VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
601             vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
602             MED::PCellInfo aCellInfo = theMEDWrapper->GetPCellInfo(aMeshInfo,aMEntity,aMGeom);
603             TInt aNbElem = aCellInfo->GetNbElem();
604             aMeshOnEntity->myNbCells += aNbElem;
605             aMeshOnEntity->myCellsSize += aNbElem*(aVNbNodes+1);
606             
607             INITMSG(MYDEBUG,
608                     "- aMGeom = "<<aMGeom<<
609                     "; aNbElem = "<<aNbElem<<
610                     "; myNbCells = "<<aMeshOnEntity->myNbCells<<
611                     "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
612                     endl);
613             
614             for(TInt iElem = 0; iElem < aNbElem; iElem++){
615               TInt aFamId = aCellInfo->GetFamNum(iElem);
616               if(aFamId != 0)
617                 aFamilyID2CellsSize[aFamId] += aVNbNodes + 1;
618             }
619           }} // end switch(...)
620         }
621       }
622     }
623   }
624
625   //---------------------------------------------------------------
626   void
627   BuildMeshGrilleOnEntityMap(PMEDMesh theMesh,
628                              const MED::TEntityInfo& theEntityInfo,
629                              const MED::PGrilleInfo& theGrilleInfo,
630                              const MED::PWrapper& theMEDWrapper)
631   {
632     TTimerLog aTimerLog(MYDEBUG,"BuildMeshGrilleOnEntityMap");
633     INITMSG(MYDEBUG,"BuildMeshGrilleOnEntityMap"<<endl);
634     
635     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
636     const std::string& aMeshName = theMesh->myName;
637     TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
638     MED::TEntityInfo::const_iterator anEntityIter = theEntityInfo.begin();
639     for(; anEntityIter != theEntityInfo.end(); anEntityIter++){
640       const MED::EEntiteMaillage& aMEntity = anEntityIter->first;
641       const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
642       
643       TEntity aVEntity = MEDEntityToVTK(aMEntity);
644       PMEDMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new TMEDMeshOnEntity());
645       aMeshOnEntity->myEntity = aVEntity;
646       aMeshOnEntity->myMeshName = aMeshName;
647       aMeshOnEntity->myGeom2Size = aGeom2Size;
648 //       TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize;
649
650       INITMSG(MYDEBUG,
651               "- aMEntity = "<<aMEntity<<
652               "; aVEntity = "<<aVEntity<<
653               endl);
654       
655       if(aMEntity == MED::eNOEUD){
656         aMeshOnEntity->myNbCells = theGrilleInfo->GetNbNodes();
657         aMeshOnEntity->myCellsSize = 2*theGrilleInfo->GetNbNodes();
658
659         // must be implemented (shadow point for GRILLE STANDARD,CARTESIAN,...)
660 //      for(TInt iElem = 0; iElem < theMesh->myNbPoints; iElem++){
661 //        TInt aFamId = theNodeInfo->GetFamNum(iElem);
662 //        if(aFamId != 0)
663 //          aFamilyID2CellsSize[aFamId] += 2;
664 //      }
665         
666         INITMSG(MYDEBUG,
667                 "- myNbCells = "<<aMeshOnEntity->myNbCells<<
668                 "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
669                 endl);;
670         
671       } else {
672         MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
673         aMeshOnEntity->myNbCells = 0;
674         aMeshOnEntity->myCellsSize = 0;
675         for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
676           const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
677           VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
678           vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
679           TInt aNbElem = theGrilleInfo->GetNbCells();
680           aMeshOnEntity->myNbCells += aNbElem;
681           aMeshOnEntity->myCellsSize += aNbElem*(aVNbNodes+1);
682           
683           INITMSG(MYDEBUG,
684                   "- aMGeom = "<<aMGeom<<
685                   "; aNbElem = "<<aNbElem<<
686                   "; myNbCells = "<<aMeshOnEntity->myNbCells<<
687                   "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
688                   endl);
689           
690 //        for(TInt iElem = 0; iElem < aNbElem; iElem++){
691 //          TInt aFamId = aCellInfo->GetFamNum(iElem);
692 //          if(aFamId != 0)
693 //            aFamilyID2CellsSize[aFamId] += aVNbNodes + 1;
694 //        }
695         }
696         
697       }
698
699     }
700
701     
702   }
703
704
705   //---------------------------------------------------------------
706   void
707   BuildFieldMap(PMEDMesh theMesh,
708                 const MED::TEntityInfo& theEntityInfo,
709                 MED::PWrapper theMEDWrapper)
710   {
711     TTimerLog aTimerLog(MYDEBUG,"BuildFieldMap");
712     TInt aNbFields = theMEDWrapper->GetNbFields(); 
713     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
714     const std::string& aMeshName = theMesh->myName;
715     INITMSG(MYDEBUG,"BuildFieldMap: aNbFields = "<<aNbFields<<"\n");
716     for(TInt iField = 1; iField <= aNbFields; iField++){
717       TTimerLog aTimerLog(MYDEBUG,"GetPFieldInfo");
718       MED::PFieldInfo aFieldInfo = theMEDWrapper->GetPFieldInfo(aMeshInfo,iField);
719       TInt aNbComp = aFieldInfo->GetNbComp();
720       std::string aFieldName = aFieldInfo->GetName();
721       
722       MED::TGeom2Size aGeom2Size;
723       MED::EEntiteMaillage aMEntity;
724       TInt aNbTimeStamps = theMEDWrapper->GetNbTimeStamps(aFieldInfo,
725                                                           theEntityInfo,
726                                                           aMEntity,
727                                                           aGeom2Size);
728       if(aNbTimeStamps < 1)
729         continue;
730       
731       TEntity aVEntity = MEDEntityToVTK(aMEntity);
732       PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
733       TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
734       PMEDField aField = aFieldMap[aFieldName](new TMEDField());
735       aField->myId = iField;
736       aField->InitArrays(aNbComp);
737       aField->myEntity = aVEntity;
738       aField->myName = aFieldName;
739       aField->myMeshName = aMeshName;
740       aField->myDataSize = aMeshOnEntity->myNbCells * aNbComp;
741       
742       INITMSG(MYDEBUG,"myName = '"<<aField->myName<<"'"<<
743               "; myId = "<<aField->myId<<
744               "; myEntity = "<<aField->myEntity<<
745               "; myDataSize = "<<aField->myDataSize<<
746               "; myNbComp = "<<aField->myNbComp<<"\n");
747       
748       for(TInt iComp = 0; iComp < aNbComp; iComp++){
749         aField->myCompNames[iComp] = aFieldInfo->GetCompName(iComp);
750         aField->myUnitNames[iComp] = aFieldInfo->GetUnitName(iComp);
751       }
752       
753       for(TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
754         TTimerLog aTimerLog(MYDEBUG,"GetPTimeStampInfo");
755         MED::PTimeStampInfo aTimeStampInfo = theMEDWrapper->GetPTimeStampInfo(aFieldInfo,
756                                                                               aMEntity,
757                                                                               aGeom2Size,
758                                                                               iTimeStamp);
759         TFloat aDt = aTimeStampInfo->GetDt();
760         std::string anUnitDt = aTimeStampInfo->GetUnitDt();
761
762         TValField& aValField = aField->myValField;
763         PMEDValForTime aValForTime = aValField[iTimeStamp](new TMEDValForTime());
764         aValForTime->myId = iTimeStamp;
765         aValForTime->myFieldName = aField->myName;
766         aValForTime->myEntity = aField->myEntity;
767         aValForTime->myMeshName = aField->myMeshName;
768         aValForTime->myTime = VISU::TTime(aDt,anUnitDt);
769         INITMSG(MYDEBUG,"aDt = '"<<aDt<<", "<<anUnitDt<<"'\n");
770         
771         TGeom2NbGauss& aVGeom2NbGauss = aValForTime->myGeom2NbGauss;
772         const MED::TGeom2NbGauss& aMGeom2NbGauss = aTimeStampInfo->myGeom2NbGauss;
773         MED::TGeom2NbGauss::const_iterator anIter = aMGeom2NbGauss.begin();
774         for(; anIter != aMGeom2NbGauss.end(); anIter++){
775           const MED::EGeometrieElement& aMGeom = anIter->first;
776           EGeometry aEGeom = MEDGeom2VISU(aMGeom);
777           TInt aNbGauss = anIter->second;
778           aVGeom2NbGauss[aEGeom] = aNbGauss;
779         }
780       }
781     }
782   }
783
784
785   //---------------------------------------------------------------
786   void
787   BuildFamilyMap(PMEDMesh theMesh,
788                  const MED::TEntityInfo& theEntityInfo,
789                  const MED::TEntity2TGeom2ElemInfo& theEntity2TGeom2ElemInfo,
790                  const MED::TFamilyInfoSet& theFamilyInfoSet,
791                  MED::PWrapper theMEDWrapper)
792   {
793     TTimerLog aTimerLog(MYDEBUG,"BuildFamilyMap");
794     INITMSG(MYDEBUG,"BuildFamilyMap\n");
795
796     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
797     MED::TEntity2FamilySet aEntity2FamilySet = MED::GetEntity2FamilySet(theMEDWrapper,theEntity2TGeom2ElemInfo,theFamilyInfoSet);
798     MED::TEntity2FamilySet::const_iterator aEntity2FamilySetIter = aEntity2FamilySet.begin();
799     for(; aEntity2FamilySetIter != aEntity2FamilySet.end(); aEntity2FamilySetIter++){
800       const MED::EEntiteMaillage& aMEntity = aEntity2FamilySetIter->first;
801       const MED::TFamilyTSizeSet& aFamilyTSizeSet = aEntity2FamilySetIter->second;
802       
803       TEntity aVEntity = MEDEntityToVTK(aMEntity);
804       PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
805       const TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize;
806       TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
807         
808       if(aFamilyTSizeSet.empty())
809         continue;
810         
811       INITMSG(MY_FAMILY_DEBUG,
812               "- aMEntity = "<<aMEntity<<
813               "; aVEntity = "<<aVEntity<<
814               endl);
815
816       MED::TFamilyTSizeSet::const_iterator aFamilyTSizeSetIter = aFamilyTSizeSet.begin();
817       for(; aFamilyTSizeSetIter != aFamilyTSizeSet.end(); aFamilyTSizeSetIter++){
818         const MED::TFamilyTSize& aFamilyTSize = *aFamilyTSizeSetIter;
819         const MED::PFamilyInfo& aFamilyInfo = boost::get<0>(aFamilyTSize);
820         TInt aSize = boost::get<1>(aFamilyTSize);
821         TInt anId = aFamilyInfo->GetId();
822         if(anId == 0) 
823           continue;
824         
825         std::string aFamilyName = aFamilyInfo->GetName();
826
827         PMEDFamily aFamily = aFamilyMap[aFamilyName](new TMEDFamily());
828         aFamily->myId = anId;
829         aFamily->myEntity = aVEntity;
830         aFamily->myName = aFamilyName;
831         aFamily->myNbCells = aSize;
832
833         aFamily->myCellsSize = 0;
834         TFamilyID2CellsSize::const_iterator anIter = aFamilyID2CellsSize.find(anId);
835         if(anIter != aFamilyID2CellsSize.end())
836           aFamily->myCellsSize = anIter->second;
837         
838         INITMSG(MY_FAMILY_DEBUG,
839                 "- aFamilyName = '"<<aFamilyName<<"'"<<
840                 "; myId = "<<aFamily->myId<<"; "<<
841                 "; aNbAttr = "<<aFamilyInfo->GetNbAttr()<<
842                 "; aNbGroup = "<<aFamilyInfo->GetNbGroup()<<
843                 "; aVEntity = "<<aVEntity<<
844                 "; myNbCells = "<<aFamily->myNbCells<<
845                 "; myCellsSize = "<<aFamily->myCellsSize<<
846                 endl);
847 #ifdef _DEBUG_  
848         const TInt aNbGroup = aFamilyInfo->GetNbGroup();
849         for(TInt i = 0; i < aNbGroup; i++){
850           std::string aGroupName = aFamilyInfo->GetGroupName(i);
851           INITMSG(MY_FAMILY_DEBUG,"- aGroupName = '"<<aGroupName<<"'\n");
852         }
853 #endif
854
855       }
856     }
857   }
858
859
860   //---------------------------------------------------------------
861   void
862   BuildGroupMap(PMEDMesh theMesh,
863                 const MED::TFamilyInfoSet& theFamilyInfoSet)
864   {
865     TTimerLog aTimerLog(MYDEBUG,"BuildGroupMap");
866     INITMSG(MYDEBUG,"BuildGroupMap\n");
867
868     TGroupMap& aGroupMap = theMesh->myGroupMap;
869     MED::TGroupInfo aGroupInfo = MED::GetGroupInfo(theFamilyInfoSet);
870     MED::TGroupInfo::const_iterator aGroupInfoIter = aGroupInfo.begin();
871     for(; aGroupInfoIter != aGroupInfo.end(); aGroupInfoIter++){
872       const std::string& aGroupName = aGroupInfoIter->first;
873       INITMSG(MY_GROUP_DEBUG,"aGroupName = '"<<aGroupName<<"'\n");
874
875       PMEDGroup aGroup(new TMEDGroup());
876       TFamilySet& aFamilySet = aGroup->myFamilySet;
877
878       const MED::TFamilyInfoSet& aFamilyInfoSet = aGroupInfoIter->second;
879       MED::TFamilyInfoSet::const_iterator aFamilyIter = aFamilyInfoSet.begin();
880       for(; aFamilyIter != aFamilyInfoSet.end(); aFamilyIter++){
881         const MED::PFamilyInfo& aFamilyInfo = *aFamilyIter;
882         std::string aFamilyName = aFamilyInfo->GetName();
883         
884         TEntity aVEntity = TEntity(-1);
885         PMEDFamily aFamily;
886         
887         // Find aVisuEntity
888         const TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
889         TMeshOnEntityMap::const_iterator aMeshOnEntityIter = aMeshOnEntityMap.begin();
890         for(; aMeshOnEntityIter != aMeshOnEntityMap.end(); aMeshOnEntityIter++){
891           const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityIter->second;
892           const TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
893           TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
894           for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
895             const std::string& aName = aFamilyMapIter->first;
896             aFamily = aFamilyMapIter->second;
897             if(aName == aFamilyName){
898               aVEntity = aFamily->myEntity;
899               goto exit_lable;
900             }
901           }
902         } 
903       exit_lable:
904         if(aFamily && aVEntity >= 0){
905           aFamilySet.insert(aFamily);
906           INITMSG(MY_GROUP_DEBUG,
907                   "- aFamilyName = '"<<aFamilyName<<"'"<<
908                   "; aVEntity = "<<aVEntity<<
909                   "\n");
910         }
911       }
912       if(!aFamilySet.empty())
913         aGroupMap.insert(VISU::TGroupMap::value_type(aGroupName,aGroup));
914     }
915   }
916
917
918   //---------------------------------------------------------------
919   void
920   TMEDNamedPointCoords
921   ::Init(vtkIdType theNbPoints,
922          vtkIdType theDim,
923          const MED::PNodeInfo& theNodeInfo)
924   {
925     if(theNodeInfo->IsElemNum())
926       TNamedPointCoords::Init(theNbPoints,theDim,theNodeInfo->myElemNum);
927     else
928       TNamedPointCoords::Init(theNbPoints,theDim);
929     if(theNodeInfo->IsElemNames())
930       myNodeInfo = theNodeInfo;
931   }
932
933   void
934   TMEDNamedPointCoords
935   ::Init(vtkIdType theNbPoints,
936          vtkIdType theDim,
937          const MED::PGrilleInfo& theInfo)
938   {
939     TNamedPointCoords::Init(theNbPoints,theDim);
940   }
941
942   std::string 
943   TMEDNamedPointCoords
944   ::GetNodeName(vtkIdType theObjID) const
945   {
946     if(myNodeInfo)
947       return myNodeInfo->GetElemName(theObjID);
948     return TNamedPointCoords::GetNodeName(theObjID);
949   }
950
951
952   //---------------------------------------------------------------
953   vtkIdType
954   TMEDSubProfile
955   ::GetElemObjID(vtkIdType theID) const
956   {
957     if(myIsElemNum)
958       return myElemNum[theID];
959     else
960       return theID;
961   }
962   
963
964   //---------------------------------------------------------------
965   void
966   TMEDGauss
967   ::LessThan(const PGaussImpl& theGauss,
968              bool& theResult) const
969   {
970     TGaussImpl::LessThan(theGauss,theResult);
971     if(myGaussInfo){
972       if(PMEDGauss aGauss = theGauss){
973         const MED::TGaussInfo& aLeft = myGaussInfo;
974         const MED::TGaussInfo& aReight = aGauss->myGaussInfo;
975         theResult = MED::TGaussInfo::TLess()(aLeft,aReight);
976       }
977     }
978   }
979
980
981   //---------------------------------------------------------------
982   TGaussPointID
983   TMEDGaussSubMesh
984   ::GetObjID(vtkIdType theID,
985              vtkIdType theStartID) const
986   {
987     TCellID aCellID = theID / myGauss->myNbPoints;
988     TLocalPntID aLocalPntID = theID % myGauss->myNbPoints;
989     
990     if(myIsElemNum)
991       aCellID = myElemNum[aCellID];
992     else
993       aCellID += theStartID;
994
995     return TGaussPointID(aCellID,aLocalPntID);
996   }
997   
998
999   //---------------------------------------------------------------
1000   void
1001   TMEDSubMesh
1002   ::Init(const MED::PElemInfo& theElemInfo)
1003   {
1004     myIsElemNum = theElemInfo->IsElemNum();
1005
1006     if(myIsElemNum)
1007       myElemNum = theElemInfo->myElemNum;
1008
1009     if(theElemInfo->IsElemNames())
1010       myElemInfo = theElemInfo;
1011   }
1012
1013
1014   void
1015   TMEDSubMesh
1016   ::Init(const MED::PGrilleInfo& theGrilleInfo)
1017   {
1018     myIsElemNum = MED::eFAUX;
1019     // must be implemented
1020   }
1021
1022   vtkIdType
1023   TMEDSubMesh
1024   ::GetElemObjID(vtkIdType theID) const
1025   {
1026     if(myIsElemNum)
1027       return myElemNum[theID];
1028     else
1029       return TSubMeshImpl::GetElemObjID(theID);
1030   }
1031
1032   std::string 
1033   TMEDSubMesh
1034   ::GetElemName(vtkIdType theObjID) const
1035   {
1036     if(myElemInfo)
1037       return myElemInfo->GetElemName(theObjID);
1038     return TSubMeshImpl::GetElemName(theObjID);
1039   }
1040
1041   struct TSetIsDone
1042   {
1043     bool& myIsDone;
1044     TSetIsDone(bool& theIsDone):
1045       myIsDone(theIsDone)
1046     {}
1047
1048     ~TSetIsDone()
1049     {
1050       myIsDone = true;
1051     }
1052
1053   };
1054 }
1055
1056
1057 //---------------------------------------------------------------
1058 extern "C"
1059 VISU_Convertor* 
1060 CreateConvertor(const string& theFileName)
1061 {
1062   if(MED::PWrapper aMed = MED::CrWrapper(theFileName,true))
1063     return new VISU_MedConvertor(theFileName);
1064   return NULL;
1065 }
1066
1067 VISU_MedConvertor
1068 ::VISU_MedConvertor(const string& theFileName):
1069   myIsEntitiesDone(false),
1070   myIsFieldsDone(false),
1071   myIsGroupsDone(false),
1072   myIsMinMaxDone(false)
1073 {
1074   myFileInfo.setFile(QString(theFileName.c_str()));
1075   myName = myFileInfo.baseName().latin1();
1076 }
1077
1078
1079 //---------------------------------------------------------------
1080 VISU_Convertor* 
1081 VISU_MedConvertor
1082 ::BuildEntities()
1083 {
1084   if(myIsEntitiesDone)
1085     return this;
1086
1087   TSetIsDone aSetIsDone(myIsEntitiesDone);
1088   TTimerLog aTimerLog(MYDEBUG,"BuildEntities");
1089   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1090
1091   TInt aNbMeshes = aMed->GetNbMeshes();
1092   TMeshMap& aMeshMap = myMeshMap;
1093
1094   INITMSG(MYDEBUG,"BuildEntities aNbMeshes = "<<aNbMeshes<<"\n");
1095
1096   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
1097 #ifndef _DEXCEPT_
1098     try{
1099 #endif
1100       TTimerLog aTimerLog(MYDEBUG,"GetPMeshInfo");
1101
1102       MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
1103       std::string aMeshName = aMeshInfo->GetName();
1104       TInt aDim = aMeshInfo->GetDim();
1105       MED::EMaillage aType = aMeshInfo->GetType();
1106         
1107       // creating TMesh structure and TMeshOnEntityMap         
1108       PMEDMesh aMesh = aMeshMap[aMeshName](new TMEDMesh());
1109       
1110       aMesh->myDim = aDim;
1111       aMesh->myName = aMeshName;
1112       aMesh->myMeshInfo = aMeshInfo;
1113       aMesh->myNamedPointCoords(new TMEDNamedPointCoords());
1114       
1115       INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<
1116               "; aDim = "<<aDim<<"\n");
1117
1118       if(aType == MED::eNON_STRUCTURE){
1119
1120         if(MED::PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo)){
1121           MED::TEntityInfo anEntityInfo = aMed->GetEntityInfo(aMeshInfo);
1122
1123           aMesh->myNbPoints = aNodeInfo->GetNbElem();
1124           aMesh->myEntityInfo = anEntityInfo;
1125         
1126         
1127 #ifndef _DEXCEPT_
1128           try{
1129 #endif
1130             INITMSG(MYDEBUG,"myNbPoints = "<<aMesh->myNbPoints<<
1131                     "; anEntityInfo.size() = "<<anEntityInfo.size()<<
1132                     "\n");
1133             
1134             BuildMeshOnEntityMap(aMesh,
1135                                  anEntityInfo,
1136                                  aNodeInfo,
1137                                aMed);
1138             
1139 #ifndef _DEXCEPT_
1140           }catch(std::exception& exc){
1141             MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1142           }catch(...){
1143             MSG(MYDEBUG,"Unknown exception !!!");
1144           }
1145 #endif
1146         }
1147       } // NON STRUCTURED MESH
1148       else {
1149         MED::PGrilleInfo aGrilleInfo = aMed->GetPGrilleInfo(aMeshInfo);
1150
1151         MED::TEntityInfo anEntityInfo;
1152         anEntityInfo[MED::eNOEUD][MED::ePOINT1] = aGrilleInfo->GetNbNodes();
1153         anEntityInfo[aGrilleInfo->GetEntity()][aGrilleInfo->GetGeom()] = aGrilleInfo->GetNbCells();
1154         
1155         aMesh->myNbPoints   = aGrilleInfo->GetNbNodes();
1156         aMesh->myEntityInfo = anEntityInfo;
1157
1158 #ifndef _DEXCEPT_
1159         try{
1160 #endif
1161           BEGMSG(MYDEBUG,"anEntityInfo.size() = "<<anEntityInfo.size()<<"\n");
1162           
1163           BuildMeshGrilleOnEntityMap(aMesh,
1164                                      anEntityInfo,
1165                                      aGrilleInfo,
1166                                      aMed);
1167           
1168 #ifndef _DEXCEPT_
1169         }catch(std::exception& exc){
1170           MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1171         }catch(...){
1172           MSG(MYDEBUG,"Unknown exception !!!");
1173         }
1174 #endif
1175
1176       }
1177
1178 #ifndef _DEXCEPT_
1179     }catch(std::exception& exc){
1180       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1181     }catch(...){
1182       MSG(MYDEBUG,"Unknown exception !!!");
1183     }
1184 #endif
1185   } 
1186
1187   return this; 
1188 }
1189
1190
1191 //---------------------------------------------------------------
1192 VISU_Convertor* 
1193 VISU_MedConvertor
1194 ::BuildFields()
1195 {
1196   if(myIsFieldsDone)
1197     return this;
1198
1199   TSetIsDone aSetIsDone(myIsFieldsDone);
1200   TTimerLog aTimerLog(MYDEBUG,"BuildFields");
1201   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1202
1203   TInt aNbMeshes = aMed->GetNbMeshes();
1204   TMeshMap& aMeshMap = myMeshMap;
1205
1206   INITMSG(MYDEBUG,"BuildFields - aNbMeshes = "<<aNbMeshes<<"\n");
1207
1208   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
1209 #ifndef _DEXCEPT_
1210     try{
1211 #endif
1212       TTimerLog aTimerLog(MYDEBUG,"GetPMeshInfo");
1213
1214       MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
1215       std::string aMeshName = aMeshInfo->GetName();
1216       
1217       TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName);
1218       if(anIter == aMeshMap.end())
1219         continue;
1220       PMEDMesh aMesh = anIter->second;
1221
1222       INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<"'\n");
1223 #ifndef _DEXCEPT_
1224       try{
1225 #endif
1226         MED::TEntityInfo anEntityInfo = aMed->GetEntityInfo(aMeshInfo);
1227
1228         BuildFieldMap(aMesh,
1229                       anEntityInfo,
1230                       aMed);
1231 #ifndef _DEXCEPT_
1232       }catch(std::exception& exc){
1233         MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1234       }catch(...){
1235         MSG(MYDEBUG,"Unknown exception !!!");
1236       }
1237 #endif
1238
1239 #ifndef _DEXCEPT_
1240     }catch(std::exception& exc){
1241       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1242     }catch(...){
1243       MSG(MYDEBUG,"Unknown exception !!!");
1244     }
1245 #endif
1246   } 
1247
1248   return this; 
1249 }
1250
1251
1252 //---------------------------------------------------------------
1253 VISU_Convertor* 
1254 VISU_MedConvertor
1255 ::BuildMinMax()
1256 {
1257   if(myIsMinMaxDone)
1258     return this;
1259
1260   TSetIsDone aSetIsDone(myIsMinMaxDone);
1261   TTimerLog aTimerLog(MYDEBUG,"BuildMinMax");
1262   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1263
1264   MED::TKey2Gauss aKey2Gauss = MED::GetKey2Gauss(aMed);
1265   MED::TMKey2Profile aMKey2Profile = MED::GetMKey2Profile(aMed);
1266
1267   TInt aNbMeshes = aMed->GetNbMeshes();
1268   TMeshMap& aMeshMap = myMeshMap;
1269
1270   INITMSG(MYDEBUG,"BuildMinMax - aNbMeshes = "<<aNbMeshes<<"\n");
1271
1272   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
1273 #ifndef _DEXCEPT_
1274     try{
1275 #endif
1276       TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPMeshInfo");
1277
1278       MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
1279       std::string aMeshName = aMeshInfo->GetName();
1280       
1281       TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName);
1282       if(anIter == aMeshMap.end())
1283         continue;
1284       PMEDMesh aMesh = anIter->second;
1285
1286 #ifndef _DEXCEPT_
1287       try{
1288 #endif
1289         TInt aNbFields = aMed->GetNbFields(); 
1290
1291         INITMSG(MYDEBUG,
1292                 "- aMeshName = '"<<aMeshName<<"'"<<
1293                 "; aNbFields = "<<aNbFields<<"\n");
1294
1295         MED::TEntityInfo anEntityInfo = aMed->GetEntityInfo(aMeshInfo);
1296
1297         for(TInt iField = 1; iField <= aNbFields; iField++){
1298           TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPFieldInfo()");
1299           MED::PFieldInfo aFieldInfo = aMed->GetPFieldInfo(aMeshInfo,iField);
1300           std::string aFieldName = aFieldInfo->GetName();
1301           INITMSG(MYDEBUG,"- aFieldName = '"<<aFieldName<<"'\n");
1302           
1303           MED::TGeom2Size aGeom2Size;
1304           MED::EEntiteMaillage aMEntity;
1305           TInt aNbTimeStamps = aMed->GetNbTimeStamps(aFieldInfo,
1306                                                      anEntityInfo,
1307                                                      aMEntity,
1308                                                      aGeom2Size);
1309           if(aNbTimeStamps < 1)
1310             continue;
1311         
1312           TEntity aVEntity = MEDEntityToVTK(aMEntity);
1313           PMEDMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
1314           TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1315           PMEDField aField = aFieldMap[aFieldName];
1316         
1317           TInt aNbComp = aField->myNbComp;
1318           int aNbComp2 = aNbComp;
1319           if(aNbComp == 2 || aNbComp == 4)
1320             aNbComp2 = 2;
1321           else if(aNbComp > 4)
1322             aNbComp2 = 3;
1323
1324           TMinMaxArr& aMinMaxArr = aField->myMinMaxArr;
1325           TSetIsDone aSetIsDone(aField->myIsMinMaxInitilized);
1326           for(TInt iTimeStamp = aNbTimeStamps; iTimeStamp >= 1; iTimeStamp--){
1327             TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPTimeStampInfo()");
1328             INITMSG(MYDEBUG,"- iTimeStamp = "<<iTimeStamp<<endl);
1329             
1330 #ifndef _DEXCEPT_
1331             CASCatch_TRY{ 
1332               try{
1333 #endif
1334                 MED::PTimeStampInfo aTimeStampInfo = aMed->GetPTimeStampInfo(aFieldInfo,
1335                                                                              aMEntity,
1336                                                                              aGeom2Size,
1337                                                                              iTimeStamp);
1338                 
1339                 MED::PTimeStampVal aTimeStampVal = aMed->GetPTimeStampVal(aTimeStampInfo,
1340                                                                           aMKey2Profile,
1341                                                                           aKey2Gauss);
1342                 
1343                 const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->GetGeom2Gauss();
1344                 
1345                 const MED::TTimeStampVal& aTimeStampValRef = aTimeStampVal;
1346                 
1347                 const MED::TGeom2Value& aGeom2Value = aTimeStampValRef.myGeom2Value;
1348                 MED::TGeom2Value::const_iterator anIter = aGeom2Value.begin();
1349                 for(; anIter != aGeom2Value.end(); anIter++){
1350                   const MED::TMeshValue& aMMeshValue = anIter->second;
1351                   MED::EGeometrieElement aMGeom = anIter->first;
1352                   
1353                   TInt aNbElem = aMMeshValue.myNbElem;
1354                   TInt aNbGauss = aMMeshValue.myNbGauss;
1355                   
1356                   MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom);
1357                   if(aGaussIter == aGeom2Gauss.end())
1358                     aNbGauss = 1;
1359                   
1360                   INITMSG(MYDEBUG,
1361                           "- aMGeom = "<<aMGeom<<
1362                           "; aNbElem = "<<aNbElem<<
1363                           "; aNbGauss = "<<aNbGauss<<
1364                           endl);
1365                   
1366                   // To calculate min/max per components
1367                   for(TInt iElem = 0; iElem < aNbElem; iElem++){
1368                     MED::TCValueSliceArr aMValueSliceArr = aMMeshValue.GetCompValueSliceArr(iElem);
1369                     for(TInt iComp = 0; iComp < aNbComp; iComp++){
1370                       const MED::TCValueSlice& aMValueSlice = aMValueSliceArr[iComp];
1371                       TMinMax& aMinMax = aMinMaxArr[iComp+1];
1372                       vtkFloatingPointType& aMin = aMinMax.first;
1373                       vtkFloatingPointType& aMax = aMinMax.second;
1374                       for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
1375                         const vtkFloatingPointType& aVal = aMValueSlice[iGauss];
1376                         aMin = min(aMin,aVal);
1377                         aMax = max(aMax,aVal);
1378                       }
1379                     }
1380                   }
1381                   
1382                   // To calculate min/max per vector modulus
1383                   TMinMax& aMinMax = aMinMaxArr[0];
1384                   vtkFloatingPointType& aMin = aMinMax.first;
1385                   vtkFloatingPointType& aMax = aMinMax.second;
1386                   for(TInt iElem = 0; iElem < aNbElem; iElem++){
1387                     MED::TCValueSliceArr aMValueSliceArr = aMMeshValue.GetGaussValueSliceArr(iElem);
1388                     for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
1389                       const MED::TCValueSlice& aMValueSlice = aMValueSliceArr[iGauss];
1390                       vtkFloatingPointType aValue = 0.0;
1391                       for(TInt iComp = 0; iComp < aNbComp2; iComp++){
1392                         vtkFloatingPointType aVal = aMValueSlice[iComp];
1393                         aValue += aVal*aVal;
1394                       }
1395                       aValue = sqrt(aValue);
1396                       aMin = min(aMin,aValue);
1397                       aMax = max(aMax,aValue);
1398                     }
1399                   }
1400                 }
1401 #ifndef _DEXCEPT_
1402               }catch(std::exception& exc){
1403                 MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1404               }catch(...){
1405                 MSG(MYDEBUG,"Unknown exception !!!");
1406               }
1407             }CASCatch_CATCH(Standard_Failure){
1408               Handle(Standard_Failure) aFail = Standard_Failure::Caught();          
1409               MSG(MYDEBUG,"Follow signal was occured in:\n"<<aFail->GetMessageString());
1410             }
1411 #endif
1412           }
1413           for(TInt iComp = 0; iComp <= aNbComp; iComp++){
1414             VISU::TMinMax aMinMax = aField->GetMinMax(iComp);
1415             INITMSG(MYDEBUG,"- "<<iComp<<": "<<aMinMax.first<<"; "<<aMinMax.second<<endl);
1416           }
1417         }
1418 #ifndef _DEXCEPT_
1419       }catch(std::exception& exc){
1420         MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1421       }catch(...){
1422         MSG(MYDEBUG,"Unknown exception !!!");
1423       }
1424 #endif
1425
1426 #ifndef _DEXCEPT_
1427     }catch(std::exception& exc){
1428       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1429     }catch(...){
1430       MSG(MYDEBUG,"Unknown exception !!!");
1431     }
1432 #endif
1433   }
1434
1435   return this; 
1436 }
1437
1438
1439 //---------------------------------------------------------------
1440 VISU_Convertor* 
1441 VISU_MedConvertor
1442 ::BuildGroups()
1443 {
1444   if(myIsGroupsDone)
1445     return this;
1446
1447   TSetIsDone aSetIsDone(myIsGroupsDone);
1448   TTimerLog aTimerLog(MYDEBUG,"BuildGroups");
1449   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1450
1451   TInt aNbMeshes = aMed->GetNbMeshes();
1452   TMeshMap& aMeshMap = myMeshMap;
1453
1454   INITMSG(MYDEBUG,"BuildGroups - aNbMeshes = "<<aNbMeshes<<"\n");
1455
1456   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
1457 #ifndef _DEXCEPT_
1458     try{
1459 #endif
1460       TTimerLog aTimerLog(MYDEBUG,"GetPMeshInfo");
1461
1462       MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
1463       std::string aMeshName = aMeshInfo->GetName();      
1464
1465       TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName);
1466       if(anIter == aMeshMap.end())
1467         continue;
1468       PMEDMesh aMesh = anIter->second;
1469
1470       INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<"'\n");
1471
1472       MED::TEntityInfo anEntityInfo = aMed->GetEntityInfo(aMeshInfo);
1473       
1474       MED::TEntity2TGeom2ElemInfo anEntity2TGeom2ElemInfo = 
1475         MED::GetEntity2TGeom2ElemInfo(aMed,aMeshInfo,anEntityInfo);
1476       
1477 #ifndef _DEXCEPT_
1478       try{
1479 #endif
1480         MED::TFamilyInfoSet aFamilyInfoSet = MED::GetFamilyInfoSet(aMed,aMeshInfo);
1481         
1482         BuildFamilyMap(aMesh,
1483                        anEntityInfo,
1484                        anEntity2TGeom2ElemInfo,
1485                        aFamilyInfoSet,
1486                        aMed);
1487         
1488         BuildGroupMap(aMesh,
1489                       aFamilyInfoSet);
1490 #ifndef _DEXCEPT_
1491       }catch(std::exception& exc){
1492         MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1493       }catch(...){
1494         MSG(MYDEBUG,"Unknown exception !!!");
1495       }
1496 #endif
1497
1498 #ifndef _DEXCEPT_
1499     }catch(std::exception& exc){
1500       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1501     }catch(...){
1502       MSG(MYDEBUG,"Unknown exception !!!");
1503     }
1504 #endif
1505   } 
1506
1507   return this; 
1508 }
1509
1510
1511 //---------------------------------------------------------------
1512 int
1513 VISU_MedConvertor
1514 ::LoadMeshOnEntity(VISU::PMeshImpl theMesh,
1515                    VISU::PMeshOnEntityImpl theMeshOnEntity)
1516 {
1517   TTimerLog aTimerLog(MYDEBUG,"LoadMeshOnEntity");
1518   INITMSG(MYDEBUG,"LoadMeshOnEntity"<<endl);
1519
1520   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1521   const TEntity& anEntity = theMeshOnEntity->myEntity;
1522
1523   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
1524   if(anEntity == NODE_ENTITY){
1525     isPointsUpdated += LoadPoints(aMed,theMesh);
1526   }else{
1527     isPointsUpdated += LoadPoints(aMed,theMesh);
1528     isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity);
1529   }
1530
1531   return (isPointsUpdated || isCellsOnEntityUpdated);
1532 }
1533
1534
1535 //---------------------------------------------------------------
1536 int
1537 VISU_MedConvertor
1538 ::LoadFamilyOnEntity(VISU::PMeshImpl theMesh,
1539                      VISU::PMeshOnEntityImpl theMeshOnEntity, 
1540                      VISU::PFamilyImpl theFamily)
1541 {
1542   TTimerLog aTimerLog(MYDEBUG,"LoadFamilyOnEntity");
1543   INITMSG(MYDEBUG,"LoadFamilyOnEntity"<<endl);
1544
1545   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1546   const TEntity& anEntity = theMeshOnEntity->myEntity;
1547
1548   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
1549   if(anEntity == NODE_ENTITY){
1550     isPointsUpdated += LoadPointsOnFamily(aMed,theMesh,theFamily);
1551   }else{
1552     isPointsUpdated += LoadPoints(aMed,theMesh);
1553     isCellsOnEntityUpdated += LoadCellsOnFamily(aMed,theMesh,theMeshOnEntity,theFamily);
1554   }
1555
1556   return (isPointsUpdated || isCellsOnEntityUpdated);
1557 }
1558
1559
1560 //---------------------------------------------------------------
1561 int
1562 VISU_MedConvertor
1563 ::LoadMeshOnGroup(VISU::PMeshImpl theMesh, 
1564                   const VISU::TFamilySet& theFamilySet)
1565 {
1566   TTimerLog aTimerLog(MYDEBUG,"LoadMeshOnGroup");
1567   INITMSG(MYDEBUG,"LoadMeshOnGroup"<<endl);
1568
1569   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1570   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
1571   TFamilySet::const_iterator aFamilyIter = theFamilySet.begin();
1572   for(; aFamilyIter != theFamilySet.end(); aFamilyIter++){
1573     PMEDFamily aFamily = *aFamilyIter;
1574     const TEntity& anEntity = aFamily->myEntity;
1575     const PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity];
1576     isPointsUpdated += LoadPoints(aMed,theMesh);
1577     if(anEntity == NODE_ENTITY){
1578       isPointsUpdated += LoadPointsOnFamily(aMed,theMesh,aFamily);
1579     }else{
1580       isCellsOnEntityUpdated += LoadCellsOnFamily(aMed,theMesh,aMeshOnEntity,aFamily);
1581     }
1582   }
1583
1584   return (isPointsUpdated || isCellsOnEntityUpdated);
1585 }
1586
1587
1588 //---------------------------------------------------------------
1589 int
1590 VISU_MedConvertor
1591 ::LoadValForTimeOnMesh(VISU::PMeshImpl theMesh, 
1592                        VISU::PMeshOnEntityImpl theMeshOnEntity, 
1593                        VISU::PFieldImpl theField, 
1594                        VISU::PValForTimeImpl theValForTime)
1595 {
1596   TTimerLog aTimerLog(MYDEBUG,"LoadValForTimeOnMesh");
1597   INITMSG(MYDEBUG,"LoadValForTimeOnMesh"<<endl);
1598
1599   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1600
1601   const TEntity& anEntity = theMeshOnEntity->myEntity;
1602   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
1603   isPointsUpdated += LoadPoints(aMed,theMesh);
1604   if(anEntity != NODE_ENTITY)
1605     isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity);
1606   int isFieldUpdated = LoadValForTimeOnMesh(aMed,theMesh,theMeshOnEntity,theField,theValForTime);
1607   
1608   return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
1609 }
1610
1611
1612 //---------------------------------------------------------------
1613 int
1614 VISU_MedConvertor
1615 ::LoadValForTimeOnGaussPts(VISU::PMeshImpl theMesh, 
1616                            VISU::PMeshOnEntityImpl theMeshOnEntity, 
1617                            VISU::PFieldImpl theField, 
1618                            VISU::PValForTimeImpl theValForTime)
1619 {
1620   TTimerLog aTimerLog(MYDEBUG,"LoadValForTimeOnGaussPts");
1621   INITMSG(MYDEBUG,"LoadValForTimeOnGaussPts"<<endl);
1622
1623   MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
1624
1625   const TEntity& anEntity = theMeshOnEntity->myEntity;
1626   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
1627   if(anEntity != NODE_ENTITY)
1628     isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity);
1629   int isFieldUpdated = LoadValForTimeOnGaussPts(aMed,theMesh,theMeshOnEntity,theField,theValForTime);
1630   
1631   return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
1632 }
1633
1634
1635 //---------------------------------------------------------------
1636 int 
1637 VISU_MedConvertor
1638 ::LoadPoints(const MED::PWrapper& theMed,
1639              VISU::PMEDMesh theMesh) 
1640 {
1641   TTimerLog aTimerLog(MYDEBUG,"LoadPoints");
1642   try{
1643     //Check on existing family
1644     PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
1645     aMeshOnEntity->myMeshName = theMesh->myName;
1646     aMeshOnEntity->myEntity = NODE_ENTITY;
1647
1648     INITMSG(MYDEBUG,"LoadPoints - theMesh->myIsDone = "<<theMesh->myIsDone<<"'\n");
1649
1650     //Check on loading already done
1651     if(theMesh->myIsDone)
1652       return 0;
1653
1654     MED::EMaillage aType = theMesh->myMeshInfo->GetType();
1655     
1656     if(aType == MED::eNON_STRUCTURE){
1657       //Main part of code
1658       MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo);
1659       TInt aNbElem = aNodeInfo->GetNbElem();
1660       TInt aDim = theMesh->myDim;
1661       
1662       PMEDNamedPointCoords aNamedPointCoords = theMesh->myNamedPointCoords;
1663       TMEDNamedPointCoords& aCoords = aNamedPointCoords;
1664       aCoords.Init(aNbElem,aDim,aNodeInfo);
1665       
1666       for(int iDim = 0; iDim < aDim; iDim++)
1667         aCoords.GetName(iDim) = aNodeInfo->GetCoordName(iDim);
1668       
1669       for(int iElem = 0; iElem < aNbElem; iElem++){
1670         TCoordSlice aVCoordSlice = aCoords.GetCoordSlice(iElem);
1671         MED::TCCoordSlice aMCoordSlice = aNodeInfo->GetCoordSlice(iElem);
1672         for(int iDim = 0; iDim < aDim; iDim++)
1673           aVCoordSlice[iDim] = aMCoordSlice[iDim];
1674       }
1675       
1676       TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
1677       PMEDSubMesh aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new TMEDSubMesh());
1678       
1679       aSubMesh->Init(MED::PElemInfo(aNodeInfo)); 
1680       aSubMesh->myNbCells = theMesh->myNbPoints;
1681       aSubMesh->myCellsSize = 2*theMesh->myNbPoints;
1682       
1683       TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1684       aCell2Connect.resize(aNbElem);
1685       for (int iElem = 0; iElem < aNbElem; iElem++)
1686         aCell2Connect[iElem] = VISU::TConnect(1,iElem);
1687     } // END NON_STRUCTURED
1688     else { // STRUCTURED
1689       //Main part of code
1690       MED::PGrilleInfo aGrilleInfo = theMed->GetPGrilleInfo(theMesh->myMeshInfo);
1691       TInt aNbElem = aGrilleInfo->GetNbNodes();
1692       TInt aDim = theMesh->myDim;
1693       
1694       PMEDNamedPointCoords aNamedPointCoords = theMesh->myNamedPointCoords;
1695       TMEDNamedPointCoords& aCoords = aNamedPointCoords;
1696       aCoords.Init(aNbElem,aDim,aGrilleInfo);
1697       
1698       for(int iDim = 0; iDim < aDim; iDim++)
1699         aCoords.GetName(iDim) = aGrilleInfo->GetCoordName(iDim);
1700       
1701       for(int iElem = 0; iElem < aNbElem; iElem++){
1702         TCoordSlice aVCoordSlice = aCoords.GetCoordSlice(iElem);
1703         MED::TNodeCoord aMCoord = aGrilleInfo->GetCoord(iElem);
1704         for(int iDim = 0; iDim < aDim; iDim++){
1705           aVCoordSlice[iDim] = aMCoord[iDim];
1706         }
1707       }
1708       
1709       TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
1710       PMEDSubMesh aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new TMEDSubMesh());
1711       
1712       aSubMesh->Init(aGrilleInfo); 
1713       aSubMesh->myNbCells = theMesh->myNbPoints;
1714       aSubMesh->myCellsSize = 2*theMesh->myNbPoints;
1715       
1716       TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1717       aCell2Connect.resize(aNbElem);
1718       for (int iElem = 0; iElem < aNbElem; iElem++)
1719         aCell2Connect[iElem] = VISU::TConnect(1,iElem);
1720       
1721     }
1722     
1723     theMesh->myIsDone = true;
1724     
1725     return 1;
1726
1727   }catch(std::exception& exc){
1728     throw;
1729   }catch(...){
1730     EXCEPTION(runtime_error,"Unknown exception !!!");
1731   }
1732
1733   return 0;
1734 }
1735
1736
1737 //---------------------------------------------------------------
1738 int 
1739 VISU_MedConvertor
1740 ::LoadPointsOnFamily(const MED::PWrapper& theMed,
1741                      const VISU::PMEDMesh theMesh, 
1742                      const VISU::PMEDFamily theFamily) 
1743 {
1744   TTimerLog aTimerLog(MYDEBUG,"LoadPointsOnFamily");
1745   try{
1746     if(theFamily->myIsDone) 
1747       return 0;
1748
1749     //Main part of code
1750     MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo);
1751     TInt aNbElem = aNodeInfo->GetNbElem();
1752
1753     if(aNbElem > 0){
1754       TInt anId = theFamily->myId;
1755       TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1];
1756       for(TInt iElem = 0; iElem < aNbElem; iElem++) 
1757         if(aNodeInfo->GetFamNum(iElem) == anId)
1758           aSubMeshID.push_back(iElem);
1759     }
1760
1761     theFamily->myIsDone = true;
1762
1763     return 1;
1764
1765   }catch(std::exception& exc){
1766     throw;
1767   }catch(...){
1768     EXCEPTION(runtime_error,"Unknown exception !!!");
1769   }
1770
1771   return 0;
1772 }
1773
1774
1775 //---------------------------------------------------------------
1776 int 
1777 VISU_MedConvertor
1778 ::LoadCellsOnEntity(const MED::PWrapper& theMed,
1779                     const VISU::PMEDMesh theMesh,
1780                     const VISU::PMEDMeshOnEntity theMeshOnEntity)
1781 {
1782   TTimerLog aTimerLog(MYDEBUG,"LoadCellsOnEntity");
1783 #ifndef _DEXCEPT_
1784   try{
1785 #endif
1786     const TEntity& aVEntity = theMeshOnEntity->myEntity;
1787     const MED::EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity);
1788
1789     INITMSG(MYDEBUG,"LoadCellsOnEntity - aVEntity = "<<aVEntity<<"\n");
1790
1791     if(theMeshOnEntity->myIsDone)
1792       return 0;
1793
1794     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
1795
1796     MED::EMaillage aType = aMeshInfo->GetType();
1797
1798     if(aType == MED::eSTRUCTURE){
1799       
1800       MED::PGrilleInfo aGrilleInfo = theMed->GetPGrilleInfo(aMeshInfo);
1801       TInt aNbPoints = aGrilleInfo->GetNbNodes();
1802       
1803       std::map<TInt,TInt> aNodeIdMap;
1804       EBooleen anIsNodeNum = MED::eFAUX;
1805       
1806       const MED::TGeom2Size& aGeom2Size = theMeshOnEntity->myGeom2Size;
1807       MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
1808       TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
1809       
1810       for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
1811         const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
1812         VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
1813         INITMSG(MYDEBUG,"aMGeom = "<<aMGeom<<"; aEGeom = "<<aEGeom<<"\n");
1814         {
1815           vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
1816           INITMSG(MYDEBUG,"aVNbNodes = "<<aVNbNodes<<"\n");
1817         
1818           TInt aNbElem = aGrilleInfo->GetNbCells();
1819           
1820           if(aNbElem > 0){
1821             PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new TMEDSubMesh());
1822             
1823             aSubMesh->Init(aGrilleInfo); 
1824             aSubMesh->myNbCells = aNbElem;      
1825             aSubMesh->myCellsSize = aNbElem*(aVNbNodes+1);
1826             
1827             TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1828             aCell2Connect.resize(aNbElem);
1829             
1830             TInt aMNbNodes = MEDGeom2NbNodes(aMGeom);
1831             TVector<TInt> aConnect(aMNbNodes);
1832             
1833             for(TInt iElem = 0; iElem < aNbElem; iElem++) {
1834               MED::TIntVector aConn = aGrilleInfo->GetConn(iElem);
1835               TConnect& anArray = aCell2Connect[iElem];
1836               anArray.resize(aVNbNodes);
1837               
1838               if(anIsNodeNum){
1839                 for(TInt iConn = 0; iConn < aMNbNodes; iConn++){
1840                   aConnect[iConn] = aNodeIdMap[aConn[iConn] - 1];
1841                 }
1842               }else{
1843                 for(int iConn = 0; iConn < aMNbNodes; ++iConn){
1844                   aConnect[iConn] = aConn[iConn];
1845                 }
1846               }
1847               
1848               switch(aMGeom){
1849               case MED::eQUAD4:
1850                 anArray[0] = aConnect[0];
1851                 anArray[1] = aConnect[2];
1852                 anArray[2] = aConnect[3];
1853                 anArray[3] = aConnect[1];
1854                 break;
1855               case MED::eHEXA8:
1856                 anArray[0] = aConnect[0];
1857                 anArray[1] = aConnect[2];
1858                 anArray[2] = aConnect[3];
1859                 anArray[3] = aConnect[1];
1860                 anArray[4] = aConnect[4];
1861                 anArray[5] = aConnect[6];
1862                 anArray[6] = aConnect[7];
1863                 anArray[7] = aConnect[5];
1864                 break;
1865               default:
1866                 for(int iNode = 0; iNode < aVNbNodes; iNode++) 
1867                   anArray[iNode] = aConnect[iNode];
1868               }
1869               
1870               for(int iNode = 0; iNode < aVNbNodes; iNode++) 
1871                 if(anArray[iNode] < 0 || aNbPoints <= anArray[iNode])
1872                   EXCEPTION(runtime_error,"LoadCellsOnEntity - "<<
1873                             " aNbPoints("<<aNbPoints<<") "<<
1874                             "<= anArray["<<iElem<<"]"<<
1875                             "["<<iNode<<"]"<<
1876                             "("<<anArray[iNode]<<") < 0");
1877             }
1878           }
1879         }
1880       }
1881
1882       theMeshOnEntity->myIsDone = true;
1883       
1884       return 1;
1885       
1886     }
1887     
1888     MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
1889     TInt aNbPoints = aNodeInfo->GetNbElem();
1890
1891     std::map<TInt,TInt> aNodeIdMap;
1892 #ifdef _EDF_NODE_IDS_
1893     EBooleen anIsNodeNum = MED::eFAUX;
1894 #else
1895     EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
1896     if(anIsNodeNum){
1897       for(TInt i = 0; i < aNbPoints; i++){
1898         aNodeIdMap[aNodeInfo->GetElemNum(i)-1] = i;
1899       }
1900     }
1901 #endif
1902
1903     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity->myGeom2Size;
1904     MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
1905     TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
1906
1907     for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
1908       const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
1909       VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
1910       INITMSG(MYDEBUG,"aMGeom = "<<aMGeom<<"; aEGeom = "<<aEGeom<<"\n");
1911       switch(aMGeom){
1912       case MED::ePOLYGONE: {
1913         MED::PPolygoneInfo aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom);
1914         TInt aNbElem = aPolygoneInfo->GetNbElem();
1915         if(aNbElem > 0){
1916           PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new TMEDSubMesh());
1917           
1918           aSubMesh->Init(MED::PElemInfo(aPolygoneInfo)); 
1919           aSubMesh->myNbCells = aNbElem;      
1920
1921           TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1922           aCell2Connect.resize(aNbElem);
1923           
1924           for(TInt iElem = 0; iElem < aNbElem; iElem++) {
1925             MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
1926             TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
1927             aSubMesh->myCellsSize += aNbConn;
1928             TConnect& anArray = aCell2Connect[iElem];
1929             anArray.resize(aNbConn);
1930             for(TInt iConn = 0; iConn < aNbConn; iConn++)
1931               anArray[iConn] = aConnSlice[iConn] - 1;
1932           }
1933         }
1934         break;
1935       }
1936       case MED::ePOLYEDRE: {
1937         MED::PPolyedreInfo aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom);
1938         TInt aNbElem = aPolyedreInfo->GetNbElem();
1939         
1940         if(aNbElem > 0){
1941           PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new TMEDSubMesh());
1942           
1943           aSubMesh->Init((MED::PElemInfo)aPolyedreInfo); 
1944           aSubMesh->myNbCells = aNbElem;      
1945
1946           TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1947           aCell2Connect.resize(aNbElem);
1948           
1949           for(TInt iElem = 0; iElem < aNbElem; iElem++){
1950             MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
1951             TConnect& anArray = aCell2Connect[iElem];
1952             typedef std::set<TInt> TConnectSet;
1953             TConnectSet aConnectSet;
1954             TInt aNbFaces = aConnSliceArr.size();
1955             for(TInt iFace = 0; iFace < aNbFaces; iFace++){
1956               MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
1957               TInt aNbConn = aConnSlice.size();
1958               aSubMesh->myCellsSize += aNbConn;
1959               for(TInt iConn = 0; iConn < aNbConn; iConn++){
1960                 aConnectSet.insert(aConnSlice[iConn]);
1961               }
1962             }
1963           
1964             int aNbConn = aConnectSet.size();
1965             anArray.resize(aNbConn);
1966             TConnectSet::iterator anIter = aConnectSet.begin();
1967             for(int i = 0; anIter != aConnectSet.end(); anIter++, i++){
1968               TInt anId = *anIter;
1969               anArray[i] = anId - 1;
1970             }
1971           }
1972         }
1973
1974         break;
1975       }
1976       default: {
1977         vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
1978         INITMSG(MYDEBUG,"aVNbNodes = "<<aVNbNodes<<"\n");
1979         
1980         MED::PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aMGeom);
1981         TInt aNbElem = aCellInfo->GetNbElem();
1982         
1983         if(aNbElem > 0){
1984           PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new TMEDSubMesh());
1985           
1986           aSubMesh->Init((MED::PElemInfo)aCellInfo); 
1987           aSubMesh->myNbCells = aNbElem;      
1988           aSubMesh->myCellsSize = aNbElem*(aVNbNodes+1);
1989
1990           TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
1991           aCell2Connect.resize(aNbElem);
1992         
1993           TInt aMNbNodes = MEDGeom2NbNodes(aMGeom);
1994           TVector<TInt> aConnect(aMNbNodes);
1995         
1996           for(TInt iElem = 0; iElem < aNbElem; iElem++) {
1997             MED::TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
1998             TConnect& anArray = aCell2Connect[iElem];
1999             anArray.resize(aVNbNodes);
2000             
2001             if(anIsNodeNum){
2002               for(TInt iConn = 0; iConn < aMNbNodes; iConn++){
2003                 aConnect[iConn] = aNodeIdMap[aConnSlice[iConn] - 1];
2004               }
2005             }else{
2006               for(int iConn = 0; iConn < aMNbNodes; iConn++){
2007                 aConnect[iConn] = aConnSlice[iConn] - 1;
2008               }
2009             }
2010             
2011             switch(aMGeom){
2012 #if !(defined(VTK_QUADRATIC_EDGE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2013             case MED::eSEG3:
2014               anArray[0] = aConnect[0];
2015               anArray[2] = aConnect[1];  
2016
2017               anArray[1] = aConnect[2];
2018               break;
2019 #endif
2020 #if !(defined(VTK_QUADRATIC_TRIANGLE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2021             case MED::eTRIA6:
2022               anArray[0] = aConnect[0];
2023               anArray[2] = aConnect[1];  
2024               anArray[4] = aConnect[2];  
2025
2026               anArray[1] = aConnect[3];
2027               anArray[3] = aConnect[4];  
2028               anArray[5] = aConnect[5];  
2029               break;
2030 #endif
2031 #if !(defined(VTK_QUADRATIC_QUAD) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2032             case MED::eQUAD8:
2033               anArray[0] = aConnect[0];
2034               anArray[2] = aConnect[1];  
2035               anArray[4] = aConnect[2];  
2036               anArray[6] = aConnect[3];  
2037
2038               anArray[1] = aConnect[4];
2039               anArray[3] = aConnect[5];  
2040               anArray[5] = aConnect[6];  
2041               anArray[7] = aConnect[7];  
2042               break;
2043 #endif
2044 #if (defined(VTK_QUADRATIC_TETRA) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2045             case MED::eTETRA10:
2046               anArray[0] = aConnect[0];
2047               anArray[1] = aConnect[2];
2048               anArray[2] = aConnect[1];  
2049               anArray[3] = aConnect[3];  
2050
2051               anArray[4] = aConnect[6];
2052               anArray[5] = aConnect[5];
2053               anArray[6] = aConnect[4];  
2054
2055               anArray[7] = aConnect[7];  
2056               anArray[8] = aConnect[9];  
2057               anArray[9] = aConnect[8];  
2058               break;
2059 #endif
2060             case MED::eTETRA4:
2061               anArray[0] = aConnect[0];
2062               anArray[1] = aConnect[2];
2063               anArray[2] = aConnect[1];  
2064               anArray[3] = aConnect[3];  
2065               break;
2066 #if (defined(VTK_QUADRATIC_PYRAMID) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2067             case MED::ePYRA13:
2068               anArray[0] = aConnect[0];
2069               anArray[1] = aConnect[3];
2070               anArray[2] = aConnect[2];  
2071               anArray[3] = aConnect[1];  
2072               anArray[4] = aConnect[4];
2073
2074               anArray[5] = aConnect[5];
2075               anArray[6] = aConnect[8];  
2076               anArray[7] = aConnect[7];  
2077               anArray[8] = aConnect[6];  
2078
2079               anArray[9] = aConnect[9];  
2080               anArray[10] = aConnect[12];  
2081               anArray[11] = aConnect[11];  
2082               anArray[12] = aConnect[10];  
2083               break;
2084 #endif
2085             case MED::ePYRA5:
2086               anArray[0] = aConnect[0];
2087               anArray[1] = aConnect[3];  
2088               anArray[2] = aConnect[2];
2089               anArray[3] = aConnect[1];  
2090               anArray[4] = aConnect[4];
2091               break;
2092             default:
2093               for(int iNode = 0; iNode < aVNbNodes; iNode++) 
2094                 anArray[iNode] = aConnect[iNode];
2095             }
2096             for(int iNode = 0; iNode < aVNbNodes; iNode++) 
2097               if(anArray[iNode] < 0 || aNbPoints <= anArray[iNode])
2098                 EXCEPTION(runtime_error,"LoadCellsOnEntity - "<<
2099                           " aNbPoints("<<aNbPoints<<") "<<
2100                           "<= anArray["<<iElem<<"]"<<
2101                           "["<<iNode<<"]"<<
2102                           "("<<anArray[iNode]<<") < 0");
2103           }
2104         }
2105       }}
2106     }
2107
2108     // END NON_STRUCTURED
2109
2110     theMeshOnEntity->myIsDone = true;
2111
2112     return 1;
2113
2114 #ifndef _DEXCEPT_
2115   }catch(std::exception& exc){
2116     throw;
2117   }catch(...){
2118     EXCEPTION(runtime_error,"Unknown exception !!!");
2119   }
2120 #endif
2121
2122   return 0;
2123 }
2124
2125
2126 //---------------------------------------------------------------
2127 int 
2128 VISU_MedConvertor
2129 ::LoadCellsOnFamily(const MED::PWrapper& theMed,
2130                     const VISU::PMEDMesh theMesh,
2131                     const VISU::PMEDMeshOnEntity theMeshOnEntity,
2132                     const VISU::PMEDFamily theFamily)
2133 {
2134   TTimerLog aTimerLog(MYDEBUG,"LoadCellsOnFamily");
2135 #ifndef _DEXCEPT_
2136   try{
2137 #endif
2138     const TEntity& aVEntity = theMeshOnEntity->myEntity;
2139     const MED::EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity);
2140
2141     INITMSG(MYDEBUG,"LoadCellsOnFamily - aVEntity = "<<aVEntity<<"\n");
2142
2143     if(theFamily->myIsDone)
2144       return 0;
2145
2146     TInt anId = theFamily->myId;
2147
2148     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2149     TGeom2SubMeshID& aGeom2SubMeshID = theFamily->myGeom2SubMeshID;
2150
2151     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity->myGeom2Size;
2152     MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
2153     for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
2154       const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
2155       MED::PElemInfo anElemInfo;
2156       switch(aMGeom){
2157       case MED::ePOLYGONE: {
2158         anElemInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom);
2159         break;
2160       }
2161       case MED::ePOLYEDRE: {
2162         anElemInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom);
2163         break;
2164       }
2165       default: {
2166         anElemInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aMGeom);
2167         break;
2168       }}
2169       if(anElemInfo){
2170         if(TInt aNbElem = anElemInfo->GetNbElem()){
2171           TSubMeshID aSubMeshID;
2172           for(TInt iElem = 0; iElem < aNbElem; iElem++) 
2173             if(anElemInfo->GetFamNum(iElem) == anId)
2174               aSubMeshID.push_back(iElem);
2175           if(!aSubMeshID.empty()){
2176             VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
2177             INITMSG(MYDEBUG,"aMGeom = "<<aMGeom<<"\n");
2178             aGeom2SubMeshID.insert(TGeom2SubMeshID::value_type(aEGeom,aSubMeshID));
2179           }
2180         }
2181       }
2182     }
2183
2184     theFamily->myIsDone = true;
2185
2186     return 1;
2187
2188 #ifndef _DEXCEPT_
2189   }catch(std::exception& exc){
2190     throw;
2191   }catch(...){
2192     EXCEPTION(runtime_error,"Unknown exception !!!");
2193   }
2194 #endif
2195
2196   return 0;
2197 }
2198
2199
2200 //---------------------------------------------------------------
2201 void
2202 LoadProfile(const MED::PWrapper& theMed,
2203             VISU::PMEDMesh theMesh,
2204             MED::TTimeStampVal& theTimeStampVal,
2205             VISU::TMEDValForTime& theValForTime,
2206             VISU::TMEDMeshOnEntity& theMeshOnEntity)
2207 {
2208   TTimerLog aTimerLog(MYDEBUG,"LoadProfile");
2209   INITMSG(MYDEBUG,"LoadProfile"<<endl);
2210
2211   PMEDProfile aProfile = theValForTime.myProfile;
2212   if(aProfile->myIsDone)
2213     return;
2214
2215   const TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
2216   const MED::TGeom2Profile& aGeom2Profile = theTimeStampVal.GetGeom2Profile();
2217   MED::TGeom2Profile::const_iterator anIter = aGeom2Profile.begin();
2218   for(; anIter != aGeom2Profile.end(); anIter++){
2219     MED::PProfileInfo aProfileInfo = anIter->second;
2220     MED::EGeometrieElement aMGeom = anIter->first;
2221     VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
2222
2223     TGeom2SubProfile::const_iterator anIter2 = aGeom2SubProfile.find(aEGeom);
2224     if(anIter2 != aGeom2SubProfile.end()){
2225       PMEDSubProfile aSubProfile = anIter2->second;
2226
2227       MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
2228       if(!anElemNum.empty()){
2229         TSubMeshID& aSubMeshID = aSubProfile->mySubMeshID;
2230         TInt aSize = anElemNum.size();
2231         aSubMeshID.resize(aSize);
2232         for(TInt anId = 0; anId < aSize; anId++)
2233           aSubMeshID[anId] = anElemNum[anId] - 1;
2234       }
2235
2236       INITMSG(MYDEBUG,
2237               "- aEGeom = "<<aEGeom<<
2238               "; aNbCells = "<<aSubProfile->mySubMeshID.size()<<
2239               endl);
2240     }
2241   }
2242   {
2243     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2244     
2245     TEntity aVEntity = theMeshOnEntity.myEntity;
2246     MED::EEntiteMaillage aMEntity = VTKEntityToMED(aVEntity);
2247     
2248     const TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
2249     TGeom2SubProfile::const_iterator anIter = aGeom2SubProfile.begin();
2250     for(; anIter != aGeom2SubProfile.end(); anIter++){
2251       const PMEDSubProfile& aSubProfile = anIter->second;
2252       MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
2253       MED::PElemInfo anElemInfo;
2254       anElemInfo = theMed->GetPElemInfo(aMeshInfo,aMEntity,aMGeom);
2255       aSubProfile->myIsElemNum = anElemInfo->IsElemNum();
2256       aSubProfile->myElemNum = anElemInfo->myElemNum;
2257     }
2258   }
2259
2260   aProfile->myIsDone = true;
2261 }
2262
2263
2264 //---------------------------------------------------------------
2265 void
2266 LoadGaussMesh(const MED::PWrapper& theMed,
2267               VISU::PMEDMesh theMesh,
2268               MED::TTimeStampVal& theTimeStampVal,
2269               VISU::TMEDValForTime& theValForTime,
2270               VISU::TMEDMeshOnEntity& theMeshOnEntity)
2271 {
2272   TTimerLog aTimerLog(MYDEBUG,"LoadGaussMesh");
2273   INITMSG(MYDEBUG,"LoadGaussMesh"<<endl);
2274
2275   // this part of code must be reimplemented in connection with GRILLE structures
2276   if(theMesh->myMeshInfo->GetType() == MED::eSTRUCTURE)
2277     EXCEPTION(runtime_error,"LoadGaussMesh - Gauss Points localization error!!!");
2278   
2279   PMEDGaussMesh aGaussMesh = theValForTime.myGaussMesh;
2280   if(!aGaussMesh || aGaussMesh->myIsDone)
2281     return;
2282
2283   const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2284   MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
2285
2286   TEntity aVEntity = theMeshOnEntity.myEntity;
2287   MED::EEntiteMaillage aMEntity = VTKEntityToMED(aVEntity);
2288
2289   const TGeom2GaussSubMesh& aGeom2GaussSubMesh = aGaussMesh->myGeom2GaussSubMesh;
2290   const MED::TTimeStampInfo& aTimeStampInfo = theTimeStampVal.GetTimeStampInfo();
2291   const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo.GetGeom2Gauss();
2292
2293   TGeom2GaussSubMesh::const_iterator aSubMeshIter = aGeom2GaussSubMesh.begin();
2294   for(; aSubMeshIter != aGeom2GaussSubMesh.end(); aSubMeshIter++){
2295     PMEDGaussSubMesh aGaussSubMesh = aSubMeshIter->second;
2296     VISU::EGeometry aEGeom = aSubMeshIter->first;
2297     
2298     if(aGaussSubMesh->myIsDone)
2299       continue;
2300
2301     PMEDSubProfile aSubProfile = aGaussSubMesh->mySubProfile;
2302     const TSubMeshID& aSubMeshID = aSubProfile->mySubMeshID;
2303     MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
2304
2305     MED::PPolygoneInfo aPolygoneInfo;
2306     MED::PPolyedreInfo aPolyedreInfo;
2307     MED::PCellInfo aCellInfo;
2308     MED::PElemInfo anElemInfo;
2309
2310     switch(aMGeom){
2311     case MED::ePOLYGONE: 
2312       aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,
2313                                                aMEntity,
2314                                                aMGeom);
2315       anElemInfo = aPolygoneInfo;
2316       break;
2317     case MED::ePOLYEDRE: 
2318       aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,
2319                                                aMEntity,
2320                                                aMGeom);
2321       anElemInfo = aPolyedreInfo;
2322       break;
2323     default:
2324       aCellInfo = theMed->GetPCellInfo(aMeshInfo,
2325                                        aMEntity, 
2326                                        aMGeom);
2327       anElemInfo = aCellInfo;
2328     }
2329     aGaussSubMesh->myIsElemNum = anElemInfo->IsElemNum();
2330     aGaussSubMesh->myElemNum = anElemInfo->myElemNum;
2331
2332     std::string aName;
2333     MED::TGaussCoord aGaussCoord;
2334     bool anIsGaussCoord3D = false;
2335
2336     MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom);
2337     if(aGaussIter != aGeom2Gauss.end()){
2338       PMEDGauss aGauss = aGaussSubMesh->myGauss;
2339       MED::PGaussInfo aGaussInfo = aGauss->myGaussInfo;
2340       if(aGaussInfo){
2341         aName = aGaussInfo->GetName();
2342         if(!aSubMeshID.empty()){
2343           const std::string& aProfileName = aSubProfile->myName;
2344           MED::PProfileInfo aProfileInfo = MED::GetProfileInfo(theMed,
2345                                                                aProfileName);
2346           if(aProfileInfo){
2347             const MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
2348             anIsGaussCoord3D = MED::GetGaussCoord3D(aGaussInfo,
2349                                                     aCellInfo,
2350                                                     aNodeInfo,
2351                                                     aGaussCoord,
2352                                                     anElemNum);
2353           }
2354         }else
2355           anIsGaussCoord3D = MED::GetGaussCoord3D(aGaussInfo,
2356                                                   aCellInfo,
2357                                                   aNodeInfo,
2358                                                   aGaussCoord);
2359       }
2360     }else{
2361       if(!aSubMeshID.empty()){
2362         const std::string& aProfileName = aSubProfile->myName;
2363         MED::PProfileInfo aProfileInfo = MED::GetProfileInfo(theMed,
2364                                                              aProfileName);
2365         if(aProfileInfo){
2366           const MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
2367           switch(aMGeom){
2368           case MED::ePOLYGONE: 
2369             anIsGaussCoord3D = MED::GetBaryCenter(aPolygoneInfo,
2370                                                   aNodeInfo,
2371                                                   aGaussCoord,
2372                                                   anElemNum);
2373             break;
2374           case MED::ePOLYEDRE: 
2375             anIsGaussCoord3D = MED::GetBaryCenter(aPolyedreInfo,
2376                                                   aNodeInfo,
2377                                                   aGaussCoord,
2378                                                   anElemNum);
2379             break;
2380           default:
2381             anIsGaussCoord3D = MED::GetBaryCenter(aCellInfo,
2382                                                   aNodeInfo,
2383                                                   aGaussCoord,
2384                                                   anElemNum);
2385           }
2386         }
2387       }else
2388         switch(aMGeom){
2389         case MED::ePOLYGONE: 
2390           anIsGaussCoord3D = MED::GetBaryCenter(aPolygoneInfo,
2391                                                 aNodeInfo,
2392                                                 aGaussCoord);
2393           break;
2394         case MED::ePOLYEDRE: 
2395           anIsGaussCoord3D = MED::GetBaryCenter(aPolyedreInfo,
2396                                                 aNodeInfo,
2397                                                 aGaussCoord);
2398           break;
2399         default:
2400           anIsGaussCoord3D = MED::GetBaryCenter(aCellInfo,
2401                                                 aNodeInfo,
2402                                                 aGaussCoord);
2403         }
2404     }
2405     
2406     if(anIsGaussCoord3D){
2407       TPointCoords& aCoords = aGaussSubMesh->myPointCoords;
2408       TInt aNbGauss = aGaussCoord.GetNbGauss();
2409       TInt aNbElem = aGaussCoord.GetNbElem();
2410       TInt aDim = aGaussCoord.GetDim();
2411       vtkIdType aNbCells = aNbElem*aNbGauss;
2412       aCoords.Init(aNbCells,aDim);
2413       for(TInt anElemId = 0, aNodeId = 0; anElemId < aNbElem; anElemId++){
2414         MED::TCoordSliceArr aCoordSliceArr = aGaussCoord.GetCoordSliceArr(anElemId);
2415         for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++, aNodeId++){
2416           MED::TCoordSlice aCoordSlice = aCoordSliceArr[aGaussId];
2417           TCoordSlice aSlice = aCoords.GetCoordSlice(aNodeId);
2418           for(TInt aDimId = 0; aDimId < aDim; aDimId++)
2419             aSlice[aDimId] = aCoordSlice[aDimId];
2420         }
2421       }
2422       
2423       aGaussSubMesh->myIsDone = true;;
2424       
2425       INITMSG(MYDEBUG,
2426               "- aEGeom = "<<aEGeom<<
2427               "; aName = '"<<aName<<"'"<<
2428               "; aStatus = "<<aGaussSubMesh->myStatus<<
2429               "; aNbElem = "<<aNbElem<<
2430               "; aNbGauss = "<<aNbGauss<<
2431               "; aNbCells = "<<aNbCells<<
2432               endl);
2433     }else
2434       EXCEPTION(runtime_error,"LoadGaussMesh - Gauss Points localization error!!!");
2435   }
2436   
2437   aGaussMesh->myIsDone = true;
2438 }
2439
2440
2441 //---------------------------------------------------------------
2442 int 
2443 LoadValForTime(const MED::PWrapper& theMed,
2444                VISU::PMEDMesh theMesh,
2445                VISU::PMEDMeshOnEntity theMeshOnEntity,
2446                VISU::PMEDField theField, 
2447                VISU::PMEDValForTime theValForTime,
2448                bool theIsGauss,
2449                bool& theIsDone)
2450 {
2451   TTimerLog aTimerLog(MYDEBUG,"LoadValForTime");
2452   INITMSG(MYDEBUG,"LoadValForTime - theIsGauss = "<<theIsGauss<<endl);
2453
2454   //Check on loading already done
2455   if(theIsDone) 
2456     return 0;
2457
2458   //Main part of code
2459   const std::string& aMeshName = theMeshOnEntity->myMeshName;
2460   const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2461   MED::PFieldInfo aFieldInfo = theMed->GetPFieldInfo(aMeshInfo,
2462                                                      theField->myId);
2463
2464   MED::TGeom2Size aGeom2Size;
2465   MED::EEntiteMaillage aMEntity;
2466   theMed->GetNbTimeStamps(aFieldInfo,
2467                           theMesh->myEntityInfo,
2468                           aMEntity,
2469                           aGeom2Size);
2470
2471   MED::PTimeStampInfo aTimeStampInfo = 
2472     theMed->GetPTimeStampInfo(aFieldInfo,
2473                               aMEntity,
2474                               aGeom2Size,
2475                               theValForTime->myId);
2476
2477   MED::TKey2Gauss aKey2Gauss = GetKey2Gauss(theMed);
2478   MED::TMKey2Profile aMKey2Profile = GetMKey2Profile(theMed);
2479
2480   MED::PTimeStampVal aTimeStampVal = 
2481     theMed->GetPTimeStampVal(aTimeStampInfo,
2482                              aMKey2Profile,
2483                              aKey2Gauss);
2484
2485   InitGaussProfile(theMed,
2486                    aMeshInfo,
2487                    aTimeStampVal,
2488                    theMeshOnEntity,
2489                    aMEntity,
2490                    aGeom2Size,
2491                    theValForTime);
2492
2493   LoadProfile(theMed,
2494               theMesh,
2495               aTimeStampVal,
2496               theValForTime,
2497               theMeshOnEntity);
2498   
2499   if(theIsGauss)
2500     LoadGaussMesh(theMed,
2501                   theMesh,
2502                   aTimeStampVal,
2503                   theValForTime,
2504                   theMeshOnEntity);
2505   
2506   PMEDProfile aProfile = theValForTime->myProfile;
2507   TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
2508
2509   TInt aNbComp = theField->myNbComp;
2510
2511   INITMSGA(MYDEBUG,0,
2512            "- aMeshName = '"<<aMeshName<<"'"<<
2513            "; aFieldName = '"<<aFieldInfo->GetName()<<"'"<<
2514            "; aMEntity = "<<aMEntity<<
2515            "; aNbComp = "<<aNbComp<<
2516            endl);
2517
2518   theField->myDataSize = 0;
2519
2520   const MED::TTimeStampVal& aTimeStampValRef = aTimeStampVal;
2521   TGeom2SubProfile::const_iterator anIter = aGeom2SubProfile.begin();
2522   for(; anIter != aGeom2SubProfile.end(); anIter++){
2523     VISU::EGeometry aEGeom = anIter->first;
2524     PMEDSubProfile aSubProfile(anIter->second);
2525
2526     TInt aNbElem = aSubProfile->myNbCells;
2527     theField->myDataSize += aNbElem*aNbComp;
2528
2529     if(aSubProfile->myStatus != eRemoveAll){
2530       TInt aNbGauss = theValForTime->GetNbGauss(aEGeom);
2531
2532       INITMSG(MYDEBUG,
2533               "- aEGeom = "<<aEGeom<<
2534               "; aNbElem = "<<aNbElem<<
2535               "; aNbGauss = "<<aNbGauss<<
2536               endl);
2537       
2538       TMeshValue& aVMeshValue = theValForTime->GetMeshValue(aEGeom);
2539       aVMeshValue.Init(aNbElem,aNbGauss,aNbComp);
2540
2541       MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
2542       const MED::TMeshValue& aMMeshValue = aTimeStampValRef.GetMeshValue(aMGeom);
2543       for(TInt iElem = 0; iElem < aNbElem; iElem++){
2544         TValueSliceArr aVValueSliceArr = aVMeshValue.GetGaussValueSliceArr(iElem);
2545         MED::TCValueSliceArr aMValueSliceArr = aMMeshValue.GetGaussValueSliceArr(iElem);
2546         ADDMSG(MYVALUEDEBUG,"{");
2547         for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
2548           TValueSlice& aVValueSlice = aVValueSliceArr[iGauss];
2549           const MED::TCValueSlice& aMValueSlice = aMValueSliceArr[iGauss];
2550           for(TInt iComp = 0; iComp < aNbComp; iComp++){
2551             aVValueSlice[iComp] = aMValueSlice[iComp];
2552             ADDMSG(MYVALUEDEBUG,aVValueSlice[iComp]<<" ");
2553           }
2554           ADDMSG(MYVALUEDEBUG,"| ");
2555         }
2556         ADDMSG(MYVALUEDEBUG,"} ");
2557       }
2558       ADDMSG(MYDEBUG,"\n");
2559     }
2560   }
2561
2562   theIsDone = true;
2563
2564   return 1; 
2565 }
2566
2567
2568 //---------------------------------------------------------------
2569 int 
2570 VISU_MedConvertor
2571 ::LoadValForTimeOnMesh(const MED::PWrapper& theMed,
2572                        VISU::PMEDMesh theMesh,
2573                        VISU::PMEDMeshOnEntity theMeshOnEntity,
2574                        VISU::PMEDField theField, 
2575                        VISU::PMEDValForTime theValForTime)
2576 {
2577   PIDMapperFilter anIDMapperFilter = theValForTime->myIDMapperFilter;
2578   return LoadValForTime(theMed,
2579                         theMesh,
2580                         theMeshOnEntity,
2581                         theField,
2582                         theValForTime,
2583                         false,
2584                         anIDMapperFilter->myIsVTKDone);
2585 }
2586
2587
2588 //---------------------------------------------------------------
2589 int 
2590 VISU_MedConvertor
2591 ::LoadValForTimeOnGaussPts(const MED::PWrapper& theMed,
2592                            VISU::PMEDMesh theMesh,
2593                            VISU::PMEDMeshOnEntity theMeshOnEntity,
2594                            VISU::PMEDField theField, 
2595                            VISU::PMEDValForTime theValForTime)
2596 {
2597   PGaussPtsIDFilter aGaussPtsIDFilter = theValForTime->myGaussPtsIDFilter;
2598   return LoadValForTime(theMed,
2599                         theMesh,
2600                         theMeshOnEntity,
2601                         theField,
2602                         theValForTime,
2603                         true,
2604                         aGaussPtsIDFilter->myIsVTKDone);
2605 }