# Deleting vertices based on normal vector

**URL:** https://discourse.vtk.org/t/deleting-vertices-based-on-normal-vector/4362
**Category:** Support
**Created:** [October 6, 2020, 3:24pm UTC](https://discourse.vtk.org/t/deleting-vertices-based-on-normal-vector/4362 "2020-10-06T15:24:46Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rjs44](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rjs44/32/1245_2.png) [@rjs44](https://discourse.vtk.org/u/rjs44)
#### Post date: [October 6, 2020, 3:24pm UTC](https://discourse.vtk.org/t/deleting-vertices-based-on-normal-vector/4362/1 "2020-10-06T15:24:47Z")

</div>

I have a triangular mesh containing vertices that I would like to filter. I am able to filter based on the scalar values of the mean curvature, using vtkThreshold with Python3:

```
curvatureFilter = vtk.vtkCurvatures()
curvatureFilter.SetCurvatureTypeToMean()
curvatureFilter.SetInputData(polydata)
curvatureFilter.Update()
polydata = curvatureFilter.GetOutput()

threshold = vtk.vtkThreshold()
threshold.SetInputData(polydata)
threshold.ThresholdByUpper(0.01)
threshold.Update()
polydata = threshold.GetOutput()

```

The nice thing about vtkThreshold is that it deletes all vertices and corresponding edges that do not meet the requirement. I would like to do a similar thing based on the normal vectors of the vertices. For example, remove a vertex if the x-value is higher than the y-value of the normal vector.

Does anyone know a proper way how to do this?

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [October 6, 2020, 3:34pm UTC](https://discourse.vtk.org/t/deleting-vertices-based-on-normal-vector/4362/2 "2020-10-06T15:34:31Z")

</div>

You can use vtkArrayCalculator to perform various scalar and vector operations on point data and store results in a new array that you can use for thresholding.

What is your end goal with this? Would you like to extract “one side” of a surface? There are much better methods for this than filtering based on normal vector direction.

It would be useful if you could give a context of your question (what is your application area, problem you want to solve, approach that you are implementing), and not just write about the very specific technical issue.

---

<div class="post-metadata">

### Author: ![rjs44](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rjs44/32/1245_2.png) [@rjs44](https://discourse.vtk.org/u/rjs44)
#### Post date: [October 6, 2020, 4:25pm UTC](https://discourse.vtk.org/t/deleting-vertices-based-on-normal-vector/4362/3 "2020-10-06T16:25:13Z")

</div>

Hi Andras, my goal is indeed to extract the vertices that are on the sides.

This is the original mesh:

 ![original_mesh](https://discourse.vtk.org/uploads/default/original/2X/4/475062023d7307519505c024beef6358d1458b7a.png)

This is after thresholding on a mean curvature value of \> 0.01:

 ![threshold_mc](https://discourse.vtk.org/uploads/default/original/2X/0/09aee3ad0d31499823cd9d50b425b3b7645c705d.png)

And this is after thresholding and filtering on the direction of the normal vector:

 ![filtered_n](https://discourse.vtk.org/uploads/default/original/2X/1/12d0d3a4dda92aed7af4aae385077a51140313f5.png)

I obtain the last image by adding the coordinates of every vertex that satisfies the condition for the normal vector to a vtkVertexGlyphFilter. However, I would like to maintain/include the corresponding edges between the vertices. In this way, I would be able to cluster the vertices that are connected to each other.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [October 6, 2020, 4:51pm UTC](https://discourse.vtk.org/t/deleting-vertices-based-on-normal-vector/4362/4 "2020-10-06T16:51:33Z")

</div>

You can find continuous edge by computing curvature for each point and connecting them using vtkDijkstraGraphGeodesicPath, as suggested before:

> [@Get surface area of region on polydata](https://discourse.vtk.org/t/get-surface-area-of-region-on-polydata/3738):
>
> I would like to derive the surface area of a specific region on the surface of polydata. This specific region would be the part of the surface that is visible when viewed from above (in the y-plane) such that overlapping “points” are not considered. This is the isosurface generated by Marching Cubes: To illustrate, I have derive this particular top-surface by manipulating the original image stack and use MC to reconstruct the isosurface of the manipulated images (in green):

---

<div class="post-metadata">

### Author: ![rjs44](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rjs44/32/1245_2.png) [@rjs44](https://discourse.vtk.org/u/rjs44)
#### Post date: [October 6, 2020, 6:08pm UTC](https://discourse.vtk.org/t/deleting-vertices-based-on-normal-vector/4362/5 "2020-10-06T18:08:10Z")

</div>

Hi Andras, the objective of the post you referred to is different from what I am trying to accomplish for this experiment.

As you suggested, I now added an additional array to the polydata which has 1 for every index/vertex that should be considered and a 0 otherwise. If I visualize it with Paraview it looks like this:

 ![additional_arr](https://discourse.vtk.org/uploads/default/original/2X/4/4cc6680c61421fe84e546dc2e69aa9f1be5191c4.png)

When applying the threshold filter in Paraview on this new array:

 ![additional_arr_thresh](https://discourse.vtk.org/uploads/default/original/2X/1/1d8cf3f23b925bbdb9272b2f3b5d6d2f126645da.png)

This is exactly what I want. However, Paraview’s threshold filter allows specifying the scalar array to which the threshold should be applied. I cannot find this in vtk, so I was wondering if you’d know how to specify the array for the threshold filter in vtk (python3)?

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [October 6, 2020, 6:26pm UTC](https://discourse.vtk.org/t/deleting-vertices-based-on-normal-vector/4362/6 "2020-10-06T18:26:09Z")

</div>

You can choose an array to work by prepending an [vtkAssignAttribute](https://vtk.org/doc/nightly/html/classvtkAssignAttribute.html) filter before the threshold filter; or using [SetInputArrayToProcess() method of the threshold filter](https://vtk.org/doc/nightly/html/classvtkAlgorithm.html#a6bea16e1329609dbccce0ff8d2367484).

Dijkstra path search is usually needed for boundary extraction because the region that you get with thresholding is thick and noisy.
