Commit 2974c4ec authored by Jayant Khatkar's avatar Jayant Khatkar
Browse files

speedup and count unlinked voxels

parent 54b2c037
......@@ -136,6 +136,7 @@ def vox_section_area(voxels, mesh_file_name, vox_dim=3):
tu.transform_to_z0(mesh)
tm_mesh = to_trimesh(mesh)
SecArea = np.zeros(len(voxels))
default_high = 1e7
z = 0
i = 0
......@@ -147,11 +148,19 @@ def vox_section_area(voxels, mesh_file_name, vox_dim=3):
if c[2] != z:
sl = tm_mesh.section(plane_origin=c, plane_normal=[0,0,1])
if sl is None:
SecArea[i] = 1e7
SecArea[i] = default_high
continue
sl2d,_ =sl.to_planar()
z = c[2]
# if neighbour is adjacent and completed, can simply copy over info
if SecArea[i-1] != 0 and SecArea[i-1]!= default_high:
c1 = voxels.iloc[i-1,1:4].to_numpy()
d1 = abs(sum(c-c1))/vox_dim
if d1 <1.001:
SecArea[i] = SecArea[i-1]
continue
for e in sl2d.split():
e.apply_translation(-sl2d.centroid)
e.apply_translation(sl.centroid[0:2])
......@@ -159,23 +168,23 @@ def vox_section_area(voxels, mesh_file_name, vox_dim=3):
if poly.contains(Point(c[:2])):
SecArea[i] = poly.area
if abs(SecArea[i-1] - default_high) < 1:
c1 = voxels.iloc[i-1,1:4].to_numpy()
d1 = abs(sum(c-c1))/vox_dim
print("Trying to fix voxel " + str(i-1) + ", dist: " + str(d1))
if d1 <1.001:
SecArea[i-1] = SecArea[i]
print("voxel " + str(i-1) + " fixed")
if SecArea[i] == 0:
c1 = voxels.iloc[i-1,1:4].to_numpy()
d1 = abs(sum(c-c1))/vox_dim
c2 = voxels.iloc[i+1,1:4].to_numpy()
d2 = abs(sum(c-c2))/vox_dim
if d1 <1.001:
SecArea[i] = SecArea[i-1]
elif d2 < 1.001:
SecArea[i] = SecArea[i+1]
else:
print("Uh OH rogue voxel")
SecArea[i] = 1e7
if z>20:
print(set(SecArea))
break
print("Uh OH unlinked voxel " + str(i))
SecArea[i] = default_high
#if z>40:
# print(set(SecArea))
# break
print("Unlinked Voxels: {}/{}".format(sum(SecArea==default_high), len(SecArea)))
if __name__ == '__main__':
......
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