# What is best way to get the highest point (z-axis) in a polydata?

**URL:** <https://discourse.vtk.org/t/what-is-best-way-to-get-the-highest-point-z-axis-in-a-polydata/1833>\
**Category:** Development\
**Created:** [September 27, 2019, 1:02pm UTC](https://discourse.vtk.org/t/what-is-best-way-to-get-the-highest-point-z-axis-in-a-polydata/1833 "2019-09-27T13:02:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthijs\_Hendriks](https://discourse.vtk.org/user_avatar/discourse.vtk.org/matthijs_hendriks/32/845_2.png) [@Matthijs\_Hendriks](https://discourse.vtk.org/u/Matthijs_Hendriks)\
**Post date:** [September 27, 2019, 1:02pm UTC](https://discourse.vtk.org/t/what-is-best-way-to-get-the-highest-point-z-axis-in-a-polydata/1833/1 "2019-09-27T13:02:15Z")

</div>

Is it possible to get the highest point (z-axis) in a polydata.  
The GetBound() function in vtkActor is not usefull because it only give the boundary

---

<div class="post-metadata">

**Author:** ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)\
**Post date:** [September 27, 2019, 5:11pm UTC](https://discourse.vtk.org/t/what-is-best-way-to-get-the-highest-point-z-axis-in-a-polydata/1833/2 "2019-09-27T17:11:24Z")

</div>

You mean you want to get the xyz coordinate values of the highest point? I’m afraid you’ll have to iterate over the points to figure that out, but it shouldn’t be hard. Use `vtkPolyData::GetPoints()` to get the `vtkPoints` object, then you can iterate over it with:

```auto
vtkPoints* points = polydata->GetPoints();
for (vtkIdType i = 0; i < points->GetNumberOfPoints(); ++i)
{
  double pt[3];
  points->GetPoint(i, pt);
  double z= pt[2];

  // check if z is max, store pt if it is
}

```

---

<div class="post-metadata">

**Author:** ![Matthijs\_Hendriks](https://discourse.vtk.org/user_avatar/discourse.vtk.org/matthijs_hendriks/32/845_2.png) [@Matthijs\_Hendriks](https://discourse.vtk.org/u/Matthijs_Hendriks)\
**Post date:** [October 11, 2019, 9:17am UTC](https://discourse.vtk.org/t/what-is-best-way-to-get-the-highest-point-z-axis-in-a-polydata/1833/3 "2019-10-11T09:17:53Z")

</div>

Thanx, it isn’t hard indeed, however it can be inefficient / time consuming 😉

thanks for your answer

---

<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 11, 2019, 11:55am UTC](https://discourse.vtk.org/t/what-is-best-way-to-get-the-highest-point-z-axis-in-a-polydata/1833/4 "2019-10-11T11:55:09Z")

</div>

Such loop is very fast in C++ (probably takes a few milliseconds on a not too large mesh). In Python, you cannot iterate through mesh points (it would be way too slow), but you can get point coordinates as a numpy array and find the maximum using a single function call.

---

<div class="post-metadata">

**Author:** ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)\
**Post date:** [October 11, 2019, 8:08pm UTC](https://discourse.vtk.org/t/what-is-best-way-to-get-the-highest-point-z-axis-in-a-polydata/1833/5 "2019-10-11T20:08:23Z")

</div>

If you’re looking for an easy way to do this in Python with VTK, check out [PyVista](http://docs.pyvista.org) which makes using VTK a bit more Pythonic. For example, here I load an existing `vtkPolyData` object of a large point cloud (3392091 points) and find the vertex with the highest Z value in like no time at all:

```auto
import pyvista as pv
from pyvista import examples

# This is vtkPolyData
poly = examples.download_lidar()

idx = np.argmax(poly.points[:,2])
print(idx)

```

---

<div class="post-metadata">

**Author:** ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)\
**Post date:** [October 11, 2019, 8:13pm UTC](https://discourse.vtk.org/t/what-is-best-way-to-get-the-highest-point-z-axis-in-a-polydata/1833/6 "2019-10-11T20:13:40Z")

</div>

And just to prove it found the right one:

```python
p = pv.Plotter()
p.add_mesh(poly, color="tan", point_size=5)
p.add_point_labels(poly.points[idx], ["Here it is"], color="pink", point_size=10)
p.enable_eye_dome_lighting()
p.camera_position = [(481304., 4400357., 1849.),
 (481028., 4400161., 1770.),
 (-0.21, -0.092, 0.973)]
p.show()

```

 ![download](https://discourse.vtk.org/uploads/default/original/1X/f97c017df94c3d8a7d698a329b462b2572b52ad8.jpeg)
