rockydut
(Rockydut)
August 20, 2023, 5:16am
1
I am using vtkUnstructuredGrid to show mesh. I need to hide some cells(points) based on user input.
I do not want to delete cell. Just hide them temporary and make them visible later.
I know in vtkStructuredGrid, there is a funciton named BlankPoint/UnBlankPoint or BlankCell/UnBlankCell to show or hide the cell(points);
Any way to hide a cell in vtkUnstructuedGrid/vtkPolyData will be help a lot.
Hello,
I use vtkThreshold
to hide/show certain cells:
(...)
vtkSmartPointer<vtkIntArray> visibility = vtkSmartPointer<vtkIntArray>::New();
visibility->SetNumberOfComponents(1);
visibility->SetName("Visibility");
visibility->Allocate( nI * nJ );
for( int j = 0; j < nJ; ++j){
for( int i = 0; i < nI; ++i){
// visibility flag
if( cell_should_be_visible(i, j) )
visibility->InsertNextValue( 1 );
else
visibility->InsertNextValue( 0 );
}
}
(...)
unstructuredGrid->GetPointData()->SetScalars( data_values );
unstructuredGrid->GetPointData()->AddArray ( visibility );
(...)
// threshold to make vertexes with unvalued Z's invisible
vtkSmartPointer<vtkThreshold> threshold = vtkSmartPointer<vtkThreshold>::New();
threshold->SetInputData( unstructuredGrid );
threshold->SetUpperThreshold(1); // Criterion is cells whose scalars are greater or equal to threshold.
threshold->SetThresholdFunction( vtkThreshold::THRESHOLD_UPPER );
threshold->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, "Visibility");
threshold->Update();
// Create mapper (visualization parameters)
vtkSmartPointer<vtkDataSetMapper> mapper =
vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInputConnection( threshold->GetOutputPort() );
(...)
regards,
PC
To toggle visibility, just alternate the value passed to threshold->SetUpperThreshold()
between 1 and, say, 10 and update the scene.