Commit 3d120f3e authored by Jayant Khatkar's avatar Jayant Khatkar
Browse files

cleanup and export voxels as csv

parent c92134ad
......@@ -12,12 +12,5 @@ def main(fname):
if __name__ == '__main__':
fname = 'tensile.vtk'
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)
pl = Voxelizer(fname, 1, 1) #0.25)
#pl.export_voxels('tensile')
from .planner import Planner
from .planner import Voxelizer
......@@ -7,9 +7,10 @@ import trimesh as tm
import pymeshfix as pf
from scipy.spatial import KDTree
from scipy.interpolate import LinearNDInterpolator
import pandas as pd
class Planner:
class Voxelizer:
"""
Track all relevant mesh objects for pin insertion
"""
......@@ -21,28 +22,25 @@ class Planner:
):
# record params
s = time.time()
self.voxel_dim = voxel_dim
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()
v = time.time()
print(v-s)
#voxelize
print("Voxelizing mesh")
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 = []
temptree = KDTree(self.grid.points, leafsize=5) #kd tree for fast lookup of adjacent grid points
......@@ -52,16 +50,17 @@ class Planner:
d2, ii = temptree.query(self.grid.points + [voxel_dim, 0, layer_height])
d3, ii = temptree.query(self.grid.points + [0, voxel_dim, 0])
self.centers = self.grid.points[d1 + d2 + d3 < 1e-4] + [voxel_dim/2, voxel_dim/2, layer_height/2]
# move grid points to center of each voxel and remove grid points which are not contained in a voxel
gs = time.time()
print(gs-c)
print("Interpolating pointcloud to grid stresses")
# get mean stress at each voxel
print("Interpolating pointcloud to grid stresses")
self.interpolator = LinearNDInterpolator(self.mesh.points, self.mesh['StressValues'])
print("Completed generating LinearND lookup")
print(time.time()-gs) # up to 100s for mesh with 300k points
print("Performing interpolations")
self.cstress = self.interpolator(self.centers)
def check_interp1s(self, node_is):
"""
......@@ -78,3 +77,13 @@ class Planner:
e = time.time()
print(e-s)
return node_i_pred_stress, node_i_stress
def export_voxels(self, fname):
"""
Export voxel center locations and voxel stress to csv
"""
df = pd.DataFrame(np.hstack((self.centers,self.cstress.reshape(-1,1))), columns=['x','y','z','stress'])
csv_name = "{}-{}-{}.csv".format(fname, self.voxel_dim, self.lheight)
df.to_csv(csv_name)
return csv_name
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