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.push_back( 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;
296 //================================================================================
298 * \brief Returns iterator on sub-meshes
300 //================================================================================
302 SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& mySubMeshes )
304 return SMESHDS_SubMeshIteratorPtr
305 ( new SMDS_SetIterator
306 < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(),
307 mySubMeshes.end() ));
311 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
313 Status aResult = DRS_OK;
314 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
315 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
319 MESSAGE("Perform - myFile : "<<myFile);
321 // Creating the MED mesh for corresponding SMDS structure
322 //-------------------------------------------------------
324 if (myMeshId != -1) {
325 ostringstream aMeshNameStr;
326 aMeshNameStr<<myMeshId;
327 aMeshName = aMeshNameStr.str();
329 aMeshName = myMeshName;
332 // Mesh dimension definition
333 TInt aSpaceDimension = 3;
334 TCoordHelperPtr aCoordHelperPtr;
336 bool anIsXDimension = false;
337 bool anIsYDimension = false;
338 bool anIsZDimension = false;
339 if ( myAutoDimension )
341 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
343 if(aNodesIter->more()){
344 const SMDS_MeshNode* aNode = aNodesIter->next();
345 aBounds[0] = aBounds[1] = aNode->X();
346 aBounds[2] = aBounds[3] = aNode->Y();
347 aBounds[4] = aBounds[5] = aNode->Z();
349 while(aNodesIter->more()){
350 const SMDS_MeshNode* aNode = aNodesIter->next();
351 aBounds[0] = min(aBounds[0],aNode->X());
352 aBounds[1] = max(aBounds[1],aNode->X());
354 aBounds[2] = min(aBounds[2],aNode->Y());
355 aBounds[3] = max(aBounds[3],aNode->Y());
357 aBounds[4] = min(aBounds[4],aNode->Z());
358 aBounds[5] = max(aBounds[5],aNode->Z());
362 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
363 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
364 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
365 aSpaceDimension = anIsXDimension + anIsYDimension + anIsZDimension;
368 // PAL16857(SMESH not conform to the MED convention):
369 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
371 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
372 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
373 if ( anIsYDimension ) {
375 anIsXDimension = true;
382 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
383 switch(aSpaceDimension){
385 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
388 if(anIsXDimension && anIsYDimension)
389 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
390 if(anIsYDimension && anIsZDimension)
391 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
392 if(anIsXDimension && anIsZDimension)
393 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
397 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
399 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
401 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
405 TInt aMeshDimension = 0;
406 if ( myMesh->NbEdges() > 0 )
408 if ( myMesh->NbFaces() > 0 )
410 if ( myMesh->NbVolumes() > 0 )
413 MED::PWrapper myMed = CrWrapper(myFile,myMedVersion);
414 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
415 MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
416 myMed->SetMeshInfo(aMeshInfo);
418 // Storing SMDS groups and sub-meshes as med families
419 //----------------------------------------------------
420 int myNodesDefaultFamilyId = 0;
421 int my0DElementsDefaultFamilyId = 0;
422 int myBallsDefaultFamilyId = 0;
423 int myEdgesDefaultFamilyId = 0;
424 int myFacesDefaultFamilyId = 0;
425 int myVolumesDefaultFamilyId = 0;
426 int nbNodes = myMesh->NbNodes();
427 int nb0DElements = myMesh->Nb0DElements();
428 int nbBalls = myMesh->NbBalls();
429 int nbEdges = myMesh->NbEdges();
430 int nbFaces = myMesh->NbFaces();
431 int nbVolumes = myMesh->NbVolumes();
432 if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
433 if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
434 if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
435 if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
436 if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
437 if (myDoGroupOfBalls && nbBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
439 MESSAGE("Perform - aFamilyInfo");
440 list<DriverMED_FamilyPtr> aFamilies;
441 if (myAllSubMeshes) {
442 aFamilies = DriverMED_Family::MakeFamilies
443 (myMesh->SubMeshes(), myGroups,
444 myDoGroupOfNodes && nbNodes,
445 myDoGroupOfEdges && nbEdges,
446 myDoGroupOfFaces && nbFaces,
447 myDoGroupOfVolumes && nbVolumes,
448 myDoGroupOf0DElems && nb0DElements,
449 myDoGroupOfBalls && nbBalls);
451 aFamilies = DriverMED_Family::MakeFamilies
452 (getIterator( mySubMeshes ), myGroups,
453 myDoGroupOfNodes && nbNodes,
454 myDoGroupOfEdges && nbEdges,
455 myDoGroupOfFaces && nbFaces,
456 myDoGroupOfVolumes && nbVolumes,
457 myDoGroupOf0DElems && nb0DElements,
458 myDoGroupOfBalls && nbBalls);
460 list<DriverMED_FamilyPtr>::iterator aFamsIter;
461 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
463 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
464 myMed->SetFamilyInfo(aFamilyInfo);
467 // Storing SMDS nodes to the MED file for the MED mesh
468 //----------------------------------------------------
469 #ifdef _EDF_NODE_IDS_
470 typedef map<TInt,TInt> TNodeIdMap;
471 TNodeIdMap aNodeIdMap;
473 const EModeSwitch theMode = eFULL_INTERLACE;
474 const ERepere theSystem = eCART;
475 const EBooleen theIsElemNum = eVRAI;
476 const EBooleen theIsElemNames = eFAUX;
477 const EConnectivite theConnMode = eNOD;
479 TInt aNbNodes = myMesh->NbNodes();
480 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
481 theMode, theSystem, theIsElemNum, theIsElemNames);
483 //cout << " fillElemFamilyMap( SMDSAbs_Node )" << endl;
484 // find family numbers for nodes
485 TElemFamilyMap anElemFamMap;
486 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
488 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
491 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
492 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
493 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
496 int aNodeID = aCoordHelperPtr->GetID();
497 aNodeInfo->SetElemNum( iNode, aNodeID );
498 #ifdef _EDF_NODE_IDS_
499 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
502 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
503 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
504 aNodeInfo->SetFamNum( iNode, famNum );
506 anElemFamMap.Clear();
508 // coordinate names and units
509 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
510 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
511 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
514 //cout << " SetNodeInfo(aNodeInfo)" << endl;
515 MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
516 myMed->SetNodeInfo(aNodeInfo);
517 aNodeInfo.reset(); // free memory used for arrays
520 // Storing SMDS elements to the MED file for the MED mesh
521 //-------------------------------------------------------
522 // Write one element type at once in order to minimize memory usage (PAL19276)
524 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
526 // poly elements are not supported by med-2.1
527 bool polyTypesSupported = myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0);
528 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
530 // nodes on VERTEXes where 0D elements are absent
531 std::vector<const SMDS_MeshElement*> nodesOf0D;
532 std::vector< SMDS_ElemIteratorPtr > iterVec;
533 SMDS_ElemIteratorPtr iterVecIter;
534 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
537 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
538 iterVec[1] = SMDS_ElemIteratorPtr
539 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
541 typedef SMDS_IteratorOnIterators
542 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
543 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
546 // collect info on all geom types
548 list< TElemTypeData > aTElemTypeDatas;
550 EEntiteMaillage anEntity = eMAILLE;
551 #ifdef _ELEMENTS_BY_DIM_
552 anEntity = eNOEUD_ELEMENT;
554 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
556 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
558 #ifdef _ELEMENTS_BY_DIM_
559 anEntity = eSTRUCT_ELEMENT;
561 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
563 nbElemInfo.NbBalls(),
565 #ifdef _ELEMENTS_BY_DIM_
568 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
570 nbElemInfo.NbEdges( ORDER_LINEAR ),
572 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
574 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
576 #ifdef _ELEMENTS_BY_DIM_
579 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
581 nbElemInfo.NbTriangles( ORDER_LINEAR ),
583 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
585 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
586 nbElemInfo.NbBiQuadTriangles(),
588 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
590 nbElemInfo.NbBiQuadTriangles(),
592 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
594 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
596 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
598 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
599 nbElemInfo.NbBiQuadQuadrangles(),
601 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
603 nbElemInfo.NbBiQuadQuadrangles(),
605 if ( polyTypesSupported ) {
606 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
608 nbElemInfo.NbPolygons(),
610 // we need one more loop on poly elements to count nb of their nodes
611 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
613 nbElemInfo.NbPolygons(),
616 #ifdef _ELEMENTS_BY_DIM_
619 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
621 nbElemInfo.NbTetras( ORDER_LINEAR ),
623 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
625 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
627 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
629 nbElemInfo.NbPyramids( ORDER_LINEAR ),
631 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
633 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
635 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
637 nbElemInfo.NbPrisms( ORDER_LINEAR ),
639 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
641 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
643 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
645 nbElemInfo.NbHexas( ORDER_LINEAR ),
647 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
649 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
650 nbElemInfo.NbTriQuadHexas(),
652 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
654 nbElemInfo.NbTriQuadHexas(),
656 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
658 nbElemInfo.NbHexPrisms(),
660 if ( polyTypesSupported ) {
661 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
663 nbElemInfo.NbPolyhedrons(),
665 // we need one more loop on poly elements to count nb of their nodes
666 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
668 nbElemInfo.NbPolyhedrons(),
672 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
674 // loop on all geom types of elements
676 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
677 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
679 if ( aElemTypeData->_nbElems == 0 )
682 int defaultFamilyId = 0;
683 switch ( aElemTypeData->_smdsType ) {
684 case SMDSAbs_0DElement:
685 defaultFamilyId = my0DElementsDefaultFamilyId;
688 defaultFamilyId = myBallsDefaultFamilyId;
691 defaultFamilyId = myEdgesDefaultFamilyId;
694 defaultFamilyId = myFacesDefaultFamilyId;
697 defaultFamilyId = myVolumesDefaultFamilyId;
703 // iterator on elements of a current type
704 SMDS_ElemIteratorPtr elemIterator;
709 if ( aElemTypeData->_geomType == ePOLYGONE )
711 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYGON );
712 if ( nbPolygonNodes == 0 ) {
714 while ( elemIterator->more() ) {
715 const SMDS_MeshElement* anElem = elemIterator->next();
716 nbPolygonNodes += anElem->NbNodes();
717 if ( ++iElem == aElemTypeData->_nbElems )
723 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
724 aElemTypeData->_entity,
725 aElemTypeData->_geomType,
726 aElemTypeData->_nbElems,
728 theConnMode, theIsElemNum,
730 TElemNum & index = *(aPolygoneInfo->myIndex.get());
733 while ( elemIterator->more() )
735 const SMDS_MeshElement* anElem = elemIterator->next();
737 TInt aNbNodes = anElem->NbNodes();
738 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
741 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
742 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
743 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
744 #ifdef _EDF_NODE_IDS_
745 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
747 aTConnSlice[ iNode ] = aNode->GetID();
751 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
754 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
755 aPolygoneInfo->SetFamNum( iElem, famNum );
757 if ( ++iElem == aPolygoneInfo->GetNbElem() )
760 myMed->SetPolygoneInfo(aPolygoneInfo);
767 else if (aElemTypeData->_geomType == ePOLYEDRE )
769 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
771 if ( nbPolyhedronNodes == 0 ) {
773 while ( elemIterator->more() ) {
774 const SMDS_MeshElement* anElem = elemIterator->next();
775 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
776 if ( !aPolyedre ) continue;
777 nbPolyhedronNodes += aPolyedre->NbNodes();
778 nbPolyhedronFaces += aPolyedre->NbFaces();
779 if ( ++iElem == aElemTypeData->_nbElems )
785 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
786 aElemTypeData->_entity,
787 aElemTypeData->_geomType,
788 aElemTypeData->_nbElems,
794 TElemNum & index = *(aPolyhInfo->myIndex.get());
795 TElemNum & faces = *(aPolyhInfo->myFaces.get());
796 TElemNum & conn = *(aPolyhInfo->myConn.get());
800 TInt iFace = 0, iNode = 0;
801 while ( elemIterator->more() )
803 const SMDS_MeshElement* anElem = elemIterator->next();
804 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
805 if ( !aPolyedre ) continue;
807 TInt aNbFaces = aPolyedre->NbFaces();
808 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
811 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
812 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
813 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
816 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
817 while ( nodeIt->more() ) {
818 const SMDS_MeshElement* aNode = nodeIt->next();
819 #ifdef _EDF_NODE_IDS_
820 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
822 conn[ iNode ] = aNode->GetID();
827 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
830 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
831 aPolyhInfo->SetFamNum( iElem, famNum );
833 if ( ++iElem == aPolyhInfo->GetNbElem() )
836 myMed->SetPolyedreInfo(aPolyhInfo);
838 } // if (aElemTypeData->_geomType == ePOLYEDRE )
842 else if (aElemTypeData->_geomType == eBALL )
844 // allocate data arrays
845 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo,
846 aElemTypeData->_nbElems );
848 // build map of family numbers for this type
849 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
851 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
852 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
855 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
856 while ( elemIterator->more() )
858 const SMDS_MeshElement* anElem = elemIterator->next();
860 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
861 #ifdef _EDF_NODE_IDS_
862 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
864 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
867 aBallInfo->SetElemNum( iElem, anElem->GetID() );
870 aBallInfo->myDiameters[ iElem ] =
871 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
874 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
875 aBallInfo->SetFamNum( iElem, famNum );
878 // store data in a file
879 myMed->SetBallInfo(aBallInfo);
884 // Treat standard types
885 // ---------------------
887 // allocate data arrays
888 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
889 aElemTypeData->_entity,
890 aElemTypeData->_geomType,
891 aElemTypeData->_nbElems,
895 // build map of family numbers for this type
896 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
898 //cout << " fillElemFamilyMap()" << endl;
899 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
900 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
903 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
904 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
905 if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() )
906 elemIterator = iterVecIter;
907 while ( elemIterator->more() )
909 const SMDS_MeshElement* anElem = elemIterator->next();
910 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
911 continue; // other geometry
914 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
915 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
916 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
917 #ifdef _EDF_NODE_IDS_
918 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
920 aTConnSlice[ iNode ] = aNode->GetID();
924 aCellInfo->SetElemNum( iElem, anElem->GetID() );
927 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
928 aCellInfo->SetFamNum( iElem, famNum );
930 if ( ++iElem == aCellInfo->GetNbElem() )
933 // store data in a file
934 myMed->SetCellInfo(aCellInfo);
937 } // loop on geom types
941 catch(const std::exception& exc) {
942 INFOS("The following exception was caught:\n\t"<<exc.what());
946 INFOS("Unknown exception was caught !!!");
956 //================================================================================
958 * \brief Returns nodes on VERTEXes where 0D elements are absent
960 //================================================================================
962 bool DriverMED_W_SMESHDS_Mesh::
963 getNodesOfMissing0DOnVert(SMESHDS_Mesh* meshDS,
964 std::vector<const SMDS_MeshElement*>& nodes)
967 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
969 if ( meshDS->IndexToShape( i ).ShapeType() != TopAbs_VERTEX )
971 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(i) ) {
972 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
975 const SMDS_MeshNode* n = nIt->next();
976 if ( n->NbInverseElements( SMDSAbs_0DElement ) == 0 )
977 nodes.push_back( n );
981 return !nodes.empty();