I used vtkDelaunay2d to generate a terrain surface. I wanted to obtain the elevation at two locations following this example suggested from an earlier posting. The locations are coordinates in terrain units. I have written the following code:
a= (533519, 4387387)
b= (533555, 4387387)
viewpts = vtkPoints()
values = vtkPolyData()
z_probe = vtkProbeFilter()
The result when I run the following
(533519, 4387387, 0.0)
What am I doing wrong? Why am I not getting the z value for location a?
ps. I have also tried using,
gridWarpScalar = vtkWarpScalar()
But I get the same result.
Almost there !
As per documentation the
vtkProbeFilter computes point attributes (e.g., scalars, vectors, etc.) at specified point positions. So the coordinates of a,b are expected to remain the same but their attibutes will be filled by the filter. To get the z value try
Thank you Christos,
I am still unable to get some results. It appears that I am not getting any scalar back (I used
print(z_probe) to see what I got back. I am not certain why I am getting this result given that I know that the Delaunay Tessellation computed correctly (I was able to see it) and the locations that I used are within this tesselation!
I am going over everything to see what is missing!!!??
Without more code I cannot figure out what it could be the issue. Here is a full python example I created based on the VTK example and your test case. I hope it helps:
# based on https://kitware.github.io/vtk-examples/site/Cxx/PolyData/InterpolateMeshOnGrid/
# Create a random set of 100 points in the xy-plane in (0,10)x(0,10).
# If you had instead started with a set of (x,y,z) points, you must copy
# the zvalues into a FloatArray and set it as the data set's scalars,
# and then set the z-coordinates to zero
randomPoints = vtk.vtkPoints()
zvalues = vtk.vtkFloatArray()
gridSize = 10
maxHeight = 1.0
randomSequence = vtk.vtkMinimalStandardRandomSequence()
for i in range(100):
x = randomSequence.GetRangeValue(0, gridSize)
y = randomSequence.GetRangeValue(0, gridSize)
z = randomSequence.GetRangeValue(0, maxHeight)
randomPoints.InsertNextPoint(x, y, 0)
randomPolyData = vtk.vtkPolyData()
# Triangulate the grid points. If you do not have a mesh (points
# only), the output will not be interpolated!
randomDelaunay = vtk.vtkDelaunay2D()
a = (5,5,0)
b = (4,5,0)
viewpts = vtk.vtkPoints()
data = vtk.vtkPolyData()
z_probe = vtk.vtkProbeFilter()
I adapted your code and I did get results. Frankly, I am still a bit confused as to the logic (the bit where I cannot follow the logic is having to leave out z values when creating
randompoints and having to set the scalars separately). But… it does work so I will endeavor to try to make sense of why.
Thanks again! It has been very helpful.
(the bit where I cannot follow the logic is having to leave out z values when creating
randompoints and having to set the scalars separately)
Delaunay2D can only work on 2D points. So we only pass
y. We treat
z as an attribute of the points which we want to interpolate( if
z is confusing think of it as temperature/density or any other scalar value).
z as a point attribute.
randomDelaunay will then triangulate the points leaving the zvalues untouched. (We could even have appended the zvalues after running the filter)
vtkProbeFilter requires a geometric object with cells as source where we can use to locate the InputData and interpolate the zvalues onto the points of InputData.