forked from PyMesh/PyMesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
voxelize.py
executable file
·35 lines (30 loc) · 1 KB
/
voxelize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
""" Compute voxelization of an input mesh.
"""
import argparse
import pymesh
import numpy as np
def parse_args():
parser = argparse.ArgumentParser(description=__doc__);
parser.add_argument("--cell-size", default=1.0, type=float,
help="size of each voxel");
parser.add_argument("--erode", help="erode N layers of voxel", default=0,
type=int, metavar="N");
parser.add_argument("--dilate", help="dilate N layers of voxel", default=0,
type=int, metavar="N");
parser.add_argument("input_mesh");
parser.add_argument("output_mesh");
args = parser.parse_args();
return args;
def main():
args = parse_args();
mesh = pymesh.load_mesh(args.input_mesh);
grid = pymesh.VoxelGrid(args.cell_size, mesh.dim);
grid.insert_mesh(mesh);
grid.create_grid();
grid.dilate(args.dilate);
grid.erode(args.erode);
out_mesh = grid.mesh;
pymesh.save_mesh(args.output_mesh, out_mesh);
if __name__ == "__main__":
main();