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

finish segment intersection used to intersection contours with voxels

parent ed1eb911
......@@ -11,11 +11,12 @@ struct contour
end
struct depTracker
struct problem
contours::Vector{contour}
G::SimpleDiGraph
layers::Vector
done_contours::Vector
layer_height::Number
end
......@@ -38,7 +39,7 @@ function contour(d::Dict)
end
function depTracker(cons::Vector{contour}, max_layers::Int, min_dist::Number)
function problem(cons::Vector{contour}, max_layers::Int, min_dist::Number)
G = LightGraphs.SimpleDiGraph(0)
# separate contours into layers
......@@ -79,9 +80,103 @@ function depTracker(cons::Vector{contour}, max_layers::Int, min_dist::Number)
end
end
return depTracker(cons, G, layers, [])
return problem(cons, G, layers, [], layer_heights[1])
end
struct voxmap
seglen::Array{Number}
segoffset::Array{Number}
segcontours::Array{Int}
end
function seg_helper_orientation(p,q,r)
val = (q[2]-p[2]) * (r[1]-q[1]) - (q[1]-p[1]) * (r[2]-q[2])
if val > 0
# clockwise
return 1
elseif val < 0
# anticlockwise
return 2
else
# colinear
return 0
end
end
function seg_intersect(p1,q1,p2,q2)
o1 = seg_helper_orientation(p1, q1, p2)
o2 = seg_helper_orientation(p1, q1, q2)
o3 = seg_helper_orientation(p2, q2, p1)
o4 = seg_helper_orientation(p2, q2, q1)
if (o1 o2) && (o3 o4)
return true
elseif o1==0 || o2==0 || o3==0 || o4==0
print("Colinearity! - TODO")
end
return false
end
function voxmap(vox, vox_d, problem)
# for one vox, get all contours which pass through it
# only need to search contours in its layer
l = Int((vox[3] + problem.layer_height/2)/problem.layer_height)
voxx1 = vox[1] + vox_d/2
voxx2 = vox[1] - vox_d/2
voxy1 = vox[2] + vox_d/2
voxy2 = vox[2] - vox_d/2
seg_now = false
for c in problem.layers[l]:
# check if contour passes thorough this vox
for i in 2:size(c.pos)[1]
# is this line segment completely outside vox?
if c.pos[i, 1] > voxx1 && c.pos[i-1, 1] > voxx1 ||
c.pos[i,1] < voxx2 && c.pos[i-1, 1] < voxx2 ||
c.pos[i,2] < voxy2 && c.pos[i-1, 2] < voxy2 ||
c.pos[i,2] < voxy1 && c.pos[i-1, 2] > voxy1
# segment outside loop entirely
if seg_now
print("Something's gone wrong: segment entirely outside voxel, but last segment inside")
end
continue
if c.pos[i, 1] > voxx1 && c.pos[i-1, 1] > voxx1 ||
c.pos[i,1] < voxx2 && c.pos[i-1, 1] < voxx2 ||
c.pos[i,2] < voxy2 && c.pos[i-1, 2] < voxy2 ||
c.pos[i,2] < voxy1 && c.pos[i-1, 2] > voxy1
# segment outside loop entirely
if seg_now
# TODO add this to segment
else
# TODO START NEW SEGMENT
end
# check line segment i and i-1
elseif seg_intersect(c.pos[i,:], c.pos[i,:], [voxx1, voxy1], [voxx1, voxy2]) ||
seg_intersect(c.pos[i,:], c.pos[i,:], [voxx1, voxy1], [voxx2, voxy1]) ||
seg_intersect(c.pos[i,:], c.pos[i,:], [voxx2, voxy1], [voxx2, voxy2]) ||
seg_intersect(c.pos[i,:], c.pos[i,:], [voxx2, voxy2], [voxx1, voxy2])
print("intersecting")
end
end
# for those contours find exact segments
end
end
voxels = DataFrames.DataFrame(CSV.File("tensile-1-1.csv"))
contours = contour.(JSON.parse(open("tensilecontours.json")))
dt = depTracker(contours, 5, 5)
dt = problem(contours, 5, 5)
......@@ -86,7 +86,7 @@ class Voxelizer:
"""
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)
df.to_csv(csv_name, index=False)
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