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),
68 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName, int theVersion)
70 myVersion = theVersion;
71 Driver_SMESHDS_Mesh::SetFile(theFileName);
75 * MED version is either the latest available, or with an inferior minor,
76 * to ensure backward compatibility on writing med files.
78 string DriverMED_W_SMESHDS_Mesh::GetVersionString(int theMinor, int theNbDigits)
80 TInt majeur, mineur, release;
83 release=MED_RELEASE_NUM;
84 TInt imposedMineur = mineur;
87 imposedMineur = mineur;
88 else if (theMinor > MED_MINOR_NUM)
89 imposedMineur = mineur;
91 imposedMineur = theMinor;
94 if ( theNbDigits > 0 )
96 if ( theNbDigits > 1 )
97 name << "." << imposedMineur;
98 if ( theNbDigits > 2 )
99 name << "." << release;
103 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
105 myGroups.push_back(theGroup);
108 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
110 myAllSubMeshes = true;
113 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
115 mySubMeshes.push_back( theSubMesh );
118 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
120 myDoGroupOfNodes = true;
123 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
125 myDoGroupOfEdges = true;
128 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
130 myDoGroupOfFaces = true;
133 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
135 myDoGroupOfVolumes = true;
138 void DriverMED_W_SMESHDS_Mesh::AddGroupOf0DElems()
140 myDoGroupOf0DElems = true;
143 void DriverMED_W_SMESHDS_Mesh::AddGroupOfBalls()
145 myDoGroupOfBalls = true;
148 //================================================================================
150 * \brief Set up a flag to add all elements not belonging to any group to
151 * some auxiliary group. This is needed for SMESH -> SAUVE -> SMESH conversion,
152 * which since PAL0023285 reads only SAUVE elements belonging to any group,
153 * and hence can lose some elements. That auxiliary group is ignored while
154 * reading a MED file.
156 //================================================================================
158 void DriverMED_W_SMESHDS_Mesh::AddAllToGroup()
160 myDoAllInGroups = true;
166 typedef double (SMDS_MeshNode::* TGetCoord)() const;
167 typedef const char* TName;
168 typedef const char* TUnit;
170 // name length in a mesh must be equal to 16 :
177 TUnit aUnit[3] = {M,M,M};
180 TGetCoord aXYZGetCoord[3] = {
185 TName aXYZName[3] = {X,Y,Z};
188 TGetCoord aXYGetCoord[2] = {
192 TName aXYName[2] = {X,Y};
194 TGetCoord aYZGetCoord[2] = {
198 TName aYZName[2] = {Y,Z};
200 TGetCoord aXZGetCoord[2] = {
204 TName aXZName[2] = {X,Z};
207 TGetCoord aXGetCoord[1] = {
210 TName aXName[1] = {X};
212 TGetCoord aYGetCoord[1] = {
215 TName aYName[1] = {Y};
217 TGetCoord aZGetCoord[1] = {
220 TName aZName[1] = {Z};
224 SMDS_NodeIteratorPtr myNodeIter;
225 const SMDS_MeshNode* myCurrentNode;
226 TGetCoord* myGetCoord;
230 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
231 TGetCoord* theGetCoord,
233 TUnit* theUnit = aUnit):
234 myNodeIter(theNodeIter),
235 myGetCoord(theGetCoord),
239 virtual ~TCoordHelper(){}
241 return myNodeIter->more() &&
242 (myCurrentNode = myNodeIter->next());
244 const SMDS_MeshNode* GetNode(){
245 return myCurrentNode;
247 MED::TIntVector::value_type GetID(){
248 return myCurrentNode->GetID();
250 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
251 return (myCurrentNode->*myGetCoord[theCoodId])();
253 MED::TStringVector::value_type GetName(TInt theDimId){
254 return myName[theDimId];
256 MED::TStringVector::value_type GetUnit(TInt theDimId){
257 return myUnit[theDimId];
260 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
262 //-------------------------------------------------------
264 * \brief Structure describing element type
266 //-------------------------------------------------------
269 EEntiteMaillage _entity;
270 EGeometrieElement _geomType;
272 SMDSAbs_ElementType _smdsType;
274 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
275 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
279 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
281 //================================================================================
283 * \brief Fills element to famaly ID map for element type.
284 * Removes all families of anElemType
286 //================================================================================
288 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
289 list<DriverMED_FamilyPtr> & aFamilies,
290 const SMDSAbs_ElementType anElemType)
292 anElemFamMap.Clear();
293 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
294 while ( aFamsIter != aFamilies.end() )
296 if ((*aFamsIter)->GetType() != anElemType) {
300 int aFamId = (*aFamsIter)->GetId();
301 const ElementsSet& anElems = (*aFamsIter)->GetElements();
302 ElementsSet::const_iterator anElemsIter = anElems.begin();
303 for (; anElemsIter != anElems.end(); anElemsIter++)
305 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
307 // remove a family from the list
308 aFamilies.erase( aFamsIter++ );
313 //================================================================================
315 * \brief For an element, return family ID found in the map or a default one
317 //================================================================================
319 int getFamilyId( const TElemFamilyMap & anElemFamMap,
320 const SMDS_MeshElement* anElement,
321 const int aDefaultFamilyId)
323 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
324 return anElemFamMap( (Standard_Address) anElement );
326 return aDefaultFamilyId;
329 //================================================================================
331 * \brief Returns iterator on sub-meshes
333 //================================================================================
335 SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& mySubMeshes )
337 return SMESHDS_SubMeshIteratorPtr
338 ( new SMDS_SetIterator
339 < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(),
340 mySubMeshes.end() ));
344 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
346 Status aResult = DRS_OK;
348 //MESSAGE("Perform - myFile : "<<myFile);
350 // Creating the MED mesh for corresponding SMDS structure
351 //-------------------------------------------------------
353 if (myMeshId != -1) {
354 ostringstream aMeshNameStr;
355 aMeshNameStr<<myMeshId;
356 aMeshName = aMeshNameStr.str();
358 aMeshName = myMeshName;
361 // Mesh dimension definition
363 TInt aMeshDimension = 0;
364 if ( myMesh->NbEdges() > 0 )
366 if ( myMesh->NbFaces() > 0 )
368 if ( myMesh->NbVolumes() > 0 )
371 TInt aSpaceDimension = 3;
372 TCoordHelperPtr aCoordHelperPtr;
374 bool anIsXDimension = false;
375 bool anIsYDimension = false;
376 bool anIsZDimension = false;
377 if ( myAutoDimension && aMeshDimension < 3 )
379 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
381 if(aNodesIter->more()){
382 const SMDS_MeshNode* aNode = aNodesIter->next();
383 aBounds[0] = aBounds[1] = aNode->X();
384 aBounds[2] = aBounds[3] = aNode->Y();
385 aBounds[4] = aBounds[5] = aNode->Z();
387 while(aNodesIter->more()){
388 const SMDS_MeshNode* aNode = aNodesIter->next();
389 aBounds[0] = min(aBounds[0],aNode->X());
390 aBounds[1] = max(aBounds[1],aNode->X());
392 aBounds[2] = min(aBounds[2],aNode->Y());
393 aBounds[3] = max(aBounds[3],aNode->Y());
395 aBounds[4] = min(aBounds[4],aNode->Z());
396 aBounds[5] = max(aBounds[5],aNode->Z());
400 TopoDS_Shape mainShape = myMesh->ShapeToMesh();
401 bool hasShapeToMesh = ( myMesh->SubMeshIndices().size() > 1 );
402 if ( !mainShape.IsNull() && hasShapeToMesh )
404 // define EPS by max tolerance of the mainShape (IPAL53097)
405 TopExp_Explorer subShape;
406 for ( subShape.Init( mainShape, TopAbs_FACE ); subShape.More(); subShape.Next() ) {
407 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Face( subShape.Current() )));
409 for ( subShape.Init( mainShape, TopAbs_EDGE ); subShape.More(); subShape.Next() ) {
410 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Edge( subShape.Current() )));
412 for ( subShape.Init( mainShape, TopAbs_VERTEX ); subShape.More(); subShape.Next() ) {
413 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Vertex( subShape.Current() )));
417 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
418 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
419 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
420 aSpaceDimension = Max( aMeshDimension, anIsXDimension + anIsYDimension + anIsZDimension );
421 if ( !aSpaceDimension )
423 // PAL16857(SMESH not conform to the MED convention):
424 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
426 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
427 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
428 if ( anIsYDimension ) {
430 anIsXDimension = true;
437 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
438 switch ( aSpaceDimension ) {
440 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
443 if(anIsXDimension && anIsYDimension)
444 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
445 if(anIsYDimension && anIsZDimension)
446 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
447 if(anIsXDimension && anIsZDimension)
448 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
452 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
454 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
456 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
461 MED::PWrapper myMed = CrWrapperW(myFile, myVersion);
462 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
463 //MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
464 myMed->SetMeshInfo(aMeshInfo);
466 // Storing SMDS groups and sub-meshes as med families
467 //----------------------------------------------------
468 int myNodesDefaultFamilyId = 0;
469 int my0DElementsDefaultFamilyId = 0;
470 int myBallsDefaultFamilyId = 0;
471 int myEdgesDefaultFamilyId = 0;
472 int myFacesDefaultFamilyId = 0;
473 int myVolumesDefaultFamilyId = 0;
474 int nbNodes = myMesh->NbNodes();
475 int nb0DElements = myMesh->Nb0DElements();
476 int nbBalls = myMesh->NbBalls();
477 int nbEdges = myMesh->NbEdges();
478 int nbFaces = myMesh->NbFaces();
479 int nbVolumes = myMesh->NbVolumes();
480 if (myDoGroupOfNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
481 if (myDoGroupOfEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
482 if (myDoGroupOfFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
483 if (myDoGroupOfVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
484 if (myDoGroupOf0DElems) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
485 if (myDoGroupOfBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
486 if (myDoAllInGroups )
488 if (!myDoGroupOfEdges) myEdgesDefaultFamilyId = NIG_EDGES_FAMILY ;
489 if (!myDoGroupOfFaces) myFacesDefaultFamilyId = NIG_FACES_FAMILY ;
490 if (!myDoGroupOfVolumes) myVolumesDefaultFamilyId = NIG_VOLS_FAMILY ;
491 if (!myDoGroupOf0DElems) my0DElementsDefaultFamilyId = NIG_0DELEM_FAMILY ;
492 if (!myDoGroupOfBalls) myBallsDefaultFamilyId = NIG_BALL_FAMILY ;
495 //MESSAGE("Perform - aFamilyInfo");
496 list<DriverMED_FamilyPtr> aFamilies;
497 if (myAllSubMeshes) {
498 aFamilies = DriverMED_Family::MakeFamilies
499 (myMesh->SubMeshes(), myGroups,
500 myDoGroupOfNodes && nbNodes,
501 myDoGroupOfEdges && nbEdges,
502 myDoGroupOfFaces && nbFaces,
503 myDoGroupOfVolumes && nbVolumes,
504 myDoGroupOf0DElems && nb0DElements,
505 myDoGroupOfBalls && nbBalls,
509 aFamilies = DriverMED_Family::MakeFamilies
510 (getIterator( mySubMeshes ), myGroups,
511 myDoGroupOfNodes && nbNodes,
512 myDoGroupOfEdges && nbEdges,
513 myDoGroupOfFaces && nbFaces,
514 myDoGroupOfVolumes && nbVolumes,
515 myDoGroupOf0DElems && nb0DElements,
516 myDoGroupOfBalls && nbBalls,
519 list<DriverMED_FamilyPtr>::iterator aFamsIter;
520 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
522 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
523 myMed->SetFamilyInfo(aFamilyInfo);
526 // Storing SMDS nodes to the MED file for the MED mesh
527 //----------------------------------------------------
528 #ifdef _EDF_NODE_IDS_
529 typedef map<TInt,TInt> TNodeIdMap;
530 TNodeIdMap aNodeIdMap;
532 const EModeSwitch theMode = eFULL_INTERLACE;
533 const ERepere theSystem = eCART;
534 const EBooleen theIsElemNum = eVRAI;
535 const EBooleen theIsElemNames = eFAUX;
536 const EConnectivite theConnMode = eNOD;
538 TInt aNbNodes = myMesh->NbNodes();
539 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
540 theMode, theSystem, theIsElemNum, theIsElemNames);
542 // find family numbers for nodes
543 TElemFamilyMap anElemFamMap;
544 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
546 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
549 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
550 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
551 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
554 int aNodeID = aCoordHelperPtr->GetID();
555 aNodeInfo->SetElemNum( iNode, aNodeID );
556 #ifdef _EDF_NODE_IDS_
557 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
560 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
561 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
562 aNodeInfo->SetFamNum( iNode, famNum );
564 anElemFamMap.Clear();
566 // coordinate names and units
567 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
568 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
569 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
572 //MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
573 myMed->SetNodeInfo(aNodeInfo);
574 aNodeInfo.reset(); // free memory used for arrays
577 // Storing SMDS elements to the MED file for the MED mesh
578 //-------------------------------------------------------
579 // Write one element type at once in order to minimize memory usage (PAL19276)
581 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
583 // poly elements are not supported by med-2.1
584 bool polyTypesSupported = ( myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0).get() != 0 );
585 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
587 // nodes on VERTEXes where 0D elements are absent
588 std::vector<const SMDS_MeshElement*> nodesOf0D;
589 std::vector< SMDS_ElemIteratorPtr > iterVec;
590 SMDS_ElemIteratorPtr iterVecIter;
591 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
594 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
595 iterVec[1] = SMDS_ElemIteratorPtr
596 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
598 typedef SMDS_IteratorOnIterators
599 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
600 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
603 // collect info on all geom types
605 list< TElemTypeData > aTElemTypeDatas;
607 EEntiteMaillage anEntity = eMAILLE;
608 #ifdef _ELEMENTS_BY_DIM_
609 anEntity = eNOEUD_ELEMENT;
611 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
613 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
615 #ifdef _ELEMENTS_BY_DIM_
616 anEntity = eSTRUCT_ELEMENT;
618 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
620 nbElemInfo.NbBalls(),
622 #ifdef _ELEMENTS_BY_DIM_
625 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
627 nbElemInfo.NbEdges( ORDER_LINEAR ),
629 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
631 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
633 #ifdef _ELEMENTS_BY_DIM_
636 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
638 nbElemInfo.NbTriangles( ORDER_LINEAR ),
640 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
642 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
643 nbElemInfo.NbBiQuadTriangles(),
645 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
647 nbElemInfo.NbBiQuadTriangles(),
649 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
651 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
653 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
655 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
656 nbElemInfo.NbBiQuadQuadrangles(),
658 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
660 nbElemInfo.NbBiQuadQuadrangles(),
662 if ( polyTypesSupported ) {
663 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
665 nbElemInfo.NbPolygons( ORDER_LINEAR ),
667 // we need one more loop on poly elements to count nb of their nodes
668 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
670 nbElemInfo.NbPolygons( ORDER_LINEAR ),
672 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
674 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
676 // we need one more loop on QUAD poly elements to count nb of their nodes
677 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
679 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
682 #ifdef _ELEMENTS_BY_DIM_
685 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
687 nbElemInfo.NbTetras( ORDER_LINEAR ),
689 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
691 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
693 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
695 nbElemInfo.NbPyramids( ORDER_LINEAR ),
697 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
699 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
701 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
703 nbElemInfo.NbPrisms( ORDER_LINEAR ),
705 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
707 nbElemInfo.NbQuadPrisms(),
709 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
711 nbElemInfo.NbBiQuadPrisms(),
713 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
715 nbElemInfo.NbHexas( ORDER_LINEAR ),
717 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
719 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
720 nbElemInfo.NbTriQuadHexas(),
722 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
724 nbElemInfo.NbTriQuadHexas(),
726 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
728 nbElemInfo.NbHexPrisms(),
730 if ( polyTypesSupported ) {
731 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
733 nbElemInfo.NbPolyhedrons(),
735 // we need one more loop on poly elements to count nb of their nodes
736 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
738 nbElemInfo.NbPolyhedrons(),
742 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
744 // loop on all geom types of elements
746 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
747 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
749 if ( aElemTypeData->_nbElems == 0 )
752 int defaultFamilyId = 0;
753 switch ( aElemTypeData->_smdsType ) {
754 case SMDSAbs_0DElement: defaultFamilyId = my0DElementsDefaultFamilyId; break;
755 case SMDSAbs_Ball: defaultFamilyId = myBallsDefaultFamilyId; break;
756 case SMDSAbs_Edge: defaultFamilyId = myEdgesDefaultFamilyId; break;
757 case SMDSAbs_Face: defaultFamilyId = myFacesDefaultFamilyId; break;
758 case SMDSAbs_Volume: defaultFamilyId = myVolumesDefaultFamilyId; break;
763 // build map of family numbers for this type
764 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
766 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
767 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
770 // iterator on elements of a current type
771 SMDS_ElemIteratorPtr elemIterator;
776 if ( aElemTypeData->_geomType == ePOLYGONE ||
777 aElemTypeData->_geomType == ePOLYGON2 )
779 if ( aElemTypeData->_geomType == ePOLYGONE )
780 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Polygon );
782 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Quad_Polygon );
784 if ( nbPolygonNodes == 0 ) {
786 while ( elemIterator->more() ) {
787 const SMDS_MeshElement* anElem = elemIterator->next();
788 nbPolygonNodes += anElem->NbNodes();
789 if ( ++iElem == aElemTypeData->_nbElems )
795 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
796 aElemTypeData->_entity,
797 aElemTypeData->_geomType,
798 aElemTypeData->_nbElems,
800 theConnMode, theIsElemNum,
802 TElemNum & index = *(aPolygoneInfo->myIndex.get());
805 while ( elemIterator->more() )
807 const SMDS_MeshElement* anElem = elemIterator->next();
809 TInt aNbNodes = anElem->NbNodes();
810 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
813 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
814 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
815 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
816 #ifdef _EDF_NODE_IDS_
817 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
819 aTConnSlice[ iNode ] = aNode->GetID();
823 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
826 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
827 aPolygoneInfo->SetFamNum( iElem, famNum );
829 if ( ++iElem == aPolygoneInfo->GetNbElem() )
832 myMed->SetPolygoneInfo(aPolygoneInfo);
834 nbPolygonNodes = 0; // to treat next polygon type
840 else if ( aElemTypeData->_geomType == ePOLYEDRE )
842 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
844 if ( nbPolyhedronNodes == 0 ) {
846 while ( elemIterator->more() ) {
847 const SMDS_MeshElement* anElem = elemIterator->next();
848 nbPolyhedronNodes += anElem->NbNodes();
849 nbPolyhedronFaces += anElem->NbFaces();
850 if ( ++iElem == aElemTypeData->_nbElems )
856 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
857 aElemTypeData->_entity,
858 aElemTypeData->_geomType,
859 aElemTypeData->_nbElems,
865 TElemNum & index = *(aPolyhInfo->myIndex.get());
866 TElemNum & faces = *(aPolyhInfo->myFaces.get());
867 TElemNum & conn = *(aPolyhInfo->myConn.get());
871 TInt iFace = 0, iNode = 0;
872 while ( elemIterator->more() )
874 const SMDS_MeshElement* anElem = elemIterator->next();
875 const SMDS_MeshVolume *aPolyedre = myMesh->DownCast< SMDS_MeshVolume >( anElem );
876 if ( !aPolyedre ) continue;
878 TInt aNbFaces = aPolyedre->NbFaces();
879 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
882 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
883 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
884 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
887 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
888 while ( nodeIt->more() ) {
889 const SMDS_MeshElement* aNode = nodeIt->next();
890 #ifdef _EDF_NODE_IDS_
891 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
893 conn[ iNode ] = aNode->GetID();
898 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
901 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
902 aPolyhInfo->SetFamNum( iElem, famNum );
904 if ( ++iElem == aPolyhInfo->GetNbElem() )
907 myMed->SetPolyedreInfo(aPolyhInfo);
909 } // if (aElemTypeData->_geomType == ePOLYEDRE )
913 else if (aElemTypeData->_geomType == eBALL )
915 // allocate data arrays
916 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo, aElemTypeData->_nbElems );
918 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
919 while ( elemIterator->more() )
921 const SMDS_MeshElement* anElem = elemIterator->next();
923 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
924 #ifdef _EDF_NODE_IDS_
925 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
927 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
930 aBallInfo->SetElemNum( iElem, anElem->GetID() );
933 aBallInfo->myDiameters[ iElem ] =
934 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
937 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
938 aBallInfo->SetFamNum( iElem, famNum );
941 // store data in a file
942 myMed->SetBallInfo(aBallInfo);
947 // Treat standard types
948 // ---------------------
949 // allocate data arrays
950 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
951 aElemTypeData->_entity,
952 aElemTypeData->_geomType,
953 aElemTypeData->_nbElems,
958 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
959 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
960 if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() )
961 elemIterator = iterVecIter;
962 while ( elemIterator->more() )
964 const SMDS_MeshElement* anElem = elemIterator->next();
965 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
966 continue; // other geometry
969 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
970 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
971 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
972 #ifdef _EDF_NODE_IDS_
973 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
975 aTConnSlice[ iNode ] = aNode->GetID();
979 aCellInfo->SetElemNum( iElem, anElem->GetID() );
982 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
983 aCellInfo->SetFamNum( iElem, famNum );
985 if ( ++iElem == aCellInfo->GetNbElem() )
988 // store data in a file
989 myMed->SetCellInfo(aCellInfo);
991 } // loop on geom types
993 catch(const std::exception& exc) {
994 INFOS("The following exception was caught:\n\t"<<exc.what());
998 INFOS("Unknown exception was caught !!!");
1004 mySubMeshes.clear();
1008 //================================================================================
1010 * \brief Returns nodes on VERTEXes where 0D elements are absent
1012 //================================================================================
1014 bool DriverMED_W_SMESHDS_Mesh::
1015 getNodesOfMissing0DOnVert(SMESHDS_Mesh* meshDS,
1016 std::vector<const SMDS_MeshElement*>& nodes)
1019 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
1021 if ( meshDS->IndexToShape( i ).ShapeType() != TopAbs_VERTEX )
1023 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(i) ) {
1024 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
1027 const SMDS_MeshNode* n = nIt->next();
1028 if ( n->NbInverseElements( SMDSAbs_0DElement ) == 0 )
1029 nodes.push_back( n );
1033 return !nodes.empty();