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)
66 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
68 Driver_SMESHDS_Mesh::SetFile(theFileName);
71 string DriverMED_W_SMESHDS_Mesh::GetVersionString(int theNbDigits)
73 TInt majeur, mineur, release;
74 majeur = mineur = release = 0;
75 MED::GetVersionRelease(majeur, mineur, release);
77 if ( theNbDigits > 0 )
79 if ( theNbDigits > 1 )
80 name << "." << mineur;
81 if ( theNbDigits > 2 )
82 name << "." << release;
86 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
88 myGroups.push_back(theGroup);
91 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
93 myAllSubMeshes = true;
96 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
98 mySubMeshes.push_back( theSubMesh );
101 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
103 myDoGroupOfNodes = true;
106 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
108 myDoGroupOfEdges = true;
111 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
113 myDoGroupOfFaces = true;
116 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
118 myDoGroupOfVolumes = true;
123 typedef double (SMDS_MeshNode::* TGetCoord)() const;
124 typedef const char* TName;
125 typedef const char* TUnit;
127 // name length in a mesh must be equal to 16 :
134 TUnit aUnit[3] = {M,M,M};
137 TGetCoord aXYZGetCoord[3] = {
142 TName aXYZName[3] = {X,Y,Z};
145 TGetCoord aXYGetCoord[2] = {
149 TName aXYName[2] = {X,Y};
151 TGetCoord aYZGetCoord[2] = {
155 TName aYZName[2] = {Y,Z};
157 TGetCoord aXZGetCoord[2] = {
161 TName aXZName[2] = {X,Z};
164 TGetCoord aXGetCoord[1] = {
167 TName aXName[1] = {X};
169 TGetCoord aYGetCoord[1] = {
172 TName aYName[1] = {Y};
174 TGetCoord aZGetCoord[1] = {
177 TName aZName[1] = {Z};
181 SMDS_NodeIteratorPtr myNodeIter;
182 const SMDS_MeshNode* myCurrentNode;
183 TGetCoord* myGetCoord;
187 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
188 TGetCoord* theGetCoord,
190 TUnit* theUnit = aUnit):
191 myNodeIter(theNodeIter),
192 myGetCoord(theGetCoord),
196 virtual ~TCoordHelper(){}
198 return myNodeIter->more() &&
199 (myCurrentNode = myNodeIter->next());
201 const SMDS_MeshNode* GetNode(){
202 return myCurrentNode;
204 MED::TIntVector::value_type GetID(){
205 return myCurrentNode->GetID();
207 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
208 return (myCurrentNode->*myGetCoord[theCoodId])();
210 MED::TStringVector::value_type GetName(TInt theDimId){
211 return myName[theDimId];
213 MED::TStringVector::value_type GetUnit(TInt theDimId){
214 return myUnit[theDimId];
217 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
219 //-------------------------------------------------------
221 * \brief Structure describing element type
223 //-------------------------------------------------------
226 EEntiteMaillage _entity;
227 EGeometrieElement _geomType;
229 SMDSAbs_ElementType _smdsType;
231 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
232 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
236 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
238 //================================================================================
240 * \brief Fills element to famaly ID map for element type.
241 * Removes all families of anElemType
243 //================================================================================
245 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
246 list<DriverMED_FamilyPtr> & aFamilies,
247 const SMDSAbs_ElementType anElemType)
249 anElemFamMap.Clear();
250 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
251 while ( aFamsIter != aFamilies.end() )
253 if ((*aFamsIter)->GetType() != anElemType) {
257 int aFamId = (*aFamsIter)->GetId();
258 const ElementsSet& anElems = (*aFamsIter)->GetElements();
259 ElementsSet::const_iterator anElemsIter = anElems.begin();
260 for (; anElemsIter != anElems.end(); anElemsIter++)
262 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
264 // remove a family from the list
265 aFamilies.erase( aFamsIter++ );
270 //================================================================================
272 * \brief For an element, return family ID found in the map or a default one
274 //================================================================================
276 int getFamilyId( const TElemFamilyMap & anElemFamMap,
277 const SMDS_MeshElement* anElement,
278 const int aDefaultFamilyId)
280 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
281 return anElemFamMap( (Standard_Address) anElement );
283 return aDefaultFamilyId;
286 //================================================================================
288 * \brief Returns iterator on sub-meshes
290 //================================================================================
292 SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& mySubMeshes )
294 return SMESHDS_SubMeshIteratorPtr
295 ( new SMDS_SetIterator
296 < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(),
297 mySubMeshes.end() ));
301 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
303 Status aResult = DRS_OK;
304 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
305 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
309 //MESSAGE("Perform - myFile : "<<myFile);
311 // Creating the MED mesh for corresponding SMDS structure
312 //-------------------------------------------------------
314 if (myMeshId != -1) {
315 ostringstream aMeshNameStr;
316 aMeshNameStr<<myMeshId;
317 aMeshName = aMeshNameStr.str();
319 aMeshName = myMeshName;
322 // Mesh dimension definition
324 TInt aMeshDimension = 0;
325 if ( myMesh->NbEdges() > 0 )
327 if ( myMesh->NbFaces() > 0 )
329 if ( myMesh->NbVolumes() > 0 )
332 TInt aSpaceDimension = 3;
333 TCoordHelperPtr aCoordHelperPtr;
335 bool anIsXDimension = false;
336 bool anIsYDimension = false;
337 bool anIsZDimension = false;
338 if ( myAutoDimension && aMeshDimension < 3 )
340 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
342 if(aNodesIter->more()){
343 const SMDS_MeshNode* aNode = aNodesIter->next();
344 aBounds[0] = aBounds[1] = aNode->X();
345 aBounds[2] = aBounds[3] = aNode->Y();
346 aBounds[4] = aBounds[5] = aNode->Z();
348 while(aNodesIter->more()){
349 const SMDS_MeshNode* aNode = aNodesIter->next();
350 aBounds[0] = min(aBounds[0],aNode->X());
351 aBounds[1] = max(aBounds[1],aNode->X());
353 aBounds[2] = min(aBounds[2],aNode->Y());
354 aBounds[3] = max(aBounds[3],aNode->Y());
356 aBounds[4] = min(aBounds[4],aNode->Z());
357 aBounds[5] = max(aBounds[5],aNode->Z());
361 TopoDS_Shape mainShape = myMesh->ShapeToMesh();
362 bool hasShapeToMesh = ( myMesh->SubMeshIndices().size() > 1 );
363 if ( !mainShape.IsNull() && hasShapeToMesh )
365 // define EPS by max tolerance of the mainShape (IPAL53097)
366 TopExp_Explorer subShape;
367 for ( subShape.Init( mainShape, TopAbs_FACE ); subShape.More(); subShape.Next() ) {
368 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Face( subShape.Current() )));
370 for ( subShape.Init( mainShape, TopAbs_EDGE ); subShape.More(); subShape.Next() ) {
371 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Edge( subShape.Current() )));
373 for ( subShape.Init( mainShape, TopAbs_VERTEX ); subShape.More(); subShape.Next() ) {
374 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Vertex( subShape.Current() )));
378 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
379 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
380 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
381 aSpaceDimension = Max( aMeshDimension, anIsXDimension + anIsYDimension + anIsZDimension );
382 if ( !aSpaceDimension )
384 // PAL16857(SMESH not conform to the MED convention):
385 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
387 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
388 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
389 if ( anIsYDimension ) {
391 anIsXDimension = true;
398 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
399 switch ( aSpaceDimension ) {
401 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
404 if(anIsXDimension && anIsYDimension)
405 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
406 if(anIsYDimension && anIsZDimension)
407 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
408 if(anIsXDimension && anIsZDimension)
409 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
413 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
415 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
417 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
422 MED::PWrapper myMed = CrWrapperW(myFile);
423 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
424 //MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
425 myMed->SetMeshInfo(aMeshInfo);
427 // Storing SMDS groups and sub-meshes as med families
428 //----------------------------------------------------
429 int myNodesDefaultFamilyId = 0;
430 int my0DElementsDefaultFamilyId = 0;
431 int myBallsDefaultFamilyId = 0;
432 int myEdgesDefaultFamilyId = 0;
433 int myFacesDefaultFamilyId = 0;
434 int myVolumesDefaultFamilyId = 0;
435 int nbNodes = myMesh->NbNodes();
436 int nb0DElements = myMesh->Nb0DElements();
437 int nbBalls = myMesh->NbBalls();
438 int nbEdges = myMesh->NbEdges();
439 int nbFaces = myMesh->NbFaces();
440 int nbVolumes = myMesh->NbVolumes();
441 if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
442 if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
443 if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
444 if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
445 if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
446 if (myDoGroupOfBalls && nbBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
448 //MESSAGE("Perform - aFamilyInfo");
449 list<DriverMED_FamilyPtr> aFamilies;
450 if (myAllSubMeshes) {
451 aFamilies = DriverMED_Family::MakeFamilies
452 (myMesh->SubMeshes(), myGroups,
453 myDoGroupOfNodes && nbNodes,
454 myDoGroupOfEdges && nbEdges,
455 myDoGroupOfFaces && nbFaces,
456 myDoGroupOfVolumes && nbVolumes,
457 myDoGroupOf0DElems && nb0DElements,
458 myDoGroupOfBalls && nbBalls);
461 aFamilies = DriverMED_Family::MakeFamilies
462 (getIterator( mySubMeshes ), myGroups,
463 myDoGroupOfNodes && nbNodes,
464 myDoGroupOfEdges && nbEdges,
465 myDoGroupOfFaces && nbFaces,
466 myDoGroupOfVolumes && nbVolumes,
467 myDoGroupOf0DElems && nb0DElements,
468 myDoGroupOfBalls && nbBalls);
470 list<DriverMED_FamilyPtr>::iterator aFamsIter;
471 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
473 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
474 myMed->SetFamilyInfo(aFamilyInfo);
477 // Storing SMDS nodes to the MED file for the MED mesh
478 //----------------------------------------------------
479 #ifdef _EDF_NODE_IDS_
480 typedef map<TInt,TInt> TNodeIdMap;
481 TNodeIdMap aNodeIdMap;
483 const EModeSwitch theMode = eFULL_INTERLACE;
484 const ERepere theSystem = eCART;
485 const EBooleen theIsElemNum = eVRAI;
486 const EBooleen theIsElemNames = eFAUX;
487 const EConnectivite theConnMode = eNOD;
489 TInt aNbNodes = myMesh->NbNodes();
490 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
491 theMode, theSystem, theIsElemNum, theIsElemNames);
493 // find family numbers for nodes
494 TElemFamilyMap anElemFamMap;
495 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
497 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
500 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
501 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
502 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
505 int aNodeID = aCoordHelperPtr->GetID();
506 aNodeInfo->SetElemNum( iNode, aNodeID );
507 #ifdef _EDF_NODE_IDS_
508 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
511 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
512 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
513 aNodeInfo->SetFamNum( iNode, famNum );
515 anElemFamMap.Clear();
517 // coordinate names and units
518 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
519 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
520 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
523 //MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
524 myMed->SetNodeInfo(aNodeInfo);
525 aNodeInfo.reset(); // free memory used for arrays
528 // Storing SMDS elements to the MED file for the MED mesh
529 //-------------------------------------------------------
530 // Write one element type at once in order to minimize memory usage (PAL19276)
532 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
534 // poly elements are not supported by med-2.1
535 bool polyTypesSupported = ( myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0).get() != 0 );
536 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
538 // nodes on VERTEXes where 0D elements are absent
539 std::vector<const SMDS_MeshElement*> nodesOf0D;
540 std::vector< SMDS_ElemIteratorPtr > iterVec;
541 SMDS_ElemIteratorPtr iterVecIter;
542 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
545 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
546 iterVec[1] = SMDS_ElemIteratorPtr
547 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
549 typedef SMDS_IteratorOnIterators
550 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
551 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
554 // collect info on all geom types
556 list< TElemTypeData > aTElemTypeDatas;
558 EEntiteMaillage anEntity = eMAILLE;
559 #ifdef _ELEMENTS_BY_DIM_
560 anEntity = eNOEUD_ELEMENT;
562 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
564 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
566 #ifdef _ELEMENTS_BY_DIM_
567 anEntity = eSTRUCT_ELEMENT;
569 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
571 nbElemInfo.NbBalls(),
573 #ifdef _ELEMENTS_BY_DIM_
576 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
578 nbElemInfo.NbEdges( ORDER_LINEAR ),
580 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
582 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
584 #ifdef _ELEMENTS_BY_DIM_
587 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
589 nbElemInfo.NbTriangles( ORDER_LINEAR ),
591 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
593 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
594 nbElemInfo.NbBiQuadTriangles(),
596 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
598 nbElemInfo.NbBiQuadTriangles(),
600 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
602 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
604 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
606 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
607 nbElemInfo.NbBiQuadQuadrangles(),
609 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
611 nbElemInfo.NbBiQuadQuadrangles(),
613 if ( polyTypesSupported ) {
614 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
616 nbElemInfo.NbPolygons( ORDER_LINEAR ),
618 // we need one more loop on poly elements to count nb of their nodes
619 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
621 nbElemInfo.NbPolygons( ORDER_LINEAR ),
623 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
625 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
627 // we need one more loop on QUAD poly elements to count nb of their nodes
628 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
630 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
633 #ifdef _ELEMENTS_BY_DIM_
636 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
638 nbElemInfo.NbTetras( ORDER_LINEAR ),
640 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
642 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
644 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
646 nbElemInfo.NbPyramids( ORDER_LINEAR ),
648 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
650 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
652 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
654 nbElemInfo.NbPrisms( ORDER_LINEAR ),
656 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
658 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
660 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
662 nbElemInfo.NbHexas( ORDER_LINEAR ),
664 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
666 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
667 nbElemInfo.NbTriQuadHexas(),
669 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
671 nbElemInfo.NbTriQuadHexas(),
673 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
675 nbElemInfo.NbHexPrisms(),
677 if ( polyTypesSupported ) {
678 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
680 nbElemInfo.NbPolyhedrons(),
682 // we need one more loop on poly elements to count nb of their nodes
683 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
685 nbElemInfo.NbPolyhedrons(),
689 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
691 // loop on all geom types of elements
693 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
694 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
696 if ( aElemTypeData->_nbElems == 0 )
699 int defaultFamilyId = 0;
700 switch ( aElemTypeData->_smdsType ) {
701 case SMDSAbs_0DElement: defaultFamilyId = my0DElementsDefaultFamilyId; break;
702 case SMDSAbs_Ball: defaultFamilyId = myBallsDefaultFamilyId; break;
703 case SMDSAbs_Edge: defaultFamilyId = myEdgesDefaultFamilyId; break;
704 case SMDSAbs_Face: defaultFamilyId = myFacesDefaultFamilyId; break;
705 case SMDSAbs_Volume: defaultFamilyId = myVolumesDefaultFamilyId; break;
710 // iterator on elements of a current type
711 SMDS_ElemIteratorPtr elemIterator;
716 if ( aElemTypeData->_geomType == ePOLYGONE ||
717 aElemTypeData->_geomType == ePOLYGON2 )
719 if ( aElemTypeData->_geomType == ePOLYGONE )
720 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Polygon );
722 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Quad_Polygon );
724 if ( nbPolygonNodes == 0 ) {
726 while ( elemIterator->more() ) {
727 const SMDS_MeshElement* anElem = elemIterator->next();
728 nbPolygonNodes += anElem->NbNodes();
729 if ( ++iElem == aElemTypeData->_nbElems )
735 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
736 aElemTypeData->_entity,
737 aElemTypeData->_geomType,
738 aElemTypeData->_nbElems,
740 theConnMode, theIsElemNum,
742 TElemNum & index = *(aPolygoneInfo->myIndex.get());
745 while ( elemIterator->more() )
747 const SMDS_MeshElement* anElem = elemIterator->next();
749 TInt aNbNodes = anElem->NbNodes();
750 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
753 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
754 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
755 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
756 #ifdef _EDF_NODE_IDS_
757 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
759 aTConnSlice[ iNode ] = aNode->GetID();
763 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
766 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
767 aPolygoneInfo->SetFamNum( iElem, famNum );
769 if ( ++iElem == aPolygoneInfo->GetNbElem() )
772 myMed->SetPolygoneInfo(aPolygoneInfo);
774 nbPolygonNodes = 0; // to treat next polygon type
780 else if (aElemTypeData->_geomType == ePOLYEDRE )
782 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
784 if ( nbPolyhedronNodes == 0 ) {
786 while ( elemIterator->more() ) {
787 const SMDS_MeshElement* anElem = elemIterator->next();
788 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
789 if ( !aPolyedre ) continue;
790 nbPolyhedronNodes += aPolyedre->NbNodes();
791 nbPolyhedronFaces += aPolyedre->NbFaces();
792 if ( ++iElem == aElemTypeData->_nbElems )
798 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
799 aElemTypeData->_entity,
800 aElemTypeData->_geomType,
801 aElemTypeData->_nbElems,
807 TElemNum & index = *(aPolyhInfo->myIndex.get());
808 TElemNum & faces = *(aPolyhInfo->myFaces.get());
809 TElemNum & conn = *(aPolyhInfo->myConn.get());
813 TInt iFace = 0, iNode = 0;
814 while ( elemIterator->more() )
816 const SMDS_MeshElement* anElem = elemIterator->next();
817 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
818 if ( !aPolyedre ) continue;
820 TInt aNbFaces = aPolyedre->NbFaces();
821 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
824 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
825 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
826 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
829 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
830 while ( nodeIt->more() ) {
831 const SMDS_MeshElement* aNode = nodeIt->next();
832 #ifdef _EDF_NODE_IDS_
833 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
835 conn[ iNode ] = aNode->GetID();
840 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
843 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
844 aPolyhInfo->SetFamNum( iElem, famNum );
846 if ( ++iElem == aPolyhInfo->GetNbElem() )
849 myMed->SetPolyedreInfo(aPolyhInfo);
851 } // if (aElemTypeData->_geomType == ePOLYEDRE )
855 else if (aElemTypeData->_geomType == eBALL )
857 // allocate data arrays
858 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo, aElemTypeData->_nbElems );
860 // build map of family numbers for this type
861 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
863 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
864 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
867 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
868 while ( elemIterator->more() )
870 const SMDS_MeshElement* anElem = elemIterator->next();
872 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
873 #ifdef _EDF_NODE_IDS_
874 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
876 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
879 aBallInfo->SetElemNum( iElem, anElem->GetID() );
882 aBallInfo->myDiameters[ iElem ] =
883 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
886 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
887 aBallInfo->SetFamNum( iElem, famNum );
890 // store data in a file
891 myMed->SetBallInfo(aBallInfo);
896 // Treat standard types
897 // ---------------------
899 // allocate data arrays
900 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
901 aElemTypeData->_entity,
902 aElemTypeData->_geomType,
903 aElemTypeData->_nbElems,
907 // build map of family numbers for this type
908 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
910 //cout << " fillElemFamilyMap()" << endl;
911 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
912 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
915 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
916 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
917 if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() )
918 elemIterator = iterVecIter;
919 while ( elemIterator->more() )
921 const SMDS_MeshElement* anElem = elemIterator->next();
922 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
923 continue; // other geometry
926 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
927 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
928 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
929 #ifdef _EDF_NODE_IDS_
930 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
932 aTConnSlice[ iNode ] = aNode->GetID();
936 aCellInfo->SetElemNum( iElem, anElem->GetID() );
939 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
940 aCellInfo->SetFamNum( iElem, famNum );
942 if ( ++iElem == aCellInfo->GetNbElem() )
945 // store data in a file
946 myMed->SetCellInfo(aCellInfo);
949 } // loop on geom types
953 catch(const std::exception& exc) {
954 INFOS("The following exception was caught:\n\t"<<exc.what());
958 INFOS("Unknown exception was caught !!!");
968 //================================================================================
970 * \brief Returns nodes on VERTEXes where 0D elements are absent
972 //================================================================================
974 bool DriverMED_W_SMESHDS_Mesh::
975 getNodesOfMissing0DOnVert(SMESHDS_Mesh* meshDS,
976 std::vector<const SMDS_MeshElement*>& nodes)
979 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
981 if ( meshDS->IndexToShape( i ).ShapeType() != TopAbs_VERTEX )
983 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(i) ) {
984 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
987 const SMDS_MeshNode* n = nIt->next();
988 if ( n->NbInverseElements( SMDSAbs_0DElement ) == 0 )
989 nodes.push_back( n );
993 return !nodes.empty();