Skip to content
Snippets Groups Projects
Commit ed1eb911 authored by Jayant Khatkar's avatar Jayant Khatkar
Browse files

create dependency graph for contours

parent 84303203
Branches
No related merge requests found
......@@ -2,6 +2,8 @@ using DataFrames
using CSV
using JSON
using LightGraphs
using NearestNeighbors
struct contour
pos
......@@ -9,19 +11,77 @@ struct contour
end
struct depTracker
contours::Vector{contour}
G::SimpleDiGraph
layers::Vector
done_contours::Vector
end
function vecvec_to_matrix(vecvec)
# convert vector of vectors int a matrix
dim1 = length(vecvec)
dim2 = length(vecvec[1])
my_array = zeros(Float32, dim1, dim2)
for i in 1:dim1
for j in 1:dim2
my_array[i,j] = vecvec[i][j]
end
end
return my_array
end
function contour(d::Dict)
return contour(d["pos"], d["time"])
return contour(vecvec_to_matrix(d["pos"]), d["time"])
end
function dependencyGraph(cons::Vector{contour})
function depTracker(cons::Vector{contour}, max_layers::Int, min_dist::Number)
G = LightGraphs.SimpleDiGraph(0)
# separate contours into layers
layer_heights = sort(collect(Set([c.pos[1,3] for c in cons])))
layers = [[] for i in 1:length(layer_heights)]
clayeri = []
contour_trees = []
# place contours in layers and construct KDTree for each contour
for i in 1:length(cons)
l = searchsorted(layer_heights, cons[i].pos[1,3])[1]
push!(layers[l], i)
push!(clayeri, l)
add_vertex!(G)
push!(contour_trees, KDTree(transpose(cons[i].pos)))
end
# loop through contours from previous layer and compare waypoints
# use KDTree to do this fast
for i in 1:length(cons)
l = clayeri[i]
# add contours from max_layers below
if l > max_layers
for c in layers[l-max_layers]
add_edge!(G, c, i)
end
end
if l == 1 || max_layers == 1
continue
end
for c in layers[l-1]
# if any points in contour i within min_dist of any points in contour c
if any([length(b) > 0 for b in inrange(contour_trees[c], transpose(cons[i].pos), min_dist)])
add_edge!(G, c, i) # mark i dependent on c
end
end
end
return G
return depTracker(cons, G, layers, [])
end
voxels = DataFrames.DataFrame(CSV.File("tensile-1-1.csv"))
contours = contour.(JSON.parse(open("tensilecontours.json")))
dt = depTracker(contours, 5, 5)
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