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::PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
164 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
166 MED::TElemGroup anElemGroup = GetElemsByEntity(aMed,aMeshInfo,aEntityInfo);
168 MED::TInt aDim = aMeshInfo->GetDim();
169 std::string aMeshName = aMeshInfo->GetName();
171 VISU::PMEDMesh aMesh = myMeshMap[aMeshName](new VISU::TMEDMesh());
173 aMesh->myName = aMeshName;
174 aMesh->myNbPoints = aNodeInfo->GetNbElem();
175 aMesh->myMeshInfo = aMeshInfo;
176 aMesh->myEntityInfo = aEntityInfo;
178 INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<
179 "'; myNbPoints = "<<aMesh->myNbPoints<<
180 "; aDim = "<<aDim<<"\n");
182 BEGMSG(MYDEBUG,"aEntityInfo.size() = "<<aEntityInfo.size()<<"\n");
184 typedef std::map<TInt,TInt> TFamilyCounterMap;
185 TFamilyCounterMap aFamilyNbCellsCounterMap, aFamilyCellsSizeCounterMap;
186 TFamilyCounterMap aFamilyNbPolygonesCounterMap, aFamilyPolygonesSizeCounterMap;
188 VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
189 MED::TElemGroup::const_iterator anElemGroupIter = anElemGroup.begin();
190 for(; anElemGroupIter != anElemGroup.end(); anElemGroupIter++){
191 const MED::EEntiteMaillage& aMEntity = anElemGroupIter->first;
192 const MED::TElemMap& anElemMap = anElemGroupIter->second;
194 VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
195 VISU::PMEDMeshOnEntity aMeshOnEntity =
196 aMeshOnEntityMap[aVEntity](new VISU::TMEDMeshOnEntity());
197 aMeshOnEntity->myEntity = aVEntity;
198 aMeshOnEntity->myMeshName = aMeshName;
199 aMeshOnEntity->myGeom = aEntityInfo[aMEntity];
201 INITMSG(MYDEBUG,"aMEntity = "<<aMEntity<<"; aVEntity = "<<aVEntity<<"\n");
203 if(aMEntity == MED::eNOEUD){
204 aMeshOnEntity->myNbCells = aMesh->myNbPoints;
205 aMeshOnEntity->myCellsSize = 2*aMesh->myNbPoints;
207 for(MED::TInt iElem = 0; iElem < aMesh->myNbPoints; iElem++){
208 MED::TInt aFamId = aNodeInfo->GetFamNum(iElem);
210 aFamilyNbCellsCounterMap[aFamId] += 1;
211 aFamilyCellsSizeCounterMap[aFamId] += 2;
215 INITMSG(MYDEBUG,"myNbCells = "<<aMeshOnEntity->myNbCells<<
216 "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<"\n");;
219 aMeshOnEntity->myNbCells = 0;
220 aMeshOnEntity->myCellsSize = 0;
221 MED::TElemMap::const_iterator anElemMapIter = anElemMap.begin();
222 for(; anElemMapIter != anElemMap.end(); anElemMapIter++){
223 const MED::EGeometrieElement& aGeom = anElemMapIter->first;
224 MED::PElemInfo anElemInfo = anElemMapIter->second;
227 case MED::ePOLYGONE: {
228 MED::PPolygoneInfo aPolygoneInfo =
229 aMed->GetPPolygoneInfo(aMeshInfo,aMEntity,MED::ePOLYGONE);
230 MED::TInt aNbElem = aPolygoneInfo->GetNbElem();
231 MED::TElemNum aConn = aPolygoneInfo->GetConnectivite();
232 MED::TElemNum aIndex = aPolygoneInfo->GetIndex();
233 MED::TInt aNbConn = aConn.size();
235 aMeshOnEntity->myNbCells += aNbElem;
237 for (int ii = 0; ii<aNbElem ; ii++){
238 int aNbConnii = aPolygoneInfo->GetNbConn(ii);
239 aMeshOnEntity->myCellsSize += aNbConnii;
242 INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<
243 "; myNbPolygones = "<<aNbElem<<
244 "; nbConn= "<<aNbConn<<"\n");
246 for(MED::TInt iElem = 0; iElem < aNbElem; iElem++){
247 MED::TInt aFamId = aPolygoneInfo->GetFamNum(iElem);
249 aFamilyNbCellsCounterMap[aFamId] += 1;
250 aFamilyCellsSizeCounterMap[aFamId] += aPolygoneInfo->GetNbConn(iElem) + 1;
256 int aVNbNodes = VTKGeom2NbNodes(MEDGeomToVTK(aGeom));
257 MED::PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,aMEntity,aGeom);
258 MED::TInt aNbElem = aCellInfo->GetNbElem();
259 aMeshOnEntity->myNbCells += aNbElem;
260 aMeshOnEntity->myCellsSize += aNbElem*(aVNbNodes+1);
261 INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<
262 "; myNbCells = "<<aMeshOnEntity->myNbCells<<
263 "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<"\n");
265 for(MED::TInt iElem = 0; iElem < aNbElem; iElem++){
266 MED::TInt aFamId = aCellInfo->GetFamNum(iElem);
268 aFamilyNbCellsCounterMap[aFamId] += 1;
269 aFamilyCellsSizeCounterMap[aFamId] += aVNbNodes + 1;
277 BEGMSG(MYDEBUG,"TFamilyByEntity:\n");
279 MED::TFamilyGroup aFamilyGroup = GetFamilies(aMed,aMeshInfo);
281 MED::TGroupInfo aGroupInfo = GetFamiliesByGroup(aFamilyGroup);
283 MED::TFamilyByEntity aFamilyByEntity = GetFamiliesByEntity(aMed,anElemGroup,aFamilyGroup);
285 MED::TFamilyByEntity::const_iterator aFamilyByEntityIter = aFamilyByEntity.begin();
286 for(; aFamilyByEntityIter != aFamilyByEntity.end(); aFamilyByEntityIter++){
287 const MED::EEntiteMaillage& aMEntity = aFamilyByEntityIter->first;
288 const MED::TFamilyGroup& aFamilyGroup = aFamilyByEntityIter->second;
290 VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
291 VISU::PMEDMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
292 VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
294 if(aFamilyGroup.empty())
297 INITMSG(MYDEBUG,"aMEntity = "<<aMEntity<<"; aVEntity = "<<aVEntity<<"\n");
298 MED::TFamilyGroup::const_iterator aFamilyGroupIter = aFamilyGroup.begin();
299 for(; aFamilyGroupIter != aFamilyGroup.end(); aFamilyGroupIter++){
300 MED::PFamilyInfo aFamilyInfo = *aFamilyGroupIter;
301 if(aFamilyInfo->GetId() == 0)
304 std::string aFamilyName = aFamilyInfo->GetName();
305 VISU::PMEDFamily aFamily = aFamilyMap[aFamilyName](new TMEDFamily());
307 aFamily->myId = aFamilyInfo->GetId();
308 aFamily->myName = aFamilyInfo->GetName();
309 aFamily->myEntity = aVEntity;
310 aFamily->myNbCells = aFamilyNbCellsCounterMap[aFamily->myId];
311 aFamily->myCellsSize = aFamilyCellsSizeCounterMap[aFamily->myId];
313 INITMSG(MYDEBUG,"aFamilyName = '"<<aFamily->myName<<
314 "'; myId = "<<aFamily->myId<<"; "<<
315 "; aNbGroup = "<<aFamilyInfo->GetNbGroup()<<
316 "; myEntity = "<<aFamily->myEntity<<
317 "; myNbCells = "<<aFamily->myNbCells<<
318 "; myCellsSize = "<<aFamily->myCellsSize<<"\n");
320 VISU::TBindGroups& aBindGroups = aFamily->myGroups;
321 MED::TInt aNbGroup = aFamilyInfo->GetNbGroup();
322 for(MED::TInt i = 0; i < aNbGroup; i++){
323 std::string aGroupName = aFamilyInfo->GetGroupName(i);
324 aBindGroups.insert(aGroupName);
325 INITMSG(MYDEBUG,"aGroupName = '"<<aGroupName<<"'\n");
330 BEGMSG(MYDEBUG,"VISU::TGroup:\n");
332 VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
333 MED::TGroupInfo::const_iterator aGroupInfoIter = aGroupInfo.begin();
334 for(; aGroupInfoIter != aGroupInfo.end(); aGroupInfoIter++){
335 const std::string& aGroupName = aGroupInfoIter->first;
336 const MED::TFamilyGroup& aFamilyGroup = aGroupInfoIter->second;
337 VISU::PMEDGroup aGroup(new TMEDGroup());
338 aGroup->myName = aGroupName;
339 aGroup->myMeshName = aMeshName;
341 INITMSG(MYDEBUG,"aGroup->myName = '"<<aGroup->myName<<"'\n");
343 MED::TFamilyGroup::const_iterator aFamilyIter = aFamilyGroup.begin();
344 for(; aFamilyIter != aFamilyGroup.end(); aFamilyIter++){
345 MED::PFamilyInfo aFamilyInfo = *aFamilyIter;
346 std::string aFamilyName = aFamilyInfo->GetName();
348 VISU::TEntity aVEntity = TEntity(-1);
349 VISU::PFamily aFamily;
352 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
353 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityIter = aMeshOnEntityMap.begin();
354 for(; aMeshOnEntityIter != aMeshOnEntityMap.end(); aMeshOnEntityIter++){
355 const VISU::PMeshOnEntity& aMeshOnEntity = aMeshOnEntityIter->second;
356 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
357 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
358 for (; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
359 const std::string& aName = aFamilyMapIter->first;
360 aFamily = aFamilyMapIter->second;
361 if(aName == aFamilyName){
362 aVEntity = aFamily->myEntity;
368 if(aFamily && aVEntity >= 0){
369 aGroup->myFamilyAndEntitySet.insert(TFamilyAndEntity(aFamilyName,aVEntity));
370 INITMSG(MYDEBUG,"aFamilyName = '"<<aFamilyName<<"'; '"<<aFamily->myName<<"'; aVEntity = "<<aVEntity<<"\n");
372 aGroup->myNbCells += aFamily->myNbCells;
373 aGroup->myCellsSize += aFamily->myCellsSize;
376 if(!aGroup->myFamilyAndEntitySet.empty() && aGroup->myNbCells > 0){
377 BEGMSG(MYDEBUG,"myNbCells = "<<aGroup->myNbCells<<
378 "; myCellsSize = "<<aGroup->myCellsSize<<"\n\n");
379 aGroupMap.insert(VISU::TGroupMap::value_type(aGroupName,aGroup));
383 MED::TInt aNbFields = aMed->GetNbFields();
384 BEGMSG(MYDEBUG,"VISU::TField aNbFields = "<<aNbFields<<"\n");
385 for(MED::TInt iField = 1; iField <= aNbFields; iField++){
386 MED::PFieldInfo aFieldInfo = aMed->GetPFieldInfo(aMeshInfo,iField);
387 MED::TInt aNbComp = aFieldInfo->GetNbComp();
388 std::string aFieldName = aFieldInfo->GetName();
392 MED::EEntiteMaillage aMEntity;
393 MED::TInt aNbTimeStamps = aMed->GetNbTimeStamps(aFieldInfo,
401 VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity);
402 VISU::PMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
403 VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
404 VISU::PMEDField aField = aFieldMap[aFieldName](new TMEDField());
405 aField->myId = iField;
406 aField->myNbComp = aNbComp;
407 aField->myEntity = aVEntity;
408 aField->myName = aFieldName;
409 aField->myMeshName = aMeshName;
410 aField->myDataSize = aMeshOnEntity->myNbCells * aNbComp;
411 aField->myCompNames.resize(aNbComp);
412 aField->myUnitNames.resize(aNbComp);
414 INITMSG(MYDEBUG,"myName = '"<<aField->myName<<
415 "'; myId = "<<aField->myId<<
416 "; myEntity = "<<aField->myEntity<<
417 "; myDataSize = "<<aField->myDataSize<<
418 "; myNbComp = "<<aField->myNbComp<<"\n");
420 for(MED::TInt iComp = 0; iComp < aNbComp; iComp++){
421 aField->myCompNames[iComp] = aFieldInfo->GetCompName(iComp);
422 aField->myUnitNames[iComp] = aFieldInfo->GetUnitName(iComp);
425 for(MED::TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
426 MED::PTimeStampInfo aTimeStamp = aMed->GetPTimeStampInfo(aFieldInfo,
434 MED::PTimeStampVal aTimeStampVal = aMed->GetPTimeStampVal(aTimeStamp,&anErr);
436 MED::TFloat aDt = aTimeStamp->GetDt();
437 std::string anUnitDt = aTimeStamp->GetUnitDt();
438 VISU::TValField& aValField = aField->myValField;
439 VISU::PMEDValForTime aValForTime = aValField[iTimeStamp](new TMEDValForTime());
440 aValForTime->myId = iTimeStamp;
441 aValForTime->myFieldName = aField->myName;
442 aValForTime->myEntity = aField->myEntity;
443 aValForTime->myMeshName = aField->myMeshName;
444 aValForTime->myNbComp = aField->myNbComp;
445 aValForTime->myTime = VISU::TTime(aDt,anUnitDt);
446 INITMSG(MYDEBUG,"aDt = "<<aDt<<", "<<anUnitDt<<"\n");
449 }catch (std::exception& exc){
450 MSG(MYDEBUG,"Follow exception was occured :\n"<<exc.what());
453 EXCEPTION(runtime_error,"Unknown exception !!!");
459 int VISU_MedConvertor::LoadMeshOnEntity(VISU::PMeshOnEntityImpl theMeshOnEntity,
460 const string& theFamilyName)
462 MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
463 const std::string& aMeshName = theMeshOnEntity->myMeshName;
464 const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
465 VISU::PMeshImpl aMesh = myMeshMap[aMeshName];
467 if(anEntity == VISU::NODE_ENTITY)
468 isPointsUpdated = LoadPoints(aMed,aMesh,theFamilyName);
470 isPointsUpdated = LoadPoints(aMed,aMesh);
471 int isCellsOnEntityUpdated = LoadCellsOnEntity(aMed,aMesh,theMeshOnEntity,theFamilyName);
473 return (isPointsUpdated || isCellsOnEntityUpdated);
476 int VISU_MedConvertor::LoadMeshOnGroup(VISU::PMeshImpl theMesh,
477 const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
479 MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
480 int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
481 VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
482 for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
483 const std::string& aFamilyName = aFamilyAndEntitySetIter->first;
484 const VISU::TEntity& anEntity = aFamilyAndEntitySetIter->second;
485 const VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity];
486 if(anEntity == VISU::NODE_ENTITY){
487 isPointsUpdated += LoadPoints(aMed,theMesh,aFamilyName);
488 isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,aMeshOnEntity);
490 isPointsUpdated += LoadPoints(aMed,theMesh);
491 isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,aMeshOnEntity,aFamilyName);
495 return (isPointsUpdated || isCellsOnEntityUpdated);
498 int VISU_MedConvertor::LoadFieldOnMesh(VISU::PMeshImpl theMesh,
499 VISU::PMeshOnEntityImpl theMeshOnEntity,
500 VISU::PFieldImpl theField,
501 VISU::PValForTimeImpl theValForTime)
503 MED::PWrapper aMed = MED::CrWrapper(myFileInfo.absFilePath().latin1());
504 int isPointsUpdated = LoadPoints(aMed,theMesh);
505 int isCellsOnEntityUpdated = LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity);
506 int isFieldUpdated = LoadField(aMed,theMesh,theMeshOnEntity,theField,theValForTime);
508 return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
513 VISU_MedConvertor::LoadPoints(const MED::PWrapper& theMed,
514 VISU::PMEDMesh theMesh,
515 const string& theFamilyName)
518 //Check on existing family
519 VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
520 aMeshOnEntity->myEntity = VISU::NODE_ENTITY;
521 aMeshOnEntity->myMeshName = theMesh->myName;
522 VISU::PFamilyImpl aFamily = GetFamily(aMeshOnEntity,theFamilyName);
523 //Check on loading already done
524 bool isPointsLoaded = !theMesh->myPointsCoord.empty();
528 else if(!aFamily->mySubMesh.empty())
531 INITMSG(MYDEBUG,"LoadPoints - isPointsLoaded = "<<isPointsLoaded<<"; theFamilyName = '"<<theFamilyName<<"'\n");
534 MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo);
535 MED::TInt aNbElem = aNodeInfo->GetNbElem();
538 VISU::TMeshImpl::TPointsDim& aPointsDim = theMesh->myPointsDim;
539 aPointsDim.resize(theMesh->myDim);
540 for(int iDim = 0; iDim < theMesh->myDim; iDim++)
541 aPointsDim[iDim] = aNodeInfo->GetCoordName(iDim);
543 VISU::TMeshImpl::TPointsCoord& aPointsCoord = theMesh->myPointsCoord;
544 aPointsCoord.resize(aNbElem*theMesh->myDim);
545 for(int iElem = 0; iElem < aNbElem; iElem++)
546 for(int iDim = 0, iElem2Dim = iElem*theMesh->myDim; iDim < theMesh->myDim; iDim++, iElem2Dim++)
547 aPointsCoord[iElem2Dim] = aNodeInfo->GetNodeCoord(iElem,iDim);
549 VISU::TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aMeshOnEntity->myCellsConn[VTK_VERTEX];
550 aConnForCellType.resize(aNbElem);
551 for (int iElem = 0; iElem < aNbElem; iElem++)
552 aConnForCellType[iElem] = TMeshOnEntityImpl::TConnect(1,iElem);
554 if(aFamily && aNbElem > 0){
555 VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[VTK_VERTEX];
556 for (int iElem = 0; iElem < aNbElem; iElem++)
557 if(aNodeInfo->GetFamNum(iElem) == aFamily->myId)
558 aSubMeshOnCellType.insert(iElem);
561 }catch(std::exception& exc){
562 MSG(MYDEBUG,"Follow exception was occured :\n"<<exc.what());
563 theMesh->myPointsCoord.clear();
566 theMesh->myPointsCoord.clear();
567 EXCEPTION(runtime_error,"Unknown exception !!!");
574 VISU_MedConvertor::LoadCellsOnEntity(const MED::PWrapper& theMed,
575 VISU::PMEDMesh theMesh,
576 VISU::PMEDMeshOnEntity theMeshOnEntity,
577 const string& theFamilyName)
580 //Check on existing family
581 VISU::PFamilyImpl aFamily = GetFamily(theMeshOnEntity,theFamilyName);
582 //Check on loading already done
583 bool isCellsLoaded = !theMeshOnEntity->myCellsConn.empty();
587 else if(!aFamily->mySubMesh.empty())
590 INITMSG(MYDEBUG,"LoadCellsOnEntity - theFamilyName = '"<<theFamilyName<<"'\n");
591 BEGMSG(MYDEBUG,"LoadCellsOnEntity - isCellsLoaded = "<<isCellsLoaded<<"; isFamilyPresent = "<<bool(aFamily)<<endl);
593 const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
594 const MED::EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity);
596 MED::PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
597 MED::PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
598 MED::TInt aNbPoints = aNodeInfo->GetNbElem();
600 std::map<TInt,TInt> aNodeIdMap;
601 #ifdef _EDF_NODE_IDS_
602 MED::EBooleen anIsNodeNum = MED::eFAUX;
604 MED::EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
606 for(MED::TInt i = 0; i < aNbPoints; i++){
607 aNodeIdMap[aNodeInfo->GetElemNum(i)-1] = i;
612 const MED::TGeom& aTGeom = theMeshOnEntity->myGeom;
613 MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
614 VISU::TMeshOnEntityImpl::TCellsConn& aCellsConn = theMeshOnEntity->myCellsConn;
616 for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
617 const MED::EGeometrieElement& aGeom = anTGeomIter->first;
618 int aVTKGeomType = MEDGeomToVTK(aGeom);
620 case MED::ePOLYGONE: {
621 MED::PPolygoneInfo aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aGeom);
622 MED::TInt aNbElem = aPolygoneInfo->GetNbElem();
625 VISU::TMeshOnEntityImpl::TConnForCellType& aConnForPolygoneType = aCellsConn[aVTKGeomType];
626 aConnForPolygoneType.resize(aNbElem);
628 int aMNbNodes = aPolygoneInfo->GetConnDim();
630 vector<MED::TInt> aConnect(aMNbNodes);
631 vector<MED::TInt> aIndex = aPolygoneInfo->GetIndex();
633 for(int iElem = 0; iElem < aNbElem; iElem++){
634 VISU::TMeshOnEntityImpl::TConnect& anArray = aConnForPolygoneType[iElem];
635 int aNbConn = aPolygoneInfo->GetNbConn(iElem);
637 anArray.resize(aNbConn);
639 aConnect = aPolygoneInfo->GetConnectivite();
641 for(int i = 0 ; i < aNbConn; i++){
642 anArray[i] = aConnect[aIndex[iElem]-1+i]-1;
647 VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVTKGeomType];
648 for(int iElem = 0; iElem < aNbElem; iElem++)
649 if(aPolygoneInfo->GetFamNum(iElem) == aFamily->myId)
650 aSubMeshOnCellType.insert(iElem);
655 int aVNbNodes = VTKGeom2NbNodes(aVTKGeomType);
657 MED::PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aGeom);
658 MED::TInt aNbElem = aCellInfo->GetNbElem();
661 VISU::TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aCellsConn[aVTKGeomType];
662 aConnForCellType.resize(aNbElem);
664 int aMNbNodes = MEDGeom2NbNodes(aGeom);
665 vector<MED::TInt> aConnect(aMNbNodes);
667 for(int iElem = 0; iElem < aNbElem; iElem++) {
668 TMeshOnEntityImpl::TConnect& anArray = aConnForCellType[iElem];
669 anArray.resize(aVNbNodes);
672 for(int i = 0; i < aMNbNodes; i++){
673 aConnect[i] = aNodeIdMap[aCellInfo->GetConn(iElem,i)-1];
676 for(int i = 0; i < aMNbNodes; i++){
677 aConnect[i] = aCellInfo->GetConn(iElem,i)-1;
684 anArray[0] = aConnect[0];
685 anArray[1] = aConnect[1];
686 anArray[2] = aConnect[3];
687 anArray[3] = aConnect[2];
691 anArray[0] = aConnect[0];
692 anArray[1] = aConnect[3];
693 anArray[2] = aConnect[2];
694 anArray[3] = aConnect[1];
695 anArray[4] = aConnect[4];
698 for(int iNode = 0; iNode < aVNbNodes; iNode++)
699 anArray[iNode] = aConnect[iNode];
701 for(int iNode = 0; iNode < aVNbNodes; iNode++)
702 if(anArray[iNode] < 0 || aNbPoints <= anArray[iNode])
703 EXCEPTION(runtime_error,"ImportCells >> aNbPoints("<<aNbPoints<<") "<<
704 "<= anArray["<<iElem<<"]"<<
706 "("<<anArray[iNode]<<") < 0");
709 //Filling aFamily SubMesh
711 VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVTKGeomType];
712 for(int iElem = 0; iElem < aNbElem; iElem++)
713 if(aCellInfo->GetFamNum(iElem) == aFamily->myId)
714 aSubMeshOnCellType.insert(iElem);
719 }catch(std::exception& exc){
720 theMeshOnEntity->myCellsConn.clear();
723 theMeshOnEntity->myCellsConn.clear();
724 EXCEPTION(runtime_error,"Unknown exception !!!");
731 VISU_MedConvertor::LoadField(const MED::PWrapper& theMed,
732 VISU::PMEDMesh theMesh,
733 VISU::PMEDMeshOnEntity theMeshOnEntity,
734 VISU::PMEDField theField,
735 VISU::PMEDValForTime theValForTime)
737 //Check on loading already done
738 if(!theValForTime->myValForCells.empty()) return 0;
741 MED::PMeshInfo aMeshInfo = theMesh->myMeshInfo;
742 MED::TInt anId = theField->myId;
743 MED::PFieldInfo aFieldInfo = theMed->GetPFieldInfo(aMeshInfo,anId);
746 MED::EEntiteMaillage aMEntity;
747 const MED::TEntityInfo& anEntityInfo = theMesh->myEntityInfo;
748 theMed->GetNbTimeStamps(aFieldInfo,anEntityInfo,aMEntity,aTGeom);
750 anId = theValForTime->myId;
751 MED::PTimeStampInfo aTimeStampInfo =
752 theMed->GetPTimeStampInfo(aFieldInfo,aMEntity,aTGeom,anId);
754 MED::PTimeStampVal aTimeStampVal = theMed->GetPTimeStampVal(aTimeStampInfo);
756 MED::TInt aNbGauss = aTimeStampInfo->GetNbGauss();
757 MED::TInt aNbComp = theField->myNbComp;
759 bool anIsTrimmed = theField->myIsTrimmed;
760 const MED::TGeom& anEntityTGeom = theMeshOnEntity->myGeom;
761 MED::TGeom::const_iterator aTGeomIter = anEntityTGeom.begin();
762 for(; aTGeomIter != anEntityTGeom.end(); aTGeomIter++){
763 const MED::EGeometrieElement& aGeom = aTGeomIter->first;
764 const MED::TInt& aNbElem = aTGeomIter->second;
766 INITMSG(MYDEBUG,"LoadField - aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<endl);
768 if(aTGeom.find(aGeom) == aTGeom.end()){
769 if(!theField->myIsTrimmed){
770 theField->myDataSize -= aNbElem*theField->myNbComp;
774 int aVTKGeomType = MEDGeomToVTK(aGeom);
775 VISU::TValForTimeImpl::TValForCellsWithType& anArray = theValForTime->myValForCells[aVTKGeomType];
776 anArray.resize(aNbComp*aNbElem);
777 for(MED::TInt iElem = 0, anId = 0; iElem < aNbElem; iElem++){
778 for(MED::TInt iComp = 0; iComp < aNbComp; iComp++, anId++){
779 for(MED::TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
780 anArray[anId] += aTimeStampVal->GetVal(aGeom,iElem,iComp,iGauss);
782 anArray[anId] /= aNbGauss;
787 theField->myIsTrimmed = anIsTrimmed;