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_MeshNode.hxx"
35 #include "SMDS_SetIterator.hxx"
36 #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),
64 myDoAllInGroups(false)
67 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theMinor)
70 Driver_SMESHDS_Mesh::SetFile(theFileName);
74 * MED version is either the latest available, or with an inferior minor,
75 * to ensure backward compatibility on writing med files.
77 string DriverMED_W_SMESHDS_Mesh::GetVersionString(int theVersion, int theNbDigits)
79 TInt majeur, mineur, release;
82 release=MED_RELEASE_NUM;
83 TInt imposedMineur = mineur;
86 imposedMineur = mineur;
87 else if (theVersion > MED_MINOR_NUM)
88 imposedMineur = mineur;
90 imposedMineur = theVersion;
93 if ( theNbDigits > 0 )
95 if ( theNbDigits > 1 )
96 name << "." << imposedMineur;
97 if ( theNbDigits > 2 )
98 name << "." << release;
102 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
104 myGroups.push_back(theGroup);
107 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
109 myAllSubMeshes = true;
112 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
114 mySubMeshes.push_back( theSubMesh );
117 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
119 myDoGroupOfNodes = true;
122 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
124 myDoGroupOfEdges = true;
127 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
129 myDoGroupOfFaces = true;
132 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
134 myDoGroupOfVolumes = true;
137 void DriverMED_W_SMESHDS_Mesh::AddGroupOf0DElems()
139 myDoGroupOf0DElems = true;
142 void DriverMED_W_SMESHDS_Mesh::AddGroupOfBalls()
144 myDoGroupOfBalls = true;
147 //================================================================================
149 * \brief Set up a flag to add all elements not belonging to any group to
150 * some auxiliary group. This is needed for SMESH -> SAUVE -> SMESH conversion,
151 * which since PAL0023285 reads only SAUVE elements belonging to any group,
152 * and hence can lose some elements. That auxiliary group is ignored while
153 * reading a MED file.
155 //================================================================================
157 void DriverMED_W_SMESHDS_Mesh::AddAllToGroup()
159 myDoAllInGroups = true;
165 typedef double (SMDS_MeshNode::* TGetCoord)() const;
166 typedef const char* TName;
167 typedef const char* TUnit;
169 // name length in a mesh must be equal to 16 :
176 TUnit aUnit[3] = {M,M,M};
179 TGetCoord aXYZGetCoord[3] = {
184 TName aXYZName[3] = {X,Y,Z};
187 TGetCoord aXYGetCoord[2] = {
191 TName aXYName[2] = {X,Y};
193 TGetCoord aYZGetCoord[2] = {
197 TName aYZName[2] = {Y,Z};
199 TGetCoord aXZGetCoord[2] = {
203 TName aXZName[2] = {X,Z};
206 TGetCoord aXGetCoord[1] = {
209 TName aXName[1] = {X};
211 TGetCoord aYGetCoord[1] = {
214 TName aYName[1] = {Y};
216 TGetCoord aZGetCoord[1] = {
219 TName aZName[1] = {Z};
223 SMDS_NodeIteratorPtr myNodeIter;
224 const SMDS_MeshNode* myCurrentNode;
225 TGetCoord* myGetCoord;
229 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
230 TGetCoord* theGetCoord,
232 TUnit* theUnit = aUnit):
233 myNodeIter(theNodeIter),
234 myGetCoord(theGetCoord),
238 virtual ~TCoordHelper(){}
240 return myNodeIter->more() &&
241 (myCurrentNode = myNodeIter->next());
243 const SMDS_MeshNode* GetNode(){
244 return myCurrentNode;
246 MED::TIntVector::value_type GetID(){
247 return myCurrentNode->GetID();
249 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
250 return (myCurrentNode->*myGetCoord[theCoodId])();
252 MED::TStringVector::value_type GetName(TInt theDimId){
253 return myName[theDimId];
255 MED::TStringVector::value_type GetUnit(TInt theDimId){
256 return myUnit[theDimId];
259 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
261 //-------------------------------------------------------
263 * \brief Structure describing element type
265 //-------------------------------------------------------
268 EEntiteMaillage _entity;
269 EGeometrieElement _geomType;
271 SMDSAbs_ElementType _smdsType;
273 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
274 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
278 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
280 //================================================================================
282 * \brief Fills element to famaly ID map for element type.
283 * Removes all families of anElemType
285 //================================================================================
287 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
288 list<DriverMED_FamilyPtr> & aFamilies,
289 const SMDSAbs_ElementType anElemType)
291 anElemFamMap.Clear();
292 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
293 while ( aFamsIter != aFamilies.end() )
295 if ((*aFamsIter)->GetType() != anElemType) {
299 int aFamId = (*aFamsIter)->GetId();
300 const ElementsSet& anElems = (*aFamsIter)->GetElements();
301 ElementsSet::const_iterator anElemsIter = anElems.begin();
302 for (; anElemsIter != anElems.end(); anElemsIter++)
304 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
306 // remove a family from the list
307 aFamilies.erase( aFamsIter++ );
312 //================================================================================
314 * \brief For an element, return family ID found in the map or a default one
316 //================================================================================
318 int getFamilyId( const TElemFamilyMap & anElemFamMap,
319 const SMDS_MeshElement* anElement,
320 const int aDefaultFamilyId)
322 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
323 return anElemFamMap( (Standard_Address) anElement );
325 return aDefaultFamilyId;
328 //================================================================================
330 * \brief Returns iterator on sub-meshes
332 //================================================================================
334 SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& mySubMeshes )
336 return SMESHDS_SubMeshIteratorPtr
337 ( new SMDS_SetIterator
338 < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(),
339 mySubMeshes.end() ));
343 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
345 Status aResult = DRS_OK;
347 //MESSAGE("Perform - myFile : "<<myFile);
349 // Creating the MED mesh for corresponding SMDS structure
350 //-------------------------------------------------------
352 if (myMeshId != -1) {
353 ostringstream aMeshNameStr;
354 aMeshNameStr<<myMeshId;
355 aMeshName = aMeshNameStr.str();
357 aMeshName = myMeshName;
360 // Mesh dimension definition
362 TInt aMeshDimension = 0;
363 if ( myMesh->NbEdges() > 0 )
365 if ( myMesh->NbFaces() > 0 )
367 if ( myMesh->NbVolumes() > 0 )
370 TInt aSpaceDimension = 3;
371 TCoordHelperPtr aCoordHelperPtr;
373 bool anIsXDimension = false;
374 bool anIsYDimension = false;
375 bool anIsZDimension = false;
376 if ( myAutoDimension && aMeshDimension < 3 )
378 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
380 if(aNodesIter->more()){
381 const SMDS_MeshNode* aNode = aNodesIter->next();
382 aBounds[0] = aBounds[1] = aNode->X();
383 aBounds[2] = aBounds[3] = aNode->Y();
384 aBounds[4] = aBounds[5] = aNode->Z();
386 while(aNodesIter->more()){
387 const SMDS_MeshNode* aNode = aNodesIter->next();
388 aBounds[0] = min(aBounds[0],aNode->X());
389 aBounds[1] = max(aBounds[1],aNode->X());
391 aBounds[2] = min(aBounds[2],aNode->Y());
392 aBounds[3] = max(aBounds[3],aNode->Y());
394 aBounds[4] = min(aBounds[4],aNode->Z());
395 aBounds[5] = max(aBounds[5],aNode->Z());
399 TopoDS_Shape mainShape = myMesh->ShapeToMesh();
400 bool hasShapeToMesh = ( myMesh->SubMeshIndices().size() > 1 );
401 if ( !mainShape.IsNull() && hasShapeToMesh )
403 // define EPS by max tolerance of the mainShape (IPAL53097)
404 TopExp_Explorer subShape;
405 for ( subShape.Init( mainShape, TopAbs_FACE ); subShape.More(); subShape.Next() ) {
406 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Face( subShape.Current() )));
408 for ( subShape.Init( mainShape, TopAbs_EDGE ); subShape.More(); subShape.Next() ) {
409 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Edge( subShape.Current() )));
411 for ( subShape.Init( mainShape, TopAbs_VERTEX ); subShape.More(); subShape.Next() ) {
412 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Vertex( subShape.Current() )));
416 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
417 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
418 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
419 aSpaceDimension = Max( aMeshDimension, anIsXDimension + anIsYDimension + anIsZDimension );
420 if ( !aSpaceDimension )
422 // PAL16857(SMESH not conform to the MED convention):
423 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
425 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
426 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
427 if ( anIsYDimension ) {
429 anIsXDimension = true;
436 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
437 switch ( aSpaceDimension ) {
439 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
442 if(anIsXDimension && anIsYDimension)
443 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
444 if(anIsYDimension && anIsZDimension)
445 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
446 if(anIsXDimension && anIsZDimension)
447 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
451 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
453 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
455 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
460 MED::PWrapper myMed = CrWrapperW(myFile, myMinor);
461 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
462 //MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
463 myMed->SetMeshInfo(aMeshInfo);
465 // Storing SMDS groups and sub-meshes as med families
466 //----------------------------------------------------
467 int myNodesDefaultFamilyId = 0;
468 int my0DElementsDefaultFamilyId = 0;
469 int myBallsDefaultFamilyId = 0;
470 int myEdgesDefaultFamilyId = 0;
471 int myFacesDefaultFamilyId = 0;
472 int myVolumesDefaultFamilyId = 0;
473 int nbNodes = myMesh->NbNodes();
474 int nb0DElements = myMesh->Nb0DElements();
475 int nbBalls = myMesh->NbBalls();
476 int nbEdges = myMesh->NbEdges();
477 int nbFaces = myMesh->NbFaces();
478 int nbVolumes = myMesh->NbVolumes();
479 if (myDoGroupOfNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
480 if (myDoGroupOfEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
481 if (myDoGroupOfFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
482 if (myDoGroupOfVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
483 if (myDoGroupOf0DElems) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
484 if (myDoGroupOfBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
485 if (myDoAllInGroups )
487 if (!myDoGroupOfEdges) myEdgesDefaultFamilyId = NIG_EDGES_FAMILY ;
488 if (!myDoGroupOfFaces) myFacesDefaultFamilyId = NIG_FACES_FAMILY ;
489 if (!myDoGroupOfVolumes) myVolumesDefaultFamilyId = NIG_VOLS_FAMILY ;
490 if (!myDoGroupOf0DElems) my0DElementsDefaultFamilyId = NIG_0DELEM_FAMILY ;
491 if (!myDoGroupOfBalls) myBallsDefaultFamilyId = NIG_BALL_FAMILY ;
494 //MESSAGE("Perform - aFamilyInfo");
495 list<DriverMED_FamilyPtr> aFamilies;
496 if (myAllSubMeshes) {
497 aFamilies = DriverMED_Family::MakeFamilies
498 (myMesh->SubMeshes(), myGroups,
499 myDoGroupOfNodes && nbNodes,
500 myDoGroupOfEdges && nbEdges,
501 myDoGroupOfFaces && nbFaces,
502 myDoGroupOfVolumes && nbVolumes,
503 myDoGroupOf0DElems && nb0DElements,
504 myDoGroupOfBalls && nbBalls,
508 aFamilies = DriverMED_Family::MakeFamilies
509 (getIterator( mySubMeshes ), myGroups,
510 myDoGroupOfNodes && nbNodes,
511 myDoGroupOfEdges && nbEdges,
512 myDoGroupOfFaces && nbFaces,
513 myDoGroupOfVolumes && nbVolumes,
514 myDoGroupOf0DElems && nb0DElements,
515 myDoGroupOfBalls && nbBalls,
518 list<DriverMED_FamilyPtr>::iterator aFamsIter;
519 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
521 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
522 myMed->SetFamilyInfo(aFamilyInfo);
525 // Storing SMDS nodes to the MED file for the MED mesh
526 //----------------------------------------------------
527 #ifdef _EDF_NODE_IDS_
528 typedef map<TInt,TInt> TNodeIdMap;
529 TNodeIdMap aNodeIdMap;
531 const EModeSwitch theMode = eFULL_INTERLACE;
532 const ERepere theSystem = eCART;
533 const EBooleen theIsElemNum = eVRAI;
534 const EBooleen theIsElemNames = eFAUX;
535 const EConnectivite theConnMode = eNOD;
537 TInt aNbNodes = myMesh->NbNodes();
538 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
539 theMode, theSystem, theIsElemNum, theIsElemNames);
541 // find family numbers for nodes
542 TElemFamilyMap anElemFamMap;
543 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
545 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
548 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
549 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
550 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
553 int aNodeID = aCoordHelperPtr->GetID();
554 aNodeInfo->SetElemNum( iNode, aNodeID );
555 #ifdef _EDF_NODE_IDS_
556 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
559 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
560 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
561 aNodeInfo->SetFamNum( iNode, famNum );
563 anElemFamMap.Clear();
565 // coordinate names and units
566 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
567 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
568 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
571 //MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
572 myMed->SetNodeInfo(aNodeInfo);
573 aNodeInfo.reset(); // free memory used for arrays
576 // Storing SMDS elements to the MED file for the MED mesh
577 //-------------------------------------------------------
578 // Write one element type at once in order to minimize memory usage (PAL19276)
580 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
582 // poly elements are not supported by med-2.1
583 bool polyTypesSupported = ( myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0).get() != 0 );
584 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
586 // nodes on VERTEXes where 0D elements are absent
587 std::vector<const SMDS_MeshElement*> nodesOf0D;
588 std::vector< SMDS_ElemIteratorPtr > iterVec;
589 SMDS_ElemIteratorPtr iterVecIter;
590 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
593 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
594 iterVec[1] = SMDS_ElemIteratorPtr
595 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
597 typedef SMDS_IteratorOnIterators
598 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
599 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
602 // collect info on all geom types
604 list< TElemTypeData > aTElemTypeDatas;
606 EEntiteMaillage anEntity = eMAILLE;
607 #ifdef _ELEMENTS_BY_DIM_
608 anEntity = eNOEUD_ELEMENT;
610 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
612 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
614 #ifdef _ELEMENTS_BY_DIM_
615 anEntity = eSTRUCT_ELEMENT;
617 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
619 nbElemInfo.NbBalls(),
621 #ifdef _ELEMENTS_BY_DIM_
624 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
626 nbElemInfo.NbEdges( ORDER_LINEAR ),
628 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
630 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
632 #ifdef _ELEMENTS_BY_DIM_
635 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
637 nbElemInfo.NbTriangles( ORDER_LINEAR ),
639 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
641 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
642 nbElemInfo.NbBiQuadTriangles(),
644 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
646 nbElemInfo.NbBiQuadTriangles(),
648 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
650 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
652 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
654 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
655 nbElemInfo.NbBiQuadQuadrangles(),
657 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
659 nbElemInfo.NbBiQuadQuadrangles(),
661 if ( polyTypesSupported ) {
662 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
664 nbElemInfo.NbPolygons( ORDER_LINEAR ),
666 // we need one more loop on poly elements to count nb of their nodes
667 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
669 nbElemInfo.NbPolygons( ORDER_LINEAR ),
671 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
673 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
675 // we need one more loop on QUAD poly elements to count nb of their nodes
676 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
678 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
681 #ifdef _ELEMENTS_BY_DIM_
684 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
686 nbElemInfo.NbTetras( ORDER_LINEAR ),
688 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
690 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
692 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
694 nbElemInfo.NbPyramids( ORDER_LINEAR ),
696 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
698 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
700 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
702 nbElemInfo.NbPrisms( ORDER_LINEAR ),
704 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
706 nbElemInfo.NbQuadPrisms(),
708 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
710 nbElemInfo.NbBiQuadPrisms(),
712 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
714 nbElemInfo.NbHexas( ORDER_LINEAR ),
716 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
718 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
719 nbElemInfo.NbTriQuadHexas(),
721 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
723 nbElemInfo.NbTriQuadHexas(),
725 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
727 nbElemInfo.NbHexPrisms(),
729 if ( polyTypesSupported ) {
730 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
732 nbElemInfo.NbPolyhedrons(),
734 // we need one more loop on poly elements to count nb of their nodes
735 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
737 nbElemInfo.NbPolyhedrons(),
741 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
743 // loop on all geom types of elements
745 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
746 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
748 if ( aElemTypeData->_nbElems == 0 )
751 int defaultFamilyId = 0;
752 switch ( aElemTypeData->_smdsType ) {
753 case SMDSAbs_0DElement: defaultFamilyId = my0DElementsDefaultFamilyId; break;
754 case SMDSAbs_Ball: defaultFamilyId = myBallsDefaultFamilyId; break;
755 case SMDSAbs_Edge: defaultFamilyId = myEdgesDefaultFamilyId; break;
756 case SMDSAbs_Face: defaultFamilyId = myFacesDefaultFamilyId; break;
757 case SMDSAbs_Volume: defaultFamilyId = myVolumesDefaultFamilyId; break;
762 // build map of family numbers for this type
763 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
765 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
766 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
769 // iterator on elements of a current type
770 SMDS_ElemIteratorPtr elemIterator;
775 if ( aElemTypeData->_geomType == ePOLYGONE ||
776 aElemTypeData->_geomType == ePOLYGON2 )
778 if ( aElemTypeData->_geomType == ePOLYGONE )
779 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Polygon );
781 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Quad_Polygon );
783 if ( nbPolygonNodes == 0 ) {
785 while ( elemIterator->more() ) {
786 const SMDS_MeshElement* anElem = elemIterator->next();
787 nbPolygonNodes += anElem->NbNodes();
788 if ( ++iElem == aElemTypeData->_nbElems )
794 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
795 aElemTypeData->_entity,
796 aElemTypeData->_geomType,
797 aElemTypeData->_nbElems,
799 theConnMode, theIsElemNum,
801 TElemNum & index = *(aPolygoneInfo->myIndex.get());
804 while ( elemIterator->more() )
806 const SMDS_MeshElement* anElem = elemIterator->next();
808 TInt aNbNodes = anElem->NbNodes();
809 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
812 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
813 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
814 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
815 #ifdef _EDF_NODE_IDS_
816 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
818 aTConnSlice[ iNode ] = aNode->GetID();
822 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
825 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
826 aPolygoneInfo->SetFamNum( iElem, famNum );
828 if ( ++iElem == aPolygoneInfo->GetNbElem() )
831 myMed->SetPolygoneInfo(aPolygoneInfo);
833 nbPolygonNodes = 0; // to treat next polygon type
839 else if ( aElemTypeData->_geomType == ePOLYEDRE )
841 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
843 if ( nbPolyhedronNodes == 0 ) {
845 while ( elemIterator->more() ) {
846 const SMDS_MeshElement* anElem = elemIterator->next();
847 nbPolyhedronNodes += anElem->NbNodes();
848 nbPolyhedronFaces += anElem->NbFaces();
849 if ( ++iElem == aElemTypeData->_nbElems )
855 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
856 aElemTypeData->_entity,
857 aElemTypeData->_geomType,
858 aElemTypeData->_nbElems,
864 TElemNum & index = *(aPolyhInfo->myIndex.get());
865 TElemNum & faces = *(aPolyhInfo->myFaces.get());
866 TElemNum & conn = *(aPolyhInfo->myConn.get());
870 TInt iFace = 0, iNode = 0;
871 while ( elemIterator->more() )
873 const SMDS_MeshElement* anElem = elemIterator->next();
874 const SMDS_MeshVolume *aPolyedre = myMesh->DownCast< SMDS_MeshVolume >( anElem );
875 if ( !aPolyedre ) continue;
877 TInt aNbFaces = aPolyedre->NbFaces();
878 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
881 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
882 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
883 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
886 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
887 while ( nodeIt->more() ) {
888 const SMDS_MeshElement* aNode = nodeIt->next();
889 #ifdef _EDF_NODE_IDS_
890 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
892 conn[ iNode ] = aNode->GetID();
897 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
900 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
901 aPolyhInfo->SetFamNum( iElem, famNum );
903 if ( ++iElem == aPolyhInfo->GetNbElem() )
906 myMed->SetPolyedreInfo(aPolyhInfo);
908 } // if (aElemTypeData->_geomType == ePOLYEDRE )
912 else if (aElemTypeData->_geomType == eBALL )
914 // allocate data arrays
915 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo, aElemTypeData->_nbElems );
917 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
918 while ( elemIterator->more() )
920 const SMDS_MeshElement* anElem = elemIterator->next();
922 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
923 #ifdef _EDF_NODE_IDS_
924 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
926 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
929 aBallInfo->SetElemNum( iElem, anElem->GetID() );
932 aBallInfo->myDiameters[ iElem ] =
933 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
936 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
937 aBallInfo->SetFamNum( iElem, famNum );
940 // store data in a file
941 myMed->SetBallInfo(aBallInfo);
946 // Treat standard types
947 // ---------------------
948 // allocate data arrays
949 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
950 aElemTypeData->_entity,
951 aElemTypeData->_geomType,
952 aElemTypeData->_nbElems,
957 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
958 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
959 if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() )
960 elemIterator = iterVecIter;
961 while ( elemIterator->more() )
963 const SMDS_MeshElement* anElem = elemIterator->next();
964 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
965 continue; // other geometry
968 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
969 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
970 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
971 #ifdef _EDF_NODE_IDS_
972 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
974 aTConnSlice[ iNode ] = aNode->GetID();
978 aCellInfo->SetElemNum( iElem, anElem->GetID() );
981 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
982 aCellInfo->SetFamNum( iElem, famNum );
984 if ( ++iElem == aCellInfo->GetNbElem() )
987 // store data in a file
988 myMed->SetCellInfo(aCellInfo);
990 } // loop on geom types
992 catch(const std::exception& exc) {
993 INFOS("The following exception was caught:\n\t"<<exc.what());
997 INFOS("Unknown exception was caught !!!");
1003 mySubMeshes.clear();
1007 //================================================================================
1009 * \brief Returns nodes on VERTEXes where 0D elements are absent
1011 //================================================================================
1013 bool DriverMED_W_SMESHDS_Mesh::
1014 getNodesOfMissing0DOnVert(SMESHDS_Mesh* meshDS,
1015 std::vector<const SMDS_MeshElement*>& nodes)
1018 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
1020 if ( meshDS->IndexToShape( i ).ShapeType() != TopAbs_VERTEX )
1022 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(i) ) {
1023 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
1026 const SMDS_MeshNode* n = nIt->next();
1027 if ( n->NbInverseElements( SMDSAbs_0DElement ) == 0 )
1028 nodes.push_back( n );
1032 return !nodes.empty();