1 // Copyright (C) 2007-2014 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_MeshElement.hxx"
34 #include "SMDS_MeshNode.hxx"
35 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
36 #include "SMESHDS_Mesh.hxx"
38 #include <utilities.h>
41 #define _EDF_NODE_IDS_
42 //#define _ELEMENTS_BY_DIM_
48 DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
49 myMedVersion(MED::eV2_2),
50 myAllSubMeshes (false),
51 myDoGroupOfNodes (false),
52 myDoGroupOfEdges (false),
53 myDoGroupOfFaces (false),
54 myDoGroupOfVolumes (false),
55 myDoGroupOf0DElems(false),
56 myDoGroupOfBalls(false),
60 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
63 Driver_SMESHDS_Mesh::SetFile(theFileName);
67 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
69 Driver_SMESHDS_Mesh::SetFile(theFileName);
72 string DriverMED_W_SMESHDS_Mesh::GetVersionString(const MED::EVersion theVersion, int theNbDigits)
74 TInt majeur, mineur, release;
75 majeur = mineur = release = 0;
76 // if ( theVersion == eV2_1 )
77 // MED::GetVersionRelease<eV2_1>(majeur, mineur, release);
79 MED::GetVersionRelease<eV2_2>(majeur, mineur, release);
81 if ( theNbDigits > 0 )
83 if ( theNbDigits > 1 )
84 name << "." << mineur;
85 if ( theNbDigits > 2 )
86 name << "." << release;
90 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
92 myGroups.push_back(theGroup);
95 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
97 myAllSubMeshes = true;
100 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
102 mySubMeshes[theID] = theSubMesh;
105 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
107 myDoGroupOfNodes = true;
110 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
112 myDoGroupOfEdges = true;
115 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
117 myDoGroupOfFaces = true;
120 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
122 myDoGroupOfVolumes = true;
127 typedef double (SMDS_MeshNode::* TGetCoord)() const;
128 typedef const char* TName;
129 typedef const char* TUnit;
131 // name length in a mesh must be equal to 16 :
138 TUnit aUnit[3] = {M,M,M};
141 TGetCoord aXYZGetCoord[3] = {
146 TName aXYZName[3] = {X,Y,Z};
149 TGetCoord aXYGetCoord[2] = {
153 TName aXYName[2] = {X,Y};
155 TGetCoord aYZGetCoord[2] = {
159 TName aYZName[2] = {Y,Z};
161 TGetCoord aXZGetCoord[2] = {
165 TName aXZName[2] = {X,Z};
168 TGetCoord aXGetCoord[1] = {
171 TName aXName[1] = {X};
173 TGetCoord aYGetCoord[1] = {
176 TName aYName[1] = {Y};
178 TGetCoord aZGetCoord[1] = {
181 TName aZName[1] = {Z};
185 SMDS_NodeIteratorPtr myNodeIter;
186 const SMDS_MeshNode* myCurrentNode;
187 TGetCoord* myGetCoord;
191 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
192 TGetCoord* theGetCoord,
194 TUnit* theUnit = aUnit):
195 myNodeIter(theNodeIter),
196 myGetCoord(theGetCoord),
200 virtual ~TCoordHelper(){}
202 return myNodeIter->more() &&
203 (myCurrentNode = myNodeIter->next());
205 const SMDS_MeshNode* GetNode(){
206 return myCurrentNode;
208 MED::TIntVector::value_type GetID(){
209 return myCurrentNode->GetID();
211 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
212 return (myCurrentNode->*myGetCoord[theCoodId])();
214 MED::TStringVector::value_type GetName(TInt theDimId){
215 return myName[theDimId];
217 MED::TStringVector::value_type GetUnit(TInt theDimId){
218 return myUnit[theDimId];
221 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
223 //-------------------------------------------------------
225 * \brief Structure describing element type
227 //-------------------------------------------------------
230 EEntiteMaillage _entity;
231 EGeometrieElement _geomType;
233 SMDSAbs_ElementType _smdsType;
235 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
236 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
240 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
242 //================================================================================
244 * \brief Fills element to famaly ID map for element type.
245 * Removes all families of anElemType
247 //================================================================================
249 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
250 list<DriverMED_FamilyPtr> & aFamilies,
251 const SMDSAbs_ElementType anElemType)
253 anElemFamMap.Clear();
254 //anElemFamMap.clear();
255 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
256 while ( aFamsIter != aFamilies.end() )
258 if ((*aFamsIter)->GetType() != anElemType) {
262 int aFamId = (*aFamsIter)->GetId();
263 const set<const SMDS_MeshElement *>& anElems = (*aFamsIter)->GetElements();
264 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElems.begin();
265 for (; anElemsIter != anElems.end(); anElemsIter++)
267 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
268 //anElemFamMap[*anElemsIter] = aFamId;
270 // remove a family from the list
271 aFamilies.erase( aFamsIter++ );
276 //================================================================================
278 * \brief For an element, return family ID found in the map or a default one
280 //================================================================================
282 int getFamilyId( const TElemFamilyMap & anElemFamMap,
283 const SMDS_MeshElement* anElement,
284 const int aDefaultFamilyId)
286 if ( anElemFamMap.IsBound( (Standard_Address) anElement ))
287 return anElemFamMap( (Standard_Address) anElement );
288 // TElemFamilyMap::iterator elem_famNum = anElemFamMap.find( anElement );
289 // if ( elem_famNum != anElemFamMap.end() )
290 // return elem_famNum->second;
291 return aDefaultFamilyId;
295 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
297 Status aResult = DRS_OK;
298 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
299 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
303 MESSAGE("Perform - myFile : "<<myFile);
305 // Creating the MED mesh for corresponding SMDS structure
306 //-------------------------------------------------------
308 if (myMeshId != -1) {
309 ostringstream aMeshNameStr;
310 aMeshNameStr<<myMeshId;
311 aMeshName = aMeshNameStr.str();
313 aMeshName = myMeshName;
316 // Mesh dimension definition
317 TInt aSpaceDimension = 3;
318 TCoordHelperPtr aCoordHelperPtr;
320 bool anIsXDimension = false;
321 bool anIsYDimension = false;
322 bool anIsZDimension = false;
323 if ( myAutoDimension )
325 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
327 if(aNodesIter->more()){
328 const SMDS_MeshNode* aNode = aNodesIter->next();
329 aBounds[0] = aBounds[1] = aNode->X();
330 aBounds[2] = aBounds[3] = aNode->Y();
331 aBounds[4] = aBounds[5] = aNode->Z();
333 while(aNodesIter->more()){
334 const SMDS_MeshNode* aNode = aNodesIter->next();
335 aBounds[0] = min(aBounds[0],aNode->X());
336 aBounds[1] = max(aBounds[1],aNode->X());
338 aBounds[2] = min(aBounds[2],aNode->Y());
339 aBounds[3] = max(aBounds[3],aNode->Y());
341 aBounds[4] = min(aBounds[4],aNode->Z());
342 aBounds[5] = max(aBounds[5],aNode->Z());
346 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
347 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
348 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
349 aSpaceDimension = anIsXDimension + anIsYDimension + anIsZDimension;
352 // PAL16857(SMESH not conform to the MED convention):
353 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
355 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
356 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
357 if ( anIsYDimension ) {
359 anIsXDimension = true;
366 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
367 switch(aSpaceDimension){
369 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
372 if(anIsXDimension && anIsYDimension)
373 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
374 if(anIsYDimension && anIsZDimension)
375 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
376 if(anIsXDimension && anIsZDimension)
377 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
381 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
383 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
385 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
389 TInt aMeshDimension = 0;
390 if ( myMesh->NbEdges() > 0 )
392 if ( myMesh->NbFaces() > 0 )
394 if ( myMesh->NbVolumes() > 0 )
397 MED::PWrapper myMed = CrWrapper(myFile,myMedVersion);
398 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
399 MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
400 myMed->SetMeshInfo(aMeshInfo);
402 // Storing SMDS groups and sub-meshes as med families
403 //----------------------------------------------------
404 int myNodesDefaultFamilyId = 0;
405 int my0DElementsDefaultFamilyId = 0;
406 int myBallsDefaultFamilyId = 0;
407 int myEdgesDefaultFamilyId = 0;
408 int myFacesDefaultFamilyId = 0;
409 int myVolumesDefaultFamilyId = 0;
410 int nbNodes = myMesh->NbNodes();
411 int nb0DElements = myMesh->Nb0DElements();
412 int nbBalls = myMesh->NbBalls();
413 int nbEdges = myMesh->NbEdges();
414 int nbFaces = myMesh->NbFaces();
415 int nbVolumes = myMesh->NbVolumes();
416 if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
417 if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
418 if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
419 if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
420 if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
421 if (myDoGroupOfBalls && nbBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
423 MESSAGE("Perform - aFamilyInfo");
424 //cout << " DriverMED_Family::MakeFamilies() " << endl;
425 list<DriverMED_FamilyPtr> aFamilies;
426 if (myAllSubMeshes) {
427 aFamilies = DriverMED_Family::MakeFamilies
428 (myMesh->SubMeshes(), myGroups,
429 myDoGroupOfNodes && nbNodes,
430 myDoGroupOfEdges && nbEdges,
431 myDoGroupOfFaces && nbFaces,
432 myDoGroupOfVolumes && nbVolumes,
433 myDoGroupOf0DElems && nb0DElements,
434 myDoGroupOfBalls && nbBalls);
436 aFamilies = DriverMED_Family::MakeFamilies
437 (mySubMeshes, myGroups,
438 myDoGroupOfNodes && nbNodes,
439 myDoGroupOfEdges && nbEdges,
440 myDoGroupOfFaces && nbFaces,
441 myDoGroupOfVolumes && nbVolumes,
442 myDoGroupOf0DElems && nb0DElements,
443 myDoGroupOfBalls && nbBalls);
445 //cout << " myMed->SetFamilyInfo() " << endl;
446 list<DriverMED_FamilyPtr>::iterator aFamsIter;
447 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
449 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
450 myMed->SetFamilyInfo(aFamilyInfo);
453 // Storing SMDS nodes to the MED file for the MED mesh
454 //----------------------------------------------------
455 #ifdef _EDF_NODE_IDS_
456 typedef map<TInt,TInt> TNodeIdMap;
457 TNodeIdMap aNodeIdMap;
459 const EModeSwitch theMode = eFULL_INTERLACE;
460 const ERepere theSystem = eCART;
461 const EBooleen theIsElemNum = eVRAI;
462 const EBooleen theIsElemNames = eFAUX;
463 const EConnectivite theConnMode = eNOD;
465 TInt aNbNodes = myMesh->NbNodes();
466 //cout << " myMed->CrNodeInfo() aNbNodes = " << aNbNodes << endl;
467 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
468 theMode, theSystem, theIsElemNum, theIsElemNames);
470 //cout << " fillElemFamilyMap( SMDSAbs_Node )" << endl;
471 // find family numbers for nodes
472 TElemFamilyMap anElemFamMap;
473 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
475 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
478 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
479 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
480 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
483 int aNodeID = aCoordHelperPtr->GetID();
484 aNodeInfo->SetElemNum( iNode, aNodeID );
485 #ifdef _EDF_NODE_IDS_
486 aNodeIdMap.insert( aNodeIdMap.end(), make_pair( aNodeID, iNode+1 ));
489 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
490 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
491 aNodeInfo->SetFamNum( iNode, famNum );
493 anElemFamMap.Clear();
495 // coordinate names and units
496 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
497 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
498 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
501 //cout << " SetNodeInfo(aNodeInfo)" << endl;
502 MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
503 myMed->SetNodeInfo(aNodeInfo);
504 aNodeInfo.reset(); // free memory used for arrays
507 // Storing SMDS elements to the MED file for the MED mesh
508 //-------------------------------------------------------
509 // Write one element type at once in order to minimize memory usage (PAL19276)
511 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
513 // poly elements are not supported by med-2.1
514 bool polyTypesSupported = myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0);
515 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
517 // collect info on all geom types
519 list< TElemTypeData > aTElemTypeDatas;
521 EEntiteMaillage anEntity = eMAILLE;
522 #ifdef _ELEMENTS_BY_DIM_
523 anEntity = eNOEUD_ELEMENT;
525 aTElemTypeDatas.push_back(TElemTypeData(anEntity,
527 nbElemInfo.Nb0DElements(),
529 #ifdef _ELEMENTS_BY_DIM_
530 anEntity = eSTRUCT_ELEMENT;
532 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
534 nbElemInfo.NbBalls(),
536 #ifdef _ELEMENTS_BY_DIM_
539 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
541 nbElemInfo.NbEdges( ORDER_LINEAR ),
543 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
545 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
547 #ifdef _ELEMENTS_BY_DIM_
550 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
552 nbElemInfo.NbTriangles( ORDER_LINEAR ),
554 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
556 nbElemInfo.NbTriangles( ORDER_QUADRATIC ) -
557 nbElemInfo.NbBiQuadTriangles(),
559 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
561 nbElemInfo.NbBiQuadTriangles(),
563 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
565 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
567 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
569 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ) -
570 nbElemInfo.NbBiQuadQuadrangles(),
572 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
574 nbElemInfo.NbBiQuadQuadrangles(),
576 if ( polyTypesSupported ) {
577 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
579 nbElemInfo.NbPolygons(),
581 // we need one more loop on poly elements to count nb of their nodes
582 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
584 nbElemInfo.NbPolygons(),
587 #ifdef _ELEMENTS_BY_DIM_
590 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
592 nbElemInfo.NbTetras( ORDER_LINEAR ),
594 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
596 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
598 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
600 nbElemInfo.NbPyramids( ORDER_LINEAR ),
602 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
604 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
606 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
608 nbElemInfo.NbPrisms( ORDER_LINEAR ),
610 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
612 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
614 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
616 nbElemInfo.NbHexas( ORDER_LINEAR ),
618 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
620 nbElemInfo.NbHexas( ORDER_QUADRATIC )-
621 nbElemInfo.NbTriQuadHexas(),
623 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
625 nbElemInfo.NbTriQuadHexas(),
627 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
629 nbElemInfo.NbHexPrisms(),
631 if ( polyTypesSupported ) {
632 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
634 nbElemInfo.NbPolyhedrons(),
636 // we need one more loop on poly elements to count nb of their nodes
637 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
639 nbElemInfo.NbPolyhedrons(),
643 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
645 // loop on all geom types of elements
647 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
648 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
650 if ( aElemTypeData->_nbElems == 0 )
653 int defaultFamilyId = 0;
654 switch ( aElemTypeData->_smdsType ) {
655 case SMDSAbs_0DElement:
656 defaultFamilyId = my0DElementsDefaultFamilyId;
659 defaultFamilyId = myBallsDefaultFamilyId;
662 defaultFamilyId = myEdgesDefaultFamilyId;
665 defaultFamilyId = myFacesDefaultFamilyId;
668 defaultFamilyId = myVolumesDefaultFamilyId;
674 // iterator on elements of a current type
675 SMDS_ElemIteratorPtr elemIterator;
680 if ( aElemTypeData->_geomType == ePOLYGONE )
682 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYGON );
683 if ( nbPolygonNodes == 0 ) {
685 while ( elemIterator->more() ) {
686 const SMDS_MeshElement* anElem = elemIterator->next();
687 nbPolygonNodes += anElem->NbNodes();
688 if ( ++iElem == aElemTypeData->_nbElems )
694 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
695 aElemTypeData->_entity,
696 aElemTypeData->_geomType,
697 aElemTypeData->_nbElems,
699 theConnMode, theIsElemNum,
701 TElemNum & index = *(aPolygoneInfo->myIndex.get());
704 while ( elemIterator->more() )
706 const SMDS_MeshElement* anElem = elemIterator->next();
708 TInt aNbNodes = anElem->NbNodes();
709 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
712 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
713 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
714 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
715 #ifdef _EDF_NODE_IDS_
716 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
718 aTConnSlice[ iNode ] = aNode->GetID();
722 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
725 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
726 aPolygoneInfo->SetFamNum( iElem, famNum );
728 if ( ++iElem == aPolygoneInfo->GetNbElem() )
731 myMed->SetPolygoneInfo(aPolygoneInfo);
738 else if (aElemTypeData->_geomType == ePOLYEDRE )
740 elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
742 if ( nbPolyhedronNodes == 0 ) {
744 while ( elemIterator->more() ) {
745 const SMDS_MeshElement* anElem = elemIterator->next();
746 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
747 if ( !aPolyedre ) continue;
748 nbPolyhedronNodes += aPolyedre->NbNodes();
749 nbPolyhedronFaces += aPolyedre->NbFaces();
750 if ( ++iElem == aElemTypeData->_nbElems )
756 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
757 aElemTypeData->_entity,
758 aElemTypeData->_geomType,
759 aElemTypeData->_nbElems,
765 TElemNum & index = *(aPolyhInfo->myIndex.get());
766 TElemNum & faces = *(aPolyhInfo->myFaces.get());
767 TElemNum & conn = *(aPolyhInfo->myConn.get());
771 TInt iFace = 0, iNode = 0;
772 while ( elemIterator->more() )
774 const SMDS_MeshElement* anElem = elemIterator->next();
775 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
776 if ( !aPolyedre ) continue;
778 TInt aNbFaces = aPolyedre->NbFaces();
779 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
782 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
783 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
784 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
787 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
788 while ( nodeIt->more() ) {
789 const SMDS_MeshElement* aNode = nodeIt->next();
790 #ifdef _EDF_NODE_IDS_
791 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
793 conn[ iNode ] = aNode->GetID();
798 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
801 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
802 aPolyhInfo->SetFamNum( iElem, famNum );
804 if ( ++iElem == aPolyhInfo->GetNbElem() )
807 myMed->SetPolyedreInfo(aPolyhInfo);
809 } // if (aElemTypeData->_geomType == ePOLYEDRE )
813 else if (aElemTypeData->_geomType == eBALL )
815 // allocate data arrays
816 PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo,
817 aElemTypeData->_nbElems );
819 // build map of family numbers for this type
820 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
822 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
823 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
826 elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
827 while ( elemIterator->more() )
829 const SMDS_MeshElement* anElem = elemIterator->next();
831 const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
832 #ifdef _EDF_NODE_IDS_
833 (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
835 (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
838 aBallInfo->SetElemNum( iElem, anElem->GetID() );
841 aBallInfo->myDiameters[ iElem ] =
842 static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
845 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
846 aBallInfo->SetFamNum( iElem, famNum );
849 // store data in a file
850 myMed->SetBallInfo(aBallInfo);
855 // Treat standard types
856 // ---------------------
858 // allocate data arrays
859 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
860 aElemTypeData->_entity,
861 aElemTypeData->_geomType,
862 aElemTypeData->_nbElems,
866 // build map of family numbers for this type
867 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
869 //cout << " fillElemFamilyMap()" << endl;
870 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
871 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
874 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
875 elemIterator = myMesh->elementsIterator( aElemTypeData->_smdsType );
876 while ( elemIterator->more() )
878 const SMDS_MeshElement* anElem = elemIterator->next();
879 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
880 continue; // other geometry
883 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
884 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
885 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
886 #ifdef _EDF_NODE_IDS_
887 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
889 aTConnSlice[ iNode ] = aNode->GetID();
893 aCellInfo->SetElemNum( iElem, anElem->GetID() );
896 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
897 aCellInfo->SetFamNum( iElem, famNum );
899 if ( ++iElem == aCellInfo->GetNbElem() )
902 // store data in a file
903 myMed->SetCellInfo(aCellInfo);
906 } // loop on geom types
910 catch(const std::exception& exc) {
911 INFOS("The following exception was caught:\n\t"<<exc.what());
915 INFOS("Unknown exception was caught !!!");