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

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

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:

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
}

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

thanks for your answer

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.

If you’re looking for an easy way to do this in Python with VTK, check out PyVista 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:

import pyvista as pv
from pyvista import examples

# This is vtkPolyData
poly = examples.download_lidar()

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

And just to prove it found the right one:

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()