#endif
#ifdef _DEBUG_
-static int MYDEBUG = 0;
+static int MYDEBUG = 1;
static int MYDEBUGWITHFILES = 0;
#else
static int MYDEBUG = 0;
//=================================================================================
SMESH_VisualObjDef::SMESH_VisualObjDef()
{
+ MESSAGE("---------------------------------------------SMESH_VisualObjDef::SMESH_VisualObjDef");
myGrid = vtkUnstructuredGrid::New();
+ myLocalGrid = false;
}
SMESH_VisualObjDef::~SMESH_VisualObjDef()
{
- if ( MYDEBUG )
+ MESSAGE("---------------------------------------------SMESH_VisualObjDef::~SMESH_VisualObjDef");
+ //if ( MYDEBUG )
MESSAGE( "~SMESH_MeshObj - myGrid->GetReferenceCount() = " << myGrid->GetReferenceCount() );
myGrid->Delete();
}
//=================================================================================
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);
}
//=================================================================================
// 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 )
TEntityList aNodes;
vtkIdType nbNodes = GetEntities( SMDSAbs_Node, aNodes );
thePoints->SetNumberOfPoints( nbNodes );
-
+
int nbPoints = 0;
TEntityList::const_iterator anIter;
// function : buildPrs
// purpose : create VTK cells( fill unstructured grid )
//=================================================================================
-void SMESH_VisualObjDef::buildPrs()
+void SMESH_VisualObjDef::buildPrs(bool buildGrid)
{
- try
+ MESSAGE("----------------------------------------------------------SMESH_VisualObjDef::buildPrs " << buildGrid);
+ if (buildGrid)
{
- mySMDS2VTKNodes.clear();
- myVTK2SMDSNodes.clear();
- mySMDS2VTKElems.clear();
- myVTK2SMDSElems.clear();
-
- if ( IsNodePrs() )
- buildNodePrs();
- else
- buildElemPrs();
+ 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;
+ }
}
- catch(...)
+ else
{
- mySMDS2VTKNodes.clear();
- myVTK2SMDSNodes.clear();
- mySMDS2VTKElems.clear();
- myVTK2SMDSElems.clear();
-
- myGrid->SetPoints( 0 );
- myGrid->SetCells( 0, 0, 0 );
- throw;
+ myLocalGrid = false;
+ vtkUnstructuredGrid *theGrid = GetMesh()->getGrid();
+ myGrid->ShallowCopy(theGrid);
+ MESSAGE(myGrid->GetReferenceCount());
+ MESSAGE( "Update - myGrid->GetNumberOfCells() = "<<myGrid->GetNumberOfCells() );
+ MESSAGE( "Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints() );
+ if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"/tmp/buildPrs" );
}
-
- if( MYDEBUG ) MESSAGE( "Update - myGrid->GetNumberOfCells() = "<<myGrid->GetNumberOfCells() );
- if( MYDEBUGWITHFILES ) SMESH::WriteUnstructuredGrid( myGrid,"/tmp/buildPrs" );
}
//=================================================================================
// function : buildNodePrs
// 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
+ // SMDS_Mesh::CheckMemory(); // PAL16631
vtkPoints* aPoints = vtkPoints::New();
createPoints( aPoints );
- SMDS_Mesh::CheckMemory();
+ // SMDS_Mesh::CheckMemory();
myGrid->SetPoints( aPoints );
aPoints->Delete();
void SMESH_VisualObjDef::buildElemPrs()
{
// Create points
-
+
vtkPoints* aPoints = vtkPoints::New();
createPoints( aPoints );
myGrid->SetPoints( aPoints );
aPoints->Delete();
-
+
if ( MYDEBUG )
MESSAGE("Update - myGrid->GetNumberOfPoints() = "<<myGrid->GetNumberOfPoints());
// 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
+ // SMDS_Mesh::CheckMemory(); // PAL16631
vtkIdType aCellsSize = 2 * nbEnts[ SMDSAbs_0DElement ] + 3 * nbEnts[ SMDSAbs_Edge ];
vtkIdType aNbCells = nbEnts[ SMDSAbs_0DElement ] + nbEnts[ SMDSAbs_Edge ] +
nbEnts[ SMDSAbs_Face ] + nbEnts[ SMDSAbs_Volume ];
-
+
if ( MYDEBUG )
MESSAGE( "Update - aNbCells = "<<aNbCells<<"; aCellsSize = "<<aCellsSize );
vtkCellArray* aConnectivity = vtkCellArray::New();
aConnectivity->Allocate( aCellsSize, 0 );
- SMDS_Mesh::CheckMemory(); // PAL16631
+ // SMDS_Mesh::CheckMemory(); // PAL16631
vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
aCellTypesArray->SetNumberOfComponents( 1 );
aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
- SMDS_Mesh::CheckMemory(); // PAL16631
+ // SMDS_Mesh::CheckMemory(); // PAL16631
vtkIdList *anIdList = vtkIdList::New();
vtkIdType iElem = 0;
TConnect aConnect;
aConnect.reserve(VTK_CELL_SIZE);
- SMDS_Mesh::CheckMemory(); // PAL16631
+ // SMDS_Mesh::CheckMemory(); // PAL16631
for ( int i = 0; i <= 3; i++ ) // iterate through 0d elements, edges, faces and volumes
{
iElem++;
}
}
- SMDS_Mesh::CheckMemory(); // PAL16631
+ // SMDS_Mesh::CheckMemory(); // PAL16631
}
// Insert cells in grid
-
+
VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
aCellLocationsArray->SetNumberOfComponents( 1 );
aCellLocationsArray->SetNumberOfTuples( aNbCells );
-
- SMDS_Mesh::CheckMemory(); // PAL16631
+
+ // 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
+ // SMDS_Mesh::CheckMemory(); // PAL16631
}
//=================================================================================
return true;
}
+vtkUnstructuredGrid* SMESH_VisualObjDef::GetUnstructuredGrid()
+{
+ MESSAGE("SMESH_VisualObjDef::GetUnstructuredGrid " << myGrid);
+ return myGrid;
+}
+
+
//=================================================================================
// function : IsValid
// purpose : Return true if there are some entities
//=================================================================================
bool SMESH_VisualObjDef::IsValid() const
{
+ MESSAGE("SMESH_VisualObjDef::IsValid");
return GetNbEntities(SMDSAbs_Node) > 0 ||
GetNbEntities(SMDSAbs_0DElement) > 0 ||
GetNbEntities(SMDSAbs_Edge) > 0 ||
SMESH_MeshObj::SMESH_MeshObj(SMESH::SMESH_Mesh_ptr theMesh):
myClient(SalomeApp_Application::orb(),theMesh)
{
+ myEmptyGrid = 0;
if ( MYDEBUG )
MESSAGE("SMESH_MeshObj - this = "<<this<<"; theMesh->_is_nil() = "<<theMesh->_is_nil());
}
bool SMESH_MeshObj::Update( int theIsClear )
{
// Update SMDS_Mesh on client part
+ MESSAGE("SMESH_MeshObj::Update " << this);
if ( myClient.Update(theIsClear) || GetUnstructuredGrid()->GetNumberOfPoints()==0) {
buildPrs(); // Fill unstructured grid
return true;
return false;
}
+bool SMESH_MeshObj::NulData()
+{
+ MESSAGE ("SMESH_MeshObj::NulData() ==================================================================================");
+ if (!myEmptyGrid)
+ {
+ myEmptyGrid = SMDS_UnstructuredGrid::New();
+ myEmptyGrid->Initialize();
+ myEmptyGrid->Allocate();
+ vtkPoints* points = vtkPoints::New();
+ points->SetNumberOfPoints(0);
+ myEmptyGrid->SetPoints( points );
+ points->Delete();
+ myEmptyGrid->BuildLinks();
+ }
+ myGrid->ShallowCopy(myEmptyGrid);
+}
//=================================================================================
// function : GetElemDimension
// purpose : Get dimension of element
//=================================================================================
bool SMESH_SubMeshObj::Update( int theIsClear )
{
+ MESSAGE("SMESH_SubMeshObj::Update " << this)
bool changed = myMeshObj->Update( theIsClear );
- buildPrs();
+ buildPrs(true);
return changed;
}