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

add partition dependency graph and visualisation of progress

parent d2a51980
No related merge requests found
from .reebpartition import ReebPartition
from .reebpartition import ReebPartition, PartitionTracker
......@@ -21,6 +21,39 @@ def to_trimesh(mesh):
def contour2shapely(c):
return shp.geometry.LineString([(x,y) for x,y,z in c.pos])
class PartitionTracker:
def __init__(self, GP):
self.G = GP # dependency graph over the partitions
self.reset()
def reset(self):
self.all = list(self.G.nodes)
self.available = []
for p in self.all:
if len(self.G.in_edges(p))==0:
self.available.append(p)
self.remaining = copy(self.all)
self.completed = []
def do(self, i):
self.available.remove(i)
self.remaining.remove(i)
self.completed.append(i)
for p in self.remaining:
if p in self.available:
continue
dependencies_satisfied = True
for d,_ in self.G.in_edges(p):
if d not in self.completed:
dependencies_satisfied = False
break
if dependencies_satisfied:
self.available.append(p)
class ReebPartition:
def __init__(self, mesh, z_res, col_theta=np.pi/4):
......@@ -150,6 +183,7 @@ class ReebPartition:
overlap = npol.intersection(self.G.nodes[n2]['poly'].polygons_full[0])
if overlap.area>0:
col = True
self.G.nodes[n]['dependson'] = n2
break
if not col:
......@@ -157,6 +191,25 @@ class ReebPartition:
self.partitions[-1].append(n)
self.G.nodes[n]['partition'] = len(self.partitions)-1
# generate dependency graph over the contouros
self.GP = nx.MultiDiGraph()
for n in self.G:
if self.G.nodes[n]['partition'] not in self.GP:
self.GP.add_node(self.G.nodes[n]['partition'],
nodes=[n])
else:
self.GP.nodes[self.G.nodes[n]['partition']]['nodes'].append(n)
# partition dependencies
for n2,_ in self.G.in_edges(n):
if self.G.nodes[n]['partition'] != self.G.nodes[n2]['partition'] and \
not self.GP.has_edge(self.G.nodes[n2]['partition'], self.G.nodes[n]['partition']):
self.GP.add_edge(self.G.nodes[n2]['partition'], self.G.nodes[n]['partition'])
if 'dependson' in self.G.nodes[n] and \
not self.GP.has_edge(self.G.nodes[self.G.nodes[n]['dependson']]['partition'], self.G.nodes[n]['partition']):
self.GP.add_edge(self.G.nodes[self.G.nodes[n]['dependson']]['partition'], self.G.nodes[n]['partition'])
def assign_contours(self, contours):
# save contours
self.contours = contours
......@@ -313,6 +366,39 @@ def plot_polys(spol1, spol2):
plt.legend()
plt.show()
def vis_progress(pt, rp):
#import matplotlib.colors as mcolors
#from matplotlib.colors import ListedColormap
p = pv.Plotter()
p.add_mesh(rp.mesh, opacity=0.3)
# convert network graph to pv.PolyData
new_nodes = list(rp.G.nodes)
ps = []
lines = []
for n in rp.GP.nodes:
ps.append(rp.G.nodes[rp.GP.nodes[n]['nodes'][0]]['loc'])
for e in rp.GP.edges:
lines += [2, new_nodes.index(e[0]), new_nodes.index(e[1])]
ps = np.array(ps)
pv_black = pv.PolyData(ps, lines=lines)
p.add_mesh(pv_black, line_width=5, color='black')
p.set_background("white")
#p.remove_scalar_bar()
for i,box in enumerate(rp.bboxes):
if i in pt.available:
col = 'green'
elif i in pt.completed:
col = 'red'
else:
col = 'blue'
p.add_mesh(pv.Box(box), opacity=0.3, color=col)
p.show()
if __name__=='__main__':
mesh = pv.read('../horse.stl')
rg = ReebPartition(mesh, 1)
......
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