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),
59 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
62 myMed = CrWrapper(theFileName,theId);
63 Driver_SMESHDS_Mesh::SetFile(theFileName);
66 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
68 return SetFile(theFileName,MED::eV2_2);
71 string DriverMED_W_SMESHDS_Mesh::GetVersionString(const MED::EVersion theVersion, int theNbDigits)
73 TInt majeur, mineur, release;
74 majeur = mineur = release = 0;
75 // if ( theVersion == eV2_1 )
76 // MED::GetVersionRelease<eV2_1>(majeur, mineur, release);
78 MED::GetVersionRelease<eV2_2>(majeur, mineur, release);
80 if ( theNbDigits > 0 )
82 if ( theNbDigits > 1 )
83 name << "." << mineur;
84 if ( theNbDigits > 2 )
85 name << "." << release;
89 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
91 myGroups.push_back(theGroup);
94 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
96 myAllSubMeshes = true;
99 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
101 mySubMeshes[theID] = theSubMesh;
104 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
106 myDoGroupOfNodes = true;
109 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
111 myDoGroupOfEdges = true;
114 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
116 myDoGroupOfFaces = true;
119 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
121 myDoGroupOfVolumes = true;
126 typedef double (SMDS_MeshNode::* TGetCoord)() const;
127 typedef const char* TName;
128 typedef const char* TUnit;
130 // name length in a mesh must be equal to 16 :
137 TUnit aUnit[3] = {M,M,M};
140 TGetCoord aXYZGetCoord[3] = {
145 TName aXYZName[3] = {X,Y,Z};
148 TGetCoord aXYGetCoord[2] = {
152 TName aXYName[2] = {X,Y};
154 TGetCoord aYZGetCoord[2] = {
158 TName aYZName[2] = {Y,Z};
160 TGetCoord aXZGetCoord[2] = {
164 TName aXZName[2] = {X,Z};
167 TGetCoord aXGetCoord[1] = {
170 TName aXName[1] = {X};
172 TGetCoord aYGetCoord[1] = {
175 TName aYName[1] = {Y};
177 TGetCoord aZGetCoord[1] = {
180 TName aZName[1] = {Z};
184 SMDS_NodeIteratorPtr myNodeIter;
185 const SMDS_MeshNode* myCurrentNode;
186 TGetCoord* myGetCoord;
190 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
191 TGetCoord* theGetCoord,
193 TUnit* theUnit = aUnit):
194 myNodeIter(theNodeIter),
195 myGetCoord(theGetCoord),
199 virtual ~TCoordHelper(){}
201 return myNodeIter->more() &&
202 (myCurrentNode = myNodeIter->next());
204 const SMDS_MeshNode* GetNode(){
205 return myCurrentNode;
207 MED::TIntVector::value_type GetID(){
208 return myCurrentNode->GetID();
210 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
211 return (myCurrentNode->*myGetCoord[theCoodId])();
213 MED::TStringVector::value_type GetName(TInt theDimId){
214 return myName[theDimId];
216 MED::TStringVector::value_type GetUnit(TInt theDimId){
217 return myUnit[theDimId];
220 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
222 //-------------------------------------------------------
224 * \brief Structure describing element type
226 //-------------------------------------------------------
229 EEntiteMaillage _entity;
230 EGeometrieElement _geomType;
232 SMDSAbs_ElementType _smdsType;
234 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
235 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
239 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
241 //================================================================================
243 * \brief Fills element to famaly ID map for element type.
244 * Removes all families of anElemType
246 //================================================================================
248 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
249 list<DriverMED_FamilyPtr> & aFamilies,
250 const SMDSAbs_ElementType anElemType)
252 anElemFamMap.Clear();
253 //anElemFamMap.clear();
254 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
255 while ( aFamsIter != aFamilies.end() )
257 if ((*aFamsIter)->GetType() != anElemType) {
261 int aFamId = (*aFamsIter)->GetId();
262 const set<const SMDS_MeshElement *>& anElems = (*aFamsIter)->GetElements();
263 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElems.begin();
264 for (; anElemsIter != anElems.end(); anElemsIter++)
266 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
267 //anElemFamMap[*anElemsIter] = aFamId;
269 // remove a family from the list
270 aFamilies.erase( aFamsIter++ );
275 //================================================================================
277 * \brief For an element, return family ID found in the map or a default one
279 //================================================================================
281 int getFamilyId( const TElemFamilyMap & anElemFamMap,
282 const SMDS_MeshElement* anElement,
283 const int aDefaultFamilyId)
285 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
286 return anElemFamMap( (Standard_Address) anElement );
287 // TElemFamilyMap::iterator elem_famNum = anElemFamMap.find( anElement );
288 // if ( elem_famNum != anElemFamMap.end() )
289 // return elem_famNum->second;
290 return aDefaultFamilyId;
294 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
296 Status aResult = DRS_OK;
297 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
298 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
302 MESSAGE("Perform - myFile : "<<myFile);
304 // Creating the MED mesh for corresponding SMDS structure
305 //-------------------------------------------------------
307 if (myMeshId != -1) {
308 ostringstream aMeshNameStr;
309 aMeshNameStr<<myMeshId;
310 aMeshName = aMeshNameStr.str();
312 aMeshName = myMeshName;
315 // Mesh dimension definition
316 TInt aSpaceDimension = 3;
317 TCoordHelperPtr aCoordHelperPtr;
319 bool anIsXDimension = false;
320 bool anIsYDimension = false;
321 bool anIsZDimension = false;
322 if ( myAutoDimension )
324 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
326 if(aNodesIter->more()){
327 const SMDS_MeshNode* aNode = aNodesIter->next();
328 aBounds[0] = aBounds[1] = aNode->X();
329 aBounds[2] = aBounds[3] = aNode->Y();
330 aBounds[4] = aBounds[5] = aNode->Z();
332 while(aNodesIter->more()){
333 const SMDS_MeshNode* aNode = aNodesIter->next();
334 aBounds[0] = min(aBounds[0],aNode->X());
335 aBounds[1] = max(aBounds[1],aNode->X());
337 aBounds[2] = min(aBounds[2],aNode->Y());
338 aBounds[3] = max(aBounds[3],aNode->Y());
340 aBounds[4] = min(aBounds[4],aNode->Z());
341 aBounds[5] = max(aBounds[5],aNode->Z());
345 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
346 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
347 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
348 aSpaceDimension = anIsXDimension + anIsYDimension + anIsZDimension;
351 // PAL16857(SMESH not conform to the MED convention):
352 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
354 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
355 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
356 if ( anIsYDimension ) {
358 anIsXDimension = true;
365 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
366 switch(aSpaceDimension){
368 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
371 if(anIsXDimension && anIsYDimension)
372 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
373 if(anIsYDimension && anIsZDimension)
374 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
375 if(anIsXDimension && anIsZDimension)
376 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
380 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
382 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
384 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
388 TInt aMeshDimension = 0;
389 if ( myMesh->NbEdges() > 0 )
391 if ( myMesh->NbFaces() > 0 )
393 if ( myMesh->NbVolumes() > 0 )
396 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
397 MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
398 myMed->SetMeshInfo(aMeshInfo);
400 // Storing SMDS groups and sub-meshes as med families
401 //----------------------------------------------------
402 int myNodesDefaultFamilyId = 0;
403 int my0DElementsDefaultFamilyId = 0;
404 int myBallsDefaultFamilyId = 0;
405 int myEdgesDefaultFamilyId = 0;
406 int myFacesDefaultFamilyId = 0;
407 int myVolumesDefaultFamilyId = 0;
408 int nbNodes = myMesh->NbNodes();
409 int nb0DElements = myMesh->Nb0DElements();
410 int nbBalls = myMesh->NbBalls();
411 int nbEdges = myMesh->NbEdges();
412 int nbFaces = myMesh->NbFaces();
413 int nbVolumes = myMesh->NbVolumes();
414 if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
415 if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
416 if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
417 if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
418 if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
419 if (myDoGroupOfBalls && nbBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
421 MESSAGE("Perform - aFamilyInfo");
422 //cout << " DriverMED_Family::MakeFamilies() " << endl;
423 list<DriverMED_FamilyPtr> aFamilies;
424 if (myAllSubMeshes) {
425 aFamilies = DriverMED_Family::MakeFamilies
426 (myMesh->SubMeshes(), myGroups,
427 myDoGroupOfNodes && nbNodes,
428 myDoGroupOfEdges && nbEdges,
429 myDoGroupOfFaces && nbFaces,
430 myDoGroupOfVolumes && nbVolumes,
431 myDoGroupOf0DElems && nb0DElements,
432 myDoGroupOfBalls && nbBalls);
434 aFamilies = DriverMED_Family::MakeFamilies
435 (mySubMeshes, myGroups,
436 myDoGroupOfNodes && nbNodes,
437 myDoGroupOfEdges && nbEdges,
438 myDoGroupOfFaces && nbFaces,
439 myDoGroupOfVolumes && nbVolumes,
440 myDoGroupOf0DElems && nb0DElements,
441 myDoGroupOfBalls && nbBalls);
443 //cout << " myMed->SetFamilyInfo() " << endl;
444 list<DriverMED_FamilyPtr>::iterator aFamsIter;
445 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
447 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
448 myMed->SetFamilyInfo(aFamilyInfo);
451 // Storing SMDS nodes to the MED file for the MED mesh
452 //----------------------------------------------------
453 #ifdef _EDF_NODE_IDS_
454 typedef map<TInt,TInt> TNodeIdMap;
455 TNodeIdMap aNodeIdMap;
457 const EModeSwitch theMode = eFULL_INTERLACE;
458 const ERepere theSystem = eCART;
459 const EBooleen theIsElemNum = eVRAI;
460 const EBooleen theIsElemNames = eFAUX;
461 const EConnectivite theConnMode = eNOD;
463 TInt aNbNodes = myMesh->NbNodes();
464 //cout << " myMed->CrNodeInfo() aNbNodes = " << aNbNodes << endl;
465 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
466 theMode, theSystem, theIsElemNum, theIsElemNames);
468 //cout << " fillElemFamilyMap( SMDSAbs_Node )" << endl;
469 // find family numbers for nodes
470 TElemFamilyMap anElemFamMap;
471 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
473 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
476 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
477 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
478 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
481 int aNodeID = aCoordHelperPtr->GetID();
482 aNodeInfo->SetElemNum( iNode, aNodeID );
483 #ifdef _EDF_NODE_IDS_
484 aNodeIdMap[aNodeID] = iNode+1;
487 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
488 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
489 aNodeInfo->SetFamNum( iNode, famNum );
491 anElemFamMap.Clear();
493 // coordinate names and units
494 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
495 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
496 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
499 //cout << " SetNodeInfo(aNodeInfo)" << endl;
500 MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
501 myMed->SetNodeInfo(aNodeInfo);
502 aNodeInfo.reset(); // free memory used for arrays
505 // Storing SMDS elements to the MED file for the MED mesh
506 //-------------------------------------------------------
507 // Write one element type at once in order to minimize memory usage (PAL19276)
509 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
511 // poly elements are not supported by med-2.1
512 bool polyTypesSupported = myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0);
513 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
515 // collect info on all geom types
517 list< TElemTypeData > aTElemTypeDatas;
519 EEntiteMaillage anEntity = eMAILLE;
520 #ifdef _ELEMENTS_BY_DIM_
521 anEntity = eNOEUD_ELEMENT;
523 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
525 nbElemInfo.Nb0DElements(),
527 #ifdef _ELEMENTS_BY_DIM_
528 anEntity = eSTRUCT_ELEMENT;
530 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
532 nbElemInfo.NbBalls(),
534 #ifdef _ELEMENTS_BY_DIM_
537 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
539 nbElemInfo.NbEdges( ORDER_LINEAR ),
541 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
543 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
545 #ifdef _ELEMENTS_BY_DIM_
548 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
550 nbElemInfo.NbTriangles( ORDER_LINEAR ),
552 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
554 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
555 nbElemInfo.NbBiQuadTriangles(),
557 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
559 nbElemInfo.NbBiQuadTriangles(),
561 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
563 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
565 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
567 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
568 nbElemInfo.NbBiQuadQuadrangles(),
570 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
572 nbElemInfo.NbBiQuadQuadrangles(),
574 if ( polyTypesSupported ) {
575 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
577 nbElemInfo.NbPolygons(),
579 // we need one more loop on poly elements to count nb of their nodes
580 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
582 nbElemInfo.NbPolygons(),
585 #ifdef _ELEMENTS_BY_DIM_
588 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
590 nbElemInfo.NbTetras( ORDER_LINEAR ),
592 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
594 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
596 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
598 nbElemInfo.NbPyramids( ORDER_LINEAR ),
600 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
602 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
604 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
606 nbElemInfo.NbPrisms( ORDER_LINEAR ),
608 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
610 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
612 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
614 nbElemInfo.NbHexas( ORDER_LINEAR ),
616 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
618 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
619 nbElemInfo.NbTriQuadHexas(),
621 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
623 nbElemInfo.NbTriQuadHexas(),
625 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
627 nbElemInfo.NbHexPrisms(),
629 if ( polyTypesSupported ) {
630 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
632 nbElemInfo.NbPolyhedrons(),
634 // we need one more loop on poly elements to count nb of their nodes
635 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
637 nbElemInfo.NbPolyhedrons(),
641 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
643 // loop on all geom types of elements
645 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
646 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
648 if ( aElemTypeData->_nbElems == 0 )
651 int defaultFamilyId = 0;
652 switch ( aElemTypeData->_smdsType ) {
653 case SMDSAbs_0DElement:
654 defaultFamilyId = my0DElementsDefaultFamilyId;
657 defaultFamilyId = myBallsDefaultFamilyId;
660 defaultFamilyId = myEdgesDefaultFamilyId;
663 defaultFamilyId = myFacesDefaultFamilyId;
666 defaultFamilyId = myVolumesDefaultFamilyId;
672 // iterator on elements of a current type
673 SMDS_ElemIteratorPtr elemIterator;
678 if ( aElemTypeData->_geomType == ePOLYGONE )
680 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYGON );
681 if ( nbPolygonNodes == 0 ) {
683 while ( elemIterator->more() ) {
684 const SMDS_MeshElement* anElem = elemIterator->next();
685 nbPolygonNodes += anElem->NbNodes();
686 if ( ++iElem == aElemTypeData->_nbElems )
692 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
693 aElemTypeData->_entity,
694 aElemTypeData->_geomType,
695 aElemTypeData->_nbElems,
697 theConnMode, theIsElemNum,
699 TElemNum & index = *(aPolygoneInfo->myIndex.get());
702 while ( elemIterator->more() )
704 const SMDS_MeshElement* anElem = elemIterator->next();
706 TInt aNbNodes = anElem->NbNodes();
707 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
710 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
711 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
712 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
713 #ifdef _EDF_NODE_IDS_
714 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
716 aTConnSlice[ iNode ] = aNode->GetID();
720 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
723 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
724 aPolygoneInfo->SetFamNum( iElem, famNum );
726 if ( ++iElem == aPolygoneInfo->GetNbElem() )
729 myMed->SetPolygoneInfo(aPolygoneInfo);
736 else if (aElemTypeData->_geomType == ePOLYEDRE )
738 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
740 if ( nbPolyhedronNodes == 0 ) {
742 while ( elemIterator->more() ) {
743 const SMDS_MeshElement* anElem = elemIterator->next();
744 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
745 if ( !aPolyedre ) continue;
746 nbPolyhedronNodes += aPolyedre->NbNodes();
747 nbPolyhedronFaces += aPolyedre->NbFaces();
748 if ( ++iElem == aElemTypeData->_nbElems )
754 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
755 aElemTypeData->_entity,
756 aElemTypeData->_geomType,
757 aElemTypeData->_nbElems,
763 TElemNum & index = *(aPolyhInfo->myIndex.get());
764 TElemNum & faces = *(aPolyhInfo->myFaces.get());
765 TElemNum & conn = *(aPolyhInfo->myConn.get());
769 TInt iFace = 0, iNode = 0;
770 while ( elemIterator->more() )
772 const SMDS_MeshElement* anElem = elemIterator->next();
773 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
774 if ( !aPolyedre ) continue;
776 TInt aNbFaces = aPolyedre->NbFaces();
777 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
780 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
781 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
782 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
785 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
786 while ( nodeIt->more() ) {
787 const SMDS_MeshElement* aNode = nodeIt->next();
788 #ifdef _EDF_NODE_IDS_
789 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
791 conn[ iNode ] = aNode->GetID();
796 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
799 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
800 aPolyhInfo->SetFamNum( iElem, famNum );
802 if ( ++iElem == aPolyhInfo->GetNbElem() )
805 myMed->SetPolyedreInfo(aPolyhInfo);
807 } // if (aElemTypeData->_geomType == ePOLYEDRE )
811 else if (aElemTypeData->_geomType == eBALL )
813 // allocate data arrays
814 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo,
815 aElemTypeData->_nbElems );
817 // build map of family numbers for this type
818 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
820 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
821 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
824 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
825 while ( elemIterator->more() )
827 const SMDS_MeshElement* anElem = elemIterator->next();
829 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
830 #ifdef _EDF_NODE_IDS_
831 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
833 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
836 aBallInfo->SetElemNum( iElem, anElem->GetID() );
839 aBallInfo->myDiameters[ iElem ] =
840 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
843 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
844 aBallInfo->SetFamNum( iElem, famNum );
847 // store data in a file
848 myMed->SetBallInfo(aBallInfo);
853 // Treat standard types
854 // ---------------------
856 // allocate data arrays
857 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
858 aElemTypeData->_entity,
859 aElemTypeData->_geomType,
860 aElemTypeData->_nbElems,
864 // build map of family numbers for this type
865 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
867 //cout << " fillElemFamilyMap()" << endl;
868 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
869 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
872 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
873 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
874 while ( elemIterator->more() )
876 const SMDS_MeshElement* anElem = elemIterator->next();
877 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
878 continue; // other geometry
881 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
882 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
883 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
884 #ifdef _EDF_NODE_IDS_
885 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
887 aTConnSlice[ iNode ] = aNode->GetID();
891 aCellInfo->SetElemNum( iElem, anElem->GetID() );
894 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
895 aCellInfo->SetFamNum( iElem, famNum );
897 if ( ++iElem == aCellInfo->GetNbElem() )
900 // store data in a file
901 myMed->SetCellInfo(aCellInfo);
904 } // loop on geom types
908 catch(const std::exception& exc) {
909 INFOS("The following exception was caught:\n\t"<<exc.what());
913 INFOS("Unknown exception was caught !!!");