# Slicer quit when using vtkStatisticalOutlierRemoval

**URL:** <https://discourse.slicer.org/t/slicer-quit-when-using-vtkstatisticaloutlierremoval/23381>\
**Category:** Support\
**Created:** [May 12, 2022, 2:09am UTC](https://discourse.slicer.org/t/slicer-quit-when-using-vtkstatisticaloutlierremoval/23381 "2022-05-12T02:09:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![efu98](https://avatars.discourse-cdn.com/v4/letter/e/46a35a/32.png) [@efu98](https://discourse.slicer.org/u/efu98)\
**Post date:** [May 12, 2022, 2:09am UTC](https://discourse.slicer.org/t/slicer-quit-when-using-vtkstatisticaloutlierremoval/23381/1 "2022-05-12T02:09:53Z")

</div>

Hello!  
I am trying to extract enclosed points of a point cloud inside a polydata using VTK.  
Extracting the points (with vtkExtractEnclosedPoints) seems to work. However, there are outlier points that aren’t inside the polydata that are still there.  
I’m trying to remove them using vtkStatisticalOutlierRemoval but Slicer crashes when I call the Update() function. I have tried using vtkRadiusOutlierRemoval but it does not seem to do anything (but it doesn’t make Slicer crash.)

I have created a C++ script independant from Slicer and used vtkStatisticalOutlierRemoval there and things are working well.

Here is my code:

```cpp
vtkNew<vtkExtractEnclosedPoints> extract;
extract->SetSurfaceData(customShape);
extract->SetInputData(mosaic);
extract->CheckSurfaceOn();
extract->Update();
		
vtkNew<vtkStatisticalOutlierRemoval> removal;
removal->SetInputConnection(extract->GetOutputPort());
removal->SetSampleSize(25);
removal->Update(); //Slicer crashes here

```

Am I doing something wrong?

Kind regards,

Elise

---

<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:** [May 12, 2022, 2:13am UTC](https://discourse.slicer.org/t/slicer-quit-when-using-vtkstatisticaloutlierremoval/23381/2 "2022-05-12T02:13:10Z")

</div>

This is a pure VTK issue, but if you provide sample data (`customShape` and `mosaic` polydata) that reproduce the issue then we can have a quick look.

---

<div class="post-metadata">

**Author:** ![efu98](https://avatars.discourse-cdn.com/v4/letter/e/46a35a/32.png) [@efu98](https://discourse.slicer.org/u/efu98)\
**Post date:** [May 16, 2022, 1:05pm UTC](https://discourse.slicer.org/t/slicer-quit-when-using-vtkstatisticaloutlierremoval/23381/3 "2022-05-16T13:05:13Z")

</div>

Hello! Sorry for the late reply.

I’ve solved the issue by using a markup closed curve to draw the region of interest. It’s quicker to compute and creates a cleaner shape.

I cannot share the mosaic but the issue is the same using randomly generated points (like on the [ExtractEnclosedPoints example](https://kitware.github.io/vtk-examples/site/Cxx/Points/ExtractEnclosedPoints/)).

The `customShape` is actually the `closedSurfacePolyData` inside the `updateBrushModel` function in the scissor script (`qSlicersegmentBreastScissorWidget`) on the SegmentEditor. My guess is that it might have tiny polygons and points but i’m not sure.

Here is the [customShape](https://filesender.renater.fr/?s=download&token=c3cff411-b1ca-4b16-9e5a-e9fd751954f8) with a test script.

---

<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:** [May 16, 2022, 3:43pm UTC](https://discourse.slicer.org/t/slicer-quit-when-using-vtkstatisticaloutlierremoval/23381/4 "2022-05-16T15:43:09Z")

</div>

> [@efu98](#):
>
> Here is the [customShape](https://filesender.renater.fr/?s=download&token=c3cff411-b1ca-4b16-9e5a-e9fd751954f8) with a test script.

This example works well for me with using customShape.vtk as input file, on Windows, with Slicer’s VTK version, both in debug and in release modes.

---

<div class="post-metadata">

**Author:** ![efu98](https://avatars.discourse-cdn.com/v4/letter/e/46a35a/32.png) [@efu98](https://discourse.slicer.org/u/efu98)\
**Post date:** [May 25, 2022, 10:20pm UTC](https://discourse.slicer.org/t/slicer-quit-when-using-vtkstatisticaloutlierremoval/23381/5 "2022-05-25T22:20:57Z")

</div>

Sorry for the late reply, it seems like I’ve managed to make it work by using  
`vtkVertexGlyphFilter` before displaying the polydata 😅  
Thank you for your help!
