Commit 62598212 authored by Jayant Khatkar's avatar Jayant Khatkar
Browse files

getting voxel centers, but slow

parent 9c38f6bc
......@@ -4,6 +4,7 @@ import numpy as np
import time
#from slicer import Slicer, GCode, plot_meshes, ParsedSettings, utils
import pandas as pd
import pyvista as pv
def main(fname):
......@@ -11,4 +12,12 @@ def main(fname):
if __name__ == '__main__':
fname = 'tensile.vtk'
pl = Planner(fname, 1, 0.25)
pl = Planner(fname, 1, 1) #0.25)
def test(cen):
plotter = pv.Plotter()
plotter.add_mesh(pl.grid, opacity=0.2)
plotter.add_mesh(pv.PolyData(cen))
plotter.show()
test(pl.centers)
......@@ -23,6 +23,8 @@ class Planner:
self.lheight = layer_height
# read mesh data
s = time.time()
print("Reading mesh")
self.mesh = pv.read(mesh_file_name)
self.boundary = self.mesh.decimate_boundary()
......@@ -30,5 +32,25 @@ class Planner:
hwratio = voxel_dim/self.lheight
m = self.boundary.copy()
m.points[:,2] *= hwratio
v = time.time()
print(v-s)
print("Voxelizing mesh")
self.grid = pv.voxelize(m, density=self.voxel_dim)
self.grid.points[:,2] *= 1/hwratio
# get voxel centers
c = time.time()
print(c-s)
print("Getting Voxel centers")
points_to_add = []
for i in range(self.grid.n_points):
# TODO This logic is not necessarily accurate - voxel could still be empty
# but should be fine for our case
if np.any(
np.all(self.grid.points[i] + [voxel_dim, voxel_dim, layer_height] == self.grid.points,
axis=1)):
points_to_add.append(i)
self.centers = self.grid.points[points_to_add] + [voxel_dim/2, voxel_dim/2, layer_height/2]
print("Done")
print(time.time()-c)
Markdown is supported
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