1 // Copyright (C) 2007-2015 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 <utilities.h>
43 #define _EDF_NODE_IDS_
44 //#define _ELEMENTS_BY_DIM_
50 DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
51 myMedVersion(MED::eV2_2),
52 myAllSubMeshes (false),
53 myDoGroupOfNodes (false),
54 myDoGroupOfEdges (false),
55 myDoGroupOfFaces (false),
56 myDoGroupOfVolumes (false),
57 myDoGroupOf0DElems(false),
58 myDoGroupOfBalls(false),
59 myAutoDimension(true),
60 myAddODOnVertices(false)
63 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
66 Driver_SMESHDS_Mesh::SetFile(theFileName);
70 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
72 Driver_SMESHDS_Mesh::SetFile(theFileName);
75 string DriverMED_W_SMESHDS_Mesh::GetVersionString(const MED::EVersion theVersion, int theNbDigits)
77 TInt majeur, mineur, release;
78 majeur = mineur = release = 0;
79 // if ( theVersion == eV2_1 )
80 // MED::GetVersionRelease<eV2_1>(majeur, mineur, release);
82 MED::GetVersionRelease<eV2_2>(majeur, mineur, release);
84 if ( theNbDigits > 0 )
86 if ( theNbDigits > 1 )
87 name << "." << mineur;
88 if ( theNbDigits > 2 )
89 name << "." << release;
93 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
95 myGroups.push_back(theGroup);
98 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
100 myAllSubMeshes = true;
103 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
105 mySubMeshes.push_back( theSubMesh );
108 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
110 myDoGroupOfNodes = true;
113 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
115 myDoGroupOfEdges = true;
118 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
120 myDoGroupOfFaces = true;
123 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
125 myDoGroupOfVolumes = true;
130 typedef double (SMDS_MeshNode::* TGetCoord)() const;
131 typedef const char* TName;
132 typedef const char* TUnit;
134 // name length in a mesh must be equal to 16 :
141 TUnit aUnit[3] = {M,M,M};
144 TGetCoord aXYZGetCoord[3] = {
149 TName aXYZName[3] = {X,Y,Z};
152 TGetCoord aXYGetCoord[2] = {
156 TName aXYName[2] = {X,Y};
158 TGetCoord aYZGetCoord[2] = {
162 TName aYZName[2] = {Y,Z};
164 TGetCoord aXZGetCoord[2] = {
168 TName aXZName[2] = {X,Z};
171 TGetCoord aXGetCoord[1] = {
174 TName aXName[1] = {X};
176 TGetCoord aYGetCoord[1] = {
179 TName aYName[1] = {Y};
181 TGetCoord aZGetCoord[1] = {
184 TName aZName[1] = {Z};
188 SMDS_NodeIteratorPtr myNodeIter;
189 const SMDS_MeshNode* myCurrentNode;
190 TGetCoord* myGetCoord;
194 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
195 TGetCoord* theGetCoord,
197 TUnit* theUnit = aUnit):
198 myNodeIter(theNodeIter),
199 myGetCoord(theGetCoord),
203 virtual ~TCoordHelper(){}
205 return myNodeIter->more() &&
206 (myCurrentNode = myNodeIter->next());
208 const SMDS_MeshNode* GetNode(){
209 return myCurrentNode;
211 MED::TIntVector::value_type GetID(){
212 return myCurrentNode->GetID();
214 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
215 return (myCurrentNode->*myGetCoord[theCoodId])();
217 MED::TStringVector::value_type GetName(TInt theDimId){
218 return myName[theDimId];
220 MED::TStringVector::value_type GetUnit(TInt theDimId){
221 return myUnit[theDimId];
224 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
226 //-------------------------------------------------------
228 * \brief Structure describing element type
230 //-------------------------------------------------------
233 EEntiteMaillage _entity;
234 EGeometrieElement _geomType;
236 SMDSAbs_ElementType _smdsType;
238 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
239 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
243 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
245 //================================================================================
247 * \brief Fills element to famaly ID map for element type.
248 * Removes all families of anElemType
250 //================================================================================
252 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
253 list<DriverMED_FamilyPtr> & aFamilies,
254 const SMDSAbs_ElementType anElemType)
256 anElemFamMap.Clear();
257 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
258 while ( aFamsIter != aFamilies.end() )
260 if ((*aFamsIter)->GetType() != anElemType) {
264 int aFamId = (*aFamsIter)->GetId();
265 const ElementsSet& anElems = (*aFamsIter)->GetElements();
266 ElementsSet::const_iterator anElemsIter = anElems.begin();
267 for (; anElemsIter != anElems.end(); anElemsIter++)
269 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
271 // remove a family from the list
272 aFamilies.erase( aFamsIter++ );
277 //================================================================================
279 * \brief For an element, return family ID found in the map or a default one
281 //================================================================================
283 int getFamilyId( const TElemFamilyMap & anElemFamMap,
284 const SMDS_MeshElement* anElement,
285 const int aDefaultFamilyId)
287 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
288 return anElemFamMap( (Standard_Address) anElement );
290 return aDefaultFamilyId;
293 //================================================================================
295 * \brief Returns iterator on sub-meshes
297 //================================================================================
299 SMESHDS_SubMeshIteratorPtr getIterator( std::vector<SMESHDS_SubMesh*>& mySubMeshes )
301 return SMESHDS_SubMeshIteratorPtr
302 ( new SMDS_SetIterator
303 < const SMESHDS_SubMesh*, std::vector< SMESHDS_SubMesh* >::iterator >( mySubMeshes.begin(),
304 mySubMeshes.end() ));
308 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
310 Status aResult = DRS_OK;
311 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
312 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
316 MESSAGE("Perform - myFile : "<<myFile);
318 // Creating the MED mesh for corresponding SMDS structure
319 //-------------------------------------------------------
321 if (myMeshId != -1) {
322 ostringstream aMeshNameStr;
323 aMeshNameStr<<myMeshId;
324 aMeshName = aMeshNameStr.str();
326 aMeshName = myMeshName;
329 // Mesh dimension definition
330 TInt aSpaceDimension = 3;
331 TCoordHelperPtr aCoordHelperPtr;
333 bool anIsXDimension = false;
334 bool anIsYDimension = false;
335 bool anIsZDimension = false;
336 if ( myAutoDimension )
338 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
340 if(aNodesIter->more()){
341 const SMDS_MeshNode* aNode = aNodesIter->next();
342 aBounds[0] = aBounds[1] = aNode->X();
343 aBounds[2] = aBounds[3] = aNode->Y();
344 aBounds[4] = aBounds[5] = aNode->Z();
346 while(aNodesIter->more()){
347 const SMDS_MeshNode* aNode = aNodesIter->next();
348 aBounds[0] = min(aBounds[0],aNode->X());
349 aBounds[1] = max(aBounds[1],aNode->X());
351 aBounds[2] = min(aBounds[2],aNode->Y());
352 aBounds[3] = max(aBounds[3],aNode->Y());
354 aBounds[4] = min(aBounds[4],aNode->Z());
355 aBounds[5] = max(aBounds[5],aNode->Z());
359 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
360 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
361 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
362 aSpaceDimension = anIsXDimension + anIsYDimension + anIsZDimension;
365 // PAL16857(SMESH not conform to the MED convention):
366 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
368 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
369 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
370 if ( anIsYDimension ) {
372 anIsXDimension = true;
379 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
380 switch(aSpaceDimension){
382 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
385 if(anIsXDimension && anIsYDimension)
386 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
387 if(anIsYDimension && anIsZDimension)
388 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
389 if(anIsXDimension && anIsZDimension)
390 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
394 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
396 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
398 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
402 TInt aMeshDimension = 0;
403 if ( myMesh->NbEdges() > 0 )
405 if ( myMesh->NbFaces() > 0 )
407 if ( myMesh->NbVolumes() > 0 )
410 MED::PWrapper myMed = CrWrapper(myFile,myMedVersion);
411 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
412 MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
413 myMed->SetMeshInfo(aMeshInfo);
415 // Storing SMDS groups and sub-meshes as med families
416 //----------------------------------------------------
417 int myNodesDefaultFamilyId = 0;
418 int my0DElementsDefaultFamilyId = 0;
419 int myBallsDefaultFamilyId = 0;
420 int myEdgesDefaultFamilyId = 0;
421 int myFacesDefaultFamilyId = 0;
422 int myVolumesDefaultFamilyId = 0;
423 int nbNodes = myMesh->NbNodes();
424 int nb0DElements = myMesh->Nb0DElements();
425 int nbBalls = myMesh->NbBalls();
426 int nbEdges = myMesh->NbEdges();
427 int nbFaces = myMesh->NbFaces();
428 int nbVolumes = myMesh->NbVolumes();
429 if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
430 if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
431 if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
432 if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
433 if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
434 if (myDoGroupOfBalls && nbBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
436 MESSAGE("Perform - aFamilyInfo");
437 list<DriverMED_FamilyPtr> aFamilies;
438 if (myAllSubMeshes) {
439 aFamilies = DriverMED_Family::MakeFamilies
440 (myMesh->SubMeshes(), myGroups,
441 myDoGroupOfNodes && nbNodes,
442 myDoGroupOfEdges && nbEdges,
443 myDoGroupOfFaces && nbFaces,
444 myDoGroupOfVolumes && nbVolumes,
445 myDoGroupOf0DElems && nb0DElements,
446 myDoGroupOfBalls && nbBalls);
448 aFamilies = DriverMED_Family::MakeFamilies
449 (getIterator( mySubMeshes ), myGroups,
450 myDoGroupOfNodes && nbNodes,
451 myDoGroupOfEdges && nbEdges,
452 myDoGroupOfFaces && nbFaces,
453 myDoGroupOfVolumes && nbVolumes,
454 myDoGroupOf0DElems && nb0DElements,
455 myDoGroupOfBalls && nbBalls);
457 list<DriverMED_FamilyPtr>::iterator aFamsIter;
458 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
460 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
461 myMed->SetFamilyInfo(aFamilyInfo);
464 // Storing SMDS nodes to the MED file for the MED mesh
465 //----------------------------------------------------
466 #ifdef _EDF_NODE_IDS_
467 typedef map<TInt,TInt> TNodeIdMap;
468 TNodeIdMap aNodeIdMap;
470 const EModeSwitch theMode = eFULL_INTERLACE;
471 const ERepere theSystem = eCART;
472 const EBooleen theIsElemNum = eVRAI;
473 const EBooleen theIsElemNames = eFAUX;
474 const EConnectivite theConnMode = eNOD;
476 TInt aNbNodes = myMesh->NbNodes();
477 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
478 theMode, theSystem, theIsElemNum, theIsElemNames);
480 //cout << " fillElemFamilyMap( SMDSAbs_Node )" << endl;
481 // find family numbers for nodes
482 TElemFamilyMap anElemFamMap;
483 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
485 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
488 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
489 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
490 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
493 int aNodeID = aCoordHelperPtr->GetID();
494 aNodeInfo->SetElemNum( iNode, aNodeID );
495 #ifdef _EDF_NODE_IDS_
496 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
499 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
500 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
501 aNodeInfo->SetFamNum( iNode, famNum );
503 anElemFamMap.Clear();
505 // coordinate names and units
506 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
507 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
508 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
511 //cout << " SetNodeInfo(aNodeInfo)" << endl;
512 MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
513 myMed->SetNodeInfo(aNodeInfo);
514 aNodeInfo.reset(); // free memory used for arrays
517 // Storing SMDS elements to the MED file for the MED mesh
518 //-------------------------------------------------------
519 // Write one element type at once in order to minimize memory usage (PAL19276)
521 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
523 // poly elements are not supported by med-2.1
524 bool polyTypesSupported = ( myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0).get() != 0 );
525 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
527 // nodes on VERTEXes where 0D elements are absent
528 std::vector<const SMDS_MeshElement*> nodesOf0D;
529 std::vector< SMDS_ElemIteratorPtr > iterVec;
530 SMDS_ElemIteratorPtr iterVecIter;
531 if ( myAddODOnVertices && getNodesOfMissing0DOnVert( myMesh, nodesOf0D ))
534 iterVec[0] = myMesh->elementsIterator( SMDSAbs_0DElement );
535 iterVec[1] = SMDS_ElemIteratorPtr
536 ( new SMDS_ElementVectorIterator( nodesOf0D.begin(), nodesOf0D.end() ));
538 typedef SMDS_IteratorOnIterators
539 < const SMDS_MeshElement *, std::vector< SMDS_ElemIteratorPtr > > TItIterator;
540 iterVecIter = SMDS_ElemIteratorPtr( new TItIterator( iterVec ));
543 // collect info on all geom types
545 list< TElemTypeData > aTElemTypeDatas;
547 EEntiteMaillage anEntity = eMAILLE;
548 #ifdef _ELEMENTS_BY_DIM_
549 anEntity = eNOEUD_ELEMENT;
551 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
553 nbElemInfo.Nb0DElements() + nodesOf0D.size(),
555 #ifdef _ELEMENTS_BY_DIM_
556 anEntity = eSTRUCT_ELEMENT;
558 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
560 nbElemInfo.NbBalls(),
562 #ifdef _ELEMENTS_BY_DIM_
565 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
567 nbElemInfo.NbEdges( ORDER_LINEAR ),
569 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
571 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
573 #ifdef _ELEMENTS_BY_DIM_
576 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
578 nbElemInfo.NbTriangles( ORDER_LINEAR ),
580 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
582 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
583 nbElemInfo.NbBiQuadTriangles(),
585 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
587 nbElemInfo.NbBiQuadTriangles(),
589 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
591 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
593 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
595 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
596 nbElemInfo.NbBiQuadQuadrangles(),
598 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
600 nbElemInfo.NbBiQuadQuadrangles(),
602 if ( polyTypesSupported ) {
603 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
605 nbElemInfo.NbPolygons( ORDER_LINEAR ),
607 // we need one more loop on poly elements to count nb of their nodes
608 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
610 nbElemInfo.NbPolygons( ORDER_LINEAR ),
612 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
614 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
616 // we need one more loop on QUAD poly elements to count nb of their nodes
617 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
619 nbElemInfo.NbPolygons( ORDER_QUADRATIC ),
622 #ifdef _ELEMENTS_BY_DIM_
625 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
627 nbElemInfo.NbTetras( ORDER_LINEAR ),
629 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
631 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
633 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
635 nbElemInfo.NbPyramids( ORDER_LINEAR ),
637 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
639 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
641 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
643 nbElemInfo.NbPrisms( ORDER_LINEAR ),
645 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
647 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
649 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
651 nbElemInfo.NbHexas( ORDER_LINEAR ),
653 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
655 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
656 nbElemInfo.NbTriQuadHexas(),
658 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
660 nbElemInfo.NbTriQuadHexas(),
662 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
664 nbElemInfo.NbHexPrisms(),
666 if ( polyTypesSupported ) {
667 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
669 nbElemInfo.NbPolyhedrons(),
671 // we need one more loop on poly elements to count nb of their nodes
672 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
674 nbElemInfo.NbPolyhedrons(),
678 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
680 // loop on all geom types of elements
682 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
683 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
685 if ( aElemTypeData->_nbElems == 0 )
688 int defaultFamilyId = 0;
689 switch ( aElemTypeData->_smdsType ) {
690 case SMDSAbs_0DElement:
691 defaultFamilyId = my0DElementsDefaultFamilyId;
694 defaultFamilyId = myBallsDefaultFamilyId;
697 defaultFamilyId = myEdgesDefaultFamilyId;
700 defaultFamilyId = myFacesDefaultFamilyId;
703 defaultFamilyId = myVolumesDefaultFamilyId;
709 // iterator on elements of a current type
710 SMDS_ElemIteratorPtr elemIterator;
715 if ( aElemTypeData->_geomType == ePOLYGONE ||
716 aElemTypeData->_geomType == ePOLYGON2 )
718 if ( aElemTypeData->_geomType == ePOLYGONE )
719 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Polygon );
721 elemIterator = myMesh->elementEntityIterator( SMDSEntity_Quad_Polygon );
723 if ( nbPolygonNodes == 0 ) {
725 while ( elemIterator->more() ) {
726 const SMDS_MeshElement* anElem = elemIterator->next();
727 nbPolygonNodes += anElem->NbNodes();
728 if ( ++iElem == aElemTypeData->_nbElems )
734 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
735 aElemTypeData->_entity,
736 aElemTypeData->_geomType,
737 aElemTypeData->_nbElems,
739 theConnMode, theIsElemNum,
741 TElemNum & index = *(aPolygoneInfo->myIndex.get());
744 while ( elemIterator->more() )
746 const SMDS_MeshElement* anElem = elemIterator->next();
748 TInt aNbNodes = anElem->NbNodes();
749 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
752 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
753 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
754 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
755 #ifdef _EDF_NODE_IDS_
756 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
758 aTConnSlice[ iNode ] = aNode->GetID();
762 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
765 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
766 aPolygoneInfo->SetFamNum( iElem, famNum );
768 if ( ++iElem == aPolygoneInfo->GetNbElem() )
771 myMed->SetPolygoneInfo(aPolygoneInfo);
773 nbPolygonNodes = 0; // to treat next polygon type
779 else if (aElemTypeData->_geomType == ePOLYEDRE )
781 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
783 if ( nbPolyhedronNodes == 0 ) {
785 while ( elemIterator->more() ) {
786 const SMDS_MeshElement* anElem = elemIterator->next();
787 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
788 if ( !aPolyedre ) continue;
789 nbPolyhedronNodes += aPolyedre->NbNodes();
790 nbPolyhedronFaces += aPolyedre->NbFaces();
791 if ( ++iElem == aElemTypeData->_nbElems )
797 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
798 aElemTypeData->_entity,
799 aElemTypeData->_geomType,
800 aElemTypeData->_nbElems,
806 TElemNum & index = *(aPolyhInfo->myIndex.get());
807 TElemNum & faces = *(aPolyhInfo->myFaces.get());
808 TElemNum & conn = *(aPolyhInfo->myConn.get());
812 TInt iFace = 0, iNode = 0;
813 while ( elemIterator->more() )
815 const SMDS_MeshElement* anElem = elemIterator->next();
816 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
817 if ( !aPolyedre ) continue;
819 TInt aNbFaces = aPolyedre->NbFaces();
820 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
823 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
824 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
825 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
828 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
829 while ( nodeIt->more() ) {
830 const SMDS_MeshElement* aNode = nodeIt->next();
831 #ifdef _EDF_NODE_IDS_
832 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
834 conn[ iNode ] = aNode->GetID();
839 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
842 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
843 aPolyhInfo->SetFamNum( iElem, famNum );
845 if ( ++iElem == aPolyhInfo->GetNbElem() )
848 myMed->SetPolyedreInfo(aPolyhInfo);
850 } // if (aElemTypeData->_geomType == ePOLYEDRE )
854 else if (aElemTypeData->_geomType == eBALL )
856 // allocate data arrays
857 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo,
858 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();