# Wrong Volume after Clipping

**URL:** https://discourse.slicer.org/t/wrong-volume-after-clipping/11279
**Category:** Development
**Created:** [April 24, 2020, 2:52am UTC](https://discourse.slicer.org/t/wrong-volume-after-clipping/11279 "2020-04-24T02:52:03Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![siaeleni](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@siaeleni](https://discourse.slicer.org/u/siaeleni)
#### Post date: [April 24, 2020, 2:52am UTC](https://discourse.slicer.org/t/wrong-volume-after-clipping/11279/1 "2020-04-24T02:52:03Z")

</div>

Hi all,  
I am trying to clip a model and I expect to have a smaller volume after clipping.  
I use vtkClipPolyData and vtkImplicitBoolean for clipping (my own way).  
Green is the initial input and the blue is the cropped and I expect the volume to be smaller.  
As you can see in the image I created the segmentation for both and it seems that I compare the right things. But if you check the Volumes are not correct.

Could you help or give any workaround?  
Thanks

 ![pic3](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/b/2b93a2a6dc7621e4ad808e4bf48952bb3d46e1f3.jpeg)  
 ![pic4](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/3/234c69695ee89aa8fbaf16678dd8f8c82270a60f.jpeg)

---

<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: [April 24, 2020, 3:04am UTC](https://discourse.slicer.org/t/wrong-volume-after-clipping/11279/2 "2020-04-24T03:04:45Z")

</div>

Model volume can only be interpreted for closed surfaces. Are your models all closed surfaces?

Are the volumes correct if you import the models into a segmentation and compute the volume of the segment (using Segment Statistics module)?

---

<div class="post-metadata">

### Author: ![siaeleni](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@siaeleni](https://discourse.slicer.org/u/siaeleni)
#### Post date: [April 24, 2020, 3:33am UTC](https://discourse.slicer.org/t/wrong-volume-after-clipping/11279/3 "2020-04-24T03:33:57Z")

</div>

Thanks for your answer.

I used Segment Statistics Module and here are the results  
Seems that there is an issue with the “Cutter”. I tried to close it with the following way but I am not sure if that is the right way:

> segmentationNode.CreateClosedSurfaceRepresentation()

 ![pic5](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/d/0d097179121f97e01f2b0685be61a70fd76162ff.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: [April 24, 2020, 4:08am UTC](https://discourse.slicer.org/t/wrong-volume-after-clipping/11279/4 "2020-04-24T04:08:23Z")

</div>

I don’t know what results do you expect. Did Segment Statistics provide correct results?

It would help if you could upload the scene somewhere and post the link here so that I can have a look.

---

<div class="post-metadata">

### Author: ![siaeleni](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@siaeleni](https://discourse.slicer.org/u/siaeleni)
#### Post date: [April 24, 2020, 4:13am UTC](https://discourse.slicer.org/t/wrong-volume-after-clipping/11279/5 "2020-04-24T04:13:19Z")

</div>

I think I need the ones from Segment Statistics Column C and not Column F.  
How can I close the segmentation for the cutter model? I try

> segmentationNode.CreateClosedSurfaceRepresentation()

but it is not updating anything. But if I will try to close the surface from the “Segmentation” module works.  
Do I miss something in the code?

---

<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: [April 24, 2020, 4:21am UTC](https://discourse.slicer.org/t/wrong-volume-after-clipping/11279/6 "2020-04-24T04:21:31Z")

</div>

Segments in a segmentations node are always “closed”, regardless of what representations are used. Calling `CreateClosedSurfaceRepresentation()` just ensures that closed surface representation is present. Segment statistics computes volume from both labelmap and closed surface representations (you can find more details in the tooltip when you hover the mouse over the table).

If you want to recreate closed surface representation from labelmap representation then make labelmap the master representation and delete and create closed surface representation.

---

<div class="post-metadata">

### Author: ![siaeleni](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@siaeleni](https://discourse.slicer.org/u/siaeleni)
#### Post date: [April 24, 2020, 4:33am UTC](https://discourse.slicer.org/t/wrong-volume-after-clipping/11279/7 "2020-04-24T04:33:03Z")

</div>

Sure, I have uploaded these two files and I expect the cutter to have less Volume.

> **[Data](https://www.dropbox.com/sh/nyjcb2uall589du/AACuxDpoNByKpZPl_UZLxuPFa?dl=0)**
>
> Shared with Dropbox

Hope that helps,  
Thanks

---

<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: [April 24, 2020, 5:02am UTC](https://discourse.slicer.org/t/wrong-volume-after-clipping/11279/8 "2020-04-24T05:02:08Z")

</div>

I don’t know how did you close the surface but Segmentation module’s closed surface to labelmap importer closed it correctly, so I would recommend to use that.

---

<div class="post-metadata">

### Author: ![siaeleni](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@siaeleni](https://discourse.slicer.org/u/siaeleni)
#### Post date: [April 24, 2020, 1:59pm UTC](https://discourse.slicer.org/t/wrong-volume-after-clipping/11279/9 "2020-04-24T13:59:20Z")

</div>

I use the following code

```
> def export():
> segmentationNode = slicer.util.getNode("Cutter-segmentation")
> segmentationNode.CreateClosedSurfaceRepresentation()
> segmentation=segmentationNode.GetSegmentation()
> for segmentIndex in range(segmentation.GetNumberOfSegments()):
> segmentID = segmentation.GetNthSegmentID(segmentIndex)
> polydata = vtk.vtkPolyData()
> segmentationNode.GetClosedSurfaceRepresentation(segmentID, polydata)
> writer = vtk.vtkSTLWriter()
> writer.SetInputData(polydata)
> writer.SetFileName("D:/Cutter1.stl")
> writer.Update()

```

Do I miss something?

> **[Data](https://www.dropbox.com/sh/1xdr5y39x87pq6v/AABuchDT9MURWnO_EesygLiGa?dl=0)**
>
> Shared with Dropbox
