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);
75 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
77 Driver_SMESHDS_Mesh::SetFile(theFileName);
80 string DriverMED_W_SMESHDS_Mesh::GetVersionString(const MED::EVersion theVersion, int theNbDigits)
82 TInt majeur, mineur, release;
83 majeur = mineur = release = 0;
84 // if ( theVersion == eV2_1 )
85 // MED::GetVersionRelease<eV2_1>(majeur, mineur, release);
87 MED::GetVersionRelease<eV2_2>(majeur, mineur, release);
89 if ( theNbDigits > 0 )
91 if ( theNbDigits > 1 )
92 name << "." << mineur;
93 if ( theNbDigits > 2 )
94 name << "." << release;
98 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
100 myGroups.push_back(theGroup);
103 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
105 myAllSubMeshes = true;
108 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
110 mySubMeshes.push_back( theSubMesh );
113 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
115 myDoGroupOfNodes = true;
118 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
120 myDoGroupOfEdges = true;
123 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
125 myDoGroupOfFaces = true;
128 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
130 myDoGroupOfVolumes = true;
133 void DriverMED_W_SMESHDS_Mesh::AddGroupOf0DElems()
135 myDoGroupOf0DElems = true;
138 void DriverMED_W_SMESHDS_Mesh::AddGroupOfBalls()
140 myDoGroupOfBalls = true;
143 //================================================================================
145 * \brief Set up a flag to add all elements not belonging to any group to
146 * some auxiliary group. This is needed for SMESH -> SAUVE -> SMESH conversion,
147 * which since PAL0023285 reads only SAUVE elements belonging to any group,
148 * and hence can lose some elements. That auxiliary group is ignored while
149 * reading a MED file.
151 //================================================================================
153 void DriverMED_W_SMESHDS_Mesh::AddAllToGroup()
155 myDoAllInGroups = true;
161 typedef double (SMDS_MeshNode::* TGetCoord)() const;
162 typedef const char* TName;
163 typedef const char* TUnit;
165 // name length in a mesh must be equal to 16 :
172 TUnit aUnit[3] = {M,M,M};
175 TGetCoord aXYZGetCoord[3] = {
180 TName aXYZName[3] = {X,Y,Z};
183 TGetCoord aXYGetCoord[2] = {
187 TName aXYName[2] = {X,Y};
189 TGetCoord aYZGetCoord[2] = {
193 TName aYZName[2] = {Y,Z};
195 TGetCoord aXZGetCoord[2] = {
199 TName aXZName[2] = {X,Z};
202 TGetCoord aXGetCoord[1] = {
205 TName aXName[1] = {X};
207 TGetCoord aYGetCoord[1] = {
210 TName aYName[1] = {Y};
212 TGetCoord aZGetCoord[1] = {
215 TName aZName[1] = {Z};
219 SMDS_NodeIteratorPtr myNodeIter;
220 const SMDS_MeshNode* myCurrentNode;
221 TGetCoord* myGetCoord;
225 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
226 TGetCoord* theGetCoord,
228 TUnit* theUnit = aUnit):
229 myNodeIter(theNodeIter),
230 myGetCoord(theGetCoord),
234 virtual ~TCoordHelper(){}
236 return myNodeIter->more() &&
237 (myCurrentNode = myNodeIter->next());
239 const SMDS_MeshNode* GetNode(){
240 return myCurrentNode;
242 MED::TIntVector::value_type GetID(){
243 return myCurrentNode->GetID();
245 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
246 return (myCurrentNode->*myGetCoord[theCoodId])();
248 MED::TStringVector::value_type GetName(TInt theDimId){
249 return myName[theDimId];
251 MED::TStringVector::value_type GetUnit(TInt theDimId){
252 return myUnit[theDimId];
255 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
257 //-------------------------------------------------------
259 * \brief Structure describing element type
261 //-------------------------------------------------------
264 EEntiteMaillage _entity;
265 EGeometrieElement _geomType;
267 SMDSAbs_ElementType _smdsType;
269 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
270 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
274 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
276 //================================================================================
278 * \brief Fills element to famaly ID map for element type.
279 * Removes all families of anElemType
281 //================================================================================
283 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
284 list<DriverMED_FamilyPtr> & aFamilies,
285 const SMDSAbs_ElementType anElemType)
287 anElemFamMap.Clear();
288 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
289 while ( aFamsIter != aFamilies.end() )
291 if ((*aFamsIter)->GetType() != anElemType) {
295 int aFamId = (*aFamsIter)->GetId();
296 const ElementsSet& anElems = (*aFamsIter)->GetElements();
297 ElementsSet::const_iterator anElemsIter = anElems.begin();
298 for (; anElemsIter != anElems.end(); anElemsIter++)
300 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
302 // remove a family from the list
303 aFamilies.erase( aFamsIter++ );
308 //================================================================================
310 * \brief For an element, return family ID found in the map or a default one
312 //================================================================================
314 int getFamilyId( const TElemFamilyMap & anElemFamMap,
315 const SMDS_MeshElement* anElement,
316 const int aDefaultFamilyId)
318 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
319 return anElemFamMap( (Standard_Address) anElement );
321 return aDefaultFamilyId;
324 //================================================================================
326 * \brief Returns iterator on sub-meshes
328 //================================================================================
330 SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& mySubMeshes )
332 return SMESHDS_SubMeshIteratorPtr
333 ( new SMDS_SetIterator
334 < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(),
335 mySubMeshes.end() ));
339 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
341 Status aResult = DRS_OK;
342 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
343 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
347 //MESSAGE("Perform - myFile : "<<myFile);
349 // Creating the MED mesh for corresponding SMDS structure
350 //-------------------------------------------------------
352 if (myMeshId != -1) {
353 ostringstream aMeshNameStr;
354 aMeshNameStr<<myMeshId;
355 aMeshName = aMeshNameStr.str();
357 aMeshName = myMeshName;
360 // Mesh dimension definition
362 TInt aMeshDimension = 0;
363 if ( myMesh->NbEdges() > 0 )
365 if ( myMesh->NbFaces() > 0 )
367 if ( myMesh->NbVolumes() > 0 )
370 TInt aSpaceDimension = 3;
371 TCoordHelperPtr aCoordHelperPtr;
373 bool anIsXDimension = false;
374 bool anIsYDimension = false;
375 bool anIsZDimension = false;
376 if ( myAutoDimension && aMeshDimension < 3 )
378 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
380 if(aNodesIter->more()){
381 const SMDS_MeshNode* aNode = aNodesIter->next();
382 aBounds[0] = aBounds[1] = aNode->X();
383 aBounds[2] = aBounds[3] = aNode->Y();
384 aBounds[4] = aBounds[5] = aNode->Z();
386 while(aNodesIter->more()){
387 const SMDS_MeshNode* aNode = aNodesIter->next();
388 aBounds[0] = min(aBounds[0],aNode->X());
389 aBounds[1] = max(aBounds[1],aNode->X());
391 aBounds[2] = min(aBounds[2],aNode->Y());
392 aBounds[3] = max(aBounds[3],aNode->Y());
394 aBounds[4] = min(aBounds[4],aNode->Z());
395 aBounds[5] = max(aBounds[5],aNode->Z());
399 TopoDS_Shape mainShape = myMesh->ShapeToMesh();
400 bool hasShapeToMesh = ( myMesh->SubMeshIndices().size() > 1 );
401 if ( !mainShape.IsNull() && hasShapeToMesh )
403 // define EPS by max tolerance of the mainShape (IPAL53097)
404 TopExp_Explorer subShape;
405 for ( subShape.Init( mainShape, TopAbs_FACE ); subShape.More(); subShape.Next() ) {
406 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Face( subShape.Current() )));
408 for ( subShape.Init( mainShape, TopAbs_EDGE ); subShape.More(); subShape.Next() ) {
409 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Edge( subShape.Current() )));
411 for ( subShape.Init( mainShape, TopAbs_VERTEX ); subShape.More(); subShape.Next() ) {
412 EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Vertex( subShape.Current() )));
416 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
417 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
418 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
419 aSpaceDimension = Max( aMeshDimension, anIsXDimension + anIsYDimension + anIsZDimension );
420 if ( !aSpaceDimension )
422 // PAL16857(SMESH not conform to the MED convention):
423 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
425 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
426 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
427 if ( anIsYDimension ) {
429 anIsXDimension = true;
436 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
437 switch ( aSpaceDimension ) {
439 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
442 if(anIsXDimension && anIsYDimension)
443 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
444 if(anIsYDimension && anIsZDimension)
445 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
446 if(anIsXDimension && anIsZDimension)
447 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
451 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
453 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
455 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
460 MED::PWrapper myMed = CrWrapper(myFile,myMedVersion);
461 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
462 //MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
463 myMed->SetMeshInfo(aMeshInfo);
465 // Storing SMDS groups and sub-meshes as med families
466 //----------------------------------------------------
467 int myNodesDefaultFamilyId = 0;
468 int my0DElementsDefaultFamilyId = 0;
469 int myBallsDefaultFamilyId = 0;
470 int myEdgesDefaultFamilyId = 0;
471 int myFacesDefaultFamilyId = 0;
472 int myVolumesDefaultFamilyId = 0;
473 int nbNodes = myMesh->NbNodes();
474 int nb0DElements = myMesh->Nb0DElements();
475 int nbBalls = myMesh->NbBalls();
476 int nbEdges = myMesh->NbEdges();
477 int nbFaces = myMesh->NbFaces();
478 int nbVolumes = myMesh->NbVolumes();
479 if (myDoGroupOfNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
480 if (myDoGroupOfEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
481 if (myDoGroupOfFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
482 if (myDoGroupOfVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
483 if (myDoGroupOf0DElems) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
484 if (myDoGroupOfBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
485 if (myDoAllInGroups )
487 if (!myDoGroupOfEdges) myEdgesDefaultFamilyId = NIG_EDGES_FAMILY ;
488 if (!myDoGroupOfFaces) myFacesDefaultFamilyId = NIG_FACES_FAMILY ;
489 if (!myDoGroupOfVolumes) myVolumesDefaultFamilyId = NIG_VOLS_FAMILY ;
490 if (!myDoGroupOf0DElems) my0DElementsDefaultFamilyId = NIG_0DELEM_FAMILY ;
491 if (!myDoGroupOfBalls) myBallsDefaultFamilyId = NIG_BALL_FAMILY ;
494 //MESSAGE("Perform - aFamilyInfo");
495 list<DriverMED_FamilyPtr> aFamilies;
496 if (myAllSubMeshes) {
497 aFamilies = DriverMED_Family::MakeFamilies
498 (myMesh->SubMeshes(), myGroups,
499 myDoGroupOfNodes && nbNodes,
500 myDoGroupOfEdges && nbEdges,
501 myDoGroupOfFaces && nbFaces,
502 myDoGroupOfVolumes && nbVolumes,
503 myDoGroupOf0DElems && nb0DElements,
504 myDoGroupOfBalls && nbBalls,
508 aFamilies = DriverMED_Family::MakeFamilies
509 (getIterator( mySubMeshes ), myGroups,
510 myDoGroupOfNodes && nbNodes,
511 myDoGroupOfEdges && nbEdges,
512 myDoGroupOfFaces && nbFaces,
513 myDoGroupOfVolumes && nbVolumes,
514 myDoGroupOf0DElems && nb0DElements,
515 myDoGroupOfBalls && nbBalls,
518 list<DriverMED_FamilyPtr>::iterator aFamsIter;
519 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
521 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
522 myMed->SetFamilyInfo(aFamilyInfo);
525 // Storing SMDS nodes to the MED file for the MED mesh
526 //----------------------------------------------------
527 #ifdef _EDF_NODE_IDS_
528 typedef map<TInt,TInt> TNodeIdMap;
529 TNodeIdMap aNodeIdMap;
531 const EModeSwitch theMode = eFULL_INTERLACE;
532 const ERepere theSystem = eCART;
533 const EBooleen theIsElemNum = eVRAI;
534 const EBooleen theIsElemNames = eFAUX;
535 const EConnectivite theConnMode = eNOD;
537 TInt aNbNodes = myMesh->NbNodes();
538 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
539 theMode, theSystem, theIsElemNum, theIsElemNames);
541 // find family numbers for nodes
542 TElemFamilyMap anElemFamMap;
543 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
545 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
548 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
549 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
550 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
553 int aNodeID = aCoordHelperPtr->GetID();
554 aNodeInfo->SetElemNum( iNode, aNodeID );
555 #ifdef _EDF_NODE_IDS_
556 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
559 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
560 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
561 aNodeInfo->SetFamNum( iNode, famNum );
563 anElemFamMap.Clear();
565 // coordinate names and units
566 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
567 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
568 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
571 //MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
572 myMed->SetNodeInfo(aNodeInfo);
573 aNodeInfo.reset(); // free memory used for arrays
576 // Storing SMDS elements to the MED file for the MED mesh
577 //-------------------------------------------------------
578 // Write one element type at once in order to minimize memory usage (PAL19276)
580 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
582 // poly elements are not supported by med-2.1
583 bool polyTypesSupported = ( myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0).get() != 0 );
584 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
586 // nodes on VERTEXes where 0D elements are absent
587 std::vector<const SMDS_MeshElement*> nodesOf0D;
588 std::vector< SMDS_ElemIteratorPtr > iterVec;
589 SMDS_ElemIteratorPtr iterVecIter;
590 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
593 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
594 iterVec[1] = SMDS_ElemIteratorPtr
595 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
597 typedef SMDS_IteratorOnIterators
598 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
599 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
602 // collect info on all geom types
604 list< TElemTypeData > aTElemTypeDatas;
606 EEntiteMaillage anEntity = eMAILLE;
607 #ifdef _ELEMENTS_BY_DIM_
608 anEntity = eNOEUD_ELEMENT;
610 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
612 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
614 #ifdef _ELEMENTS_BY_DIM_
615 anEntity = eSTRUCT_ELEMENT;
617 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
619 nbElemInfo.NbBalls(),
621 #ifdef _ELEMENTS_BY_DIM_
624 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
626 nbElemInfo.NbEdges( ORDER_LINEAR ),
628 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
630 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
632 #ifdef _ELEMENTS_BY_DIM_
635 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
637 nbElemInfo.NbTriangles( ORDER_LINEAR ),
639 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
641 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
642 nbElemInfo.NbBiQuadTriangles(),
644 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
646 nbElemInfo.NbBiQuadTriangles(),
648 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
650 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
652 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
654 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
655 nbElemInfo.NbBiQuadQuadrangles(),
657 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
659 nbElemInfo.NbBiQuadQuadrangles(),
661 if ( polyTypesSupported ) {
662 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
664 nbElemInfo.NbPolygons( ORDER_LINEAR ),
666 // we need one more loop on poly elements to count nb of their nodes
667 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
669 nbElemInfo.NbPolygons( ORDER_LINEAR ),
671 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
673 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
675 // we need one more loop on QUAD poly elements to count nb of their nodes
676 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
678 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
681 #ifdef _ELEMENTS_BY_DIM_
684 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
686 nbElemInfo.NbTetras( ORDER_LINEAR ),
688 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
690 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
692 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
694 nbElemInfo.NbPyramids( ORDER_LINEAR ),
696 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
698 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
700 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
702 nbElemInfo.NbPrisms( ORDER_LINEAR ),
704 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
706 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
708 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
710 nbElemInfo.NbHexas( ORDER_LINEAR ),
712 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
714 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
715 nbElemInfo.NbTriQuadHexas(),
717 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
719 nbElemInfo.NbTriQuadHexas(),
721 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
723 nbElemInfo.NbHexPrisms(),
725 if ( polyTypesSupported ) {
726 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
728 nbElemInfo.NbPolyhedrons(),
730 // we need one more loop on poly elements to count nb of their nodes
731 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
733 nbElemInfo.NbPolyhedrons(),
737 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
739 // loop on all geom types of elements
741 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
742 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
744 if ( aElemTypeData->_nbElems == 0 )
747 int defaultFamilyId = 0;
748 switch ( aElemTypeData->_smdsType ) {
749 case SMDSAbs_0DElement: defaultFamilyId = my0DElementsDefaultFamilyId; break;
750 case SMDSAbs_Ball: defaultFamilyId = myBallsDefaultFamilyId; break;
751 case SMDSAbs_Edge: defaultFamilyId = myEdgesDefaultFamilyId; break;
752 case SMDSAbs_Face: defaultFamilyId = myFacesDefaultFamilyId; break;
753 case SMDSAbs_Volume: defaultFamilyId = myVolumesDefaultFamilyId; break;
758 // iterator on elements of a current type
759 SMDS_ElemIteratorPtr elemIterator;
764 if ( aElemTypeData->_geomType == ePOLYGONE ||
765 aElemTypeData->_geomType == ePOLYGON2 )
767 if ( aElemTypeData->_geomType == ePOLYGONE )
768 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Polygon );
770 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Quad_Polygon );
772 if ( nbPolygonNodes == 0 ) {
774 while ( elemIterator->more() ) {
775 const SMDS_MeshElement* anElem = elemIterator->next();
776 nbPolygonNodes += anElem->NbNodes();
777 if ( ++iElem == aElemTypeData->_nbElems )
783 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
784 aElemTypeData->_entity,
785 aElemTypeData->_geomType,
786 aElemTypeData->_nbElems,
788 theConnMode, theIsElemNum,
790 TElemNum & index = *(aPolygoneInfo->myIndex.get());
793 while ( elemIterator->more() )
795 const SMDS_MeshElement* anElem = elemIterator->next();
797 TInt aNbNodes = anElem->NbNodes();
798 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
801 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
802 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
803 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
804 #ifdef _EDF_NODE_IDS_
805 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
807 aTConnSlice[ iNode ] = aNode->GetID();
811 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
814 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
815 aPolygoneInfo->SetFamNum( iElem, famNum );
817 if ( ++iElem == aPolygoneInfo->GetNbElem() )
820 myMed->SetPolygoneInfo(aPolygoneInfo);
822 nbPolygonNodes = 0; // to treat next polygon type
828 else if (aElemTypeData->_geomType == ePOLYEDRE )
830 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
832 if ( nbPolyhedronNodes == 0 ) {
834 while ( elemIterator->more() ) {
835 const SMDS_MeshElement* anElem = elemIterator->next();
836 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
837 if ( !aPolyedre ) continue;
838 nbPolyhedronNodes += aPolyedre->NbNodes();
839 nbPolyhedronFaces += aPolyedre->NbFaces();
840 if ( ++iElem == aElemTypeData->_nbElems )
846 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
847 aElemTypeData->_entity,
848 aElemTypeData->_geomType,
849 aElemTypeData->_nbElems,
855 TElemNum & index = *(aPolyhInfo->myIndex.get());
856 TElemNum & faces = *(aPolyhInfo->myFaces.get());
857 TElemNum & conn = *(aPolyhInfo->myConn.get());
861 TInt iFace = 0, iNode = 0;
862 while ( elemIterator->more() )
864 const SMDS_MeshElement* anElem = elemIterator->next();
865 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
866 if ( !aPolyedre ) continue;
868 TInt aNbFaces = aPolyedre->NbFaces();
869 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
872 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
873 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
874 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
877 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
878 while ( nodeIt->more() ) {
879 const SMDS_MeshElement* aNode = nodeIt->next();
880 #ifdef _EDF_NODE_IDS_
881 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
883 conn[ iNode ] = aNode->GetID();
888 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
891 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
892 aPolyhInfo->SetFamNum( iElem, famNum );
894 if ( ++iElem == aPolyhInfo->GetNbElem() )
897 myMed->SetPolyedreInfo(aPolyhInfo);
899 } // if (aElemTypeData->_geomType == ePOLYEDRE )
903 else if (aElemTypeData->_geomType == eBALL )
905 // allocate data arrays
906 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo, aElemTypeData->_nbElems );
908 // build map of family numbers for this type
909 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
911 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
912 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
915 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
916 while ( elemIterator->more() )
918 const SMDS_MeshElement* anElem = elemIterator->next();
920 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
921 #ifdef _EDF_NODE_IDS_
922 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
924 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
927 aBallInfo->SetElemNum( iElem, anElem->GetID() );
930 aBallInfo->myDiameters[ iElem ] =
931 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
934 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
935 aBallInfo->SetFamNum( iElem, famNum );
938 // store data in a file
939 myMed->SetBallInfo(aBallInfo);
944 // Treat standard types
945 // ---------------------
947 // allocate data arrays
948 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
949 aElemTypeData->_entity,
950 aElemTypeData->_geomType,
951 aElemTypeData->_nbElems,
955 // build map of family numbers for this type
956 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
958 //cout << " fillElemFamilyMap()" << endl;
959 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
960 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
963 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
964 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
965 if ( aElemTypeData->_smdsType == SMDSAbs_0DElement && ! nodesOf0D.empty() )
966 elemIterator = iterVecIter;
967 while ( elemIterator->more() )
969 const SMDS_MeshElement* anElem = elemIterator->next();
970 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
971 continue; // other geometry
974 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
975 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
976 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
977 #ifdef _EDF_NODE_IDS_
978 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
980 aTConnSlice[ iNode ] = aNode->GetID();
984 aCellInfo->SetElemNum( iElem, anElem->GetID() );
987 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
988 aCellInfo->SetFamNum( iElem, famNum );
990 if ( ++iElem == aCellInfo->GetNbElem() )
993 // store data in a file
994 myMed->SetCellInfo(aCellInfo);
997 } // loop on geom types
1001 catch(const std::exception& exc) {
1002 INFOS("The following exception was caught:\n\t"<<exc.what());
1006 INFOS("Unknown exception was caught !!!");
1012 mySubMeshes.clear();
1016 //================================================================================
1018 * \brief Returns nodes on VERTEXes where 0D elements are absent
1020 //================================================================================
1022 bool DriverMED_W_SMESHDS_Mesh::
1023 getNodesOfMissing0DOnVert(SMESHDS_Mesh* meshDS,
1024 std::vector<const SMDS_MeshElement*>& nodes)
1027 for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
1029 if ( meshDS->IndexToShape( i ).ShapeType() != TopAbs_VERTEX )
1031 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(i) ) {
1032 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
1035 const SMDS_MeshNode* n = nIt->next();
1036 if ( n->NbInverseElements( SMDSAbs_0DElement ) == 0 )
1037 nodes.push_back( n );
1041 return !nodes.empty();