# Get Mesh Cell and Modify

**URL:** https://discourse.slicer.org/t/get-mesh-cell-and-modify/9459
**Category:** Support
**Tags:** visualization, 3d-model
**Created:** [December 10, 2019, 8:05am UTC](https://discourse.slicer.org/t/get-mesh-cell-and-modify/9459 "2019-12-10T08:05:39Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 10, 2019, 8:05am UTC](https://discourse.slicer.org/t/get-mesh-cell-and-modify/9459/1 "2019-12-10T08:05:39Z")

</div>

for mesh cell 1 …, end of mesh \<== executing all of the mesh

1. Get each mesh cell(below first picture) of all the mesh cells in the volume
2. Modify each cell value(color)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/f/3f8261af1125092ef1047c68237ecc5db9a2f6f2.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/f/7f3726fb1cd714404b3f747cc292cd5bc89b9657.jpeg)

referral script code^^

> modelNode = slicer.util.getNode(inputVolume.GetID())  
> m = modelNode.GetMesh()
> 
> ```auto
> trianglefilter = vtk.vtkTriangleFilter()
> 
> trianglefilter.SetInputData(m)
> trianglefilter.Update()
> 
> cellPointIds = vtk.vtkIdList()
> 
> trianglefilter.GetOutput().GetCellPoints(2978, cellPointIds)
> 
> for i in range(0,3):
> print(cellPointIds.GetId(i))
>     
> neighbourcells = vtk.vtkIdList()
> 
> idList = vtk.vtkIdList()
> idList.SetNumberOfIds(3)
> idList.SetId(0,1552)
> 
> ```

---

<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: [December 10, 2019, 8:05pm UTC](https://discourse.slicer.org/t/get-mesh-cell-and-modify/9459/2 "2019-12-10T20:05:47Z")

</div>

Let us know if you have any questions.

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 11, 2019, 12:17am UTC](https://discourse.slicer.org/t/get-mesh-cell-and-modify/9459/3 "2019-12-11T00:17:01Z")

</div>

I will do it by myself and let sample code shared in this page^^

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 15, 2019, 5:01am UTC](https://discourse.slicer.org/t/get-mesh-cell-and-modify/9459/4 "2019-12-15T05:01:16Z")

</div>

I found below when executing python script

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/5/6552df9ca578cc22a0e637545648f6ac377f4d0b.png)

[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: ![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: [December 15, 2019, 6:05am UTC](https://discourse.slicer.org/t/get-mesh-cell-and-modify/9459/5 "2019-12-15T06:05:11Z")

</div>

You have set a segmentation node into `modelNode` variable. As the name suggests, a model node is expected. You can create model nodes from segmentations by exporting segments to model nodes (this creates surface meshes) or by using Segment Mesher extension (this creates volumetric mesh).

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 16, 2019, 3:19am UTC](https://discourse.slicer.org/t/get-mesh-cell-and-modify/9459/6 "2019-12-16T03:19:05Z")

</div>

I did mesh from Segment Mesher^^

when i call modelNode.GetMesh()

> cellScalars = modelNode.GetMesh().GetCellData()

it seemed to be there’s no attribute ‘GetMesh’  
or python script can **find** ‘GetMesh’ function

---

<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: [December 16, 2019, 3:47pm UTC](https://discourse.slicer.org/t/get-mesh-cell-and-modify/9459/7 "2019-12-16T15:47:47Z")

</div>

You can run `print(modelNode)` in the Python console to see if the object is indeed a model node.

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 17, 2019, 4:49am UTC](https://discourse.slicer.org/t/get-mesh-cell-and-modify/9459/8 "2019-12-17T04:49:39Z")

</div>

> [@lassoan](#):
>
> print(modelNode)

I seemed to be real node

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/e/fe807c47e18ec3faf1b5ee011f658febc3a7a8ad.png)

---

<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: [December 19, 2019, 5:41pm UTC](https://discourse.slicer.org/t/get-mesh-cell-and-modify/9459/9 "2019-12-19T17:41:36Z")

</div>

“modelNode” is a vtkMRMLSegmentationNode, so it is _not_ a model node. Segmentation node is an input to model generators. You can create model nodes from segmentations by exporting segments to model nodes (this creates surface meshes) or by using Segment Mesher extension (this creates volumetric mesh).

---

<div class="post-metadata">

### Author: ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)
#### Post date: [December 20, 2019, 8:39pm UTC](https://discourse.slicer.org/t/get-mesh-cell-and-modify/9459/10 "2019-12-20T20:39:36Z")

</div>

Thanks Adras, I have time so now analysis all of the slicer source code for accumulated and structured knowledges. I think slicer has positive contribution to the medical imaging and communication (like DICOM Concept). Always thinking your slicer community member’s hard working and Voluntary commitment 🙂
