Skip to content
Snippets Groups Projects
Commit d8ae27ed authored by tolgayurt's avatar tolgayurt
Browse files

updated polygon splitter

parent d2162f38
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,8 @@ from bokeh.palettes import Dark2_5 as palette
from bokeh.palettes import Viridis256
from bokeh.models import CustomJS
import itertools
import pdb
a = 0.407
......@@ -100,8 +102,8 @@ class Polygon2(object):
if spine[0][0] == spine[1][0]: # Sonderfall für eine senkrechte
slope = math.inf
else:
slope = (spine[1][1] - spine[0][1]) / (spine[1][0] - spine[0][
0]) # m = y2-y1/x2-x1 Formel für die Geradensteigung mithilfe aus zwei verschiedenen Punkten der Geraden
slope = (spine[1][1] - spine[0][1]) / (spine[1][0] - spine[0][0])
# m = y2-y1/x2-x1 Formel für die Geradensteigung mithilfe aus zwei verschiedenen Punkten der Geraden
return slope
def plot_polygon(self, title="", render=True):
......@@ -136,20 +138,22 @@ class Polygon2(object):
spine_bottom = self.spine[0]
spine_top = self.spine[1]
help_array = self.shell.copy()
if help_array[0] == help_array[-1]: # falls letztes element doppelt
help_array = help_array[0:-1]
spine_bottom_found = False
spine_top_found = False
spine_bottom_not_horizontal = False
while spine_bottom_found == False: # Phase 1 der Funktion sie sucht den bottom spine, dabei werden die Ecken die nicht der Spine Bottom sind ans Ende der Liste geschoben
if help_array[0] == spine_bottom:
if spine_bottom[1] != help_array[-1][
1]: # checkt ob Spine bottom ein horizontalen Nachbar hat falls ja wird ein Flag gesetzt damit Spine bottomt später nicht in die Rechte mitgenommen wird
if spine_bottom[1] != help_array[-1][1]:
# checkt ob Spine bottom ein horizontalen Nachbar hat falls ja wird ein Flag gesetzt damit Spine bottomt später nicht in die Rechte mitgenommen wird
spine_bottom_not_horizontal = True
spine_bottom_found = True
left.append(help_array.pop(0))
else:
help_array.append(help_array.pop(0))
while spine_top_found == False: # iterieren die Liste erneut durch bis wir spine top finden, falls spine top gefunden wurde wird auch geschaut ob spine top ein horizontalen linken
if help_array[0] == spine_top: # Nachbar hat falls ja wird spine top nicht in die Linke Liste miteingefügt
if help_array[0] == spine_top: # Nachbar hat falls ja wird spine top nicht in die rechte Liste miteingefügt
spine_top_found = True
if spine_top[1] != left[-1][1]:
left.append(spine_top)
......@@ -548,6 +552,7 @@ class Container(object):
successor_vertex = self.Tree.find_edges(self.root, vertex_y, self.root)
corresponding_edge_points = (successor_vertex.vertice, successor_vertex.vertice_neighbour)
# print("corresponding edge points",corresponding_edge_points,"for vertex",vertex)#p
#pdb.set_trace()
distance = self.slope3(corresponding_edge_points, vertex)
if distance <= min_horizontal_distance:
min_horizontal_distance = distance
......@@ -782,18 +787,24 @@ def plot_mini_containers(plot_steps, render=True, plot_width=600, plot_height=60
class End_Container(object):
def __init__(self, mini_container_array, angle=0):
self.mini_containers = mini_container_array
self.pack_mini_containers()
self.polygons,self.max_width,self.max_height =self.pack_mini_containers()
self.container_area = self.container_area(self.mini_containers)
self.angle = angle
def pack_mini_containers(self):
y_offset = self.mini_containers[0].height
polygons=[]
container_max_width =0
for mini_container in self.mini_containers[1:]:
for polygon in mini_container.polygons:
polygon.translation(0, y_offset)
mini_container.y_offset = y_offset
y_offset += mini_container.height
return
polygons= polygons+mini_container.polygons
if container_max_width < mini_container.max_width:
container_max_width = mini_container.max_width
border_points = [(0,0),(0,y_offset),(container_max_width,y_offset),(container_max_width,0)]
return (polygons,container_max_width,y_offset,)
def container_area(self, mini_containers):
container_area = 0
......@@ -843,4 +854,11 @@ class End_Container(object):
if render:
return show(fig)
else:
return fig
\ No newline at end of file
return fig
list2=[[(233.50398313507685, 1720.9265753781722), (787.0422555505176, 1491.3173835514308), (0.0, 1680.8654987569212), (233.50398313507685, 1720.9265753781722)], [(1124.8805630148158, 1708.6895362501566), (532.1290575497333, 1491.3173835514308), (233.50398313507685, 1519.6028026015497), (1124.8805630148158, 1708.6895362501566)], [(1498.1911834971443, 1765.660563957103), (1832.2885709298307, 1593.0223998373076), (1124.8805630148158, 1491.3173835514308), (1498.1911834971443, 1765.660563957103)]]
list3=[]
for poly in list2:
list3.append((Polygon2(poly)))
high_classes = height_classes(list3)
test = building_containers(high_classes)
\ No newline at end of file
......@@ -25,54 +25,37 @@ from bokeh.io import curdoc
from bokeh.plotting import figure
# def index(request):
# return HttpResponse("Hello, world. You're at the polls index.")
def index(request):
# list_hc = height_classes(polygons)
# list_containers = building_containers(list_hc)
# list_mini_containers = pack_mini_containers(list_containers)
# end_container = End_Container(list_mini_containers, True)
#[(0.5, 0), (0, 1), (1, 0), (0.5, 0)]
convex_polygons = poly.create_multiple_convex_polygons(14,3)
convex_polygons = poly.create_multiple_convex_polygons(20,9)
polygons_plot= poly.plot_polygons(convex_polygons,plot_width=300,plot_height=300,render=False)
html_polygons = file_html(polygons_plot, CDN, "my plot")
high_classes = poly.height_classes(convex_polygons)
# hc_plot_helper=[]
# for hc in high_classes:
# hc_plot = hc.plot_hc(render=False,plot_width=300,plot_height=300)
# html_hc = file_html(hc_plot, CDN, "my plot")
# hc_plot_helper.append(html_hc)
hc_tab_list = []
counter = 0
for hc in high_classes:
# building highclass plots
for counter,hc in enumerate(high_classes):
hc_plot = hc.plot_hc(render=False,plot_width=300,plot_height=300)
# html_container = file_html(container_plot, CDN, "my plot")
# container_plot_helper.append(html_container)
tab = Panel(child=hc_plot, title="High-Class {}".format(counter, counter))
tab = Panel(child=hc_plot, title="High-Class {}".format(counter))
hc_tab_list.append(tab)
counter += 1
hc_tabs = Tabs(tabs=hc_tab_list)
hc_plot_helper = file_html(hc_tabs, CDN, "my plot")
list_containers = poly.building_containers(high_classes)
container_plot_helper = []
tab_list=[]
counter = 0
for container in list_containers:
container_tab_list=[]
#building container plots
for counter,container in enumerate(list_containers):
container_plot = container.plot_container_steps(plot_width=500,colums=3,plot_height=500,render=False)
#html_container = file_html(container_plot, CDN, "my plot")
#container_plot_helper.append(html_container)
tab = Panel(child=container_plot, title="High-Class {} -> Container {}".format(counter, counter))
tab_list.append(tab)
counter += 1
tabs = Tabs(tabs=tab_list)
container_tab_list.append(tab)
tabs = Tabs(tabs=container_tab_list)
container_plot_helper= file_html(tabs, CDN, "my plot")
......@@ -81,24 +64,16 @@ def index(request):
mini_container_plots = mini_containers_tuple[1]
mini_plot = poly.plot_mini_containers(mini_container_plots,render=False)
mini_plots=[]
# building mini container plots
mini_plots_tabs=[]
for counter,m_plot in enumerate(mini_plot):
print(m_plot)
# print(m_plot[0])
# print(m_plot[1])
tab = Panel(child=m_plot, title="Container {} -> Mini-Container {}".format(counter, counter))
tab = Panel(child=m_plot, title="Container {} -> Mini-Containers".format(counter))
mini_plots_tabs.append(tab)
#m_plot = layout([[m_plot]],sizing_mode="scale_both")
#mini_plots.append(file_html( m_plot, CDN, "my plot"))
#tabs.append(Panel(child=m_plot, title="circle {}".format(counter)))
mini_tabs = Tabs(tabs=mini_plots_tabs)
mini_html_plots = file_html(mini_tabs, CDN, "my plot")
#tab =Tabs(tabs=tabs)
#mini_html_plots= mini_plots
# end container plot
end_container = poly.End_Container(list_mini_containers)
end_container_plot= end_container.plot_container(render=False)
end_container_html =file_html(end_container_plot, CDN, "my plot2")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment