1 // Copyright (C) 2007-2010 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.
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
29 #include "DriverMED_W_SMESHDS_Mesh.h"
30 #include "DriverMED_W_SMDS_Mesh.h"
31 #include "DriverMED_Family.h"
33 #include "SMESHDS_Mesh.hxx"
34 #include "SMDS_MeshElement.hxx"
35 #include "SMDS_MeshNode.hxx"
36 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
38 #include "utilities.h"
40 #include "MED_Utilities.hxx"
42 #define _EDF_NODE_IDS_
43 //#define _ELEMENTS_BY_DIM_
49 DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
50 myAllSubMeshes (false),
51 myDoGroupOfNodes (false),
52 myDoGroupOfEdges (false),
53 myDoGroupOfFaces (false),
54 myDoGroupOfVolumes (false)
57 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
60 myMed = CrWrapper(theFileName,theId);
61 Driver_SMESHDS_Mesh::SetFile(theFileName);
64 void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName)
66 return SetFile(theFileName,MED::eV2_2);
69 string DriverMED_W_SMESHDS_Mesh::GetVersionString(const MED::EVersion theVersion, int theNbDigits)
71 TInt majeur, mineur, release;
72 majeur = mineur = release = 0;
73 // if ( theVersion == eV2_1 )
74 // MED::GetVersionRelease<eV2_1>(majeur, mineur, release);
76 MED::GetVersionRelease<eV2_2>(majeur, mineur, release);
78 if ( theNbDigits > 0 )
80 if ( theNbDigits > 1 )
81 name << "." << mineur;
82 if ( theNbDigits > 2 )
83 name << "." << release;
87 void DriverMED_W_SMESHDS_Mesh::SetMeshName(const std::string& theMeshName)
89 myMeshName = theMeshName;
92 void DriverMED_W_SMESHDS_Mesh::AddGroup(SMESHDS_GroupBase* theGroup)
94 myGroups.push_back(theGroup);
97 void DriverMED_W_SMESHDS_Mesh::AddAllSubMeshes()
99 myAllSubMeshes = true;
102 void DriverMED_W_SMESHDS_Mesh::AddSubMesh(SMESHDS_SubMesh* theSubMesh, int theID)
104 mySubMeshes[theID] = theSubMesh;
107 void DriverMED_W_SMESHDS_Mesh::AddGroupOfNodes()
109 myDoGroupOfNodes = true;
112 void DriverMED_W_SMESHDS_Mesh::AddGroupOfEdges()
114 myDoGroupOfEdges = true;
117 void DriverMED_W_SMESHDS_Mesh::AddGroupOfFaces()
119 myDoGroupOfFaces = true;
122 void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
124 myDoGroupOfVolumes = true;
128 typedef double (SMDS_MeshNode::* TGetCoord)() const;
129 typedef const char* TName;
130 typedef const char* TUnit;
132 // name length in a mesh must be equal to 16 :
139 TUnit aUnit[3] = {M,M,M};
142 TGetCoord aXYZGetCoord[3] = {
147 TName aXYZName[3] = {X,Y,Z};
150 TGetCoord aXYGetCoord[2] = {
154 TName aXYName[2] = {X,Y};
156 TGetCoord aYZGetCoord[2] = {
160 TName aYZName[2] = {Y,Z};
162 TGetCoord aXZGetCoord[2] = {
166 TName aXZName[2] = {X,Z};
169 TGetCoord aXGetCoord[1] = {
172 TName aXName[1] = {X};
174 TGetCoord aYGetCoord[1] = {
177 TName aYName[1] = {Y};
179 TGetCoord aZGetCoord[1] = {
182 TName aZName[1] = {Z};
186 SMDS_NodeIteratorPtr myNodeIter;
187 const SMDS_MeshNode* myCurrentNode;
188 TGetCoord* myGetCoord;
192 TCoordHelper(const SMDS_NodeIteratorPtr& theNodeIter,
193 TGetCoord* theGetCoord,
195 TUnit* theUnit = aUnit):
196 myNodeIter(theNodeIter),
197 myGetCoord(theGetCoord),
201 virtual ~TCoordHelper(){}
203 return myNodeIter->more() &&
204 (myCurrentNode = myNodeIter->next());
206 const SMDS_MeshNode* GetNode(){
207 return myCurrentNode;
209 MED::TIntVector::value_type GetID(){
210 return myCurrentNode->GetID();
212 MED::TFloatVector::value_type GetCoord(TInt theCoodId){
213 return (myCurrentNode->*myGetCoord[theCoodId])();
215 MED::TStringVector::value_type GetName(TInt theDimId){
216 return myName[theDimId];
218 MED::TStringVector::value_type GetUnit(TInt theDimId){
219 return myUnit[theDimId];
222 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
225 //-------------------------------------------------------
227 * \brief Class helping to use either SMDS_0DElementIterator,
228 * SMDS_EdgeIterator, SMDS_FaceIterator or SMDS_VolumeIterator
231 //-------------------------------------------------------
234 virtual const SMDS_MeshElement* next() = 0;
235 virtual ~TElemIterator() {}
237 typedef boost::shared_ptr<TElemIterator> PElemIterator;
239 template< class SMDSIteratorPtr > class TypedElemIterator: public TElemIterator
241 SMDSIteratorPtr myItPtr;
243 TypedElemIterator(SMDSIteratorPtr it): myItPtr(it) {}
244 virtual const SMDS_MeshElement* next() {
245 if ( myItPtr->more() ) return myItPtr->next();
249 typedef TypedElemIterator< SMDS_0DElementIteratorPtr > T0DElementIterator;
250 typedef TypedElemIterator< SMDS_EdgeIteratorPtr > TEdgeIterator;
251 typedef TypedElemIterator< SMDS_FaceIteratorPtr > TFaceIterator;
252 typedef TypedElemIterator< SMDS_VolumeIteratorPtr > TVolumeIterator;
254 //-------------------------------------------------------
256 * \brief Structure describing element type
258 //-------------------------------------------------------
261 EEntiteMaillage _entity;
262 EGeometrieElement _geomType;
264 SMDSAbs_ElementType _smdsType;
266 TElemTypeData (EEntiteMaillage entity, EGeometrieElement geom, TInt nb, SMDSAbs_ElementType type)
267 : _entity(entity), _geomType(geom), _nbElems( nb ), _smdsType( type ) {}
271 typedef NCollection_DataMap< Standard_Address, int > TElemFamilyMap;
272 //typedef map<const SMDS_MeshElement *, int> TElemFamilyMap;
274 //================================================================================
276 * \brief Fills element to famaly ID map for element type.
277 * Removes all families of anElemType
279 //================================================================================
281 void fillElemFamilyMap( TElemFamilyMap & anElemFamMap,
282 list<DriverMED_FamilyPtr> & aFamilies,
283 const SMDSAbs_ElementType anElemType)
285 anElemFamMap.Clear();
286 //anElemFamMap.clear();
287 list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
288 while ( aFamsIter != aFamilies.end() )
290 if ((*aFamsIter)->GetType() != anElemType) {
294 int aFamId = (*aFamsIter)->GetId();
295 const set<const SMDS_MeshElement *>& anElems = (*aFamsIter)->GetElements();
296 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElems.begin();
297 for (; anElemsIter != anElems.end(); anElemsIter++)
299 anElemFamMap.Bind( (Standard_Address)*anElemsIter, aFamId );
300 //anElemFamMap[*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 );
320 // TElemFamilyMap::iterator elem_famNum = anElemFamMap.find( anElement );
321 // if ( elem_famNum != anElemFamMap.end() )
322 // return elem_famNum->second;
323 return aDefaultFamilyId;
327 Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
329 Status aResult = DRS_OK;
330 if (myMesh->hasConstructionEdges() || myMesh->hasConstructionFaces()) {
331 INFOS("SMDS_MESH with hasConstructionEdges() or hasConstructionFaces() do not supports!!!");
335 MESSAGE("Perform - myFile : "<<myFile);
337 // Creating the MED mesh for corresponding SMDS structure
338 //-------------------------------------------------------
340 if (myMeshId != -1) {
341 ostringstream aMeshNameStr;
342 aMeshNameStr<<myMeshId;
343 aMeshName = aMeshNameStr.str();
345 aMeshName = myMeshName;
348 // Mesh dimension definition
349 TInt aSpaceDimension;
350 TCoordHelperPtr aCoordHelperPtr;
352 bool anIsXDimension = false;
353 bool anIsYDimension = false;
354 bool anIsZDimension = false;
356 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
358 if(aNodesIter->more()){
359 const SMDS_MeshNode* aNode = aNodesIter->next();
360 aBounds[0] = aBounds[1] = aNode->X();
361 aBounds[2] = aBounds[3] = aNode->Y();
362 aBounds[4] = aBounds[5] = aNode->Z();
364 while(aNodesIter->more()){
365 const SMDS_MeshNode* aNode = aNodesIter->next();
366 aBounds[0] = min(aBounds[0],aNode->X());
367 aBounds[1] = max(aBounds[1],aNode->X());
369 aBounds[2] = min(aBounds[2],aNode->Y());
370 aBounds[3] = max(aBounds[3],aNode->Y());
372 aBounds[4] = min(aBounds[4],aNode->Z());
373 aBounds[5] = max(aBounds[5],aNode->Z());
377 anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
378 anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
379 anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
380 aSpaceDimension = anIsXDimension + anIsYDimension + anIsZDimension;
383 // PAL16857(SMESH not conform to the MED convention):
384 if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
386 // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
387 if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
388 if ( anIsYDimension ) {
390 anIsXDimension = true;
397 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
398 switch(aSpaceDimension){
400 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
403 if(anIsXDimension && anIsYDimension)
404 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
405 if(anIsYDimension && anIsZDimension)
406 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
407 if(anIsXDimension && anIsZDimension)
408 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
412 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
414 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
416 aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
420 TInt aMeshDimension = 0;
421 if ( myMesh->NbEdges() > 0 )
423 if ( myMesh->NbFaces() > 0 )
425 if ( myMesh->NbVolumes() > 0 )
428 PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
429 MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
430 myMed->SetMeshInfo(aMeshInfo);
432 // Storing SMDS groups and sub-meshes as med families
433 //----------------------------------------------------
434 int myNodesDefaultFamilyId = 0;
435 int my0DElementsDefaultFamilyId = 0;
436 int myEdgesDefaultFamilyId = 0;
437 int myFacesDefaultFamilyId = 0;
438 int myVolumesDefaultFamilyId = 0;
439 int nbNodes = myMesh->NbNodes();
440 //int nb0DElements = myMesh->Nb0DElements();
441 int nbEdges = myMesh->NbEdges();
442 int nbFaces = myMesh->NbFaces();
443 int nbVolumes = myMesh->NbVolumes();
444 if (myDoGroupOfNodes && nbNodes)
445 myNodesDefaultFamilyId = REST_NODES_FAMILY;
446 if (myDoGroupOfEdges && nbEdges)
447 myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
448 if (myDoGroupOfFaces && nbFaces)
449 myFacesDefaultFamilyId = REST_FACES_FAMILY;
450 if (myDoGroupOfVolumes && nbVolumes)
451 myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
453 MESSAGE("Perform - aFamilyInfo");
454 //cout << " DriverMED_Family::MakeFamilies() " << endl;
455 list<DriverMED_FamilyPtr> aFamilies;
456 if (myAllSubMeshes) {
457 aFamilies = DriverMED_Family::MakeFamilies
458 (myMesh->SubMeshes(), myGroups,
459 myDoGroupOfNodes && nbNodes,
460 myDoGroupOfEdges && nbEdges,
461 myDoGroupOfFaces && nbFaces,
462 myDoGroupOfVolumes && nbVolumes);
464 aFamilies = DriverMED_Family::MakeFamilies
465 (mySubMeshes, myGroups,
466 myDoGroupOfNodes && nbNodes,
467 myDoGroupOfEdges && nbEdges,
468 myDoGroupOfFaces && nbFaces,
469 myDoGroupOfVolumes && nbVolumes);
471 //cout << " myMed->SetFamilyInfo() " << endl;
472 list<DriverMED_FamilyPtr>::iterator aFamsIter;
473 for (aFamsIter = aFamilies.begin(); aFamsIter != aFamilies.end(); aFamsIter++)
475 PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
476 myMed->SetFamilyInfo(aFamilyInfo);
479 // Storing SMDS nodes to the MED file for the MED mesh
480 //----------------------------------------------------
481 #ifdef _EDF_NODE_IDS_
482 typedef map<TInt,TInt> TNodeIdMap;
483 TNodeIdMap aNodeIdMap;
485 const EModeSwitch theMode = eFULL_INTERLACE;
486 const ERepere theSystem = eCART;
487 const EBooleen theIsElemNum = eVRAI;
488 const EBooleen theIsElemNames = eFAUX;
489 const EConnectivite theConnMode = eNOD;
491 TInt aNbNodes = myMesh->NbNodes();
492 //cout << " myMed->CrNodeInfo() aNbNodes = " << aNbNodes << endl;
493 PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, aNbNodes,
494 theMode, theSystem, theIsElemNum, theIsElemNames);
496 //cout << " fillElemFamilyMap( SMDSAbs_Node )" << endl;
497 // find family numbers for nodes
498 TElemFamilyMap anElemFamMap;
499 fillElemFamilyMap( anElemFamMap, aFamilies, SMDSAbs_Node );
501 for (TInt iNode = 0; aCoordHelperPtr->Next(); iNode++)
504 TCoordSlice aTCoordSlice = aNodeInfo->GetCoordSlice( iNode );
505 for(TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++){
506 aTCoordSlice[iCoord] = aCoordHelperPtr->GetCoord(iCoord);
509 int aNodeID = aCoordHelperPtr->GetID();
510 aNodeInfo->SetElemNum( iNode, aNodeID );
511 #ifdef _EDF_NODE_IDS_
512 aNodeIdMap[aNodeID] = iNode+1;
515 const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
516 int famNum = getFamilyId( anElemFamMap, aNode, myNodesDefaultFamilyId );
517 aNodeInfo->SetFamNum( iNode, famNum );
519 anElemFamMap.Clear();
521 // coordinate names and units
522 for (TInt iCoord = 0; iCoord < aSpaceDimension; iCoord++) {
523 aNodeInfo->SetCoordName( iCoord, aCoordHelperPtr->GetName(iCoord));
524 aNodeInfo->SetCoordUnit( iCoord, aCoordHelperPtr->GetUnit(iCoord));
527 //cout << " SetNodeInfo(aNodeInfo)" << endl;
528 MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbNodes);
529 myMed->SetNodeInfo(aNodeInfo);
530 aNodeInfo.reset(); // free memory used for arrays
533 // Storing SMDS elements to the MED file for the MED mesh
534 //-------------------------------------------------------
535 // Write one element type at once in order to minimize memory usage (PAL19276)
537 const SMDS_MeshInfo& nbElemInfo = myMesh->GetMeshInfo();
539 // poly elements are not supported by med-2.1
540 bool polyTypesSupported = myMed->CrPolygoneInfo(aMeshInfo,eMAILLE,ePOLYGONE,0,0);
541 TInt nbPolygonNodes = 0, nbPolyhedronNodes = 0, nbPolyhedronFaces = 0;
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(),
555 #ifdef _ELEMENTS_BY_DIM_
558 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
560 nbElemInfo.NbEdges( ORDER_LINEAR ),
562 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
564 nbElemInfo.NbEdges( ORDER_QUADRATIC ),
566 #ifdef _ELEMENTS_BY_DIM_
569 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
571 nbElemInfo.NbTriangles( ORDER_LINEAR ),
573 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
575 nbElemInfo.NbTriangles( ORDER_QUADRATIC ),
577 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
579 nbElemInfo.NbQuadrangles( ORDER_LINEAR ),
581 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
583 nbElemInfo.NbQuadrangles( ORDER_QUADRATIC ),
585 if ( polyTypesSupported ) {
586 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
588 nbElemInfo.NbPolygons(),
590 // we need one more loop on poly elements to count nb of their nodes
591 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
593 nbElemInfo.NbPolygons(),
596 #ifdef _ELEMENTS_BY_DIM_
599 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
601 nbElemInfo.NbTetras( ORDER_LINEAR ),
603 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
605 nbElemInfo.NbTetras( ORDER_QUADRATIC ),
607 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
609 nbElemInfo.NbPyramids( ORDER_LINEAR ),
611 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
613 nbElemInfo.NbPyramids( ORDER_QUADRATIC ),
615 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
617 nbElemInfo.NbPrisms( ORDER_LINEAR ),
619 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
621 nbElemInfo.NbPrisms( ORDER_QUADRATIC ),
623 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
625 nbElemInfo.NbHexas( ORDER_LINEAR ),
627 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
629 nbElemInfo.NbHexas( ORDER_QUADRATIC ),
631 if ( polyTypesSupported ) {
632 //MESSAGE("polyTypesSupported");
633 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
635 nbElemInfo.NbPolyhedrons(),
637 // we need one more loop on poly elements to count nb of their nodes
638 aTElemTypeDatas.push_back( TElemTypeData(anEntity,
640 nbElemInfo.NbPolyhedrons(),
644 vector< bool > isElemFamMapBuilt( SMDSAbs_NbElementTypes, false );
646 // loop on all geom types of elements
648 list< TElemTypeData >::iterator aElemTypeData = aTElemTypeDatas.begin();
649 for ( ; aElemTypeData != aTElemTypeDatas.end(); ++aElemTypeData )
651 if ( aElemTypeData->_nbElems == 0 )
654 // iterator on elements of a current type
655 PElemIterator elemIterator;
656 int defaultFamilyId = 0;
657 switch ( aElemTypeData->_smdsType ) {
658 case SMDSAbs_0DElement:
659 elemIterator = PElemIterator( new T0DElementIterator( myMesh->elements0dIterator() ));
660 defaultFamilyId = my0DElementsDefaultFamilyId;
663 elemIterator = PElemIterator( new TEdgeIterator( myMesh->edgesIterator() ));
664 defaultFamilyId = myEdgesDefaultFamilyId;
667 elemIterator = PElemIterator( new TFaceIterator( myMesh->facesIterator() ));
668 defaultFamilyId = myFacesDefaultFamilyId;
671 elemIterator = PElemIterator( new TVolumeIterator( myMesh->volumesIterator() ));
672 defaultFamilyId = myVolumesDefaultFamilyId;
679 //cout << " Treat type " << aElemTypeData->_geomType << " nb = " <<aElemTypeData->_nbElems<< endl;
682 if ( aElemTypeData->_geomType == ePOLYGONE )
684 if ( nbPolygonNodes == 0 ) {
686 while ( const SMDS_MeshElement* anElem = elemIterator->next() ) {
687 if ( anElem->IsPoly() ) {
688 nbPolygonNodes += anElem->NbNodes();
689 if ( ++iElem == aElemTypeData->_nbElems )
696 PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
697 aElemTypeData->_entity,
698 aElemTypeData->_geomType,
699 aElemTypeData->_nbElems,
701 theConnMode, theIsElemNum,
703 TElemNum & index = *(aPolygoneInfo->myIndex.get());
706 while ( const SMDS_MeshElement* anElem = elemIterator->next() )
708 if ( !anElem->IsPoly() )
712 TInt aNbNodes = anElem->NbNodes();
713 index[ iElem+1 ] = index[ iElem ] + aNbNodes;
716 TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
717 for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
718 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
719 #ifdef _EDF_NODE_IDS_
720 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
722 aTConnSlice[ iNode ] = aNode->GetID();
726 aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
729 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
730 aPolygoneInfo->SetFamNum( iElem, famNum );
732 if ( ++iElem == aPolygoneInfo->GetNbElem() )
735 // if(TInt aNbElems = aPolygoneElemNums.size())
736 // // add one element in connectivities,
737 // // referenced by the last element in indices
738 // aPolygoneConn.push_back(0);
739 //cout << " SetPolygoneInfo(aPolygoneInfo)" << endl;
740 myMed->SetPolygoneInfo(aPolygoneInfo);
747 else if (aElemTypeData->_geomType == ePOLYEDRE )
749 //MESSAGE("_geomType == ePOLYEDRE");
750 if ( nbPolyhedronNodes == 0 ) {
752 while ( const SMDS_MeshElement* anElem = elemIterator->next() ) {
753 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
754 if ( aPolyedre && aPolyedre->IsPoly()) {
755 nbPolyhedronNodes += aPolyedre->NbNodes();
756 nbPolyhedronFaces += aPolyedre->NbFaces();
757 if ( ++iElem == aElemTypeData->_nbElems )
761 //MESSAGE("nbPolyhedronNodes=" << nbPolyhedronNodes);
762 //MESSAGE("nbPolyhedronFaces=" << nbPolyhedronFaces);
763 //MESSAGE("_nbElems="<< aElemTypeData->_nbElems);
767 PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
768 aElemTypeData->_entity,
769 aElemTypeData->_geomType,
770 aElemTypeData->_nbElems,
776 TElemNum & index = *(aPolyhInfo->myIndex.get());
777 TElemNum & faces = *(aPolyhInfo->myFaces.get());
778 TElemNum & conn = *(aPolyhInfo->myConn.get());
782 TInt iFace = 0, iNode = 0;
783 while ( const SMDS_MeshElement* anElem = elemIterator->next() )
785 const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
788 if ( !aPolyedre->IsPoly() )
790 //MESSAGE("index[" << iElem << "]=" << index[iElem] << " iElem=" << iElem);
792 TInt aNbFaces = aPolyedre->NbFaces();
793 index[ iElem+1 ] = index[ iElem ] + aNbFaces;
794 //MESSAGE("index[" << iElem+1 << "]=" << index[iElem+1] << " iElem=" << iElem);
797 for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
798 int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
799 faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
800 //MESSAGE("faces[" << iFace+1 << "]=" << faces[iFace+1] << " iFace=" << iFace);
803 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
804 while ( nodeIt->more() ) {
805 const SMDS_MeshElement* aNode = nodeIt->next();
806 #ifdef _EDF_NODE_IDS_
807 conn[ iNode ] = aNodeIdMap[aNode->GetID()];
808 //MESSAGE("conn["<< iNode << "]=" << conn[iNode] << " aNode->GetID()=" << aNode->GetID());
810 conn[ iNode ] = aNode->GetID();
811 //MESSAGE("conn["<< iNode << "]=" << conn[iNode]);
816 aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
819 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
820 aPolyhInfo->SetFamNum( iElem, famNum );
822 if ( ++iElem == aPolyhInfo->GetNbElem() )
825 //cout << " SetPolyedreInfo(aPolyhInfo )" << endl;
826 myMed->SetPolyedreInfo(aPolyhInfo);
828 } // if (aElemTypeData->_geomType == ePOLYEDRE )
832 // Treat standard types
833 // ---------------------
835 // allocate data arrays
836 PCellInfo aCellInfo = myMed->CrCellInfo( aMeshInfo,
837 aElemTypeData->_entity,
838 aElemTypeData->_geomType,
839 aElemTypeData->_nbElems,
843 // build map of family numbers for this type
844 if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
846 //cout << " fillElemFamilyMap()" << endl;
847 fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
848 isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
851 TInt aNbNodes = MED::GetNbNodes(aElemTypeData->_geomType);
852 while ( const SMDS_MeshElement* anElem = elemIterator->next() )
854 if ( anElem->NbNodes() != aNbNodes || anElem->IsPoly() )
855 continue; // other geometry
858 TConnSlice aTConnSlice = aCellInfo->GetConnSlice( iElem );
859 for (TInt iNode = 0; iNode < aNbNodes; iNode++) {
860 const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
861 #ifdef _EDF_NODE_IDS_
862 aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
864 aTConnSlice[ iNode ] = aNode->GetID();
868 aCellInfo->SetElemNum( iElem, anElem->GetID() );
871 int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
872 aCellInfo->SetFamNum( iElem, famNum );
874 if ( ++iElem == aCellInfo->GetNbElem() )
877 // store data in a file
878 //cout << " SetCellInfo(aCellInfo)" << endl;
879 myMed->SetCellInfo(aCellInfo);
882 } // loop on geom types
886 catch(const std::exception& exc) {
887 INFOS("The following exception was caught:\n\t"<<exc.what());
891 INFOS("Unknown exception was caught !!!");