Salome HOME
IMP 0017328: min and max scalar map of results given at gauss points. A fix for the...
[modules/visu.git] / src / CONVERTOR / VISU_MedConvertor.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU OBJECT : interactive object for VISU entities implementation
23 //  File   : VISU_MedConvertor.cxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26 //
27 #include "VISU_MedConvertor.hxx"
28 #include "VISU_ConvertorUtils.hxx"
29
30 #include "MED_Factory.hxx"
31 #include "MED_Algorithm.hxx"
32 #include "MED_GaussUtils.hxx"
33 #include "MED_Utilities.hxx"
34
35 #include "SALOMEconfig.h"
36
37 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
38 #define NO_CAS_CATCH
39 #endif
40
41 #include <Standard_Failure.hxx>
42
43 #ifdef NO_CAS_CATCH
44 #include <Standard_ErrorHandler.hxx>
45 #endif
46
47 #include <vtkCellType.h>
48
49 #ifdef WNT
50 #include <float.h>
51 #define isnan _isnan
52 #endif
53
54 using MED::TInt;
55 using MED::TFloat;
56 using MED::EBooleen;
57
58 #ifdef _DEBUG_
59 static int MYDEBUG = 0;
60 static int MYVALUEDEBUG = 0;
61 static int MY_FAMILY_DEBUG = 0;
62 static int MY_GROUP_DEBUG = 0;
63 //#define _DEXCEPT_
64 #else
65 static int MYDEBUG = 0;
66 static int MYVALUEDEBUG = 0;
67 static int MY_FAMILY_DEBUG = 0;
68 static int MY_GROUP_DEBUG = 0;
69 #endif
70
71 #define _LOAD_FAMILIES_
72 #define _EDF_NODE_IDS_
73
74
75
76 namespace
77 {
78   //---------------------------------------------------------------
79   vtkIdType
80   MEDGeom2NbNodes(MED::EGeometrieElement theMEDGeomType)
81   { 
82     return theMEDGeomType % 100;
83   }
84
85
86   //---------------------------------------------------------------
87   VISU::EGeometry
88   MEDGeom2VISU(MED::EGeometrieElement theGeom)
89   { 
90     switch(theGeom){
91     case MED::ePOINT1: return VISU::ePOINT1;
92     case MED::eSEG2: return VISU::eSEG2;
93     case MED::eTRIA3: return VISU::eTRIA3;
94     case MED::eQUAD4: return VISU::eQUAD4;
95     case MED::eTETRA4: return VISU::eTETRA4;
96     case MED::eHEXA8: return VISU::eHEXA8;
97     case MED::ePENTA6: return VISU::ePENTA6;
98     case MED::ePYRA5: return VISU::ePYRA5;
99
100     case MED::eSEG3: return VISU::eSEG3;
101     case MED::eTRIA6: return VISU::eTRIA6;
102     case MED::eQUAD8: return VISU::eQUAD8;
103     case MED::eTETRA10: return VISU::eTETRA10;
104     case MED::eHEXA20: return VISU::eHEXA20;
105     case MED::ePENTA15: return VISU::ePENTA15;
106     case MED::ePYRA13: return VISU::ePYRA13;
107
108     case MED::ePOLYGONE: return VISU::ePOLYGONE;
109     case MED::ePOLYEDRE: return VISU::ePOLYEDRE;
110     }
111     return VISU::eNONE;
112   }
113
114
115   //---------------------------------------------------------------
116   MED::EGeometrieElement 
117   VISUGeom2MED(int theGeom)
118   { 
119     switch(theGeom){
120     case VISU::ePOINT1: return MED::ePOINT1;
121     case VISU::eSEG2: return MED::eSEG2;
122     case VISU::eTRIA3: return MED::eTRIA3;
123     case VISU::eQUAD4: return MED::eQUAD4;
124     case VISU::eTETRA4: return MED::eTETRA4;
125     case VISU::eHEXA8: return MED::eHEXA8;
126     case VISU::ePENTA6: return MED::ePENTA6;
127     case VISU::ePYRA5: return MED::ePYRA5;
128
129     case VISU::eSEG3: return MED::eSEG3;
130     case VISU::eTRIA6: return MED::eTRIA6;
131     case VISU::eQUAD8: return MED::eQUAD8;
132     case VISU::eTETRA10: return MED::eTETRA10;
133     case VISU::eHEXA20: return MED::eHEXA20;
134     case VISU::ePENTA15: return MED::ePENTA15;
135     case VISU::ePYRA13: return MED::ePYRA13;
136
137     case VISU::ePOLYGONE: return MED::ePOLYGONE;
138     case VISU::ePOLYEDRE: return MED::ePOLYEDRE;
139     }
140     return MED::EGeometrieElement(-1);
141   }
142
143
144   //---------------------------------------------------------------
145   VISU::TEntity
146   MEDEntityToVTK( MED::EEntiteMaillage theMEDEntity )
147   {
148     VISU::TEntity anEntity = VISU::TEntity( -1 );
149
150     switch(theMEDEntity){
151     case MED::eNOEUD :
152       anEntity = VISU::NODE_ENTITY;
153       break;
154     case MED::eARETE : 
155       anEntity = VISU::EDGE_ENTITY;
156       break;
157     case MED::eFACE : 
158       anEntity = VISU::FACE_ENTITY;
159       break;
160     case MED::eMAILLE : 
161       anEntity = VISU::CELL_ENTITY;
162       break;
163     case MED::eNOEUD_ELEMENT :
164       anEntity = VISU::CELL_ENTITY;
165       break;
166     }
167
168     return anEntity;
169   }
170
171
172   //---------------------------------------------------------------
173   MED::EEntiteMaillage 
174   VTKEntityToMED(VISU::TEntity theVTKEntity)
175   {
176     switch(theVTKEntity){
177     case VISU::NODE_ENTITY: return MED::eNOEUD;
178     case VISU::EDGE_ENTITY: return MED::eARETE;
179     case VISU::FACE_ENTITY: return MED::eFACE;
180     case VISU::CELL_ENTITY: return MED::eMAILLE;
181     }
182     return MED::EEntiteMaillage(-1);
183   }
184
185
186   //---------------------------------------------------------------
187   VISU::PMEDSubProfile
188   CrSubProfile(const MED::PWrapper& theMEDWrapper,
189                const MED::PMeshInfo& theMeshInfo,
190                MED::EEntiteMaillage theMEntity,
191                MED::EGeometrieElement theMGeom,
192                const MED::TGeom2Size& theGeom2Size,
193                const MED::TGeom2Profile& theGeom2Profile)
194   {
195     VISU::EGeometry aEGeom = MEDGeom2VISU(theMGeom);
196     vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
197
198     VISU::PMEDSubProfile aSubProfile(new VISU::TMEDSubProfile());
199     aSubProfile->myGeom = aEGeom;
200     aSubProfile->myMGeom = theMGeom;
201     aSubProfile->myStatus = VISU::eAddAll;
202
203     MED::TGeom2Size::const_iterator aTimeStampIter = theGeom2Size.find(theMGeom);
204     if(aTimeStampIter == theGeom2Size.end())
205       aSubProfile->myStatus = VISU::eRemoveAll;
206     else{
207       MED::TGeom2Profile::const_iterator aProfileIter = theGeom2Profile.find(theMGeom);
208       if(aProfileIter != theGeom2Profile.end()){
209         MED::PProfileInfo aProfileInfo = aProfileIter->second;
210
211         aSubProfile->myName = aProfileInfo->GetName();
212         aSubProfile->myStatus = VISU::eAddPart;
213
214         const MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
215         TInt aNbElem = anElemNum.size();
216         aSubProfile->myNbCells = aNbElem;
217         switch(theMGeom){
218         case MED::ePOLYGONE: {
219           MED::PPolygoneInfo aPolygoneInfo = 
220             theMEDWrapper->GetPPolygoneInfo(theMeshInfo,theMEntity,theMGeom);
221           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
222             TInt aNbConn = aPolygoneInfo->GetNbConn( anElemNum[ anElemId ] - 1 );
223             aSubProfile->myCellsSize += aNbConn;
224           }
225           break;
226         }
227         case MED::ePOLYEDRE: {
228           MED::PPolyedreInfo aPolyedreInfo = 
229             theMEDWrapper->GetPPolyedreInfo(theMeshInfo,theMEntity,theMGeom);
230           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
231             MED::TCConnSliceArr aConnSliceArr = 
232               aPolyedreInfo->GetConnSliceArr( anElemNum[ anElemId ] - 1 );
233             TInt aNbFaces = aConnSliceArr.size();
234             TInt aCellSize = 0;
235             for(TInt iFace = 0; iFace < aNbFaces; iFace++){
236               MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
237               TInt aNbConn = aConnSlice.size();
238               aCellSize += aNbConn;
239             }
240             aSubProfile->myCellsSize += aCellSize;
241           }
242           break;
243         }
244         default: {
245           aSubProfile->myCellsSize = aSubProfile->myNbCells*aVNbNodes;
246         }}
247       }else{
248         TInt aNbElem = aTimeStampIter->second;
249         aSubProfile->myNbCells = aNbElem;
250         switch(theMGeom){
251         case MED::ePOLYGONE: {
252           MED::PPolygoneInfo aPolygoneInfo = 
253             theMEDWrapper->GetPPolygoneInfo(theMeshInfo,theMEntity,theMGeom);
254           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
255             TInt aNbConn = aPolygoneInfo->GetNbConn(anElemId);
256             aSubProfile->myCellsSize += aNbConn;
257           }
258           break;
259         }
260         case MED::ePOLYEDRE: {
261           MED::PPolyedreInfo aPolyedreInfo = 
262             theMEDWrapper->GetPPolyedreInfo(theMeshInfo,theMEntity,theMGeom);
263           for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
264             MED::TCConnSliceArr aConnSliceArr = 
265               aPolyedreInfo->GetConnSliceArr(anElemId);
266             TInt aNbFaces = aConnSliceArr.size();
267             TInt aCellSize = 0;
268             for(TInt iFace = 0; iFace < aNbFaces; iFace++){
269               MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
270               TInt aNbConn = aConnSlice.size();
271               aCellSize += aNbConn;
272             }
273             aSubProfile->myCellsSize += aCellSize;
274           }
275           break;
276         }
277         default: {
278           aSubProfile->myCellsSize = aSubProfile->myNbCells*aVNbNodes;
279         }}
280       }
281     }
282     INITMSG(MYDEBUG,
283             "- aMGeom = "<<theMGeom<<
284             "; aEGeom = "<<aEGeom<<
285             "; aName = '"<<aSubProfile->myName<<"'"<<
286             "; aStatus = "<<aSubProfile->myStatus<<
287             "; aNbCells = "<<aSubProfile->myNbCells<<
288             "; aCellsSize = "<<aSubProfile->myCellsSize<<
289             endl);
290     
291     return aSubProfile;
292   }
293
294
295   //---------------------------------------------------------------
296   VISU::TProfileKey
297   GetProfileKey(const MED::PWrapper& theMEDWrapper,
298                 const MED::PMeshInfo& theMeshInfo,
299                 const MED::PTimeStampValueBase& theTimeStampValue,
300                 const VISU::TMEDMeshOnEntity& theMeshOnEntity,
301                 MED::EEntiteMaillage theMEntity,
302                 const MED::TGeom2Size& theGeom2Size)
303   {
304     INITMSG(MYDEBUG,"GetProfileKey"<<endl);
305     
306     VISU::TProfileKey aProfileKey;
307     const MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->GetGeom2Profile();
308
309     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity.myGeom2Size;
310     MED::TGeom2Size::const_iterator anIter = aGeom2Size.begin();
311     for(; anIter != aGeom2Size.end(); anIter++){
312       MED::EGeometrieElement aMGeom = anIter->first;
313       VISU::PSubProfile aSubProfile = CrSubProfile(theMEDWrapper,
314                                                    theMeshInfo,
315                                                    theMEntity,
316                                                    aMGeom,
317                                                    theGeom2Size,
318                                                    aGeom2Profile);
319       aProfileKey.insert(aSubProfile);
320     }
321     
322     return aProfileKey;
323   }
324   
325
326   //---------------------------------------------------------------
327   void
328   InitProfile(const MED::PWrapper& theMEDWrapper,
329               const MED::PMeshInfo& theMeshInfo,
330               MED::PTimeStampValueBase& theTimeStampValue,
331               VISU::TMEDMeshOnEntity& theMeshOnEntity,
332               MED::EEntiteMaillage theMEntity,
333               const MED::TGeom2Size& theGeom2Size,
334               VISU::TMEDValForTime& theValForTime)
335   {
336     VISU::TTimerLog aTimerLog(MYDEBUG,"InitProfile");
337     INITMSG(MYDEBUG,"InitProfile"<<endl);
338     
339     VISU::TProfileMap& aProfileMap = theMeshOnEntity.myProfileMap;
340     
341     VISU::TProfileKey aProfileKey = GetProfileKey(theMEDWrapper,
342                                             theMeshInfo,
343                                             theTimeStampValue,
344                                             theMeshOnEntity,
345                                             theMEntity,
346                                             theGeom2Size);
347     
348     VISU::TProfileMap::const_iterator anIter = aProfileMap.find(aProfileKey);
349     if(anIter != aProfileMap.end()){
350       theValForTime.myProfile = anIter->second;
351       INITMSG(MYDEBUG,"aProfileMap.find(aProfileKey)"<<endl);
352     }else{
353       VISU::PMEDProfile aProfile(new VISU::TMEDProfile());
354       VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
355       
356       VISU::TProfileKey::const_iterator anIter = aProfileKey.begin();
357       for(; anIter != aProfileKey.end(); anIter++){
358         VISU::PMEDSubProfile aSubProfile(*anIter);
359
360         if(aProfile->myIsAll && aSubProfile->myStatus != VISU::eAddAll)
361           aProfile->myIsAll = false;
362
363         VISU::EGeometry aEGeom = aSubProfile->myGeom;
364         aGeom2SubProfile[aEGeom] = aSubProfile;
365       }
366
367       aProfileMap[aProfileKey] = aProfile;
368       theValForTime.myProfile = aProfile;
369     }
370   }
371
372
373   //---------------------------------------------------------------
374   VISU::TGaussKey
375   GetGaussKey(const MED::PTimeStampValueBase& theTimeStampValue,
376               const VISU::TMEDMeshOnEntity& theMeshOnEntity,
377               const MED::TGeom2Size& theGeom2Size,
378               VISU::TMEDValForTime& theValForTime)
379   {
380     VISU::TTimerLog aTimerLog(MYDEBUG,"GetGaussKey");
381     INITMSG(MYDEBUG,"GetGaussKey"<<endl);
382
383     VISU::TGaussKey aGaussKey;
384     VISU::PMEDProfile aProfile = theValForTime.myProfile;
385     VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
386
387     const MED::TTimeStampInfo& aTimeStampInfo = theTimeStampValue->GetTimeStampInfo();
388     const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo.GetGeom2Gauss();
389
390     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity.myGeom2Size;
391     MED::TGeom2Size::const_iterator anIter = aGeom2Size.begin();
392     for(; anIter != aGeom2Size.end(); anIter++){
393       MED::EGeometrieElement aMGeom = anIter->first;
394       VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
395
396       VISU::TGeom2SubProfile::iterator anIter2 = aGeom2SubProfile.find(aEGeom);
397       if(anIter2 == aGeom2SubProfile.end()){
398         INITMSG(MYDEBUG,"anIter2 == aGeom2SubProfile.end!!"<<endl);
399         continue;
400       }
401       VISU::PMEDSubProfile aSubProfile = anIter2->second;
402
403       MED::TGeom2Size::const_iterator aTimeStampIter = theGeom2Size.find(aMGeom);
404       if(aTimeStampIter != theGeom2Size.end()){
405         TInt aNbCells = aTimeStampIter->second;
406         if(aSubProfile->myStatus == VISU::eAddPart)
407           aNbCells = aSubProfile->myNbCells;
408
409         VISU::PMEDGaussSubMesh aGaussSubMesh(new VISU::TMEDGaussSubMesh());
410         aGaussSubMesh->mySubProfile = aSubProfile;
411         aGaussSubMesh->myStatus = aSubProfile->myStatus;
412           
413         VISU::PMEDGauss aGauss(new VISU::TMEDGauss());
414         aGaussSubMesh->myGauss = aGauss;
415         aGauss->myGeom = aEGeom;
416         aGauss->myNbPoints = 1;
417
418         MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom);
419         if(aGaussIter != aGeom2Gauss.end()){
420           MED::PGaussInfo aGaussInfo = aGaussIter->second;
421           aGauss->myGaussInfo = aGaussInfo;
422           aGauss->myName = aGaussInfo->GetName();
423           aGauss->myNbPoints = aGaussInfo->GetNbGauss();
424         } else if ( aTimeStampInfo.GetNbGauss(aMGeom) > 1 )
425           EXCEPTION( std::runtime_error, "aGaussIter == aGeom2Gauss.end()"
426                      " && aTimeStampInfo.GetNbGauss(aMGeom) > 1 !!!" );
427         
428         aGaussSubMesh->myNbCells = aNbCells*aGauss->myNbPoints;
429         aGaussSubMesh->myCellsSize = aGaussSubMesh->myNbCells*2;
430
431         aGaussKey.insert(aGaussSubMesh);
432
433         INITMSGA(MYDEBUG,0,
434                  "- aEGeom = "<<aGauss->myGeom<<
435                  "; aName = '"<<aGauss->myName<<"'"<<
436                  "; aNbGauss = "<<aGauss->myNbPoints<<
437                  "; aStatus = "<<aGaussSubMesh->myStatus<<
438                  "; aNbCells = "<<aGaussSubMesh->myNbCells<<
439                  "; aCellsSize = "<<aGaussSubMesh->myCellsSize<<
440                  endl);
441
442         //break;
443       }
444     }
445
446     return aGaussKey;
447   }
448
449
450   //---------------------------------------------------------------
451   void
452   InitGaussMesh(MED::PTimeStampValueBase& theTimeStampValue,
453                 VISU::TMEDMeshOnEntity& theMeshOnEntity,
454                 const MED::TGeom2Size& theGeom2Size,
455                 VISU::TMEDValForTime& theValForTime)
456   {
457     VISU::TTimerLog aTimerLog(MYDEBUG,"InitGaussMesh");
458     INITMSG(MYDEBUG,"InitGaussMesh"<<endl);
459
460     if(theMeshOnEntity.myEntity == VISU::NODE_ENTITY)
461       return;
462
463     VISU::TGaussMeshMap& aGaussMeshMap = theMeshOnEntity.myGaussMeshMap;
464     
465     VISU::TGaussKey aGaussKey = GetGaussKey(theTimeStampValue,
466                                             theMeshOnEntity,
467                                             theGeom2Size,
468                                             theValForTime);
469
470     VISU::TGaussMeshMap::const_iterator anIter = aGaussMeshMap.find(aGaussKey);
471     if(anIter != aGaussMeshMap.end()){
472       theValForTime.myGaussMesh = anIter->second;
473       INITMSG(MYDEBUG,"aGaussMeshMap.find(aGaussKey)"<<endl);
474     }else{
475       VISU::PMEDGaussMesh aGaussMesh(new VISU::TMEDGaussMesh());
476       VISU::TGeom2GaussSubMesh& aGeom2GaussSubMesh = aGaussMesh->myGeom2GaussSubMesh;
477       {
478         VISU::TGaussKey::const_iterator anIter = aGaussKey.begin();
479         for(; anIter != aGaussKey.end(); anIter++){
480           VISU::PMEDGaussSubMesh aGaussSubMesh(*anIter);
481           VISU::PMEDGauss aGauss = aGaussSubMesh->myGauss;
482           VISU::EGeometry aEGeom = aGauss->myGeom;
483           aGeom2GaussSubMesh[aEGeom] = aGaussSubMesh;
484         }
485       }
486       {
487         VISU::TGaussSubMeshArr& aGaussSubMeshArr = aGaussMesh->myGaussSubMeshArr;
488         aGaussSubMeshArr.resize(aGeom2GaussSubMesh.size());
489         VISU::TGeom2GaussSubMesh::const_iterator anIter = aGeom2GaussSubMesh.begin();
490         for(TInt anID = 0; anIter != aGeom2GaussSubMesh.end(); anIter++, anID++){
491           const VISU::PGaussSubMeshImpl& aGaussSubMesh = anIter->second;
492           aGaussSubMeshArr[anID] = aGaussSubMesh;
493         }
494       }
495       INITMSG(MYDEBUG,"aGaussMeshMap[aGaussKey] = aGaussMesh"<<std::endl);
496       aGaussMeshMap[aGaussKey] = aGaussMesh;
497       theValForTime.myGaussMesh = aGaussMesh;
498     }
499   }
500
501   //---------------------------------------------------------------
502   void
503   BuildMeshOnEntityMap(VISU::PMEDMesh theMesh,
504                        const MED::TEntityInfo& theEntityInfo,
505                        const MED::PNodeInfo& theNodeInfo,
506                        const MED::PWrapper& theMEDWrapper)
507   {
508     VISU::TTimerLog aTimerLog(MYDEBUG,"BuildMeshOnEntityMap");
509     INITMSG(MYDEBUG,"BuildMeshOnEntityMap"<<endl);
510
511     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
512     const std::string& aMeshName = theMesh->myName;
513     VISU::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       VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
520       VISU::PMEDMeshOnEntity aMeshOnEntity = 
521         aMeshOnEntityMap[aVEntity](new VISU::TMEDMeshOnEntity());
522       aMeshOnEntity->myEntity = aVEntity;
523       aMeshOnEntity->myMeshName = aMeshName;
524       aMeshOnEntity->myGeom2Size = aGeom2Size;
525       VISU::TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize;
526       VISU::TGeom2ElemID2FamilyID& aGeom2ElemID2FamilyID = aMeshOnEntity->myGeom2ElemID2FamilyID;
527
528       INITMSG(MYDEBUG,
529               "- aMEntity = "<<aMEntity<<
530               "; aVEntity = "<<aVEntity<<
531               endl);
532       
533       if(aMEntity == MED::eNOEUD){
534         aMeshOnEntity->myNbCells = theMesh->myNbPoints;
535         aMeshOnEntity->myCellsSize = 2*theMesh->myNbPoints;
536         
537         VISU::TElemID2FamilyID& anElemID2FamilyID = aGeom2ElemID2FamilyID[MED::ePOINT1];
538
539         for(TInt iElem = 0; iElem < theMesh->myNbPoints; iElem++){
540           TInt aFamId = theNodeInfo->GetFamNum(iElem);
541           if(aFamId != 0)
542             aFamilyID2CellsSize[aFamId] += 2;
543           anElemID2FamilyID[iElem] = aFamId;
544         }
545         
546         INITMSG(MYDEBUG,
547                 "- myNbCells = "<<aMeshOnEntity->myNbCells<<
548                 "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
549                 std::endl);
550         
551       }else{
552         MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
553         aMeshOnEntity->myNbCells = 0;
554         aMeshOnEntity->myCellsSize = 0;
555         for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
556           const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
557           
558           VISU::TElemID2FamilyID& anElemID2FamilyID = aGeom2ElemID2FamilyID[aMGeom];
559           switch(aMGeom){
560           case MED::ePOLYGONE: {
561             MED::PPolygoneInfo aPolygoneInfo = theMEDWrapper->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom);
562             TInt aNbElem = aPolygoneInfo->GetNbElem();
563             
564             INITMSG(MYDEBUG,
565                     "- aMGeom = "<<aMGeom<<
566                     "; aNbElem = "<<aNbElem<<
567                     endl);
568             
569             aMeshOnEntity->myNbCells += aNbElem;      
570             for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
571               TInt aNbConn = aPolygoneInfo->GetNbConn(anElemId);
572               aMeshOnEntity->myCellsSize += aNbConn;
573               TInt aFamId = aPolygoneInfo->GetFamNum(anElemId);
574               if(aFamId != 0)
575                 aFamilyID2CellsSize[aFamId] += aNbConn + 1;
576               anElemID2FamilyID[anElemId] = aFamId;
577             }
578             break;
579           }
580           case MED::ePOLYEDRE: {
581             MED::PPolyedreInfo aPolyedreInfo = theMEDWrapper->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom);
582             TInt aNbElem = aPolyedreInfo->GetNbElem();
583             
584             INITMSG(MYDEBUG,
585                     "- aMGeom = "<<aMGeom<<
586                     "; aNbElem = "<<aNbElem<<
587                     endl);
588             
589             aMeshOnEntity->myNbCells += aNbElem;
590             for(TInt anElemId = 0; anElemId < aNbElem ; anElemId++){
591               MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(anElemId);
592               TInt aNbFaces = aConnSliceArr.size();
593               TInt aCellSize = 0;
594               for(TInt iFace = 0; iFace < aNbFaces; iFace++){
595                 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
596                 TInt aNbConn = aConnSlice.size();
597                 aCellSize += aNbConn;
598               }
599               aMeshOnEntity->myCellsSize += aCellSize;
600               TInt aFamId = aPolyedreInfo->GetFamNum(anElemId);
601               if(aFamId != 0)
602                 aFamilyID2CellsSize[aFamId] += aCellSize + 1;
603               anElemID2FamilyID[anElemId] = aFamId;
604             }
605             break;
606           }
607           default: {
608             VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
609             vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
610             MED::PCellInfo aCellInfo = theMEDWrapper->GetPCellInfo(aMeshInfo,aMEntity,aMGeom);
611             TInt aNbElem = aCellInfo->GetNbElem();
612             aMeshOnEntity->myNbCells += aNbElem;
613             aMeshOnEntity->myCellsSize += aNbElem*(aVNbNodes+1);
614             
615             INITMSG(MYDEBUG,
616                     "- aMGeom = "<<aMGeom<<
617                     "; aNbElem = "<<aNbElem<<
618                     "; myNbCells = "<<aMeshOnEntity->myNbCells<<
619                     "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
620                     endl);
621             
622             for(TInt iElem = 0; iElem < aNbElem; iElem++){
623               TInt aFamId = aCellInfo->GetFamNum(iElem);
624               if(aFamId != 0)
625                 aFamilyID2CellsSize[aFamId] += aVNbNodes + 1;
626               anElemID2FamilyID[iElem] = aFamId;
627             }
628           }} // end switch(...)
629         }
630       }
631     }
632   }
633
634   //---------------------------------------------------------------
635   void
636   BuildMeshGrilleOnEntityMap(VISU::PMEDMesh theMesh,
637                              const MED::TEntityInfo& theEntityInfo,
638                              const MED::PGrilleInfo& theGrilleInfo,
639                              const MED::PWrapper& theMEDWrapper)
640   {
641     VISU::TTimerLog aTimerLog(MYDEBUG,"BuildMeshGrilleOnEntityMap");
642     INITMSG(MYDEBUG,"BuildMeshGrilleOnEntityMap"<<endl);
643     
644     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
645     const std::string& aMeshName = theMesh->myName;
646     VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
647     MED::TEntityInfo::const_iterator anEntityIter = theEntityInfo.begin();
648     
649     VISU::TStructuredId& aGrilleStructure = theMesh->myGrilleStructure;
650     if ( theGrilleInfo->GetGrilleType() != MED::eGRILLE_STANDARD )
651       for ( int aDimId = 0; aDimId < theMesh->myDim; aDimId++ )
652         aGrilleStructure[aDimId] = theGrilleInfo->GetNbIndexes(aDimId);
653     else {
654       MED::TIntVector aVector = theGrilleInfo->GetGrilleStructure();
655       for ( int aDimId = 0; aDimId < aVector.size(); aDimId++ )
656         aGrilleStructure[aDimId] = aVector[aDimId];
657     }
658
659     int kMax = aGrilleStructure[2];
660     int jMax = aGrilleStructure[1];
661     int iMax = aGrilleStructure[0];
662     
663     int iii = 0;
664     VISU::TObj2StructuredId& aObj2StructuredId = theMesh->myObj2StructuredId;
665     switch ( theMesh->myDim ) {
666     case 1:
667       for ( int i = 1; i <= iMax; i++ )
668         aObj2StructuredId[i-1][0] = i;
669       break;
670     case 2:
671       for ( int j = 1; j <= jMax; j++ )
672         for ( int i = 1; i <= iMax; i++ ) {
673           aObj2StructuredId[iii][0] = i;
674           aObj2StructuredId[iii][1] = j;
675           iii++;
676         }
677       break;
678     case 3:
679       for ( int k = 1; k <= kMax; k++ )
680         for ( int j = 1; j <= jMax; j++ )
681           for ( int i = 1; i <= iMax; i++ ) {
682             aObj2StructuredId[iii][0] = i;
683             aObj2StructuredId[iii][1] = j;
684             aObj2StructuredId[iii][2] = k;
685             iii++;
686           }
687     }
688     
689     for(; anEntityIter != theEntityInfo.end(); anEntityIter++){
690       const MED::EEntiteMaillage& aMEntity = anEntityIter->first;
691       const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
692       
693       VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
694       VISU::PMEDMeshOnEntity aMeshOnEntity = 
695         aMeshOnEntityMap[aVEntity](new VISU::TMEDMeshOnEntity());
696       aMeshOnEntity->myEntity = aVEntity;
697       aMeshOnEntity->myMeshName = aMeshName;
698       aMeshOnEntity->myGeom2Size = aGeom2Size;
699       VISU::TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize;
700       VISU::TGeom2ElemID2FamilyID& aGeom2ElemID2FamilyID = aMeshOnEntity->myGeom2ElemID2FamilyID;
701
702       INITMSG(MYDEBUG,
703               "- aMEntity = "<<aMEntity<<
704               "; aVEntity = "<<aVEntity<<
705               endl);
706       
707       if(aMEntity == MED::eNOEUD){
708         aMeshOnEntity->myNbCells = theGrilleInfo->GetNbNodes();
709         aMeshOnEntity->myCellsSize = 2*theGrilleInfo->GetNbNodes();
710
711         VISU::TElemID2FamilyID& anElemID2FamilyID = aGeom2ElemID2FamilyID[MED::ePOINT1];
712
713         if((theGrilleInfo->myFamNumNode).size() > 0)
714         for(TInt iElem = 0; iElem < theGrilleInfo->GetNbNodes(); iElem++){
715           TInt aFamId = theGrilleInfo->GetFamNumNode(iElem);
716           if(aFamId != 0)
717             aFamilyID2CellsSize[aFamId] += 2;
718           anElemID2FamilyID[iElem] = aFamId;
719         }
720         
721         INITMSG(MYDEBUG,
722                 "- myNbCells = "<<aMeshOnEntity->myNbCells<<
723                 "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
724                 endl);;
725         
726       } else {
727         MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
728         aMeshOnEntity->myNbCells = 0;
729         aMeshOnEntity->myCellsSize = 0;
730         for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
731           const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
732           VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
733           vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
734           TInt aNbElem = aGeom2SizeIter->second;//theGrilleInfo->GetNbCells();
735           aMeshOnEntity->myNbCells += aNbElem;
736           aMeshOnEntity->myCellsSize += aNbElem*(aVNbNodes+1);
737
738           VISU::TElemID2FamilyID& anElemID2FamilyID = aGeom2ElemID2FamilyID[aMGeom];
739           
740           INITMSG(MYDEBUG,
741                   "- aMGeom = "<<aMGeom<<
742                   "; aNbElem = "<<aNbElem<<
743                   "; myNbCells = "<<aMeshOnEntity->myNbCells<<
744                   "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<
745                   endl);
746           
747           if((theGrilleInfo->myFamNum).size() > 0)
748           for(TInt iElem = 0; iElem < aNbElem; iElem++){
749             TInt aFamId = theGrilleInfo->GetFamNum(iElem);
750             if(aFamId != 0)
751               aFamilyID2CellsSize[aFamId] += aVNbNodes + 1;
752             anElemID2FamilyID[iElem] = aFamId;
753           }
754         }
755       }
756     }
757   }
758
759
760   //---------------------------------------------------------------
761   void
762   BuildFieldMap(VISU::PMEDMesh theMesh,
763                 const MED::TEntityInfo& theEntityInfo,
764                 MED::PWrapper theMEDWrapper)
765   {
766     VISU::TTimerLog aTimerLog(MYDEBUG,"BuildFieldMap");
767     TInt aNbFields = theMEDWrapper->GetNbFields(); 
768     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
769     const std::string& aMeshName = theMesh->myName;
770     INITMSG(MYDEBUG,"BuildFieldMap: aNbFields = "<<aNbFields<<"\n");
771     for(TInt iField = 1; iField <= aNbFields; iField++){
772       VISU::TTimerLog aTimerLog(MYDEBUG,"GetPFieldInfo");
773       
774       MED::TErr anError = 0;
775       MED::PFieldInfo aFieldInfo = theMEDWrapper->GetPFieldInfo(aMeshInfo, iField, &anError);
776       if ( anError < 0 )
777         continue;
778
779       TInt aNbComp = aFieldInfo->GetNbComp();
780       std::string aFieldName = aFieldInfo->GetName();
781       
782       MED::TGeom2Size aGeom2Size;
783       MED::EEntiteMaillage aMEntity;
784       TInt aNbTimeStamps = theMEDWrapper->GetNbTimeStamps(aFieldInfo,
785                                                           theEntityInfo,
786                                                           aMEntity,
787                                                           aGeom2Size);
788       if(aNbTimeStamps < 1)
789         continue;
790       
791       VISU::TEntity aVEntity = MEDEntityToVTK( aMEntity );
792       vtkIdType aDataType = VTK_DOUBLE;
793       if ( aFieldInfo->GetType() != MED::eFLOAT64 ) {
794 #if defined(HAVE_F77INT64)
795         aDataType = VTK_LONG;
796 #else   
797         aDataType = VTK_INT;
798 #endif
799       }
800       VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
801       VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
802       VISU::PMEDField aField = aFieldMap[aFieldName](new VISU::TMEDField());
803       aField->myId = iField;
804       aField->Init(aNbComp, aDataType);
805       aField->myEntity = aVEntity;
806       aField->myName = aFieldName;
807       aField->myMeshName = aMeshName;
808       aField->myDataSize = aMeshOnEntity->myNbCells * aNbComp;
809       aField->myIsELNO = ( aMEntity == MED::eNOEUD_ELEMENT );
810
811       INITMSG(MYDEBUG,"myName = '"<<aField->myName<<"'"<<
812               "; myId = "<<aField->myId<<
813               "; myEntity = "<<aField->myEntity<<
814               "; myDataSize = "<<aField->myDataSize<<
815               "; myNbComp = "<<aField->myNbComp<<"\n");
816       
817       for(TInt iComp = 0; iComp < aNbComp; iComp++){
818         aField->myCompNames[iComp] = aFieldInfo->GetCompName(iComp);
819         aField->myUnitNames[iComp] = aFieldInfo->GetUnitName(iComp);
820       }
821       
822       for(TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
823         VISU::TTimerLog aTimerLog(MYDEBUG,"GetPTimeStampInfo");
824
825         MED::TErr anError = 0;
826         MED::PTimeStampInfo aTimeStampInfo = theMEDWrapper->GetPTimeStampInfo(aFieldInfo,
827                                                                               aMEntity,
828                                                                               aGeom2Size,
829                                                                               iTimeStamp,
830                                                                               &anError);
831         if ( anError < 0 )
832           continue;
833
834         TFloat aDt = aTimeStampInfo->GetDt();
835         std::string anUnitDt = aTimeStampInfo->GetUnitDt();
836
837         VISU::TValField& aValField = aField->myValField;
838         VISU::PMEDValForTime aValForTime = aValField[iTimeStamp](new VISU::TMEDValForTime());
839         aValForTime->myId = iTimeStamp;
840         aValForTime->myFieldName = aField->myName;
841         aValForTime->myEntity = aField->myEntity;
842         aValForTime->myMeshName = aField->myMeshName;
843         aValForTime->myTime = VISU::TTime(aDt,anUnitDt);
844         INITMSG(MYDEBUG,"aDt = '"<<aDt<<", "<<anUnitDt<<"'\n");
845         
846         VISU::TGeom2NbGauss& aVGeom2NbGauss = aValForTime->myGeom2NbGauss;
847         const MED::TGeom2NbGauss& aMGeom2NbGauss = aTimeStampInfo->myGeom2NbGauss;
848         MED::TGeom2NbGauss::const_iterator anIter = aMGeom2NbGauss.begin();
849         for(; anIter != aMGeom2NbGauss.end(); anIter++){
850           const MED::EGeometrieElement& aMGeom = anIter->first;
851           VISU::EGeometry aEGeom = MEDGeom2VISU( aMGeom );
852           TInt aNbGauss = anIter->second;
853           aVGeom2NbGauss[ aEGeom ] = aNbGauss;
854
855           // ELNO data should satisfy the following condition ( implicitly )
856           vtkIdType aNbNodes = MEDGeom2NbNodes( aMGeom );
857           aField->myIsELNO &= ( aNbGauss == aNbNodes );
858         }
859       }
860     }
861   }
862
863
864   //---------------------------------------------------------------
865   void
866   BuildFamilyMap(VISU::PMEDMesh theMesh,
867                  const MED::TEntityInfo& theEntityInfo,
868                  const MED::TEntity2TGeom2ElemInfo& theEntity2TGeom2ElemInfo,
869                  const MED::TFamilyInfoSet& theFamilyInfoSet,
870                  MED::PWrapper theMEDWrapper)
871   {
872     VISU::TTimerLog aTimerLog(MYDEBUG,"BuildFamilyMap");
873     INITMSG(MYDEBUG,"BuildFamilyMap\n");
874
875     MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
876     MED::TEntity2FamilySet aEntity2FamilySet = MED::GetEntity2FamilySet(theMEDWrapper,theEntity2TGeom2ElemInfo,theFamilyInfoSet);
877     MED::TEntity2FamilySet::const_iterator aEntity2FamilySetIter = aEntity2FamilySet.begin();
878     for(; aEntity2FamilySetIter != aEntity2FamilySet.end(); aEntity2FamilySetIter++){
879       const MED::EEntiteMaillage& aMEntity = aEntity2FamilySetIter->first;
880       const MED::TFamilyTSizeSet& aFamilyTSizeSet = aEntity2FamilySetIter->second;
881       
882       VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
883       VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[aVEntity];
884       const VISU::TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize;
885       VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
886       VISU::TFamilyIDMap& aFamilyIDMap = aMeshOnEntity->myFamilyIDMap;
887         
888       if(aFamilyTSizeSet.empty())
889         continue;
890         
891       INITMSG(MY_FAMILY_DEBUG,
892               "- aMEntity = "<<aMEntity<<
893               "; aVEntity = "<<aVEntity<<
894               endl);
895
896       MED::TFamilyTSizeSet::const_iterator aFamilyTSizeSetIter = aFamilyTSizeSet.begin();
897       for(; aFamilyTSizeSetIter != aFamilyTSizeSet.end(); aFamilyTSizeSetIter++){
898         const MED::TFamilyTSize& aFamilyTSize = *aFamilyTSizeSetIter;
899         const MED::PFamilyInfo& aFamilyInfo = boost::get<0>(aFamilyTSize);
900         TInt aSize = boost::get<1>(aFamilyTSize);
901         TInt anId = aFamilyInfo->GetId();
902         if(anId == 0) 
903           continue;
904         
905         std::string aFamilyName = aFamilyInfo->GetName();
906
907         VISU::PMEDFamily aFamily = aFamilyMap[aFamilyName](new VISU::TMEDFamily());
908         aFamily->myId = anId;
909         aFamily->myEntity = aVEntity;
910         aFamily->myName = aFamilyName;
911         aFamily->myNbCells = aSize;
912
913         aFamily->myCellsSize = 0;
914         VISU::TFamilyID2CellsSize::const_iterator anIter = aFamilyID2CellsSize.find(anId);
915         if(anIter != aFamilyID2CellsSize.end())
916           aFamily->myCellsSize = anIter->second;
917
918         const TInt aNbGroup = aFamilyInfo->GetNbGroup();
919         VISU::TNames& aGroupNames = aFamily->myGroupNames;
920         aGroupNames.resize(aNbGroup);
921         for(TInt i = 0; i < aNbGroup; i++){
922           std::string aGroupName = aFamilyInfo->GetGroupName(i);
923           aGroupNames[i] = aGroupName;
924         }
925
926         aFamilyIDMap[anId] = aFamily;
927
928         INITMSG(MY_FAMILY_DEBUG,
929                 "- aFamilyName = '"<<aFamilyName<<"'"<<
930                 "; myId = "<<aFamily->myId<<"; "<<
931                 "; aNbAttr = "<<aFamilyInfo->GetNbAttr()<<
932                 "; aNbGroup = "<<aFamilyInfo->GetNbGroup()<<
933                 "; aVEntity = "<<aVEntity<<
934                 "; myNbCells = "<<aFamily->myNbCells<<
935                 "; myCellsSize = "<<aFamily->myCellsSize<<
936                 endl);
937 #ifdef _DEBUG_  
938         for(TInt i = 0; i < aNbGroup; i++){
939           std::string aGroupName = aFamilyInfo->GetGroupName(i);
940           INITMSG(MY_FAMILY_DEBUG,"- aGroupName = '"<<aGroupName<<"'\n");
941         }
942 #endif
943
944       }
945     }
946   }
947
948   
949   /*!
950    * Build grille family map
951    */
952   void
953   BuildGrilleFamilyMap(VISU::PMEDMesh theMesh,
954                        const MED::TEntityInfo& theEntityInfo,
955                        const MED::TFamilyInfoSet& theFamilyInfoSet,
956                        MED::PWrapper theMEDWrapper)
957   {
958     VISU::TTimerLog aTimerLog(MYDEBUG,"BuildGrilleFamilyMap");
959     INITMSG(MYDEBUG,"BuildGrilleFamilyMap\n");
960     
961     VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
962
963     MED::TEntityInfo::const_iterator aEntityIter = theEntityInfo.begin();
964
965     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
966     MED::PGrilleInfo aGrilleInfo = theMEDWrapper->GetPGrilleInfo(aMeshInfo);
967
968     const MED::TFamilyID2NbCells& aFam2NbCells = MED::GetFamilyID2NbCells(aGrilleInfo);
969
970     MED::TFamilyInfoSet::const_iterator aFamInter = theFamilyInfoSet.begin();
971     for(; aFamInter != theFamilyInfoSet.end(); aFamInter++){
972       const MED::PFamilyInfo& aFamilyInfo = *aFamInter;
973       TInt anId = aFamilyInfo->GetId();
974
975       if(anId == 0)
976         continue;
977
978       std::string aFamilyName = aFamilyInfo->GetName();
979       const MED::EEntiteMaillage& aMEntity = MED::GetEntityByFamilyId(aGrilleInfo,
980                                                                       anId);
981       VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
982
983       VISU::PMEDMeshOnEntity aMeshOnEntity;
984       VISU::TMeshOnEntityMap::iterator aMeshOnEntityIter = aMeshOnEntityMap.find(aVEntity);
985       if(aMeshOnEntityIter != aMeshOnEntityMap.end())
986         aMeshOnEntity = aMeshOnEntityIter->second;
987
988       VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
989       VISU::TFamilyIDMap& aFamilyIDMap = aMeshOnEntity->myFamilyIDMap;
990
991       VISU::PMEDFamily aFamily = aFamilyMap[aFamilyName](new VISU::TMEDFamily());
992       aFamily->myId = anId;
993       aFamily->myEntity = aVEntity;
994       aFamily->myName = aFamilyName;
995       aFamily->myNbCells = 0;
996       aFamily->myCellsSize = 0;
997
998       const VISU::TFamilyID2CellsSize& aFamilyID2CellsSize = aMeshOnEntity->myFamilyID2CellsSize;
999       VISU::TFamilyID2CellsSize::const_iterator aFamilyid2CellsSizeIter = aFamilyID2CellsSize.find(anId);
1000       if(aFamilyid2CellsSizeIter != (aMeshOnEntity->myFamilyID2CellsSize).end())
1001         aFamily->myCellsSize = aFamilyid2CellsSizeIter->second;
1002       MED::TFamilyID2NbCells::const_iterator aFam2NbCellsIter = aFam2NbCells.find(anId);
1003       if(aFam2NbCellsIter != aFam2NbCells.end())
1004         aFamily->myNbCells = aFam2NbCellsIter->second;
1005
1006       const TInt aNbGroup = aFamilyInfo->GetNbGroup();
1007       VISU::TNames& aGroupNames = aFamily->myGroupNames;
1008       aGroupNames.resize(aNbGroup);
1009       for(TInt i = 0; i < aNbGroup; i++){
1010         std::string aGroupName = aFamilyInfo->GetGroupName(i);
1011         aGroupNames[i] = aGroupName;
1012       }
1013
1014       aFamilyIDMap[anId] = aFamily;
1015
1016       INITMSG(MY_FAMILY_DEBUG,
1017               "- aFamilyName =|"<<aFamily->myName<<"|"
1018               << "; myId = "<<aFamily->myId
1019               << "; aNbAttr = "<<aFamilyInfo->GetNbAttr()
1020               << "; aNbGroup = "<<aFamilyInfo->GetNbGroup()
1021               << "; aVEntity = "<<aVEntity
1022               << "; myNbCells = "<<aFamily->myNbCells
1023               << "; myCellsSize = "<<aFamily->myCellsSize
1024               <<endl);
1025
1026
1027     }
1028   }
1029
1030   //---------------------------------------------------------------
1031   void
1032   BuildGroupMap(VISU::PMEDMesh theMesh,
1033                 const MED::TFamilyInfoSet& theFamilyInfoSet)
1034   {
1035     VISU::TTimerLog aTimerLog(MYDEBUG,"BuildGroupMap");
1036     INITMSG(MYDEBUG,"BuildGroupMap\n");
1037
1038     VISU::TGroupMap& aGroupMap = theMesh->myGroupMap;
1039     MED::TGroupInfo aGroupInfo = MED::GetGroupInfo(theFamilyInfoSet);
1040     MED::TGroupInfo::const_iterator aGroupInfoIter = aGroupInfo.begin();
1041     for(; aGroupInfoIter != aGroupInfo.end(); aGroupInfoIter++){
1042       const std::string& aGroupName = aGroupInfoIter->first;
1043       INITMSG(MY_GROUP_DEBUG,"aGroupName = '"<<aGroupName<<"'\n");
1044
1045       VISU::PMEDGroup aGroup(new VISU::TMEDGroup());
1046       VISU::TFamilySet& aFamilySet = aGroup->myFamilySet;
1047
1048       const MED::TFamilyInfoSet& aFamilyInfoSet = aGroupInfoIter->second;
1049       MED::TFamilyInfoSet::const_iterator aFamilyIter = aFamilyInfoSet.begin();
1050       for(; aFamilyIter != aFamilyInfoSet.end(); aFamilyIter++){
1051         const MED::PFamilyInfo& aFamilyInfo = *aFamilyIter;
1052         std::string aFamilyName = aFamilyInfo->GetName();
1053         
1054         VISU::TEntity aVEntity = VISU::TEntity(-1);
1055         VISU::PMEDFamily aFamily;
1056         
1057         // Find aVisuEntity
1058         const VISU::TMeshOnEntityMap& aMeshOnEntityMap = theMesh->myMeshOnEntityMap;
1059         VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityIter = aMeshOnEntityMap.begin();
1060         for(; aMeshOnEntityIter != aMeshOnEntityMap.end(); aMeshOnEntityIter++){
1061           const VISU::PMeshOnEntity& aMeshOnEntity = aMeshOnEntityIter->second;
1062           const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
1063           VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
1064           for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
1065             const std::string& aName = aFamilyMapIter->first;
1066             if(aName == aFamilyName){
1067               aFamily = aFamilyMapIter->second;
1068               aVEntity = aFamily->myEntity;
1069               goto exit_lable;
1070             }
1071           }
1072         } 
1073       exit_lable:
1074         if(aFamily && aVEntity >= 0){
1075           aFamilySet.insert(aFamily);
1076           INITMSG(MY_GROUP_DEBUG,
1077                   "- aFamilyName = '"<<aFamilyName<<"'"<<
1078                   "; aVEntity = "<<aVEntity<<
1079                   "\n");
1080         }
1081       }
1082       if(!aFamilySet.empty())
1083         aGroupMap.insert(VISU::TGroupMap::value_type(aGroupName,aGroup));
1084     }
1085   }
1086
1087
1088   //---------------------------------------------------------------
1089   struct TSetIsDone
1090   {
1091     bool& myIsDone;
1092     TSetIsDone(bool& theIsDone):
1093       myIsDone(theIsDone)
1094     {}
1095
1096     ~TSetIsDone()
1097     {
1098       myIsDone = true;
1099     }
1100
1101   };
1102
1103
1104   //---------------------------------------------------------------
1105 }
1106
1107 namespace VISU
1108 {
1109   //---------------------------------------------------------------
1110   void
1111   TMEDNamedPointCoords
1112   ::Init(const MED::PNodeInfo& theNodeInfo,
1113          MED::EVersion theVersion)
1114   {
1115     TMEDCoordHolder* aCoordHolder = new TMEDCoordHolder();
1116     TInt aNbElem = theNodeInfo->GetNbElem();
1117     TInt aDim = theNodeInfo->GetMeshInfo()->GetDim();
1118     aCoordHolder->Init(aNbElem, aDim, theNodeInfo->myCoord);
1119     TNamedPointCoords::Init(PCoordHolder(aCoordHolder));
1120     myVersion = theVersion;
1121
1122     for(TInt iDim = 0; iDim < aDim; iDim++)
1123       myPointsDim[iDim] = theNodeInfo->GetCoordName(iDim);
1124       
1125     myIsElemNum = theNodeInfo->IsElemNum();
1126     if(theNodeInfo->IsElemNum())
1127       myElemNum = theNodeInfo->myElemNum;
1128
1129     myIsElemNames = theNodeInfo->IsElemNames();
1130     if(theNodeInfo->IsElemNames())
1131       myElemNames = theNodeInfo->myElemNames;
1132   }
1133
1134   void
1135   TMEDNamedPointCoords
1136   ::Init(const MED::PGrilleInfo& theGrilleInfo)
1137   {
1138     TMEDCoordHolder* aCoordHolder = new TMEDCoordHolder();
1139     TInt aNbElem = theGrilleInfo->GetNbNodes();
1140     TInt aDim = theGrilleInfo->GetMeshInfo()->GetDim();
1141     MED::PNodeCoord aCoord(new MED::TNodeCoord(aNbElem * aDim));
1142     aCoordHolder->Init(aNbElem, aDim, aCoord);
1143     TNamedPointCoords::Init(PCoordHolder(aCoordHolder));
1144
1145     for(TInt iDim = 0; iDim < aDim; iDim++)
1146       myPointsDim[iDim] = theGrilleInfo->GetCoordName(iDim);
1147
1148     for(TInt iElem = 0; iElem < aNbElem; iElem++){
1149       VISU::TCoordSlice aVCoordSlice = GetCoordSlice(iElem);
1150       MED::TNodeCoord aMCoord = theGrilleInfo->GetCoord(iElem);
1151       for(TInt iDim = 0; iDim < aDim; iDim++){
1152         aVCoordSlice[iDim] = aMCoord[iDim];
1153       }
1154     }
1155   }
1156
1157   vtkIdType
1158   TMEDNamedPointCoords
1159   ::GetObjID(vtkIdType theID) const
1160   {
1161     if(myIsElemNum)
1162       return (*myElemNum)[theID];
1163     return TNamedPointCoords::GetObjID(theID);
1164   }
1165
1166
1167   vtkIdType
1168   TMEDNamedPointCoords
1169   ::GetVTKID(vtkIdType theID) const
1170   {
1171     if(myIsElemNum){
1172       // To prepare corresponding mapper engine
1173       if(myObj2VTKID.empty()){
1174         vtkIdType anEnd = myElemNum->size();
1175         for(vtkIdType anID = 0; anID < anEnd; anID++)
1176           myObj2VTKID[(*myElemNum)[anID]] = anID;
1177       }
1178       TObj2VTKID::const_iterator anIter = myObj2VTKID.find(theID);
1179       if(anIter != myObj2VTKID.end())
1180         return anIter->second;
1181       return -1;
1182     }
1183     return TNamedPointCoords::GetVTKID(theID);
1184   }
1185
1186   MED::TInt
1187   GetPNOMLength(MED::EVersion theVersion)
1188   {
1189     if(theVersion == MED::eV2_1)
1190       return MED::GetPNOMLength<MED::eV2_1>();
1191     return MED::GetPNOMLength<MED::eV2_2>();
1192   }
1193
1194   std::string 
1195   TMEDNamedPointCoords
1196   ::GetNodeName(vtkIdType theObjID) const
1197   {
1198     if(myIsElemNames)
1199       return GetString(theObjID, GetPNOMLength(myVersion), *myElemNames);
1200     return TNamedPointCoords::GetNodeName(theObjID);
1201   }
1202
1203   unsigned long int
1204   TMEDNamedPointCoords
1205   ::GetMemorySize()
1206   {
1207     size_t aSize = TNamedPointCoords::GetMemorySize();
1208
1209     if(myElemNum){
1210       aSize += myObj2VTKID.size() * sizeof(vtkIdType) * 2;
1211       aSize += myElemNum->size() * sizeof(MED::TInt);
1212     }
1213
1214     if(myIsElemNames)
1215       aSize += myElemNames->size() * sizeof(char);
1216     return aSize;
1217   }
1218
1219
1220   //---------------------------------------------------------------
1221   vtkIdType
1222   TMEDSubProfile
1223   ::GetElemObjID(vtkIdType theID) const
1224   {
1225     if ( !mySubMeshID.empty() )
1226       theID = mySubMeshID[theID];
1227
1228     if ( myIsElemNum )
1229       return (*myElemNum)[theID];
1230     else
1231       return theID;
1232   }
1233   
1234
1235   //---------------------------------------------------------------
1236   vtkIdType
1237   TMEDSubProfile
1238   ::GetElemVTKID(vtkIdType theID) const
1239   {
1240     if ( myIsElemNum )
1241       for ( size_t anId = 0; anId < (*myElemNum).size(); anId++ ) 
1242         if ( (*myElemNum)[ anId ] == theID ) {
1243           theID = anId;
1244           break;
1245         }
1246
1247     return TSubProfileImpl::GetElemVTKID( theID );
1248   }
1249
1250
1251   //----------------------------------------------------------------
1252   unsigned long int
1253   TMEDSubProfile
1254   ::GetMemorySize()
1255   {
1256     size_t aSize = TSubProfileImpl::GetMemorySize();
1257     if(myIsElemNum)
1258       aSize += myElemNum->size() * sizeof(MED::TInt);
1259     return aSize;
1260   }
1261
1262
1263   //---------------------------------------------------------------
1264   void
1265   TMEDGauss
1266   ::LessThan(const PGaussImpl& theGauss,
1267              bool& theResult) const
1268   {
1269     TGaussImpl::LessThan(theGauss,theResult);
1270     if(myGaussInfo){
1271       if(PMEDGauss aGauss = theGauss){
1272         const MED::TGaussInfo& aLeft = myGaussInfo;
1273         const MED::TGaussInfo& aReight = aGauss->myGaussInfo;
1274         theResult = MED::TGaussInfo::TLess()(aLeft,aReight);
1275       }
1276     }
1277   }
1278
1279
1280   //---------------------------------------------------------------
1281   TGaussPointID
1282   TMEDGaussSubMesh
1283   ::GetObjID(vtkIdType theID) const
1284   {
1285     vtkIdType aNbPoints = myGauss->myNbPoints;
1286     TCellID aCellID = theID / aNbPoints;
1287     TLocalPntID aLocalPntID = theID % aNbPoints;
1288
1289     if ( myIsElemNum )
1290       aCellID = GetElemObjID(aCellID);
1291     else
1292       aCellID += myStartID;
1293
1294     return TGaussPointID(aCellID, aLocalPntID);
1295   }
1296   
1297   
1298   //---------------------------------------------------------------
1299   vtkIdType
1300   TMEDGaussSubMesh
1301   ::GetVTKID( const TGaussPointID& theID ) const
1302   {
1303     vtkIdType aResult = -1;
1304
1305     TCellID aCellID = theID.first;
1306     TLocalPntID aLocalPntID = theID.second;
1307     
1308     vtkIdType aNbPoints = myGauss->myNbPoints;
1309     if ( aLocalPntID >= aNbPoints )
1310       return aResult;
1311     
1312     if ( myIsElemNum ) {
1313       aCellID = GetElemVTKID( aCellID );
1314     } else
1315       aCellID -= myStartID;
1316
1317     return aCellID * aNbPoints + aLocalPntID + myStartID;
1318   }
1319
1320
1321   //---------------------------------------------------------------
1322   unsigned long int
1323   TMEDGaussSubMesh
1324   ::GetMemorySize()
1325   {
1326     size_t aSize = TGaussSubMeshImpl::GetMemorySize();
1327     if(myIsElemNum)
1328       aSize += myElemNum->size() * sizeof(MED::TInt);
1329     return aSize;
1330   }
1331
1332
1333   //---------------------------------------------------------------
1334   void
1335   TMEDSubMesh
1336   ::Init(const MED::PElemInfo& theElemInfo,
1337          MED::EVersion theVersion)
1338   {
1339     myVersion = theVersion;
1340     myIsElemNum = theElemInfo->IsElemNum();
1341     if(myIsElemNum)
1342       myElemNum = theElemInfo->myElemNum;
1343
1344     myIsElemNames = theElemInfo->IsElemNames();
1345     if(theElemInfo->IsElemNames())
1346       myElemNames = theElemInfo->myElemNames;
1347   }
1348
1349
1350   void
1351   TMEDSubMesh
1352   ::Init(const MED::PGrilleInfo& theGrilleInfo)
1353   {}
1354
1355   vtkIdType
1356   TMEDSubMesh
1357   ::GetElemObjID(vtkIdType theID) const
1358   {
1359     if(myIsElemNum)
1360       return (*myElemNum)[theID];
1361     else
1362       return TSubMeshImpl::GetElemObjID(theID);
1363   }
1364
1365   std::string 
1366   TMEDSubMesh
1367   ::GetElemName(vtkIdType theObjID) const
1368   {
1369     if(myIsElemNames)
1370       return GetString(theObjID, GetPNOMLength(myVersion), *myElemNames);
1371     return TSubMeshImpl::GetElemName(theObjID);
1372   }
1373
1374   unsigned long int
1375   TMEDSubMesh
1376   ::GetMemorySize()
1377   {
1378     size_t aSize = TSubMeshImpl::GetMemorySize();
1379
1380     if(myIsElemNum)
1381       aSize += myElemNum->size() * sizeof(MED::TInt);
1382
1383     if(myIsElemNames)
1384       aSize += myElemNames->size() * sizeof(char);
1385
1386     return aSize;
1387   }
1388
1389
1390   //---------------------------------------------------------------
1391 }
1392
1393
1394 //---------------------------------------------------------------
1395 extern "C"
1396 VISU_Convertor* 
1397 CreateConvertor(const std::string& theFileName)
1398 {
1399   if(MED::PWrapper aMed = MED::CrWrapper(theFileName,true))
1400     return new VISU_MedConvertor(theFileName, aMed);
1401   return NULL;
1402 }
1403
1404 VISU_MedConvertor
1405 ::VISU_MedConvertor(const std::string& theFileName, MED::PWrapper theMed):
1406   myIsEntitiesDone(false),
1407   myIsFieldsDone(false),
1408   myIsGroupsDone(false),
1409   myIsMinMaxDone(false),
1410   myMed(theMed)
1411 {
1412   myName = theFileName;
1413 }
1414
1415
1416 //---------------------------------------------------------------
1417 VISU_Convertor* 
1418 VISU_MedConvertor
1419 ::BuildEntities()
1420 {
1421   if(myIsEntitiesDone)
1422     return this;
1423
1424   TSetIsDone aSetIsDone(myIsEntitiesDone);
1425   VISU::TTimerLog aTimerLog(MYDEBUG,"BuildEntities");
1426
1427   TInt aNbMeshes = myMed->GetNbMeshes();
1428   VISU::TMeshMap& aMeshMap = myMeshMap;
1429
1430   INITMSG(MYDEBUG,"BuildEntities aNbMeshes = "<<aNbMeshes<<"\n");
1431
1432   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
1433 #ifndef _DEXCEPT_
1434     try{
1435 #endif
1436       VISU::TTimerLog aTimerLog(MYDEBUG,"GetPMeshInfo");
1437
1438       MED::PMeshInfo aMeshInfo = myMed->GetPMeshInfo(iMesh);
1439       std::string aMeshName = aMeshInfo->GetName();
1440       TInt aDim = aMeshInfo->GetDim();
1441       MED::EMaillage aType = aMeshInfo->GetType();
1442         
1443       // creating TMesh structure and TMeshOnEntityMap         
1444       VISU::PMEDMesh aMesh = aMeshMap[aMeshName](new VISU::TMEDMesh());
1445       
1446       aMesh->myDim = aDim;
1447       aMesh->myName = aMeshName;
1448       aMesh->myMeshInfo = aMeshInfo;
1449       aMesh->myNamedPointCoords(new VISU::TMEDNamedPointCoords());
1450       
1451       INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<
1452               "; aDim = "<<aDim<<"\n");
1453
1454       if(aType == MED::eNON_STRUCTURE){
1455
1456         if(MED::PNodeInfo aNodeInfo = myMed->GetPNodeInfo(aMeshInfo)){
1457           MED::TEntityInfo anEntityInfo = myMed->GetEntityInfo(aMeshInfo);
1458
1459           aMesh->myNbPoints = aNodeInfo->GetNbElem();
1460           aMesh->myEntityInfo = anEntityInfo;
1461         
1462         
1463 #ifndef _DEXCEPT_
1464           try{
1465 #endif
1466             INITMSG(MYDEBUG,"myNbPoints = "<<aMesh->myNbPoints<<
1467                     "; anEntityInfo.size() = "<<anEntityInfo.size()<<
1468                     "\n");
1469             
1470             BuildMeshOnEntityMap(aMesh,
1471                                  anEntityInfo,
1472                                  aNodeInfo,
1473                                  myMed);
1474             
1475 #ifndef _DEXCEPT_
1476           }catch(std::exception& exc){
1477             MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1478           }catch(...){
1479             MSG(MYDEBUG,"Unknown exception !!!");
1480           }
1481 #endif
1482         }
1483       } // NON STRUCTURED MESH
1484       else {
1485         MED::PGrilleInfo aGrilleInfo = myMed->GetPGrilleInfo(aMeshInfo);
1486
1487         MED::TEntityInfo anEntityInfo;
1488         anEntityInfo[MED::eNOEUD][MED::ePOINT1] = aGrilleInfo->GetNbNodes();
1489         anEntityInfo[aGrilleInfo->GetEntity()][aGrilleInfo->GetGeom()] = aGrilleInfo->GetNbCells();
1490         
1491         aMesh->myNbPoints   = aGrilleInfo->GetNbNodes();
1492         aMesh->myEntityInfo = anEntityInfo;
1493
1494         aMesh->myIsPolarType = (MED::eGRILLE_POLAIRE == aGrilleInfo->GetGrilleType());
1495         aMesh->myIsStructured = true;
1496 #ifndef _DEXCEPT_
1497         try{
1498 #endif
1499           BEGMSG(MYDEBUG,"anEntityInfo.size() = "<<anEntityInfo.size()<<"\n");
1500           
1501           BuildMeshGrilleOnEntityMap(aMesh,
1502                                      anEntityInfo,
1503                                      aGrilleInfo,
1504                                      myMed);
1505           
1506 #ifndef _DEXCEPT_
1507         }catch(std::exception& exc){
1508           MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1509         }catch(...){
1510           MSG(MYDEBUG,"Unknown exception !!!");
1511         }
1512 #endif
1513
1514       }
1515
1516 #ifndef _DEXCEPT_
1517     }catch(std::exception& exc){
1518       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1519     }catch(...){
1520       MSG(MYDEBUG,"Unknown exception !!!");
1521     }
1522 #endif
1523   } 
1524
1525   return this; 
1526 }
1527
1528
1529 //---------------------------------------------------------------
1530 VISU_Convertor* 
1531 VISU_MedConvertor
1532 ::BuildFields()
1533 {
1534   if(myIsFieldsDone)
1535     return this;
1536
1537   VISU_Convertor_impl::BuildFields();
1538
1539   TSetIsDone aSetIsDone(myIsFieldsDone);
1540   VISU::TTimerLog aTimerLog(MYDEBUG,"BuildFields");
1541
1542   TInt aNbMeshes = myMed->GetNbMeshes();
1543   VISU::TMeshMap& aMeshMap = myMeshMap;
1544
1545   INITMSG(MYDEBUG,"BuildFields - aNbMeshes = "<<aNbMeshes<<"\n");
1546
1547   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
1548 #ifndef _DEXCEPT_
1549     try{
1550 #endif
1551       VISU::TTimerLog aTimerLog(MYDEBUG,"GetPMeshInfo");
1552
1553       MED::PMeshInfo aMeshInfo = myMed->GetPMeshInfo(iMesh);
1554       std::string aMeshName = aMeshInfo->GetName();
1555       
1556       VISU::TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName);
1557       if(anIter == aMeshMap.end())
1558         continue;
1559       VISU::PMEDMesh aMesh = anIter->second;
1560
1561       INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<"'\n");
1562 #ifndef _DEXCEPT_
1563       try{
1564 #endif
1565         MED::TEntityInfo anEntityInfo = myMed->GetEntityInfo(aMeshInfo);
1566
1567         BuildFieldMap(aMesh,
1568                       anEntityInfo,
1569                       myMed);
1570 #ifndef _DEXCEPT_
1571       }catch(std::exception& exc){
1572         MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1573       }catch(...){
1574         MSG(MYDEBUG,"Unknown exception !!!");
1575       }
1576 #endif
1577
1578 #ifndef _DEXCEPT_
1579     }catch(std::exception& exc){
1580       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1581     }catch(...){
1582       MSG(MYDEBUG,"Unknown exception !!!");
1583     }
1584 #endif
1585   } 
1586
1587   return this; 
1588 }
1589
1590
1591 //---------------------------------------------------------------
1592 template<class TimeStampValueType>
1593 void
1594 BuildTimeStampMinMax(MED::SharedPtr<TimeStampValueType> theTimeStampValue,
1595                      const VISU::PMEDMeshOnEntity theMeshOnEntity,
1596                      const MED::TGeom2Gauss& theGeom2Gauss,
1597                      VISU::TMetric2Comp2MinMax& theMetric2Comp2MinMax,
1598                      VISU::TMetric2Comp2MinMax& theMetric2Comp2AverageMinMax,
1599                      VISU::TMetric2Comp2Group2MinMax& theMetric2Comp2Group2MinMax,
1600                      VISU::TMetric2Comp2Group2MinMax& theMetric2Comp2Group2AverageMinMax,
1601                      TInt theNbComp,
1602                      TInt theNbComp2)
1603 {
1604   const VISU::TFamilyIDMap& aFamilyIDMap = theMeshOnEntity->myFamilyIDMap;
1605   VISU::TGeom2ElemID2FamilyID aGeom2ElemID2FamilyID = theMeshOnEntity->myGeom2ElemID2FamilyID;
1606
1607   VISU::TVector<double> aBaseAverageValues;
1608   aBaseAverageValues.resize(3);
1609   aBaseAverageValues[VISU::AVERAGE_METRIC] = 0.0;
1610   aBaseAverageValues[VISU::MINIMUM_METRIC] = VTK_LARGE_FLOAT;
1611   aBaseAverageValues[VISU::MAXIMUM_METRIC] = -VTK_LARGE_FLOAT;
1612
1613   const typename TimeStampValueType::TTGeom2Value& aGeom2Value = theTimeStampValue->myGeom2Value;
1614   typename TimeStampValueType::TTGeom2Value::const_iterator anIter = aGeom2Value.begin();
1615   for(; anIter != aGeom2Value.end(); anIter++){
1616     const typename TimeStampValueType::TTMeshValue& aMMeshValue = anIter->second;
1617     MED::EGeometrieElement aMGeom = anIter->first;
1618                   
1619     TInt aNbElem = aMMeshValue.myNbElem;
1620     TInt aNbGauss = aMMeshValue.myNbGauss;
1621                   
1622     MED::TGeom2Gauss::const_iterator aGaussIter = theGeom2Gauss.find(aMGeom);
1623     if(aGaussIter == theGeom2Gauss.end())
1624       aNbGauss = 1;
1625                   
1626     INITMSG(MYDEBUG,
1627             "- aMGeom = "<<aMGeom<<
1628             "; aNbElem = "<<aNbElem<<
1629             "; aNbGauss = "<<aNbGauss<<
1630             endl);
1631
1632     VISU::TElemID2FamilyID anElemID2FamilyID = aGeom2ElemID2FamilyID[aMGeom];
1633     
1634     bool isAverageByGaussPoints = (aNbGauss > 1);
1635     // To calculate min/max per components
1636     for(TInt iElem = 0; iElem < aNbElem; iElem++){
1637       typename TimeStampValueType::TTMeshValue::TCValueSliceArr aMValueSliceArr = aMMeshValue.GetCompValueSliceArr(iElem);
1638
1639       for(int aGaussMetric = (int)VISU::AVERAGE_METRIC; aGaussMetric <= (int)VISU::MAXIMUM_METRIC; aGaussMetric++){
1640         VISU::TComp2MinMax& aComp2MinMax = theMetric2Comp2MinMax[aGaussMetric];
1641         VISU::TComp2MinMax& aComp2AverageMinMax = theMetric2Comp2AverageMinMax[aGaussMetric];
1642         VISU::TComp2Group2MinMax& aComp2Group2MinMax = theMetric2Comp2Group2MinMax[aGaussMetric];
1643         VISU::TComp2Group2MinMax& aComp2Group2AverageMinMax = theMetric2Comp2Group2AverageMinMax[aGaussMetric];
1644
1645         for(TInt iComp = 0; iComp < theNbComp; iComp++){
1646           const typename TimeStampValueType::TTMeshValue::TCValueSlice& aMValueSlice = aMValueSliceArr[iComp];
1647
1648           VISU::TMinMax& aMinMax = aComp2MinMax[iComp+1];
1649           vtkFloatingPointType& aMin = aMinMax.first;
1650           vtkFloatingPointType& aMax = aMinMax.second;
1651           VISU::TMinMax& anAverageMinMax = aComp2AverageMinMax[iComp+1];
1652           vtkFloatingPointType& anAverageMin = anAverageMinMax.first;
1653           vtkFloatingPointType& anAverageMax = anAverageMinMax.second;
1654           vtkFloatingPointType anAverageValue = aBaseAverageValues[aGaussMetric];
1655
1656           VISU::TGroup2MinMax& aGroup2MinMax = aComp2Group2MinMax[iComp+1];
1657           VISU::TGroup2MinMax& aGroup2AverageMinMax = aComp2Group2AverageMinMax[iComp+1];
1658           std::map<VISU::TName,vtkFloatingPointType> aGroup2AverageValue;
1659
1660           // get names of groups, to which the element belongs
1661           VISU::TNames aGroupNames;
1662           VISU::TElemID2FamilyID::const_iterator anIter = anElemID2FamilyID.find(iElem);
1663           if(anIter != anElemID2FamilyID.end()){
1664             int aFamilyId = anIter->second;
1665             if(aFamilyId != 0){
1666               VISU::TFamilyIDMap::const_iterator aFamilyIter = aFamilyIDMap.find(aFamilyId);
1667               if(aFamilyIter != aFamilyIDMap.end()){
1668                 VISU::PMEDFamily aFamily = aFamilyIter->second;
1669                 aGroupNames = aFamily->myGroupNames;
1670                 VISU::TNames::const_iterator aGroupIter = aGroupNames.begin();
1671                 for(; aGroupIter != aGroupNames.end(); aGroupIter++)
1672                   aGroup2AverageValue[*aGroupIter] = aBaseAverageValues[aGaussMetric];
1673               }
1674             }
1675           }
1676
1677           for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
1678             const vtkFloatingPointType& aVal = aMValueSlice[iGauss];
1679             aMin = isnan(aVal) ? aVal : std::min(aMin,aVal);
1680             aMax = isnan(aVal) ? aVal : std::max(aMax,aVal);          
1681             if(isAverageByGaussPoints){
1682               switch(aGaussMetric) {
1683                 case VISU::AVERAGE_METRIC: anAverageValue += aVal; break;
1684                 case VISU::MINIMUM_METRIC: anAverageValue = std::min(anAverageValue, aVal); break;
1685                 case VISU::MAXIMUM_METRIC: anAverageValue = std::max(anAverageValue, aVal); break;
1686               }
1687             }
1688             else {
1689               anAverageMin = aMin;
1690               anAverageMax = aMax;
1691             }
1692
1693             // additional calculation for each group, to which the element belongs
1694             VISU::TNames::const_iterator aGroupIter = aGroupNames.begin();
1695             for(; aGroupIter != aGroupNames.end(); aGroupIter++){
1696               VISU::TName aGroupName = *aGroupIter;
1697               bool isGroupFound = aGroup2MinMax.find(aGroupName) != aGroup2MinMax.end();
1698               VISU::TMinMax& aGroupMinMax = aGroup2MinMax[aGroupName];
1699               vtkFloatingPointType& aGroupMin = aGroupMinMax.first;
1700               vtkFloatingPointType& aGroupMax = aGroupMinMax.second;
1701               aGroupMin = isGroupFound ? std::min(aGroupMin,aVal) : aVal;
1702               aGroupMax = isGroupFound ? std::max(aGroupMax,aVal) : aVal;          
1703
1704               if(isAverageByGaussPoints){
1705                 switch(aGaussMetric) {
1706                   case VISU::AVERAGE_METRIC: aGroup2AverageValue[aGroupName] = aGroup2AverageValue[aGroupName] + aVal; break;
1707                   case VISU::MINIMUM_METRIC: aGroup2AverageValue[aGroupName] = std::min(aGroup2AverageValue[aGroupName], aVal); break;
1708                   case VISU::MAXIMUM_METRIC: aGroup2AverageValue[aGroupName] = std::max(aGroup2AverageValue[aGroupName], aVal); break;
1709                 }
1710               }
1711               else {
1712                 VISU::TMinMax& aGroupAverageMinMax = aGroup2AverageMinMax[aGroupName];
1713                 vtkFloatingPointType& aGroupAverageMin = aGroupAverageMinMax.first;
1714                 vtkFloatingPointType& aGroupAverageMax = aGroupAverageMinMax.second;
1715                 aGroupAverageMin = aGroupMin;
1716                 aGroupAverageMax = aGroupMax;
1717               }
1718             }
1719           }
1720           if(isAverageByGaussPoints){
1721             if(aGaussMetric == VISU::AVERAGE_METRIC)
1722               anAverageValue /= aNbGauss;
1723             anAverageMin = std::min(anAverageMin,anAverageValue);
1724             anAverageMax = std::max(anAverageMax,anAverageValue);
1725
1726             VISU::TNames::const_iterator aGroupIter = aGroupNames.begin();
1727             for(; aGroupIter != aGroupNames.end(); aGroupIter++){
1728               VISU::TName aGroupName = *aGroupIter;
1729               vtkFloatingPointType aGroupAverageValue = aGroup2AverageValue[aGroupName];
1730               if(aGaussMetric == VISU::AVERAGE_METRIC)
1731                 aGroupAverageValue /= aNbGauss;
1732               bool isGroupFound = aGroup2AverageMinMax.find(aGroupName) != aGroup2AverageMinMax.end();
1733               VISU::TMinMax& aGroupAverageMinMax = aGroup2AverageMinMax[aGroupName];
1734               vtkFloatingPointType& aGroupAverageMin = aGroupAverageMinMax.first;
1735               vtkFloatingPointType& aGroupAverageMax = aGroupAverageMinMax.second;
1736               aGroupAverageMin = isGroupFound ? std::min(aGroupAverageMin,aGroupAverageValue) : aGroupAverageValue;
1737               aGroupAverageMax = isGroupFound ? std::max(aGroupAverageMax,aGroupAverageValue) : aGroupAverageValue;
1738             }
1739           }
1740         }
1741       }
1742     }
1743
1744     // To calculate min/max per vector modulus
1745     for(int aGaussMetric = (int)VISU::AVERAGE_METRIC; aGaussMetric <= (int)VISU::MAXIMUM_METRIC; aGaussMetric++){
1746       VISU::TComp2MinMax& aComp2MinMax = theMetric2Comp2MinMax[aGaussMetric];
1747       VISU::TComp2MinMax& aComp2AverageMinMax = theMetric2Comp2AverageMinMax[aGaussMetric];
1748       VISU::TComp2Group2MinMax& aComp2Group2MinMax = theMetric2Comp2Group2MinMax[aGaussMetric];
1749       VISU::TComp2Group2MinMax& aComp2Group2AverageMinMax = theMetric2Comp2Group2AverageMinMax[aGaussMetric];
1750
1751       VISU::TMinMax& aMinMax = aComp2MinMax[0];
1752       vtkFloatingPointType& aMin = aMinMax.first;
1753       vtkFloatingPointType& aMax = aMinMax.second;
1754       VISU::TMinMax& anAverageMinMax = aComp2AverageMinMax[0];
1755       vtkFloatingPointType& anAverageMin = anAverageMinMax.first;
1756       vtkFloatingPointType& anAverageMax = anAverageMinMax.second;
1757
1758       VISU::TGroup2MinMax& aGroup2MinMax = aComp2Group2MinMax[0];
1759       VISU::TGroup2MinMax& aGroup2AverageMinMax = aComp2Group2AverageMinMax[0];
1760
1761       for(TInt iElem = 0; iElem < aNbElem; iElem++){
1762         typename TimeStampValueType::TTMeshValue::TCValueSliceArr aMValueSliceArr = aMMeshValue.GetGaussValueSliceArr(iElem);
1763
1764         // get names of groups, to which the element belongs
1765         VISU::TNames aGroupNames;
1766         VISU::TElemID2FamilyID::const_iterator anIter = anElemID2FamilyID.find(iElem);
1767         if(anIter != anElemID2FamilyID.end()){
1768           int aFamilyId = anIter->second;
1769           if(aFamilyId != 0){
1770             VISU::TFamilyIDMap::const_iterator aFamilyIter = aFamilyIDMap.find(aFamilyId);
1771             if(aFamilyIter != aFamilyIDMap.end()){
1772               VISU::PMEDFamily aFamily = aFamilyIter->second;
1773               aGroupNames = aFamily->myGroupNames;
1774             }
1775           }
1776         }
1777
1778         for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
1779           const typename TimeStampValueType::TTMeshValue::TCValueSlice& aMValueSlice = aMValueSliceArr[iGauss];
1780           vtkFloatingPointType aValue = 0.0;
1781           for(TInt iComp = 0; iComp < theNbComp2; iComp++){
1782             vtkFloatingPointType aVal = aMValueSlice[iComp];
1783             aValue += aVal*aVal;
1784           }
1785           aValue = sqrt(aValue);
1786           aMin = isnan(aValue) ? aValue : std::min(aMin,aValue);
1787           aMax = isnan(aValue) ? aValue : std::max(aMax,aValue);
1788
1789           // additional calculation for each group, to which the element belongs
1790           VISU::TNames::const_iterator aGroupIter = aGroupNames.begin();
1791           for(; aGroupIter != aGroupNames.end(); aGroupIter++){
1792             VISU::TName aGroupName = *aGroupIter;
1793             bool isGroupFound = aGroup2MinMax.find(aGroupName) != aGroup2MinMax.end();
1794             VISU::TMinMax& aGroupMinMax = aGroup2MinMax[aGroupName];
1795             vtkFloatingPointType& aGroupMin = aGroupMinMax.first;
1796             vtkFloatingPointType& aGroupMax = aGroupMinMax.second;
1797             aGroupMin = isGroupFound ? std::min(aGroupMin,aValue) : aValue;
1798             aGroupMax = isGroupFound ? std::max(aGroupMax,aValue) : aValue;
1799           }
1800         }
1801         if(isAverageByGaussPoints){
1802           typename TimeStampValueType::TTMeshValue::TCValueSliceArr aMCompValueSliceArr = aMMeshValue.GetCompValueSliceArr(iElem);
1803           vtkFloatingPointType aValue = 0.0;
1804           for(TInt iComp = 0; iComp < theNbComp2; iComp++){
1805             const typename TimeStampValueType::TTMeshValue::TCValueSlice& aMCompValueSlice = aMCompValueSliceArr[iComp];
1806             vtkFloatingPointType anAverageValue = aBaseAverageValues[aGaussMetric];
1807             for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
1808               const vtkFloatingPointType& aVal = aMCompValueSlice[iGauss];
1809               switch(aGaussMetric) {
1810                 case VISU::AVERAGE_METRIC: anAverageValue += aVal; break;
1811                 case VISU::MINIMUM_METRIC: anAverageValue = std::min(anAverageValue, aVal); break;
1812                 case VISU::MAXIMUM_METRIC: anAverageValue = std::max(anAverageValue, aVal); break;
1813               }
1814             }
1815             if(aGaussMetric == VISU::AVERAGE_METRIC)
1816               anAverageValue /= aNbGauss;
1817             aValue += anAverageValue*anAverageValue;
1818           }
1819           aValue = sqrt(aValue);
1820           anAverageMin = std::min(anAverageMin,aValue);
1821           anAverageMax = std::max(anAverageMax,aValue);
1822
1823           // additional calculation for each group, to which the element belongs
1824           VISU::TNames::const_iterator aGroupIter = aGroupNames.begin();
1825           for(; aGroupIter != aGroupNames.end(); aGroupIter++){
1826             VISU::TName aGroupName = *aGroupIter;
1827             bool isGroupFound = aGroup2AverageMinMax.find(aGroupName) != aGroup2AverageMinMax.end();
1828             VISU::TMinMax& aGroupAverageMinMax = aGroup2AverageMinMax[aGroupName];
1829             vtkFloatingPointType& aGroupAverageMin = aGroupAverageMinMax.first;
1830             vtkFloatingPointType& aGroupAverageMax = aGroupAverageMinMax.second;
1831             aGroupAverageMin = isGroupFound ? std::min(aGroupAverageMin,aValue) : aValue;
1832             aGroupAverageMax = isGroupFound ? std::max(aGroupAverageMax,aValue) : aValue;
1833           }
1834         }
1835         else {
1836           anAverageMin = aMin;
1837           anAverageMax = aMax;
1838
1839           // additional calculation for each group, to which the element belongs
1840           VISU::TNames::const_iterator aGroupIter = aGroupNames.begin();
1841           for(; aGroupIter != aGroupNames.end(); aGroupIter++){
1842             VISU::TName aGroupName = *aGroupIter;
1843             VISU::TMinMax& aGroupAverageMinMax = aGroup2AverageMinMax[aGroupName];
1844             vtkFloatingPointType& aGroupAverageMin = aGroupAverageMinMax.first;
1845             vtkFloatingPointType& aGroupAverageMax = aGroupAverageMinMax.second;
1846             aGroupAverageMin = aGroup2MinMax[aGroupName].first;
1847             aGroupAverageMax = aGroup2MinMax[aGroupName].second;
1848           }
1849         }
1850       }
1851     }
1852   }
1853 }
1854
1855   
1856 //---------------------------------------------------------------
1857 VISU_Convertor* 
1858 VISU_MedConvertor
1859 ::BuildMinMax()
1860 {
1861   if(myIsMinMaxDone)
1862     return this;
1863
1864   VISU_Convertor_impl::BuildMinMax();
1865
1866   TSetIsDone aSetIsDone(myIsMinMaxDone);
1867   VISU::TTimerLog aTimerLog(MYDEBUG,"BuildMinMax");
1868
1869   MED::TKey2Gauss aKey2Gauss = MED::GetKey2Gauss(myMed);
1870   MED::TMKey2Profile aMKey2Profile = MED::GetMKey2Profile(myMed);
1871
1872   TInt aNbMeshes = myMed->GetNbMeshes();
1873   VISU::TMeshMap& aMeshMap = myMeshMap;
1874
1875   INITMSG(MYDEBUG,"BuildMinMax - aNbMeshes = "<<aNbMeshes<<"\n");
1876
1877   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
1878 #ifndef _DEXCEPT_
1879     try{
1880 #endif
1881       VISU::TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPMeshInfo");
1882
1883       MED::PMeshInfo aMeshInfo = myMed->GetPMeshInfo(iMesh);
1884       std::string aMeshName = aMeshInfo->GetName();
1885       
1886       VISU::TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName);
1887       if(anIter == aMeshMap.end())
1888         continue;
1889       VISU::PMEDMesh aMesh = anIter->second;
1890
1891 #ifndef _DEXCEPT_
1892       try{
1893 #endif
1894         TInt aNbFields = myMed->GetNbFields(); 
1895
1896         INITMSG(MYDEBUG,
1897                 "- aMeshName = '"<<aMeshName<<"'"<<
1898                 "; aNbFields = "<<aNbFields<<"\n");
1899
1900         MED::TEntityInfo anEntityInfo = myMed->GetEntityInfo(aMeshInfo);
1901
1902         for(TInt iField = 1; iField <= aNbFields; iField++){
1903           VISU::TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPFieldInfo()");
1904
1905           MED::TErr anError = 0;
1906           MED::PFieldInfo aFieldInfo = myMed->GetPFieldInfo(aMeshInfo, iField, &anError);
1907           if ( anError < 0 )
1908             continue;
1909
1910           std::string aFieldName = aFieldInfo->GetName();
1911           INITMSG(MYDEBUG,"- aFieldName = '"<<aFieldName<<"'\n");
1912           
1913           MED::TGeom2Size aGeom2Size;
1914           MED::EEntiteMaillage aMEntity;
1915           TInt aNbTimeStamps = myMed->GetNbTimeStamps(aFieldInfo,
1916                                                      anEntityInfo,
1917                                                      aMEntity,
1918                                                      aGeom2Size);
1919           if(aNbTimeStamps < 1)
1920             continue;
1921         
1922           VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
1923           VISU::PMEDMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
1924           VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1925           VISU::PMEDField aField = aFieldMap[aFieldName];
1926         
1927           TInt aNbComp = aField->myNbComp;
1928           int aNbComp2 = aNbComp;
1929           if(aNbComp == 2 || aNbComp == 4)
1930             aNbComp2 = 2;
1931           else if(aNbComp > 4)
1932             aNbComp2 = 3;
1933
1934           VISU::TMetric2Comp2MinMax& aMetric2Comp2MinMax = aField->myMetric2Comp2MinMax;
1935           VISU::TMetric2Comp2MinMax& aMetric2Comp2AverageMinMax = aField->myMetric2Comp2AverageMinMax;
1936           VISU::TMetric2Comp2Group2MinMax& aMetric2Comp2Group2MinMax = aField->myMetric2Comp2Group2MinMax;
1937           VISU::TMetric2Comp2Group2MinMax& aMetric2Comp2Group2AverageMinMax = aField->myMetric2Comp2Group2AverageMinMax;
1938           TSetIsDone aSetIsDone(aField->myIsMinMaxInitilized);
1939           for(TInt iTimeStamp = aNbTimeStamps; iTimeStamp >= 1; iTimeStamp--){
1940             VISU::TTimerLog aTimerLog(MYDEBUG,"BuildMinMax - GetPTimeStampInfo()");
1941             INITMSG(MYDEBUG,"- iTimeStamp = "<<iTimeStamp<<endl);
1942             
1943 #ifndef _DEXCEPT_
1944             try {
1945 #ifdef NO_CAS_CATCH
1946               OCC_CATCH_SIGNALS;
1947 #endif
1948 #endif
1949               MED::PTimeStampInfo aTimeStampInfo = 
1950                 myMed->GetPTimeStampInfo(aFieldInfo,
1951                                          aMEntity,
1952                                          aGeom2Size,
1953                                          iTimeStamp);
1954
1955               MED::PTimeStampValueBase aTimeStampValue = 
1956                 myMed->GetPTimeStampValue(aTimeStampInfo,
1957                                           aMKey2Profile,
1958                                           aKey2Gauss);
1959
1960               const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->GetGeom2Gauss();
1961
1962               if(aFieldInfo->GetType() == MED::eFLOAT64)
1963                 BuildTimeStampMinMax<MED::TFloatTimeStampValue>(CastToFloatTimeStampValue(aTimeStampValue),
1964                                                                 aMeshOnEntity,
1965                                                                 aGeom2Gauss,
1966                                                                 aMetric2Comp2MinMax,
1967                                                                 aMetric2Comp2AverageMinMax,
1968                                                                 aMetric2Comp2Group2MinMax,
1969                                                                 aMetric2Comp2Group2AverageMinMax,
1970                                                                 aNbComp,
1971                                                                 aNbComp2);
1972               else
1973                 BuildTimeStampMinMax<MED::TIntTimeStampValue>(CastToIntTimeStampValue(aTimeStampValue),
1974                                                               aMeshOnEntity,
1975                                                               aGeom2Gauss,
1976                                                               aMetric2Comp2MinMax,
1977                                                               aMetric2Comp2AverageMinMax,
1978                                                               aMetric2Comp2Group2MinMax,
1979                                                               aMetric2Comp2Group2AverageMinMax,
1980                                                               aNbComp,
1981                                                               aNbComp2);
1982
1983 #ifndef _DEXCEPT_
1984             }catch(Standard_Failure){
1985               Handle(Standard_Failure) aFail = Standard_Failure::Caught();          
1986               MSG(MYDEBUG,"Follow signal was occured in:\n"<<aFail->GetMessageString());
1987             }catch(std::exception& exc){
1988               MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
1989             }catch(...){
1990               MSG(MYDEBUG,"Unknown exception !!!");
1991             }
1992 #endif
1993           }
1994           for(TInt iComp = 0; iComp <= aNbComp; iComp++){
1995             VISU::TMinMax aMinMax = aField->GetMinMax(iComp, VISU::TNames());
1996             INITMSG(MYDEBUG,"- "<<iComp<<": "<<aMinMax.first<<"; "<<aMinMax.second<<endl);
1997           }
1998         }
1999 #ifndef _DEXCEPT_
2000       }catch(std::exception& exc){
2001         MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
2002       }catch(...){
2003         MSG(MYDEBUG,"Unknown exception !!!");
2004       }
2005 #endif
2006
2007 #ifndef _DEXCEPT_
2008     }catch(std::exception& exc){
2009       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
2010     }catch(...){
2011       MSG(MYDEBUG,"Unknown exception !!!");
2012     }
2013 #endif
2014   }
2015
2016   return this; 
2017 }
2018
2019
2020 //---------------------------------------------------------------
2021 VISU_Convertor* 
2022 VISU_MedConvertor
2023 ::BuildGroups()
2024 {
2025   if(myIsGroupsDone)
2026     return this;
2027
2028   TSetIsDone aSetIsDone(myIsGroupsDone);
2029   VISU::TTimerLog aTimerLog(MYDEBUG,"BuildGroups");
2030
2031   TInt aNbMeshes = myMed->GetNbMeshes();
2032   VISU::TMeshMap& aMeshMap = myMeshMap;
2033
2034   INITMSG(MYDEBUG,"BuildGroups - aNbMeshes = "<<aNbMeshes<<"\n");
2035
2036   for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
2037 #ifndef _DEXCEPT_
2038     try{
2039 #endif
2040       VISU::TTimerLog aTimerLog(MYDEBUG,"GetPMeshInfo");
2041
2042       MED::PMeshInfo aMeshInfo = myMed->GetPMeshInfo(iMesh);
2043       std::string aMeshName = aMeshInfo->GetName();      
2044
2045       VISU::TMeshMap::const_iterator anIter = aMeshMap.find(aMeshName);
2046       if(anIter == aMeshMap.end())
2047         continue;
2048       VISU::PMEDMesh aMesh = anIter->second;
2049
2050       INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<"'\n");
2051
2052       MED::EMaillage aType = aMeshInfo->GetType();
2053       
2054       MED::TEntityInfo anEntityInfo = myMed->GetEntityInfo(aMeshInfo);
2055       
2056       MED::TEntity2TGeom2ElemInfo anEntity2TGeom2ElemInfo = 
2057         MED::GetEntity2TGeom2ElemInfo(myMed, aMeshInfo, anEntityInfo);
2058       
2059 #ifndef _DEXCEPT_
2060       try{
2061 #endif
2062         MED::TFamilyInfoSet aFamilyInfoSet = MED::GetFamilyInfoSet(myMed, aMeshInfo);
2063         
2064         if(aType == MED::eNON_STRUCTURE)
2065           BuildFamilyMap(aMesh,
2066                          anEntityInfo,
2067                          anEntity2TGeom2ElemInfo,
2068                          aFamilyInfoSet,
2069                          myMed);
2070         else
2071           BuildGrilleFamilyMap(aMesh,
2072                                anEntityInfo,
2073                                aFamilyInfoSet,
2074                                myMed);
2075         
2076         BuildGroupMap(aMesh,
2077                       aFamilyInfoSet);
2078 #ifndef _DEXCEPT_
2079       }catch(std::exception& exc){
2080         MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
2081       }catch(...){
2082           MSG(MYDEBUG,"Unknown exception !!!");
2083       }
2084 #endif
2085
2086 #ifndef _DEXCEPT_
2087     }catch(std::exception& exc){
2088       MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
2089     }catch(...){
2090       MSG(MYDEBUG,"Unknown exception !!!");
2091     }
2092 #endif
2093   } 
2094
2095   return this; 
2096 }
2097
2098
2099 //---------------------------------------------------------------
2100 int
2101 VISU_MedConvertor
2102 ::LoadMeshOnEntity(VISU::PMeshImpl theMesh,
2103                    VISU::PMeshOnEntityImpl theMeshOnEntity)
2104 {
2105   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadMeshOnEntity");
2106   INITMSG(MYDEBUG,"LoadMeshOnEntity"<<endl);
2107
2108   const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
2109
2110   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
2111   if(anEntity == VISU::NODE_ENTITY){
2112     isPointsUpdated += LoadPoints(myMed, theMesh);
2113   }else{
2114     isPointsUpdated += LoadPoints(myMed, theMesh);
2115     isCellsOnEntityUpdated += LoadCellsOnEntity(myMed, theMesh, theMeshOnEntity);
2116   }
2117
2118   return (isPointsUpdated || isCellsOnEntityUpdated);
2119 }
2120
2121
2122 //---------------------------------------------------------------
2123 int
2124 VISU_MedConvertor
2125 ::LoadFamilyOnEntity(VISU::PMeshImpl theMesh,
2126                      VISU::PMeshOnEntityImpl theMeshOnEntity, 
2127                      VISU::PFamilyImpl theFamily)
2128 {
2129   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadFamilyOnEntity");
2130   INITMSG(MYDEBUG,"LoadFamilyOnEntity"<<endl);
2131
2132   const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
2133
2134   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
2135   if(anEntity == VISU::NODE_ENTITY){
2136     isPointsUpdated += LoadPointsOnFamily(myMed, theMesh, theFamily);
2137   }else{
2138     isPointsUpdated += LoadPoints(myMed, theMesh);
2139     isCellsOnEntityUpdated += LoadCellsOnFamily(myMed, theMesh, theMeshOnEntity, theFamily);
2140   }
2141
2142   return (isPointsUpdated || isCellsOnEntityUpdated);
2143 }
2144
2145
2146 //---------------------------------------------------------------
2147 int
2148 VISU_MedConvertor
2149 ::LoadMeshOnGroup(VISU::PMeshImpl theMesh, 
2150                   const VISU::TFamilySet& theFamilySet)
2151 {
2152   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadMeshOnGroup");
2153   INITMSG(MYDEBUG,"LoadMeshOnGroup"<<endl);
2154
2155   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
2156   VISU::TFamilySet::const_iterator aFamilyIter = theFamilySet.begin();
2157   for(; aFamilyIter != theFamilySet.end(); aFamilyIter++){
2158     VISU::PMEDFamily aFamily = *aFamilyIter;
2159     const VISU::TEntity& anEntity = aFamily->myEntity;
2160     const VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity];
2161     isPointsUpdated += LoadPoints(myMed, theMesh);
2162     if(anEntity == VISU::NODE_ENTITY){
2163       isPointsUpdated += LoadPointsOnFamily(myMed, theMesh, aFamily);
2164     }else{
2165       isCellsOnEntityUpdated += LoadCellsOnFamily(myMed,theMesh,aMeshOnEntity,aFamily);
2166     }
2167   }
2168
2169   return (isPointsUpdated || isCellsOnEntityUpdated);
2170 }
2171
2172
2173 //---------------------------------------------------------------
2174 int
2175 VISU_MedConvertor
2176 ::LoadValForTimeOnMesh(VISU::PMeshImpl theMesh, 
2177                        VISU::PMeshOnEntityImpl theMeshOnEntity, 
2178                        VISU::PFieldImpl theField, 
2179                        VISU::PValForTimeImpl theValForTime)
2180 {
2181   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadValForTimeOnMesh");
2182   INITMSG(MYDEBUG,"LoadValForTimeOnMesh"<<endl);
2183
2184   const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
2185   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
2186   isPointsUpdated += LoadPoints(myMed,theMesh);
2187   if(anEntity != VISU::NODE_ENTITY)
2188     isCellsOnEntityUpdated += LoadCellsOnEntity(myMed,theMesh,theMeshOnEntity);
2189   int isFieldUpdated = LoadValForTimeOnMesh(myMed,theMesh,theMeshOnEntity,theField,theValForTime);
2190   
2191   return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
2192 }
2193
2194
2195 //---------------------------------------------------------------
2196 int
2197 VISU_MedConvertor
2198 ::LoadValForTimeOnGaussPts(VISU::PMeshImpl theMesh, 
2199                            VISU::PMeshOnEntityImpl theMeshOnEntity, 
2200                            VISU::PFieldImpl theField, 
2201                            VISU::PValForTimeImpl theValForTime)
2202 {
2203   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadValForTimeOnGaussPts");
2204   INITMSG(MYDEBUG,"LoadValForTimeOnGaussPts"<<endl);
2205
2206   const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
2207   int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
2208   if(anEntity != VISU::NODE_ENTITY)
2209     isCellsOnEntityUpdated += LoadCellsOnEntity(myMed,theMesh,theMeshOnEntity);
2210   int isFieldUpdated = LoadValForTimeOnGaussPts(myMed,theMesh,theMeshOnEntity,theField,theValForTime);
2211   
2212   return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
2213 }
2214
2215
2216 //---------------------------------------------------------------
2217 int 
2218 VISU_MedConvertor
2219 ::LoadPoints(const MED::PWrapper& theMed,
2220              VISU::PMEDMesh theMesh) 
2221 {
2222   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadPoints");
2223   try{
2224     //Check on existing family
2225     VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
2226     aMeshOnEntity->myMeshName = theMesh->myName;
2227     aMeshOnEntity->myEntity = VISU::NODE_ENTITY;
2228
2229     INITMSG(MYDEBUG,"LoadPoints - theMesh->myIsDone = "<<theMesh->myIsDone<<"'\n");
2230
2231     //Check on loading already done
2232     if(theMesh->myIsDone)
2233       return 0;
2234
2235     MED::EMaillage aType = theMesh->myMeshInfo->GetType();
2236     
2237     if(aType == MED::eNON_STRUCTURE){
2238       //Main part of code
2239       MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo);
2240       TInt aNbElem = aNodeInfo->GetNbElem();
2241       
2242       VISU::PMEDNamedPointCoords aNamedPointCoords = theMesh->myNamedPointCoords;
2243       aNamedPointCoords->Init(aNodeInfo, theMed->GetVersion());
2244       
2245       VISU::TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
2246       VISU::PMEDSubMesh aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new VISU::TMEDSubMesh());
2247       
2248       aSubMesh->Init(MED::PElemInfo(aNodeInfo), theMed->GetVersion()); 
2249       aSubMesh->myNbCells = theMesh->myNbPoints;
2250       aSubMesh->myCellsSize = 2*theMesh->myNbPoints;
2251       
2252       VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
2253       aCell2Connect.resize(aNbElem);
2254       for (int iElem = 0; iElem < aNbElem; iElem++)
2255         aCell2Connect[iElem] = VISU::TConnect(1,iElem);
2256     } // END NON_STRUCTURED
2257     else { // STRUCTURED
2258       //Main part of code
2259       MED::PGrilleInfo aGrilleInfo = theMed->GetPGrilleInfo(theMesh->myMeshInfo);
2260       TInt aNbElem = aGrilleInfo->GetNbNodes();
2261       
2262       VISU::PMEDNamedPointCoords aNamedPointCoords = theMesh->myNamedPointCoords;
2263       aNamedPointCoords->Init(aGrilleInfo);
2264       
2265       VISU::TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
2266       VISU::PMEDSubMesh aSubMesh = aGeom2SubMesh[VISU::ePOINT1](new VISU::TMEDSubMesh());
2267       
2268       aSubMesh->Init(aGrilleInfo); 
2269       aSubMesh->myNbCells = theMesh->myNbPoints;
2270       aSubMesh->myCellsSize = 2*theMesh->myNbPoints;
2271       
2272       VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
2273       aCell2Connect.resize(aNbElem);
2274       for(int iElem = 0; iElem < aNbElem; iElem++)
2275         aCell2Connect[iElem] = VISU::TConnect(1,iElem);
2276       
2277     }
2278     
2279     theMesh->myIsDone = true;
2280     
2281     return 1;
2282
2283   }catch(std::exception& exc){
2284     throw;
2285   }catch(...){
2286     EXCEPTION(std::runtime_error,"Unknown exception !!!");
2287   }
2288
2289   return 0;
2290 }
2291
2292
2293 //---------------------------------------------------------------
2294 int 
2295 VISU_MedConvertor
2296 ::LoadPointsOnFamily(const MED::PWrapper& theMed,
2297                      const VISU::PMEDMesh theMesh, 
2298                      const VISU::PMEDFamily theFamily) 
2299 {
2300   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadPointsOnFamily");
2301   try{
2302     if(theFamily->myIsDone) 
2303       return 0;
2304
2305     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2306     MED::EMaillage aType = aMeshInfo->GetType();
2307
2308     //Main part of code
2309     if(aType == MED::eNON_STRUCTURE){
2310       MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo);
2311       TInt aNbElem = aNodeInfo->GetNbElem();
2312       
2313       if(aNbElem > 0){
2314         TInt anId = theFamily->myId;
2315         VISU::TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1];
2316         for(TInt iElem = 0; iElem < aNbElem; iElem++) 
2317           if(aNodeInfo->GetFamNum(iElem) == anId)
2318             aSubMeshID.push_back(iElem);
2319       }
2320     }
2321     else {
2322       MED::PGrilleInfo aGrilleInfo = theMed->GetPGrilleInfo(aMeshInfo);
2323       TInt aNbElem = aGrilleInfo->GetNbNodes();
2324       
2325       if(aNbElem > 0){
2326         TInt anId = theFamily->myId;
2327         VISU::TSubMeshID& aSubMeshID = theFamily->myGeom2SubMeshID[VISU::ePOINT1];
2328         for(TInt iElem = 0; iElem < aNbElem; iElem++) 
2329           if(aGrilleInfo->GetFamNumNode(iElem) == anId)
2330             aSubMeshID.push_back(iElem);
2331       }
2332     }
2333
2334     theFamily->myIsDone = true;
2335
2336     return 1;
2337
2338   }catch(std::exception& exc){
2339     throw;
2340   }catch(...){
2341     EXCEPTION(std::runtime_error,"Unknown exception !!!");
2342   }
2343
2344   return 0;
2345 }
2346
2347
2348 //---------------------------------------------------------------
2349 int 
2350 VISU_MedConvertor
2351 ::LoadCellsOnEntity(const MED::PWrapper& theMed,
2352                     const VISU::PMEDMesh theMesh,
2353                     const VISU::PMEDMeshOnEntity theMeshOnEntity)
2354 {
2355   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadCellsOnEntity");
2356 #ifndef _DEXCEPT_
2357   try{
2358 #endif
2359     const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
2360     const MED::EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity);
2361
2362     INITMSG(MYDEBUG,"LoadCellsOnEntity - aVEntity = "<<aVEntity<<"\n");
2363
2364     if(theMeshOnEntity->myIsDone)
2365       return 0;
2366
2367     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2368
2369     MED::EMaillage aType = aMeshInfo->GetType();
2370
2371     if(aType == MED::eSTRUCTURE){
2372       
2373       MED::PGrilleInfo aGrilleInfo = theMed->GetPGrilleInfo(aMeshInfo);
2374       TInt aNbPoints = aGrilleInfo->GetNbNodes();
2375       
2376       std::map<TInt,TInt> aNodeIdMap;
2377       EBooleen anIsNodeNum = MED::eFAUX;
2378       
2379       const MED::TGeom2Size& aGeom2Size = theMeshOnEntity->myGeom2Size;
2380       MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
2381       VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
2382       
2383       for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
2384         const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
2385         VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
2386         INITMSG(MYDEBUG,"aMGeom = "<<aMGeom<<"; aEGeom = "<<aEGeom<<"\n");
2387         {
2388           vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
2389           INITMSG(MYDEBUG,"aVNbNodes = "<<aVNbNodes<<"\n");
2390         
2391           TInt aNbElem = aGeom2SizeIter->second;//aGrilleInfo->GetNbCells();
2392           
2393           if(aNbElem > 0){
2394             VISU::PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TMEDSubMesh());
2395             
2396             aSubMesh->Init(aGrilleInfo); 
2397             aSubMesh->myNbCells = aNbElem;      
2398             aSubMesh->myCellsSize = aNbElem*(aVNbNodes+1);
2399             
2400             VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
2401             aCell2Connect.resize(aNbElem);
2402             
2403             TInt aMNbNodes = MEDGeom2NbNodes(aMGeom);
2404             VISU::TVector<TInt> aConnect(aMNbNodes);
2405             
2406             for(TInt iElem = 0; iElem < aNbElem; iElem++) {
2407               MED::TIntVector aConn = aGrilleInfo->GetConn(iElem);
2408               VISU::TConnect& anArray = aCell2Connect[iElem];
2409               anArray.resize(aVNbNodes);
2410               
2411               if(anIsNodeNum){
2412                 for(TInt iConn = 0; iConn < aMNbNodes; iConn++){
2413                   aConnect[iConn] = aNodeIdMap[aConn[iConn] - 1];
2414                 }
2415               }else{
2416                 for(int iConn = 0; iConn < aMNbNodes; ++iConn){
2417                   aConnect[iConn] = aConn[iConn];
2418                 }
2419               }
2420               
2421               switch(aMGeom){
2422               case MED::eQUAD4:
2423                 anArray[0] = aConnect[0];
2424                 anArray[1] = aConnect[2];
2425                 anArray[2] = aConnect[3];
2426                 anArray[3] = aConnect[1];
2427                 break;
2428               case MED::eHEXA8:
2429                 anArray[0] = aConnect[0];
2430                 anArray[1] = aConnect[2];
2431                 anArray[2] = aConnect[3];
2432                 anArray[3] = aConnect[1];
2433                 anArray[4] = aConnect[4];
2434                 anArray[5] = aConnect[6];
2435                 anArray[6] = aConnect[7];
2436                 anArray[7] = aConnect[5];
2437                 break;
2438               default:
2439                 for(int iNode = 0; iNode < aVNbNodes; iNode++) 
2440                   anArray[iNode] = aConnect[iNode];
2441               }
2442               
2443               for(int iNode = 0; iNode < aVNbNodes; iNode++) 
2444                 if(anArray[iNode] < 0 || aNbPoints <= anArray[iNode])
2445                   EXCEPTION(std::runtime_error,"LoadCellsOnEntity - "<<
2446                             " aNbPoints("<<aNbPoints<<") "<<
2447                             "<= anArray["<<iElem<<"]"<<
2448                             "["<<iNode<<"]"<<
2449                             "("<<anArray[iNode]<<") < 0");
2450             }
2451           }
2452         }
2453       }
2454
2455       theMeshOnEntity->myIsDone = true;
2456       
2457       return 1;
2458       
2459     }
2460     
2461     MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
2462     TInt aNbPoints = aNodeInfo->GetNbElem();
2463
2464     std::map<TInt,TInt> aNodeIdMap;
2465 #ifdef _EDF_NODE_IDS_
2466     EBooleen anIsNodeNum = MED::eFAUX;
2467 #else
2468     EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
2469     if(anIsNodeNum){
2470       for(TInt i = 0; i < aNbPoints; i++){
2471         aNodeIdMap[aNodeInfo->GetElemNum(i)-1] = i;
2472       }
2473     }
2474 #endif
2475
2476     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity->myGeom2Size;
2477     MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
2478     VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
2479
2480     for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
2481       const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
2482       VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
2483       INITMSG(MYDEBUG,"aMGeom = "<<aMGeom<<"; aEGeom = "<<aEGeom<<"\n");
2484       switch(aMGeom){
2485       case MED::ePOLYGONE: {
2486         MED::PPolygoneInfo aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom);
2487         TInt aNbElem = aPolygoneInfo->GetNbElem();
2488         if(aNbElem > 0){
2489           VISU::PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TMEDSubMesh());
2490           
2491           aSubMesh->Init(MED::PElemInfo(aPolygoneInfo),theMed->GetVersion()); 
2492           aSubMesh->myNbCells = aNbElem;      
2493
2494           VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
2495           aCell2Connect.resize(aNbElem);
2496           
2497           for(TInt iElem = 0; iElem < aNbElem; iElem++) {
2498             MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
2499             TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
2500             aSubMesh->myCellsSize += aNbConn;
2501             VISU::TConnect& anArray = aCell2Connect[iElem];
2502             anArray.resize(aNbConn);
2503             for(TInt iConn = 0; iConn < aNbConn; iConn++)
2504               anArray[iConn] = aConnSlice[iConn] - 1;
2505           }
2506         }
2507         break;
2508       }
2509       case MED::ePOLYEDRE: {
2510         MED::PPolyedreInfo aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom);
2511         TInt aNbElem = aPolyedreInfo->GetNbElem();
2512         
2513         if(aNbElem > 0){
2514           VISU::PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TMEDSubMesh());
2515           
2516           aSubMesh->Init(MED::PElemInfo(aPolyedreInfo),theMed->GetVersion()); 
2517           aSubMesh->myNbCells = aNbElem;      
2518
2519           VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
2520           aCell2Connect.resize(aNbElem);
2521           
2522           for(TInt iElem = 0; iElem < aNbElem; iElem++){
2523             MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
2524             VISU::TConnect& anArray = aCell2Connect[iElem];
2525             typedef std::set<TInt> TConnectSet;
2526             TConnectSet aConnectSet;
2527             TInt aNbFaces = aConnSliceArr.size();
2528             for(TInt iFace = 0; iFace < aNbFaces; iFace++){
2529               MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
2530               TInt aNbConn = aConnSlice.size();
2531               aSubMesh->myCellsSize += aNbConn;
2532               for(TInt iConn = 0; iConn < aNbConn; iConn++){
2533                 aConnectSet.insert(aConnSlice[iConn]);
2534               }
2535             }
2536           
2537             int aNbConn = aConnectSet.size();
2538             anArray.resize(aNbConn);
2539             TConnectSet::iterator anIter = aConnectSet.begin();
2540             for(int i = 0; anIter != aConnectSet.end(); anIter++, i++){
2541               TInt anId = *anIter;
2542               anArray[i] = anId - 1;
2543             }
2544           }
2545         }
2546
2547         break;
2548       }
2549       default: {
2550         vtkIdType aVNbNodes = VISUGeom2NbNodes(aEGeom);
2551         INITMSG(MYDEBUG,"aVNbNodes = "<<aVNbNodes<<"\n");
2552         
2553         MED::PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aMGeom);
2554         TInt aNbElem = aCellInfo->GetNbElem();
2555         
2556         if(aNbElem > 0){
2557           VISU::PMEDSubMesh aSubMesh = aGeom2SubMesh[aEGeom](new VISU::TMEDSubMesh());
2558           
2559           aSubMesh->Init(MED::PElemInfo(aCellInfo), theMed->GetVersion()); 
2560           aSubMesh->myNbCells = aNbElem;      
2561           aSubMesh->myCellsSize = aNbElem*(aVNbNodes+1);
2562
2563           VISU::TCell2Connect& aCell2Connect = aSubMesh->myCell2Connect;
2564           aCell2Connect.resize(aNbElem);
2565         
2566           TInt aMNbNodes = MEDGeom2NbNodes(aMGeom);
2567           VISU::TVector<TInt> aConnect(aMNbNodes);
2568         
2569           for(TInt iElem = 0; iElem < aNbElem; iElem++) {
2570             MED::TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
2571             VISU::TConnect& anArray = aCell2Connect[iElem];
2572             anArray.resize(aVNbNodes);
2573             
2574             if(anIsNodeNum){
2575               for(TInt iConn = 0; iConn < aMNbNodes; iConn++){
2576                 aConnect[iConn] = aNodeIdMap[aConnSlice[iConn] - 1];
2577               }
2578             }else{
2579               for(int iConn = 0; iConn < aMNbNodes; iConn++){
2580                 aConnect[iConn] = aConnSlice[iConn] - 1;
2581               }
2582             }
2583             
2584             switch(aMGeom){
2585 #if !(defined(VTK_QUADRATIC_EDGE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2586             case MED::eSEG3:
2587               anArray[0] = aConnect[0];
2588               anArray[2] = aConnect[1];  
2589
2590               anArray[1] = aConnect[2];
2591               break;
2592 #endif
2593 #if !(defined(VTK_QUADRATIC_TRIANGLE) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2594             case MED::eTRIA6:
2595               anArray[0] = aConnect[0];
2596               anArray[2] = aConnect[1];  
2597               anArray[4] = aConnect[2];  
2598
2599               anArray[1] = aConnect[3];
2600               anArray[3] = aConnect[4];  
2601               anArray[5] = aConnect[5];  
2602               break;
2603 #endif
2604 #if !(defined(VTK_QUADRATIC_QUAD) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2605             case MED::eQUAD8:
2606               anArray[0] = aConnect[0];
2607               anArray[2] = aConnect[1];  
2608               anArray[4] = aConnect[2];  
2609               anArray[6] = aConnect[3];  
2610
2611               anArray[1] = aConnect[4];
2612               anArray[3] = aConnect[5];  
2613               anArray[5] = aConnect[6];  
2614               anArray[7] = aConnect[7];  
2615               break;
2616 #endif
2617 #if (defined(VTK_QUADRATIC_TETRA) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2618             case MED::eTETRA10:
2619               anArray[0] = aConnect[0];
2620               anArray[1] = aConnect[2];
2621               anArray[2] = aConnect[1];  
2622               anArray[3] = aConnect[3];  
2623
2624               anArray[4] = aConnect[6];
2625               anArray[5] = aConnect[5];
2626               anArray[6] = aConnect[4];  
2627
2628               anArray[7] = aConnect[7];  
2629               anArray[8] = aConnect[9];  
2630               anArray[9] = aConnect[8];  
2631               break;
2632 #endif
2633             case MED::eTETRA4:
2634               anArray[0] = aConnect[0];
2635               anArray[1] = aConnect[2];
2636               anArray[2] = aConnect[1];  
2637               anArray[3] = aConnect[3];  
2638               break;
2639 #if (defined(VTK_QUADRATIC_PYRAMID) && defined(VISU_USE_VTK_QUADRATIC)) && defined(VISU_ENABLE_QUADRATIC)
2640             case MED::ePYRA13:
2641               anArray[0] = aConnect[0];
2642               anArray[1] = aConnect[3];
2643               anArray[2] = aConnect[2];  
2644               anArray[3] = aConnect[1];  
2645               anArray[4] = aConnect[4];
2646
2647               anArray[5] = aConnect[8];
2648               anArray[6] = aConnect[7];  
2649               anArray[7] = aConnect[6];  
2650               anArray[8] = aConnect[5];  
2651
2652               anArray[9] = aConnect[9];  
2653               anArray[10] = aConnect[12];  
2654               anArray[11] = aConnect[11];  
2655               anArray[12] = aConnect[10];  
2656               break;
2657 #endif
2658             case MED::ePYRA5:
2659               anArray[0] = aConnect[0];
2660               anArray[1] = aConnect[3];  
2661               anArray[2] = aConnect[2];
2662               anArray[3] = aConnect[1];  
2663               anArray[4] = aConnect[4];
2664               break;
2665             default:
2666               for(int iNode = 0; iNode < aVNbNodes; iNode++) 
2667                 anArray[iNode] = aConnect[iNode];
2668             }
2669             for(int iNode = 0; iNode < aVNbNodes; iNode++) 
2670               if(anArray[iNode] < 0 || aNbPoints <= anArray[iNode])
2671                 EXCEPTION(std::runtime_error,"LoadCellsOnEntity - "<<
2672                           " aNbPoints("<<aNbPoints<<") "<<
2673                           "<= anArray["<<iElem<<"]"<<
2674                           "["<<iNode<<"]"<<
2675                           "("<<anArray[iNode]<<") < 0");
2676           }
2677         }
2678       }}
2679     }
2680
2681     // END NON_STRUCTURED
2682
2683     theMeshOnEntity->myIsDone = true;
2684
2685     return 1;
2686
2687 #ifndef _DEXCEPT_
2688   }catch(std::exception& exc){
2689     throw;
2690   }catch(...){
2691     EXCEPTION(std::runtime_error,"Unknown exception !!!");
2692   }
2693 #endif
2694
2695   return 0;
2696 }
2697
2698
2699 //---------------------------------------------------------------
2700 int 
2701 VISU_MedConvertor
2702 ::LoadCellsOnFamily(const MED::PWrapper& theMed,
2703                     const VISU::PMEDMesh theMesh,
2704                     const VISU::PMEDMeshOnEntity theMeshOnEntity,
2705                     const VISU::PMEDFamily theFamily)
2706 {
2707   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadCellsOnFamily");
2708 #ifndef _DEXCEPT_
2709   try{
2710 #endif
2711     const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
2712     const MED::EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity);
2713
2714     INITMSG(MYDEBUG,"LoadCellsOnFamily - aVEntity = "<<aVEntity<<"\n");
2715
2716     if(theFamily->myIsDone)
2717       return 0;
2718
2719     TInt anId = theFamily->myId;
2720
2721     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2722     VISU::TGeom2SubMeshID& aGeom2SubMeshID = theFamily->myGeom2SubMeshID;
2723     MED::EMaillage aType = aMeshInfo->GetType();
2724
2725     const MED::TGeom2Size& aGeom2Size = theMeshOnEntity->myGeom2Size;
2726     MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
2727     for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
2728       const MED::EGeometrieElement& aMGeom = aGeom2SizeIter->first;
2729       if(aType == MED::eNON_STRUCTURE){
2730         MED::PElemInfo anElemInfo;
2731         switch(aMGeom){
2732         case MED::ePOLYGONE: {
2733           anElemInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aMGeom);
2734           break;
2735         }
2736         case MED::ePOLYEDRE: {
2737           anElemInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aMGeom);
2738           break;
2739         }
2740         default: {
2741           anElemInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aMGeom);
2742           break;
2743         }}
2744         if(anElemInfo){
2745           if(TInt aNbElem = anElemInfo->GetNbElem()){
2746             VISU::TSubMeshID aSubMeshID;
2747             for(TInt iElem = 0; iElem < aNbElem; iElem++) 
2748               if(anElemInfo->GetFamNum(iElem) == anId)
2749                 aSubMeshID.push_back(iElem);
2750             if(!aSubMeshID.empty()){
2751               VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
2752               INITMSG(MYDEBUG,"aMGeom = "<<aMGeom<<"\n");
2753               aGeom2SubMeshID.insert(VISU::TGeom2SubMeshID::value_type(aEGeom,aSubMeshID));
2754             }
2755           }
2756         }
2757       } else {
2758         MED::PGrilleInfo anElemInfo = theMed->GetPGrilleInfo(aMeshInfo);
2759         if(anElemInfo){
2760           TInt aNbElem = anElemInfo->GetNbCells();
2761           if(aNbElem>0 && (aMGeom == anElemInfo->GetGeom()) ){
2762             VISU::TSubMeshID aSubMeshID;
2763             for(TInt iElem = 0; iElem < aNbElem; iElem++) 
2764               if(anElemInfo->GetFamNum(iElem) == anId)
2765                 aSubMeshID.push_back(iElem);
2766             if(!aSubMeshID.empty()){
2767               VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
2768               INITMSG(MYDEBUG,"aMGeom = "<<aMGeom<<"\n");
2769               aGeom2SubMeshID.insert(VISU::TGeom2SubMeshID::value_type(aEGeom,aSubMeshID));
2770             }
2771           }
2772         }
2773       }
2774     }
2775
2776     theFamily->myIsDone = true;
2777
2778     return 1;
2779
2780 #ifndef _DEXCEPT_
2781   }catch(std::exception& exc){
2782     throw;
2783   }catch(...){
2784     EXCEPTION(std::runtime_error,"Unknown exception !!!");
2785   }
2786 #endif
2787
2788   return 0;
2789 }
2790
2791
2792 //---------------------------------------------------------------
2793 void
2794 LoadProfile(const MED::PWrapper& theMed,
2795             VISU::PMEDMesh theMesh,
2796             MED::PTimeStampValueBase theTimeStampValue,
2797             VISU::TMEDValForTime& theValForTime,
2798             VISU::TMEDMeshOnEntity& theMeshOnEntity)
2799 {
2800   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadProfile");
2801   INITMSG(MYDEBUG,"LoadProfile"<<endl);
2802
2803   VISU::PMEDProfile aProfile = theValForTime.myProfile;
2804   if(aProfile->myIsDone)
2805     return;
2806
2807   const VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
2808   const MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->GetGeom2Profile();
2809   MED::TGeom2Profile::const_iterator anIter = aGeom2Profile.begin();
2810   for(; anIter != aGeom2Profile.end(); anIter++){
2811     MED::PProfileInfo aProfileInfo = anIter->second;
2812     MED::EGeometrieElement aMGeom = anIter->first;
2813     VISU::EGeometry aEGeom = MEDGeom2VISU(aMGeom);
2814
2815     VISU::TGeom2SubProfile::const_iterator anIter2 = aGeom2SubProfile.find(aEGeom);
2816     if(anIter2 != aGeom2SubProfile.end()){
2817       VISU::PMEDSubProfile aSubProfile = anIter2->second;
2818
2819       MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
2820       if(!anElemNum.empty()){
2821         VISU::TSubMeshID& aSubMeshID = aSubProfile->mySubMeshID;
2822         TInt aSize = anElemNum.size();
2823         aSubMeshID.resize(aSize);
2824         for(TInt anId = 0; anId < aSize; anId++)
2825           aSubMeshID[anId] = anElemNum[anId] - 1;
2826       }
2827
2828       INITMSG(MYDEBUG,
2829               "- aEGeom = "<<aEGeom<<
2830               "; aNbCells = "<<aSubProfile->mySubMeshID.size()<<
2831               endl);
2832     }
2833   }
2834   {
2835     const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2836     
2837     VISU::TEntity aVEntity = theMeshOnEntity.myEntity;
2838     MED::EEntiteMaillage aMEntity = VTKEntityToMED(aVEntity);
2839     
2840     const VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
2841     VISU::TGeom2SubProfile::const_iterator anIter = aGeom2SubProfile.begin();
2842     for(; anIter != aGeom2SubProfile.end(); anIter++){
2843       const VISU::PMEDSubProfile& aSubProfile = anIter->second;
2844       MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
2845       MED::PElemInfo anElemInfo;
2846       anElemInfo = theMed->GetPElemInfo(aMeshInfo,aMEntity,aMGeom);
2847       aSubProfile->myIsElemNum = anElemInfo->IsElemNum();
2848       aSubProfile->myElemNum = anElemInfo->myElemNum;
2849     }
2850   }
2851
2852   aProfile->myIsDone = true;
2853 }
2854
2855
2856 //---------------------------------------------------------------
2857 void
2858 LoadGaussMesh(const MED::PWrapper& theMed,
2859               VISU::PMEDMesh theMesh,
2860               MED::PTimeStampValueBase theTimeStampValue,
2861               VISU::TMEDValForTime& theValForTime,
2862               VISU::TMEDMeshOnEntity& theMeshOnEntity)
2863 {
2864   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadGaussMesh");
2865   INITMSG(MYDEBUG,"LoadGaussMesh"<<endl);
2866
2867   // this part of code must be reimplemented in connection with GRILLE structures
2868   if(theMesh->myMeshInfo->GetType() == MED::eSTRUCTURE)
2869     EXCEPTION(std::runtime_error,"LoadGaussMesh - Gauss Points localization error!!!");
2870   
2871   VISU::PMEDGaussMesh aGaussMesh = theValForTime.myGaussMesh;
2872   if(!aGaussMesh || aGaussMesh->myIsDone)
2873     return;
2874
2875   const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
2876   MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
2877
2878   VISU::TEntity aVEntity = theMeshOnEntity.myEntity;
2879   MED::EEntiteMaillage aMEntity = VTKEntityToMED(aVEntity);
2880
2881   const VISU::TGeom2GaussSubMesh& aGeom2GaussSubMesh = aGaussMesh->myGeom2GaussSubMesh;
2882   const MED::TTimeStampInfo& aTimeStampInfo = theTimeStampValue->GetTimeStampInfo();
2883   const MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo.GetGeom2Gauss();
2884
2885   VISU::TGeom2GaussSubMesh::const_iterator aSubMeshIter = aGeom2GaussSubMesh.begin();
2886   for(; aSubMeshIter != aGeom2GaussSubMesh.end(); aSubMeshIter++){
2887     VISU::PMEDGaussSubMesh aGaussSubMesh = aSubMeshIter->second;
2888     VISU::EGeometry aEGeom = aSubMeshIter->first;
2889     
2890     if(aGaussSubMesh->myIsDone)
2891       continue;
2892
2893     VISU::PMEDSubProfile aSubProfile = aGaussSubMesh->mySubProfile;
2894     const VISU::TSubMeshID& aSubMeshID = aSubProfile->mySubMeshID;
2895     MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
2896
2897     MED::PPolygoneInfo aPolygoneInfo;
2898     MED::PPolyedreInfo aPolyedreInfo;
2899     MED::PCellInfo aCellInfo;
2900     MED::PElemInfo anElemInfo;
2901
2902     switch(aMGeom){
2903     case MED::ePOLYGONE: 
2904       aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,
2905                                                aMEntity,
2906                                                aMGeom);
2907       anElemInfo = aPolygoneInfo;
2908       break;
2909     case MED::ePOLYEDRE: 
2910       aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,
2911                                                aMEntity,
2912                                                aMGeom);
2913       anElemInfo = aPolyedreInfo;
2914       break;
2915     default:
2916       aCellInfo = theMed->GetPCellInfo(aMeshInfo,
2917                                        aMEntity, 
2918                                        aMGeom);
2919       anElemInfo = aCellInfo;
2920     }
2921     aGaussSubMesh->myIsElemNum = anElemInfo->IsElemNum();
2922     aGaussSubMesh->myElemNum = anElemInfo->myElemNum;
2923
2924     std::string aName;
2925     bool anIsGaussCoord3D = false;
2926     MED::PGaussCoord aGaussCoordPtr(new MED::TGaussCoord());
2927     MED::TGaussCoord& aGaussCoord = *aGaussCoordPtr;
2928
2929     MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aMGeom);
2930     if(aGaussIter != aGeom2Gauss.end()){
2931       VISU::PMEDGauss aGauss = aGaussSubMesh->myGauss;
2932       MED::PGaussInfo aGaussInfo = aGauss->myGaussInfo;
2933       if(aGaussInfo){
2934         aName = aGaussInfo->GetName();
2935         if(!aSubMeshID.empty()){
2936           const std::string& aProfileName = aSubProfile->myName;
2937           MED::PProfileInfo aProfileInfo = MED::GetProfileInfo(theMed,
2938                                                                aProfileName);
2939           if(aProfileInfo){
2940             const MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
2941             anIsGaussCoord3D = MED::GetGaussCoord3D(aGaussInfo,
2942                                                     aCellInfo,
2943                                                     aNodeInfo,
2944                                                     aGaussCoord,
2945                                                     anElemNum);
2946           }
2947         }else
2948           anIsGaussCoord3D = MED::GetGaussCoord3D(aGaussInfo,
2949                                                   aCellInfo,
2950                                                   aNodeInfo,
2951                                                   aGaussCoord);
2952       }
2953     }else{
2954       if(!aSubMeshID.empty()){
2955         const std::string& aProfileName = aSubProfile->myName;
2956         MED::PProfileInfo aProfileInfo = MED::GetProfileInfo(theMed,
2957                                                              aProfileName);
2958         if(aProfileInfo){
2959           const MED::TElemNum& anElemNum = aProfileInfo->myElemNum;
2960           switch(aMGeom){
2961           case MED::ePOLYGONE: 
2962             anIsGaussCoord3D = MED::GetBaryCenter(aPolygoneInfo,
2963                                                   aNodeInfo,
2964                                                   aGaussCoord,
2965                                                   anElemNum);
2966             break;
2967           case MED::ePOLYEDRE: 
2968             anIsGaussCoord3D = MED::GetBaryCenter(aPolyedreInfo,
2969                                                   aNodeInfo,
2970                                                   aGaussCoord,
2971                                                   anElemNum);
2972             break;
2973           default:
2974             anIsGaussCoord3D = MED::GetBaryCenter(aCellInfo,
2975                                                   aNodeInfo,
2976                                                   aGaussCoord,
2977                                                   anElemNum);
2978           }
2979         }
2980       }else
2981         switch(aMGeom){
2982         case MED::ePOLYGONE: 
2983           anIsGaussCoord3D = MED::GetBaryCenter(aPolygoneInfo,
2984                                                 aNodeInfo,
2985                                                 aGaussCoord);
2986           break;
2987         case MED::ePOLYEDRE: 
2988           anIsGaussCoord3D = MED::GetBaryCenter(aPolyedreInfo,
2989                                                 aNodeInfo,
2990                                                 aGaussCoord);
2991           break;
2992         default:
2993           anIsGaussCoord3D = MED::GetBaryCenter(aCellInfo,
2994                                                 aNodeInfo,
2995                                                 aGaussCoord);
2996         }
2997     }
2998     
2999     if(anIsGaussCoord3D){
3000       VISU::TPointCoords& aCoords = aGaussSubMesh->myPointCoords;
3001       VISU::TMEDGaussCoordHolder* aCoordHolder = new VISU::TMEDGaussCoordHolder();
3002       aCoordHolder->Init(aGaussCoordPtr);
3003       aCoords.Init(VISU::PCoordHolder(aCoordHolder));
3004       
3005       aGaussSubMesh->myIsDone = true;
3006       
3007       TInt aNbGauss = aGaussCoord.GetNbGauss();
3008       TInt aNbElem = aGaussCoord.GetNbElem();
3009       TInt aNbCells = aNbElem*aNbGauss;
3010
3011       INITMSG(MYDEBUG,
3012               "- aEGeom = "<<aEGeom<<
3013               "; aName = '"<<aName<<"'"<<
3014               "; aStatus = "<<aGaussSubMesh->myStatus<<
3015               "; aNbElem = "<<aNbElem<<
3016               "; aNbGauss = "<<aNbGauss<<
3017               "; aNbCells = "<<aNbCells<<
3018               endl);
3019     }else
3020       EXCEPTION(std::runtime_error,"LoadGaussMesh - Gauss Points localization error!!!");
3021   }
3022   
3023   aGaussMesh->myIsDone = true;
3024 }
3025
3026
3027 //---------------------------------------------------------------
3028 template<class TimeStampValueType>
3029 void
3030 FillValForTime(MED::SharedPtr<TimeStampValueType> theTimeStampValue,
3031                const VISU::TGeom2SubProfile& theGeom2SubProfile,
3032                VISU::PMEDValForTime theValForTime,
3033                VISU::PMEDField theField)
3034 {
3035   theField->myDataSize = 0;
3036   TInt aNbComp = theField->myNbComp;
3037
3038   VISU::TGeom2SubProfile::const_iterator anIter = theGeom2SubProfile.begin();
3039   for(; anIter != theGeom2SubProfile.end(); anIter++){
3040     VISU::EGeometry aEGeom = anIter->first;
3041     VISU::PMEDSubProfile aSubProfile(anIter->second);
3042
3043     TInt aNbElem = aSubProfile->myNbCells;
3044     theField->myDataSize += aNbElem * aNbComp;
3045
3046     if(aSubProfile->myStatus != VISU::eRemoveAll){
3047       TInt aNbGauss = theValForTime->GetNbGauss(aEGeom);
3048
3049       INITMSG(MYDEBUG,
3050               "- aEGeom = "<<aEGeom<<
3051               "; aNbElem = "<<aNbElem<<
3052               "; aNbGauss = "<<aNbGauss<<
3053               endl);
3054       
3055       VISU::PMeshValue& aVMeshValue = theValForTime->GetMeshValue(aEGeom);
3056       typedef typename TimeStampValueType::TElement TElement;
3057       typedef VISU::TTMEDMeshValue<TElement> TVMeshValue;
3058       TVMeshValue* aMeshValue = new TVMeshValue();
3059
3060       MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
3061       typedef typename TimeStampValueType::PTMeshValue PTMeshValue;
3062       PTMeshValue aMeshValuePtr = theTimeStampValue->GetMeshValuePtr(aMGeom);
3063       aMeshValue->Init(aNbElem, aNbGauss, aNbComp, aMeshValuePtr);
3064       aVMeshValue.reset(aMeshValue);
3065     }
3066   }
3067 }
3068
3069 //---------------------------------------------------------------
3070 int 
3071 LoadValForTime(const MED::PWrapper& theMed,
3072                VISU::PMEDMesh theMesh,
3073                VISU::PMEDMeshOnEntity theMeshOnEntity,
3074                VISU::PMEDField theField, 
3075                VISU::PMEDValForTime theValForTime,
3076                bool theIsGauss,
3077                bool& theIsDone)
3078 {
3079   VISU::TTimerLog aTimerLog(MYDEBUG,"LoadValForTime");
3080   INITMSG(MYDEBUG,"LoadValForTime - theIsGauss = "<<theIsGauss<<endl);
3081
3082   //Check on loading already done
3083   if(theIsDone) 
3084     return 0;
3085
3086   //Main part of code
3087   const std::string& aMeshName = theMeshOnEntity->myMeshName;
3088   const MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
3089   MED::PFieldInfo aFieldInfo = theMed->GetPFieldInfo(aMeshInfo,
3090                                                      theField->myId);
3091
3092   MED::TGeom2Size aGeom2Size;
3093   MED::EEntiteMaillage aMEntity;
3094   theMed->GetNbTimeStamps(aFieldInfo,
3095                           theMesh->myEntityInfo,
3096                           aMEntity,
3097                           aGeom2Size);
3098
3099   MED::PTimeStampInfo aTimeStampInfo = 
3100     theMed->GetPTimeStampInfo(aFieldInfo,
3101                               aMEntity,
3102                               aGeom2Size,
3103                               theValForTime->myId);
3104
3105   MED::TKey2Gauss aKey2Gauss = GetKey2Gauss(theMed);
3106   MED::TMKey2Profile aMKey2Profile = GetMKey2Profile(theMed);
3107
3108   MED::PTimeStampValueBase aTimeStampValue = 
3109     theMed->GetPTimeStampValue(aTimeStampInfo,
3110                                aMKey2Profile,
3111                                aKey2Gauss);
3112   
3113   InitProfile(theMed,
3114               aMeshInfo,
3115               aTimeStampValue,
3116               theMeshOnEntity,
3117               aMEntity,
3118               aGeom2Size,
3119               theValForTime);
3120
3121   LoadProfile(theMed,
3122               theMesh,
3123               aTimeStampValue,
3124               theValForTime,
3125               theMeshOnEntity);
3126   
3127   if(theIsGauss) {
3128     InitGaussMesh(aTimeStampValue,
3129                   theMeshOnEntity,
3130                   aGeom2Size,
3131                   theValForTime);
3132
3133     LoadGaussMesh(theMed,
3134                   theMesh,
3135                   aTimeStampValue,
3136                   theValForTime,
3137                   theMeshOnEntity);
3138   }
3139   
3140   VISU::PMEDProfile aProfile = theValForTime->myProfile;
3141   VISU::TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
3142
3143   INITMSGA(MYDEBUG,0,
3144            "- aMeshName = '"<<aMeshName<<"'"<<
3145            "; aFieldName = '"<<aFieldInfo->GetName()<<"'"<<
3146            "; aMEntity = "<<aMEntity<<
3147            "; aNbComp = "<<theField->myNbComp<<
3148            endl);
3149
3150   if(aFieldInfo->GetType() == MED::eFLOAT64)
3151     FillValForTime<MED::TFloatTimeStampValue>(CastToFloatTimeStampValue(aTimeStampValue),
3152                                               aGeom2SubProfile,
3153                                               theValForTime,
3154                                               theField);
3155   else
3156     FillValForTime<MED::TIntTimeStampValue>(CastToIntTimeStampValue(aTimeStampValue),
3157                                             aGeom2SubProfile,
3158                                             theValForTime,
3159                                             theField);
3160   theIsDone = true;
3161
3162   return 1; 
3163 }
3164
3165
3166 //---------------------------------------------------------------
3167 int 
3168 VISU_MedConvertor
3169 ::LoadValForTimeOnMesh(const MED::PWrapper& theMed,
3170                        VISU::PMEDMesh theMesh,
3171                        VISU::PMEDMeshOnEntity theMeshOnEntity,
3172                        VISU::PMEDField theField, 
3173                        VISU::PMEDValForTime theValForTime)
3174 {
3175   VISU::PUnstructuredGridIDMapperImpl anUnstructuredGridIDMapper = theValForTime->myUnstructuredGridIDMapper;
3176   return LoadValForTime(theMed,
3177                         theMesh,
3178                         theMeshOnEntity,
3179                         theField,
3180                         theValForTime,
3181                         false,
3182                         anUnstructuredGridIDMapper->myIsVTKDone);
3183 }
3184
3185
3186 //---------------------------------------------------------------
3187 int 
3188 VISU_MedConvertor
3189 ::LoadValForTimeOnGaussPts(const MED::PWrapper& theMed,
3190                            VISU::PMEDMesh theMesh,
3191                            VISU::PMEDMeshOnEntity theMeshOnEntity,
3192                            VISU::PMEDField theField, 
3193                            VISU::PMEDValForTime theValForTime)
3194 {
3195   VISU::PGaussPtsIDFilter aGaussPtsIDFilter = theValForTime->myGaussPtsIDFilter;
3196   return LoadValForTime(theMed,
3197                         theMesh,
3198                         theMeshOnEntity,
3199                         theField,
3200                         theValForTime,
3201                         true,
3202                         aGaussPtsIDFilter->myIsVTKDone);
3203 }