1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_MedConvertor.cxx
24 // Author : Alexey PETROV
28 #include "VISU_MedConvertor.hxx"
29 #include "VISU_Convertor.hxx"
30 #include "VISU_ConvertorUtils.hxx"
32 #include "MED_Factory.hxx"
33 #include "MED_Algorithm.hxx"
34 #include "MED_Utilities.hxx"
36 #include <vtkCellType.h>
38 #define _EDF_NODE_IDS_
45 static int MYDEBUG = 0;
47 static int MYDEBUG = 0;
56 int MEDGeom2NbNodes(MED::EGeometrieElement theMEDGeomType)
58 return theMEDGeomType % 100;
61 int MEDGeomToVTK(MED::EGeometrieElement theMEDGeomType)
63 switch(theMEDGeomType){
64 case ePOINT1: return VTK_VERTEX;
65 case eSEG2: return VTK_LINE;
66 case eSEG3: return VTK_LINE;
67 case eTRIA3: return VTK_TRIANGLE;
68 case eTRIA6: return VTK_TRIANGLE;
69 case eQUAD4: return VTK_QUAD;
70 case eQUAD8: return VTK_QUAD;
71 case eTETRA4: return VTK_TETRA;
72 case eTETRA10: return VTK_TETRA;
73 case eHEXA8: return VTK_HEXAHEDRON;
74 case eHEXA20: return VTK_HEXAHEDRON;
75 case ePENTA6: return VTK_WEDGE;
76 case ePENTA15: return VTK_WEDGE;
77 case ePYRA5: return VTK_PYRAMID;
78 case ePYRA13: return VTK_PYRAMID;
79 case ePOLYGONE: return VTK_POLYGON;
80 // case ePOLYEDRE: return VTK_POLYEDRE;
85 int VTKGeom2NbNodes(int theVTKGeomType)
87 switch(theVTKGeomType){
88 case VTK_VERTEX: return 1;
89 case VTK_LINE: return 2;
90 case VTK_TRIANGLE: return 3;
91 case VTK_QUAD: return 4;
92 case VTK_TETRA: return 4;
93 case VTK_HEXAHEDRON: return 8;
94 case VTK_WEDGE: return 6;
95 case VTK_PYRAMID: return 5;
100 MED::EGeometrieElement VTKGeomToMED(int theVTKGeomType)
102 switch(theVTKGeomType){
103 case VTK_VERTEX: return ePOINT1;
104 case VTK_LINE: return eSEG2;
105 case VTK_TRIANGLE: return eTRIA3;
106 case VTK_QUAD: return eQUAD4;
107 case VTK_TETRA: return eTETRA4;
108 case VTK_HEXAHEDRON: return eHEXA8;
109 case VTK_WEDGE: return ePENTA6;
110 case VTK_PYRAMID: return ePYRA5;
111 case VTK_POLYGON: return ePOLYGONE;
113 return EGeometrieElement(-1);
116 TEntity MEDEntityToVTK(MED::EEntiteMaillage theMEDEntity)
118 switch(theMEDEntity){
119 case eNOEUD: return NODE_ENTITY;
120 case eARETE: return EDGE_ENTITY;
121 case eFACE: return FACE_ENTITY;
122 case eMAILLE: return CELL_ENTITY;
127 MED::EEntiteMaillage VTKEntityToMED(TEntity theVTKEntity)
129 switch(theVTKEntity){
130 case NODE_ENTITY: return eNOEUD;
131 case EDGE_ENTITY: return eARETE;
132 case FACE_ENTITY: return eFACE;
133 case CELL_ENTITY: return eMAILLE;
135 return MED::EEntiteMaillage(-1);
141 VISU_Convertor* CreateConvertor(const string& theFileName)
143 return new VISU_MedConvertor(theFileName);
146 VISU_MedConvertor::VISU_MedConvertor(const string& theFileName) {
147 myFileInfo.setFile(QString(theFileName.c_str()));
148 myName = myFileInfo.baseName().latin1();
151 VISU_Convertor* VISU_MedConvertor::Build() {
152 MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
153 MED::TInt aNbMeshes = aMed->GetNbMeshes();
155 MSG(MYDEBUG,"VISU_MedConvertor::Build()");
156 INITMSG(MYDEBUG,"GetNbMeshes() = "<<aNbMeshes<<"\n");
158 for(MED::TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
160 MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
162 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
164 MED::TElemGroup anElemGroup = GetElemsByEntity(aMed,aMeshInfo,aEntityInfo);
167 MED::TElemGroup::const_iterator anElemGroupIter = anElemGroup.find(MED::eNOEUD);
168 if(anElemGroupIter == anElemGroup.end())
171 const MED::TElemMap& anElemMap = anElemGroupIter->second;
172 MED::TElemMap::const_iterator anElemMapIter = anElemMap.find(MED::ePOINT1);
173 if(anElemMapIter == anElemMap.end())
176 MED::PNodeInfo aNodeInfo(anElemMapIter->second);
178 // creating TMesh structure and TMeshOnEntityMap
179 typedef std::map<TInt,TInt> TFamilyCounterMap;
180 TFamilyCounterMap aFamilyNbCellsCounterMap, aFamilyCellsSizeCounterMap;
181 TFamilyCounterMap aFamilyNbPolygonesCounterMap, aFamilyPolygonesSizeCounterMap;
183 MED::TInt aDim = aMeshInfo->GetDim();
184 std::string aMeshName = aMeshInfo->GetName();
186 VISU::PMEDMesh aMesh = myMeshMap[aMeshName](new VISU::TMEDMesh());
188 aMesh->myName = aMeshName;
189 aMesh->myNbPoints = aNodeInfo->GetNbElem();
190 aMesh->myMeshInfo = aMeshInfo;
191 aMesh->myEntityInfo = aEntityInfo;
193 INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<
194 "'; myNbPoints = "<<aMesh->myNbPoints<<
195 "; aDim = "<<aDim<<"\n");
197 BEGMSG(MYDEBUG,"aEntityInfo.size() = "<<aEntityInfo.size()<<"\n");
199 VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
200 anElemGroupIter = anElemGroup.begin();
201 for(; anElemGroupIter != anElemGroup.end(); anElemGroupIter++){
202 const MED::EEntiteMaillage& aMEntity = anElemGroupIter->first;
203 const MED::TElemMap& anElemMap = anElemGroupIter->second;
205 VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
206 VISU::PMEDMeshOnEntity aMeshOnEntity =
207 aMeshOnEntityMap[aVEntity](new VISU::TMEDMeshOnEntity());
208 aMeshOnEntity->myEntity = aVEntity;
209 aMeshOnEntity->myMeshName = aMeshName;
210 aMeshOnEntity->myGeom = aEntityInfo[aMEntity];
212 INITMSG(MYDEBUG,"aMEntity = "<<aMEntity<<"; aVEntity = "<<aVEntity<<"\n");
214 if(aMEntity == MED::eNOEUD){
215 aMeshOnEntity->myNbCells = aMesh->myNbPoints;
216 aMeshOnEntity->myCellsSize = 2*aMesh->myNbPoints;
218 for(MED::TInt iElem = 0; iElem < aMesh->myNbPoints; iElem++){
219 MED::TInt aFamId = aNodeInfo->GetFamNum(iElem);
221 aFamilyNbCellsCounterMap[aFamId] += 1;
222 aFamilyCellsSizeCounterMap[aFamId] += 2;
226 INITMSG(MYDEBUG,"myNbCells = "<<aMeshOnEntity->myNbCells<<
227 "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<"\n");;
230 aMeshOnEntity->myNbCells = 0;
231 aMeshOnEntity->myCellsSize = 0;
232 anElemMapIter = anElemMap.begin();
233 for(; anElemMapIter != anElemMap.end(); anElemMapIter++){
234 const MED::EGeometrieElement& aGeom = anElemMapIter->first;
235 MED::PElemInfo anElemInfo = anElemMapIter->second;
238 case MED::ePOLYGONE: {
239 MED::PPolygoneInfo aPolygoneInfo(anElemInfo);
240 MED::TInt aNbElem = aPolygoneInfo->GetNbElem();
241 MED::TElemNum aConn = aPolygoneInfo->GetConnectivite();
242 MED::TElemNum aIndex = aPolygoneInfo->GetIndex();
243 MED::TInt aNbConn = aConn.size();
245 aMeshOnEntity->myNbCells += aNbElem;
247 for (int ii = 0; ii<aNbElem ; ii++){
248 int aNbConnii = aPolygoneInfo->GetNbConn(ii);
249 aMeshOnEntity->myCellsSize += aNbConnii;
252 INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<
253 "; myNbPolygones = "<<aNbElem<<
254 "; nbConn= "<<aNbConn<<"\n");
256 for(MED::TInt iElem = 0; iElem < aNbElem; iElem++){
257 MED::TInt aFamId = aPolygoneInfo->GetFamNum(iElem);
259 aFamilyNbCellsCounterMap[aFamId] += 1;
260 aFamilyCellsSizeCounterMap[aFamId] += aPolygoneInfo->GetNbConn(iElem) + 1;
266 int aVNbNodes = VTKGeom2NbNodes(MEDGeomToVTK(aGeom));
267 MED::PCellInfo aCellInfo(anElemInfo);
268 MED::TInt aNbElem = aCellInfo->GetNbElem();
269 aMeshOnEntity->myNbCells += aNbElem;
270 aMeshOnEntity->myCellsSize += aNbElem*(aVNbNodes+1);
271 INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<
272 "; myNbCells = "<<aMeshOnEntity->myNbCells<<
273 "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<"\n");
275 for(MED::TInt iElem = 0; iElem < aNbElem; iElem++){
276 MED::TInt aFamId = aCellInfo->GetFamNum(iElem);
278 aFamilyNbCellsCounterMap[aFamId] += 1;
279 aFamilyCellsSizeCounterMap[aFamId] += aVNbNodes + 1;
287 BEGMSG(MYDEBUG,"TFamilyByEntity:\n");
289 MED::TFamilyGroup aFamilyGroup = GetFamilies(aMed,aMeshInfo);
291 MED::TGroupInfo aGroupInfo = GetFamiliesByGroup(aFamilyGroup);
293 MED::TFamilyByEntity aFamilyByEntity = GetFamiliesByEntity(aMed,anElemGroup,aFamilyGroup);
295 MED::TFamilyByEntity::const_iterator aFamilyByEntityIter = aFamilyByEntity.begin();
296 for(; aFamilyByEntityIter != aFamilyByEntity.end(); aFamilyByEntityIter++){
297 const MED::EEntiteMaillage& aMEntity = aFamilyByEntityIter->first;
298 const MED::TFamilyGroup& aFamilyGroup = aFamilyByEntityIter->second;
300 VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
301 VISU::PMEDMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
302 VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
304 if(aFamilyGroup.empty())
307 INITMSG(MYDEBUG,"aMEntity = "<<aMEntity<<"; aVEntity = "<<aVEntity<<"\n");
308 MED::TFamilyGroup::const_iterator aFamilyGroupIter = aFamilyGroup.begin();
309 for(; aFamilyGroupIter != aFamilyGroup.end(); aFamilyGroupIter++){
310 MED::PFamilyInfo aFamilyInfo = *aFamilyGroupIter;
311 if(aFamilyInfo->GetId() == 0)
314 std::string aFamilyName = aFamilyInfo->GetName();
315 VISU::PMEDFamily aFamily = aFamilyMap[aFamilyName](new TMEDFamily());
317 aFamily->myId = aFamilyInfo->GetId();
318 aFamily->myName = aFamilyInfo->GetName();
319 aFamily->myEntity = aVEntity;
320 aFamily->myNbCells = aFamilyNbCellsCounterMap[aFamily->myId];
321 aFamily->myCellsSize = aFamilyCellsSizeCounterMap[aFamily->myId];
323 INITMSG(MYDEBUG,"aFamilyName = '"<<aFamily->myName<<
324 "'; myId = "<<aFamily->myId<<"; "<<
325 "; aNbGroup = "<<aFamilyInfo->GetNbGroup()<<
326 "; myEntity = "<<aFamily->myEntity<<
327 "; myNbCells = "<<aFamily->myNbCells<<
328 "; myCellsSize = "<<aFamily->myCellsSize<<"\n");
330 VISU::TBindGroups& aBindGroups = aFamily->myGroups;
331 MED::TInt aNbGroup = aFamilyInfo->GetNbGroup();
332 for(MED::TInt i = 0; i < aNbGroup; i++){
333 std::string aGroupName = aFamilyInfo->GetGroupName(i);
334 aBindGroups.insert(aGroupName);
335 INITMSG(MYDEBUG,"aGroupName = '"<<aGroupName<<"'\n");
340 BEGMSG(MYDEBUG,"VISU::TGroup:\n");
342 VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
343 MED::TGroupInfo::const_iterator aGroupInfoIter = aGroupInfo.begin();
344 for(; aGroupInfoIter != aGroupInfo.end(); aGroupInfoIter++){
345 const std::string& aGroupName = aGroupInfoIter->first;
346 const MED::TFamilyGroup& aFamilyGroup = aGroupInfoIter->second;
347 VISU::PMEDGroup aGroup(new TMEDGroup());
348 aGroup->myName = aGroupName;
349 aGroup->myMeshName = aMesh->myName;
351 INITMSG(MYDEBUG,"aGroup->myName = '"<<aGroup->myName<<"'\n");
353 MED::TFamilyGroup::const_iterator aFamilyIter = aFamilyGroup.begin();
354 for(; aFamilyIter != aFamilyGroup.end(); aFamilyIter++){
355 MED::PFamilyInfo aFamilyInfo = *aFamilyIter;
356 std::string aFamilyName = aFamilyInfo->GetName();
358 VISU::TEntity aVEntity = TEntity(-1);
359 VISU::PFamily aFamily;
362 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
363 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityIter = aMeshOnEntityMap.begin();
364 for(; aMeshOnEntityIter != aMeshOnEntityMap.end(); aMeshOnEntityIter++){
365 const VISU::PMeshOnEntity& aMeshOnEntity = aMeshOnEntityIter->second;
366 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
367 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
368 for (; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
369 const std::string& aName = aFamilyMapIter->first;
370 aFamily = aFamilyMapIter->second;
371 if(aName == aFamilyName){
372 aVEntity = aFamily->myEntity;
378 if(aFamily && aVEntity >= 0){
379 aGroup->myFamilyAndEntitySet.insert(TFamilyAndEntity(aFamilyName,aVEntity));
380 INITMSG(MYDEBUG,"aFamilyName = '"<<aFamilyName<<"'; '"<<aFamily->myName<<"'; aVEntity = "<<aVEntity<<"\n");
382 aGroup->myNbCells += aFamily->myNbCells;
383 aGroup->myCellsSize += aFamily->myCellsSize;
386 if(!aGroup->myFamilyAndEntitySet.empty() && aGroup->myNbCells > 0){
387 BEGMSG(MYDEBUG,"myNbCells = "<<aGroup->myNbCells<<
388 "; myCellsSize = "<<aGroup->myCellsSize<<"\n\n");
389 aGroupMap.insert(VISU::TGroupMap::value_type(aGroupName,aGroup));
393 MED::TInt aNbFields = aMed->GetNbFields();
394 BEGMSG(MYDEBUG,"VISU::TField aNbFields = "<<aNbFields<<"\n");
395 for(MED::TInt iField = 1; iField <= aNbFields; iField++){
396 MED::PFieldInfo aFieldInfo = aMed->GetPFieldInfo(aMeshInfo,iField);
397 MED::TInt aNbComp = aFieldInfo->GetNbComp();
398 std::string aFieldName = aFieldInfo->GetName();
401 MED::EEntiteMaillage aMEntity;
402 MED::TInt aNbTimeStamps = aMed->GetNbTimeStamps(aFieldInfo,aEntityInfo,aMEntity,aTGeom);
403 VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
404 VISU::PMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
405 VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
406 VISU::PMEDField aField = aFieldMap[aFieldName](new TMEDField());
407 aField->myId = iField;
408 aField->myNbComp = aNbComp;
409 aField->myEntity = aVEntity;
410 aField->myName = aFieldName;
411 aField->myMeshName = aMeshName;
412 aField->myDataSize = aMeshOnEntity->myNbCells * aNbComp;
413 aField->myCompNames.resize(aNbComp);
414 aField->myUnitNames.resize(aNbComp);
416 INITMSG(MYDEBUG,"myName = '"<<aField->myName<<
417 "'; myId = "<<aField->myId<<
418 "; myEntity = "<<aField->myEntity<<
419 "; myDataSize = "<<aField->myDataSize<<
420 "; myNbComp = "<<aField->myNbComp<<"\n");
422 for(MED::TInt iComp = 0; iComp < aNbComp; iComp++){
423 aField->myCompNames[iComp] = aFieldInfo->GetCompName(iComp);
424 aField->myUnitNames[iComp] = aFieldInfo->GetUnitName(iComp);
427 for(MED::TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
429 MED::PTimeStampInfo aTimeStamp = aMed->GetPTimeStampInfo(aFieldInfo,
437 MED::PTimeStampVal aTimeStampVal = aMed->GetPTimeStampVal(aTimeStamp,&anErr);
439 MED::TFloat aDt = aTimeStamp->GetDt();
440 std::string anUnitDt = aTimeStamp->GetUnitDt();
441 VISU::TValField& aValField = aField->myValField;
442 VISU::PMEDValForTime aValForTime = aValField[iTimeStamp](new TMEDValForTime());
443 aValForTime->myId = iTimeStamp;
444 aValForTime->myFieldName = aField->myName;
445 aValForTime->myEntity = aField->myEntity;
446 aValForTime->myMeshName = aField->myMeshName;
447 aValForTime->myNbComp = aField->myNbComp;
448 aValForTime->myTime = VISU::TTime(aDt,anUnitDt);
449 INITMSG(MYDEBUG,"aDt = "<<aDt<<", "<<anUnitDt<<"\n");
452 }catch (std::exception& exc){
453 MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
455 EXCEPTION(runtime_error,"Unknown exception !!!");
461 int VISU_MedConvertor::LoadMeshOnEntity(VISU::PMeshOnEntityImpl theMeshOnEntity,
462 const string& theFamilyName)
464 MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
465 const std::string& aMeshName = theMeshOnEntity->myMeshName;
466 const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
467 VISU::PMeshImpl aMesh = myMeshMap[aMeshName];
469 if(anEntity == VISU::NODE_ENTITY)
470 isPointsUpdated = LoadPoints(aMed,aMesh,theFamilyName);
472 isPointsUpdated = LoadPoints(aMed,aMesh);
473 int isCellsOnEntityUpdated = LoadCellsOnEntity(aMed,aMesh,theMeshOnEntity,theFamilyName);
475 return (isPointsUpdated || isCellsOnEntityUpdated);
478 int VISU_MedConvertor::LoadMeshOnGroup(VISU::PMeshImpl theMesh,
479 const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
481 MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
482 int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
483 VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
484 for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
485 const std::string& aFamilyName = aFamilyAndEntitySetIter->first;
486 const VISU::TEntity& anEntity = aFamilyAndEntitySetIter->second;
487 const VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity];
488 if(anEntity == VISU::NODE_ENTITY){
489 isPointsUpdated += LoadPoints(aMed,theMesh,aFamilyName);
490 isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,aMeshOnEntity);
492 isPointsUpdated += LoadPoints(aMed,theMesh);
493 isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,aMeshOnEntity,aFamilyName);
497 return (isPointsUpdated || isCellsOnEntityUpdated);
500 int VISU_MedConvertor::LoadFieldOnMesh(VISU::PMeshImpl theMesh,
501 VISU::PMeshOnEntityImpl theMeshOnEntity,
502 VISU::PFieldImpl theField,
503 VISU::PValForTimeImpl theValForTime)
505 MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
506 int isPointsUpdated = LoadPoints(aMed,theMesh);
507 int isCellsOnEntityUpdated = LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity);
508 int isFieldUpdated = LoadField(aMed,theMesh,theMeshOnEntity,theField,theValForTime);
510 return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
515 VISU_MedConvertor::LoadPoints(const MED::PWrapper& theMed,
516 VISU::PMEDMesh theMesh,
517 const string& theFamilyName)
520 //Check on existing family
521 VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
522 aMeshOnEntity->myEntity = VISU::NODE_ENTITY;
523 aMeshOnEntity->myMeshName = theMesh->myName;
524 VISU::PFamilyImpl aFamily = GetFamily(aMeshOnEntity,theFamilyName);
525 //Check on loading already done
526 bool isPointsLoaded = !theMesh->myPointsCoord.empty();
530 else if(!aFamily->mySubMesh.empty())
533 INITMSG(MYDEBUG,"LoadPoints - isPointsLoaded = "<<isPointsLoaded<<"; theFamilyName = '"<<theFamilyName<<"'\n");
536 MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo);
537 MED::TInt aNbElem = aNodeInfo->GetNbElem();
540 VISU::TMeshImpl::TPointsDim& aPointsDim = theMesh->myPointsDim;
541 aPointsDim.resize(theMesh->myDim);
542 for(int iDim = 0; iDim < theMesh->myDim; iDim++)
543 aPointsDim[iDim] = aNodeInfo->GetCoordName(iDim);
545 VISU::TMeshImpl::TPointsCoord& aPointsCoord = theMesh->myPointsCoord;
546 aPointsCoord.resize(aNbElem*theMesh->myDim);
547 for(int iElem = 0; iElem < aNbElem; iElem++)
548 for(int iDim = 0, iElem2Dim = iElem*theMesh->myDim; iDim < theMesh->myDim; iDim++, iElem2Dim++)
549 aPointsCoord[iElem2Dim] = aNodeInfo->GetNodeCoord(iElem,iDim);
551 VISU::TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aMeshOnEntity->myCellsConn[VTK_VERTEX];
552 aConnForCellType.resize(aNbElem);
553 for (int iElem = 0; iElem < aNbElem; iElem++)
554 aConnForCellType[iElem] = TMeshOnEntityImpl::TConnect(1,iElem);
556 if(aFamily && aNbElem > 0){
557 VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[VTK_VERTEX];
558 for (int iElem = 0; iElem < aNbElem; iElem++)
559 if(aNodeInfo->GetFamNum(iElem) == aFamily->myId)
560 aSubMeshOnCellType.insert(iElem);
563 }catch(std::exception& exc){
564 MSG(MYDEBUG,"Follow exception was occured :\n"<<exc.what());
565 theMesh->myPointsCoord.clear();
568 theMesh->myPointsCoord.clear();
569 EXCEPTION(runtime_error,"Unknown exception !!!");
576 VISU_MedConvertor::LoadCellsOnEntity(const MED::PWrapper& theMed,
577 VISU::PMEDMesh theMesh,
578 VISU::PMEDMeshOnEntity theMeshOnEntity,
579 const string& theFamilyName)
582 //Check on existing family
583 VISU::PFamilyImpl aFamily = GetFamily(theMeshOnEntity,theFamilyName);
584 //Check on loading already done
585 bool isCellsLoaded = !theMeshOnEntity->myCellsConn.empty();
589 else if(!aFamily->mySubMesh.empty())
592 INITMSG(MYDEBUG,"LoadCellsOnEntity - theFamilyName = '"<<theFamilyName<<"'\n");
593 BEGMSG(MYDEBUG,"LoadCellsOnEntity - isCellsLoaded = "<<isCellsLoaded<<"; isFamilyPresent = "<<bool(aFamily)<<endl);
595 const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
596 const MED::EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity);
598 MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
599 MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
600 MED::TInt aNbPoints = aNodeInfo->GetNbElem();
602 std::map<TInt,TInt> aNodeIdMap;
603 #ifdef _EDF_NODE_IDS_
604 MED::EBooleen anIsNodeNum = MED::eFAUX;
606 MED::EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
608 for(MED::TInt i = 0; i < aNbPoints; i++){
609 aNodeIdMap[aNodeInfo->GetElemNum(i)-1] = i;
614 const MED::TGeom& aTGeom = theMeshOnEntity->myGeom;
615 MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
616 VISU::TMeshOnEntityImpl::TCellsConn& aCellsConn = theMeshOnEntity->myCellsConn;
618 for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
619 const MED::EGeometrieElement& aGeom = anTGeomIter->first;
620 int aVTKGeomType = MEDGeomToVTK(aGeom);
622 case MED::ePOLYGONE: {
623 MED::PPolygoneInfo aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aGeom);
624 MED::TInt aNbElem = aPolygoneInfo->GetNbElem();
627 VISU::TMeshOnEntityImpl::TConnForCellType& aConnForPolygoneType = aCellsConn[aVTKGeomType];
628 aConnForPolygoneType.resize(aNbElem);
630 int aMNbNodes = aPolygoneInfo->GetConnDim();
632 vector<MED::TInt> aConnect(aMNbNodes);
633 vector<MED::TInt> aIndex = aPolygoneInfo->GetIndex();
635 for(int iElem = 0; iElem < aNbElem; iElem++){
636 VISU::TMeshOnEntityImpl::TConnect& anArray = aConnForPolygoneType[iElem];
637 int aNbConn = aPolygoneInfo->GetNbConn(iElem);
639 anArray.resize(aNbConn);
641 aConnect = aPolygoneInfo->GetConnectivite();
643 for(int i = 0 ; i < aNbConn; i++){
644 anArray[i] = aConnect[aIndex[iElem]-1+i]-1;
649 VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVTKGeomType];
650 for(int iElem = 0; iElem < aNbElem; iElem++)
651 if(aPolygoneInfo->GetFamNum(iElem) == aFamily->myId)
652 aSubMeshOnCellType.insert(iElem);
657 int aVNbNodes = VTKGeom2NbNodes(aVTKGeomType);
659 MED::PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aGeom);
660 MED::TInt aNbElem = aCellInfo->GetNbElem();
663 VISU::TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aCellsConn[aVTKGeomType];
664 aConnForCellType.resize(aNbElem);
666 int aMNbNodes = MEDGeom2NbNodes(aGeom);
667 vector<MED::TInt> aConnect(aMNbNodes);
669 for(int iElem = 0; iElem < aNbElem; iElem++) {
670 TMeshOnEntityImpl::TConnect& anArray = aConnForCellType[iElem];
671 anArray.resize(aVNbNodes);
674 for(int i = 0; i < aMNbNodes; i++){
675 aConnect[i] = aNodeIdMap[aCellInfo->GetConn(iElem,i)-1];
678 for(int i = 0; i < aMNbNodes; i++){
679 aConnect[i] = aCellInfo->GetConn(iElem,i)-1;
686 anArray[0] = aConnect[0];
687 anArray[1] = aConnect[1];
688 anArray[2] = aConnect[3];
689 anArray[3] = aConnect[2];
693 anArray[0] = aConnect[0];
694 anArray[1] = aConnect[3];
695 anArray[2] = aConnect[2];
696 anArray[3] = aConnect[1];
697 anArray[4] = aConnect[4];
700 for(int iNode = 0; iNode < aVNbNodes; iNode++)
701 anArray[iNode] = aConnect[iNode];
703 for(int iNode = 0; iNode < aVNbNodes; iNode++)
704 if(anArray[iNode] < 0 || aNbPoints <= anArray[iNode])
705 EXCEPTION(runtime_error,"ImportCells >> aNbPoints("<<aNbPoints<<") "<<
706 "<= anArray["<<iElem<<"]"<<
708 "("<<anArray[iNode]<<") < 0");
711 //Filling aFamily SubMesh
713 VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVTKGeomType];
714 for(int iElem = 0; iElem < aNbElem; iElem++)
715 if(aCellInfo->GetFamNum(iElem) == aFamily->myId)
716 aSubMeshOnCellType.insert(iElem);
721 }catch(std::exception& exc){
722 theMeshOnEntity->myCellsConn.clear();
725 theMeshOnEntity->myCellsConn.clear();
726 EXCEPTION(runtime_error,"Unknown exception !!!");
733 VISU_MedConvertor::LoadField(const MED::PWrapper& theMed,
734 VISU::PMEDMesh theMesh,
735 VISU::PMEDMeshOnEntity theMeshOnEntity,
736 VISU::PMEDField theField,
737 VISU::PMEDValForTime theValForTime)
739 //Check on loading already done
740 if(!theValForTime->myValForCells.empty()) return 0;
743 MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
744 MED::TInt anId = theField->myId;
745 MED::PFieldInfo aFieldInfo = theMed->GetPFieldInfo(aMeshInfo,anId);
748 MED::EEntiteMaillage aMEntity;
749 const MED::TEntityInfo& anEntityInfo = theMesh->myEntityInfo;
750 theMed->GetNbTimeStamps(aFieldInfo,anEntityInfo,aMEntity,aTGeom);
752 anId = theValForTime->myId;
753 MED::PTimeStampInfo aTimeStampInfo =
754 theMed->GetPTimeStampInfo(aFieldInfo,aMEntity,aTGeom,anId);
756 MED::PTimeStampVal aTimeStampVal = theMed->GetPTimeStampVal(aTimeStampInfo);
758 MED::TInt aNbGauss = aTimeStampInfo->GetNbGauss();
759 MED::TInt aNbComp = theField->myNbComp;
761 const MED::TGeom& anEntityTGeom = theMeshOnEntity->myGeom;
762 MED::TGeom::const_iterator aTGeomIter = anEntityTGeom.begin();
763 for(; aTGeomIter != anEntityTGeom.end(); aTGeomIter++){
764 const MED::EGeometrieElement& aGeom = aTGeomIter->first;
765 const MED::TInt& aNbElem = aTGeomIter->second;
767 INITMSG(MYDEBUG,"LoadField - aGeom = "<<aGeom<<"; aNbElem = '"<<aNbElem<<endl);
769 if(aTGeom.find(aGeom) == aTGeom.end()){
770 theField->myDataSize -= aNbElem*theField->myNbComp;
771 theField->myIsTrimmed = true;
773 int aVTKGeomType = MEDGeomToVTK(aGeom);
774 VISU::TValForTimeImpl::TValForCellsWithType& anArray = theValForTime->myValForCells[aVTKGeomType];
775 anArray.resize(aNbComp*aNbElem);
776 for(MED::TInt iElem = 0, anId = 0; iElem < aNbElem; iElem++){
777 for(MED::TInt iComp = 0; iComp < aNbComp; iComp++, anId++){
778 for(MED::TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
779 anArray[anId] += aTimeStampVal->GetVal(aGeom,iElem,iComp,iGauss);
781 anArray[anId] /= aNbGauss;