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;
36 aVisu2MedEntity[VISU::CELL_ENTITY] = SALOME_MED::MED_CELL,
37 aVisu2MedEntity[VISU::FACE_ENTITY] = SALOME_MED::MED_FACE,
38 aVisu2MedEntity[VISU::EDGE_ENTITY] = SALOME_MED::MED_EDGE,
39 aVisu2MedEntity[VISU::NODE_ENTITY] = SALOME_MED::MED_NODE,
42 static int CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = {
43 SALOME_MED::MED_POINT1,
46 SALOME_MED::MED_TRIA3,
47 SALOME_MED::MED_QUAD4,
48 SALOME_MED::MED_TRIA6,
49 SALOME_MED::MED_QUAD8,
50 SALOME_MED::MED_TETRA4,
51 SALOME_MED::MED_PYRA5,
52 SALOME_MED::MED_PENTA6,
53 SALOME_MED::MED_TETRA10,
54 SALOME_MED::MED_HEXA8,
55 SALOME_MED::MED_PYRA13,
56 SALOME_MED::MED_PENTA15,
57 SALOME_MED::MED_HEXA20
60 static const int VTKCELLGEOMEND = 8;
61 static int VTKCELLGEOM[VTKCELLGEOMEND] = {
62 SALOME_MED::MED_POINT1,
64 SALOME_MED::MED_TRIA3,
65 SALOME_MED::MED_QUAD4,
66 SALOME_MED::MED_TETRA4,
67 SALOME_MED::MED_PYRA5,
68 SALOME_MED::MED_PENTA6,
72 static int FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
73 SALOME_MED::MED_TRIA3,
74 SALOME_MED::MED_QUAD4,
75 SALOME_MED::MED_TRIA6,
79 static int EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
84 static int NODEGEOM[1] = {
85 SALOME_MED::MED_POINT1,
88 void Entity2Geom(const VISU::TEntity& theEntity, int* theVector, int* theEnd) {
90 case VISU::CELL_ENTITY: theVector = CELLGEOM; *theEnd = MED_NBR_GEOMETRIE_MAILLE; break;
91 case VISU::FACE_ENTITY: theVector = FACEGEOM; *theEnd = MED_NBR_GEOMETRIE_FACE; break;
92 case VISU::EDGE_ENTITY: theVector = EDGEGEOM; *theEnd = MED_NBR_GEOMETRIE_ARETE; break;
93 case VISU::NODE_ENTITY: theVector = NODEGEOM; *theEnd = 1; break;
97 typedef pair<int*,int> TEntity2Geom;
98 typedef map<SALOME_MED::medEntityMesh,TEntity2Geom> TEntity2GeomMap;
99 static TEntity2GeomMap anEntity2GeomMap;
101 anEntity2GeomMap[SALOME_MED::MED_CELL] = TEntity2Geom(CELLGEOM,MED_NBR_GEOMETRIE_MAILLE),
102 anEntity2GeomMap[SALOME_MED::MED_FACE] = TEntity2Geom(FACEGEOM,MED_NBR_GEOMETRIE_FACE),
103 anEntity2GeomMap[SALOME_MED::MED_EDGE] = TEntity2Geom(EDGEGEOM,MED_NBR_GEOMETRIE_ARETE),
104 anEntity2GeomMap[SALOME_MED::MED_NODE] = TEntity2Geom(NODEGEOM,1),
108 struct SalomeMed2vtk {
109 SALOME_MED::medGeometryElement medType;
117 #define CORBAMED2VTK(MEDTYPE,VTKTYPE,VTKNBNODES) \
118 {SALOME_MED::MEDTYPE,#MEDTYPE,getNbMedNodes(MEDTYPE),VTKTYPE,#VTKTYPE,VTKNBNODES}
119 static SalomeMed2vtk salome_med2vtk[SALOME_MED::MED_ALL_ELEMENTS] = {
120 {SALOME_MED::MED_NONE,"MED_NONE",0,VTK_EMPTY_CELL,"VTK_EMPTY_CELL",0},
121 CORBAMED2VTK(MED_POINT1,VTK_VERTEX,1),
122 CORBAMED2VTK(MED_SEG2,VTK_LINE,2),
123 CORBAMED2VTK(MED_SEG3,VTK_LINE,2),
124 CORBAMED2VTK(MED_TRIA3,VTK_TRIANGLE,3),
125 CORBAMED2VTK(MED_QUAD4,VTK_QUAD,4),
126 CORBAMED2VTK(MED_TRIA6,VTK_TRIANGLE,3),
127 CORBAMED2VTK(MED_QUAD8,VTK_QUAD,4),
128 CORBAMED2VTK(MED_TETRA4,VTK_TETRA,4),
129 CORBAMED2VTK(MED_PYRA5,VTK_PYRAMID,5),
130 CORBAMED2VTK(MED_PENTA6,VTK_WEDGE,6),
131 CORBAMED2VTK(MED_TETRA10,VTK_TETRA,4),
132 CORBAMED2VTK(MED_HEXA8,VTK_HEXAHEDRON,8),
133 CORBAMED2VTK(MED_PYRA13,VTK_PYRAMID,5),
134 CORBAMED2VTK(MED_PENTA15,VTK_WEDGE,6),
135 CORBAMED2VTK(MED_HEXA20,VTK_HEXAHEDRON,8)
139 int FindIdMEDType(int medType){
140 for(int i = 0; i < SALOME_MED::MED_ALL_ELEMENTS; i++)
141 if(salome_med2vtk[i].medType == medType) return i;
145 void VISU_MedMeshConvertor::SetMedMesh(SALOME_MED::MESH_ptr theMedMesh) {
146 myMedMesh = SALOME_MED::MESH::_duplicate(theMedMesh);
149 VISU_Convertor* VISU_MEDFieldConvertor::Build() throw (std::runtime_error&){
150 if(myField->_is_nil())
151 throw std::runtime_error("VISU_MEDFieldConvertor::Build >> myField->_is_nil() !!!");
153 SALOME_MED::SUPPORT_var aMEDSupport = myField->getSupport();
154 if(aMEDSupport->_is_nil())
155 throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDSupport->_is_nil() !!!");
156 SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
157 VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
158 SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
159 if(aMEDMesh->_is_nil())
160 throw std::runtime_error("VISU_MEDFieldConvertor::Build >> aMEDMesh->_is_nil() !!!");
161 CORBA::String_var aMeshName = aMEDMesh->getName();
162 CORBA::String_var aFieldName = myField->getName();
164 VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
165 aMesh.myDim = aMEDMesh->getSpaceDimension();
166 aMesh.myName = aMeshName.in();
167 VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
168 aMesh2.myMesh = aMEDMesh;
169 if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
171 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
172 aMeshOnEntity.myEntity = anEntity;
173 aMeshOnEntity.myMeshName = aMeshName.in();
174 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
175 aMeshOnEntity2.mySupport = aMEDSupport;
176 if(anEntity == VISU::NODE_ENTITY){
177 aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myEntity = VISU::CELL_ENTITY;
178 aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myMeshName = aMeshName.in();
179 aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
182 VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
183 aField.myId = myField->getOrderNumber();
184 aField.myName = aFieldName.in();
185 aField.myEntity = anEntity;
186 aField.myMeshName = aMeshName.in();
187 aField.myNbComp = myField->getNumberOfComponents();
188 aField.myCompNames.resize(aField.myNbComp);
189 aField.myUnitNames.resize(aField.myNbComp);
190 if(MYDEBUG) MESSAGE("VISU_MEDFieldConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
191 int iTimeStamp = myField->getIterationNumber();
192 VISU::TField::TValForTime& aValForTime = aField.myValField[iTimeStamp];
193 aValForTime.myId = iTimeStamp;
194 double dt = myField->getTime();
195 aValForTime.myTime = VISU::TField::TTime(dt,"");
197 VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
198 VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[iTimeStamp];
199 aValForTime2.myField = myField;
201 MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<<aFieldName<<"'; myId = "<<aField.myId<<"; myTime = "<<dt);
205 VISU_Convertor* VISU_MEDConvertor::Build() throw (std::runtime_error&){
206 if(mySObject->_is_nil())
207 throw std::runtime_error("VISU_MEDConvertor::Build >> mySObject->_is_nil() !!!");
208 SALOMEDS::Study_var aStudy = mySObject->GetStudy();
210 CORBA::Object_var aMedObject = SObjectToObject(mySObject);
211 if(!CORBA::is_nil(aMedObject)){
212 SALOME_MED::MED_var aMED = SALOME_MED::MED::_narrow(aMedObject);
213 if(!aMED->_is_nil()){
214 CORBA::Short aTag = mySObject->Tag();
215 SALOMEDS::SObject_var aMedCompSObj = mySObject->GetFather();
216 SALOMEDS::SObject_var aMeshSObj;
217 CORBA::Boolean aBool = aMedCompSObj->FindSubObject(aTag+1,aMeshSObj);
218 if(!aBool) throw std::runtime_error("VISU_MEDConvertor::Build >> Cann't find MEDMESH label !!!");
219 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDMESH found.");
220 SALOMEDS::ChildIterator_var aMeshIterator = aStudy->NewChildIterator(aMeshSObj);
221 for(; aMeshIterator->More(); aMeshIterator->Next()){
222 aMeshSObj = aMeshIterator->Value();
223 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshSObj = '"<<::GetName(aMeshSObj)<<"'");
224 CORBA::Object_var aMedMesh = SObjectToObject(aMeshSObj);
225 if(CORBA::is_nil(aMedMesh)) continue;
226 SALOME_MED::MESH_var aMEDMesh = SALOME_MED::MESH::_narrow(aMedMesh);
227 if(aMEDMesh->_is_nil()) continue;
228 CORBA::String_var aMeshName = aMEDMesh->getName();
229 VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
230 aMesh.myDim = aMEDMesh->getSpaceDimension();
231 aMesh.myName = aMeshName.in();
232 VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
233 aMesh2.myMesh = aMEDMesh;
234 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
235 SALOMEDS::ChildIterator_var aSupportIterator = aStudy->NewChildIterator(aMeshSObj);
236 for(; aSupportIterator->More(); aSupportIterator->Next()){
237 SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value();
238 CORBA::Object_var aMedSupport = SObjectToObject(aSupportSObj);
239 if(CORBA::is_nil(aMedSupport)) continue;
240 SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport);
241 if(aMEDSupport->_is_nil()) continue;
242 SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
243 VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
244 CORBA::String_var aSupportName = aMEDSupport->getName();
245 bool isDataPresent = false;
246 if(aMEDSupport->isOnAllElements()){
247 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - Support isOnAllElements = '"<<aSupportName<<"' anEntity = "<<anEntity);
248 //Check, if there is any data on the support?
249 SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh();
250 if(anEntity == VISU::NODE_ENTITY){
251 if(aMeshOnSupport->getNumberOfNodes() > 0)
252 isDataPresent = true;
255 int* aGeomElemVector;
256 GetEntity2Geom(anEntity,aGeomElemVector,&iGeomElemEnd);
257 const SALOME_MED::medEntityMesh& aMedEntity = aVisu2MedEntity[anEntity];
258 for (int iGeomElem = 0, aCounter = 0; iGeomElem < iGeomElemEnd; iGeomElem++) {
259 int medId = GetIdMEDType(aGeomElemVector[iGeomElem]);
260 SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
261 med_int iNumElemEnd = aMeshOnSupport->getNumberOfElements(aMedEntity,aMedType);
262 if(iNumElemEnd > 0) {
263 isDataPresent = true;
268 if(!isDataPresent) continue;
269 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
270 aMeshOnEntity.myEntity = anEntity;
271 aMeshOnEntity.myMeshName = aMeshName.in();
272 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
273 aMeshOnEntity2.mySupport = aMEDSupport;
275 SALOME_MED::FAMILY_var aMEDFamily = SALOME_MED::FAMILY::_narrow(aMedSupport);
276 if(!aMEDFamily->_is_nil()) {
277 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFamily = '"<<aSupportName<<"' anEntity = "<<anEntity);
278 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
279 VISU::TFamily& aFamily = aMeshOnEntity.myFamilyMap[aSupportName.in()];
280 aFamily.myName = aSupportName.in();
281 aFamily.myEntity = anEntity;
282 aFamily.myId = aMEDFamily->getIdentifier();
283 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
284 VISUMED::TFamily& aFamily2 = aMeshOnEntity2.myFamilyMap[aSupportName.in()];
285 aFamily2.myFamily = aMEDFamily;
287 SALOME_MED::GROUP_var aMEDGroup = SALOME_MED::GROUP::_narrow(aMedSupport);
288 if(!aMEDGroup->_is_nil()) {
289 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup = '"<<aSupportName<<"' anEntity = "<<anEntity);
290 VISUMED::TGroupMap& aGroupMap2 = aMesh2.myGroupMap;
291 VISUMED::TGroup& aGroup2 = aGroupMap2[aSupportName.in()];
292 aGroup2.myGroup = aMEDGroup;
293 //VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
294 //VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
295 //VISU::TGroup& aGroup = aGroupMap[aSupportName.in()];
296 //aGroup.myName = aSupportName.in();
297 //aGroup.myMeshName = aMesh.myName;
298 SALOME_MED::Family_array_var aFamilies = aMEDGroup->getFamilies();
299 int iFamilyEnd = aFamilies->length();
300 for(int iFamaily = 0; iFamaily < iFamilyEnd; iFamaily++){
301 aMEDFamily = aFamilies[iFamaily];
302 CORBA::String_var aFamilyName = aMEDFamily->getName();
303 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
304 VISU::TFamily& aFamily = aMeshOnEntity.myFamilyMap[aFamilyName.in()];
305 VISU::TBindGroups& aBindGroups = aFamily.myGroups;
306 aBindGroups.insert(aSupportName.in());
311 //Correction of TMesh.TGroupMap
312 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
313 if(aMeshOnEntityMap.empty()) continue;
314 VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
315 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
316 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
317 const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
318 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap;
319 if(aFamilyMap.empty()) continue;
320 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
321 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
322 const VISU::TFamily& aFamily = aFamilyMapIter->second;
323 const VISU::TBindGroups& aBindGroups = aFamily.myGroups;
324 if(aBindGroups.empty()) continue;
325 VISU::TBindGroups::const_iterator aBindGroupsIter = aBindGroups.begin();
326 for(; aBindGroupsIter != aBindGroups.end(); aBindGroupsIter++){
327 const string& aGroupName = *aBindGroupsIter;
328 VISU::TGroup& aGroup = aGroupMap[aGroupName];
329 aGroup.myName = aGroupName;
330 aGroup.myMeshName = aMesh.myName;
331 VISU::TFamilyAndEntity aFamilyAndEntity(aFamily.myName,aFamily.myEntity);
332 aGroup.myFamilyAndEntitySet.insert(aFamilyAndEntity);
337 SALOMEDS::SObject_var aFieldSObj;
338 aBool = aMedCompSObj->FindSubObject(aTag+2,aFieldSObj);
340 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDFIELD found.");
341 SALOMEDS::ChildIterator_var aFieldIterator = aStudy->NewChildIterator(aFieldSObj);
342 for(int iField = 0; aFieldIterator->More(); aFieldIterator->Next(), iField++){
343 aFieldSObj = aFieldIterator->Value();
344 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<<::GetName(aFieldSObj)<<"'");
345 SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(aFieldSObj);
346 for(; aTimeStampIterator->More(); aTimeStampIterator->Next()){
347 SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
348 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<::GetName(aTimeStampSObj)<<"'");
349 CORBA::Object_var aMedField = SObjectToObject(aTimeStampSObj);
350 if(CORBA::is_nil(aMedField)) continue;
351 SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
352 if(aMEDField->_is_nil()) continue;
353 SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
354 if(aMEDSupport->_is_nil()) continue;
355 SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
356 VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
357 SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
358 if(aMEDMesh->_is_nil()) continue;
359 CORBA::String_var aMeshName = aMEDMesh->getName();
360 CORBA::String_var aFieldName = aMEDField->getName();
362 VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
363 aMesh.myDim = aMEDMesh->getSpaceDimension();
364 aMesh.myName = aMeshName.in();
365 VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
366 aMesh2.myMesh = aMEDMesh;
368 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
369 aMeshOnEntity.myEntity = anEntity;
370 aMeshOnEntity.myMeshName = aMeshName.in();
371 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
372 aMeshOnEntity2.mySupport = aMEDSupport;
373 if(anEntity == VISU::NODE_ENTITY){
374 aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myEntity = VISU::CELL_ENTITY;
375 aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myMeshName = aMeshName.in();
376 aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
379 VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
380 aField.myId = iField;
381 aField.myName = aFieldName.in();
382 aField.myEntity = anEntity;
383 aField.myMeshName = aMeshName.in();
384 aField.myNbComp = aMEDField->getNumberOfComponents();
385 aField.myCompNames.resize(aField.myNbComp);
386 aField.myUnitNames.resize(aField.myNbComp);
387 //int iTimeStamp = aMEDField->getOrderNumber();
388 int iTimeStamp = aMEDField->getIterationNumber();
389 VISU::TField::TValForTime& aValForTime = aField.myValField[iTimeStamp];
390 aValForTime.myId = iTimeStamp;
391 double dt = aMEDField->getTime();
392 aValForTime.myTime = VISU::TField::TTime(dt,"");
394 VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
395 VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[iTimeStamp];
396 aValForTime2.myField = aMEDField;
398 MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<"'; myEntity = "<<anEntity<<"; myTime = "<<dt);
406 SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(mySObject);
407 for(; aTimeStampIterator->More(); aTimeStampIterator->Next()){
408 SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
409 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<::GetName(aTimeStampSObj)<<"'");
410 CORBA::Object_var aMedField = SObjectToObject(aTimeStampSObj);
411 if(CORBA::is_nil(aMedField)) continue;
412 SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
413 if(aMEDField->_is_nil()) continue;
414 SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport();
415 if(aMEDSupport->_is_nil()) continue;
416 SALOME_MED::medEntityMesh aMEDEntity = aMEDSupport->getEntity();
417 VISU::TEntity anEntity = aMed2VisuEntity[aMEDEntity];
418 SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh();
419 if(aMEDMesh->_is_nil()) continue;
420 CORBA::String_var aMeshName = aMEDMesh->getName();
421 CORBA::String_var aFieldName = aMEDField->getName();
423 VISU::TMesh &aMesh = myMeshMap[aMeshName.in()];
424 aMesh.myDim = aMEDMesh->getSpaceDimension();
425 aMesh.myName = aMeshName.in();
426 VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()];
427 aMesh2.myMesh = aMEDMesh;
428 if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
430 VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[anEntity];
431 aMeshOnEntity.myEntity = anEntity;
432 aMeshOnEntity.myMeshName = aMeshName.in();
433 VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[anEntity];
434 aMeshOnEntity2.mySupport = aMEDSupport;
435 if(anEntity == VISU::NODE_ENTITY){
436 aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myEntity = VISU::CELL_ENTITY;
437 aMesh.myMeshOnEntityMap[VISU::CELL_ENTITY].myMeshName = aMeshName.in();
438 aMesh2.myMeshOnEntityMap[VISU::CELL_ENTITY].mySupport = aMEDSupport;
441 VISU::TField& aField = aMeshOnEntity.myFieldMap[aFieldName.in()];
442 CORBA::Short iField = mySObject->Tag();
443 aField.myId = iField;
444 aField.myName = aFieldName.in();
445 aField.myEntity = anEntity;
446 aField.myMeshName = aMeshName.in();
447 aField.myNbComp = aMEDField->getNumberOfComponents();
448 aField.myCompNames.resize(aField.myNbComp);
449 aField.myUnitNames.resize(aField.myNbComp);
450 //int iTimeStamp = aMEDField->getOrderNumber();
451 int iTimeStamp = aMEDField->getIterationNumber();
452 VISU::TField::TValForTime& aValForTime = aField.myValField[iTimeStamp];
453 aValForTime.myId = iTimeStamp;
454 double dt = aMEDField->getTime();
455 aValForTime.myTime = VISU::TField::TTime(dt,"");
457 VISUMED::TField& aField2 = aMeshOnEntity2.myFieldMap[aFieldName.in()];
458 VISUMED::TField::TValForTime& aValForTime2 = aField2.myValField[iTimeStamp];
459 aValForTime2.myField = aMEDField;
461 MESSAGE("VISU_MEDConvertor::Build - aMeshName = '"<<aMeshName<<"'; myEntity = "<<anEntity<<"; myTime = "<<dt);
466 int VISU_MEDConvertor::LoadMeshOnEntity(VISU::TMeshOnEntity& theMeshOnEntity,
467 const string& theFamilyName)
468 throw (std::runtime_error&)
471 const string& aMeshName = theMeshOnEntity.myMeshName;
472 const VISU::TEntity& anEntity = theMeshOnEntity.myEntity;
473 VISU::TMesh& aMesh = myMeshMap[aMeshName];
475 if(anEntity == VISU::NODE_ENTITY)
476 isPointsUpdated = LoadPoints(aMesh,theFamilyName);
478 isPointsUpdated = LoadPoints(aMesh);
479 int isCellsOnEntityUpdated = LoadCellsOnEntity(theMeshOnEntity,theFamilyName);
481 return (isPointsUpdated || isCellsOnEntityUpdated);
484 int VISU_MEDConvertor::LoadMeshOnGroup(VISU::TMesh& theMesh,
485 const VISU::TFamilyAndEntitySet& theFamilyAndEntitySet)
486 throw (std::runtime_error&)
489 int isPointsUpdated = 0;
490 int isCellsOnEntityUpdated = 0;
491 VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = theFamilyAndEntitySet.begin();
492 for(; aFamilyAndEntitySetIter != theFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
493 const string& aFamilyName = aFamilyAndEntitySetIter->first;
494 const VISU::TEntity& anEntity = aFamilyAndEntitySetIter->second;
495 VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[anEntity];
496 if(anEntity == VISU::NODE_ENTITY){
497 isPointsUpdated += LoadPoints(theMesh,aFamilyName);
498 isCellsOnEntityUpdated += LoadCellsOnEntity(aMeshOnEntity);
500 isPointsUpdated += LoadPoints(theMesh);
501 isCellsOnEntityUpdated += LoadCellsOnEntity(aMeshOnEntity,aFamilyName);
505 return (isPointsUpdated || isCellsOnEntityUpdated);
508 void VISU_CorbaMedSupportConvertor::SetSupport(SALOME_MED::SUPPORT_ptr theSupport) {
509 mySupport = SALOME_MED::SUPPORT::_duplicate(theSupport);
510 if(!mySupport->_is_nil())
511 myMedMesh = mySupport->getMesh();
514 int ImportPoints(VISU::TMesh& theMesh, SALOME_MED::MESH_ptr theMESH)
515 throw (std::runtime_error&)
518 if(MYDEBUG) MESSAGE("ImportPoints - beginning");
519 theMesh.myDim = theMESH->getMeshDimension();
520 int aNbPoints = theMESH->getNumberOfNodes();
521 VISU::TMesh::TPointsCoord& aPointsCoord = theMesh.myPointsCoord;
522 aPointsCoord.resize(theMesh.myDim*aNbPoints,0.0);
523 Engines::double_array_var coord = theMESH->getCoordinates(SALOME_MED::MED_FULL_INTERLACE);
524 for (int i = 0 ; i < aNbPoints; i++)
525 for(int j = 0, ij = theMesh.myDim*i; j < theMesh.myDim; j++)
526 aPointsCoord[ij+j] = coord[ij+j];
528 MESSAGE("ImportPoints - End : theDim = "<<theMesh.myDim<<"; aNbPoints = "<<aNbPoints);
533 int ImportCells(VISU::TMesh& theMesh, SALOME_MED::MESH_ptr theMESH,
534 const SALOME_MED::medEntityMesh& theEntity)
535 throw (std::runtime_error&)
538 if(MYDEBUG) MESSAGE("ImportCells - theEntity = "<<theEntity);
539 //TEntity2Geom anEntity2Geom = anEntity2GeomMap[theEntity];
540 //int *iVector = anEntity2Geom->first, iEnd = anEntity2Geom->second;
542 VISU::TEntity anEntity = MED2VISUEntity(theEntity);
543 Entity2Geom(anEntity,iArray,&iEnd);
544 int aNbPoints = theMesh.myPointsCoord.size();
545 for (int i = 0; i < iEnd; i++) {
546 int medId = FindIdMEDType(iArray[i]);
547 int nbMedNodes = salome_med2vtk[medId].medNbNodes;
548 int nbVtkNodes = salome_med2vtk[medId].vtkNbNodes;
549 int aVtkType = salome_med2vtk[medId].vtkType;
550 SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType;
551 int jEnd = theMESH->getNumberOfElements(theEntity,aMedType);
553 VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[anEntity];
554 Engines::long_array_var conn =
555 theMESH->getConnectivity(SALOME_MED::MED_FULL_INTERLACE,SALOME_MED::MED_NODAL,theEntity,aMedType);
556 if(MYDEBUG) MESSAGE("ImportCells - medName = "<<salome_med2vtk[medId].medName<<"; jEnd = "<<jEnd);
557 VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = aMeshOnEntity.myCellsConn[aVtkType];
558 aConnForCellType.resize(jEnd);
559 valarray<med_int> aConnect(nbMedNodes);
560 for (int j = 0; j < jEnd; j++) {
561 VISU::TMeshOnEntity::TConnect& anArray = aConnForCellType[j];
562 anArray.resize(nbVtkNodes);
563 for (int k = 0, kj = j*nbMedNodes; k < nbMedNodes; k++)
564 aConnect[k] = conn[kj+k] - 1;
566 case SALOME_MED::MED_TETRA4 :
567 case SALOME_MED::MED_TETRA10 :
568 anArray[0] = aConnect[0];
569 anArray[1] = aConnect[1];
570 anArray[2] = aConnect[3];
571 anArray[3] = aConnect[2];
573 case SALOME_MED::MED_PYRA5 :
574 case SALOME_MED::MED_PYRA13 :
575 anArray[0] = aConnect[0];
576 anArray[1] = aConnect[3];
577 anArray[2] = aConnect[2];
578 anArray[3] = aConnect[1];
579 anArray[4] = aConnect[4];
582 for (int k = 0; k < nbVtkNodes; k++)
583 anArray[k] = aConnect[k];
585 for (int k = 0; k < nbVtkNodes; k++)
586 if(anArray[k] < 0 || aNbPoints <= anArray[k])
587 throw std::runtime_error("ImportCells >> anArray[k] < 0 || aNbPoints <= anArray[k]");
590 MESSAGE("ImportCells - aMeshOnEntity.myCellsConn.size() = "<<aMeshOnEntity.myCellsConn.size());
596 VISU_Convertor* VISU_MedMeshConvertor::Build() throw (std::runtime_error&) {
598 if(myMedMesh->_is_nil())
599 throw std::runtime_error("VISU_MedMeshConvertor::Build >> myMesh->_is_nil()");
600 CORBA::String_var aName = myMedMesh->getName();
602 TMesh& aMesh = myMeshMap[myName];
603 if(MYDEBUG) MESSAGE("MedInfo - aMeshName = "<<myMeshMap.begin()->first);
604 ::ImportPoints(aMesh,myMedMesh);
605 TVisu2MedEntity::const_iterator aVisu2MedEntityIter = aVisu2MedEntity.begin();
606 for(; aVisu2MedEntityIter != aVisu2MedEntity.end(); aVisu2MedEntityIter++)
607 ::ImportCells(aMesh,myMedMesh,aVisu2MedEntityIter->second);
613 template<class TArray> int ImportField(TArray& theArray,
614 const VISU::TMeshOnEntity& theMeshOnEntity,
615 VISU::TField& theField,
616 const SALOME_MED::medEntityMesh& theEntity,
617 const VISU::TField::TTime& theTime)
620 if(MYDEBUG) MESSAGE("ImportField - IEnd = "<<theArray->length()<<"; myNbComp = "<<theField.myNbComp);
621 VISU::TEntity anEntity = MED2VISUEntity(theEntity);
622 VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[anEntity];
623 VISU::TField& aField = aMeshOnEntity.myFieldMap[nomcha]
624 VISU::TField::TValForTime& aValForTime = theField.myValField[theTime];
625 if(theField.myTypeConn == POINT_DATA){
626 VISU::TField::TValForCellsWithType& aValForCellsWithType = aValForTime[VTK_VERTEX];
627 int iEnd = theMesh.myPointsCoord.size()/theMesh.myDim * theField.myNbComp;
628 if(MYDEBUG) MESSAGE("ImportField - iEnd = "<<iEnd);
629 aValForCellsWithType.resize(iEnd);
630 for (int i = 0; i < iEnd; i++)
631 aValForCellsWithType[i] = theArray[i];
633 int iEnd = VTKCELLGEOMEND, *iArray = VTKCELLGEOM, kEnd = theField.myNbComp;
634 for (int i = 0, I = 0; i < iEnd; i++) {
635 int medId = FindIdMEDType(iArray[i]), aVtkType = salome_med2vtk[medId].vtkType;
636 const VISU::TMeshOnEntity::TCellsConn& aCellsConn = theMesh.myCellsConn;
637 VISU::TMeshOnEntity::TCellsConn::const_iterator aCellsConnIter = aCellsConn.find(aVtkType);
638 if(aCellsConnIter != aCellsConn.end()){
639 const VISU::TMesh::TConnForCellType& aConnForCellType = aCellsConnIter->second;
640 int jEnd = aConnForCellType.size();
641 if(MYDEBUG) MESSAGE("ImportField - medName = "<<salome_med2vtk[medId].medName<<
642 "; vtkName = "<<salome_med2vtk[medId].vtkName<<"; jEnd = "<<jEnd);
643 VISU::TField::TValForCellsWithType& aValForCellsWithType = aValForTime[aVtkType];
644 aValForCellsWithType.resize(jEnd*kEnd);
645 for (int j = 0; j < jEnd; j++)
646 for (int k = 0, kj = j*kEnd; k < kEnd; k++)
647 aValForCellsWithType[kj+k] = theArray[I++];
654 VISU_Convertor* VISU_CorbaMedConvertor::Build() throw (std::runtime_error&){
656 if(myMedField->_is_nil())
657 throw std::runtime_error("VISU_CorbaMedConvertor::Build >> myField->_is_nil()");
658 if(VISU_MedMeshConvertor::Build() == NULL) return NULL;
659 CORBA::String_var aName = myMedField->getName();
661 TMeshMap::const_iterator aMeshIter = myMeshMap.begin();
662 const TMesh& aMesh = aMeshIter->second;
663 int aNbPoints = aMesh.myPointsCoord.size()/aMesh.myDim;
664 int aNbCells = aMesh.GetCellsDims().first;
665 aName = myMedField->getName();
666 aMeshOnEntity.myEntity = theEntity;
667 aMeshOnEntity.myMeshName = theMesh.myName;
668 TField& aField = myFieldMap[aName.in()];
669 aField.myMeshName = aMeshIter->first;
670 SALOME_MED::SUPPORT_var aSupport = myMedField->getSupport();
671 SALOME_MED::medEntityMesh anEntity = aSupport->getEntity();
673 if(anEntity == SALOME_MED::MED_NODE){
675 aField.myTypeConn = POINT_DATA;
676 if(MYDEBUG) MESSAGE("VISU_CorbaMedConvertor::Build - POINT_DATA = "<<aSize);
677 }else if(anEntity == SALOME_MED::MED_CELL){
679 aField.myTypeConn = CELL_DATA;
680 if(MYDEBUG) MESSAGE("VISU_CorbaMedConvertor::Build - CELL_DATA = "<<aSize);
682 aField.myNbComp = myMedField->getNumberOfComponents();
683 if(MYDEBUG) MESSAGE("VISU_CorbaMedConvertor::Build - aField.myNbComp = "<<aField.myNbComp);
684 TField::TTime aTime(myMedField->getTime(),"");
685 SALOME_MED::FIELDDOUBLE_ptr aFieldDouble = SALOME_MED::FIELDDOUBLE::_narrow(myMedField);
686 if(!aFieldDouble->_is_nil()){
687 if(MYDEBUG) MESSAGE("VISU_CorbaMedConvertor::Build - There is FIELDDOUBLE");
688 Engines::double_array_var anArray = aFieldDouble->getValue(SALOME_MED::MED_FULL_INTERLACE);
689 ::ImportField(anArray,aMesh,aField,anEntity,aTime);
691 SALOME_MED::FIELDINT_ptr aFieldInt = SALOME_MED::FIELDINT::_narrow(myMedField);
692 if(!aFieldInt->_is_nil()){
693 if(MYDEBUG) MESSAGE("VISU_CorbaMedConvertor::Build - There is FIELDINT");
694 Engines::long_array_var anArray = aFieldInt->getValue(SALOME_MED::MED_FULL_INTERLACE);
695 ::ImportField(anArray,aMesh,aField,anEntity,aTime);
702 int ImportCellsOfSupport(VISU::TMesh& theMesh, SALOME_MED::SUPPORT_ptr theSUPPORT)
703 throw (std::runtime_error&)
706 if(MYDEBUG) MESSAGE("ImportCellsOfSupport - beginning");
707 SALOME_MED::medEntityMesh anEntity = theSUPPORT->getEntity();
708 med_int nmailles[SALOME_MED::MED_ALL_ELEMENTS];
709 if(MYDEBUG) MESSAGE("ImportCellsOfSupport - anEntity = "<<anEntity);
710 if(anEntity == SALOME_MED::MED_NODE){
711 VISU::TMesh::TConnForCellType& aConnForCellType = theMesh.myCellsConn[VTK_VERTEX];
712 if(theSUPPORT->isOnAllElements()){
713 int jEnd = theMesh.myPointsCoord.size()/theMesh.myDim;
714 if(MYDEBUG) MESSAGE("ImportCellsOfSupport - isOnAllElements - "<<jEnd);
715 aConnForCellType.resize(jEnd);
716 for (int j = 0; j < jEnd; j++)
717 aConnForCellType[j] = vector<int>(1,j);
719 SALOME_MED::medGeometryElement_array_var aGeom = theSUPPORT->getTypes();
720 Engines::long_array_var aCellNumForType = theSUPPORT->getNumber(aGeom[0]);
721 int jEnd = aCellNumForType->length();
722 aConnForCellType.resize(jEnd);
723 for (int j = 0; j < jEnd; j++)
724 aConnForCellType[j] = vector<int>(1,aCellNumForType[j]-1);
727 VISU::TMesh aBaseMesh;
728 SALOME_MED::MESH_var aMedMesh = theSUPPORT->getMesh();
729 ::ImportPoints(aBaseMesh,aMedMesh);
730 ::ImportCells(aBaseMesh,aMedMesh,anEntity);
731 if(theSUPPORT->isOnAllElements()){
732 if(MYDEBUG) MESSAGE("ImportCellsOfSupport - isOnAllElements");
734 SALOME_MED::medGeometryElement_array_var aGeom = theSUPPORT->getTypes();
735 int iEnd = aGeom->length();
736 if(MYDEBUG) MESSAGE("ImportCellsOfSupport - aGeom->length() = "<<iEnd);
737 for (int i = 0; i < iEnd; i++) {
738 Engines::long_array_var aCellNumForType = theSUPPORT->getNumber(aGeom[i]);
739 int medId = FindIdMEDType(aGeom[i]);
740 int aVtkType = salome_med2vtk[medId].vtkType;
741 med_int jEnd = aCellNumForType->length();
742 if(MYDEBUG) MESSAGE("ImportCellsOfSupport - medName = "<<salome_med2vtk[medId].medName<<"; jEnd = "<<jEnd);
743 VISU::TMesh::TConnForCellType& aConnForCellType = theMesh.myCellsConn[aVtkType];
744 aConnForCellType.resize(jEnd);
745 VISU::TMesh::TConnForCellType& aBaseConnForCellType = aBaseMesh.myCellsConn[aVtkType];
746 for (int j = 0; j < jEnd; j++) {
747 aConnForCellType[j] = aBaseConnForCellType[aCellNumForType[j]-1];
756 VISU_Convertor* VISU_CorbaMedSupportConvertor::Build() throw (std::runtime_error&) {
758 if(MYDEBUG) MESSAGE("BuildSupport - checking mySupport & mySupport->getMesh()");
759 if(mySupport->_is_nil())
760 throw std::runtime_error("VISU_CorbaMedConvertor::Build >> mySupport->_is_nil()");
761 SALOME_MED::GROUP_var aGroup = SALOME_MED::GROUP::_narrow(mySupport);
763 if(!aGroup->_is_nil()){
764 CORBA::String_var aName = aGroup->getName();
766 if(MYDEBUG) MESSAGE("BuildSupport aGroup->getName() = "<<myName);
767 SALOME_MED::Family_array_var anArray = aGroup->getFamilies();
768 med_int iEnd = anArray->length();
769 TMesh& aMesh = myMeshMap[myName];
770 if(MYDEBUG) MESSAGE("BuildSupport - aGroup->getFamilies()->length() = "<<iEnd);
771 ::ImportPoints(aMesh,myMedMesh);
772 for(med_int i = 0; i < iEnd; i++){
773 if(MYDEBUG) MESSAGE("BuildSupport - import FAMILY with number = "<<i);
774 SALOME_MED::FAMILY_var aFamily = anArray[i];
775 ::ImportCellsOfSupport(aMesh,aFamily);
777 aNbCells = aMesh.GetCellsDims().first;
779 CORBA::String_var aName = mySupport->getName();
781 if(MYDEBUG) MESSAGE("mySupport - myName = "<<myName);
782 TMesh& aMesh = myMeshMap[myName];
783 myMedMesh = mySupport->getMesh();
784 ::ImportPoints(aMesh,myMedMesh);
785 ::ImportCellsOfSupport(aMesh,mySupport);
786 aNbCells = aMesh.GetCellsDims().first;
789 throw std::runtime_error("VISU_MedMeshConvertor::Build >> aNbCells == 0");
790 if(MYDEBUG) MESSAGE("BuildSupport - aNbCells = "<<aNbCells);