# How to select specific tetrahedron cells from mesh

**URL:** <https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716>\
**Category:** Development\
**Created:** [July 23, 2019, 3:44am UTC](https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716 "2019-07-23T03:44:21Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [July 23, 2019, 3:44am UTC](https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716/1 "2019-07-23T03:44:21Z")

</div>

If you have a mesh created from segmentmesher. how can you select the tetrahedron cells.

---

<div class="post-metadata">

**Author:** ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)\
**Post date:** [July 23, 2019, 12:41pm UTC](https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716/2 "2019-07-23T12:41:06Z")

</div>

With the mouse? By index? How do you want to select the cell?

---

<div class="post-metadata">

**Author:** ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)\
**Post date:** [July 23, 2019, 1:42pm UTC](https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716/3 "2019-07-23T13:42:04Z")

</div>

Two possible examples at the VTK level that might help are:

[https://lorensen.github.io/VTKExamples/site/Cxx/Picking/HighlightSelection/](https://lorensen.github.io/VTKExamples/site/Cxx/Picking/HighlightSelection/)  
[https://lorensen.github.io/VTKExamples/site/Cxx/Picking/HighlightSelectedPoints/](https://lorensen.github.io/VTKExamples/site/Cxx/Picking/HighlightSelectedPoints/)

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [July 24, 2019, 5:02am UTC](https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716/4 "2019-07-24T05:02:25Z")

</div>

how to select with the mouse in the slicer scene, selecting cells and then coloring it and then having those cells and their positions in a file

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 24, 2019, 1:14pm UTC](https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716/5 "2019-07-24T13:14:06Z")

</div>

You can use a picker to get cell IDs from mouse coordinates (see links that @adamrankin provided above). You can retrieve cell positions based on the IDs from the VTK mesh object. Add a cell array to your mesh and set different values for selected and non-selected cells. You can use this array to color the selected and non-selected cells differently.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [July 25, 2019, 8:28am UTC](https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716/6 "2019-07-25T08:28:07Z")

</div>

> [@lassoan](#):
>
> IDs from mouse coordina

how to interact with the 3d slice view of slicer. I have a mesh in 3d slice view. need to select some cells from it and change the colors of those selected cells.

I tried using the vtkcellpicker, but I dont understand the addobserver.

the addobserver of vtkcellpicker takes 2 arguments. first is the event and second is the method. Am I right?

Please help further. are there any examples related to slicer 3d view

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 25, 2019, 6:23pm UTC](https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716/7 "2019-07-25T18:23:51Z")

</div>

This example should do most of what you need:

[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get\_scalar\_values\_at\_surface\_of\_a\_model](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_scalar_values_at_surface_of_a_model)

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [February 9, 2021, 9:56pm UTC](https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716/8 "2021-02-09T21:56:16Z")

</div>

Hi andras,  
How to select tetrahedrons in a mesh using another mesh through a python script.

Thank you

Regards,  
Saima safdar

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 10, 2021, 2:22am UTC](https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716/9 "2021-02-10T02:22:06Z")

</div>

You can follow this example: [Documentation/Nightly/ScriptRepository - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Select_cells_of_a_model_using_markups_fiducial_points)

In a volumetric mesh, cells are tetrahedra, so probably the code will work without modification.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [February 23, 2021, 6:51am UTC](https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716/10 "2021-02-23T06:51:21Z")

</div>

Hi Andras,  
After selecting tetrahedrons. How to remove the selected tetrahedrons and have the unstructured grid remain without those deleted ones. example removing tumore cells from the brain mesh. how to retain the brain geometry.

regards,  
Saima Safdar

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 23, 2021, 1:10pm UTC](https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716/11 "2021-02-23T13:10:39Z")

</div>

You can either use vtkThreshold (cells that need to be deleted are identified by the value of a designated cell data array) or vtkExtractCells (cells that need to be deleted are identified by a cell ID list).

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [February 25, 2021, 6:30am UTC](https://discourse.slicer.org/t/how-to-select-specific-tetrahedron-cells-from-mesh/7716/12 "2021-02-25T06:30:21Z")

</div>

Hi Andras,  
Could you please see the post

> [@Select nearest neighbour voxels using some voxels as reference?](https://discourse.slicer.org/t/select-nearest-neighbour-voxels-using-some-voxels-as-reference/16175):
>
> Hi, Is there a possibility to select nearest neighbor voxels in an MRI based on the label-map. For-example I have the voxels based on some label. then I need to find nearest neighbour voxels that dont belong to voxels identified through label. I found this import numpy volume = array(‘Volume’) label = array(‘Volume-label’) points = numpy.where( label == 1 ) # or use another label number depending on what you segmented values = volume[points] # this will be a list of the label values v…

I created it seperately as I could not find any thing related to it on the forum.

Thank you

Regards,  
Saima Safdar
