# Hide cell or point in vtkunstructuredgrid

**URL:** https://discourse.vtk.org/t/hide-cell-or-point-in-vtkunstructuredgrid/12169
**Category:** Support
**Tags:** code, proposal
**Created:** [August 20, 2023, 5:16am UTC](https://discourse.vtk.org/t/hide-cell-or-point-in-vtkunstructuredgrid/12169 "2023-08-20T05:16:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rockydut](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rockydut/32/4261_2.png) [@rockydut](https://discourse.vtk.org/u/rockydut)
#### Post date: [August 20, 2023, 5:16am UTC](https://discourse.vtk.org/t/hide-cell-or-point-in-vtkunstructuredgrid/12169/1 "2023-08-20T05:16:08Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 21, 2023, 7:11pm UTC](https://discourse.vtk.org/t/hide-cell-or-point-in-vtkunstructuredgrid/12169/2 "2023-08-21T19:11:07Z")

</div>

Hello,

I use `vtkThreshold` to hide/show certain cells:

```cpp
    (...)

    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

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 21, 2023, 7:14pm UTC](https://discourse.vtk.org/t/hide-cell-or-point-in-vtkunstructuredgrid/12169/3 "2023-08-21T19:14:16Z")

</div>

To toggle visibility, just alternate the value passed to `threshold->SetUpperThreshold()` between 1 and, say, 10 and update the scene.
