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 myMedVersion(MED::eV2_2),
56 myAllSubMeshes (false),
57 myDoGroupOfNodes (false),
58 myDoGroupOfEdges (false),
59 myDoGroupOfFaces (false),
60 myDoGroupOfVolumes (false),
61 myDoGroupOf0DElems(false),
62 myDoGroupOfBalls(false),
63 myAutoDimension(false),
64 myAddODOnVertices(false),
65 myDoAllInGroups(false)
68 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
71 Driver_SMESHDS_Mesh::SetFile(theFileName);
73 //MESSAGE("myMedVersion:"<<myMedVersion);
76 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
78 Driver_SMESHDS_Mesh::SetFile(theFileName);
82 * MED version is either the latest available, or with an inferior minor,
83 * to ensure backward compatibility on writing med files.
85 string DriverMED_W_SMESHDS_Mesh::GetVersionString(const MED::EVersion theVersion, int theNbDigits)
87 TInt majeur, mineur, release;
88 majeur = mineur = release = 0;
89 MED::GetVersionRelease<eV2_2>(majeur, mineur, release);
90 TInt imposedMineur = mineur;
91 switch( theVersion ) {
94 case MED::eLATEST : break;
95 case MED::eMINOR_0 : imposedMineur = 0; break;
96 case MED::eMINOR_1 : imposedMineur = 1; break;
97 case MED::eMINOR_2 : imposedMineur = 2; break;
98 case MED::eMINOR_3 : imposedMineur = 3; break;
99 case MED::eMINOR_4 : imposedMineur = 4; break;
100 case MED::eMINOR_5 : imposedMineur = 5; break;
101 case MED::eMINOR_6 : imposedMineur = 6; break;
102 case MED::eMINOR_7 : imposedMineur = 7; break;
103 case MED::eMINOR_8 : imposedMineur = 8; break;
104 case MED::eMINOR_9 : imposedMineur = 9; break;
105 case MED::eVUnknown : imposedMineur = mineur; break;
107 if (imposedMineur > mineur)
108 imposedMineur = mineur;
110 if ( theNbDigits > 0 )
112 if ( theNbDigits > 1 )
113 name << "." << imposedMineur;
114 if ( theNbDigits > 2 )
115 name << "." << release;
119 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
121 myGroups.push_back(theGroup);
124 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
126 myAllSubMeshes = true;
129 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
131 mySubMeshes.push_back( theSubMesh );
134 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
136 myDoGroupOfNodes = true;
139 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
141 myDoGroupOfEdges = true;
144 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
146 myDoGroupOfFaces = true;
149 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
151 myDoGroupOfVolumes = true;
154 void DriverMED_W_SMESHDS_Mesh::AddGroupOf0DElems()
156 myDoGroupOf0DElems = true;
159 void DriverMED_W_SMESHDS_Mesh::AddGroupOfBalls()
161 myDoGroupOfBalls = true;
164 //================================================================================
166 * \brief Set up a flag to add all elements not belonging to any group to
167 * some auxiliary group. This is needed for SMESH -> SAUVE -> SMESH conversion,
168 * which since PAL0023285 reads only SAUVE elements belonging to any group,
169 * and hence can lose some elements. That auxiliary group is ignored while
170 * reading a MED file.
172 //================================================================================
174 void DriverMED_W_SMESHDS_Mesh::AddAllToGroup()
176 myDoAllInGroups = true;
182 typedef double (SMDS_MeshNode::* TGetCoord)() const;
183 typedef const char* TName;
184 typedef const char* TUnit;
186 // name length in a mesh must be equal to 16 :
193 TUnit aUnit[3] = {M,M,M};
196 TGetCoord aXYZGetCoord[3] = {
201 TName aXYZName[3] = {X,Y,Z};
204 TGetCoord aXYGetCoord[2] = {
208 TName aXYName[2] = {X,Y};
210 TGetCoord aYZGetCoord[2] = {
214 TName aYZName[2] = {Y,Z};
216 TGetCoord aXZGetCoord[2] = {
220 TName aXZName[2] = {X,Z};
223 TGetCoord aXGetCoord[1] = {
226 TName aXName[1] = {X};
228 TGetCoord aYGetCoord[1] = {
231 TName aYName[1] = {Y};
233 TGetCoord aZGetCoord[1] = {
236 TName aZName[1] = {Z};
240 SMDS_NodeIteratorPtr myNodeIter;
241 const SMDS_MeshNode* myCurrentNode;
242 TGetCoord* myGetCoord;
246 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
247 TGetCoord* theGetCoord,
249 TUnit* theUnit = aUnit):
250 myNodeIter(theNodeIter),
251 myGetCoord(theGetCoord),
255 virtual ~TCoordHelper(){}
257 return myNodeIter->more() &&
258 (myCurrentNode = myNodeIter->next());
260 const SMDS_MeshNode* GetNode(){
261 return myCurrentNode;
263 MED::TIntVector::value_type GetID(){
264 return myCurrentNode->GetID();
266 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
267 return (myCurrentNode->*myGetCoord[theCoodId])();
269 MED::TStringVector::value_type GetName(TInt theDimId){
270 return myName[theDimId];
272 MED::TStringVector::value_type GetUnit(TInt theDimId){
273 return myUnit[theDimId];
276 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
278 //-------------------------------------------------------
280 * \brief Structure describing element type
282 //-------------------------------------------------------
285 EEntiteMaillage _entity;
286 EGeometrieElement _geomType;
288 SMDSAbs_ElementType _smdsType;
290 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
291 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
295 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
297 //================================================================================
299 * \brief Fills element to famaly ID map for element type.
300 * Removes all families of anElemType
302 //================================================================================
304 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
305 list<DriverMED_FamilyPtr> & aFamilies,
306 const SMDSAbs_ElementType anElemType)
308 anElemFamMap.Clear();
309 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
310 while ( aFamsIter != aFamilies.end() )
312 if ((*aFamsIter)->GetType() != anElemType) {
316 int aFamId = (*aFamsIter)->GetId();
317 const ElementsSet& anElems = (*aFamsIter)->GetElements();
318 ElementsSet::const_iterator anElemsIter = anElems.begin();
319 for (; anElemsIter != anElems.end(); anElemsIter++)
321 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
323 // remove a family from the list
324 aFamilies.erase( aFamsIter++ );
329 //================================================================================
331 * \brief For an element, return family ID found in the map or a default one
333 //================================================================================
335 int getFamilyId( const TElemFamilyMap & anElemFamMap,
336 const SMDS_MeshElement* anElement,
337 const int aDefaultFamilyId)
339 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
340 return anElemFamMap( (Standard_Address) anElement );
342 return aDefaultFamilyId;
345 //================================================================================
347 * \brief Returns iterator on sub-meshes
349 //================================================================================
351 SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& mySubMeshes )
353 return SMESHDS_SubMeshIteratorPtr
354 ( new SMDS_SetIterator
355 < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(),
356 mySubMeshes.end() ));
360 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
362 Status aResult = DRS_OK;
363 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
364 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
368 //MESSAGE("Perform - myFile : "<<myFile);
370 // Creating the MED mesh for corresponding SMDS structure
371 //-------------------------------------------------------
373 if (myMeshId != -1) {
374 ostringstream aMeshNameStr;
375 aMeshNameStr<<myMeshId;
376 aMeshName = aMeshNameStr.str();
378 aMeshName = myMeshName;
381 // Mesh dimension definition
383 TInt aMeshDimension = 0;
384 if ( myMesh->NbEdges() > 0 )
386 if ( myMesh->NbFaces() > 0 )
388 if ( myMesh->NbVolumes() > 0 )
391 TInt aSpaceDimension = 3;
392 TCoordHelperPtr aCoordHelperPtr;
394 bool anIsXDimension = false;
395 bool anIsYDimension = false;
396 bool anIsZDimension = false;
397 if ( myAutoDimension && aMeshDimension < 3 )
399 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
401 if(aNodesIter->more()){
402 const SMDS_MeshNode* aNode = aNodesIter->next();
403 aBounds[0] = aBounds[1] = aNode->X();
404 aBounds[2] = aBounds[3] = aNode->Y();
405 aBounds[4] = aBounds[5] = aNode->Z();
407 while(aNodesIter->more()){
408 const SMDS_MeshNode* aNode = aNodesIter->next();
409 aBounds[0] = min(aBounds[0],aNode->X());
410 aBounds[1] = max(aBounds[1],aNode->X());
412 aBounds[2] = min(aBounds[2],aNode->Y());
413 aBounds[3] = max(aBounds[3],aNode->Y());
415 aBounds[4] = min(aBounds[4],aNode->Z());
416 aBounds[5] = max(aBounds[5],aNode->Z());
420 TopoDS_Shape mainShape = myMesh->ShapeToMesh();
421 bool hasShapeToMesh = ( myMesh->SubMeshIndices().size() > 1 );
422 if ( !mainShape.IsNull() && hasShapeToMesh )
424 // define EPS by max tolerance of the mainShape (IPAL53097)
425 TopExp_Explorer subShape;
426 for ( subShape.Init( mainShape, TopAbs_FACE ); subShape.More(); subShape.Next() ) {
427 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Face( subShape.Current() )));
429 for ( subShape.Init( mainShape, TopAbs_EDGE ); subShape.More(); subShape.Next() ) {
430 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Edge( subShape.Current() )));
432 for ( subShape.Init( mainShape, TopAbs_VERTEX ); subShape.More(); subShape.Next() ) {
433 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Vertex( subShape.Current() )));
437 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
438 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
439 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
440 aSpaceDimension = Max( aMeshDimension, anIsXDimension + anIsYDimension + anIsZDimension );
441 if ( !aSpaceDimension )
443 // PAL16857(SMESH not conform to the MED convention):
444 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
446 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
447 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
448 if ( anIsYDimension ) {
450 anIsXDimension = true;
457 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
458 switch ( aSpaceDimension ) {
460 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
463 if(anIsXDimension && anIsYDimension)
464 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
465 if(anIsYDimension && anIsZDimension)
466 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
467 if(anIsXDimension && anIsZDimension)
468 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
472 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
474 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
476 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
480 //MESSAGE("myMedVersion:"<<myMedVersion);
481 MED::PWrapper myMed = CrWrapper(myFile,myMedVersion);
482 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
483 //MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
484 myMed->SetMeshInfo(aMeshInfo);
486 // Storing SMDS groups and sub-meshes as med families
487 //----------------------------------------------------
488 int myNodesDefaultFamilyId = 0;
489 int my0DElementsDefaultFamilyId = 0;
490 int myBallsDefaultFamilyId = 0;
491 int myEdgesDefaultFamilyId = 0;
492 int myFacesDefaultFamilyId = 0;
493 int myVolumesDefaultFamilyId = 0;
494 int nbNodes = myMesh->NbNodes();
495 int nb0DElements = myMesh->Nb0DElements();
496 int nbBalls = myMesh->NbBalls();
497 int nbEdges = myMesh->NbEdges();
498 int nbFaces = myMesh->NbFaces();
499 int nbVolumes = myMesh->NbVolumes();
500 if (myDoGroupOfNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
501 if (myDoGroupOfEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
502 if (myDoGroupOfFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
503 if (myDoGroupOfVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
504 if (myDoGroupOf0DElems) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
505 if (myDoGroupOfBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
506 if (myDoAllInGroups )
508 if (!myDoGroupOfEdges) myEdgesDefaultFamilyId = NIG_EDGES_FAMILY ;
509 if (!myDoGroupOfFaces) myFacesDefaultFamilyId = NIG_FACES_FAMILY ;
510 if (!myDoGroupOfVolumes) myVolumesDefaultFamilyId = NIG_VOLS_FAMILY ;
511 if (!myDoGroupOf0DElems) my0DElementsDefaultFamilyId = NIG_0DELEM_FAMILY ;
512 if (!myDoGroupOfBalls) myBallsDefaultFamilyId = NIG_BALL_FAMILY ;
515 //MESSAGE("Perform - aFamilyInfo");
516 list<DriverMED_FamilyPtr> aFamilies;
517 if (myAllSubMeshes) {
518 aFamilies = DriverMED_Family::MakeFamilies
519 (myMesh->SubMeshes(), myGroups,
520 myDoGroupOfNodes && nbNodes,
521 myDoGroupOfEdges && nbEdges,
522 myDoGroupOfFaces && nbFaces,
523 myDoGroupOfVolumes && nbVolumes,
524 myDoGroupOf0DElems && nb0DElements,
525 myDoGroupOfBalls && nbBalls,
529 aFamilies = DriverMED_Family::MakeFamilies
530 (getIterator( mySubMeshes ), myGroups,
531 myDoGroupOfNodes && nbNodes,
532 myDoGroupOfEdges && nbEdges,
533 myDoGroupOfFaces && nbFaces,
534 myDoGroupOfVolumes && nbVolumes,
535 myDoGroupOf0DElems && nb0DElements,
536 myDoGroupOfBalls && nbBalls,
539 list<DriverMED_FamilyPtr>::iterator aFamsIter;
540 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
542 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
543 myMed->SetFamilyInfo(aFamilyInfo);
546 // Storing SMDS nodes to the MED file for the MED mesh
547 //----------------------------------------------------
548 #ifdef _EDF_NODE_IDS_
549 typedef map<TInt,TInt> TNodeIdMap;
550 TNodeIdMap aNodeIdMap;
552 const EModeSwitch theMode = eFULL_INTERLACE;
553 const ERepere theSystem = eCART;
554 const EBooleen theIsElemNum = eVRAI;
555 const EBooleen theIsElemNames = eFAUX;
556 const EConnectivite theConnMode = eNOD;
558 TInt aNbNodes = myMesh->NbNodes();
559 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
560 theMode, theSystem, theIsElemNum, theIsElemNames);
562 // find family numbers for nodes
563 TElemFamilyMap anElemFamMap;
564 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
566 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
569 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
570 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
571 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
574 int aNodeID = aCoordHelperPtr->GetID();
575 aNodeInfo->SetElemNum( iNode, aNodeID );
576 #ifdef _EDF_NODE_IDS_
577 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
580 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
581 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
582 aNodeInfo->SetFamNum( iNode, famNum );
584 anElemFamMap.Clear();
586 // coordinate names and units
587 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
588 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
589 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
592 //MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
593 myMed->SetNodeInfo(aNodeInfo);
594 aNodeInfo.reset(); // free memory used for arrays
597 // Storing SMDS elements to the MED file for the MED mesh
598 //-------------------------------------------------------
599 // Write one element type at once in order to minimize memory usage (PAL19276)
601 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
603 // poly elements are not supported by med-2.1
604 bool polyTypesSupported = ( myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0).get() != 0 );
605 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
607 // nodes on VERTEXes where 0D elements are absent
608 std::vector<const SMDS_MeshElement*> nodesOf0D;
609 std::vector< SMDS_ElemIteratorPtr > iterVec;
610 SMDS_ElemIteratorPtr iterVecIter;
611 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
614 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
615 iterVec[1] = SMDS_ElemIteratorPtr
616 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
618 typedef SMDS_IteratorOnIterators
619 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
620 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
623 // collect info on all geom types
625 list< TElemTypeData > aTElemTypeDatas;
627 EEntiteMaillage anEntity = eMAILLE;
628 #ifdef _ELEMENTS_BY_DIM_
629 anEntity = eNOEUD_ELEMENT;
631 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
633 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
635 #ifdef _ELEMENTS_BY_DIM_
636 anEntity = eSTRUCT_ELEMENT;
638 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
640 nbElemInfo.NbBalls(),
642 #ifdef _ELEMENTS_BY_DIM_
645 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
647 nbElemInfo.NbEdges( ORDER_LINEAR ),
649 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
651 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
653 #ifdef _ELEMENTS_BY_DIM_
656 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
658 nbElemInfo.NbTriangles( ORDER_LINEAR ),
660 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
662 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
663 nbElemInfo.NbBiQuadTriangles(),
665 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
667 nbElemInfo.NbBiQuadTriangles(),
669 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
671 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
673 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
675 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
676 nbElemInfo.NbBiQuadQuadrangles(),
678 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
680 nbElemInfo.NbBiQuadQuadrangles(),
682 if ( polyTypesSupported ) {
683 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
685 nbElemInfo.NbPolygons( ORDER_LINEAR ),
687 // we need one more loop on poly elements to count nb of their nodes
688 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
690 nbElemInfo.NbPolygons( ORDER_LINEAR ),
692 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
694 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
696 // we need one more loop on QUAD poly elements to count nb of their nodes
697 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
699 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
702 #ifdef _ELEMENTS_BY_DIM_
705 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
707 nbElemInfo.NbTetras( ORDER_LINEAR ),
709 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
711 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
713 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
715 nbElemInfo.NbPyramids( ORDER_LINEAR ),
717 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
719 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
721 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
723 nbElemInfo.NbPrisms( ORDER_LINEAR ),
725 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
727 nbElemInfo.NbQuadPrisms(),
729 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
731 nbElemInfo.NbBiQuadPrisms(),
733 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
735 nbElemInfo.NbHexas( ORDER_LINEAR ),
737 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
739 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
740 nbElemInfo.NbTriQuadHexas(),
742 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
744 nbElemInfo.NbTriQuadHexas(),
746 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
748 nbElemInfo.NbHexPrisms(),
750 if ( polyTypesSupported ) {
751 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
753 nbElemInfo.NbPolyhedrons(),
755 // we need one more loop on poly elements to count nb of their nodes
756 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
758 nbElemInfo.NbPolyhedrons(),
762 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
764 // loop on all geom types of elements
766 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
767 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
769 if ( aElemTypeData->_nbElems == 0 )
772 int defaultFamilyId = 0;
773 switch ( aElemTypeData->_smdsType ) {
774 case SMDSAbs_0DElement: defaultFamilyId = my0DElementsDefaultFamilyId; break;
775 case SMDSAbs_Ball: defaultFamilyId = myBallsDefaultFamilyId; break;
776 case SMDSAbs_Edge: defaultFamilyId = myEdgesDefaultFamilyId; break;
777 case SMDSAbs_Face: defaultFamilyId = myFacesDefaultFamilyId; break;
778 case SMDSAbs_Volume: defaultFamilyId = myVolumesDefaultFamilyId; break;
783 // build map of family numbers for this type
784 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
786 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
787 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
790 // iterator on elements of a current type
791 SMDS_ElemIteratorPtr elemIterator;
796 if ( aElemTypeData->_geomType == ePOLYGONE ||
797 aElemTypeData->_geomType == ePOLYGON2 )
799 if ( aElemTypeData->_geomType == ePOLYGONE )
800 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Polygon );
802 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Quad_Polygon );
804 if ( nbPolygonNodes == 0 ) {
806 while ( elemIterator->more() ) {
807 const SMDS_MeshElement* anElem = elemIterator->next();
808 nbPolygonNodes += anElem->NbNodes();
809 if ( ++iElem == aElemTypeData->_nbElems )
815 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
816 aElemTypeData->_entity,
817 aElemTypeData->_geomType,
818 aElemTypeData->_nbElems,
820 theConnMode, theIsElemNum,
822 TElemNum & index = *(aPolygoneInfo->myIndex.get());
825 while ( elemIterator->more() )
827 const SMDS_MeshElement* anElem = elemIterator->next();
829 TInt aNbNodes = anElem->NbNodes();
830 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
833 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
834 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
835 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
836 #ifdef _EDF_NODE_IDS_
837 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
839 aTConnSlice[ iNode ] = aNode->GetID();
843 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
846 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
847 aPolygoneInfo->SetFamNum( iElem, famNum );
849 if ( ++iElem == aPolygoneInfo->GetNbElem() )
852 myMed->SetPolygoneInfo(aPolygoneInfo);
854 nbPolygonNodes = 0; // to treat next polygon type
860 else if (aElemTypeData->_geomType == ePOLYEDRE )
862 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
864 if ( nbPolyhedronNodes == 0 ) {
866 while ( elemIterator->more() ) {
867 const SMDS_MeshElement* anElem = elemIterator->next();
868 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
869 if ( !aPolyedre ) continue;
870 nbPolyhedronNodes += aPolyedre->NbNodes();
871 nbPolyhedronFaces += aPolyedre->NbFaces();
872 if ( ++iElem == aElemTypeData->_nbElems )
878 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
879 aElemTypeData->_entity,
880 aElemTypeData->_geomType,
881 aElemTypeData->_nbElems,
887 TElemNum & index = *(aPolyhInfo->myIndex.get());
888 TElemNum & faces = *(aPolyhInfo->myFaces.get());
889 TElemNum & conn = *(aPolyhInfo->myConn.get());
893 TInt iFace = 0, iNode = 0;
894 while ( elemIterator->more() )
896 const SMDS_MeshElement* anElem = elemIterator->next();
897 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
898 if ( !aPolyedre ) continue;
900 TInt aNbFaces = aPolyedre->NbFaces();
901 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
904 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
905 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
906 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
909 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
910 while ( nodeIt->more() ) {
911 const SMDS_MeshElement* aNode = nodeIt->next();
912 #ifdef _EDF_NODE_IDS_
913 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
915 conn[ iNode ] = aNode->GetID();
920 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
923 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
924 aPolyhInfo->SetFamNum( iElem, famNum );
926 if ( ++iElem == aPolyhInfo->GetNbElem() )
929 myMed->SetPolyedreInfo(aPolyhInfo);
931 } // if (aElemTypeData->_geomType == ePOLYEDRE )
935 else if (aElemTypeData->_geomType == eBALL )
937 // allocate data arrays
938 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo, aElemTypeData->_nbElems );
940 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
941 while ( elemIterator->more() )
943 const SMDS_MeshElement* anElem = elemIterator->next();
945 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
946 #ifdef _EDF_NODE_IDS_
947 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
949 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
952 aBallInfo->SetElemNum( iElem, anElem->GetID() );
955 aBallInfo->myDiameters[ iElem ] =
956 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
959 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
960 aBallInfo->SetFamNum( iElem, famNum );
963 // store data in a file
964 myMed->SetBallInfo(aBallInfo);
969 // Treat standard types
970 // ---------------------
971 // allocate data arrays
972 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
973 aElemTypeData->_entity,
974 aElemTypeData->_geomType,
975 aElemTypeData->_nbElems,
980 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
981 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
982 if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() )
983 elemIterator = iterVecIter;
984 while ( elemIterator->more() )
986 const SMDS_MeshElement* anElem = elemIterator->next();
987 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
988 continue; // other geometry
991 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
992 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
993 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
994 #ifdef _EDF_NODE_IDS_
995 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
997 aTConnSlice[ iNode ] = aNode->GetID();
1001 aCellInfo->SetElemNum( iElem, anElem->GetID() );
1004 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
1005 aCellInfo->SetFamNum( iElem, famNum );
1007 if ( ++iElem == aCellInfo->GetNbElem() )
1010 // store data in a file
1011 myMed->SetCellInfo(aCellInfo);
1013 } // loop on geom types
1015 catch(const std::exception& exc) {
1016 INFOS("The following exception was caught:\n\t"<<exc.what());
1020 INFOS("Unknown exception was caught !!!");
1026 mySubMeshes.clear();
1030 //================================================================================
1032 * \brief Returns nodes on VERTEXes where 0D elements are absent
1034 //================================================================================
1036 bool DriverMED_W_SMESHDS_Mesh::
1037 getNodesOfMissing0DOnVert(SMESHDS_Mesh* meshDS,
1038 std::vector<const SMDS_MeshElement*>& nodes)
1041 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
1043 if ( meshDS->IndexToShape( i ).ShapeType() != TopAbs_VERTEX )
1045 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(i) ) {
1046 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
1049 const SMDS_MeshNode* n = nIt->next();
1050 if ( n->NbInverseElements( SMDSAbs_0DElement ) == 0 )
1051 nodes.push_back( n );
1055 return !nodes.empty();