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)
67 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
70 Driver_SMESHDS_Mesh::SetFile(theFileName);
74 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
76 Driver_SMESHDS_Mesh::SetFile(theFileName);
79 string DriverMED_W_SMESHDS_Mesh::GetVersionString(const MED::EVersion theVersion, int theNbDigits)
81 TInt majeur, mineur, release;
82 majeur = mineur = release = 0;
83 // if ( theVersion == eV2_1 )
84 // MED::GetVersionRelease<eV2_1>(majeur, mineur, release);
86 MED::GetVersionRelease<eV2_2>(majeur, mineur, release);
88 if ( theNbDigits > 0 )
90 if ( theNbDigits > 1 )
91 name << "." << mineur;
92 if ( theNbDigits > 2 )
93 name << "." << release;
97 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
99 myGroups.push_back(theGroup);
102 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
104 myAllSubMeshes = true;
107 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
109 mySubMeshes.push_back( theSubMesh );
112 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
114 myDoGroupOfNodes = true;
117 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
119 myDoGroupOfEdges = true;
122 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
124 myDoGroupOfFaces = true;
127 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
129 myDoGroupOfVolumes = true;
134 typedef double (SMDS_MeshNode::* TGetCoord)() const;
135 typedef const char* TName;
136 typedef const char* TUnit;
138 // name length in a mesh must be equal to 16 :
145 TUnit aUnit[3] = {M,M,M};
148 TGetCoord aXYZGetCoord[3] = {
153 TName aXYZName[3] = {X,Y,Z};
156 TGetCoord aXYGetCoord[2] = {
160 TName aXYName[2] = {X,Y};
162 TGetCoord aYZGetCoord[2] = {
166 TName aYZName[2] = {Y,Z};
168 TGetCoord aXZGetCoord[2] = {
172 TName aXZName[2] = {X,Z};
175 TGetCoord aXGetCoord[1] = {
178 TName aXName[1] = {X};
180 TGetCoord aYGetCoord[1] = {
183 TName aYName[1] = {Y};
185 TGetCoord aZGetCoord[1] = {
188 TName aZName[1] = {Z};
192 SMDS_NodeIteratorPtr myNodeIter;
193 const SMDS_MeshNode* myCurrentNode;
194 TGetCoord* myGetCoord;
198 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
199 TGetCoord* theGetCoord,
201 TUnit* theUnit = aUnit):
202 myNodeIter(theNodeIter),
203 myGetCoord(theGetCoord),
207 virtual ~TCoordHelper(){}
209 return myNodeIter->more() &&
210 (myCurrentNode = myNodeIter->next());
212 const SMDS_MeshNode* GetNode(){
213 return myCurrentNode;
215 MED::TIntVector::value_type GetID(){
216 return myCurrentNode->GetID();
218 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
219 return (myCurrentNode->*myGetCoord[theCoodId])();
221 MED::TStringVector::value_type GetName(TInt theDimId){
222 return myName[theDimId];
224 MED::TStringVector::value_type GetUnit(TInt theDimId){
225 return myUnit[theDimId];
228 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
230 //-------------------------------------------------------
232 * \brief Structure describing element type
234 //-------------------------------------------------------
237 EEntiteMaillage _entity;
238 EGeometrieElement _geomType;
240 SMDSAbs_ElementType _smdsType;
242 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
243 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
247 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
249 //================================================================================
251 * \brief Fills element to famaly ID map for element type.
252 * Removes all families of anElemType
254 //================================================================================
256 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
257 list<DriverMED_FamilyPtr> & aFamilies,
258 const SMDSAbs_ElementType anElemType)
260 anElemFamMap.Clear();
261 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
262 while ( aFamsIter != aFamilies.end() )
264 if ((*aFamsIter)->GetType() != anElemType) {
268 int aFamId = (*aFamsIter)->GetId();
269 const ElementsSet& anElems = (*aFamsIter)->GetElements();
270 ElementsSet::const_iterator anElemsIter = anElems.begin();
271 for (; anElemsIter != anElems.end(); anElemsIter++)
273 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
275 // remove a family from the list
276 aFamilies.erase( aFamsIter++ );
281 //================================================================================
283 * \brief For an element, return family ID found in the map or a default one
285 //================================================================================
287 int getFamilyId( const TElemFamilyMap & anElemFamMap,
288 const SMDS_MeshElement* anElement,
289 const int aDefaultFamilyId)
291 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
292 return anElemFamMap( (Standard_Address) anElement );
294 return aDefaultFamilyId;
297 //================================================================================
299 * \brief Returns iterator on sub-meshes
301 //================================================================================
303 SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& mySubMeshes )
305 return SMESHDS_SubMeshIteratorPtr
306 ( new SMDS_SetIterator
307 < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(),
308 mySubMeshes.end() ));
312 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
314 Status aResult = DRS_OK;
315 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
316 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
320 //MESSAGE("Perform - myFile : "<<myFile);
322 // Creating the MED mesh for corresponding SMDS structure
323 //-------------------------------------------------------
325 if (myMeshId != -1) {
326 ostringstream aMeshNameStr;
327 aMeshNameStr<<myMeshId;
328 aMeshName = aMeshNameStr.str();
330 aMeshName = myMeshName;
333 // Mesh dimension definition
335 TInt aMeshDimension = 0;
336 if ( myMesh->NbEdges() > 0 )
338 if ( myMesh->NbFaces() > 0 )
340 if ( myMesh->NbVolumes() > 0 )
343 TInt aSpaceDimension = 3;
344 TCoordHelperPtr aCoordHelperPtr;
346 bool anIsXDimension = false;
347 bool anIsYDimension = false;
348 bool anIsZDimension = false;
349 if ( myAutoDimension && aMeshDimension < 3 )
351 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
353 if(aNodesIter->more()){
354 const SMDS_MeshNode* aNode = aNodesIter->next();
355 aBounds[0] = aBounds[1] = aNode->X();
356 aBounds[2] = aBounds[3] = aNode->Y();
357 aBounds[4] = aBounds[5] = aNode->Z();
359 while(aNodesIter->more()){
360 const SMDS_MeshNode* aNode = aNodesIter->next();
361 aBounds[0] = min(aBounds[0],aNode->X());
362 aBounds[1] = max(aBounds[1],aNode->X());
364 aBounds[2] = min(aBounds[2],aNode->Y());
365 aBounds[3] = max(aBounds[3],aNode->Y());
367 aBounds[4] = min(aBounds[4],aNode->Z());
368 aBounds[5] = max(aBounds[5],aNode->Z());
372 TopoDS_Shape mainShape = myMesh->ShapeToMesh();
373 bool hasShapeToMesh = ( myMesh->SubMeshIndices().size() > 1 );
374 if ( !mainShape.IsNull() && hasShapeToMesh )
376 // define EPS by max tolerance of the mainShape (IPAL53097)
377 TopExp_Explorer subShape;
378 for ( subShape.Init( mainShape, TopAbs_FACE ); subShape.More(); subShape.Next() ) {
379 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Face( subShape.Current() )));
381 for ( subShape.Init( mainShape, TopAbs_EDGE ); subShape.More(); subShape.Next() ) {
382 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Edge( subShape.Current() )));
384 for ( subShape.Init( mainShape, TopAbs_VERTEX ); subShape.More(); subShape.Next() ) {
385 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Vertex( subShape.Current() )));
389 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
390 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
391 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
392 aSpaceDimension = Max( aMeshDimension, anIsXDimension + anIsYDimension + anIsZDimension );
393 if ( !aSpaceDimension )
395 // PAL16857(SMESH not conform to the MED convention):
396 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
398 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
399 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
400 if ( anIsYDimension ) {
402 anIsXDimension = true;
409 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
410 switch ( aSpaceDimension ) {
412 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
415 if(anIsXDimension && anIsYDimension)
416 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
417 if(anIsYDimension && anIsZDimension)
418 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
419 if(anIsXDimension && anIsZDimension)
420 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
424 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
426 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
428 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
433 MED::PWrapper myMed = CrWrapper(myFile,myMedVersion);
434 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
435 //MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
436 myMed->SetMeshInfo(aMeshInfo);
438 // Storing SMDS groups and sub-meshes as med families
439 //----------------------------------------------------
440 int myNodesDefaultFamilyId = 0;
441 int my0DElementsDefaultFamilyId = 0;
442 int myBallsDefaultFamilyId = 0;
443 int myEdgesDefaultFamilyId = 0;
444 int myFacesDefaultFamilyId = 0;
445 int myVolumesDefaultFamilyId = 0;
446 int nbNodes = myMesh->NbNodes();
447 int nb0DElements = myMesh->Nb0DElements();
448 int nbBalls = myMesh->NbBalls();
449 int nbEdges = myMesh->NbEdges();
450 int nbFaces = myMesh->NbFaces();
451 int nbVolumes = myMesh->NbVolumes();
452 if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
453 if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
454 if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
455 if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
456 if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
457 if (myDoGroupOfBalls && nbBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
459 //MESSAGE("Perform - aFamilyInfo");
460 list<DriverMED_FamilyPtr> aFamilies;
461 if (myAllSubMeshes) {
462 aFamilies = DriverMED_Family::MakeFamilies
463 (myMesh->SubMeshes(), myGroups,
464 myDoGroupOfNodes && nbNodes,
465 myDoGroupOfEdges && nbEdges,
466 myDoGroupOfFaces && nbFaces,
467 myDoGroupOfVolumes && nbVolumes,
468 myDoGroupOf0DElems && nb0DElements,
469 myDoGroupOfBalls && nbBalls);
472 aFamilies = DriverMED_Family::MakeFamilies
473 (getIterator( mySubMeshes ), myGroups,
474 myDoGroupOfNodes && nbNodes,
475 myDoGroupOfEdges && nbEdges,
476 myDoGroupOfFaces && nbFaces,
477 myDoGroupOfVolumes && nbVolumes,
478 myDoGroupOf0DElems && nb0DElements,
479 myDoGroupOfBalls && nbBalls);
481 list<DriverMED_FamilyPtr>::iterator aFamsIter;
482 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
484 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
485 myMed->SetFamilyInfo(aFamilyInfo);
488 // Storing SMDS nodes to the MED file for the MED mesh
489 //----------------------------------------------------
490 #ifdef _EDF_NODE_IDS_
491 typedef map<TInt,TInt> TNodeIdMap;
492 TNodeIdMap aNodeIdMap;
494 const EModeSwitch theMode = eFULL_INTERLACE;
495 const ERepere theSystem = eCART;
496 const EBooleen theIsElemNum = eVRAI;
497 const EBooleen theIsElemNames = eFAUX;
498 const EConnectivite theConnMode = eNOD;
500 TInt aNbNodes = myMesh->NbNodes();
501 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
502 theMode, theSystem, theIsElemNum, theIsElemNames);
504 // find family numbers for nodes
505 TElemFamilyMap anElemFamMap;
506 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
508 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
511 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
512 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
513 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
516 int aNodeID = aCoordHelperPtr->GetID();
517 aNodeInfo->SetElemNum( iNode, aNodeID );
518 #ifdef _EDF_NODE_IDS_
519 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
522 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
523 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
524 aNodeInfo->SetFamNum( iNode, famNum );
526 anElemFamMap.Clear();
528 // coordinate names and units
529 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
530 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
531 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
534 //MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
535 myMed->SetNodeInfo(aNodeInfo);
536 aNodeInfo.reset(); // free memory used for arrays
539 // Storing SMDS elements to the MED file for the MED mesh
540 //-------------------------------------------------------
541 // Write one element type at once in order to minimize memory usage (PAL19276)
543 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
545 // poly elements are not supported by med-2.1
546 bool polyTypesSupported = ( myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0).get() != 0 );
547 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
549 // nodes on VERTEXes where 0D elements are absent
550 std::vector<const SMDS_MeshElement*> nodesOf0D;
551 std::vector< SMDS_ElemIteratorPtr > iterVec;
552 SMDS_ElemIteratorPtr iterVecIter;
553 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
556 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
557 iterVec[1] = SMDS_ElemIteratorPtr
558 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
560 typedef SMDS_IteratorOnIterators
561 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
562 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
565 // collect info on all geom types
567 list< TElemTypeData > aTElemTypeDatas;
569 EEntiteMaillage anEntity = eMAILLE;
570 #ifdef _ELEMENTS_BY_DIM_
571 anEntity = eNOEUD_ELEMENT;
573 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
575 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
577 #ifdef _ELEMENTS_BY_DIM_
578 anEntity = eSTRUCT_ELEMENT;
580 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
582 nbElemInfo.NbBalls(),
584 #ifdef _ELEMENTS_BY_DIM_
587 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
589 nbElemInfo.NbEdges( ORDER_LINEAR ),
591 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
593 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
595 #ifdef _ELEMENTS_BY_DIM_
598 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
600 nbElemInfo.NbTriangles( ORDER_LINEAR ),
602 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
604 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
605 nbElemInfo.NbBiQuadTriangles(),
607 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
609 nbElemInfo.NbBiQuadTriangles(),
611 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
613 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
615 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
617 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
618 nbElemInfo.NbBiQuadQuadrangles(),
620 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
622 nbElemInfo.NbBiQuadQuadrangles(),
624 if ( polyTypesSupported ) {
625 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
627 nbElemInfo.NbPolygons( ORDER_LINEAR ),
629 // we need one more loop on poly elements to count nb of their nodes
630 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
632 nbElemInfo.NbPolygons( ORDER_LINEAR ),
634 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
636 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
638 // we need one more loop on QUAD poly elements to count nb of their nodes
639 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
641 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
644 #ifdef _ELEMENTS_BY_DIM_
647 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
649 nbElemInfo.NbTetras( ORDER_LINEAR ),
651 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
653 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
655 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
657 nbElemInfo.NbPyramids( ORDER_LINEAR ),
659 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
661 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
663 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
665 nbElemInfo.NbPrisms( ORDER_LINEAR ),
667 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
669 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
671 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
673 nbElemInfo.NbHexas( ORDER_LINEAR ),
675 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
677 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
678 nbElemInfo.NbTriQuadHexas(),
680 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
682 nbElemInfo.NbTriQuadHexas(),
684 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
686 nbElemInfo.NbHexPrisms(),
688 if ( polyTypesSupported ) {
689 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
691 nbElemInfo.NbPolyhedrons(),
693 // we need one more loop on poly elements to count nb of their nodes
694 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
696 nbElemInfo.NbPolyhedrons(),
700 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
702 // loop on all geom types of elements
704 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
705 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
707 if ( aElemTypeData->_nbElems == 0 )
710 int defaultFamilyId = 0;
711 switch ( aElemTypeData->_smdsType ) {
712 case SMDSAbs_0DElement: defaultFamilyId = my0DElementsDefaultFamilyId; break;
713 case SMDSAbs_Ball: defaultFamilyId = myBallsDefaultFamilyId; break;
714 case SMDSAbs_Edge: defaultFamilyId = myEdgesDefaultFamilyId; break;
715 case SMDSAbs_Face: defaultFamilyId = myFacesDefaultFamilyId; break;
716 case SMDSAbs_Volume: defaultFamilyId = myVolumesDefaultFamilyId; break;
721 // iterator on elements of a current type
722 SMDS_ElemIteratorPtr elemIterator;
727 if ( aElemTypeData->_geomType == ePOLYGONE ||
728 aElemTypeData->_geomType == ePOLYGON2 )
730 if ( aElemTypeData->_geomType == ePOLYGONE )
731 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Polygon );
733 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Quad_Polygon );
735 if ( nbPolygonNodes == 0 ) {
737 while ( elemIterator->more() ) {
738 const SMDS_MeshElement* anElem = elemIterator->next();
739 nbPolygonNodes += anElem->NbNodes();
740 if ( ++iElem == aElemTypeData->_nbElems )
746 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
747 aElemTypeData->_entity,
748 aElemTypeData->_geomType,
749 aElemTypeData->_nbElems,
751 theConnMode, theIsElemNum,
753 TElemNum & index = *(aPolygoneInfo->myIndex.get());
756 while ( elemIterator->more() )
758 const SMDS_MeshElement* anElem = elemIterator->next();
760 TInt aNbNodes = anElem->NbNodes();
761 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
764 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
765 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
766 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
767 #ifdef _EDF_NODE_IDS_
768 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
770 aTConnSlice[ iNode ] = aNode->GetID();
774 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
777 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
778 aPolygoneInfo->SetFamNum( iElem, famNum );
780 if ( ++iElem == aPolygoneInfo->GetNbElem() )
783 myMed->SetPolygoneInfo(aPolygoneInfo);
785 nbPolygonNodes = 0; // to treat next polygon type
791 else if (aElemTypeData->_geomType == ePOLYEDRE )
793 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
795 if ( nbPolyhedronNodes == 0 ) {
797 while ( elemIterator->more() ) {
798 const SMDS_MeshElement* anElem = elemIterator->next();
799 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
800 if ( !aPolyedre ) continue;
801 nbPolyhedronNodes += aPolyedre->NbNodes();
802 nbPolyhedronFaces += aPolyedre->NbFaces();
803 if ( ++iElem == aElemTypeData->_nbElems )
809 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
810 aElemTypeData->_entity,
811 aElemTypeData->_geomType,
812 aElemTypeData->_nbElems,
818 TElemNum & index = *(aPolyhInfo->myIndex.get());
819 TElemNum & faces = *(aPolyhInfo->myFaces.get());
820 TElemNum & conn = *(aPolyhInfo->myConn.get());
824 TInt iFace = 0, iNode = 0;
825 while ( elemIterator->more() )
827 const SMDS_MeshElement* anElem = elemIterator->next();
828 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
829 if ( !aPolyedre ) continue;
831 TInt aNbFaces = aPolyedre->NbFaces();
832 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
835 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
836 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
837 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
840 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
841 while ( nodeIt->more() ) {
842 const SMDS_MeshElement* aNode = nodeIt->next();
843 #ifdef _EDF_NODE_IDS_
844 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
846 conn[ iNode ] = aNode->GetID();
851 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
854 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
855 aPolyhInfo->SetFamNum( iElem, famNum );
857 if ( ++iElem == aPolyhInfo->GetNbElem() )
860 myMed->SetPolyedreInfo(aPolyhInfo);
862 } // if (aElemTypeData->_geomType == ePOLYEDRE )
866 else if (aElemTypeData->_geomType == eBALL )
868 // allocate data arrays
869 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo, aElemTypeData->_nbElems );
871 // build map of family numbers for this type
872 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
874 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
875 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
878 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
879 while ( elemIterator->more() )
881 const SMDS_MeshElement* anElem = elemIterator->next();
883 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
884 #ifdef _EDF_NODE_IDS_
885 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
887 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
890 aBallInfo->SetElemNum( iElem, anElem->GetID() );
893 aBallInfo->myDiameters[ iElem ] =
894 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
897 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
898 aBallInfo->SetFamNum( iElem, famNum );
901 // store data in a file
902 myMed->SetBallInfo(aBallInfo);
907 // Treat standard types
908 // ---------------------
910 // allocate data arrays
911 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
912 aElemTypeData->_entity,
913 aElemTypeData->_geomType,
914 aElemTypeData->_nbElems,
918 // build map of family numbers for this type
919 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
921 //cout << " fillElemFamilyMap()" << endl;
922 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
923 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
926 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
927 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
928 if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() )
929 elemIterator = iterVecIter;
930 while ( elemIterator->more() )
932 const SMDS_MeshElement* anElem = elemIterator->next();
933 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
934 continue; // other geometry
937 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
938 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
939 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
940 #ifdef _EDF_NODE_IDS_
941 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
943 aTConnSlice[ iNode ] = aNode->GetID();
947 aCellInfo->SetElemNum( iElem, anElem->GetID() );
950 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
951 aCellInfo->SetFamNum( iElem, famNum );
953 if ( ++iElem == aCellInfo->GetNbElem() )
956 // store data in a file
957 myMed->SetCellInfo(aCellInfo);
960 } // loop on geom types
964 catch(const std::exception& exc) {
965 INFOS("The following exception was caught:\n\t"<<exc.what());
969 INFOS("Unknown exception was caught !!!");
979 //================================================================================
981 * \brief Returns nodes on VERTEXes where 0D elements are absent
983 //================================================================================
985 bool DriverMED_W_SMESHDS_Mesh::
986 getNodesOfMissing0DOnVert(SMESHDS_Mesh* meshDS,
987 std::vector<const SMDS_MeshElement*>& nodes)
990 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
992 if ( meshDS->IndexToShape( i ).ShapeType() != TopAbs_VERTEX )
994 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(i) ) {
995 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
998 const SMDS_MeshNode* n = nIt->next();
999 if ( n->NbInverseElements( SMDSAbs_0DElement ) == 0 )
1000 nodes.push_back( n );
1004 return !nodes.empty();