Voxelize a .stl#
Walkthrough#
Create a TargetGeometry from a .stl file by specifying the stlfilename and resolution i.e. the number of slices in the z-axis.
import vamtoolbox as vam
target_geo = vam.geometry.TargetGeometry(stlfilename=vam.resources.load("trifurcatedvasculature.stl"),resolution=250)
Show the voxel array of the TargetGeometry instance (array) with show().
target_geo.show()
Tip
Hover the mouse pointer over either slice and scroll to slice through the 3D voxel array at different z and x indices.
Alternatively, the vedo plotting package may be used to display the voxel array.
import vedo
vol = vedo.Volume(target_geo.array).legosurface(vmin=0.5,vmax=1.5)
vol.show(viewup="x")
Example file#
examples/voxelizestl.py#
import vamtoolbox as vam
target_geo = vam.geometry.TargetGeometry(stlfilename=vam.resources.load("trifurcatedvasculature.stl"),resolution=250)
target_geo.show()
import vedo
vol = vedo.Volume(target_geo.array).legosurface(vmin=0.5,vmax=1.5)
vol.show(viewup="x")
voxelizer = vam.voxelize.Voxelizer()
voxelizer.addMeshes(
{vam.resources.load("trifurcatedvasculature.stl"):"print_body"}
)
array = voxelizer.voxelize("print_body",layer_thickness=0.1,voxel_value=1.0,voxel_dtype='uint8')