Generation a Heightmap using Mesh Face_normals Elevation in Pyvista

101 Views Asked by At

So, to explain the context ! what I'm trying to do is to generate a heightmap of a Voxelized Buildings mesh, to do that I tried getting the upper faces and their cell_centers so I can use each cell_center elevation as a height and do some math to calculate it.

The issue here is that I'm having a 32x32 ( x,y ) Voxelized mesh, which means I should have in total 1024 ( 32x32 ) cell center of the upper faces.

But when I try doing that, I get 1132 Elevations, and couldn't figure it out why and how to have only the ones I need.

This is the code I made to do that :

mesh = pv.read("voxeled_withfloor.obj")

elv = mesh.elevation(preference="cell")
elv.compute_normals(cell_normals=True)
face_normals = elv.cell_normals
upward_face_indices = np.where(face_normals[:, 2] > 0.0)[0]
upper_face_mesh = elv.extract_cells(upward_face_indices)
cell_centers = upper_face_mesh.cell_centers()
elevation = cell_centers.elevation()
elevation_array = elevation["Elevation"]
here = np.asarray(elevation_array)

num_arrays = len(elevation_array) // 32
string_array = elevation_array.astype(np.float64)


multidimensional_arrays = np.reshape(string_array[: num_arrays * 32], (num_arrays, 32))

When I use pyvista plotter to show the cell_centers I get this, which looks good and correct :

Cell_centers enter image description here

Number of Elevations

enter image description here

If anyone tried doing this before or knows how to do that please don't hesitate !

Thank you in advance.

I tried every possible way to do that, nothing is working

0

There are 0 best solutions below