1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH DriverMED : driver to read and write 'med' files
24 // File : DriverMED_W_SMESHDS_Mesh.cxx
28 #include "DriverMED_W_SMESHDS_Mesh.h"
30 #include "DriverMED_Family.h"
31 #include "MED_Factory.hxx"
32 #include "MED_Utilities.hxx"
33 #include "SMDS_IteratorOnIterators.hxx"
34 #include "SMDS_MeshElement.hxx"
35 #include "SMDS_MeshNode.hxx"
36 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
37 #include "SMDS_SetIterator.hxx"
38 #include "SMESHDS_Mesh.hxx"
40 #include <BRep_Tool.hxx>
41 #include <TopExp_Explorer.hxx>
44 #include <utilities.h>
47 #define _EDF_NODE_IDS_
48 //#define _ELEMENTS_BY_DIM_
54 DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
55 myAllSubMeshes (false),
56 myDoGroupOfNodes (false),
57 myDoGroupOfEdges (false),
58 myDoGroupOfFaces (false),
59 myDoGroupOfVolumes (false),
60 myDoGroupOf0DElems(false),
61 myDoGroupOfBalls(false),
62 myAutoDimension(false),
63 myAddODOnVertices(false),
64 myDoAllInGroups(false)
67 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
69 Driver_SMESHDS_Mesh::SetFile(theFileName);
72 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
74 myGroups.push_back(theGroup);
77 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
79 myAllSubMeshes = true;
82 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
84 mySubMeshes.push_back( theSubMesh );
87 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
89 myDoGroupOfNodes = true;
92 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
94 myDoGroupOfEdges = true;
97 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
99 myDoGroupOfFaces = true;
102 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
104 myDoGroupOfVolumes = true;
107 void DriverMED_W_SMESHDS_Mesh::AddGroupOf0DElems()
109 myDoGroupOf0DElems = true;
112 void DriverMED_W_SMESHDS_Mesh::AddGroupOfBalls()
114 myDoGroupOfBalls = true;
117 //================================================================================
119 * \brief Set up a flag to add all elements not belonging to any group to
120 * some auxiliary group. This is needed for SMESH -> SAUVE -> SMESH conversion,
121 * which since PAL0023285 reads only SAUVE elements belonging to any group,
122 * and hence can lose some elements. That auxiliary group is ignored while
123 * reading a MED file.
125 //================================================================================
127 void DriverMED_W_SMESHDS_Mesh::AddAllToGroup()
129 myDoAllInGroups = true;
135 typedef double (SMDS_MeshNode::* TGetCoord)() const;
136 typedef const char* TName;
137 typedef const char* TUnit;
139 // name length in a mesh must be equal to 16 :
146 TUnit aUnit[3] = {M,M,M};
149 TGetCoord aXYZGetCoord[3] = {
154 TName aXYZName[3] = {X,Y,Z};
157 TGetCoord aXYGetCoord[2] = {
161 TName aXYName[2] = {X,Y};
163 TGetCoord aYZGetCoord[2] = {
167 TName aYZName[2] = {Y,Z};
169 TGetCoord aXZGetCoord[2] = {
173 TName aXZName[2] = {X,Z};
176 TGetCoord aXGetCoord[1] = {
179 TName aXName[1] = {X};
181 TGetCoord aYGetCoord[1] = {
184 TName aYName[1] = {Y};
186 TGetCoord aZGetCoord[1] = {
189 TName aZName[1] = {Z};
193 SMDS_NodeIteratorPtr myNodeIter;
194 const SMDS_MeshNode* myCurrentNode;
195 TGetCoord* myGetCoord;
199 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
200 TGetCoord* theGetCoord,
202 TUnit* theUnit = aUnit):
203 myNodeIter(theNodeIter),
204 myGetCoord(theGetCoord),
208 virtual ~TCoordHelper(){}
210 return myNodeIter->more() &&
211 (myCurrentNode = myNodeIter->next());
213 const SMDS_MeshNode* GetNode(){
214 return myCurrentNode;
216 MED::TIntVector::value_type GetID(){
217 return myCurrentNode->GetID();
219 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
220 return (myCurrentNode->*myGetCoord[theCoodId])();
222 MED::TStringVector::value_type GetName(TInt theDimId){
223 return myName[theDimId];
225 MED::TStringVector::value_type GetUnit(TInt theDimId){
226 return myUnit[theDimId];
229 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
231 //-------------------------------------------------------
233 * \brief Structure describing element type
235 //-------------------------------------------------------
238 EEntiteMaillage _entity;
239 EGeometrieElement _geomType;
241 SMDSAbs_ElementType _smdsType;
243 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
244 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
248 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
250 //================================================================================
252 * \brief Fills element to famaly ID map for element type.
253 * Removes all families of anElemType
255 //================================================================================
257 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
258 list<DriverMED_FamilyPtr> & aFamilies,
259 const SMDSAbs_ElementType anElemType)
261 anElemFamMap.Clear();
262 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
263 while ( aFamsIter != aFamilies.end() )
265 if ((*aFamsIter)->GetType() != anElemType) {
269 int aFamId = (*aFamsIter)->GetId();
270 const ElementsSet& anElems = (*aFamsIter)->GetElements();
271 ElementsSet::const_iterator anElemsIter = anElems.begin();
272 for (; anElemsIter != anElems.end(); anElemsIter++)
274 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
276 // remove a family from the list
277 aFamilies.erase( aFamsIter++ );
282 //================================================================================
284 * \brief For an element, return family ID found in the map or a default one
286 //================================================================================
288 int getFamilyId( const TElemFamilyMap & anElemFamMap,
289 const SMDS_MeshElement* anElement,
290 const int aDefaultFamilyId)
292 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
293 return anElemFamMap( (Standard_Address) anElement );
295 return aDefaultFamilyId;
298 //================================================================================
300 * \brief Returns iterator on sub-meshes
302 //================================================================================
304 SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& mySubMeshes )
306 return SMESHDS_SubMeshIteratorPtr
307 ( new SMDS_SetIterator
308 < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(),
309 mySubMeshes.end() ));
313 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
315 Status aResult = DRS_OK;
316 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
317 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
321 //MESSAGE("Perform - myFile : "<<myFile);
323 // Creating the MED mesh for corresponding SMDS structure
324 //-------------------------------------------------------
326 if (myMeshId != -1) {
327 ostringstream aMeshNameStr;
328 aMeshNameStr<<myMeshId;
329 aMeshName = aMeshNameStr.str();
331 aMeshName = myMeshName;
334 // Mesh dimension definition
336 TInt aMeshDimension = 0;
337 if ( myMesh->NbEdges() > 0 )
339 if ( myMesh->NbFaces() > 0 )
341 if ( myMesh->NbVolumes() > 0 )
344 TInt aSpaceDimension = 3;
345 TCoordHelperPtr aCoordHelperPtr;
347 bool anIsXDimension = false;
348 bool anIsYDimension = false;
349 bool anIsZDimension = false;
350 if ( myAutoDimension && aMeshDimension < 3 )
352 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
354 if(aNodesIter->more()){
355 const SMDS_MeshNode* aNode = aNodesIter->next();
356 aBounds[0] = aBounds[1] = aNode->X();
357 aBounds[2] = aBounds[3] = aNode->Y();
358 aBounds[4] = aBounds[5] = aNode->Z();
360 while(aNodesIter->more()){
361 const SMDS_MeshNode* aNode = aNodesIter->next();
362 aBounds[0] = min(aBounds[0],aNode->X());
363 aBounds[1] = max(aBounds[1],aNode->X());
365 aBounds[2] = min(aBounds[2],aNode->Y());
366 aBounds[3] = max(aBounds[3],aNode->Y());
368 aBounds[4] = min(aBounds[4],aNode->Z());
369 aBounds[5] = max(aBounds[5],aNode->Z());
373 TopoDS_Shape mainShape = myMesh->ShapeToMesh();
374 bool hasShapeToMesh = ( myMesh->SubMeshIndices().size() > 1 );
375 if ( !mainShape.IsNull() && hasShapeToMesh )
377 // define EPS by max tolerance of the mainShape (IPAL53097)
378 TopExp_Explorer subShape;
379 for ( subShape.Init( mainShape, TopAbs_FACE ); subShape.More(); subShape.Next() ) {
380 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Face( subShape.Current() )));
382 for ( subShape.Init( mainShape, TopAbs_EDGE ); subShape.More(); subShape.Next() ) {
383 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Edge( subShape.Current() )));
385 for ( subShape.Init( mainShape, TopAbs_VERTEX ); subShape.More(); subShape.Next() ) {
386 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Vertex( subShape.Current() )));
390 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
391 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
392 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
393 aSpaceDimension = Max( aMeshDimension, anIsXDimension + anIsYDimension + anIsZDimension );
394 if ( !aSpaceDimension )
396 // PAL16857(SMESH not conform to the MED convention):
397 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
399 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
400 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
401 if ( anIsYDimension ) {
403 anIsXDimension = true;
410 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
411 switch ( aSpaceDimension ) {
413 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
416 if(anIsXDimension && anIsYDimension)
417 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
418 if(anIsYDimension && anIsZDimension)
419 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
420 if(anIsXDimension && anIsZDimension)
421 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
425 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
427 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
429 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
434 MED::PWrapper myMed = CrWrapperW(myFile);
435 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
436 //MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
437 myMed->SetMeshInfo(aMeshInfo);
439 // Storing SMDS groups and sub-meshes as med families
440 //----------------------------------------------------
441 int myNodesDefaultFamilyId = 0;
442 int my0DElementsDefaultFamilyId = 0;
443 int myBallsDefaultFamilyId = 0;
444 int myEdgesDefaultFamilyId = 0;
445 int myFacesDefaultFamilyId = 0;
446 int myVolumesDefaultFamilyId = 0;
447 int nbNodes = myMesh->NbNodes();
448 int nb0DElements = myMesh->Nb0DElements();
449 int nbBalls = myMesh->NbBalls();
450 int nbEdges = myMesh->NbEdges();
451 int nbFaces = myMesh->NbFaces();
452 int nbVolumes = myMesh->NbVolumes();
453 if (myDoGroupOfNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
454 if (myDoGroupOfEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
455 if (myDoGroupOfFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
456 if (myDoGroupOfVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
457 if (myDoGroupOf0DElems) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
458 if (myDoGroupOfBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
459 if (myDoAllInGroups )
461 if (!myDoGroupOfEdges) myEdgesDefaultFamilyId = NIG_EDGES_FAMILY ;
462 if (!myDoGroupOfFaces) myFacesDefaultFamilyId = NIG_FACES_FAMILY ;
463 if (!myDoGroupOfVolumes) myVolumesDefaultFamilyId = NIG_VOLS_FAMILY ;
464 if (!myDoGroupOf0DElems) my0DElementsDefaultFamilyId = NIG_0DELEM_FAMILY ;
465 if (!myDoGroupOfBalls) myBallsDefaultFamilyId = NIG_BALL_FAMILY ;
468 //MESSAGE("Perform - aFamilyInfo");
469 list<DriverMED_FamilyPtr> aFamilies;
470 if (myAllSubMeshes) {
471 aFamilies = DriverMED_Family::MakeFamilies
472 (myMesh->SubMeshes(), myGroups,
473 myDoGroupOfNodes && nbNodes,
474 myDoGroupOfEdges && nbEdges,
475 myDoGroupOfFaces && nbFaces,
476 myDoGroupOfVolumes && nbVolumes,
477 myDoGroupOf0DElems && nb0DElements,
478 myDoGroupOfBalls && nbBalls,
482 aFamilies = DriverMED_Family::MakeFamilies
483 (getIterator( mySubMeshes ), myGroups,
484 myDoGroupOfNodes && nbNodes,
485 myDoGroupOfEdges && nbEdges,
486 myDoGroupOfFaces && nbFaces,
487 myDoGroupOfVolumes && nbVolumes,
488 myDoGroupOf0DElems && nb0DElements,
489 myDoGroupOfBalls && nbBalls,
492 list<DriverMED_FamilyPtr>::iterator aFamsIter;
493 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
495 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
496 myMed->SetFamilyInfo(aFamilyInfo);
499 // Storing SMDS nodes to the MED file for the MED mesh
500 //----------------------------------------------------
501 #ifdef _EDF_NODE_IDS_
502 typedef map<TInt,TInt> TNodeIdMap;
503 TNodeIdMap aNodeIdMap;
505 const EModeSwitch theMode = eFULL_INTERLACE;
506 const ERepere theSystem = eCART;
507 const EBooleen theIsElemNum = eVRAI;
508 const EBooleen theIsElemNames = eFAUX;
509 const EConnectivite theConnMode = eNOD;
511 TInt aNbNodes = myMesh->NbNodes();
512 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
513 theMode, theSystem, theIsElemNum, theIsElemNames);
515 // find family numbers for nodes
516 TElemFamilyMap anElemFamMap;
517 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
519 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
522 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
523 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
524 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
527 int aNodeID = aCoordHelperPtr->GetID();
528 aNodeInfo->SetElemNum( iNode, aNodeID );
529 #ifdef _EDF_NODE_IDS_
530 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
533 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
534 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
535 aNodeInfo->SetFamNum( iNode, famNum );
537 anElemFamMap.Clear();
539 // coordinate names and units
540 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
541 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
542 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
545 //MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
546 myMed->SetNodeInfo(aNodeInfo);
547 aNodeInfo.reset(); // free memory used for arrays
550 // Storing SMDS elements to the MED file for the MED mesh
551 //-------------------------------------------------------
552 // Write one element type at once in order to minimize memory usage (PAL19276)
554 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
556 // poly elements are not supported by med-2.1
557 bool polyTypesSupported = ( myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0).get() != 0 );
558 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
560 // nodes on VERTEXes where 0D elements are absent
561 std::vector<const SMDS_MeshElement*> nodesOf0D;
562 std::vector< SMDS_ElemIteratorPtr > iterVec;
563 SMDS_ElemIteratorPtr iterVecIter;
564 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
567 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
568 iterVec[1] = SMDS_ElemIteratorPtr
569 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
571 typedef SMDS_IteratorOnIterators
572 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
573 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
576 // collect info on all geom types
578 list< TElemTypeData > aTElemTypeDatas;
580 EEntiteMaillage anEntity = eMAILLE;
581 #ifdef _ELEMENTS_BY_DIM_
582 anEntity = eNOEUD_ELEMENT;
584 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
586 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
588 #ifdef _ELEMENTS_BY_DIM_
589 anEntity = eSTRUCT_ELEMENT;
591 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
593 nbElemInfo.NbBalls(),
595 #ifdef _ELEMENTS_BY_DIM_
598 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
600 nbElemInfo.NbEdges( ORDER_LINEAR ),
602 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
604 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
606 #ifdef _ELEMENTS_BY_DIM_
609 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
611 nbElemInfo.NbTriangles( ORDER_LINEAR ),
613 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
615 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
616 nbElemInfo.NbBiQuadTriangles(),
618 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
620 nbElemInfo.NbBiQuadTriangles(),
622 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
624 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
626 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
628 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
629 nbElemInfo.NbBiQuadQuadrangles(),
631 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
633 nbElemInfo.NbBiQuadQuadrangles(),
635 if ( polyTypesSupported ) {
636 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
638 nbElemInfo.NbPolygons( ORDER_LINEAR ),
640 // we need one more loop on poly elements to count nb of their nodes
641 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
643 nbElemInfo.NbPolygons( ORDER_LINEAR ),
645 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
647 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
649 // we need one more loop on QUAD poly elements to count nb of their nodes
650 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
652 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
655 #ifdef _ELEMENTS_BY_DIM_
658 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
660 nbElemInfo.NbTetras( ORDER_LINEAR ),
662 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
664 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
666 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
668 nbElemInfo.NbPyramids( ORDER_LINEAR ),
670 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
672 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
674 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
676 nbElemInfo.NbPrisms( ORDER_LINEAR ),
678 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
680 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
682 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
684 nbElemInfo.NbHexas( ORDER_LINEAR ),
686 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
688 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
689 nbElemInfo.NbTriQuadHexas(),
691 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
693 nbElemInfo.NbTriQuadHexas(),
695 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
697 nbElemInfo.NbHexPrisms(),
699 if ( polyTypesSupported ) {
700 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
702 nbElemInfo.NbPolyhedrons(),
704 // we need one more loop on poly elements to count nb of their nodes
705 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
707 nbElemInfo.NbPolyhedrons(),
711 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
713 // loop on all geom types of elements
715 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
716 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
718 if ( aElemTypeData->_nbElems == 0 )
721 int defaultFamilyId = 0;
722 switch ( aElemTypeData->_smdsType ) {
723 case SMDSAbs_0DElement: defaultFamilyId = my0DElementsDefaultFamilyId; break;
724 case SMDSAbs_Ball: defaultFamilyId = myBallsDefaultFamilyId; break;
725 case SMDSAbs_Edge: defaultFamilyId = myEdgesDefaultFamilyId; break;
726 case SMDSAbs_Face: defaultFamilyId = myFacesDefaultFamilyId; break;
727 case SMDSAbs_Volume: defaultFamilyId = myVolumesDefaultFamilyId; break;
732 // iterator on elements of a current type
733 SMDS_ElemIteratorPtr elemIterator;
738 if ( aElemTypeData->_geomType == ePOLYGONE ||
739 aElemTypeData->_geomType == ePOLYGON2 )
741 if ( aElemTypeData->_geomType == ePOLYGONE )
742 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Polygon );
744 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Quad_Polygon );
746 if ( nbPolygonNodes == 0 ) {
748 while ( elemIterator->more() ) {
749 const SMDS_MeshElement* anElem = elemIterator->next();
750 nbPolygonNodes += anElem->NbNodes();
751 if ( ++iElem == aElemTypeData->_nbElems )
757 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
758 aElemTypeData->_entity,
759 aElemTypeData->_geomType,
760 aElemTypeData->_nbElems,
762 theConnMode, theIsElemNum,
764 TElemNum & index = *(aPolygoneInfo->myIndex.get());
767 while ( elemIterator->more() )
769 const SMDS_MeshElement* anElem = elemIterator->next();
771 TInt aNbNodes = anElem->NbNodes();
772 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
775 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
776 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
777 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
778 #ifdef _EDF_NODE_IDS_
779 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
781 aTConnSlice[ iNode ] = aNode->GetID();
785 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
788 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
789 aPolygoneInfo->SetFamNum( iElem, famNum );
791 if ( ++iElem == aPolygoneInfo->GetNbElem() )
794 myMed->SetPolygoneInfo(aPolygoneInfo);
796 nbPolygonNodes = 0; // to treat next polygon type
802 else if (aElemTypeData->_geomType == ePOLYEDRE )
804 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
806 if ( nbPolyhedronNodes == 0 ) {
808 while ( elemIterator->more() ) {
809 const SMDS_MeshElement* anElem = elemIterator->next();
810 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
811 if ( !aPolyedre ) continue;
812 nbPolyhedronNodes += aPolyedre->NbNodes();
813 nbPolyhedronFaces += aPolyedre->NbFaces();
814 if ( ++iElem == aElemTypeData->_nbElems )
820 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
821 aElemTypeData->_entity,
822 aElemTypeData->_geomType,
823 aElemTypeData->_nbElems,
829 TElemNum & index = *(aPolyhInfo->myIndex.get());
830 TElemNum & faces = *(aPolyhInfo->myFaces.get());
831 TElemNum & conn = *(aPolyhInfo->myConn.get());
835 TInt iFace = 0, iNode = 0;
836 while ( elemIterator->more() )
838 const SMDS_MeshElement* anElem = elemIterator->next();
839 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
840 if ( !aPolyedre ) continue;
842 TInt aNbFaces = aPolyedre->NbFaces();
843 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
846 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
847 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
848 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
851 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
852 while ( nodeIt->more() ) {
853 const SMDS_MeshElement* aNode = nodeIt->next();
854 #ifdef _EDF_NODE_IDS_
855 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
857 conn[ iNode ] = aNode->GetID();
862 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
865 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
866 aPolyhInfo->SetFamNum( iElem, famNum );
868 if ( ++iElem == aPolyhInfo->GetNbElem() )
871 myMed->SetPolyedreInfo(aPolyhInfo);
873 } // if (aElemTypeData->_geomType == ePOLYEDRE )
877 else if (aElemTypeData->_geomType == eBALL )
879 // allocate data arrays
880 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo, aElemTypeData->_nbElems );
882 // build map of family numbers for this type
883 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
885 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
886 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
889 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
890 while ( elemIterator->more() )
892 const SMDS_MeshElement* anElem = elemIterator->next();
894 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
895 #ifdef _EDF_NODE_IDS_
896 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
898 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
901 aBallInfo->SetElemNum( iElem, anElem->GetID() );
904 aBallInfo->myDiameters[ iElem ] =
905 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
908 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
909 aBallInfo->SetFamNum( iElem, famNum );
912 // store data in a file
913 myMed->SetBallInfo(aBallInfo);
918 // Treat standard types
919 // ---------------------
921 // allocate data arrays
922 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
923 aElemTypeData->_entity,
924 aElemTypeData->_geomType,
925 aElemTypeData->_nbElems,
929 // build map of family numbers for this type
930 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
932 //cout << " fillElemFamilyMap()" << endl;
933 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
934 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
937 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
938 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
939 if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() )
940 elemIterator = iterVecIter;
941 while ( elemIterator->more() )
943 const SMDS_MeshElement* anElem = elemIterator->next();
944 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
945 continue; // other geometry
948 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
949 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
950 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
951 #ifdef _EDF_NODE_IDS_
952 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
954 aTConnSlice[ iNode ] = aNode->GetID();
958 aCellInfo->SetElemNum( iElem, anElem->GetID() );
961 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
962 aCellInfo->SetFamNum( iElem, famNum );
964 if ( ++iElem == aCellInfo->GetNbElem() )
967 // store data in a file
968 myMed->SetCellInfo(aCellInfo);
971 } // loop on geom types
975 catch(const std::exception& exc) {
976 INFOS("The following exception was caught:\n\t"<<exc.what());
980 INFOS("Unknown exception was caught !!!");
990 //================================================================================
992 * \brief Returns nodes on VERTEXes where 0D elements are absent
994 //================================================================================
996 bool DriverMED_W_SMESHDS_Mesh::
997 getNodesOfMissing0DOnVert(SMESHDS_Mesh* meshDS,
998 std::vector<const SMDS_MeshElement*>& nodes)
1001 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
1003 if ( meshDS->IndexToShape( i ).ShapeType() != TopAbs_VERTEX )
1005 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(i) ) {
1006 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
1009 const SMDS_MeshNode* n = nIt->next();
1010 if ( n->NbInverseElements( SMDSAbs_0DElement ) == 0 )
1011 nodes.push_back( n );
1015 return !nodes.empty();