1 // Copyright (C) 2007-2012 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)
56 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
59 myMed = CrWrapper(theFileName,theId);
60 Driver_SMESHDS_Mesh::SetFile(theFileName);
63 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
65 return SetFile(theFileName,MED::eV2_2);
68 string DriverMED_W_SMESHDS_Mesh::GetVersionString(const MED::EVersion theVersion, int theNbDigits)
70 TInt majeur, mineur, release;
71 majeur = mineur = release = 0;
72 // if ( theVersion == eV2_1 )
73 // MED::GetVersionRelease<eV2_1>(majeur, mineur, release);
75 MED::GetVersionRelease<eV2_2>(majeur, mineur, release);
77 if ( theNbDigits > 0 )
79 if ( theNbDigits > 1 )
80 name << "." << mineur;
81 if ( theNbDigits > 2 )
82 name << "." << release;
86 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
88 myGroups.push_back(theGroup);
91 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
93 myAllSubMeshes = true;
96 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
98 mySubMeshes[theID] = theSubMesh;
101 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
103 myDoGroupOfNodes = true;
106 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
108 myDoGroupOfEdges = true;
111 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
113 myDoGroupOfFaces = true;
116 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
118 myDoGroupOfVolumes = true;
122 typedef double (SMDS_MeshNode::* TGetCoord)() const;
123 typedef const char* TName;
124 typedef const char* TUnit;
126 // name length in a mesh must be equal to 16 :
133 TUnit aUnit[3] = {M,M,M};
136 TGetCoord aXYZGetCoord[3] = {
141 TName aXYZName[3] = {X,Y,Z};
144 TGetCoord aXYGetCoord[2] = {
148 TName aXYName[2] = {X,Y};
150 TGetCoord aYZGetCoord[2] = {
154 TName aYZName[2] = {Y,Z};
156 TGetCoord aXZGetCoord[2] = {
160 TName aXZName[2] = {X,Z};
163 TGetCoord aXGetCoord[1] = {
166 TName aXName[1] = {X};
168 TGetCoord aYGetCoord[1] = {
171 TName aYName[1] = {Y};
173 TGetCoord aZGetCoord[1] = {
176 TName aZName[1] = {Z};
180 SMDS_NodeIteratorPtr myNodeIter;
181 const SMDS_MeshNode* myCurrentNode;
182 TGetCoord* myGetCoord;
186 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
187 TGetCoord* theGetCoord,
189 TUnit* theUnit = aUnit):
190 myNodeIter(theNodeIter),
191 myGetCoord(theGetCoord),
195 virtual ~TCoordHelper(){}
197 return myNodeIter->more() &&
198 (myCurrentNode = myNodeIter->next());
200 const SMDS_MeshNode* GetNode(){
201 return myCurrentNode;
203 MED::TIntVector::value_type GetID(){
204 return myCurrentNode->GetID();
206 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
207 return (myCurrentNode->*myGetCoord[theCoodId])();
209 MED::TStringVector::value_type GetName(TInt theDimId){
210 return myName[theDimId];
212 MED::TStringVector::value_type GetUnit(TInt theDimId){
213 return myUnit[theDimId];
216 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
218 //-------------------------------------------------------
220 * \brief Structure describing element type
222 //-------------------------------------------------------
225 EEntiteMaillage _entity;
226 EGeometrieElement _geomType;
228 SMDSAbs_ElementType _smdsType;
230 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
231 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
235 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
237 //================================================================================
239 * \brief Fills element to famaly ID map for element type.
240 * Removes all families of anElemType
242 //================================================================================
244 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
245 list<DriverMED_FamilyPtr> & aFamilies,
246 const SMDSAbs_ElementType anElemType)
248 anElemFamMap.Clear();
249 //anElemFamMap.clear();
250 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
251 while ( aFamsIter != aFamilies.end() )
253 if ((*aFamsIter)->GetType() != anElemType) {
257 int aFamId = (*aFamsIter)->GetId();
258 const set<const SMDS_MeshElement *>& anElems = (*aFamsIter)->GetElements();
259 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElems.begin();
260 for (; anElemsIter != anElems.end(); anElemsIter++)
262 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
263 //anElemFamMap[*anElemsIter] = aFamId;
265 // remove a family from the list
266 aFamilies.erase( aFamsIter++ );
271 //================================================================================
273 * \brief For an element, return family ID found in the map or a default one
275 //================================================================================
277 int getFamilyId( const TElemFamilyMap & anElemFamMap,
278 const SMDS_MeshElement* anElement,
279 const int aDefaultFamilyId)
281 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
282 return anElemFamMap( (Standard_Address) anElement );
283 // TElemFamilyMap::iterator elem_famNum = anElemFamMap.find( anElement );
284 // if ( elem_famNum != anElemFamMap.end() )
285 // return elem_famNum->second;
286 return aDefaultFamilyId;
290 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
292 Status aResult = DRS_OK;
293 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
294 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
298 MESSAGE("Perform - myFile : "<<myFile);
300 // Creating the MED mesh for corresponding SMDS structure
301 //-------------------------------------------------------
303 if (myMeshId != -1) {
304 ostringstream aMeshNameStr;
305 aMeshNameStr<<myMeshId;
306 aMeshName = aMeshNameStr.str();
308 aMeshName = myMeshName;
311 // Mesh dimension definition
312 TInt aSpaceDimension;
313 TCoordHelperPtr aCoordHelperPtr;
315 bool anIsXDimension = false;
316 bool anIsYDimension = false;
317 bool anIsZDimension = false;
319 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
321 if(aNodesIter->more()){
322 const SMDS_MeshNode* aNode = aNodesIter->next();
323 aBounds[0] = aBounds[1] = aNode->X();
324 aBounds[2] = aBounds[3] = aNode->Y();
325 aBounds[4] = aBounds[5] = aNode->Z();
327 while(aNodesIter->more()){
328 const SMDS_MeshNode* aNode = aNodesIter->next();
329 aBounds[0] = min(aBounds[0],aNode->X());
330 aBounds[1] = max(aBounds[1],aNode->X());
332 aBounds[2] = min(aBounds[2],aNode->Y());
333 aBounds[3] = max(aBounds[3],aNode->Y());
335 aBounds[4] = min(aBounds[4],aNode->Z());
336 aBounds[5] = max(aBounds[5],aNode->Z());
340 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
341 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
342 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
343 aSpaceDimension = anIsXDimension + anIsYDimension + anIsZDimension;
346 // PAL16857(SMESH not conform to the MED convention):
347 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
349 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
350 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
351 if ( anIsYDimension ) {
353 anIsXDimension = true;
360 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
361 switch(aSpaceDimension){
363 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
366 if(anIsXDimension && anIsYDimension)
367 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
368 if(anIsYDimension && anIsZDimension)
369 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
370 if(anIsXDimension && anIsZDimension)
371 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
375 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
377 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
379 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
383 TInt aMeshDimension = 0;
384 if ( myMesh->NbEdges() > 0 )
386 if ( myMesh->NbFaces() > 0 )
388 if ( myMesh->NbVolumes() > 0 )
391 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
392 MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
393 myMed->SetMeshInfo(aMeshInfo);
395 // Storing SMDS groups and sub-meshes as med families
396 //----------------------------------------------------
397 int myNodesDefaultFamilyId = 0;
398 int my0DElementsDefaultFamilyId = 0;
399 int myBallsDefaultFamilyId = 0;
400 int myEdgesDefaultFamilyId = 0;
401 int myFacesDefaultFamilyId = 0;
402 int myVolumesDefaultFamilyId = 0;
403 int nbNodes = myMesh->NbNodes();
404 int nb0DElements = myMesh->Nb0DElements();
405 int nbBalls = myMesh->NbBalls();
406 int nbEdges = myMesh->NbEdges();
407 int nbFaces = myMesh->NbFaces();
408 int nbVolumes = myMesh->NbVolumes();
409 if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
410 if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
411 if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
412 if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
413 if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
414 if (myDoGroupOfVolumes && nbVolumes) myBallsDefaultFamilyId = REST_BALL_FAMILY;
416 MESSAGE("Perform - aFamilyInfo");
417 //cout << " DriverMED_Family::MakeFamilies() " << endl;
418 list<DriverMED_FamilyPtr> aFamilies;
419 if (myAllSubMeshes) {
420 aFamilies = DriverMED_Family::MakeFamilies
421 (myMesh->SubMeshes(), myGroups,
422 myDoGroupOfNodes && nbNodes,
423 myDoGroupOfEdges && nbEdges,
424 myDoGroupOfFaces && nbFaces,
425 myDoGroupOfVolumes && nbVolumes,
426 myDoGroupOf0DElems && nb0DElements,
427 myDoGroupOfBalls && nbBalls);
429 aFamilies = DriverMED_Family::MakeFamilies
430 (mySubMeshes, myGroups,
431 myDoGroupOfNodes && nbNodes,
432 myDoGroupOfEdges && nbEdges,
433 myDoGroupOfFaces && nbFaces,
434 myDoGroupOfVolumes && nbVolumes,
435 myDoGroupOf0DElems && nb0DElements,
436 myDoGroupOfBalls && nbBalls);
438 //cout << " myMed->SetFamilyInfo() " << endl;
439 list<DriverMED_FamilyPtr>::iterator aFamsIter;
440 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
442 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
443 myMed->SetFamilyInfo(aFamilyInfo);
446 // Storing SMDS nodes to the MED file for the MED mesh
447 //----------------------------------------------------
448 #ifdef _EDF_NODE_IDS_
449 typedef map<TInt,TInt> TNodeIdMap;
450 TNodeIdMap aNodeIdMap;
452 const EModeSwitch theMode = eFULL_INTERLACE;
453 const ERepere theSystem = eCART;
454 const EBooleen theIsElemNum = eVRAI;
455 const EBooleen theIsElemNames = eFAUX;
456 const EConnectivite theConnMode = eNOD;
458 TInt aNbNodes = myMesh->NbNodes();
459 //cout << " myMed->CrNodeInfo() aNbNodes = " << aNbNodes << endl;
460 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
461 theMode, theSystem, theIsElemNum, theIsElemNames);
463 //cout << " fillElemFamilyMap( SMDSAbs_Node )" << endl;
464 // find family numbers for nodes
465 TElemFamilyMap anElemFamMap;
466 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
468 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
471 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
472 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
473 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
476 int aNodeID = aCoordHelperPtr->GetID();
477 aNodeInfo->SetElemNum( iNode, aNodeID );
478 #ifdef _EDF_NODE_IDS_
479 aNodeIdMap[aNodeID] = iNode+1;
482 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
483 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
484 aNodeInfo->SetFamNum( iNode, famNum );
486 anElemFamMap.Clear();
488 // coordinate names and units
489 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
490 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
491 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
494 //cout << " SetNodeInfo(aNodeInfo)" << endl;
495 MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
496 myMed->SetNodeInfo(aNodeInfo);
497 aNodeInfo.reset(); // free memory used for arrays
500 // Storing SMDS elements to the MED file for the MED mesh
501 //-------------------------------------------------------
502 // Write one element type at once in order to minimize memory usage (PAL19276)
504 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
506 // poly elements are not supported by med-2.1
507 bool polyTypesSupported = myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0);
508 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
510 // collect info on all geom types
512 list< TElemTypeData > aTElemTypeDatas;
514 EEntiteMaillage anEntity = eMAILLE;
515 #ifdef _ELEMENTS_BY_DIM_
516 anEntity = eNOEUD_ELEMENT;
518 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
520 nbElemInfo.Nb0DElements(),
522 #ifdef _ELEMENTS_BY_DIM_
523 anEntity = eSTRUCT_ELEMENT;
525 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
527 nbElemInfo.NbBalls(),
529 #ifdef _ELEMENTS_BY_DIM_
532 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
534 nbElemInfo.NbEdges( ORDER_LINEAR ),
536 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
538 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
540 #ifdef _ELEMENTS_BY_DIM_
543 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
545 nbElemInfo.NbTriangles( ORDER_LINEAR ),
547 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
549 nbElemInfo.NbTriangles( ORDER_QUADRATIC ),
551 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
553 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
555 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
557 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
558 nbElemInfo.NbBiQuadQuadrangles(),
560 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
562 nbElemInfo.NbBiQuadQuadrangles(),
564 if ( polyTypesSupported ) {
565 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
567 nbElemInfo.NbPolygons(),
569 // we need one more loop on poly elements to count nb of their nodes
570 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
572 nbElemInfo.NbPolygons(),
575 #ifdef _ELEMENTS_BY_DIM_
578 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
580 nbElemInfo.NbTetras( ORDER_LINEAR ),
582 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
584 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
586 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
588 nbElemInfo.NbPyramids( ORDER_LINEAR ),
590 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
592 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
594 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
596 nbElemInfo.NbPrisms( ORDER_LINEAR ),
598 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
600 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
602 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
604 nbElemInfo.NbHexas( ORDER_LINEAR ),
606 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
608 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
609 nbElemInfo.NbTriQuadHexas(),
611 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
613 nbElemInfo.NbTriQuadHexas(),
615 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
617 nbElemInfo.NbHexPrisms(),
619 if ( polyTypesSupported ) {
620 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
622 nbElemInfo.NbPolyhedrons(),
624 // we need one more loop on poly elements to count nb of their nodes
625 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
627 nbElemInfo.NbPolyhedrons(),
631 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
633 // loop on all geom types of elements
635 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
636 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
638 if ( aElemTypeData->_nbElems == 0 )
641 int defaultFamilyId = 0;
642 switch ( aElemTypeData->_smdsType ) {
643 case SMDSAbs_0DElement:
644 defaultFamilyId = my0DElementsDefaultFamilyId;
647 defaultFamilyId = myBallsDefaultFamilyId;
650 defaultFamilyId = myEdgesDefaultFamilyId;
653 defaultFamilyId = myFacesDefaultFamilyId;
656 defaultFamilyId = myVolumesDefaultFamilyId;
662 // iterator on elements of a current type
663 SMDS_ElemIteratorPtr elemIterator;
668 if ( aElemTypeData->_geomType == ePOLYGONE )
670 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYGON );
671 if ( nbPolygonNodes == 0 ) {
673 while ( elemIterator->more() ) {
674 const SMDS_MeshElement* anElem = elemIterator->next();
675 nbPolygonNodes += anElem->NbNodes();
676 if ( ++iElem == aElemTypeData->_nbElems )
682 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
683 aElemTypeData->_entity,
684 aElemTypeData->_geomType,
685 aElemTypeData->_nbElems,
687 theConnMode, theIsElemNum,
689 TElemNum & index = *(aPolygoneInfo->myIndex.get());
692 while ( elemIterator->more() )
694 const SMDS_MeshElement* anElem = elemIterator->next();
696 TInt aNbNodes = anElem->NbNodes();
697 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
700 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
701 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
702 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
703 #ifdef _EDF_NODE_IDS_
704 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
706 aTConnSlice[ iNode ] = aNode->GetID();
710 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
713 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
714 aPolygoneInfo->SetFamNum( iElem, famNum );
716 if ( ++iElem == aPolygoneInfo->GetNbElem() )
719 myMed->SetPolygoneInfo(aPolygoneInfo);
726 else if (aElemTypeData->_geomType == ePOLYEDRE )
728 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
730 if ( nbPolyhedronNodes == 0 ) {
732 while ( elemIterator->more() ) {
733 const SMDS_MeshElement* anElem = elemIterator->next();
734 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
735 if ( !aPolyedre ) continue;
736 nbPolyhedronNodes += aPolyedre->NbNodes();
737 nbPolyhedronFaces += aPolyedre->NbFaces();
738 if ( ++iElem == aElemTypeData->_nbElems )
744 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
745 aElemTypeData->_entity,
746 aElemTypeData->_geomType,
747 aElemTypeData->_nbElems,
753 TElemNum & index = *(aPolyhInfo->myIndex.get());
754 TElemNum & faces = *(aPolyhInfo->myFaces.get());
755 TElemNum & conn = *(aPolyhInfo->myConn.get());
759 TInt iFace = 0, iNode = 0;
760 while ( elemIterator->more() )
762 const SMDS_MeshElement* anElem = elemIterator->next();
763 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
764 if ( !aPolyedre ) continue;
766 TInt aNbFaces = aPolyedre->NbFaces();
767 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
770 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
771 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
772 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
775 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
776 while ( nodeIt->more() ) {
777 const SMDS_MeshElement* aNode = nodeIt->next();
778 #ifdef _EDF_NODE_IDS_
779 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
781 conn[ iNode ] = aNode->GetID();
786 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
789 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
790 aPolyhInfo->SetFamNum( iElem, famNum );
792 if ( ++iElem == aPolyhInfo->GetNbElem() )
795 myMed->SetPolyedreInfo(aPolyhInfo);
797 } // if (aElemTypeData->_geomType == ePOLYEDRE )
801 else if (aElemTypeData->_geomType == eBALL )
803 // allocate data arrays
804 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo,
805 aElemTypeData->_nbElems );
807 // build map of family numbers for this type
808 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
810 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
811 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
814 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
815 while ( elemIterator->more() )
817 const SMDS_MeshElement* anElem = elemIterator->next();
819 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
820 #ifdef _EDF_NODE_IDS_
821 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
823 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
826 aBallInfo->SetElemNum( iElem, anElem->GetID() );
829 aBallInfo->myDiameters[ iElem ] =
830 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
833 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
834 aBallInfo->SetFamNum( iElem, famNum );
837 // store data in a file
838 myMed->SetBallInfo(aBallInfo);
843 // Treat standard types
844 // ---------------------
846 // allocate data arrays
847 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
848 aElemTypeData->_entity,
849 aElemTypeData->_geomType,
850 aElemTypeData->_nbElems,
854 // build map of family numbers for this type
855 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
857 //cout << " fillElemFamilyMap()" << endl;
858 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
859 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
862 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
863 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
864 while ( elemIterator->more() )
866 const SMDS_MeshElement* anElem = elemIterator->next();
867 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
868 continue; // other geometry
871 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
872 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
873 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
874 #ifdef _EDF_NODE_IDS_
875 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
877 aTConnSlice[ iNode ] = aNode->GetID();
881 aCellInfo->SetElemNum( iElem, anElem->GetID() );
884 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
885 aCellInfo->SetFamNum( iElem, famNum );
887 if ( ++iElem == aCellInfo->GetNbElem() )
890 // store data in a file
891 myMed->SetCellInfo(aCellInfo);
894 } // loop on geom types
898 catch(const std::exception& exc) {
899 INFOS("The following exception was caught:\n\t"<<exc.what());
903 INFOS("Unknown exception was caught !!!");