How to probe a polygonal mesh on a polydata?

I’m running a multi-body simulation of a vehicle driving on a rocky terrain
and need to get the elevation data of the terrain.
The terrain is built from 2 parts:

  1. 2D grid of elevation data.
  2. “Rocks” which are defined as low-poly polygonal meshes, scattered on the grid.
    I need to combine the 2 parts to get a single grid representing elevation
    data, including the rocks. Note that the grid of the surface is finer than that of the polygonal mesh rock, which have only a few vertices.
    I’m not sure if this is the right approach but I can store the terrain and polygonal mesh as separate vtkPolyData objects, probe the polygonal mesh on the terrain and extract a new object containing the combined elevation surface polydata.

Some guidelines to make this work would be appreciated.
Thank you.

Maybe the vtkAppendPolyData/vtkCleanPolyData filter combo would work for you.

import vtk

... # Get your meshes as poly data: `topo_grid` and `rock_poly`

app = vtk.vtkAppendPolyData()
cleaner = vtk.vtkCleanPolyData()

result = cleaner.GetOutput()
1 Like

Here’s what I would do:

  1. Use AppendPolyData to append all polydata into one polydata.
  2. Use the vtkCellLocator::IntersectWithLine to sample the appended polydata.

See the second technique described in the InterpolateTerrain example

I’ll try to write an example when I get some time.



@bdemin I just added an example that may do what your looking for. ResampleAppendedPolyData.

The example populates a flat terrain with randomly placed platonic solids

Here is a screenshot showing the original appended polydata (left) and resampled (right) at a different resolution.

here is a screenshot.


That is incredible. Thank you very much for adding this example, it is exactly what I was looking for.