X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FOBJECT%2FSMESH_Object.cxx;h=1566d3506345202bbbdd1c8d772f2caccd0cd32b;hp=58715e251e89a654ed3f4bfaa6c5337eaa10679c;hb=8c1dfe2d90664a70f4451f77af48c1cde5638b60;hpb=e3214b68d298250cb463df645aecb3d2fdd5627a diff --git a/src/OBJECT/SMESH_Object.cxx b/src/OBJECT/SMESH_Object.cxx index 58715e251..1566d3506 100644 --- a/src/OBJECT/SMESH_Object.cxx +++ b/src/OBJECT/SMESH_Object.cxx @@ -134,6 +134,7 @@ SMESH_VisualObjDef::SMESH_VisualObjDef() { MESSAGE("---------------------------------------------SMESH_VisualObjDef::SMESH_VisualObjDef"); myGrid = vtkUnstructuredGrid::New(); + myLocalGrid = false; } SMESH_VisualObjDef::~SMESH_VisualObjDef() { @@ -149,29 +150,41 @@ SMESH_VisualObjDef::~SMESH_VisualObjDef() //================================================================================= vtkIdType SMESH_VisualObjDef::GetNodeObjId( int theVTKID ) { -// TMapOfIds::const_iterator i = myVTK2SMDSNodes.find(theVTKID); -// return i == myVTK2SMDSNodes.end() ? -1 : i->second; + if (myLocalGrid) + { + TMapOfIds::const_iterator i = myVTK2SMDSNodes.find(theVTKID); + return i == myVTK2SMDSNodes.end() ? -1 : i->second; + } return theVTKID; } vtkIdType SMESH_VisualObjDef::GetNodeVTKId( int theObjID ) { -// TMapOfIds::const_iterator i = mySMDS2VTKNodes.find(theObjID); -// return i == mySMDS2VTKNodes.end() ? -1 : i->second; + if (myLocalGrid) + { + TMapOfIds::const_iterator i = mySMDS2VTKNodes.find(theObjID); + return i == mySMDS2VTKNodes.end() ? -1 : i->second; + } return theObjID; } vtkIdType SMESH_VisualObjDef::GetElemObjId( int theVTKID ) { -// TMapOfIds::const_iterator i = myVTK2SMDSElems.find(theVTKID); -// return i == myVTK2SMDSElems.end() ? -1 : i->second; + if (myLocalGrid) + { + TMapOfIds::const_iterator i = myVTK2SMDSElems.find(theVTKID); + return i == myVTK2SMDSElems.end() ? -1 : i->second; + } return this->GetMesh()->fromVtkToSmds(theVTKID); } vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID ) { -// TMapOfIds::const_iterator i = mySMDS2VTKElems.find(theObjID); -// return i == mySMDS2VTKElems.end() ? -1 : i->second; + if (myLocalGrid) + { + TMapOfIds::const_iterator i = mySMDS2VTKElems.find(theObjID); + return i == mySMDS2VTKElems.end() ? -1 : i->second; + } return this->GetMesh()->fromSmdsToVtk(theObjID); } @@ -179,72 +192,83 @@ vtkIdType SMESH_VisualObjDef::GetElemVTKId( int theObjID ) // function : SMESH_VisualObjDef::createPoints // purpose : Create points from nodes //================================================================================= +/*! fills a vtkPoints structure for a submesh. + * fills a std::list of SMDS_MeshElements*, then extract the points. + * fills also conversion id maps between SMDS and VTK. + */ +void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints ) +{ + if ( thePoints == 0 ) + return; -//void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints ) -//{ -// if ( thePoints == 0 ) -// return; -// -// TEntityList aNodes; -// vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes ); -// thePoints->SetNumberOfPoints( nbNodes ); -// -// int nbPoints = 0; -// -// TEntityList::const_iterator anIter; -// for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter ) -// { -// const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter); -// if ( aNode != 0 ) -// { -// thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() ); -// int anId = aNode->GetID(); -// mySMDS2VTKNodes.insert( TMapOfIds::value_type( anId, nbPoints ) ); -// myVTK2SMDSNodes.insert( TMapOfIds::value_type( nbPoints, anId ) ); -// nbPoints++; -// } -// } -// -// if ( nbPoints != nbNodes ) -// thePoints->SetNumberOfPoints( nbPoints ); -//} + TEntityList aNodes; + vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes ); + thePoints->SetNumberOfPoints( nbNodes ); + + int nbPoints = 0; + + TEntityList::const_iterator anIter; + for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter ) + { + const SMDS_MeshNode* aNode = ( const SMDS_MeshNode* )(*anIter); + if ( aNode != 0 ) + { + thePoints->SetPoint( nbPoints, aNode->X(), aNode->Y(), aNode->Z() ); + int anId = aNode->GetID(); + mySMDS2VTKNodes.insert( TMapOfIds::value_type( anId, nbPoints ) ); + myVTK2SMDSNodes.insert( TMapOfIds::value_type( nbPoints, anId ) ); + nbPoints++; + } + } + + if ( nbPoints != nbNodes ) + thePoints->SetNumberOfPoints( nbPoints ); +} //================================================================================= // function : buildPrs // purpose : create VTK cells( fill unstructured grid ) //================================================================================= -void SMESH_VisualObjDef::buildPrs() +void SMESH_VisualObjDef::buildPrs(bool buildGrid) { -// try -// { -// mySMDS2VTKNodes.clear(); -// myVTK2SMDSNodes.clear(); -// mySMDS2VTKElems.clear(); -// myVTK2SMDSElems.clear(); -// -// if ( IsNodePrs() ) -// buildNodePrs(); -// else -// buildElemPrs(); -// } -// catch(...) -// { -// mySMDS2VTKNodes.clear(); -// myVTK2SMDSNodes.clear(); -// mySMDS2VTKElems.clear(); -// myVTK2SMDSElems.clear(); -// -// myGrid->SetPoints( 0 ); -// myGrid->SetCells( 0, 0, 0 ); -// throw; -// } - MESSAGE("----------------------------------------------------------SMESH_VisualObjDef::buildPrs"); - vtkUnstructuredGrid *theGrid = GetMesh()->getGrid(); - myGrid->ShallowCopy(theGrid); - MESSAGE(myGrid->GetReferenceCount()); - MESSAGE( "Update - myGrid->GetNumberOfCells() = "<GetNumberOfCells() ); - MESSAGE( "Update - myGrid->GetNumberOfPoints() = "<GetNumberOfPoints() ); - if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"/tmp/buildPrs" ); + MESSAGE("----------------------------------------------------------SMESH_VisualObjDef::buildPrs " << buildGrid); + if (buildGrid) + { + myLocalGrid = true; + try + { + mySMDS2VTKNodes.clear(); + myVTK2SMDSNodes.clear(); + mySMDS2VTKElems.clear(); + myVTK2SMDSElems.clear(); + + if ( IsNodePrs() ) + buildNodePrs(); + else + buildElemPrs(); + } + catch(...) + { + mySMDS2VTKNodes.clear(); + myVTK2SMDSNodes.clear(); + mySMDS2VTKElems.clear(); + myVTK2SMDSElems.clear(); + + myGrid->SetPoints( 0 ); + myGrid->SetCells( 0, 0, 0 ); + throw; + } + } + else + { + myLocalGrid = false; + vtkUnstructuredGrid *theGrid = GetMesh()->getGrid(); + myGrid->ShallowCopy(theGrid); + MESSAGE(myGrid->GetReferenceCount()); + MESSAGE( "Update - myGrid->GetNumberOfCells() = "<GetNumberOfCells() ); + MESSAGE( "Update - myGrid->GetNumberOfPoints() = "<GetNumberOfPoints() ); + if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"/tmp/buildPrs" ); + } } //================================================================================= @@ -252,19 +276,19 @@ void SMESH_VisualObjDef::buildPrs() // purpose : create VTK cells for nodes //================================================================================= -//void SMESH_VisualObjDef::buildNodePrs() -//{ -// // 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 -// vtkPoints* aPoints = vtkPoints::New(); -// createPoints( aPoints ); -// SMDS_Mesh::CheckMemory(); -// myGrid->SetPoints( aPoints ); -// aPoints->Delete(); -// -// myGrid->SetCells( 0, 0, 0 ); -//} +void SMESH_VisualObjDef::buildNodePrs() +{ + // 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 + vtkPoints* aPoints = vtkPoints::New(); + createPoints( aPoints ); + // SMDS_Mesh::CheckMemory(); + myGrid->SetPoints( aPoints ); + aPoints->Delete(); + + myGrid->SetCells( 0, 0, 0 ); +} //================================================================================= // function : buildElemPrs @@ -296,199 +320,199 @@ namespace{ } -//void SMESH_VisualObjDef::buildElemPrs() -//{ -// // Create points -// -// vtkPoints* aPoints = vtkPoints::New(); -// createPoints( aPoints ); -// myGrid->SetPoints( aPoints ); -// aPoints->Delete(); -// -// if ( MYDEBUG ) -// MESSAGE("Update - myGrid->GetNumberOfPoints() = "<GetNumberOfPoints()); -// -// // Calculate cells size -// -// static SMDSAbs_ElementType aTypes[ 4 ] = -// { SMDSAbs_0DElement, SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume }; -// -// // get entity data -// map nbEnts; -// map anEnts; -// -// for ( int i = 0; i <= 3; i++ ) -// nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ 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 ]; -// -// for ( int i = 2; i <= 3; 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 ) -// aCellsSize += (*anIter)->NbNodes() + 1; -// } -// } -// -// vtkIdType aNbCells = nbEnts[ SMDSAbs_0DElement ] + nbEnts[ SMDSAbs_Edge ] + -// nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ]; -// -// if ( MYDEBUG ) -// MESSAGE( "Update - aNbCells = "<X()<<","<Y()<<","<Z()<<")"< 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()] ); -// } -// } -// -// aConnectivity->InsertNextCell( anIdList ); -// aCellTypesArray->InsertNextValue( getCellType( aType, anElem->IsPoly(), aNbNodes ) ); -// -// iElem++; -// } -// } -// SMDS_Mesh::CheckMemory(); // PAL16631 -// } -// -// // Insert cells in grid -// -// VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New(); -// aCellLocationsArray->SetNumberOfComponents( 1 ); -// aCellLocationsArray->SetNumberOfTuples( aNbCells ); -// -// SMDS_Mesh::CheckMemory(); // PAL16631 -// -// aConnectivity->InitTraversal(); -// for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) -// aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); -// -// myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); -// -// aCellLocationsArray->Delete(); -// aCellTypesArray->Delete(); -// aConnectivity->Delete(); -// anIdList->Delete(); -// -// SMDS_Mesh::CheckMemory(); // PAL16631 -//} +void SMESH_VisualObjDef::buildElemPrs() +{ + // Create points + + vtkPoints* aPoints = vtkPoints::New(); + createPoints( aPoints ); + myGrid->SetPoints( aPoints ); + aPoints->Delete(); + + if ( MYDEBUG ) + MESSAGE("Update - myGrid->GetNumberOfPoints() = "<GetNumberOfPoints()); + + // Calculate cells size + + static SMDSAbs_ElementType aTypes[ 4 ] = + { SMDSAbs_0DElement, SMDSAbs_Edge, SMDSAbs_Face, SMDSAbs_Volume }; + + // get entity data + map nbEnts; + map anEnts; + + for ( int i = 0; i <= 3; i++ ) + nbEnts[ aTypes[ i ] ] = GetEntities( aTypes[ i ], anEnts[ 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 ]; + + for ( int i = 2; i <= 3; 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 ) + aCellsSize += (*anIter)->NbNodes() + 1; + } + } + + vtkIdType aNbCells = nbEnts[ SMDSAbs_0DElement ] + nbEnts[ SMDSAbs_Edge ] + + nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ]; + + if ( MYDEBUG ) + MESSAGE( "Update - aNbCells = "<X()<<","<Y()<<","<Z()<<")"< 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()] ); + } + } + + aConnectivity->InsertNextCell( anIdList ); + aCellTypesArray->InsertNextValue( getCellType( aType, anElem->IsPoly(), aNbNodes ) ); + + iElem++; + } + } + // SMDS_Mesh::CheckMemory(); // PAL16631 + } + + // Insert cells in grid + + VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New(); + aCellLocationsArray->SetNumberOfComponents( 1 ); + aCellLocationsArray->SetNumberOfTuples( aNbCells ); + + // SMDS_Mesh::CheckMemory(); // PAL16631 + + aConnectivity->InitTraversal(); + for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) + aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); + + myGrid->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); + + aCellLocationsArray->Delete(); + aCellTypesArray->Delete(); + aConnectivity->Delete(); + anIdList->Delete(); + + // SMDS_Mesh::CheckMemory(); // PAL16631 +} //================================================================================= // function : GetEdgeNodes @@ -587,7 +611,7 @@ SMESH_MeshObj::~SMESH_MeshObj() bool SMESH_MeshObj::Update( int theIsClear ) { // Update SMDS_Mesh on client part - MESSAGE("SMESH_MeshObj::Update"); + MESSAGE("SMESH_MeshObj::Update " << this); if ( myClient.Update(theIsClear) || GetUnstructuredGrid()->GetNumberOfPoints()==0) { buildPrs(); // Fill unstructured grid return true; @@ -777,8 +801,9 @@ void SMESH_SubMeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunc //================================================================================= bool SMESH_SubMeshObj::Update( int theIsClear ) { + MESSAGE("SMESH_SubMeshObj::Update " << this) bool changed = myMeshObj->Update( theIsClear ); - buildPrs(); + buildPrs(true); return changed; }