1 // Copyright (C) 2003 CEA/DEN, EDF R&D
5 // File : VISU_CorbaMedConvertor.cxx
6 // Author : Alexey PETROV
10 #include "VISU_CorbaMedConvertor.hxx"
13 #include <vtkCellType.h>
15 #define USER_INTERLACE MED_FULL_INTERLACE
18 static int MYDEBUG = 0;
20 static int MYDEBUG = 0;
22 static med_err ret = 0;
25 VISU_Convertor* CreateMEDConvertor(SALOMEDS::SObject_ptr theMedSObject) throw(std::runtime_error&){
26 return new VISU_MEDConvertor(theMedSObject);
28 VISU_Convertor* CreateMEDFieldConvertor(SALOME_MED::FIELD_ptr theField) throw(std::runtime_error&){
29 return new VISU_MEDFieldConvertor(theField);
33 typedef map<VISU::TEntity,SALOME_MED::medEntityMesh> TVisu2MedEntity;
34 static TVisu2MedEntity aVisu2MedEntity;
35 typedef map<SALOME_MED::medEntityMesh,VISU::TEntity> TMed2VisuEntity;
36 static TMed2VisuEntity aMed2VisuEntity;
38 aVisu2MedEntity[VISU::CELL_ENTITY] = SALOME_MED::MED_CELL,
39 aVisu2MedEntity[VISU::FACE_ENTITY] = SALOME_MED::MED_FACE,
40 aVisu2MedEntity[VISU::EDGE_ENTITY] = SALOME_MED::MED_EDGE,
41 aVisu2MedEntity[VISU::NODE_ENTITY] = SALOME_MED::MED_NODE,
43 aMed2VisuEntity[SALOME_MED::MED_CELL] = VISU::CELL_ENTITY,
44 aMed2VisuEntity[SALOME_MED::MED_FACE] = VISU::FACE_ENTITY,
45 aMed2VisuEntity[SALOME_MED::MED_EDGE] = VISU::EDGE_ENTITY,
46 aMed2VisuEntity[SALOME_MED::MED_NODE] = VISU::NODE_ENTITY,
50 static int CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = {
51 SALOME_MED::MED_POINT1,
54 SALOME_MED::MED_TRIA3,
55 SALOME_MED::MED_QUAD4,
56 SALOME_MED::MED_TRIA6,
57 SALOME_MED::MED_QUAD8,
58 SALOME_MED::MED_TETRA4,
59 SALOME_MED::MED_PYRA5,
60 SALOME_MED::MED_PENTA6,
61 SALOME_MED::MED_TETRA10,
62 SALOME_MED::MED_HEXA8,
63 SALOME_MED::MED_PYRA13,
64 SALOME_MED::MED_PENTA15,
65 SALOME_MED::MED_HEXA20
68 static const int VTKCELLGEOMEND = 8;
69 static int VTKCELLGEOM[VTKCELLGEOMEND] = {
70 SALOME_MED::MED_POINT1,
72 SALOME_MED::MED_TRIA3,
73 SALOME_MED::MED_QUAD4,
74 SALOME_MED::MED_TETRA4,
75 SALOME_MED::MED_PYRA5,
76 SALOME_MED::MED_PENTA6,
80 static int FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
81 SALOME_MED::MED_TRIA3,
82 SALOME_MED::MED_QUAD4,
83 SALOME_MED::MED_TRIA6,
87 static int EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
92 static int NODEGEOM[1] = {
93 SALOME_MED::MED_POINT1,
96 void GetEntity2Geom(const VISU::TEntity& theEntity, int*& theVector, int* theEnd)
97 throw (std::runtime_error&)
100 case VISU::CELL_ENTITY: theVector = CELLGEOM; *theEnd = MED_NBR_GEOMETRIE_MAILLE; break;
101 case VISU::FACE_ENTITY: theVector = FACEGEOM; *theEnd = MED_NBR_GEOMETRIE_FACE; break;
102 case VISU::EDGE_ENTITY: theVector = EDGEGEOM; *theEnd = MED_NBR_GEOMETRIE_ARETE; break;
103 case VISU::NODE_ENTITY: theVector = NODEGEOM; *theEnd = 1; break;
105 throw std::runtime_error("GetEntity2Geom >> theEntity is uncorrect !!!");
109 struct SalomeMed2vtk {
110 SALOME_MED::medGeometryElement medType;
118 #define CORBAMED2VTK(MEDTYPE,VTKTYPE,VTKNBNODES) \
119 {SALOME_MED::MEDTYPE,#MEDTYPE,getNbMedNodes(MEDTYPE),VTKTYPE,#VTKTYPE,VTKNBNODES}
120 static SalomeMed2vtk salome_med2vtk[SALOME_MED::MED_ALL_ELEMENTS] = {
121 {SALOME_MED::MED_NONE,"MED_NONE",0,VTK_EMPTY_CELL,"VTK_EMPTY_CELL",0},
122 CORBAMED2VTK(MED_POINT1,VTK_VERTEX,1),
123 CORBAMED2VTK(MED_SEG2,VTK_LINE,2),
124 CORBAMED2VTK(MED_SEG3,VTK_LINE,2),
125 CORBAMED2VTK(MED_TRIA3,VTK_TRIANGLE,3),
126 CORBAMED2VTK(MED_QUAD4,VTK_QUAD,4),
127 CORBAMED2VTK(MED_TRIA6,VTK_TRIANGLE,3),
128 CORBAMED2VTK(MED_QUAD8,VTK_QUAD,4),
129 CORBAMED2VTK(MED_TETRA4,VTK_TETRA,4),
130 CORBAMED2VTK(MED_PYRA5,VTK_PYRAMID,5),
131 CORBAMED2VTK(MED_PENTA6,VTK_WEDGE,6),
132 CORBAMED2VTK(MED_TETRA10,VTK_TETRA,4),
133 CORBAMED2VTK(MED_HEXA8,VTK_HEXAHEDRON,8),
134 CORBAMED2VTK(MED_PYRA13,VTK_PYRAMID,5),
135 CORBAMED2VTK(MED_PENTA15,VTK_WEDGE,6),
136 CORBAMED2VTK(MED_HEXA20,VTK_HEXAHEDRON,8)
140 int GetIdMEDType(int medType){
141 for(int i = 0; i < SALOME_MED::MED_ALL_ELEMENTS; i++)
142 if(salome_med2vtk[i].medType == medType) return i;
146 string GetName(SALOMEDS::SObject_ptr aSObject){
147 SALOMEDS::GenericAttribute_var anAttr;
148 if (aSObject->FindAttribute(anAttr,"AttributeName")) {
149 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
150 CORBA::String_var aString = aName->Value();
156 VISU_Convertor* VISU_MEDFieldConvertor::Build() throw (std::runtime_error&){
157 if(myField->_is_nil())
158 throw std::runtime_error("VISU_MEDFieldConvertor::Build >> myField->_is_nil() !!!");
160 SALOME_MED::SUPPORT_var aMEDSupport = myField->getSupport();
161 if(aMEDSupport->_is_nil())
162 throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDSupport->_is_nil() !!!");
163 SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
164 VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
165 SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
166 if(aMEDMesh->_is_nil())
167 throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDMesh->_is_nil() !!!");
168 CORBA::String_var aMeshName = aMEDMesh->getName();
169 CORBA::String_var aFieldName = myField->getName();
171 VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
172 aMesh.myDim = aMEDMesh->getSpaceDimension();
173 aMesh.myName = aMeshName.in();
174 VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
175 aMesh2.myMesh = aMEDMesh;
176 if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
178 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
179 aMeshOnEntity.myEntity = anEntity;
180 aMeshOnEntity.myMeshName = aMeshName.in();
181 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
182 aMeshOnEntity2.mySupport = aMEDSupport;
183 if(anEntity == VISU::NODE_ENTITY){
184 aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myEntity = VISU::CELL_ENTITY;
185 aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myMeshName = aMeshName.in();
186 aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
189 VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
190 aField.myId = myField->getOrderNumber();
191 aField.myName = aFieldName.in();
192 aField.myEntity = anEntity;
193 aField.myMeshName = aMeshName.in();
194 aField.myNbComp = myField->getNumberOfComponents();
195 aField.myCompNames.resize(aField.myNbComp);
196 aField.myUnitNames.resize(aField.myNbComp);
197 if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
198 int iTimeStamp = myField->getIterationNumber();
199 VISU::TField::TValForTime& aValForTime = aField.myValField[iTimeStamp];
200 aValForTime.myId = iTimeStamp;
201 double dt = myField->getTime();
202 aValForTime.myTime = VISU::TField::TTime(dt,"");
204 VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
205 VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[iTimeStamp];
206 aValForTime2.myField = myField;
208 MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<<aFieldName<<"'; myId = "<<aField.myId<<"; myTime = "<<dt);
212 VISU_Convertor* VISU_MEDConvertor::Build() throw (std::runtime_error&){
213 if(mySObject->_is_nil())
214 throw std::runtime_error("VISU_MEDConvertor::Build >> mySObject->_is_nil() !!!");
215 SALOMEDS::Study_var aStudy = mySObject->GetStudy();
217 CORBA::Object_var aMedObject = SObjectToObject(mySObject);
218 if(!CORBA::is_nil(aMedObject)){
219 SALOME_MED::MED_var aMED = SALOME_MED::MED::_narrow(aMedObject);
220 if(!aMED->_is_nil()){
221 CORBA::Short aTag = mySObject->Tag();
222 SALOMEDS::SObject_var aMedCompSObj = mySObject->GetFather();
223 SALOMEDS::SObject_var aMeshSObj;
224 CORBA::Boolean aBool = aMedCompSObj->FindSubObject(aTag+1,aMeshSObj);
225 if(!aBool) throw std::runtime_error("VISU_MEDConvertor::Build >> Cann't find MEDMESH label !!!");
226 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDMESH found.");
227 SALOMEDS::ChildIterator_var aMeshIterator = aStudy->NewChildIterator(aMeshSObj);
228 for(; aMeshIterator->More(); aMeshIterator->Next()){
229 aMeshSObj = aMeshIterator->Value();
230 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshSObj = '"<<::GetName(aMeshSObj)<<"'");
231 CORBA::Object_var aMedMesh = SObjectToObject(aMeshSObj);
232 if(CORBA::is_nil(aMedMesh)) continue;
233 SALOME_MED::MESH_var aMEDMesh = SALOME_MED::MESH::_narrow(aMedMesh);
234 if(aMEDMesh->_is_nil()) continue;
235 CORBA::String_var aMeshName = aMEDMesh->getName();
236 VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
237 aMesh.myDim = aMEDMesh->getSpaceDimension();
238 aMesh.myName = aMeshName.in();
239 VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
240 aMesh2.myMesh = aMEDMesh;
241 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
242 SALOMEDS::ChildIterator_var aSupportIterator = aStudy->NewChildIterator(aMeshSObj);
243 for(; aSupportIterator->More(); aSupportIterator->Next()){
244 SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
245 CORBA::Object_var aMedSupport = SObjectToObject(aSupportSObj);
246 if(CORBA::is_nil(aMedSupport)) continue;
247 SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport);
248 if(aMEDSupport->_is_nil()) continue;
249 SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
250 VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
251 CORBA::String_var aSupportName = aMEDSupport->getName();
252 bool isDataPresent = false;
253 if(aMEDSupport->isOnAllElements()){
254 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - Support isOnAllElements = '"<<aSupportName<<"' anEntity = "<<anEntity);
255 //Check, if there is any data on the support?
256 SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
257 if(anEntity == VISU::NODE_ENTITY){
258 if(aMeshOnSupport->getNumberOfNodes() > 0)
259 isDataPresent = true;
262 int* aGeomElemVector;
263 GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
264 const SALOME_MED::medEntityMesh& aMedEntity = aVisu2MedEntity[anEntity];
265 for (int iGeomElem = 0, aCounter = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
266 int medId = GetIdMEDType(aGeomElemVector[iGeomElem]);
267 SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
268 med_int iNumElemEnd = aMeshOnSupport->getNumberOfElements(aMedEntity,aMedType);
269 if(iNumElemEnd > 0) {
270 isDataPresent = true;
275 if(!isDataPresent) continue;
276 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
277 aMeshOnEntity.myEntity = anEntity;
278 aMeshOnEntity.myMeshName = aMeshName.in();
279 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
280 aMeshOnEntity2.mySupport = aMEDSupport;
282 SALOME_MED::FAMILY_var aMEDFamily = SALOME_MED::FAMILY::_narrow(aMedSupport);
283 if(!aMEDFamily->_is_nil()) {
284 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFamily = '"<<aSupportName<<"' anEntity = "<<anEntity);
285 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
286 VISU::TFamily& aFamily = aMeshOnEntity.myFamilyMap[aSupportName.in()];
287 aFamily.myName = aSupportName.in();
288 aFamily.myEntity = anEntity;
289 aFamily.myId = aMEDFamily->getIdentifier();
290 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
291 VISUMED::TFamily& aFamily2 = aMeshOnEntity2.myFamilyMap[aSupportName.in()];
292 aFamily2.myFamily = aMEDFamily;
294 SALOME_MED::GROUP_var aMEDGroup = SALOME_MED::GROUP::_narrow(aMedSupport);
295 if(!aMEDGroup->_is_nil()) {
296 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup = '"<<aSupportName<<"' anEntity = "<<anEntity);
297 VISUMED::TGroupMap& aGroupMap2 = aMesh2.myGroupMap;
298 VISUMED::TGroup& aGroup2 = aGroupMap2[aSupportName.in()];
299 aGroup2.myGroup = aMEDGroup;
300 //VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
301 //VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
302 //VISU::TGroup& aGroup = aGroupMap[aSupportName.in()];
303 //aGroup.myName = aSupportName.in();
304 //aGroup.myMeshName = aMesh.myName;
305 SALOME_MED::Family_array_var aFamilies = aMEDGroup->getFamilies();
306 int iFamilyEnd = aFamilies->length();
307 for(int iFamaily = 0; iFamaily < iFamilyEnd; iFamaily++){
308 aMEDFamily = aFamilies[iFamaily];
309 CORBA::String_var aFamilyName = aMEDFamily->getName();
310 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
311 VISU::TFamily& aFamily = aMeshOnEntity.myFamilyMap[aFamilyName.in()];
312 VISU::TBindGroups& aBindGroups = aFamily.myGroups;
313 aBindGroups.insert(aSupportName.in());
318 //Correction of TMesh.TGroupMap
319 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
320 if(aMeshOnEntityMap.empty()) continue;
321 VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
322 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
323 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
324 const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
325 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap;
326 if(aFamilyMap.empty()) continue;
327 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
328 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
329 const VISU::TFamily& aFamily = aFamilyMapIter->second;
330 const VISU::TBindGroups& aBindGroups = aFamily.myGroups;
331 if(aBindGroups.empty()) continue;
332 VISU::TBindGroups::const_iterator aBindGroupsIter = aBindGroups.begin();
333 for(; aBindGroupsIter != aBindGroups.end(); aBindGroupsIter++){
334 const string& aGroupName = *aBindGroupsIter;
335 VISU::TGroup& aGroup = aGroupMap[aGroupName];
336 aGroup.myName = aGroupName;
337 aGroup.myMeshName = aMesh.myName;
338 VISU::TFamilyAndEntity aFamilyAndEntity(aFamily.myName,aFamily.myEntity);
339 aGroup.myFamilyAndEntitySet.insert(aFamilyAndEntity);
344 SALOMEDS::SObject_var aFieldSObj;
345 aBool = aMedCompSObj->FindSubObject(aTag+2,aFieldSObj);
347 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDFIELD found.");
348 SALOMEDS::ChildIterator_var aFieldIterator = aStudy->NewChildIterator(aFieldSObj);
349 for(int iField = 0; aFieldIterator->More(); aFieldIterator->Next(), iField++){
350 aFieldSObj = aFieldIterator->Value();
351 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<<::GetName(aFieldSObj)<<"'");
352 SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(aFieldSObj);
353 for(; aTimeStampIterator->More(); aTimeStampIterator->Next()){
354 SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
355 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<::GetName(aTimeStampSObj)<<"'");
356 CORBA::Object_var aMedField = SObjectToObject(aTimeStampSObj);
357 if(CORBA::is_nil(aMedField)) continue;
358 SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
359 if(aMEDField->_is_nil()) continue;
360 SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
361 if(aMEDSupport->_is_nil()) continue;
362 SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
363 VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
364 SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
365 if(aMEDMesh->_is_nil()) continue;
366 CORBA::String_var aMeshName = aMEDMesh->getName();
367 CORBA::String_var aFieldName = aMEDField->getName();
369 VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
370 aMesh.myDim = aMEDMesh->getSpaceDimension();
371 aMesh.myName = aMeshName.in();
372 VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
373 aMesh2.myMesh = aMEDMesh;
375 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
376 aMeshOnEntity.myEntity = anEntity;
377 aMeshOnEntity.myMeshName = aMeshName.in();
378 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
379 aMeshOnEntity2.mySupport = aMEDSupport;
380 if(anEntity == VISU::NODE_ENTITY){
381 aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myEntity = VISU::CELL_ENTITY;
382 aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myMeshName = aMeshName.in();
383 aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
386 VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
387 aField.myId = iField;
388 aField.myName = aFieldName.in();
389 aField.myEntity = anEntity;
390 aField.myMeshName = aMeshName.in();
391 aField.myNbComp = aMEDField->getNumberOfComponents();
392 aField.myCompNames.resize(aField.myNbComp);
393 aField.myUnitNames.resize(aField.myNbComp);
394 //int iTimeStamp = aMEDField->getOrderNumber();
395 int iTimeStamp = aMEDField->getIterationNumber();
396 VISU::TField::TValForTime& aValForTime = aField.myValField[iTimeStamp];
397 aValForTime.myId = iTimeStamp;
398 double dt = aMEDField->getTime();
399 aValForTime.myTime = VISU::TField::TTime(dt,"");
401 VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
402 VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[iTimeStamp];
403 aValForTime2.myField = aMEDField;
405 MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<"'; myEntity = "<<anEntity<<"; myTime = "<<dt);
413 SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(mySObject);
414 for(; aTimeStampIterator->More(); aTimeStampIterator->Next()){
415 SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
416 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<::GetName(aTimeStampSObj)<<"'");
417 CORBA::Object_var aMedField = SObjectToObject(aTimeStampSObj);
418 if(CORBA::is_nil(aMedField)) continue;
419 SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
420 if(aMEDField->_is_nil()) continue;
421 SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
422 if(aMEDSupport->_is_nil()) continue;
423 SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
424 VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
425 SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
426 if(aMEDMesh->_is_nil()) continue;
427 CORBA::String_var aMeshName = aMEDMesh->getName();
428 CORBA::String_var aFieldName = aMEDField->getName();
430 VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
431 aMesh.myDim = aMEDMesh->getSpaceDimension();
432 aMesh.myName = aMeshName.in();
433 VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
434 aMesh2.myMesh = aMEDMesh;
435 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
437 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
438 aMeshOnEntity.myEntity = anEntity;
439 aMeshOnEntity.myMeshName = aMeshName.in();
440 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
441 aMeshOnEntity2.mySupport = aMEDSupport;
442 if(anEntity == VISU::NODE_ENTITY){
443 aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myEntity = VISU::CELL_ENTITY;
444 aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myMeshName = aMeshName.in();
445 aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
448 VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
449 CORBA::Short iField = mySObject->Tag();
450 aField.myId = iField;
451 aField.myName = aFieldName.in();
452 aField.myEntity = anEntity;
453 aField.myMeshName = aMeshName.in();
454 aField.myNbComp = aMEDField->getNumberOfComponents();
455 aField.myCompNames.resize(aField.myNbComp);
456 aField.myUnitNames.resize(aField.myNbComp);
457 //int iTimeStamp = aMEDField->getOrderNumber();
458 int iTimeStamp = aMEDField->getIterationNumber();
459 VISU::TField::TValForTime& aValForTime = aField.myValField[iTimeStamp];
460 aValForTime.myId = iTimeStamp;
461 double dt = aMEDField->getTime();
462 aValForTime.myTime = VISU::TField::TTime(dt,"");
464 VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
465 VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[iTimeStamp];
466 aValForTime2.myField = aMEDField;
468 MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<"'; myEntity = "<<anEntity<<"; myTime = "<<dt);
473 int VISU_MEDConvertor::LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity,
474 const string& theFamilyName)
475 throw (std::runtime_error&)
478 const string& aMeshName = theMeshOnEntity.myMeshName;
479 const VISU::TEntity& anEntity = theMeshOnEntity.myEntity;
480 VISU::TMesh& aMesh = myMeshMap[aMeshName];
482 if(anEntity == VISU::NODE_ENTITY)
483 isPointsUpdated = LoadPoints(aMesh,theFamilyName);
485 isPointsUpdated = LoadPoints(aMesh);
486 int isCellsOnEntityUpdated = LoadCellsOnEntity(theMeshOnEntity,theFamilyName);
488 return (isPointsUpdated || isCellsOnEntityUpdated);
491 int VISU_MEDConvertor::LoadMeshOnGroup(VISU::TMesh& theMesh,
492 const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
493 throw (std::runtime_error&)
496 int isPointsUpdated = 0;
497 int isCellsOnEntityUpdated = 0;
498 VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
499 for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
500 const string& aFamilyName = aFamilyAndEntitySetIter->first;
501 const VISU::TEntity& anEntity = aFamilyAndEntitySetIter->second;
502 VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[anEntity];
503 if(anEntity == VISU::NODE_ENTITY){
504 isPointsUpdated += LoadPoints(theMesh,aFamilyName);
505 isCellsOnEntityUpdated += LoadCellsOnEntity(aMeshOnEntity);
507 isPointsUpdated += LoadPoints(theMesh);
508 isCellsOnEntityUpdated += LoadCellsOnEntity(aMeshOnEntity,aFamilyName);
512 return (isPointsUpdated || isCellsOnEntityUpdated);
515 int VISU_MEDConvertor::LoadFieldOnMesh(VISU::TMesh& theMesh,
516 VISU::TMeshOnEntity& theMeshOnEntity,
517 VISU::TField& theField,
518 VISU::TField::TValForTime& theValForTime)
519 throw (std::runtime_error&)
522 int isPointsUpdated = LoadPoints(theMesh);
523 int isCellsOnEntityUpdated = LoadCellsOnEntity(theMeshOnEntity);
524 int isFieldUpdated = LoadField(theMeshOnEntity,theField,theValForTime);
526 return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated);
529 int VISU_MEDConvertor::LoadPoints(VISU::TMesh& theMesh, const string& theFamilyName)
530 throw (std::runtime_error&)
532 //Check on existing family
533 VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[VISU::NODE_ENTITY];
534 aMeshOnEntity.myEntity = VISU::NODE_ENTITY;
535 aMeshOnEntity.myMeshName = theMesh.myName;
536 VISU::TFamily* pFamily = VISU::GetFamily(aMeshOnEntity,theFamilyName);
537 bool isFamilyPresent = (pFamily != NULL);
538 VISU::TFamily& aFamily = *pFamily;
539 //Check on loading already done
540 bool isPointsLoaded = !theMesh.myPointsCoord.empty();
542 if(!isFamilyPresent) return 0;
543 else if(!aFamily.mySubMesh.empty()) return 0;
544 VISUMED::TMesh& aMesh2 = myMeshMap2[theMesh.myName];
545 SALOME_MED::MESH_var& aMedMesh = aMesh2.myMesh;
546 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[VISU::NODE_ENTITY];
548 MESSAGE("LoadPoints - isPointsLoaded = "<<isPointsLoaded<<"; theFamilyName = '"<<theFamilyName<<"'");
549 theMesh.myDim = aMedMesh->getSpaceDimension();
550 int iNumElemEnd = aMedMesh->getNumberOfNodes();
551 VISU::TMesh::TPointsCoord& aPointsCoord = theMesh.myPointsCoord;
552 if(MYDEBUG) MESSAGE("LoadPoints - iNumElemEnd = "<<iNumElemEnd);
553 if (iNumElemEnd <= 0) throw std::runtime_error("LoadPoints >> There is no points in the mesh !!!");
554 aPointsCoord.resize(theMesh.myDim*iNumElemEnd,0.0);
555 Engines::double_array_var coord = aMedMesh->getCoordinates(SALOME_MED::MED_FULL_INTERLACE);
557 for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
558 for(int iDim = 0, iNumElem2Dim = iNumElem*theMesh.myDim; iDim < theMesh.myDim; iDim++, iNumElem2Dim++)
559 aPointsCoord[iNumElem2Dim] = coord[iNumElem2Dim];
560 if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY");
561 VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = aMeshOnEntity.myCellsConn[VTK_VERTEX];
562 aConnForCellType.resize(iNumElemEnd);
563 for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
564 aConnForCellType[iNumElem] = VISU::TMeshOnEntity::TConnect(1,iNumElem);
567 if(MYDEBUG) MESSAGE("LoadPoints - Filling aFamily SubMesh");
568 VISUMED::TFamily aFamily2 = aMeshOnEntity2.myFamilyMap[aFamily.myName];
569 SALOME_MED::FAMILY_var aMedFamily = aFamily2.myFamily;
570 VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[VTK_VERTEX];
571 SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes();
572 Engines::long_array_var aCellNumForType = aMedFamily->getNumber(aGeom[0]);
573 int iNumElemEndTmp = iNumElemEnd;
574 iNumElemEnd = aCellNumForType->length();
575 for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
576 int tmp = aCellNumForType[iNumElem]-1;
577 if(0 > tmp || tmp >= iNumElemEndTmp) {
578 static QString aString;
579 aString.sprintf("LoadPoints >> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEnd,iNumElem,tmp);
580 throw std::runtime_error(aString.latin1());
582 aSubMeshOnCellType.insert(tmp);
588 int VISU_MEDConvertor::LoadCellsOnEntity(VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName)
589 throw (std::runtime_error&)
591 //Check on existing family
592 VISU::TFamily* pFamily = VISU::GetFamily(theMeshOnEntity,theFamilyName);
593 bool isFamilyPresent = (pFamily != NULL);
594 VISU::TFamily& aFamily = *pFamily;
595 //Check on loading already done
596 bool isCellsLoaded = !theMeshOnEntity.myCellsConn.empty();
598 if(!isFamilyPresent) return 0;
599 else if(!aFamily.mySubMesh.empty()) return 0;
600 VISUMED::TMesh& aMesh2 = myMeshMap2[theMeshOnEntity.myMeshName];
601 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[theMeshOnEntity.myEntity];
602 SALOME_MED::SUPPORT_var& aMedSupport = aMeshOnEntity2.mySupport;
603 SALOME_MED::MESH_var aMedMesh = aMedSupport->getMesh();
605 MESSAGE("LoadCellsOnEntity - theFamilyName = '"<<theFamilyName<<"'");
606 MESSAGE("LoadCellsOnEntity - isCellsLoaded = "<<isCellsLoaded<<"; isFamilyPresent = "<<isFamilyPresent);
610 int* aGeomElemVector;
611 const VISU::TEntity& anEntity = theMeshOnEntity.myEntity;
612 GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
613 const SALOME_MED::medEntityMesh& aMedEntity = aVisu2MedEntity[anEntity];
614 VISU::TMesh &aMesh = myMeshMap[theMeshOnEntity.myMeshName];
615 int aNbPoints = aMesh.myPointsCoord.size()/aMesh.myDim;
617 for (int iGeomElem = 0, aCounter = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
618 int medId = GetIdMEDType(aGeomElemVector[iGeomElem]);
619 int nbMedNodes = salome_med2vtk[medId].medNbNodes;
620 int nbVtkNodes = salome_med2vtk[medId].vtkNbNodes;
621 int aVtkType = salome_med2vtk[medId].vtkType;
622 SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
623 med_int iNumElemEnd = aMedMesh->getNumberOfElements(aMedEntity,aMedType);
624 if (iNumElemEnd > 0) {
625 Engines::long_array_var conn =
626 aMedMesh->getConnectivity(SALOME_MED::MED_FULL_INTERLACE,SALOME_MED::MED_NODAL,aMedEntity,aMedType);
627 VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = theMeshOnEntity.myCellsConn[aVtkType];
628 //APO - aConnForCellType.resize(iNumElemEnd);
629 valarray<med_int> aConnect(nbMedNodes);
630 int aNbConnForElem = conn->length()/iNumElemEnd;
631 if(MYDEBUG) MESSAGE("LoadCellsOnEntity - medName = "<<salome_med2vtk[medId].medName<<
632 "; iNumElemEnd = "<<iNumElemEnd<<"; aNbConnForElem = "<<aNbConnForElem);
633 for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
634 //APO - VISU::TMeshOnEntity::TConnect& anArray = aConnForCellType[iNumElem];
635 //APO - anArray.resize(nbVtkNodes);
636 VISU::TMeshOnEntity::TConnect anArray(nbVtkNodes);
637 for (int k = 0, kj = iNumElem*aNbConnForElem; k < nbMedNodes; k++) {
638 aConnect[k] = conn[kj+k] - 1;
641 case SALOME_MED::MED_TETRA4 :
642 case SALOME_MED::MED_TETRA10 :
643 anArray[0] = aConnect[0];
644 anArray[1] = aConnect[1];
645 anArray[2] = aConnect[3];
646 anArray[3] = aConnect[2];
648 case SALOME_MED::MED_PYRA5 :
649 case SALOME_MED::MED_PYRA13 :
650 anArray[0] = aConnect[0];
651 anArray[1] = aConnect[3];
652 anArray[2] = aConnect[2];
653 anArray[3] = aConnect[1];
654 anArray[4] = aConnect[4];
657 for (int k = 0; k < nbVtkNodes; k++)
658 anArray[k] = aConnect[k];
660 for (int k = 0; k < nbVtkNodes; k++)
661 if(anArray[k] < 0 || aNbPoints <= anArray[k]){
662 static QString aString;
663 aString.sprintf("ImportCells >> aNbPoints(%d) <= anArray[%d][%d]=%d < 0 !!!",aNbPoints,iNumElem,k,anArray[k]);
664 throw std::runtime_error(aString.latin1());
666 aConnForCellType.push_back(anArray);
668 //Workaround for MED Component data structure
669 int aSize = aConnForCellType.size();
670 aMeshOnEntity2.myCellsFirstIndex[aMedType] = VISUMED::TMeshOnEntity::TIndexAndSize(aCounter,aSize);
675 //Filling aFamily SubMesh
677 VISUMED::TFamily aFamily2 = aMeshOnEntity2.myFamilyMap[aFamily.myName];
678 SALOME_MED::FAMILY_var aMedFamily = aFamily2.myFamily;
679 SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes();
680 iGeomElemEnd = aGeom->length();
681 if(MYDEBUG) MESSAGE("LoadCellsOnEntity - iGeomElemEnd = "<<iGeomElemEnd);
682 for (int iGeomElem = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
683 SALOME_MED::medGeometryElement aGeomType = aGeom[iGeomElem];
684 Engines::long_array_var aCellNumForType = aMedFamily->getNumber(aGeomType);
685 int medId = GetIdMEDType(aGeomType);
686 int aVtkType = salome_med2vtk[medId].vtkType;
687 SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
688 VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[aVtkType];
689 med_int iNumElemEndTmp = theMeshOnEntity.myCellsConn[aVtkType].size();
690 med_int iNumElemEnd = aCellNumForType->length();
691 int aCounter = aMeshOnEntity2.myCellsFirstIndex[aMedType].first;
693 MESSAGE("LoadCellsOnEntity - medName = "<<salome_med2vtk[medId].medName<<
694 "; iNumElemEnd = "<<iNumElemEnd<<"; aCounter = "<<aCounter);
695 for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) {
696 int tmp = aCellNumForType[iNumElem]-aCounter-1;
697 if(0 > tmp || tmp >= iNumElemEndTmp) {
698 static QString aString;
699 aString.sprintf("LoadCellsOnEntity >> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEndTmp,iNumElem,tmp);
700 throw std::runtime_error(aString.latin1());
702 aSubMeshOnCellType.insert(tmp);
709 template<class TArray> int ImportField(TArray& theArray,
710 const VISU::TMesh& theMesh,
711 const VISU::TField& theField,
712 VISU::TField::TValForTime& theValForTime,
713 const VISU::TMeshOnEntity& theMeshOnEntity,
714 const VISUMED::TMeshOnEntity& theMeshOnEntity2)
716 if(theField.myEntity == VISU::NODE_ENTITY){
717 VISU::TField::TValForCellsWithType& aValForCellsWithType = theValForTime.myValForCells[VTK_VERTEX];
718 int iNumElemEnd = theMesh.myPointsCoord.size()/theMesh.myDim*theField.myNbComp;
719 if(MYDEBUG) MESSAGE("ImportField - iNumElemEnd = "<<iNumElemEnd);
720 aValForCellsWithType.resize(iNumElemEnd);
721 for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
722 aValForCellsWithType[iNumElem] = theArray[iNumElem];
725 int* aGeomElemVector;
726 const VISU::TEntity& anEntity = theField.myEntity;
727 GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
728 for (int iGeomElem = 0, aCounter = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
729 int medId = GetIdMEDType(aGeomElemVector[iGeomElem]);
730 int aVtkType = salome_med2vtk[medId].vtkType;
731 SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
732 const VISUMED::TMeshOnEntity::TCellsFirstIndex& aCellsFirstIndex = theMeshOnEntity2.myCellsFirstIndex;
733 VISUMED::TMeshOnEntity::TCellsFirstIndex::const_iterator aCellsFirstIndexIter = aCellsFirstIndex.find(aMedType);
734 if(aCellsFirstIndexIter != aCellsFirstIndex.end()){
735 const VISU::TMeshOnEntity::TCellsConn& aCellsConn = theMeshOnEntity.myCellsConn;
736 VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.find(aVtkType);
737 const VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = aCellsConnIter->second;
738 const VISUMED::TMeshOnEntity::TIndexAndSize& aIndexAndSize = aCellsFirstIndexIter->second;
739 int iNumElemEnd = aIndexAndSize.second;
741 MESSAGE("ImportField - medName = "<<salome_med2vtk[medId].medName<<
742 "; aIndexAndSize = {"<<aIndexAndSize.first<<","<<aIndexAndSize.second<<"}");
743 VISU::TField::TValForCellsWithType& aValForCellsWithType = theValForTime.myValForCells[aVtkType];
744 aValForCellsWithType.resize(iNumElemEnd*theField.myNbComp);
745 for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++)
746 for (int k = 0, kj = iNumElem*theField.myNbComp; k < theField.myNbComp; k++)
747 aValForCellsWithType[kj+k] = theArray[aIndexAndSize.first*theField.myNbComp+kj+k];
754 int VISU_MEDConvertor::LoadField(const VISU::TMeshOnEntity& theMeshOnEntity,
755 const VISU::TField& theField, VISU::TField::TValForTime& theValForTime)
756 throw (std::runtime_error&)
758 //Check on loading already done
759 if(!theValForTime.myValForCells.empty()) return 0;
760 VISU::TMesh& aMesh = myMeshMap[theMeshOnEntity.myMeshName];
761 VISUMED::TMesh& aMesh2 = myMeshMap2[theMeshOnEntity.myMeshName];
762 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[theMeshOnEntity.myEntity];
763 VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[theField.myName];
764 VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[theValForTime.myId];
765 SALOME_MED::FIELD_var aMEDField = aValForTime2.myField;
767 SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(aMEDField);
768 if(!aFieldDouble->_is_nil()){
769 Engines::double_array_var anArray = aFieldDouble->getValue(SALOME_MED::MED_FULL_INTERLACE);
770 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDDOUBLE = "<<anArray->length());
771 ::ImportField(anArray,aMesh,theField,theValForTime,theMeshOnEntity,aMeshOnEntity2);
773 SALOME_MED::FIELDINT_ptr aFieldInt = SALOME_MED::FIELDINT::_narrow(aMEDField);
774 if(!aFieldInt->_is_nil()){
775 Engines::long_array_var anArray = aFieldInt->getValue(SALOME_MED::MED_FULL_INTERLACE);
776 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDINT = "<<anArray->length());
777 ::ImportField(anArray,aMesh,theField,theValForTime,theMeshOnEntity,aMeshOnEntity2);