1 // Copyright (C) 2007-2016 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 <BRep_Tool.hxx>
41 #include <TopExp_Explorer.hxx>
44 #include <utilities.h>
47 #define _EDF_NODE_IDS_
48 //#define _ELEMENTS_BY_DIM_
54 DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
55 myAllSubMeshes (false),
56 myDoGroupOfNodes (false),
57 myDoGroupOfEdges (false),
58 myDoGroupOfFaces (false),
59 myDoGroupOfVolumes (false),
60 myDoGroupOf0DElems(false),
61 myDoGroupOfBalls(false),
62 myAutoDimension(false),
63 myAddODOnVertices(false)
66 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
68 Driver_SMESHDS_Mesh::SetFile(theFileName);
71 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
73 myGroups.push_back(theGroup);
76 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
78 myAllSubMeshes = true;
81 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
83 mySubMeshes.push_back( theSubMesh );
86 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
88 myDoGroupOfNodes = true;
91 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
93 myDoGroupOfEdges = true;
96 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
98 myDoGroupOfFaces = true;
101 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
103 myDoGroupOfVolumes = true;
108 typedef double (SMDS_MeshNode::* TGetCoord)() const;
109 typedef const char* TName;
110 typedef const char* TUnit;
112 // name length in a mesh must be equal to 16 :
119 TUnit aUnit[3] = {M,M,M};
122 TGetCoord aXYZGetCoord[3] = {
127 TName aXYZName[3] = {X,Y,Z};
130 TGetCoord aXYGetCoord[2] = {
134 TName aXYName[2] = {X,Y};
136 TGetCoord aYZGetCoord[2] = {
140 TName aYZName[2] = {Y,Z};
142 TGetCoord aXZGetCoord[2] = {
146 TName aXZName[2] = {X,Z};
149 TGetCoord aXGetCoord[1] = {
152 TName aXName[1] = {X};
154 TGetCoord aYGetCoord[1] = {
157 TName aYName[1] = {Y};
159 TGetCoord aZGetCoord[1] = {
162 TName aZName[1] = {Z};
166 SMDS_NodeIteratorPtr myNodeIter;
167 const SMDS_MeshNode* myCurrentNode;
168 TGetCoord* myGetCoord;
172 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
173 TGetCoord* theGetCoord,
175 TUnit* theUnit = aUnit):
176 myNodeIter(theNodeIter),
177 myGetCoord(theGetCoord),
181 virtual ~TCoordHelper(){}
183 return myNodeIter->more() &&
184 (myCurrentNode = myNodeIter->next());
186 const SMDS_MeshNode* GetNode(){
187 return myCurrentNode;
189 MED::TIntVector::value_type GetID(){
190 return myCurrentNode->GetID();
192 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
193 return (myCurrentNode->*myGetCoord[theCoodId])();
195 MED::TStringVector::value_type GetName(TInt theDimId){
196 return myName[theDimId];
198 MED::TStringVector::value_type GetUnit(TInt theDimId){
199 return myUnit[theDimId];
202 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
204 //-------------------------------------------------------
206 * \brief Structure describing element type
208 //-------------------------------------------------------
211 EEntiteMaillage _entity;
212 EGeometrieElement _geomType;
214 SMDSAbs_ElementType _smdsType;
216 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
217 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
221 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
223 //================================================================================
225 * \brief Fills element to famaly ID map for element type.
226 * Removes all families of anElemType
228 //================================================================================
230 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
231 list<DriverMED_FamilyPtr> & aFamilies,
232 const SMDSAbs_ElementType anElemType)
234 anElemFamMap.Clear();
235 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
236 while ( aFamsIter != aFamilies.end() )
238 if ((*aFamsIter)->GetType() != anElemType) {
242 int aFamId = (*aFamsIter)->GetId();
243 const ElementsSet& anElems = (*aFamsIter)->GetElements();
244 ElementsSet::const_iterator anElemsIter = anElems.begin();
245 for (; anElemsIter != anElems.end(); anElemsIter++)
247 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
249 // remove a family from the list
250 aFamilies.erase( aFamsIter++ );
255 //================================================================================
257 * \brief For an element, return family ID found in the map or a default one
259 //================================================================================
261 int getFamilyId( const TElemFamilyMap & anElemFamMap,
262 const SMDS_MeshElement* anElement,
263 const int aDefaultFamilyId)
265 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
266 return anElemFamMap( (Standard_Address) anElement );
268 return aDefaultFamilyId;
271 //================================================================================
273 * \brief Returns iterator on sub-meshes
275 //================================================================================
277 SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& mySubMeshes )
279 return SMESHDS_SubMeshIteratorPtr
280 ( new SMDS_SetIterator
281 < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(),
282 mySubMeshes.end() ));
286 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
288 Status aResult = DRS_OK;
289 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
290 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
294 //MESSAGE("Perform - myFile : "<<myFile);
296 // Creating the MED mesh for corresponding SMDS structure
297 //-------------------------------------------------------
299 if (myMeshId != -1) {
300 ostringstream aMeshNameStr;
301 aMeshNameStr<<myMeshId;
302 aMeshName = aMeshNameStr.str();
304 aMeshName = myMeshName;
307 // Mesh dimension definition
309 TInt aMeshDimension = 0;
310 if ( myMesh->NbEdges() > 0 )
312 if ( myMesh->NbFaces() > 0 )
314 if ( myMesh->NbVolumes() > 0 )
317 TInt aSpaceDimension = 3;
318 TCoordHelperPtr aCoordHelperPtr;
320 bool anIsXDimension = false;
321 bool anIsYDimension = false;
322 bool anIsZDimension = false;
323 if ( myAutoDimension && aMeshDimension < 3 )
325 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
327 if(aNodesIter->more()){
328 const SMDS_MeshNode* aNode = aNodesIter->next();
329 aBounds[0] = aBounds[1] = aNode->X();
330 aBounds[2] = aBounds[3] = aNode->Y();
331 aBounds[4] = aBounds[5] = aNode->Z();
333 while(aNodesIter->more()){
334 const SMDS_MeshNode* aNode = aNodesIter->next();
335 aBounds[0] = min(aBounds[0],aNode->X());
336 aBounds[1] = max(aBounds[1],aNode->X());
338 aBounds[2] = min(aBounds[2],aNode->Y());
339 aBounds[3] = max(aBounds[3],aNode->Y());
341 aBounds[4] = min(aBounds[4],aNode->Z());
342 aBounds[5] = max(aBounds[5],aNode->Z());
346 TopoDS_Shape mainShape = myMesh->ShapeToMesh();
347 bool hasShapeToMesh = ( myMesh->SubMeshIndices().size() > 1 );
348 if ( !mainShape.IsNull() && hasShapeToMesh )
350 // define EPS by max tolerance of the mainShape (IPAL53097)
351 TopExp_Explorer subShape;
352 for ( subShape.Init( mainShape, TopAbs_FACE ); subShape.More(); subShape.Next() ) {
353 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Face( subShape.Current() )));
355 for ( subShape.Init( mainShape, TopAbs_EDGE ); subShape.More(); subShape.Next() ) {
356 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Edge( subShape.Current() )));
358 for ( subShape.Init( mainShape, TopAbs_VERTEX ); subShape.More(); subShape.Next() ) {
359 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Vertex( subShape.Current() )));
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 = Max( aMeshDimension, anIsXDimension + anIsYDimension + anIsZDimension );
367 if ( !aSpaceDimension )
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));
407 MED::PWrapper myMed = CrWrapperW(myFile);
408 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
409 //MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
410 myMed->SetMeshInfo(aMeshInfo);
412 // Storing SMDS groups and sub-meshes as med families
413 //----------------------------------------------------
414 int myNodesDefaultFamilyId = 0;
415 int my0DElementsDefaultFamilyId = 0;
416 int myBallsDefaultFamilyId = 0;
417 int myEdgesDefaultFamilyId = 0;
418 int myFacesDefaultFamilyId = 0;
419 int myVolumesDefaultFamilyId = 0;
420 int nbNodes = myMesh->NbNodes();
421 int nb0DElements = myMesh->Nb0DElements();
422 int nbBalls = myMesh->NbBalls();
423 int nbEdges = myMesh->NbEdges();
424 int nbFaces = myMesh->NbFaces();
425 int nbVolumes = myMesh->NbVolumes();
426 if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
427 if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
428 if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
429 if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
430 if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
431 if (myDoGroupOfBalls && nbBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
433 //MESSAGE("Perform - aFamilyInfo");
434 list<DriverMED_FamilyPtr> aFamilies;
435 if (myAllSubMeshes) {
436 aFamilies = DriverMED_Family::MakeFamilies
437 (myMesh->SubMeshes(), myGroups,
438 myDoGroupOfNodes && nbNodes,
439 myDoGroupOfEdges && nbEdges,
440 myDoGroupOfFaces && nbFaces,
441 myDoGroupOfVolumes && nbVolumes,
442 myDoGroupOf0DElems && nb0DElements,
443 myDoGroupOfBalls && nbBalls);
446 aFamilies = DriverMED_Family::MakeFamilies
447 (getIterator( mySubMeshes ), myGroups,
448 myDoGroupOfNodes && nbNodes,
449 myDoGroupOfEdges && nbEdges,
450 myDoGroupOfFaces && nbFaces,
451 myDoGroupOfVolumes && nbVolumes,
452 myDoGroupOf0DElems && nb0DElements,
453 myDoGroupOfBalls && nbBalls);
455 list<DriverMED_FamilyPtr>::iterator aFamsIter;
456 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
458 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
459 myMed->SetFamilyInfo(aFamilyInfo);
462 // Storing SMDS nodes to the MED file for the MED mesh
463 //----------------------------------------------------
464 #ifdef _EDF_NODE_IDS_
465 typedef map<TInt,TInt> TNodeIdMap;
466 TNodeIdMap aNodeIdMap;
468 const EModeSwitch theMode = eFULL_INTERLACE;
469 const ERepere theSystem = eCART;
470 const EBooleen theIsElemNum = eVRAI;
471 const EBooleen theIsElemNames = eFAUX;
472 const EConnectivite theConnMode = eNOD;
474 TInt aNbNodes = myMesh->NbNodes();
475 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
476 theMode, theSystem, theIsElemNum, theIsElemNames);
478 // find family numbers for nodes
479 TElemFamilyMap anElemFamMap;
480 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
482 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
485 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
486 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
487 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
490 int aNodeID = aCoordHelperPtr->GetID();
491 aNodeInfo->SetElemNum( iNode, aNodeID );
492 #ifdef _EDF_NODE_IDS_
493 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
496 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
497 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
498 aNodeInfo->SetFamNum( iNode, famNum );
500 anElemFamMap.Clear();
502 // coordinate names and units
503 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
504 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
505 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
508 //MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
509 myMed->SetNodeInfo(aNodeInfo);
510 aNodeInfo.reset(); // free memory used for arrays
513 // Storing SMDS elements to the MED file for the MED mesh
514 //-------------------------------------------------------
515 // Write one element type at once in order to minimize memory usage (PAL19276)
517 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
519 // poly elements are not supported by med-2.1
520 bool polyTypesSupported = ( myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0).get() != 0 );
521 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
523 // nodes on VERTEXes where 0D elements are absent
524 std::vector<const SMDS_MeshElement*> nodesOf0D;
525 std::vector< SMDS_ElemIteratorPtr > iterVec;
526 SMDS_ElemIteratorPtr iterVecIter;
527 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
530 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
531 iterVec[1] = SMDS_ElemIteratorPtr
532 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
534 typedef SMDS_IteratorOnIterators
535 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
536 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
539 // collect info on all geom types
541 list< TElemTypeData > aTElemTypeDatas;
543 EEntiteMaillage anEntity = eMAILLE;
544 #ifdef _ELEMENTS_BY_DIM_
545 anEntity = eNOEUD_ELEMENT;
547 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
549 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
551 #ifdef _ELEMENTS_BY_DIM_
552 anEntity = eSTRUCT_ELEMENT;
554 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
556 nbElemInfo.NbBalls(),
558 #ifdef _ELEMENTS_BY_DIM_
561 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
563 nbElemInfo.NbEdges( ORDER_LINEAR ),
565 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
567 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
569 #ifdef _ELEMENTS_BY_DIM_
572 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
574 nbElemInfo.NbTriangles( ORDER_LINEAR ),
576 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
578 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
579 nbElemInfo.NbBiQuadTriangles(),
581 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
583 nbElemInfo.NbBiQuadTriangles(),
585 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
587 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
589 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
591 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
592 nbElemInfo.NbBiQuadQuadrangles(),
594 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
596 nbElemInfo.NbBiQuadQuadrangles(),
598 if ( polyTypesSupported ) {
599 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
601 nbElemInfo.NbPolygons( ORDER_LINEAR ),
603 // we need one more loop on poly elements to count nb of their nodes
604 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
606 nbElemInfo.NbPolygons( ORDER_LINEAR ),
608 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
610 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
612 // we need one more loop on QUAD poly elements to count nb of their nodes
613 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
615 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
618 #ifdef _ELEMENTS_BY_DIM_
621 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
623 nbElemInfo.NbTetras( ORDER_LINEAR ),
625 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
627 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
629 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
631 nbElemInfo.NbPyramids( ORDER_LINEAR ),
633 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
635 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
637 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
639 nbElemInfo.NbPrisms( ORDER_LINEAR ),
641 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
643 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
645 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
647 nbElemInfo.NbHexas( ORDER_LINEAR ),
649 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
651 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
652 nbElemInfo.NbTriQuadHexas(),
654 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
656 nbElemInfo.NbTriQuadHexas(),
658 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
660 nbElemInfo.NbHexPrisms(),
662 if ( polyTypesSupported ) {
663 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
665 nbElemInfo.NbPolyhedrons(),
667 // we need one more loop on poly elements to count nb of their nodes
668 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
670 nbElemInfo.NbPolyhedrons(),
674 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
676 // loop on all geom types of elements
678 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
679 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
681 if ( aElemTypeData->_nbElems == 0 )
684 int defaultFamilyId = 0;
685 switch ( aElemTypeData->_smdsType ) {
686 case SMDSAbs_0DElement: defaultFamilyId = my0DElementsDefaultFamilyId; break;
687 case SMDSAbs_Ball: defaultFamilyId = myBallsDefaultFamilyId; break;
688 case SMDSAbs_Edge: defaultFamilyId = myEdgesDefaultFamilyId; break;
689 case SMDSAbs_Face: defaultFamilyId = myFacesDefaultFamilyId; break;
690 case SMDSAbs_Volume: defaultFamilyId = myVolumesDefaultFamilyId; break;
695 // iterator on elements of a current type
696 SMDS_ElemIteratorPtr elemIterator;
701 if ( aElemTypeData->_geomType == ePOLYGONE ||
702 aElemTypeData->_geomType == ePOLYGON2 )
704 if ( aElemTypeData->_geomType == ePOLYGONE )
705 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Polygon );
707 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Quad_Polygon );
709 if ( nbPolygonNodes == 0 ) {
711 while ( elemIterator->more() ) {
712 const SMDS_MeshElement* anElem = elemIterator->next();
713 nbPolygonNodes += anElem->NbNodes();
714 if ( ++iElem == aElemTypeData->_nbElems )
720 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
721 aElemTypeData->_entity,
722 aElemTypeData->_geomType,
723 aElemTypeData->_nbElems,
725 theConnMode, theIsElemNum,
727 TElemNum & index = *(aPolygoneInfo->myIndex.get());
730 while ( elemIterator->more() )
732 const SMDS_MeshElement* anElem = elemIterator->next();
734 TInt aNbNodes = anElem->NbNodes();
735 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
738 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
739 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
740 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
741 #ifdef _EDF_NODE_IDS_
742 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
744 aTConnSlice[ iNode ] = aNode->GetID();
748 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
751 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
752 aPolygoneInfo->SetFamNum( iElem, famNum );
754 if ( ++iElem == aPolygoneInfo->GetNbElem() )
757 myMed->SetPolygoneInfo(aPolygoneInfo);
759 nbPolygonNodes = 0; // to treat next polygon type
765 else if (aElemTypeData->_geomType == ePOLYEDRE )
767 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
769 if ( nbPolyhedronNodes == 0 ) {
771 while ( elemIterator->more() ) {
772 const SMDS_MeshElement* anElem = elemIterator->next();
773 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
774 if ( !aPolyedre ) continue;
775 nbPolyhedronNodes += aPolyedre->NbNodes();
776 nbPolyhedronFaces += aPolyedre->NbFaces();
777 if ( ++iElem == aElemTypeData->_nbElems )
783 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
784 aElemTypeData->_entity,
785 aElemTypeData->_geomType,
786 aElemTypeData->_nbElems,
792 TElemNum & index = *(aPolyhInfo->myIndex.get());
793 TElemNum & faces = *(aPolyhInfo->myFaces.get());
794 TElemNum & conn = *(aPolyhInfo->myConn.get());
798 TInt iFace = 0, iNode = 0;
799 while ( elemIterator->more() )
801 const SMDS_MeshElement* anElem = elemIterator->next();
802 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
803 if ( !aPolyedre ) continue;
805 TInt aNbFaces = aPolyedre->NbFaces();
806 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
809 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
810 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
811 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
814 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
815 while ( nodeIt->more() ) {
816 const SMDS_MeshElement* aNode = nodeIt->next();
817 #ifdef _EDF_NODE_IDS_
818 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
820 conn[ iNode ] = aNode->GetID();
825 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
828 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
829 aPolyhInfo->SetFamNum( iElem, famNum );
831 if ( ++iElem == aPolyhInfo->GetNbElem() )
834 myMed->SetPolyedreInfo(aPolyhInfo);
836 } // if (aElemTypeData->_geomType == ePOLYEDRE )
840 else if (aElemTypeData->_geomType == eBALL )
842 // allocate data arrays
843 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo, aElemTypeData->_nbElems );
845 // build map of family numbers for this type
846 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
848 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
849 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
852 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
853 while ( elemIterator->more() )
855 const SMDS_MeshElement* anElem = elemIterator->next();
857 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
858 #ifdef _EDF_NODE_IDS_
859 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
861 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
864 aBallInfo->SetElemNum( iElem, anElem->GetID() );
867 aBallInfo->myDiameters[ iElem ] =
868 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
871 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
872 aBallInfo->SetFamNum( iElem, famNum );
875 // store data in a file
876 myMed->SetBallInfo(aBallInfo);
881 // Treat standard types
882 // ---------------------
884 // allocate data arrays
885 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
886 aElemTypeData->_entity,
887 aElemTypeData->_geomType,
888 aElemTypeData->_nbElems,
892 // build map of family numbers for this type
893 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
895 //cout << " fillElemFamilyMap()" << endl;
896 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
897 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
900 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
901 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
902 if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() )
903 elemIterator = iterVecIter;
904 while ( elemIterator->more() )
906 const SMDS_MeshElement* anElem = elemIterator->next();
907 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
908 continue; // other geometry
911 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
912 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
913 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
914 #ifdef _EDF_NODE_IDS_
915 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
917 aTConnSlice[ iNode ] = aNode->GetID();
921 aCellInfo->SetElemNum( iElem, anElem->GetID() );
924 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
925 aCellInfo->SetFamNum( iElem, famNum );
927 if ( ++iElem == aCellInfo->GetNbElem() )
930 // store data in a file
931 myMed->SetCellInfo(aCellInfo);
934 } // loop on geom types
938 catch(const std::exception& exc) {
939 INFOS("The following exception was caught:\n\t"<<exc.what());
943 INFOS("Unknown exception was caught !!!");
953 //================================================================================
955 * \brief Returns nodes on VERTEXes where 0D elements are absent
957 //================================================================================
959 bool DriverMED_W_SMESHDS_Mesh::
960 getNodesOfMissing0DOnVert(SMESHDS_Mesh* meshDS,
961 std::vector<const SMDS_MeshElement*>& nodes)
964 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
966 if ( meshDS->IndexToShape( i ).ShapeType() != TopAbs_VERTEX )
968 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(i) ) {
969 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
972 const SMDS_MeshNode* n = nIt->next();
973 if ( n->NbInverseElements( SMDSAbs_0DElement ) == 0 )
974 nodes.push_back( n );
978 return !nodes.empty();