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