Closed 109021017 closed 3 years ago
Depth mapping is invalid with a parallel projection. You won't be able to get meaningful results doing this as the image is the same regardless of the camera's distance away from the mesh... a feature of parallel projection.
See also: https://github.com/pyvista/pyvista-support/issues/207#issuecomment-658499093
I want to get heightest z value of every x, y sample point in certain sample resolution. Currently I project_points_to_plane
then use the smaple
function to implement this. But it has trouble getting values when the cells overlap to each other as the image showing below.
Is there a better way in order to doing so?
here's my code:
def height_map(mesh, resolution=0.1):
mesh = mesh.elevation()
bounds = np.array(mesh.bounds).reshape([3, 2])
center = (bounds[:, 0] + bounds[:, 1])/2
center[2] = 0
mesh = mesh.project_points_to_plane(center)
x = np.arange(bounds[0, 0], bounds[0, 1], resolution)
y = np.arange(bounds[1, 0], bounds[1, 1], resolution)
z = np.array([0])
x, y, z = np.meshgrid(x, y, z)
points = np.stack([x, y, z], axis=3)
points = points.reshape([-1, 3])
points = pv.PolyData(points)
points = points.sample(mesh)
height_map = points.point_arrays['Elevation'].reshape([x.shape[0], x.shape[1]])
return height_map
if __name__ == '__main__':
mesh = pv.Sphere(20, (0, 0, 10))
mesh = extract_visible_cells(mesh)
hm = height_map(mesh)
plt.figure()
plt.imshow(hm)
plt.show()
Result:
Is there a better way in order to doing so?
I think what you are doing here is more or less the way to go.
Apologies for the slow response, I am trying to go through and resolve stale issues.
This issue seems to have gone off topic, please open a new issue for further help
image depth value not as expected when parallel projection enabled.
output:
output exepcted: