stl to voxel
#2009
-
Hi! Just discovered this library and it looks about perfect for my needs, so apologies for stupid question--how would I go about converting stl to voxel and saving both as a .npy, and as something viewable in Paraview, using Python? |
Beta Was this translation helpful? Give feedback.
Answered by
Grantim
Jan 3, 2024
Replies: 1 comment
-
Hello! from meshlib impoer mrmeshpy as mm
from meshlib impoer mrmeshnumpy as mn
import numpy as np
# load mesh from stl
mesh = mm.loadMesh( "path_to_mesh.stl" )
# configure parameters for voxel conversion
params = mm.MeshToDistanceVolumeParams()
voxelSize = 0.01
box = mesh .computeBoundingBox()
expansion = mm.Vector3f.diagonal( 3*voxelSize )
params.origin = box.min - expansion
params.voxelSize = mm.Vector3f.diagonal(0.01)
dimensionsF = ( box.max + expansion - params.origin ) / voxelSize
params.dimensions = mm.Vector3i(int(dimensionsF.x),int(dimensionsF.y),int(dimensionsF.z)) + mm.Vector3i.diagonal(1)
params.signMode = mm.SignDetectionMode.HoleWindingRule
params.maxDistSq = 3*voxelSize
# create voxels from mesh
volume = mrmesh.meshToDistanceVolume( mesh, params )
# create numpy array from voxels
npArray = mn.getNumpy3Darray(volume)
# create numpy arrays from mesh
npVertices = mn.getNumpyVerts( mesh )
npFaces = mn.getNumpyFaces( mesh.topology ) You can find useful information here #1950 Hope it helps! |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Fedr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello!
We are not really familar with paraview import but you can extract mesh and voxels in numpy like this