1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH DriverMED : driver to read and write 'med' files
24 // File : DriverMED_W_SMESHDS_Mesh.cxx
29 #include "DriverMED_W_SMESHDS_Mesh.h"
30 #include "DriverMED_Family.h"
32 #include "SMESHDS_Mesh.hxx"
33 #include "SMDS_MeshElement.hxx"
34 #include "SMDS_MeshNode.hxx"
35 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
37 #include "utilities.h"
39 #include "MED_Utilities.hxx"
41 #define _EDF_NODE_IDS_
42 //#define _ELEMENTS_BY_DIM_
48 DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
49 myAllSubMeshes (false),
50 myDoGroupOfNodes (false),
51 myDoGroupOfEdges (false),
52 myDoGroupOfFaces (false),
53 myDoGroupOfVolumes (false),
54 myDoGroupOf0DElems(false),
55 myDoGroupOfBalls(false)
58 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
61 myMed = CrWrapper(theFileName,theId);
62 Driver_SMESHDS_Mesh::SetFile(theFileName);
65 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
67 return SetFile(theFileName,MED::eV2_2);
70 string DriverMED_W_SMESHDS_Mesh::GetVersionString(const MED::EVersion theVersion, int theNbDigits)
72 TInt majeur, mineur, release;
73 majeur = mineur = release = 0;
74 // if ( theVersion == eV2_1 )
75 // MED::GetVersionRelease<eV2_1>(majeur, mineur, release);
77 MED::GetVersionRelease<eV2_2>(majeur, mineur, release);
79 if ( theNbDigits > 0 )
81 if ( theNbDigits > 1 )
82 name << "." << mineur;
83 if ( theNbDigits > 2 )
84 name << "." << release;
88 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
90 myGroups.push_back(theGroup);
93 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
95 myAllSubMeshes = true;
98 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
100 mySubMeshes[theID] = theSubMesh;
103 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
105 myDoGroupOfNodes = true;
108 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
110 myDoGroupOfEdges = true;
113 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
115 myDoGroupOfFaces = true;
118 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
120 myDoGroupOfVolumes = true;
124 typedef double (SMDS_MeshNode::* TGetCoord)() const;
125 typedef const char* TName;
126 typedef const char* TUnit;
128 // name length in a mesh must be equal to 16 :
135 TUnit aUnit[3] = {M,M,M};
138 TGetCoord aXYZGetCoord[3] = {
143 TName aXYZName[3] = {X,Y,Z};
146 TGetCoord aXYGetCoord[2] = {
150 TName aXYName[2] = {X,Y};
152 TGetCoord aYZGetCoord[2] = {
156 TName aYZName[2] = {Y,Z};
158 TGetCoord aXZGetCoord[2] = {
162 TName aXZName[2] = {X,Z};
165 TGetCoord aXGetCoord[1] = {
168 TName aXName[1] = {X};
170 TGetCoord aYGetCoord[1] = {
173 TName aYName[1] = {Y};
175 TGetCoord aZGetCoord[1] = {
178 TName aZName[1] = {Z};
182 SMDS_NodeIteratorPtr myNodeIter;
183 const SMDS_MeshNode* myCurrentNode;
184 TGetCoord* myGetCoord;
188 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
189 TGetCoord* theGetCoord,
191 TUnit* theUnit = aUnit):
192 myNodeIter(theNodeIter),
193 myGetCoord(theGetCoord),
197 virtual ~TCoordHelper(){}
199 return myNodeIter->more() &&
200 (myCurrentNode = myNodeIter->next());
202 const SMDS_MeshNode* GetNode(){
203 return myCurrentNode;
205 MED::TIntVector::value_type GetID(){
206 return myCurrentNode->GetID();
208 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
209 return (myCurrentNode->*myGetCoord[theCoodId])();
211 MED::TStringVector::value_type GetName(TInt theDimId){
212 return myName[theDimId];
214 MED::TStringVector::value_type GetUnit(TInt theDimId){
215 return myUnit[theDimId];
218 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
220 //-------------------------------------------------------
222 * \brief Structure describing element type
224 //-------------------------------------------------------
227 EEntiteMaillage _entity;
228 EGeometrieElement _geomType;
230 SMDSAbs_ElementType _smdsType;
232 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
233 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
237 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
239 //================================================================================
241 * \brief Fills element to famaly ID map for element type.
242 * Removes all families of anElemType
244 //================================================================================
246 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
247 list<DriverMED_FamilyPtr> & aFamilies,
248 const SMDSAbs_ElementType anElemType)
250 anElemFamMap.Clear();
251 //anElemFamMap.clear();
252 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
253 while ( aFamsIter != aFamilies.end() )
255 if ((*aFamsIter)->GetType() != anElemType) {
259 int aFamId = (*aFamsIter)->GetId();
260 const set<const SMDS_MeshElement *>& anElems = (*aFamsIter)->GetElements();
261 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElems.begin();
262 for (; anElemsIter != anElems.end(); anElemsIter++)
264 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
265 //anElemFamMap[*anElemsIter] = aFamId;
267 // remove a family from the list
268 aFamilies.erase( aFamsIter++ );
273 //================================================================================
275 * \brief For an element, return family ID found in the map or a default one
277 //================================================================================
279 int getFamilyId( const TElemFamilyMap & anElemFamMap,
280 const SMDS_MeshElement* anElement,
281 const int aDefaultFamilyId)
283 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
284 return anElemFamMap( (Standard_Address) anElement );
285 // TElemFamilyMap::iterator elem_famNum = anElemFamMap.find( anElement );
286 // if ( elem_famNum != anElemFamMap.end() )
287 // return elem_famNum->second;
288 return aDefaultFamilyId;
292 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
294 Status aResult = DRS_OK;
295 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
296 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
300 MESSAGE("Perform - myFile : "<<myFile);
302 // Creating the MED mesh for corresponding SMDS structure
303 //-------------------------------------------------------
305 if (myMeshId != -1) {
306 ostringstream aMeshNameStr;
307 aMeshNameStr<<myMeshId;
308 aMeshName = aMeshNameStr.str();
310 aMeshName = myMeshName;
313 // Mesh dimension definition
314 TInt aSpaceDimension;
315 TCoordHelperPtr aCoordHelperPtr;
317 bool anIsXDimension = false;
318 bool anIsYDimension = false;
319 bool anIsZDimension = false;
321 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
323 if(aNodesIter->more()){
324 const SMDS_MeshNode* aNode = aNodesIter->next();
325 aBounds[0] = aBounds[1] = aNode->X();
326 aBounds[2] = aBounds[3] = aNode->Y();
327 aBounds[4] = aBounds[5] = aNode->Z();
329 while(aNodesIter->more()){
330 const SMDS_MeshNode* aNode = aNodesIter->next();
331 aBounds[0] = min(aBounds[0],aNode->X());
332 aBounds[1] = max(aBounds[1],aNode->X());
334 aBounds[2] = min(aBounds[2],aNode->Y());
335 aBounds[3] = max(aBounds[3],aNode->Y());
337 aBounds[4] = min(aBounds[4],aNode->Z());
338 aBounds[5] = max(aBounds[5],aNode->Z());
342 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
343 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
344 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
345 aSpaceDimension = anIsXDimension + anIsYDimension + anIsZDimension;
348 // PAL16857(SMESH not conform to the MED convention):
349 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
351 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
352 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
353 if ( anIsYDimension ) {
355 anIsXDimension = true;
362 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
363 switch(aSpaceDimension){
365 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
368 if(anIsXDimension && anIsYDimension)
369 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
370 if(anIsYDimension && anIsZDimension)
371 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
372 if(anIsXDimension && anIsZDimension)
373 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
377 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
379 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
381 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
385 TInt aMeshDimension = 0;
386 if ( myMesh->NbEdges() > 0 )
388 if ( myMesh->NbFaces() > 0 )
390 if ( myMesh->NbVolumes() > 0 )
393 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
394 MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
395 myMed->SetMeshInfo(aMeshInfo);
397 // Storing SMDS groups and sub-meshes as med families
398 //----------------------------------------------------
399 int myNodesDefaultFamilyId = 0;
400 int my0DElementsDefaultFamilyId = 0;
401 int myBallsDefaultFamilyId = 0;
402 int myEdgesDefaultFamilyId = 0;
403 int myFacesDefaultFamilyId = 0;
404 int myVolumesDefaultFamilyId = 0;
405 int nbNodes = myMesh->NbNodes();
406 int nb0DElements = myMesh->Nb0DElements();
407 int nbBalls = myMesh->NbBalls();
408 int nbEdges = myMesh->NbEdges();
409 int nbFaces = myMesh->NbFaces();
410 int nbVolumes = myMesh->NbVolumes();
411 if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
412 if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
413 if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
414 if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
415 if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
416 if (myDoGroupOfBalls && nbBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
418 MESSAGE("Perform - aFamilyInfo");
419 //cout << " DriverMED_Family::MakeFamilies() " << endl;
420 list<DriverMED_FamilyPtr> aFamilies;
421 if (myAllSubMeshes) {
422 aFamilies = DriverMED_Family::MakeFamilies
423 (myMesh->SubMeshes(), myGroups,
424 myDoGroupOfNodes && nbNodes,
425 myDoGroupOfEdges && nbEdges,
426 myDoGroupOfFaces && nbFaces,
427 myDoGroupOfVolumes && nbVolumes,
428 myDoGroupOf0DElems && nb0DElements,
429 myDoGroupOfBalls && nbBalls);
431 aFamilies = DriverMED_Family::MakeFamilies
432 (mySubMeshes, myGroups,
433 myDoGroupOfNodes && nbNodes,
434 myDoGroupOfEdges && nbEdges,
435 myDoGroupOfFaces && nbFaces,
436 myDoGroupOfVolumes && nbVolumes,
437 myDoGroupOf0DElems && nb0DElements,
438 myDoGroupOfBalls && nbBalls);
440 //cout << " myMed->SetFamilyInfo() " << endl;
441 list<DriverMED_FamilyPtr>::iterator aFamsIter;
442 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
444 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
445 myMed->SetFamilyInfo(aFamilyInfo);
448 // Storing SMDS nodes to the MED file for the MED mesh
449 //----------------------------------------------------
450 #ifdef _EDF_NODE_IDS_
451 typedef map<TInt,TInt> TNodeIdMap;
452 TNodeIdMap aNodeIdMap;
454 const EModeSwitch theMode = eFULL_INTERLACE;
455 const ERepere theSystem = eCART;
456 const EBooleen theIsElemNum = eVRAI;
457 const EBooleen theIsElemNames = eFAUX;
458 const EConnectivite theConnMode = eNOD;
460 TInt aNbNodes = myMesh->NbNodes();
461 //cout << " myMed->CrNodeInfo() aNbNodes = " << aNbNodes << endl;
462 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
463 theMode, theSystem, theIsElemNum, theIsElemNames);
465 //cout << " fillElemFamilyMap( SMDSAbs_Node )" << endl;
466 // find family numbers for nodes
467 TElemFamilyMap anElemFamMap;
468 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
470 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
473 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
474 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
475 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
478 int aNodeID = aCoordHelperPtr->GetID();
479 aNodeInfo->SetElemNum( iNode, aNodeID );
480 #ifdef _EDF_NODE_IDS_
481 aNodeIdMap[aNodeID] = iNode+1;
484 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
485 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
486 aNodeInfo->SetFamNum( iNode, famNum );
488 anElemFamMap.Clear();
490 // coordinate names and units
491 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
492 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
493 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
496 //cout << " SetNodeInfo(aNodeInfo)" << endl;
497 MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
498 myMed->SetNodeInfo(aNodeInfo);
499 aNodeInfo.reset(); // free memory used for arrays
502 // Storing SMDS elements to the MED file for the MED mesh
503 //-------------------------------------------------------
504 // Write one element type at once in order to minimize memory usage (PAL19276)
506 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
508 // poly elements are not supported by med-2.1
509 bool polyTypesSupported = myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0);
510 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
512 // collect info on all geom types
514 list< TElemTypeData > aTElemTypeDatas;
516 EEntiteMaillage anEntity = eMAILLE;
517 #ifdef _ELEMENTS_BY_DIM_
518 anEntity = eNOEUD_ELEMENT;
520 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
522 nbElemInfo.Nb0DElements(),
524 #ifdef _ELEMENTS_BY_DIM_
525 anEntity = eSTRUCT_ELEMENT;
527 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
529 nbElemInfo.NbBalls(),
531 #ifdef _ELEMENTS_BY_DIM_
534 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
536 nbElemInfo.NbEdges( ORDER_LINEAR ),
538 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
540 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
542 #ifdef _ELEMENTS_BY_DIM_
545 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
547 nbElemInfo.NbTriangles( ORDER_LINEAR ),
549 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
551 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
552 nbElemInfo.NbBiQuadTriangles(),
554 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
556 nbElemInfo.NbBiQuadTriangles(),
558 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
560 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
562 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
564 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
565 nbElemInfo.NbBiQuadQuadrangles(),
567 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
569 nbElemInfo.NbBiQuadQuadrangles(),
571 if ( polyTypesSupported ) {
572 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
574 nbElemInfo.NbPolygons(),
576 // we need one more loop on poly elements to count nb of their nodes
577 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
579 nbElemInfo.NbPolygons(),
582 #ifdef _ELEMENTS_BY_DIM_
585 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
587 nbElemInfo.NbTetras( ORDER_LINEAR ),
589 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
591 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
593 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
595 nbElemInfo.NbPyramids( ORDER_LINEAR ),
597 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
599 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
601 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
603 nbElemInfo.NbPrisms( ORDER_LINEAR ),
605 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
607 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
609 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
611 nbElemInfo.NbHexas( ORDER_LINEAR ),
613 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
615 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
616 nbElemInfo.NbTriQuadHexas(),
618 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
620 nbElemInfo.NbTriQuadHexas(),
622 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
624 nbElemInfo.NbHexPrisms(),
626 if ( polyTypesSupported ) {
627 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
629 nbElemInfo.NbPolyhedrons(),
631 // we need one more loop on poly elements to count nb of their nodes
632 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
634 nbElemInfo.NbPolyhedrons(),
638 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
640 // loop on all geom types of elements
642 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
643 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
645 if ( aElemTypeData->_nbElems == 0 )
648 int defaultFamilyId = 0;
649 switch ( aElemTypeData->_smdsType ) {
650 case SMDSAbs_0DElement:
651 defaultFamilyId = my0DElementsDefaultFamilyId;
654 defaultFamilyId = myBallsDefaultFamilyId;
657 defaultFamilyId = myEdgesDefaultFamilyId;
660 defaultFamilyId = myFacesDefaultFamilyId;
663 defaultFamilyId = myVolumesDefaultFamilyId;
669 // iterator on elements of a current type
670 SMDS_ElemIteratorPtr elemIterator;
675 if ( aElemTypeData->_geomType == ePOLYGONE )
677 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYGON );
678 if ( nbPolygonNodes == 0 ) {
680 while ( elemIterator->more() ) {
681 const SMDS_MeshElement* anElem = elemIterator->next();
682 nbPolygonNodes += anElem->NbNodes();
683 if ( ++iElem == aElemTypeData->_nbElems )
689 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
690 aElemTypeData->_entity,
691 aElemTypeData->_geomType,
692 aElemTypeData->_nbElems,
694 theConnMode, theIsElemNum,
696 TElemNum & index = *(aPolygoneInfo->myIndex.get());
699 while ( elemIterator->more() )
701 const SMDS_MeshElement* anElem = elemIterator->next();
703 TInt aNbNodes = anElem->NbNodes();
704 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
707 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
708 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
709 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
710 #ifdef _EDF_NODE_IDS_
711 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
713 aTConnSlice[ iNode ] = aNode->GetID();
717 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
720 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
721 aPolygoneInfo->SetFamNum( iElem, famNum );
723 if ( ++iElem == aPolygoneInfo->GetNbElem() )
726 myMed->SetPolygoneInfo(aPolygoneInfo);
733 else if (aElemTypeData->_geomType == ePOLYEDRE )
735 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
737 if ( nbPolyhedronNodes == 0 ) {
739 while ( elemIterator->more() ) {
740 const SMDS_MeshElement* anElem = elemIterator->next();
741 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
742 if ( !aPolyedre ) continue;
743 nbPolyhedronNodes += aPolyedre->NbNodes();
744 nbPolyhedronFaces += aPolyedre->NbFaces();
745 if ( ++iElem == aElemTypeData->_nbElems )
751 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
752 aElemTypeData->_entity,
753 aElemTypeData->_geomType,
754 aElemTypeData->_nbElems,
760 TElemNum & index = *(aPolyhInfo->myIndex.get());
761 TElemNum & faces = *(aPolyhInfo->myFaces.get());
762 TElemNum & conn = *(aPolyhInfo->myConn.get());
766 TInt iFace = 0, iNode = 0;
767 while ( elemIterator->more() )
769 const SMDS_MeshElement* anElem = elemIterator->next();
770 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
771 if ( !aPolyedre ) continue;
773 TInt aNbFaces = aPolyedre->NbFaces();
774 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
777 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
778 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
779 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
782 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
783 while ( nodeIt->more() ) {
784 const SMDS_MeshElement* aNode = nodeIt->next();
785 #ifdef _EDF_NODE_IDS_
786 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
788 conn[ iNode ] = aNode->GetID();
793 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
796 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
797 aPolyhInfo->SetFamNum( iElem, famNum );
799 if ( ++iElem == aPolyhInfo->GetNbElem() )
802 myMed->SetPolyedreInfo(aPolyhInfo);
804 } // if (aElemTypeData->_geomType == ePOLYEDRE )
808 else if (aElemTypeData->_geomType == eBALL )
810 // allocate data arrays
811 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo,
812 aElemTypeData->_nbElems );
814 // build map of family numbers for this type
815 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
817 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
818 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
821 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
822 while ( elemIterator->more() )
824 const SMDS_MeshElement* anElem = elemIterator->next();
826 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
827 #ifdef _EDF_NODE_IDS_
828 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
830 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
833 aBallInfo->SetElemNum( iElem, anElem->GetID() );
836 aBallInfo->myDiameters[ iElem ] =
837 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
840 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
841 aBallInfo->SetFamNum( iElem, famNum );
844 // store data in a file
845 myMed->SetBallInfo(aBallInfo);
850 // Treat standard types
851 // ---------------------
853 // allocate data arrays
854 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
855 aElemTypeData->_entity,
856 aElemTypeData->_geomType,
857 aElemTypeData->_nbElems,
861 // build map of family numbers for this type
862 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
864 //cout << " fillElemFamilyMap()" << endl;
865 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
866 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
869 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
870 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
871 while ( elemIterator->more() )
873 const SMDS_MeshElement* anElem = elemIterator->next();
874 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
875 continue; // other geometry
878 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
879 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
880 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
881 #ifdef _EDF_NODE_IDS_
882 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
884 aTConnSlice[ iNode ] = aNode->GetID();
888 aCellInfo->SetElemNum( iElem, anElem->GetID() );
891 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
892 aCellInfo->SetFamNum( iElem, famNum );
894 if ( ++iElem == aCellInfo->GetNbElem() )
897 // store data in a file
898 myMed->SetCellInfo(aCellInfo);
901 } // loop on geom types
905 catch(const std::exception& exc) {
906 INFOS("The following exception was caught:\n\t"<<exc.what());
910 INFOS("Unknown exception was caught !!!");