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_CONVEX_POINT_SET;
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;
112 case VTK_CONVEX_POINT_SET: return ePOLYEDRE;
114 return EGeometrieElement(-1);
117 TEntity MEDEntityToVTK(MED::EEntiteMaillage theMEDEntity)
119 switch(theMEDEntity){
120 case eNOEUD: return NODE_ENTITY;
121 case eARETE: return EDGE_ENTITY;
122 case eFACE: return FACE_ENTITY;
123 case eMAILLE: return CELL_ENTITY;
128 MED::EEntiteMaillage VTKEntityToMED(TEntity theVTKEntity)
130 switch(theVTKEntity){
131 case NODE_ENTITY: return eNOEUD;
132 case EDGE_ENTITY: return eARETE;
133 case FACE_ENTITY: return eFACE;
134 case CELL_ENTITY: return eMAILLE;
136 return MED::EEntiteMaillage(-1);
142 VISU_Convertor* CreateConvertor(const string& theFileName)
144 return new VISU_MedConvertor(theFileName);
147 VISU_MedConvertor::VISU_MedConvertor(const string& theFileName) {
148 myFileInfo.setFile(QString(theFileName.c_str()));
149 myName = myFileInfo.baseName().latin1();
152 VISU_Convertor* VISU_MedConvertor::Build() {
153 PWrapper aMed = CrWrapper(myFileInfo.absFilePath().latin1());
154 TInt aNbMeshes = aMed->GetNbMeshes();
155 TMeshMap& aMeshMap = myMeshMap;
157 MSG(MYDEBUG,"VISU_MedConvertor::Build()");
158 INITMSG(MYDEBUG,"GetNbMeshes() = "<<aNbMeshes<<"\n");
160 for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++)
162 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
164 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
166 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
168 TElemGroup aElemGroup = GetElemsByEntity(aMed,aMeshInfo,aEntityInfo);
170 TFamilyGroup aFamilyGroup = GetFamilies(aMed,aMeshInfo);
172 TFamilyByEntity aFamilyByEntity = GetFamiliesByEntity(aMed,aElemGroup,aFamilyGroup);
174 TGroupInfo aGroupInfo = GetFamiliesByGroup(aFamilyGroup);
176 // creating TMesh structure and TMeshOnEntityMap
177 typedef map<TInt,TInt> TFamilyCounterMap;
178 TFamilyCounterMap aFamilyNbCellsCounterMap, aFamilyCellsSizeCounterMap;
180 TInt aDim = aMeshInfo->GetDim();
181 const string& aMeshName = aMeshInfo->GetName();
183 PMEDMesh aMesh = aMeshMap[aMeshName](new TMEDMesh());
185 aMesh->myName = aMeshName;
186 aMesh->myNbPoints = aNodeInfo->GetNbElem();
187 aMesh->myMeshInfo = aMeshInfo;
188 aMesh->myEntityInfo = aEntityInfo;
190 INITMSG(MYDEBUG,"aMeshName = '"<<aMeshName<<
191 "'; myNbPoints = "<<aMesh->myNbPoints<<
192 "; aDim = "<<aDim<<"\n");
194 BEGMSG(MYDEBUG,"aEntityInfo.size() = "<<aEntityInfo.size()<<"\n");
196 TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
197 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
198 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
199 const EEntiteMaillage& aMEntity = anEntityIter->first;
200 const MED::TGeom& aTGeom = anEntityIter->second;
202 TEntity aVEntity = MEDEntityToVTK(aMEntity);
203 PMEDMeshOnEntity aMeshOnEntity = aMeshOnEntityMap[aVEntity](new TMEDMeshOnEntity());
204 aMeshOnEntity->myEntity = aVEntity;
205 aMeshOnEntity->myMeshName = aMeshName;
206 aMeshOnEntity->myGeom = aTGeom;
208 INITMSG(MYDEBUG,"aMEntity = "<<aMEntity<<"; aVEntity = "<<aVEntity<<"\n");
210 if(aMEntity == eNOEUD){
211 aMeshOnEntity->myNbCells = aMesh->myNbPoints;
212 aMeshOnEntity->myCellsSize = 2*aMesh->myNbPoints;
214 for(TInt iElem = 0; iElem < aMesh->myNbPoints; iElem++){
215 TInt aFamId = aNodeInfo->GetFamNum(iElem);
217 aFamilyNbCellsCounterMap[aFamId] += 1;
218 aFamilyCellsSizeCounterMap[aFamId] += 2;
222 INITMSG(MYDEBUG,"myNbCells = "<<aMeshOnEntity->myNbCells<<
223 "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<"\n");;
226 MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
227 aMeshOnEntity->myNbCells = 0;
228 aMeshOnEntity->myCellsSize = 0;
229 for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
230 const EGeometrieElement& aGeom = anTGeomIter->first;
235 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aGeom);
236 TInt aNbElem = aPolygoneInfo->GetNbElem();
237 TElemNum aConn = aPolygoneInfo->GetConnectivite();
238 TElemNum aIndex = aPolygoneInfo->GetIndex();
239 TInt aNbIndex = aIndex.size();
240 TInt aNbConn = aConn.size();
242 aMeshOnEntity->myNbCells += aNbElem;
244 for (int ii = 0; ii<aNbElem ; ii++){
245 int aNbConnii = aPolygoneInfo->GetNbConn(ii);
246 aMeshOnEntity->myCellsSize += aNbConnii;
248 INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<
249 "; myNbPolygones = "<<aNbElem<<
250 "; nbConn= "<<aNbConn<<"\n");
252 for(TInt iElem = 0; iElem < aNbElem; iElem++){
253 TInt aFamId = aPolygoneInfo->GetFamNum(iElem);
255 aFamilyNbCellsCounterMap[aFamId] += 1;
256 ADDMSG(MYDEBUG,"aFamId="<<aFamId<<" ");
257 aFamilyCellsSizeCounterMap[aFamId] += aPolygoneInfo->GetNbConn(iElem) + 1;
260 ADDMSG(MYDEBUG,endl);
265 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aGeom);
266 TInt aNbElem = aPolyedreInfo->GetNbElem();
267 TElemNum aConn = aPolyedreInfo->GetConnectivite();
268 TElemNum aIndex = aPolyedreInfo->GetIndex();
269 TInt aNbIndex = aIndex.size();
270 TInt aNbConn = aConn.size();
272 aMeshOnEntity->myNbCells += aNbElem;
274 for (int ii = 0; ii<aNbElem ; ii++){
275 int aNbConnii = aPolyedreInfo->GetNbConn(ii);
276 aMeshOnEntity->myCellsSize += aNbConnii;
278 INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<
279 "; myNbPolyedres = "<<aNbElem<<
280 "; nbConn= "<<aNbConn<<"\n");
282 for(TInt iElem = 0; iElem < aNbElem; iElem++){
283 TInt aFamId = aPolyedreInfo->GetFamNum(iElem);
284 std::string aName = aPolyedreInfo->GetElemName(iElem);
286 aFamilyNbCellsCounterMap[aFamId] += 1;
287 ADDMSG(MYDEBUG,"(aFamId="<<aFamId<<";Name='"<<aName<<"') ");
288 aFamilyCellsSizeCounterMap[aFamId] += aPolyedreInfo->GetNbConn(iElem) + 1;
291 ADDMSG(MYDEBUG,endl);
296 int aVNbNodes = VTKGeom2NbNodes(MEDGeomToVTK(aGeom));
297 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,aMEntity,aGeom);
298 TInt aNbElem = aCellInfo->GetNbElem();
299 aMeshOnEntity->myNbCells += aNbElem;
300 aMeshOnEntity->myCellsSize += aNbElem*(aVNbNodes+1);
301 INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<
302 "; myNbCells = "<<aMeshOnEntity->myNbCells<<
303 "; myCellsSize = "<<aMeshOnEntity->myCellsSize<<"\n");
305 for(TInt iElem = 0; iElem < aNbElem; iElem++){
306 TInt aFamId = aCellInfo->GetFamNum(iElem);
308 aFamilyNbCellsCounterMap[aFamId] += 1;
309 ADDMSG(MYDEBUG,"aFamId = "<<aFamId<<" ");
310 aFamilyCellsSizeCounterMap[aFamId] += aVNbNodes + 1;
313 ADDMSG(MYDEBUG,endl);
320 TFamilyByEntity::const_iterator aFamilyByEntityIter = aFamilyByEntity.begin();
321 BEGMSG(MYDEBUG,"TFamilyByEntity:\n");
322 for(; aFamilyByEntityIter != aFamilyByEntity.end(); aFamilyByEntityIter++){
323 const EEntiteMaillage& aMEntity = aFamilyByEntityIter->first;
324 const TFamilyGroup& aFamilyGroup = aFamilyByEntityIter->second;
326 TEntity aVEntity = MEDEntityToVTK(aMEntity);
327 VISU::PMEDMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
328 VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
330 if(aFamilyGroup.empty())
333 INITMSG(MYDEBUG,"aMEntity = "<<aMEntity<<"; aVEntity = "<<aVEntity<<"\n");
334 TFamilyGroup::const_iterator aFamilyGroupIter = aFamilyGroup.begin();
335 for(; aFamilyGroupIter != aFamilyGroup.end(); aFamilyGroupIter++){
336 const PFamilyInfo& aFamilyInfo = *aFamilyGroupIter;
337 if (aFamilyInfo->GetId() == 0)
340 const std::string& aFamilyName = aFamilyInfo->GetName();
341 PMEDFamily aFamily = aFamilyMap[aFamilyName](new TMEDFamily());
343 aFamily->myId = aFamilyInfo->GetId();
344 aFamily->myName = aFamilyInfo->GetName();
345 aFamily->myEntity = aVEntity;
346 aFamily->myNbCells = aFamilyNbCellsCounterMap[aFamily->myId];
347 aFamily->myCellsSize = aFamilyCellsSizeCounterMap[aFamily->myId];
349 INITMSG(MYDEBUG,"aFamilyName = '"<<aFamily->myName<<
350 "'; myId = "<<aFamily->myId<<"; "<<
351 "; aNbAttr = "<<aFamilyInfo->GetNbAttr()<<
352 "; aNbGroup = "<<aFamilyInfo->GetNbGroup()<<
353 "; myEntity = "<<aFamily->myEntity<<
354 "; myNbCells = "<<aFamily->myNbCells<<
355 "; myCellsSize = "<<aFamily->myCellsSize<<"\n");
357 VISU::TBindGroups& aBindGroups = aFamily->myGroups;
358 const TInt aNbGroup = aFamilyInfo->GetNbGroup();
359 for(TInt i = 0; i < aNbGroup; i++){
360 const string& aGroupName = aFamilyInfo->GetGroupName(i);
361 aBindGroups.insert(aGroupName);
362 INITMSG(MYDEBUG,"aGroupName = '"<<aGroupName<<"'\n");
367 BEGMSG(MYDEBUG,"VISU::TGroup:\n");
369 VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
370 TGroupInfo::const_iterator aGroupInfoIter = aGroupInfo.begin();
371 for(;aGroupInfoIter != aGroupInfo.end(); aGroupInfoIter++){
372 const string& aGroupName = aGroupInfoIter->first;
373 const TFamilyGroup& aFamilyGroup = aGroupInfoIter->second;
374 PMEDGroup aGroup(new TMEDGroup());
375 aGroup->myName = aGroupName;
376 aGroup->myMeshName = aMesh->myName;
378 INITMSG(MYDEBUG,"aGroup->myName = '"<<aGroup->myName<<"'\n");
380 TFamilyGroup::const_iterator aFamilyIter = aFamilyGroup.begin();
381 for(; aFamilyIter != aFamilyGroup.end(); aFamilyIter++){
382 const PFamilyInfo& aFamilyInfo = *aFamilyIter;
383 const string& aFamilyName = aFamilyInfo->GetName();
385 TEntity aVEntity = TEntity(-1);
389 const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
390 TMeshOnEntityMap::const_iterator aMeshOnEntityIter = aMeshOnEntityMap.begin();
391 for(; aMeshOnEntityIter != aMeshOnEntityMap.end(); aMeshOnEntityIter++){
392 const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityIter->second;
393 const TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
394 TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
395 for (; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
396 const string& aName = aFamilyMapIter->first;
397 aFamily = aFamilyMapIter->second;
398 if(aName == aFamilyName){
399 aVEntity = aFamily->myEntity;
405 if(aFamily && aVEntity >= 0){
406 aGroup->myFamilyAndEntitySet.insert(TFamilyAndEntity(aFamilyName,aVEntity));
407 INITMSG(MYDEBUG,"aFamilyName = '"<<aFamilyName<<"'; '"<<aFamily->myName<<"'; aVEntity = "<<aVEntity<<"\n");
409 aGroup->myNbCells += aFamily->myNbCells;
410 aGroup->myCellsSize += aFamily->myCellsSize;
413 if(!aGroup->myFamilyAndEntitySet.empty() && aGroup->myNbCells > 0){
414 BEGMSG(MYDEBUG,"myNbCells = "<<aGroup->myNbCells<<
415 "; myCellsSize = "<<aGroup->myCellsSize<<"\n\n");
416 aGroupMap.insert(VISU::TGroupMap::value_type(aGroupName,aGroup));
420 TInt aNbFields = aMed->GetNbFields();
421 BEGMSG(MYDEBUG,"VISU::TField: NbFields="<<aNbFields<<"\n");
422 for(TInt iField = 1; iField <= aNbFields; iField++){
423 PFieldInfo aFieldInfo = aMed->GetPFieldInfo(aMeshInfo,iField);
424 TInt aNbComp = aFieldInfo->GetNbComp();
425 const string& aFieldName = aFieldInfo->GetName();
428 EEntiteMaillage aMEntity;
429 TInt aNbTimeStamps = aMed->GetNbTimeStamps(aFieldInfo,aEntityInfo,aMEntity,aTGeom);
432 TEntity aVEntity = MEDEntityToVTK(aMEntity);
433 VISU::PMeshOnEntity aMeshOnEntity = aMesh->myMeshOnEntityMap[aVEntity];
434 TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
435 PMEDField aField = aFieldMap[aFieldName](new TMEDField());
436 aField->myId = iField;
437 aField->myNbComp = aNbComp;
438 aField->myEntity = aVEntity;
439 aField->myName = aFieldName;
440 aField->myMeshName = aMeshName;
441 aField->myDataSize = aMeshOnEntity->myNbCells * aNbComp;
442 aField->myCompNames.resize(aNbComp);
443 aField->myUnitNames.resize(aNbComp);
445 INITMSG(MYDEBUG,"myName = '"<<aField->myName<<
446 "'; myId = "<<aField->myId<<
447 "; myEntity = "<<aField->myEntity<<
448 "; myDataSize = "<<aField->myDataSize<<
449 "; myNbComp = "<<aField->myNbComp<<"\n");
451 for(TInt iComp = 0; iComp < aNbComp; iComp++){
452 aField->myCompNames[iComp] = aFieldInfo->GetCompName(iComp);
453 aField->myUnitNames[iComp] = aFieldInfo->GetUnitName(iComp);
456 for(TInt iTimeStamp = 1; iTimeStamp <= aNbTimeStamps; iTimeStamp++){
457 PTimeStampInfo aTimeStamp = aMed->GetPTimeStampInfo(aFieldInfo,
461 TFloat aDt = aTimeStamp->GetDt();
462 const string& anUnitDt = aTimeStamp->GetUnitDt();
463 PTimeStampVal aTimeStampVal = aMed->GetPTimeStampVal(aTimeStamp);
464 TValField& aValField = aField->myValField;
465 PMEDValForTime aValForTime = aValField[iTimeStamp](new TMEDValForTime());
466 aValForTime->myId = iTimeStamp;
467 aValForTime->myFieldName = aField->myName;
468 aValForTime->myEntity = aField->myEntity;
469 aValForTime->myMeshName = aField->myMeshName;
470 aValForTime->myNbComp = aField->myNbComp;
471 aValForTime->myTime = VISU::TTime(aDt,anUnitDt);
472 INITMSG(MYDEBUG,"aDt = "<<aDt<<", "<<anUnitDt<<"\n");
475 } catch (std::runtime_error& exc){
476 MSG(MYDEBUG,"Follow exception wqs occured in:\n"<<exc.what());
478 EXCEPTION(runtime_error,"Unknown exception !!!");
484 int VISU_MedConvertor::LoadMeshOnEntity(VISU::PMeshOnEntityImpl theMeshOnEntity,
485 const string& theFamilyName)
487 PWrapper aMed = CrWrapper(myFileInfo.absFilePath().latin1());
488 const string& aMeshName = theMeshOnEntity->myMeshName;
489 const VISU::TEntity& anEntity = theMeshOnEntity->myEntity;
490 PMeshImpl aMesh = myMeshMap[aMeshName];
492 if(anEntity == VISU::NODE_ENTITY)
493 isPointsUpdated = LoadPoints(aMed,aMesh,theFamilyName);
495 isPointsUpdated = LoadPoints(aMed,aMesh);
496 int isCellsOnEntityUpdated = LoadCellsOnEntity(aMed,aMesh,theMeshOnEntity,theFamilyName);
498 return (isPointsUpdated || isCellsOnEntityUpdated);
501 int VISU_MedConvertor::LoadMeshOnGroup(VISU::PMeshImpl theMesh,
502 const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
504 PWrapper aMed = CrWrapper(myFileInfo.absFilePath().latin1());
505 int isPointsUpdated = 0, isCellsOnEntityUpdated = 0;
506 VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
507 for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
508 const string& aFamilyName = aFamilyAndEntitySetIter->first;
509 const VISU::TEntity& anEntity = aFamilyAndEntitySetIter->second;
510 const VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[anEntity];
511 if(anEntity == VISU::NODE_ENTITY){
512 isPointsUpdated += LoadPoints(aMed,theMesh,aFamilyName);
513 isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,aMeshOnEntity);
515 isPointsUpdated += LoadPoints(aMed,theMesh);
516 isCellsOnEntityUpdated += LoadCellsOnEntity(aMed,theMesh,aMeshOnEntity,aFamilyName);
520 return (isPointsUpdated || isCellsOnEntityUpdated);
523 int VISU_MedConvertor::LoadFieldOnMesh(VISU::PMeshImpl theMesh,
524 VISU::PMeshOnEntityImpl theMeshOnEntity,
525 VISU::PFieldImpl theField,
526 VISU::PValForTimeImpl theValForTime)
528 PWrapper aMed = CrWrapper(myFileInfo.absFilePath().latin1());
529 int isPointsUpdated = LoadPoints(aMed,theMesh);
530 int isCellsOnEntityUpdated = LoadCellsOnEntity(aMed,theMesh,theMeshOnEntity);
531 int isFieldUpdated = LoadField(aMed,theMesh,theMeshOnEntity,theField,theValForTime);
533 return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
538 VISU_MedConvertor::LoadPoints(const MED::PWrapper& theMed,
539 VISU::PMEDMesh theMesh,
540 const string& theFamilyName)
543 //Check on existing family
544 VISU::PMEDMeshOnEntity aMeshOnEntity = theMesh->myMeshOnEntityMap[VISU::NODE_ENTITY];
545 aMeshOnEntity->myEntity = VISU::NODE_ENTITY;
546 aMeshOnEntity->myMeshName = theMesh->myName;
547 PFamilyImpl aFamily = GetFamily(aMeshOnEntity,theFamilyName);
548 //Check on loading already done
549 bool isPointsLoaded = !theMesh->myPointsCoord.empty();
553 else if(!aFamily->mySubMesh.empty())
556 INITMSG(MYDEBUG,"LoadPoints - isPointsLoaded = "<<isPointsLoaded<<"; theFamilyName = '"<<theFamilyName<<"'\n");
559 PNodeInfo aNodeInfo = theMed->GetPNodeInfo(theMesh->myMeshInfo);
560 TInt aNbElem = aNodeInfo->GetNbElem();
563 VISU::TMeshImpl::TPointsDim& aPointsDim = theMesh->myPointsDim;
564 aPointsDim.resize(theMesh->myDim);
565 for(int iDim = 0; iDim < theMesh->myDim; iDim++)
566 aPointsDim[iDim] = aNodeInfo->GetCoordName(iDim);
568 VISU::TMeshImpl::TPointsCoord& aPointsCoord = theMesh->myPointsCoord;
569 aPointsCoord.resize(aNbElem*theMesh->myDim);
570 for (int iElem = 0; iElem < aNbElem; iElem++)
571 for(int iDim = 0, iElem2Dim = iElem*theMesh->myDim; iDim < theMesh->myDim; iDim++, iElem2Dim++)
572 aPointsCoord[iElem2Dim] = aNodeInfo->GetNodeCoord(iElem,iDim);
574 VISU::TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aMeshOnEntity->myCellsConn[VTK_VERTEX];
575 aConnForCellType.resize(aNbElem);
576 for (int iElem = 0; iElem < aNbElem; iElem++)
577 aConnForCellType[iElem] = VISU::TMeshOnEntityImpl::TConnect(1,iElem);
579 if(aFamily && aNbElem > 0){
580 VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[VTK_VERTEX];
581 for (int iElem = 0; iElem < aNbElem; iElem++)
582 if(aNodeInfo->GetFamNum(iElem) == aFamily->myId)
583 aSubMeshOnCellType.insert(iElem);
586 }catch(std::runtime_error& exc){
587 theMesh->myPointsCoord.clear();
590 theMesh->myPointsCoord.clear();
591 EXCEPTION(runtime_error,"Unknown exception !!!");
598 VISU_MedConvertor::LoadCellsOnEntity(const MED::PWrapper& theMed,
599 VISU::PMEDMesh theMesh,
600 VISU::PMEDMeshOnEntity theMeshOnEntity,
601 const string& theFamilyName)
604 //Check on existing family
605 PFamilyImpl aFamily = GetFamily(theMeshOnEntity,theFamilyName);
606 //Check on loading already done
607 bool isCellsLoaded = !theMeshOnEntity->myCellsConn.empty();
611 else if(!aFamily->mySubMesh.empty())
614 INITMSG(MYDEBUG,"LoadCellsOnEntity - theFamilyName = '"<<theFamilyName<<"'\n");
615 BEGMSG(MYDEBUG,"LoadCellsOnEntity - isCellsLoaded = "<<isCellsLoaded<<"; isFamilyPresent = "<<bool(aFamily)<<endl);
617 const VISU::TEntity& aVEntity = theMeshOnEntity->myEntity;
618 const EEntiteMaillage& aMEntity = VTKEntityToMED(aVEntity);
620 const PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
621 PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
622 TInt aNbPoints = aNodeInfo->GetNbElem();
624 std::map<TInt,TInt> aNodeIdMap;
625 #ifdef _EDF_NODE_IDS_
626 EBooleen anIsNodeNum = eFAUX;
628 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
630 for(TInt i = 0; i < aNbPoints; i++){
631 aNodeIdMap[aNodeInfo->GetElemNum(i)-1] = i;
636 const MED::TGeom& aTGeom = theMeshOnEntity->myGeom;
637 MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
638 TMeshOnEntityImpl::TCellsConn& aCellsConn = theMeshOnEntity->myCellsConn;
640 for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
641 const EGeometrieElement& aGeom = anTGeomIter->first;
642 int aVTKGeomType = MEDGeomToVTK(aGeom);
643 ADDMSG(MYDEBUG,"LoadCellsOnEntity aGeom="<<aGeom<<"\n");
647 PPolygoneInfo aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,aMEntity,aGeom);
648 TInt aNbElem = aPolygoneInfo->GetNbElem();
651 VISU::TMeshOnEntityImpl::TConnForCellType& aConnForPolygoneType = aCellsConn[aVTKGeomType];
652 aConnForPolygoneType.resize(aNbElem);
654 int aMNbNodes = aPolygoneInfo->GetConnDim();
656 vector<TInt> aConnect(aMNbNodes);
657 vector<TInt> aIndex = aPolygoneInfo->GetIndex();
659 for (int iElem = 0; iElem < aNbElem; iElem++) {
660 VISU::TMeshOnEntityImpl::TConnect& anArray = aConnForPolygoneType[iElem];
661 int aNbConn = aPolygoneInfo->GetNbConn(iElem);
663 anArray.resize(aNbConn);
665 aConnect = aPolygoneInfo->GetConnectivite();
667 for (int i=0;i<aNbConn;i++){
668 anArray[i] = aConnect[aIndex[iElem]-1+i]-1;
673 VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVTKGeomType];
674 for(int iElem = 0; iElem < aNbElem; iElem++)
675 if(aPolygoneInfo->GetFamNum(iElem) == aFamily->myId)
676 aSubMeshOnCellType.insert(iElem);
682 PPolyedreInfo aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,aMEntity,aGeom);
683 TInt aNbElem = aPolyedreInfo->GetNbElem();
685 int aMNbNodes = aPolyedreInfo->GetNbConn();
686 vector<TInt> aConnect(aMNbNodes);
687 aConnect = aPolyedreInfo->GetConnectivite();
690 VISU::TMeshOnEntityImpl::TConnForCellType& aConnForPolyedreType = aCellsConn[aVTKGeomType];
691 aConnForPolyedreType.resize(aNbElem);
693 vector<TInt> aFacesIndex = aPolyedreInfo->GetFacesIndex();
694 vector<TInt> aIndex = aPolyedreInfo->GetIndex();
696 for (int iElem = 0; iElem < aNbElem; iElem++) {
698 VISU::TMeshOnEntityImpl::TConnect& anArray = aConnForPolyedreType[iElem];
700 int aInd1 = aIndex[iElem]-1;
701 int aInd2 = aIndex[iElem+1]-2;
703 for (int i=aInd1;i<=aInd2;i++){
704 for (int j=aFacesIndex[i]-1;j<aFacesIndex[i+1]-1;j++){
705 aArrayNew.insert(aConnect[j]);
709 int aNbConnNew = aArrayNew.size();
710 anArray.resize(aNbConnNew);
711 set<TInt>::iterator aIter = aArrayNew.begin();
712 for (int i=0; aIter!=aArrayNew.end();aIter++, i++)
713 anArray[i] = (*aIter)-1;
718 VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVTKGeomType];
719 for(int iElem = 0; iElem < aNbElem; iElem++)
720 if(aPolyedreInfo->GetFamNum(iElem) == aFamily->myId)
721 aSubMeshOnCellType.insert(iElem);
727 int aVNbNodes = VTKGeom2NbNodes(aVTKGeomType);
729 PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,aMEntity,aGeom);
730 TInt aNbElem = aCellInfo->GetNbElem();
733 VISU::TMeshOnEntityImpl::TConnForCellType& aConnForCellType = aCellsConn[aVTKGeomType];
734 aConnForCellType.resize(aNbElem);
736 int aMNbNodes = MEDGeom2NbNodes(aGeom);
737 vector<TInt> aConnect(aMNbNodes);
739 for (int iElem = 0; iElem < aNbElem; iElem++) {
740 VISU::TMeshOnEntityImpl::TConnect& anArray = aConnForCellType[iElem];
741 anArray.resize(aVNbNodes);
744 for(int i = 0; i < aMNbNodes; i++){
745 aConnect[i] = aNodeIdMap[aCellInfo->GetConn(iElem,i)-1];
748 for(int i = 0; i < aMNbNodes; i++){
749 aConnect[i] = aCellInfo->GetConn(iElem,i)-1;
756 anArray[0] = aConnect[0];
757 anArray[1] = aConnect[1];
758 anArray[2] = aConnect[3];
759 anArray[3] = aConnect[2];
763 anArray[0] = aConnect[0];
764 anArray[1] = aConnect[3];
765 anArray[2] = aConnect[2];
766 anArray[3] = aConnect[1];
767 anArray[4] = aConnect[4];
770 for(int iNode = 0; iNode < aVNbNodes; iNode++)
771 anArray[iNode] = aConnect[iNode];
773 for(int iNode = 0; iNode < aVNbNodes; iNode++)
774 if(anArray[iNode] < 0 || aNbPoints <= anArray[iNode])
775 EXCEPTION(runtime_error,"ImportCells >> aNbPoints("<<aNbPoints<<") "<<
776 "<= anArray["<<iElem<<"]"<<
778 "("<<anArray[iNode]<<") < 0");
781 //Filling aFamily SubMesh
783 VISU::TFamilyImpl::TSubMeshOnCellType& aSubMeshOnCellType = aFamily->mySubMesh[aVTKGeomType];
784 for(int iElem = 0; iElem < aNbElem; iElem++)
785 if(aCellInfo->GetFamNum(iElem) == aFamily->myId)
786 aSubMeshOnCellType.insert(iElem);
792 }catch(std::runtime_error& exc){
793 theMeshOnEntity->myCellsConn.clear();
796 theMeshOnEntity->myCellsConn.clear();
797 EXCEPTION(runtime_error,"Unknown exception !!!");
804 VISU_MedConvertor::LoadField(const MED::PWrapper& theMed,
805 VISU::PMEDMesh theMesh,
806 VISU::PMEDMeshOnEntity theMeshOnEntity,
807 VISU::PMEDField theField,
808 VISU::PMEDValForTime theValForTime)
810 //Check on loading already done
811 if(!theValForTime->myValForCells.empty()) return 0;
814 const std::string& aMeshName = theMeshOnEntity->myMeshName;
815 const PMeshInfo& aMeshInfo = theMesh->myMeshInfo;
816 PFieldInfo aFieldInfo = theMed->GetPFieldInfo(aMeshInfo,theField->myId);
819 EEntiteMaillage aMEntity;
820 theMed->GetNbTimeStamps(aFieldInfo,theMesh->myEntityInfo,aMEntity,aTGeom);
822 PTimeStampInfo aTimeStampInfo = theMed->GetPTimeStampInfo(aFieldInfo,
825 theValForTime->myId);
826 TInt aNbGauss = aTimeStampInfo->GetNbGauss();
827 TInt aNbComp = theField->myNbComp;
829 PTimeStampVal aTimeStampVal = theMed->GetPTimeStampVal(aTimeStampInfo);
830 bool anIsTrimmed = theField->myIsTrimmed;
831 INITMSG(MYDEBUG,"LoadField - aMeshName = '"<<aMeshName<<
832 "'; aFieldName = '"<<aFieldInfo->GetName()<<
833 "'; aMEntity = "<<aMEntity<<
834 "; anId = "<<theValForTime->myId<<endl);
835 BEGMSG(MYDEBUG,"LoadField - aNbComp = "<<aNbComp<<
836 "; aNbGauss = "<<aNbGauss<<endl);
838 const MED::TGeom& anEntityTGeom = theMeshOnEntity->myGeom;
839 MED::TGeom::const_iterator aTGeomIter = anEntityTGeom.begin();
840 for(; aTGeomIter != anEntityTGeom.end(); aTGeomIter++){
841 const EGeometrieElement& aGeom = aTGeomIter->first;
842 const TInt& aNbElem = aTGeomIter->second;
844 INITMSG(MYDEBUG,"LoadField - aGeom = "<<aGeom<<"; aNbElem = '"<<aNbElem<<endl);
846 if(aTGeom.find(aGeom) == aTGeom.end()){
847 if(!theField->myIsTrimmed){
848 theField->myDataSize -= aNbElem*theField->myNbComp;
852 int aVTKGeomType = MEDGeomToVTK(aGeom);
853 VISU::TValForTimeImpl::TValForCellsWithType& anArray = theValForTime->myValForCells[aVTKGeomType];
854 anArray.resize(aNbComp*aNbElem);
855 for(TInt iElem = 0, anId = 0; iElem < aNbElem; iElem++){
856 for(TInt iComp = 0; iComp < aNbComp; iComp++, anId++){
857 for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
858 anArray[anId] += aTimeStampVal->GetVal(aGeom,iElem,iComp,iGauss);
860 anArray[anId] /= aNbGauss;
865 theField->myIsTrimmed = anIsTrimmed;