X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FOBJECT%2FSMESH_Object.cxx;h=96b25c9b99e95134faa13b0e26c0c82c2516fff8;hp=c12d63bfa68c6d733b7632f80495b6a7da527ed3;hb=20c126bc220757c06b5576f71ed6f34ae85e3e40;hpb=6665afd414e242331517f0e0c80b0896371facfb diff --git a/src/OBJECT/SMESH_Object.cxx b/src/OBJECT/SMESH_Object.cxx index c12d63bfa..96b25c9b9 100644 --- a/src/OBJECT/SMESH_Object.cxx +++ b/src/OBJECT/SMESH_Object.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -82,13 +82,14 @@ static int MYDEBUGWITHFILES = 0; // purpose : Get type of VTK cell //================================================================================= static inline vtkIdType getCellType( const SMDSAbs_ElementType theType, - const bool thePoly, - const int theNbNodes ) + const bool thePoly, + const int theNbNodes ) { switch( theType ) { - case SMDSAbs_0DElement: - return VTK_VERTEX; + case SMDSAbs_0DElement: return VTK_VERTEX; + + case SMDSAbs_Ball: return VTK_POLY_VERTEX; case SMDSAbs_Edge: if( theNbNodes == 2 ) return VTK_LINE; @@ -101,6 +102,7 @@ static inline vtkIdType getCellType( const SMDSAbs_ElementType theType, else if ( theNbNodes == 4 ) return VTK_QUAD; else if ( theNbNodes == 6 ) return VTK_QUADRATIC_TRIANGLE; else if ( theNbNodes == 8 ) return VTK_QUADRATIC_QUAD; + else if ( theNbNodes == 9 ) return VTK_BIQUADRATIC_QUAD; else return VTK_EMPTY_CELL; case SMDSAbs_Volume: @@ -109,18 +111,12 @@ static inline vtkIdType getCellType( const SMDSAbs_ElementType theType, else if ( theNbNodes == 5 ) return VTK_PYRAMID; else if ( theNbNodes == 6 ) return VTK_WEDGE; else if ( theNbNodes == 8 ) return VTK_HEXAHEDRON; - else if ( theNbNodes == 10 ) { - return VTK_QUADRATIC_TETRA; - } - else if ( theNbNodes == 20 ) { - return VTK_QUADRATIC_HEXAHEDRON; - } - else if ( theNbNodes == 15 ) { - return VTK_QUADRATIC_WEDGE; - } - else if ( theNbNodes==13 ) { - return VTK_QUADRATIC_PYRAMID; //VTK_CONVEX_POINT_SET; - } + else if ( theNbNodes == 12 ) return VTK_HEXAGONAL_PRISM; + else if ( theNbNodes == 10 ) return VTK_QUADRATIC_TETRA; + else if ( theNbNodes == 20 ) return VTK_QUADRATIC_HEXAHEDRON; + else if ( theNbNodes == 27 ) return VTK_TRIQUADRATIC_HEXAHEDRON; + else if ( theNbNodes == 15 ) return VTK_QUADRATIC_WEDGE; + else if ( theNbNodes == 13 ) return VTK_QUADRATIC_PYRAMID; //VTK_CONVEX_POINT_SET; else return VTK_EMPTY_CELL; default: return VTK_EMPTY_CELL; @@ -277,7 +273,7 @@ void SMESH_VisualObjDef::buildPrs(bool buildGrid) GetMesh()->compactMesh(); } vtkUnstructuredGrid *theGrid = GetMesh()->getGrid(); - updateEntitiesFlags(); + updateEntitiesFlags(); myGrid->ShallowCopy(theGrid); //MESSAGE(myGrid->GetReferenceCount()); //MESSAGE( "Update - myGrid->GetNumberOfCells() = "<GetNumberOfCells() ); @@ -349,52 +345,54 @@ void SMESH_VisualObjDef::buildElemPrs() // Calculate cells size - static SMDSAbs_ElementType aTypes[ 4 ] = - { SMDSAbs_0DElement, SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume }; + const int nbTypes = 5; + static SMDSAbs_ElementType aTypes[ nbTypes ] = + { SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume, SMDSAbs_Ball, SMDSAbs_0DElement }; // get entity data map nbEnts; map anEnts; - for ( int i = 0; i <= 3; i++ ) - nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] ); + vtkIdType aNbCells = 0; + for ( int i = 0; i < nbTypes; i++ ) + { + nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ aTypes[ i ] ] ); + aNbCells += nbEnts[ aTypes [ i ]]; + } // PAL16631: without swap, bad_alloc is not thrown but hung up and crash instead, // so check remaining memory size for safety SMDS_Mesh::CheckMemory(); // PAL16631 vtkIdType aCellsSize = 2 * nbEnts[ SMDSAbs_0DElement ] + 3 * nbEnts[ SMDSAbs_Edge ]; + aCellsSize += 2 * nbEnts[ SMDSAbs_Ball ]; - for ( int i = 2; i <= 3; i++ ) // iterate through faces and volumes + for ( int i = 1; i <= 2; i++ ) // iterate through faces and volumes { if ( nbEnts[ aTypes[ i ] ] ) { const TEntityList& aList = anEnts[ aTypes[ i ] ]; TEntityList::const_iterator anIter; for ( anIter = aList.begin(); anIter != aList.end(); ++anIter ) { - if((*anIter)->GetEntityType() != SMDSEntity_Polyhedra && - (*anIter)->GetEntityType() != SMDSEntity_Quad_Polyhedra) { - aCellsSize += (*anIter)->NbNodes() + 1; - } - // Special case for the VTK_POLYHEDRON: - // itsinput cellArray is of special format. - // [nCellFaces, nFace0Pts, i, j, k, nFace1Pts, i, j, k, ...] - else { - if( const SMDS_VtkVolume* ph = dynamic_cast(*anIter) ) { - int nbFaces = ph->NbFaces(); - aCellsSize += (1 + ph->NbFaces()); - for( int i = 1; i <= nbFaces; i++ ) { - aCellsSize += ph->NbFaceNodes(i); - } - } - } + if((*anIter)->GetEntityType() != SMDSEntity_Polyhedra && + (*anIter)->GetEntityType() != SMDSEntity_Quad_Polyhedra) { + aCellsSize += (*anIter)->NbNodes() + 1; + } + // Special case for the VTK_POLYHEDRON: + // itsinput cellArray is of special format. + // [nCellFaces, nFace0Pts, i, j, k, nFace1Pts, i, j, k, ...] + else { + if( const SMDS_VtkVolume* ph = dynamic_cast(*anIter) ) { + int nbFaces = ph->NbFaces(); + aCellsSize += (1 + ph->NbFaces()); + for( int i = 1; i <= nbFaces; i++ ) { + aCellsSize += ph->NbFaceNodes(i); + } + } + } } } } - - vtkIdType aNbCells = nbEnts[ SMDSAbs_0DElement ] + nbEnts[ SMDSAbs_Edge ] + - nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ]; - if ( MYDEBUG ) MESSAGE( "Update - aNbCells = "<X()<<","<Y()<<","<Z()<<")"<IsPoly() && aNbNodes > 3)) { - if ( aConnect.empty() ) - GetConnect(aNodesIter,aConnect); - - if (aConnectivities.size() > 0) { - 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()] ); + const std::vector& aConnectivities = + SMDS_MeshCell::toVtkOrder( VTKCellType( vtkElemType )); + if (aConnectivities.size() > 0) { + aConnect.clear(); + GetConnect(aNodesIter,aConnect); + for (vtkIdType aNodeId = 0; aNodeId < aNbNodes; aNodeId++) + SetId(anIdList,mySMDS2VTKNodes,aConnect,aNodeId,aConnectivities[aNodeId]); + } + else { + 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( aType, anElem->IsPoly(), aNbNodes ) ); + aCellTypesArray->InsertNextValue( vtkElemType ); iElem++; } @@ -601,7 +552,7 @@ vtkUnstructuredGrid* SMESH_VisualObjDef::GetUnstructuredGrid() if ( !myLocalGrid && !GetMesh()->isCompacted() ) { GetMesh()->compactMesh(); - updateEntitiesFlags(); + updateEntitiesFlags(); vtkUnstructuredGrid *theGrid = GetMesh()->getGrid(); myGrid->ShallowCopy(theGrid); } @@ -616,11 +567,12 @@ vtkUnstructuredGrid* SMESH_VisualObjDef::GetUnstructuredGrid() bool SMESH_VisualObjDef::IsValid() const { //MESSAGE("SMESH_VisualObjDef::IsValid"); - return GetNbEntities(SMDSAbs_Node) > 0 || - GetNbEntities(SMDSAbs_0DElement) > 0 || - GetNbEntities(SMDSAbs_Edge) > 0 || - GetNbEntities(SMDSAbs_Face) > 0 || - GetNbEntities(SMDSAbs_Volume) > 0 ; + return ( GetNbEntities(SMDSAbs_0DElement) > 0 || + GetNbEntities(SMDSAbs_Ball ) > 0 || + GetNbEntities(SMDSAbs_Edge ) > 0 || + GetNbEntities(SMDSAbs_Face ) > 0 || + GetNbEntities(SMDSAbs_Volume ) > 0 || + GetNbEntities(SMDSAbs_Node ) > 0 ); } //================================================================================= @@ -629,29 +581,32 @@ bool SMESH_VisualObjDef::IsValid() const //================================================================================= void SMESH_VisualObjDef::updateEntitiesFlags() { - unsigned int tmp = myEntitiesState; - ClearEntitiesFlags(); + unsigned int tmp = myEntitiesState; + ClearEntitiesFlags(); + + map entities = SMESH::GetEntitiesFromObject(this); + - map entities = SMESH::GetEntitiesFromObject(this); - + if( myEntitiesCache[SMDSAbs_0DElement] != 0 || myEntitiesCache[SMDSAbs_0DElement] >= entities[SMDSAbs_0DElement] ) + myEntitiesState &= ~SMESH_Actor::e0DElements; - if( myEntitiesCache[SMDSAbs_0DElement] != 0 || myEntitiesCache[SMDSAbs_0DElement] >= entities[SMDSAbs_0DElement] ) - myEntitiesState &= ~SMESH_Actor::e0DElements; + if( myEntitiesCache[SMDSAbs_Ball] != 0 || myEntitiesCache[SMDSAbs_Ball] >= entities[SMDSAbs_Ball] ) + myEntitiesState &= ~SMESH_Actor::eBallElem; - if( myEntitiesCache[SMDSAbs_Edge] != 0 || myEntitiesCache[SMDSAbs_Edge] >= entities[SMDSAbs_Edge] ) - myEntitiesState &= ~SMESH_Actor::eEdges; + if( myEntitiesCache[SMDSAbs_Edge] != 0 || myEntitiesCache[SMDSAbs_Edge] >= entities[SMDSAbs_Edge] ) + myEntitiesState &= ~SMESH_Actor::eEdges; - if( myEntitiesCache[SMDSAbs_Face] != 0 || myEntitiesCache[SMDSAbs_Face] >= entities[SMDSAbs_Face] ) - myEntitiesState &= ~SMESH_Actor::eFaces; + if( myEntitiesCache[SMDSAbs_Face] != 0 || myEntitiesCache[SMDSAbs_Face] >= entities[SMDSAbs_Face] ) + myEntitiesState &= ~SMESH_Actor::eFaces; - if( myEntitiesCache[SMDSAbs_Volume] != 0 || myEntitiesCache[SMDSAbs_Volume] >= entities[SMDSAbs_Volume] ) - myEntitiesState &= ~SMESH_Actor::eVolumes; + if( myEntitiesCache[SMDSAbs_Volume] != 0 || myEntitiesCache[SMDSAbs_Volume] >= entities[SMDSAbs_Volume] ) + myEntitiesState &= ~SMESH_Actor::eVolumes; - if( tmp != myEntitiesState ) { - myEntitiesFlag = true; - } - - myEntitiesCache = entities; + if( tmp != myEntitiesState ) { + myEntitiesFlag = true; + } + + myEntitiesCache = entities; } //================================================================================= @@ -659,8 +614,8 @@ void SMESH_VisualObjDef::updateEntitiesFlags() { // purpose : Clear the entities flags //================================================================================= void SMESH_VisualObjDef::ClearEntitiesFlags() { - myEntitiesState = SMESH_Actor::eAllEntity; - myEntitiesFlag = false; + myEntitiesState = SMESH_Actor::eAllEntity; + myEntitiesFlag = false; } //================================================================================= @@ -668,7 +623,7 @@ void SMESH_VisualObjDef::ClearEntitiesFlags() { // purpose : Return the entities flag //================================================================================= bool SMESH_VisualObjDef::GetEntitiesFlag() { - return myEntitiesFlag; + return myEntitiesFlag; } //================================================================================= @@ -676,7 +631,7 @@ bool SMESH_VisualObjDef::GetEntitiesFlag() { // purpose : Return the entities state //================================================================================= unsigned int SMESH_VisualObjDef::GetEntitiesState() { - return myEntitiesState; + return myEntitiesState; } /* @@ -704,6 +659,8 @@ SMESH_MeshObj::~SMESH_MeshObj() { if ( MYDEBUG ) MESSAGE("SMESH_MeshObj - this = "<Delete(); } //================================================================================= @@ -753,6 +710,7 @@ int SMESH_MeshObj::GetElemDimension( const int theObjId ) switch ( aType ) { case SMDSAbs_0DElement : return 0; + case SMDSAbs_Ball : return 0; case SMDSAbs_Edge : return 1; case SMDSAbs_Face : return 2; case SMDSAbs_Volume: return 3; @@ -777,6 +735,10 @@ int SMESH_MeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const { return myClient->Nb0DElements(); } + case SMDSAbs_Ball: + { + return myClient->NbBalls(); + } break; case SMDSAbs_Edge: { @@ -813,7 +775,13 @@ int SMESH_MeshObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& break; case SMDSAbs_0DElement: { - SMDS_0DElementIteratorPtr anIter = myClient->elements0dIterator(); + SMDS_ElemIteratorPtr anIter = myClient->elementsIterator(SMDSAbs_0DElement); + while ( anIter->more() ) theObjs.push_back( anIter->next() ); + } + break; + case SMDSAbs_Ball: + { + SMDS_ElemIteratorPtr anIter = myClient->elementGeomIterator(SMDSGeom_BALL); while ( anIter->more() ) theObjs.push_back( anIter->next() ); } break; @@ -857,7 +825,7 @@ void SMESH_MeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor //================================================================================= bool SMESH_MeshObj::IsNodePrs() const { - return myClient->Nb0DElements() == 0 && myClient->NbEdges() == 0 && myClient->NbFaces() == 0 && myClient->NbVolumes() == 0 ; + return myClient->Nb0DElements() + myClient->NbEdges() + myClient->NbFaces() + myClient->NbVolumes() + myClient->NbBalls() == 0 ; } @@ -894,6 +862,7 @@ int SMESH_SubMeshObj::GetElemDimension( const int theObjId ) // function : UpdateFunctor // purpose : Update functor in accordance with current mesh //================================================================================= + void SMESH_SubMeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunctor ) { theFunctor->SetMesh( myMeshObj->GetMesh() ); @@ -905,7 +874,7 @@ void SMESH_SubMeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunc //================================================================================= bool SMESH_SubMeshObj::Update( int theIsClear ) { - MESSAGE("SMESH_SubMeshObj::Update " << this) + MESSAGE("SMESH_SubMeshObj::Update " << this) bool changed = myMeshObj->Update( theIsClear ); buildPrs(true); return changed; @@ -1014,9 +983,12 @@ static int getPointers( const SMDSAbs_ElementType theRequestType, //================================================================================= int SMESH_GroupObj::GetNbEntities( const SMDSAbs_ElementType theType) const { - if(SMDSAbs_ElementType(myGroupServer->GetType()) == theType){ + if(SMDSAbs_ElementType(myGroupServer->GetType()) == theType) { return myGroupServer->Size(); } + if ( theType == SMDSAbs_Node ) { + return myGroupServer->GetNumberOfNodes(); + } return 0; } @@ -1025,11 +997,16 @@ int SMESH_GroupObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& theResList.clear(); SMDS_Mesh* aMesh = myMeshObj->GetMesh(); - if ( myGroupServer->Size() == 0 || aMesh == 0 ) + if ( aMesh == 0 ) return 0; SMDSAbs_ElementType aGrpType = SMDSAbs_ElementType(myGroupServer->GetType()); + if ( aGrpType != theType && theType != SMDSAbs_Node ) + return 0; + SMESH::long_array_var anIds = myGroupServer->GetListOfID(); + if ( anIds->length() == 0 ) + return 0; if ( aGrpType == theType ) return getPointers( theType, anIds, aMesh, theResList ); @@ -1037,7 +1014,7 @@ int SMESH_GroupObj::GetEntities( const SMDSAbs_ElementType theType, TEntityList& return getNodesFromElems( anIds, aMesh, theResList ); else return 0; -} +} @@ -1076,9 +1053,10 @@ int SMESH_subMeshObj::GetNbEntities( const SMDSAbs_ElementType theType) const { case SMDSAbs_Node: { - return mySubMeshServer->GetNumberOfNodes( false ); + return mySubMeshServer->GetNumberOfNodes( /*all=*/true ); } break; + case SMDSAbs_Ball: case SMDSAbs_0DElement: case SMDSAbs_Edge: case SMDSAbs_Face: