1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
28 #include "DriverMED_W_SMESHDS_Mesh.h"
30 #include "DriverMED_Family.h"
31 #include "MED_Factory.hxx"
32 #include "MED_Utilities.hxx"
33 #include "SMDS_IteratorOnIterators.hxx"
34 #include "SMDS_MeshElement.hxx"
35 #include "SMDS_MeshNode.hxx"
36 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
37 #include "SMDS_SetIterator.hxx"
38 #include "SMESHDS_Mesh.hxx"
40 #include <utilities.h>
43 #define _EDF_NODE_IDS_
44 //#define _ELEMENTS_BY_DIM_
50 DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
51 myMedVersion(MED::eV2_2),
52 myAllSubMeshes (false),
53 myDoGroupOfNodes (false),
54 myDoGroupOfEdges (false),
55 myDoGroupOfFaces (false),
56 myDoGroupOfVolumes (false),
57 myDoGroupOf0DElems(false),
58 myDoGroupOfBalls(false),
62 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
65 Driver_SMESHDS_Mesh::SetFile(theFileName);
69 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
71 Driver_SMESHDS_Mesh::SetFile(theFileName);
74 string DriverMED_W_SMESHDS_Mesh::GetVersionString(const MED::EVersion theVersion, int theNbDigits)
76 TInt majeur, mineur, release;
77 majeur = mineur = release = 0;
78 // if ( theVersion == eV2_1 )
79 // MED::GetVersionRelease<eV2_1>(majeur, mineur, release);
81 MED::GetVersionRelease<eV2_2>(majeur, mineur, release);
83 if ( theNbDigits > 0 )
85 if ( theNbDigits > 1 )
86 name << "." << mineur;
87 if ( theNbDigits > 2 )
88 name << "." << release;
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;
129 typedef double (SMDS_MeshNode::* TGetCoord)() const;
130 typedef const char* TName;
131 typedef const char* TUnit;
133 // name length in a mesh must be equal to 16 :
140 TUnit aUnit[3] = {M,M,M};
143 TGetCoord aXYZGetCoord[3] = {
148 TName aXYZName[3] = {X,Y,Z};
151 TGetCoord aXYGetCoord[2] = {
155 TName aXYName[2] = {X,Y};
157 TGetCoord aYZGetCoord[2] = {
161 TName aYZName[2] = {Y,Z};
163 TGetCoord aXZGetCoord[2] = {
167 TName aXZName[2] = {X,Z};
170 TGetCoord aXGetCoord[1] = {
173 TName aXName[1] = {X};
175 TGetCoord aYGetCoord[1] = {
178 TName aYName[1] = {Y};
180 TGetCoord aZGetCoord[1] = {
183 TName aZName[1] = {Z};
187 SMDS_NodeIteratorPtr myNodeIter;
188 const SMDS_MeshNode* myCurrentNode;
189 TGetCoord* myGetCoord;
193 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
194 TGetCoord* theGetCoord,
196 TUnit* theUnit = aUnit):
197 myNodeIter(theNodeIter),
198 myGetCoord(theGetCoord),
202 virtual ~TCoordHelper(){}
204 return myNodeIter->more() &&
205 (myCurrentNode = myNodeIter->next());
207 const SMDS_MeshNode* GetNode(){
208 return myCurrentNode;
210 MED::TIntVector::value_type GetID(){
211 return myCurrentNode->GetID();
213 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
214 return (myCurrentNode->*myGetCoord[theCoodId])();
216 MED::TStringVector::value_type GetName(TInt theDimId){
217 return myName[theDimId];
219 MED::TStringVector::value_type GetUnit(TInt theDimId){
220 return myUnit[theDimId];
223 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
225 //-------------------------------------------------------
227 * \brief Structure describing element type
229 //-------------------------------------------------------
232 EEntiteMaillage _entity;
233 EGeometrieElement _geomType;
235 SMDSAbs_ElementType _smdsType;
237 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
238 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
242 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
244 //================================================================================
246 * \brief Fills element to famaly ID map for element type.
247 * Removes all families of anElemType
249 //================================================================================
251 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
252 list<DriverMED_FamilyPtr> & aFamilies,
253 const SMDSAbs_ElementType anElemType)
255 anElemFamMap.Clear();
256 //anElemFamMap.clear();
257 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
258 while ( aFamsIter != aFamilies.end() )
260 if ((*aFamsIter)->GetType() != anElemType) {
264 int aFamId = (*aFamsIter)->GetId();
265 const set<const SMDS_MeshElement *>& anElems = (*aFamsIter)->GetElements();
266 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElems.begin();
267 for (; anElemsIter != anElems.end(); anElemsIter++)
269 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
270 //anElemFamMap[*anElemsIter] = aFamId;
272 // remove a family from the list
273 aFamilies.erase( aFamsIter++ );
278 //================================================================================
280 * \brief For an element, return family ID found in the map or a default one
282 //================================================================================
284 int getFamilyId( const TElemFamilyMap & anElemFamMap,
285 const SMDS_MeshElement* anElement,
286 const int aDefaultFamilyId)
288 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
289 return anElemFamMap( (Standard_Address) anElement );
290 // TElemFamilyMap::iterator elem_famNum = anElemFamMap.find( anElement );
291 // if ( elem_famNum != anElemFamMap.end() )
292 // return elem_famNum->second;
293 return aDefaultFamilyId;
297 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
299 Status aResult = DRS_OK;
300 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
301 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
305 MESSAGE("Perform - myFile : "<<myFile);
307 // Creating the MED mesh for corresponding SMDS structure
308 //-------------------------------------------------------
310 if (myMeshId != -1) {
311 ostringstream aMeshNameStr;
312 aMeshNameStr<<myMeshId;
313 aMeshName = aMeshNameStr.str();
315 aMeshName = myMeshName;
318 // Mesh dimension definition
319 TInt aSpaceDimension = 3;
320 TCoordHelperPtr aCoordHelperPtr;
322 bool anIsXDimension = false;
323 bool anIsYDimension = false;
324 bool anIsZDimension = false;
325 if ( myAutoDimension )
327 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
329 if(aNodesIter->more()){
330 const SMDS_MeshNode* aNode = aNodesIter->next();
331 aBounds[0] = aBounds[1] = aNode->X();
332 aBounds[2] = aBounds[3] = aNode->Y();
333 aBounds[4] = aBounds[5] = aNode->Z();
335 while(aNodesIter->more()){
336 const SMDS_MeshNode* aNode = aNodesIter->next();
337 aBounds[0] = min(aBounds[0],aNode->X());
338 aBounds[1] = max(aBounds[1],aNode->X());
340 aBounds[2] = min(aBounds[2],aNode->Y());
341 aBounds[3] = max(aBounds[3],aNode->Y());
343 aBounds[4] = min(aBounds[4],aNode->Z());
344 aBounds[5] = max(aBounds[5],aNode->Z());
348 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
349 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
350 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
351 aSpaceDimension = anIsXDimension + anIsYDimension + anIsZDimension;
354 // PAL16857(SMESH not conform to the MED convention):
355 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
357 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
358 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
359 if ( anIsYDimension ) {
361 anIsXDimension = true;
368 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
369 switch(aSpaceDimension){
371 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
374 if(anIsXDimension && anIsYDimension)
375 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
376 if(anIsYDimension && anIsZDimension)
377 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
378 if(anIsXDimension && anIsZDimension)
379 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
383 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
385 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
387 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
391 TInt aMeshDimension = 0;
392 if ( myMesh->NbEdges() > 0 )
394 if ( myMesh->NbFaces() > 0 )
396 if ( myMesh->NbVolumes() > 0 )
399 MED::PWrapper myMed = CrWrapper(myFile,myMedVersion);
400 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
401 MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
402 myMed->SetMeshInfo(aMeshInfo);
404 // Storing SMDS groups and sub-meshes as med families
405 //----------------------------------------------------
406 int myNodesDefaultFamilyId = 0;
407 int my0DElementsDefaultFamilyId = 0;
408 int myBallsDefaultFamilyId = 0;
409 int myEdgesDefaultFamilyId = 0;
410 int myFacesDefaultFamilyId = 0;
411 int myVolumesDefaultFamilyId = 0;
412 int nbNodes = myMesh->NbNodes();
413 int nb0DElements = myMesh->Nb0DElements();
414 int nbBalls = myMesh->NbBalls();
415 int nbEdges = myMesh->NbEdges();
416 int nbFaces = myMesh->NbFaces();
417 int nbVolumes = myMesh->NbVolumes();
418 if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
419 if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
420 if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
421 if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
422 if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
423 if (myDoGroupOfBalls && nbBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
425 MESSAGE("Perform - aFamilyInfo");
426 list<DriverMED_FamilyPtr> aFamilies;
427 if (myAllSubMeshes) {
428 aFamilies = DriverMED_Family::MakeFamilies
429 (myMesh->SubMeshes(), myGroups,
430 myDoGroupOfNodes && nbNodes,
431 myDoGroupOfEdges && nbEdges,
432 myDoGroupOfFaces && nbFaces,
433 myDoGroupOfVolumes && nbVolumes,
434 myDoGroupOf0DElems && nb0DElements,
435 myDoGroupOfBalls && nbBalls);
437 aFamilies = DriverMED_Family::MakeFamilies
438 (mySubMeshes, myGroups,
439 myDoGroupOfNodes && nbNodes,
440 myDoGroupOfEdges && nbEdges,
441 myDoGroupOfFaces && nbFaces,
442 myDoGroupOfVolumes && nbVolumes,
443 myDoGroupOf0DElems && nb0DElements,
444 myDoGroupOfBalls && nbBalls);
446 list<DriverMED_FamilyPtr>::iterator aFamsIter;
447 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
449 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
450 myMed->SetFamilyInfo(aFamilyInfo);
453 // Storing SMDS nodes to the MED file for the MED mesh
454 //----------------------------------------------------
455 #ifdef _EDF_NODE_IDS_
456 typedef map<TInt,TInt> TNodeIdMap;
457 TNodeIdMap aNodeIdMap;
459 const EModeSwitch theMode = eFULL_INTERLACE;
460 const ERepere theSystem = eCART;
461 const EBooleen theIsElemNum = eVRAI;
462 const EBooleen theIsElemNames = eFAUX;
463 const EConnectivite theConnMode = eNOD;
465 TInt aNbNodes = myMesh->NbNodes();
466 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
467 theMode, theSystem, theIsElemNum, theIsElemNames);
469 //cout << " fillElemFamilyMap( SMDSAbs_Node )" << endl;
470 // find family numbers for nodes
471 TElemFamilyMap anElemFamMap;
472 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
474 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
477 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
478 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
479 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
482 int aNodeID = aCoordHelperPtr->GetID();
483 aNodeInfo->SetElemNum( iNode, aNodeID );
484 #ifdef _EDF_NODE_IDS_
485 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
488 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
489 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
490 aNodeInfo->SetFamNum( iNode, famNum );
492 anElemFamMap.Clear();
494 // coordinate names and units
495 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
496 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
497 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
500 //cout << " SetNodeInfo(aNodeInfo)" << endl;
501 MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
502 myMed->SetNodeInfo(aNodeInfo);
503 aNodeInfo.reset(); // free memory used for arrays
506 // Storing SMDS elements to the MED file for the MED mesh
507 //-------------------------------------------------------
508 // Write one element type at once in order to minimize memory usage (PAL19276)
510 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
512 // poly elements are not supported by med-2.1
513 bool polyTypesSupported = myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0);
514 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
516 // nodes on VERTEXes where 0D elements are absent
517 std::vector<const SMDS_MeshElement*> nodesOf0D;
518 std::vector< SMDS_ElemIteratorPtr > iterVec;
519 SMDS_ElemIteratorPtr iterVecIter;
520 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
523 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
524 iterVec[1] = SMDS_ElemIteratorPtr
525 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
527 typedef SMDS_IteratorOnIterators
528 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
529 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
532 // collect info on all geom types
534 list< TElemTypeData > aTElemTypeDatas;
536 EEntiteMaillage anEntity = eMAILLE;
537 #ifdef _ELEMENTS_BY_DIM_
538 anEntity = eNOEUD_ELEMENT;
540 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
542 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
544 #ifdef _ELEMENTS_BY_DIM_
545 anEntity = eSTRUCT_ELEMENT;
547 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
549 nbElemInfo.NbBalls(),
551 #ifdef _ELEMENTS_BY_DIM_
554 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
556 nbElemInfo.NbEdges( ORDER_LINEAR ),
558 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
560 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
562 #ifdef _ELEMENTS_BY_DIM_
565 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
567 nbElemInfo.NbTriangles( ORDER_LINEAR ),
569 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
571 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
572 nbElemInfo.NbBiQuadTriangles(),
574 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
576 nbElemInfo.NbBiQuadTriangles(),
578 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
580 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
582 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
584 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
585 nbElemInfo.NbBiQuadQuadrangles(),
587 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
589 nbElemInfo.NbBiQuadQuadrangles(),
591 if ( polyTypesSupported ) {
592 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
594 nbElemInfo.NbPolygons(),
596 // we need one more loop on poly elements to count nb of their nodes
597 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
599 nbElemInfo.NbPolygons(),
602 #ifdef _ELEMENTS_BY_DIM_
605 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
607 nbElemInfo.NbTetras( ORDER_LINEAR ),
609 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
611 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
613 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
615 nbElemInfo.NbPyramids( ORDER_LINEAR ),
617 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
619 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
621 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
623 nbElemInfo.NbPrisms( ORDER_LINEAR ),
625 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
627 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
629 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
631 nbElemInfo.NbHexas( ORDER_LINEAR ),
633 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
635 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
636 nbElemInfo.NbTriQuadHexas(),
638 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
640 nbElemInfo.NbTriQuadHexas(),
642 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
644 nbElemInfo.NbHexPrisms(),
646 if ( polyTypesSupported ) {
647 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
649 nbElemInfo.NbPolyhedrons(),
651 // we need one more loop on poly elements to count nb of their nodes
652 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
654 nbElemInfo.NbPolyhedrons(),
658 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
660 // loop on all geom types of elements
662 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
663 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
665 if ( aElemTypeData->_nbElems == 0 )
668 int defaultFamilyId = 0;
669 switch ( aElemTypeData->_smdsType ) {
670 case SMDSAbs_0DElement:
671 defaultFamilyId = my0DElementsDefaultFamilyId;
674 defaultFamilyId = myBallsDefaultFamilyId;
677 defaultFamilyId = myEdgesDefaultFamilyId;
680 defaultFamilyId = myFacesDefaultFamilyId;
683 defaultFamilyId = myVolumesDefaultFamilyId;
689 // iterator on elements of a current type
690 SMDS_ElemIteratorPtr elemIterator;
695 if ( aElemTypeData->_geomType == ePOLYGONE )
697 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYGON );
698 if ( nbPolygonNodes == 0 ) {
700 while ( elemIterator->more() ) {
701 const SMDS_MeshElement* anElem = elemIterator->next();
702 nbPolygonNodes += anElem->NbNodes();
703 if ( ++iElem == aElemTypeData->_nbElems )
709 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
710 aElemTypeData->_entity,
711 aElemTypeData->_geomType,
712 aElemTypeData->_nbElems,
714 theConnMode, theIsElemNum,
716 TElemNum & index = *(aPolygoneInfo->myIndex.get());
719 while ( elemIterator->more() )
721 const SMDS_MeshElement* anElem = elemIterator->next();
723 TInt aNbNodes = anElem->NbNodes();
724 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
727 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
728 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
729 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
730 #ifdef _EDF_NODE_IDS_
731 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
733 aTConnSlice[ iNode ] = aNode->GetID();
737 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
740 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
741 aPolygoneInfo->SetFamNum( iElem, famNum );
743 if ( ++iElem == aPolygoneInfo->GetNbElem() )
746 myMed->SetPolygoneInfo(aPolygoneInfo);
753 else if (aElemTypeData->_geomType == ePOLYEDRE )
755 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
757 if ( nbPolyhedronNodes == 0 ) {
759 while ( elemIterator->more() ) {
760 const SMDS_MeshElement* anElem = elemIterator->next();
761 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
762 if ( !aPolyedre ) continue;
763 nbPolyhedronNodes += aPolyedre->NbNodes();
764 nbPolyhedronFaces += aPolyedre->NbFaces();
765 if ( ++iElem == aElemTypeData->_nbElems )
771 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
772 aElemTypeData->_entity,
773 aElemTypeData->_geomType,
774 aElemTypeData->_nbElems,
780 TElemNum & index = *(aPolyhInfo->myIndex.get());
781 TElemNum & faces = *(aPolyhInfo->myFaces.get());
782 TElemNum & conn = *(aPolyhInfo->myConn.get());
786 TInt iFace = 0, iNode = 0;
787 while ( elemIterator->more() )
789 const SMDS_MeshElement* anElem = elemIterator->next();
790 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
791 if ( !aPolyedre ) continue;
793 TInt aNbFaces = aPolyedre->NbFaces();
794 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
797 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
798 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
799 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
802 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
803 while ( nodeIt->more() ) {
804 const SMDS_MeshElement* aNode = nodeIt->next();
805 #ifdef _EDF_NODE_IDS_
806 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
808 conn[ iNode ] = aNode->GetID();
813 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
816 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
817 aPolyhInfo->SetFamNum( iElem, famNum );
819 if ( ++iElem == aPolyhInfo->GetNbElem() )
822 myMed->SetPolyedreInfo(aPolyhInfo);
824 } // if (aElemTypeData->_geomType == ePOLYEDRE )
828 else if (aElemTypeData->_geomType == eBALL )
830 // allocate data arrays
831 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo,
832 aElemTypeData->_nbElems );
834 // build map of family numbers for this type
835 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
837 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
838 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
841 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
842 while ( elemIterator->more() )
844 const SMDS_MeshElement* anElem = elemIterator->next();
846 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
847 #ifdef _EDF_NODE_IDS_
848 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
850 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
853 aBallInfo->SetElemNum( iElem, anElem->GetID() );
856 aBallInfo->myDiameters[ iElem ] =
857 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
860 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
861 aBallInfo->SetFamNum( iElem, famNum );
864 // store data in a file
865 myMed->SetBallInfo(aBallInfo);
870 // Treat standard types
871 // ---------------------
873 // allocate data arrays
874 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
875 aElemTypeData->_entity,
876 aElemTypeData->_geomType,
877 aElemTypeData->_nbElems,
881 // build map of family numbers for this type
882 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
884 //cout << " fillElemFamilyMap()" << endl;
885 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
886 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
889 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
890 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
891 if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() )
892 elemIterator = iterVecIter;
893 while ( elemIterator->more() )
895 const SMDS_MeshElement* anElem = elemIterator->next();
896 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
897 continue; // other geometry
900 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
901 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
902 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
903 #ifdef _EDF_NODE_IDS_
904 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
906 aTConnSlice[ iNode ] = aNode->GetID();
910 aCellInfo->SetElemNum( iElem, anElem->GetID() );
913 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
914 aCellInfo->SetFamNum( iElem, famNum );
916 if ( ++iElem == aCellInfo->GetNbElem() )
919 // store data in a file
920 myMed->SetCellInfo(aCellInfo);
923 } // loop on geom types
927 catch(const std::exception& exc) {
928 INFOS("The following exception was caught:\n\t"<<exc.what());
932 INFOS("Unknown exception was caught !!!");
942 //================================================================================
944 * \brief Returns nodes on VERTEXes where 0D elements are absent
946 //================================================================================
948 bool DriverMED_W_SMESHDS_Mesh::
949 getNodesOfMissing0DOnVert(SMESHDS_Mesh* meshDS,
950 std::vector<const SMDS_MeshElement*>& nodes)
953 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
955 if ( meshDS->IndexToShape( i ).ShapeType() != TopAbs_VERTEX )
957 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(i) ) {
958 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
961 const SMDS_MeshNode* n = nIt->next();
962 if ( n->NbInverseElements( SMDSAbs_0DElement ) == 0 )
963 nodes.push_back( n );
967 return !nodes.empty();