From 078f30942314173968dae427b52da958e86a9964 Mon Sep 17 00:00:00 2001 From: apo Date: Wed, 29 Dec 2004 13:38:15 +0000 Subject: [PATCH] Fix on Bug PAL7358 SMESH : 3D mesh elements has bad orientation, material is outside --- src/OBJECT/SMESH_Object.cxx | 84 +++++++++++++++++++++++++++++++----- src/OBJECT/SMESH_ObjectDef.h | 4 +- 2 files changed, 75 insertions(+), 13 deletions(-) diff --git a/src/OBJECT/SMESH_Object.cxx b/src/OBJECT/SMESH_Object.cxx index c640f6764..4b43e56ac 100644 --- a/src/OBJECT/SMESH_Object.cxx +++ b/src/OBJECT/SMESH_Object.cxx @@ -438,6 +438,32 @@ void SMESH_VisualObjDef::buildNodePrs() // function : buildElemPrs // purpose : Create VTK cells for elements //================================================================================= + +namespace{ + typedef std::vector TConnect; + + int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter, + TConnect& theConnect) + { + theConnect.clear(); + for(; theNodesIter->more();) + theConnect.push_back(theNodesIter->next()); + return theConnect.size(); + } + + inline + void SetId(vtkIdList *theIdList, + const SMESH_VisualObjDef::TMapOfIds& theSMDS2VTKNodes, + const TConnect& theConnect, + int thePosition, + int theId) + { + theIdList->SetId(thePosition,theSMDS2VTKNodes.find(theConnect[theId]->GetID())->second); + } + +} + + void SMESH_VisualObjDef::buildElemPrs() { // Create points @@ -455,8 +481,8 @@ void SMESH_VisualObjDef::buildElemPrs() static SMDSAbs_ElementType aTypes[ 3 ] = { SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume }; // get entity data - map< int, int > nbEnts; - map< int, TEntityList > anEnts; + map nbEnts; + map anEnts; for ( int i = 0; i <= 2; i++ ) nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] ); @@ -490,12 +516,16 @@ void SMESH_VisualObjDef::buildElemPrs() vtkIdList *anIdList = vtkIdList::New(); vtkIdType iElem = 0; - + + TConnect aConnect; + aConnect.reserve(VTK_CELL_SIZE); + for ( int i = 0; i <= 2; i++ ) // iterate through edges, faces and volumes { if( nbEnts[ aTypes[ i ] ] > 0 ) { - const TEntityList& aList = anEnts[ aTypes[ i ] ]; + const SMDSAbs_ElementType& aType = aTypes[ i ]; + const TEntityList& aList = anEnts[ aType ]; TEntityList::const_iterator anIter; for ( anIter = aList.begin(); anIter != aList.end(); ++anIter ) { @@ -510,14 +540,48 @@ void SMESH_VisualObjDef::buildElemPrs() myVTK2SMDSElems.insert( TMapOfIds::value_type( iElem, anId ) ); SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator(); - for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ) - { - const SMDS_MeshElement* aNode = aNodesIter->next(); - anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] ); - } + switch(aType){ + case SMDSAbs_Volume:{ + int* aConnectivities = NULL; + GetConnect(aNodesIter,aConnect); + // Convertions connectivities from SMDS to VTK + switch(aNbNodes){ + case 4:{ + static int anIds[] = {0,2,1,3}; + aConnectivities = anIds; + break; + } + case 5:{ + static int anIds[] = {0,3,2,1,4}; + aConnectivities = anIds; + break; + } + case 6:{ + static int anIds[] = {0,1,2,3,4,5}; + aConnectivities = anIds; + break; + } + case 8:{ + static int anIds[] = {0,3,2,1,4,7,6,5}; + aConnectivities = anIds; + break; + }} + + if(aConnectivities) + for( vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++ ) + SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]); + + break; + } + default: + for( vtkIdType aNodeId = 0; aNodesIter->more(); aNodeId++ ){ + const SMDS_MeshElement* aNode = aNodesIter->next(); + anIdList->SetId( aNodeId, mySMDS2VTKNodes[aNode->GetID()] ); + } + } aConnectivity->InsertNextCell( anIdList ); - aCellTypesArray->InsertNextValue( getCellType( aTypes[ i ], aNbNodes ) ); + aCellTypesArray->InsertNextValue( getCellType( aType, aNbNodes ) ); iElem++; } diff --git a/src/OBJECT/SMESH_ObjectDef.h b/src/OBJECT/SMESH_ObjectDef.h index 16cda5518..14df168d7 100644 --- a/src/OBJECT/SMESH_ObjectDef.h +++ b/src/OBJECT/SMESH_ObjectDef.h @@ -53,12 +53,10 @@ class SMDS_MeshElement; */ class SMESH_VisualObjDef: public SMESH_VisualObj { -protected: - +public: typedef std::list TEntityList; typedef std::map TMapOfIds; -public: SMESH_VisualObjDef(); virtual ~SMESH_VisualObjDef(); -- 2.39.2