Skip to content
Snippets Groups Projects
Commit e8a13263 authored by Lab Computer's avatar Lab Computer
Browse files

functino to to create gridded version of existing slicing surface mesh

parent c9bf8f0b
Branches master
No related merge requests found
......@@ -5,7 +5,7 @@ import sympy as sp
from .general import copy_over_array, gen_single_surf
def get_model_xy_grid(model_mesh, resolution):
def get_model_xy_grid(model_mesh, resolution, bigger=True):
"""
Get the xy grid used to generate the surfaces for slicing
resolution: the number of points on the longer side
......@@ -23,8 +23,12 @@ def get_model_xy_grid(model_mesh, resolution):
res_x = int(resolution*x_len/y_len)
# gen grid
x = np.linspace(min_x-1e-3, max_x+1e-3, res_x)
y = np.linspace(min_y-1e-3, max_y+1e-3, res_y)
if bigger:
x = np.linspace(min_x-1e-3, max_x+1e-3, res_x)
y = np.linspace(min_y-1e-3, max_y+1e-3, res_y)
else:
x = np.linspace(min_x, max_x, res_x)
y = np.linspace(min_y, max_y, res_y)
x, y = np.meshgrid(x, y)
return x, y
......@@ -191,4 +195,22 @@ def gen_curved_surfs(model_mesh, resolution, roundness=0.003, z_max=1, z_start=1
z = z_start + (z_top-z_start)*(z_m-z_start)/(z_top.max() - z_start)
surfs.append(gen_single_surf(x, y, z))
print("Surface {} of {} added".format(i,len(z_mids)))
return surfs
\ No newline at end of file
return surfs
def gen_grid_surf(surf_mesh, model_mesh, resolution):
"""
Generate a structured grid from a surface mesh
"""
surf_mesh = surf_mesh.extract_surface()
xall, yall = get_model_xy_grid(model_mesh, resolution, bigger=False)
zs = []
for x,y in zip(xall.flatten(), yall.flatten()):
ip, _ = surf_mesh.ray_trace((x,y,-1000), (x,y,1000), first_point=True)
if len(ip)==0:
ip = [x,y,surf_mesh.points.mean(axis=0)[2]]
zs.append(ip[2])
zall = np.array(zs).reshape(xall.shape)
return gen_single_surf(xall,yall,zall)
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment