1 // SMESH DriverMED : driver to read and write 'med' files
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : DriverMED_W_SMESHDS_Mesh.cxx
29 #include "DriverMED_W_SMESHDS_Mesh.h"
30 #include "DriverMED_W_SMDS_Mesh.h"
31 #include "DriverMED_Family.h"
33 #include "SMESHDS_Mesh.hxx"
34 #include "SMDS_MeshElement.hxx"
35 #include "SMDS_MeshNode.hxx"
36 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
38 #include "utilities.h"
40 #include "MED_Utilities.hxx"
42 #define _EDF_NODE_IDS_
43 //#define _ELEMENTS_BY_DIM_
49 DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
50 myAllSubMeshes (false),
51 myDoGroupOfNodes (false),
52 myDoGroupOfEdges (false),
53 myDoGroupOfFaces (false),
54 myDoGroupOfVolumes (false)
57 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
60 myMed = CrWrapper(theFileName,theId);
61 Driver_SMESHDS_Mesh::SetFile(theFileName);
64 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
66 return SetFile(theFileName,MED::eV2_2);
69 string DriverMED_W_SMESHDS_Mesh::GetVersionString(const MED::EVersion theVersion, int theNbDigits)
71 TInt majeur, mineur, release;
72 majeur = mineur = release = 0;
73 if ( theVersion == eV2_1 )
74 MED::GetVersionRelease<eV2_1>(majeur, mineur, release);
76 MED::GetVersionRelease<eV2_2>(majeur, mineur, release);
78 if ( theNbDigits > 0 )
80 if ( theNbDigits > 1 )
81 name << "." << mineur;
82 if ( theNbDigits > 2 )
83 name << "." << release;
87 void DriverMED_W_SMESHDS_Mesh::SetMeshName(const std::string& theMeshName)
89 myMeshName = theMeshName;
92 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
94 myGroups.push_back(theGroup);
97 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
99 myAllSubMeshes = true;
102 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
104 mySubMeshes[theID] = theSubMesh;
107 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
109 myDoGroupOfNodes = true;
112 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
114 myDoGroupOfEdges = true;
117 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
119 myDoGroupOfFaces = true;
122 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
124 myDoGroupOfVolumes = true;
128 typedef double (SMDS_MeshNode::* TGetCoord)() const;
129 typedef const char* TName;
130 typedef const char* TUnit;
132 // name length in a mesh must be equal to 16 :
139 TUnit aUnit[3] = {M,M,M};
142 TGetCoord aXYZGetCoord[3] = {
147 TName aXYZName[3] = {X,Y,Z};
150 TGetCoord aXYGetCoord[2] = {
154 TName aXYName[2] = {X,Y};
156 TGetCoord aYZGetCoord[2] = {
160 TName aYZName[2] = {Y,Z};
162 TGetCoord aXZGetCoord[2] = {
166 TName aXZName[2] = {X,Z};
169 TGetCoord aXGetCoord[1] = {
172 TName aXName[1] = {X};
174 TGetCoord aYGetCoord[1] = {
177 TName aYName[1] = {Y};
179 TGetCoord aZGetCoord[1] = {
182 TName aZName[1] = {Z};
186 SMDS_NodeIteratorPtr myNodeIter;
187 const SMDS_MeshNode* myCurrentNode;
188 TGetCoord* myGetCoord;
192 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
193 TGetCoord* theGetCoord,
195 TUnit* theUnit = aUnit):
196 myNodeIter(theNodeIter),
197 myGetCoord(theGetCoord),
201 virtual ~TCoordHelper(){}
203 return myNodeIter->more() &&
204 (myCurrentNode = myNodeIter->next());
206 const SMDS_MeshNode* GetNode(){
207 return myCurrentNode;
209 MED::TIntVector::value_type GetID(){
210 return myCurrentNode->GetID();
212 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
213 return (myCurrentNode->*myGetCoord[theCoodId])();
215 MED::TStringVector::value_type GetName(TInt theDimId){
216 return myName[theDimId];
218 MED::TStringVector::value_type GetUnit(TInt theDimId){
219 return myUnit[theDimId];
222 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
225 //-------------------------------------------------------
227 * \brief Class helping to use either SMDS_EdgeIterator, SMDS_FaceIterator
228 * or SMDS_VolumeIterator in the same code
230 //-------------------------------------------------------
233 virtual const SMDS_MeshElement* next() = 0;
234 virtual ~TElemIterator() {}
236 typedef boost::shared_ptr<TElemIterator> PElemIterator;
238 template< class SMDSIteratorPtr > class TypedElemIterator: public TElemIterator
240 SMDSIteratorPtr myItPtr;
242 TypedElemIterator(SMDSIteratorPtr it): myItPtr(it) {}
243 virtual const SMDS_MeshElement* next() {
244 if ( myItPtr->more() ) return myItPtr->next();
248 typedef TypedElemIterator< SMDS_EdgeIteratorPtr > TEdgeIterator;
249 typedef TypedElemIterator< SMDS_FaceIteratorPtr > TFaceIterator;
250 typedef TypedElemIterator< SMDS_VolumeIteratorPtr > TVolumeIterator;
252 //-------------------------------------------------------
254 * \brief Structure describing element type
256 //-------------------------------------------------------
259 EEntiteMaillage _entity;
260 EGeometrieElement _geomType;
262 SMDSAbs_ElementType _smdsType;
264 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
265 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
269 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
270 //typedef map<const SMDS_MeshElement *, int> TElemFamilyMap;
272 //================================================================================
274 * \brief Fills element to famaly ID map for element type.
275 * Removes all families of anElemType
277 //================================================================================
279 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
280 list<DriverMED_FamilyPtr> & aFamilies,
281 const SMDSAbs_ElementType anElemType)
283 anElemFamMap.Clear();
284 //anElemFamMap.clear();
285 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
286 while ( aFamsIter != aFamilies.end() )
288 if ((*aFamsIter)->GetType() != anElemType) {
292 int aFamId = (*aFamsIter)->GetId();
293 const set<const SMDS_MeshElement *>& anElems = (*aFamsIter)->GetElements();
294 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElems.begin();
295 for (; anElemsIter != anElems.end(); anElemsIter++)
297 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
298 //anElemFamMap[*anElemsIter] = aFamId;
300 // remove a family from the list
301 aFamilies.erase( aFamsIter++ );
306 //================================================================================
308 * \brief For an element, return family ID found in the map or a default one
310 //================================================================================
312 int getFamilyId( const TElemFamilyMap & anElemFamMap,
313 const SMDS_MeshElement* anElement,
314 const int aDefaultFamilyId)
316 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
317 return anElemFamMap( (Standard_Address) anElement );
318 // TElemFamilyMap::iterator elem_famNum = anElemFamMap.find( anElement );
319 // if ( elem_famNum != anElemFamMap.end() )
320 // return elem_famNum->second;
321 return aDefaultFamilyId;
325 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
327 Status aResult = DRS_OK;
328 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
329 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
333 MESSAGE("Perform - myFile : "<<myFile);
335 // Creating the MED mesh for corresponding SMDS structure
336 //-------------------------------------------------------
338 if (myMeshId != -1) {
339 ostringstream aMeshNameStr;
340 aMeshNameStr<<myMeshId;
341 aMeshName = aMeshNameStr.str();
343 aMeshName = myMeshName;
346 // Mesh dimension definition
348 TCoordHelperPtr aCoordHelperPtr;
350 bool anIsXDimension = false;
351 bool anIsYDimension = false;
352 bool anIsZDimension = false;
354 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
356 if(aNodesIter->more()){
357 const SMDS_MeshNode* aNode = aNodesIter->next();
358 aBounds[0] = aBounds[1] = aNode->X();
359 aBounds[2] = aBounds[3] = aNode->Y();
360 aBounds[4] = aBounds[5] = aNode->Z();
362 while(aNodesIter->more()){
363 const SMDS_MeshNode* aNode = aNodesIter->next();
364 aBounds[0] = min(aBounds[0],aNode->X());
365 aBounds[1] = max(aBounds[1],aNode->X());
367 aBounds[2] = min(aBounds[2],aNode->Y());
368 aBounds[3] = max(aBounds[3],aNode->Y());
370 aBounds[4] = min(aBounds[4],aNode->Z());
371 aBounds[5] = max(aBounds[5],aNode->Z());
375 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
376 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
377 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
378 aMeshDimension = anIsXDimension + anIsYDimension + anIsZDimension;
381 // PAL16857(SMESH not conform to the MED convention):
382 if ( aMeshDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
384 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
385 if ( aMeshDimension == 1 && !anIsXDimension ) // 1D only if mesh is along OX
386 if ( anIsYDimension ) {
388 anIsXDimension = true;
394 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
395 switch(aMeshDimension){
397 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
400 if(anIsXDimension && anIsYDimension)
401 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
402 if(anIsYDimension && anIsZDimension)
403 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
404 if(anIsXDimension && anIsZDimension)
405 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
409 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
411 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
413 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
419 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aMeshName);
420 MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
421 myMed->SetMeshInfo(aMeshInfo);
423 // Storing SMDS groups and sub-meshes as med families
424 //----------------------------------------------------
425 int myNodesDefaultFamilyId = 0;
426 int myEdgesDefaultFamilyId = 0;
427 int myFacesDefaultFamilyId = 0;
428 int myVolumesDefaultFamilyId = 0;
429 int nbNodes = myMesh->NbNodes();
430 int nbEdges = myMesh->NbEdges();
431 int nbFaces = myMesh->NbFaces();
432 int nbVolumes = myMesh->NbVolumes();
433 if (myDoGroupOfNodes && nbNodes)
434 myNodesDefaultFamilyId = REST_NODES_FAMILY;
435 if (myDoGroupOfEdges && nbEdges)
436 myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
437 if (myDoGroupOfFaces && nbFaces)
438 myFacesDefaultFamilyId = REST_FACES_FAMILY;
439 if (myDoGroupOfVolumes && nbVolumes)
440 myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
442 MESSAGE("Perform - aFamilyInfo");
443 //cout << " DriverMED_Family::MakeFamilies() " << endl;
444 list<DriverMED_FamilyPtr> aFamilies;
445 if (myAllSubMeshes) {
446 aFamilies = DriverMED_Family::MakeFamilies
447 (myMesh->SubMeshes(), myGroups,
448 myDoGroupOfNodes && nbNodes,
449 myDoGroupOfEdges && nbEdges,
450 myDoGroupOfFaces && nbFaces,
451 myDoGroupOfVolumes && nbVolumes);
453 aFamilies = DriverMED_Family::MakeFamilies
454 (mySubMeshes, myGroups,
455 myDoGroupOfNodes && nbNodes,
456 myDoGroupOfEdges && nbEdges,
457 myDoGroupOfFaces && nbFaces,
458 myDoGroupOfVolumes && nbVolumes);
460 //cout << " myMed->SetFamilyInfo() " << endl;
461 list<DriverMED_FamilyPtr>::iterator aFamsIter;
462 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
464 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
465 myMed->SetFamilyInfo(aFamilyInfo);
468 // Storing SMDS nodes to the MED file for the MED mesh
469 //----------------------------------------------------
470 #ifdef _EDF_NODE_IDS_
471 typedef map<TInt,TInt> TNodeIdMap;
472 TNodeIdMap aNodeIdMap;
474 const EModeSwitch theMode = eFULL_INTERLACE;
475 const ERepere theSystem = eCART;
476 const EBooleen theIsElemNum = eVRAI;
477 const EBooleen theIsElemNames = eFAUX;
478 const EConnectivite theConnMode = eNOD;
480 TInt aNbNodes = myMesh->NbNodes();
481 //cout << " myMed->CrNodeInfo() aNbNodes = " << aNbNodes << endl;
482 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
483 theMode, theSystem, theIsElemNum, theIsElemNames);
485 //cout << " fillElemFamilyMap( SMDSAbs_Node )" << endl;
486 // find family numbers for nodes
487 TElemFamilyMap anElemFamMap;
488 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
490 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
493 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
494 for(TInt iCoord = 0; iCoord < aMeshDimension; iCoord++){
495 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
498 int aNodeID = aCoordHelperPtr->GetID();
499 aNodeInfo->SetElemNum( iNode, aNodeID );
500 #ifdef _EDF_NODE_IDS_
501 aNodeIdMap[aNodeID] = iNode+1;
504 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
505 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
506 aNodeInfo->SetFamNum( iNode, famNum );
508 anElemFamMap.Clear();
510 // coordinate names and units
511 for (TInt iCoord = 0; iCoord < aMeshDimension; iCoord++) {
512 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
513 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
516 //cout << " SetNodeInfo(aNodeInfo)" << endl;
517 MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
518 myMed->SetNodeInfo(aNodeInfo);
519 aNodeInfo.reset(); // free memory used for arrays
522 // Storing SMDS elements to the MED file for the MED mesh
523 //-------------------------------------------------------
524 // Write one element type at once in order to minimize memory usage (PAL19276)
526 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
528 // poly elements are not supported by med-2.1
529 bool polyTypesSupported = myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0);
530 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
532 // collect info on all geom types
534 list< TElemTypeData > aTElemTypeDatas;
536 EEntiteMaillage anEntity = eMAILLE;
537 #ifdef _ELEMENTS_BY_DIM_
540 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
542 nbElemInfo.NbEdges( ORDER_LINEAR ),
544 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
546 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
548 #ifdef _ELEMENTS_BY_DIM_
551 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
553 nbElemInfo.NbTriangles( ORDER_LINEAR ),
555 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
557 nbElemInfo.NbTriangles( ORDER_QUADRATIC ),
559 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
561 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
563 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
565 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ),
567 if ( polyTypesSupported ) {
568 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
570 nbElemInfo.NbPolygons(),
572 // we need one more loop on poly elements to count nb of their nodes
573 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
575 nbElemInfo.NbPolygons(),
578 #ifdef _ELEMENTS_BY_DIM_
581 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
583 nbElemInfo.NbTetras( ORDER_LINEAR ),
585 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
587 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
589 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
591 nbElemInfo.NbPyramids( ORDER_LINEAR ),
593 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
595 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
597 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
599 nbElemInfo.NbPrisms( ORDER_LINEAR ),
601 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
603 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
605 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
607 nbElemInfo.NbHexas( ORDER_LINEAR ),
609 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
611 nbElemInfo.NbHexas( ORDER_QUADRATIC ),
613 if ( polyTypesSupported ) {
614 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
616 nbElemInfo.NbPolyhedrons(),
618 // we need one more loop on poly elements to count nb of their nodes
619 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
621 nbElemInfo.NbPolyhedrons(),
625 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
627 // loop on all geom types of elements
629 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
630 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
632 if ( aElemTypeData->_nbElems == 0 )
635 // iterator on elements of a current type
636 PElemIterator elemIterator;
637 int defaultFamilyId = 0;
638 switch ( aElemTypeData->_smdsType ) {
640 elemIterator = PElemIterator( new TEdgeIterator( myMesh->edgesIterator() ));
641 defaultFamilyId = myEdgesDefaultFamilyId;
644 elemIterator = PElemIterator( new TFaceIterator( myMesh->facesIterator() ));
645 defaultFamilyId = myFacesDefaultFamilyId;
648 elemIterator = PElemIterator( new TVolumeIterator( myMesh->volumesIterator() ));
649 defaultFamilyId = myVolumesDefaultFamilyId;
656 //cout << " Treat type " << aElemTypeData->_geomType << " nb = " <<aElemTypeData->_nbElems<< endl;
659 if ( aElemTypeData->_geomType == ePOLYGONE )
661 if ( nbPolygonNodes == 0 ) {
663 while ( const SMDS_MeshElement* anElem = elemIterator->next() ) {
664 if ( anElem->IsPoly() ) {
665 nbPolygonNodes += anElem->NbNodes();
666 if ( ++iElem == aElemTypeData->_nbElems )
673 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
674 aElemTypeData->_entity,
675 aElemTypeData->_geomType,
676 aElemTypeData->_nbElems,
678 theConnMode, theIsElemNum,
680 TElemNum & index = aPolygoneInfo->myIndex;
683 while ( const SMDS_MeshElement* anElem = elemIterator->next() )
685 if ( !anElem->IsPoly() )
689 TInt aNbNodes = anElem->NbNodes();
690 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
693 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
694 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
695 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
696 #ifdef _EDF_NODE_IDS_
697 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
699 aTConnSlice[ iNode ] = aNode->GetID();
703 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
706 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
707 aPolygoneInfo->SetFamNum( iElem, famNum );
709 if ( ++iElem == aPolygoneInfo->GetNbElem() )
712 // if(TInt aNbElems = aPolygoneElemNums.size())
713 // // add one element in connectivities,
714 // // referenced by the last element in indices
715 // aPolygoneConn.push_back(0);
716 //cout << " SetPolygoneInfo(aPolygoneInfo)" << endl;
717 myMed->SetPolygoneInfo(aPolygoneInfo);
724 else if (aElemTypeData->_geomType == ePOLYEDRE )
726 if ( nbPolyhedronNodes == 0 ) {
728 while ( const SMDS_MeshElement* anElem = elemIterator->next() ) {
729 const SMDS_PolyhedralVolumeOfNodes* aPolyedre =
730 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*>( anElem );
732 nbPolyhedronNodes += aPolyedre->NbNodes();
733 nbPolyhedronFaces += aPolyedre->NbFaces();
734 if ( ++iElem == aElemTypeData->_nbElems )
741 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
742 aElemTypeData->_entity,
743 aElemTypeData->_geomType,
744 aElemTypeData->_nbElems,
750 TElemNum & index = aPolyhInfo->myIndex;
751 TElemNum & faces = aPolyhInfo->myFaces;
752 TElemNum & conn = aPolyhInfo->myConn;
756 TInt iFace = 0, iNode = 0;
757 while ( const SMDS_MeshElement* anElem = elemIterator->next() )
759 const SMDS_PolyhedralVolumeOfNodes* aPolyedre =
760 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*>( anElem );
765 TInt aNbFaces = aPolyedre->NbFaces();
766 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
769 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
770 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
771 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
774 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
775 while ( nodeIt->more() ) {
776 const SMDS_MeshElement* aNode = nodeIt->next();
777 #ifdef _EDF_NODE_IDS_
778 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
780 conn[ iNode ] = aNode->GetID();
785 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
788 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
789 aPolyhInfo->SetFamNum( iElem, famNum );
791 if ( ++iElem == aPolyhInfo->GetNbElem() )
794 //cout << " SetPolyedreInfo(aPolyhInfo )" << endl;
795 myMed->SetPolyedreInfo(aPolyhInfo);
797 } // if (aElemTypeData->_geomType == ePOLYEDRE )
801 // Treat standard types
802 // ---------------------
804 // allocate data arrays
805 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
806 aElemTypeData->_entity,
807 aElemTypeData->_geomType,
808 aElemTypeData->_nbElems,
812 // build map of family numbers for this type
813 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
815 //cout << " fillElemFamilyMap()" << endl;
816 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
817 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
820 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
821 while ( const SMDS_MeshElement* anElem = elemIterator->next() )
823 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
824 continue; // other geometry
827 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
828 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
829 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
830 #ifdef _EDF_NODE_IDS_
831 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
833 aTConnSlice[ iNode ] = aNode->GetID();
837 aCellInfo->SetElemNum( iElem, anElem->GetID() );
840 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
841 aCellInfo->SetFamNum( iElem, famNum );
843 if ( ++iElem == aCellInfo->GetNbElem() )
846 // store data in a file
847 //cout << " SetCellInfo(aCellInfo)" << endl;
848 myMed->SetCellInfo(aCellInfo);
851 } // loop on geom types
855 catch(const std::exception& exc) {
856 INFOS("Follow exception was cought:\n\t"<<exc.what());
860 INFOS("Unknown exception was cought !!!");