1 // Copyright (C) 2007-2015 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),
59 myAutoDimension(true),
60 myAddODOnVertices(false)
63 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
66 Driver_SMESHDS_Mesh::SetFile(theFileName);
70 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
72 Driver_SMESHDS_Mesh::SetFile(theFileName);
75 string DriverMED_W_SMESHDS_Mesh::GetVersionString(const MED::EVersion theVersion, int theNbDigits)
77 TInt majeur, mineur, release;
78 majeur = mineur = release = 0;
79 // if ( theVersion == eV2_1 )
80 // MED::GetVersionRelease<eV2_1>(majeur, mineur, release);
82 MED::GetVersionRelease<eV2_2>(majeur, mineur, release);
84 if ( theNbDigits > 0 )
86 if ( theNbDigits > 1 )
87 name << "." << mineur;
88 if ( theNbDigits > 2 )
89 name << "." << release;
93 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
95 myGroups.push_back(theGroup);
98 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
100 myAllSubMeshes = true;
103 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
105 mySubMeshes.push_back( theSubMesh );
108 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
110 myDoGroupOfNodes = true;
113 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
115 myDoGroupOfEdges = true;
118 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
120 myDoGroupOfFaces = true;
123 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
125 myDoGroupOfVolumes = true;
130 typedef double (SMDS_MeshNode::* TGetCoord)() const;
131 typedef const char* TName;
132 typedef const char* TUnit;
134 // name length in a mesh must be equal to 16 :
141 TUnit aUnit[3] = {M,M,M};
144 TGetCoord aXYZGetCoord[3] = {
149 TName aXYZName[3] = {X,Y,Z};
152 TGetCoord aXYGetCoord[2] = {
156 TName aXYName[2] = {X,Y};
158 TGetCoord aYZGetCoord[2] = {
162 TName aYZName[2] = {Y,Z};
164 TGetCoord aXZGetCoord[2] = {
168 TName aXZName[2] = {X,Z};
171 TGetCoord aXGetCoord[1] = {
174 TName aXName[1] = {X};
176 TGetCoord aYGetCoord[1] = {
179 TName aYName[1] = {Y};
181 TGetCoord aZGetCoord[1] = {
184 TName aZName[1] = {Z};
188 SMDS_NodeIteratorPtr myNodeIter;
189 const SMDS_MeshNode* myCurrentNode;
190 TGetCoord* myGetCoord;
194 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
195 TGetCoord* theGetCoord,
197 TUnit* theUnit = aUnit):
198 myNodeIter(theNodeIter),
199 myGetCoord(theGetCoord),
203 virtual ~TCoordHelper(){}
205 return myNodeIter->more() &&
206 (myCurrentNode = myNodeIter->next());
208 const SMDS_MeshNode* GetNode(){
209 return myCurrentNode;
211 MED::TIntVector::value_type GetID(){
212 return myCurrentNode->GetID();
214 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
215 return (myCurrentNode->*myGetCoord[theCoodId])();
217 MED::TStringVector::value_type GetName(TInt theDimId){
218 return myName[theDimId];
220 MED::TStringVector::value_type GetUnit(TInt theDimId){
221 return myUnit[theDimId];
224 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
226 //-------------------------------------------------------
228 * \brief Structure describing element type
230 //-------------------------------------------------------
233 EEntiteMaillage _entity;
234 EGeometrieElement _geomType;
236 SMDSAbs_ElementType _smdsType;
238 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
239 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
243 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
245 //================================================================================
247 * \brief Fills element to famaly ID map for element type.
248 * Removes all families of anElemType
250 //================================================================================
252 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
253 list<DriverMED_FamilyPtr> & aFamilies,
254 const SMDSAbs_ElementType anElemType)
256 anElemFamMap.Clear();
257 //anElemFamMap.clear();
258 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
259 while ( aFamsIter != aFamilies.end() )
261 if ((*aFamsIter)->GetType() != anElemType) {
265 int aFamId = (*aFamsIter)->GetId();
266 const set<const SMDS_MeshElement *>& anElems = (*aFamsIter)->GetElements();
267 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElems.begin();
268 for (; anElemsIter != anElems.end(); anElemsIter++)
270 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
271 //anElemFamMap[*anElemsIter] = aFamId;
273 // remove a family from the list
274 aFamilies.erase( aFamsIter++ );
279 //================================================================================
281 * \brief For an element, return family ID found in the map or a default one
283 //================================================================================
285 int getFamilyId( const TElemFamilyMap & anElemFamMap,
286 const SMDS_MeshElement* anElement,
287 const int aDefaultFamilyId)
289 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
290 return anElemFamMap( (Standard_Address) anElement );
291 // TElemFamilyMap::iterator elem_famNum = anElemFamMap.find( anElement );
292 // if ( elem_famNum != anElemFamMap.end() )
293 // return elem_famNum->second;
294 return aDefaultFamilyId;
297 //================================================================================
299 * \brief Returns iterator on sub-meshes
301 //================================================================================
303 SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& mySubMeshes )
305 return SMESHDS_SubMeshIteratorPtr
306 ( new SMDS_SetIterator
307 < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(),
308 mySubMeshes.end() ));
312 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
314 Status aResult = DRS_OK;
315 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
316 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
320 MESSAGE("Perform - myFile : "<<myFile);
322 // Creating the MED mesh for corresponding SMDS structure
323 //-------------------------------------------------------
325 if (myMeshId != -1) {
326 ostringstream aMeshNameStr;
327 aMeshNameStr<<myMeshId;
328 aMeshName = aMeshNameStr.str();
330 aMeshName = myMeshName;
333 // Mesh dimension definition
334 TInt aSpaceDimension = 3;
335 TCoordHelperPtr aCoordHelperPtr;
337 bool anIsXDimension = false;
338 bool anIsYDimension = false;
339 bool anIsZDimension = false;
340 if ( myAutoDimension )
342 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
344 if(aNodesIter->more()){
345 const SMDS_MeshNode* aNode = aNodesIter->next();
346 aBounds[0] = aBounds[1] = aNode->X();
347 aBounds[2] = aBounds[3] = aNode->Y();
348 aBounds[4] = aBounds[5] = aNode->Z();
350 while(aNodesIter->more()){
351 const SMDS_MeshNode* aNode = aNodesIter->next();
352 aBounds[0] = min(aBounds[0],aNode->X());
353 aBounds[1] = max(aBounds[1],aNode->X());
355 aBounds[2] = min(aBounds[2],aNode->Y());
356 aBounds[3] = max(aBounds[3],aNode->Y());
358 aBounds[4] = min(aBounds[4],aNode->Z());
359 aBounds[5] = max(aBounds[5],aNode->Z());
363 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
364 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
365 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
366 aSpaceDimension = anIsXDimension + anIsYDimension + anIsZDimension;
369 // PAL16857(SMESH not conform to the MED convention):
370 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
372 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
373 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
374 if ( anIsYDimension ) {
376 anIsXDimension = true;
383 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
384 switch(aSpaceDimension){
386 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
389 if(anIsXDimension && anIsYDimension)
390 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
391 if(anIsYDimension && anIsZDimension)
392 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
393 if(anIsXDimension && anIsZDimension)
394 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
398 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
400 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
402 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
406 TInt aMeshDimension = 0;
407 if ( myMesh->NbEdges() > 0 )
409 if ( myMesh->NbFaces() > 0 )
411 if ( myMesh->NbVolumes() > 0 )
414 MED::PWrapper myMed = CrWrapper(myFile,myMedVersion);
415 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
416 MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
417 myMed->SetMeshInfo(aMeshInfo);
419 // Storing SMDS groups and sub-meshes as med families
420 //----------------------------------------------------
421 int myNodesDefaultFamilyId = 0;
422 int my0DElementsDefaultFamilyId = 0;
423 int myBallsDefaultFamilyId = 0;
424 int myEdgesDefaultFamilyId = 0;
425 int myFacesDefaultFamilyId = 0;
426 int myVolumesDefaultFamilyId = 0;
427 int nbNodes = myMesh->NbNodes();
428 int nb0DElements = myMesh->Nb0DElements();
429 int nbBalls = myMesh->NbBalls();
430 int nbEdges = myMesh->NbEdges();
431 int nbFaces = myMesh->NbFaces();
432 int nbVolumes = myMesh->NbVolumes();
433 if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
434 if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
435 if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
436 if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
437 if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
438 if (myDoGroupOfBalls && nbBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
440 MESSAGE("Perform - aFamilyInfo");
441 list<DriverMED_FamilyPtr> aFamilies;
442 if (myAllSubMeshes) {
443 aFamilies = DriverMED_Family::MakeFamilies
444 (myMesh->SubMeshes(), myGroups,
445 myDoGroupOfNodes && nbNodes,
446 myDoGroupOfEdges && nbEdges,
447 myDoGroupOfFaces && nbFaces,
448 myDoGroupOfVolumes && nbVolumes,
449 myDoGroupOf0DElems && nb0DElements,
450 myDoGroupOfBalls && nbBalls);
452 aFamilies = DriverMED_Family::MakeFamilies
453 (getIterator( mySubMeshes ), myGroups,
454 myDoGroupOfNodes && nbNodes,
455 myDoGroupOfEdges && nbEdges,
456 myDoGroupOfFaces && nbFaces,
457 myDoGroupOfVolumes && nbVolumes,
458 myDoGroupOf0DElems && nb0DElements,
459 myDoGroupOfBalls && nbBalls);
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 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
482 theMode, theSystem, theIsElemNum, theIsElemNames);
484 //cout << " fillElemFamilyMap( SMDSAbs_Node )" << endl;
485 // find family numbers for nodes
486 TElemFamilyMap anElemFamMap;
487 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
489 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
492 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
493 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
494 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
497 int aNodeID = aCoordHelperPtr->GetID();
498 aNodeInfo->SetElemNum( iNode, aNodeID );
499 #ifdef _EDF_NODE_IDS_
500 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
503 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
504 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
505 aNodeInfo->SetFamNum( iNode, famNum );
507 anElemFamMap.Clear();
509 // coordinate names and units
510 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
511 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
512 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
515 //cout << " SetNodeInfo(aNodeInfo)" << endl;
516 MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
517 myMed->SetNodeInfo(aNodeInfo);
518 aNodeInfo.reset(); // free memory used for arrays
521 // Storing SMDS elements to the MED file for the MED mesh
522 //-------------------------------------------------------
523 // Write one element type at once in order to minimize memory usage (PAL19276)
525 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
527 // poly elements are not supported by med-2.1
528 bool polyTypesSupported = myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0);
529 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
531 // nodes on VERTEXes where 0D elements are absent
532 std::vector<const SMDS_MeshElement*> nodesOf0D;
533 std::vector< SMDS_ElemIteratorPtr > iterVec;
534 SMDS_ElemIteratorPtr iterVecIter;
535 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
538 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
539 iterVec[1] = SMDS_ElemIteratorPtr
540 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
542 typedef SMDS_IteratorOnIterators
543 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
544 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
547 // collect info on all geom types
549 list< TElemTypeData > aTElemTypeDatas;
551 EEntiteMaillage anEntity = eMAILLE;
552 #ifdef _ELEMENTS_BY_DIM_
553 anEntity = eNOEUD_ELEMENT;
555 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
557 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
559 #ifdef _ELEMENTS_BY_DIM_
560 anEntity = eSTRUCT_ELEMENT;
562 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
564 nbElemInfo.NbBalls(),
566 #ifdef _ELEMENTS_BY_DIM_
569 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
571 nbElemInfo.NbEdges( ORDER_LINEAR ),
573 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
575 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
577 #ifdef _ELEMENTS_BY_DIM_
580 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
582 nbElemInfo.NbTriangles( ORDER_LINEAR ),
584 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
586 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
587 nbElemInfo.NbBiQuadTriangles(),
589 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
591 nbElemInfo.NbBiQuadTriangles(),
593 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
595 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
597 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
599 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
600 nbElemInfo.NbBiQuadQuadrangles(),
602 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
604 nbElemInfo.NbBiQuadQuadrangles(),
606 if ( polyTypesSupported ) {
607 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
609 nbElemInfo.NbPolygons( ORDER_LINEAR ),
611 // we need one more loop on poly elements to count nb of their nodes
612 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
614 nbElemInfo.NbPolygons( ORDER_LINEAR ),
616 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
618 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
620 // we need one more loop on QUAD poly elements to count nb of their nodes
621 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
623 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
626 #ifdef _ELEMENTS_BY_DIM_
629 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
631 nbElemInfo.NbTetras( ORDER_LINEAR ),
633 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
635 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
637 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
639 nbElemInfo.NbPyramids( ORDER_LINEAR ),
641 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
643 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
645 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
647 nbElemInfo.NbPrisms( ORDER_LINEAR ),
649 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
651 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
653 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
655 nbElemInfo.NbHexas( ORDER_LINEAR ),
657 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
659 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
660 nbElemInfo.NbTriQuadHexas(),
662 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
664 nbElemInfo.NbTriQuadHexas(),
666 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
668 nbElemInfo.NbHexPrisms(),
670 if ( polyTypesSupported ) {
671 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
673 nbElemInfo.NbPolyhedrons(),
675 // we need one more loop on poly elements to count nb of their nodes
676 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
678 nbElemInfo.NbPolyhedrons(),
682 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
684 // loop on all geom types of elements
686 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
687 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
689 if ( aElemTypeData->_nbElems == 0 )
692 int defaultFamilyId = 0;
693 switch ( aElemTypeData->_smdsType ) {
694 case SMDSAbs_0DElement:
695 defaultFamilyId = my0DElementsDefaultFamilyId;
698 defaultFamilyId = myBallsDefaultFamilyId;
701 defaultFamilyId = myEdgesDefaultFamilyId;
704 defaultFamilyId = myFacesDefaultFamilyId;
707 defaultFamilyId = myVolumesDefaultFamilyId;
713 // iterator on elements of a current type
714 SMDS_ElemIteratorPtr elemIterator;
719 if ( aElemTypeData->_geomType == ePOLYGONE ||
720 aElemTypeData->_geomType == ePOLYGON2 )
722 if ( aElemTypeData->_geomType == ePOLYGONE )
723 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Polygon );
725 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Quad_Polygon );
727 if ( nbPolygonNodes == 0 ) {
729 while ( elemIterator->more() ) {
730 const SMDS_MeshElement* anElem = elemIterator->next();
731 nbPolygonNodes += anElem->NbNodes();
732 if ( ++iElem == aElemTypeData->_nbElems )
738 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
739 aElemTypeData->_entity,
740 aElemTypeData->_geomType,
741 aElemTypeData->_nbElems,
743 theConnMode, theIsElemNum,
745 TElemNum & index = *(aPolygoneInfo->myIndex.get());
748 while ( elemIterator->more() )
750 const SMDS_MeshElement* anElem = elemIterator->next();
752 TInt aNbNodes = anElem->NbNodes();
753 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
756 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
757 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
758 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
759 #ifdef _EDF_NODE_IDS_
760 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
762 aTConnSlice[ iNode ] = aNode->GetID();
766 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
769 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
770 aPolygoneInfo->SetFamNum( iElem, famNum );
772 if ( ++iElem == aPolygoneInfo->GetNbElem() )
775 myMed->SetPolygoneInfo(aPolygoneInfo);
777 nbPolygonNodes = 0; // to treat next polygon type
783 else if (aElemTypeData->_geomType == ePOLYEDRE )
785 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
787 if ( nbPolyhedronNodes == 0 ) {
789 while ( elemIterator->more() ) {
790 const SMDS_MeshElement* anElem = elemIterator->next();
791 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
792 if ( !aPolyedre ) continue;
793 nbPolyhedronNodes += aPolyedre->NbNodes();
794 nbPolyhedronFaces += aPolyedre->NbFaces();
795 if ( ++iElem == aElemTypeData->_nbElems )
801 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
802 aElemTypeData->_entity,
803 aElemTypeData->_geomType,
804 aElemTypeData->_nbElems,
810 TElemNum & index = *(aPolyhInfo->myIndex.get());
811 TElemNum & faces = *(aPolyhInfo->myFaces.get());
812 TElemNum & conn = *(aPolyhInfo->myConn.get());
816 TInt iFace = 0, iNode = 0;
817 while ( elemIterator->more() )
819 const SMDS_MeshElement* anElem = elemIterator->next();
820 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
821 if ( !aPolyedre ) continue;
823 TInt aNbFaces = aPolyedre->NbFaces();
824 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
827 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
828 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
829 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
832 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
833 while ( nodeIt->more() ) {
834 const SMDS_MeshElement* aNode = nodeIt->next();
835 #ifdef _EDF_NODE_IDS_
836 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
838 conn[ iNode ] = aNode->GetID();
843 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
846 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
847 aPolyhInfo->SetFamNum( iElem, famNum );
849 if ( ++iElem == aPolyhInfo->GetNbElem() )
852 myMed->SetPolyedreInfo(aPolyhInfo);
854 } // if (aElemTypeData->_geomType == ePOLYEDRE )
858 else if (aElemTypeData->_geomType == eBALL )
860 // allocate data arrays
861 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo,
862 aElemTypeData->_nbElems );
864 // build map of family numbers for this type
865 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
867 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
868 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
871 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
872 while ( elemIterator->more() )
874 const SMDS_MeshElement* anElem = elemIterator->next();
876 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
877 #ifdef _EDF_NODE_IDS_
878 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
880 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
883 aBallInfo->SetElemNum( iElem, anElem->GetID() );
886 aBallInfo->myDiameters[ iElem ] =
887 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
890 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
891 aBallInfo->SetFamNum( iElem, famNum );
894 // store data in a file
895 myMed->SetBallInfo(aBallInfo);
900 // Treat standard types
901 // ---------------------
903 // allocate data arrays
904 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
905 aElemTypeData->_entity,
906 aElemTypeData->_geomType,
907 aElemTypeData->_nbElems,
911 // build map of family numbers for this type
912 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
914 //cout << " fillElemFamilyMap()" << endl;
915 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
916 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
919 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
920 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
921 if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() )
922 elemIterator = iterVecIter;
923 while ( elemIterator->more() )
925 const SMDS_MeshElement* anElem = elemIterator->next();
926 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
927 continue; // other geometry
930 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
931 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
932 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
933 #ifdef _EDF_NODE_IDS_
934 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
936 aTConnSlice[ iNode ] = aNode->GetID();
940 aCellInfo->SetElemNum( iElem, anElem->GetID() );
943 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
944 aCellInfo->SetFamNum( iElem, famNum );
946 if ( ++iElem == aCellInfo->GetNbElem() )
949 // store data in a file
950 myMed->SetCellInfo(aCellInfo);
953 } // loop on geom types
957 catch(const std::exception& exc) {
958 INFOS("The following exception was caught:\n\t"<<exc.what());
962 INFOS("Unknown exception was caught !!!");
972 //================================================================================
974 * \brief Returns nodes on VERTEXes where 0D elements are absent
976 //================================================================================
978 bool DriverMED_W_SMESHDS_Mesh::
979 getNodesOfMissing0DOnVert(SMESHDS_Mesh* meshDS,
980 std::vector<const SMDS_MeshElement*>& nodes)
983 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
985 if ( meshDS->IndexToShape( i ).ShapeType() != TopAbs_VERTEX )
987 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(i) ) {
988 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
991 const SMDS_MeshNode* n = nIt->next();
992 if ( n->NbInverseElements( SMDSAbs_0DElement ) == 0 )
993 nodes.push_back( n );
997 return !nodes.empty();