- fixed the Voronoi generation in the Autolevelling Tool (removed the Foronoi package due of issues and now using the embedded functionality from Shapely)
This commit is contained in:
@@ -21,17 +21,23 @@ from io import StringIO
|
|||||||
|
|
||||||
from matplotlib.backend_bases import KeyEvent as mpl_key_event
|
from matplotlib.backend_bases import KeyEvent as mpl_key_event
|
||||||
|
|
||||||
|
# try:
|
||||||
|
# from foronoi import Voronoi
|
||||||
|
# from foronoi import Polygon as voronoi_poly
|
||||||
|
# VORONOI_ENABLED = True
|
||||||
|
# except Exception:
|
||||||
|
# try:
|
||||||
|
# from shapely.ops import voronoi_diagram
|
||||||
|
# VORONOI_ENABLED = True
|
||||||
|
# # from appCommon.Common import voronoi_diagram
|
||||||
|
# except Exception:
|
||||||
|
# VORONOI_ENABLED = False
|
||||||
try:
|
try:
|
||||||
from foronoi import Voronoi
|
from shapely.ops import voronoi_diagram
|
||||||
from foronoi import Polygon as voronoi_poly
|
|
||||||
VORONOI_ENABLED = True
|
VORONOI_ENABLED = True
|
||||||
|
# from appCommon.Common import voronoi_diagram
|
||||||
except Exception:
|
except Exception:
|
||||||
try:
|
VORONOI_ENABLED = False
|
||||||
from shapely.ops import voronoi_diagram
|
|
||||||
VORONOI_ENABLED = True
|
|
||||||
# from appCommon.Common import voronoi_diagram
|
|
||||||
except Exception:
|
|
||||||
VORONOI_ENABLED = False
|
|
||||||
|
|
||||||
fcTranslate.apply_language('strings')
|
fcTranslate.apply_language('strings')
|
||||||
if '_' not in builtins.__dict__:
|
if '_' not in builtins.__dict__:
|
||||||
@@ -548,7 +554,7 @@ class ToolLevelling(AppTool, CNCjob):
|
|||||||
al_method = self.ui.al_method_radio.get_value()
|
al_method = self.ui.al_method_radio.get_value()
|
||||||
if al_method == 'v':
|
if al_method == 'v':
|
||||||
if VORONOI_ENABLED is True:
|
if VORONOI_ENABLED is True:
|
||||||
self.generate_voronoi_geometry_2(pts=vor_pts_list)
|
self.generate_voronoi_geometry(pts=vor_pts_list)
|
||||||
# generate Probing GCode
|
# generate Probing GCode
|
||||||
self.probing_gcode_text = self.probing_gcode(storage=self.al_voronoi_geo_storage)
|
self.probing_gcode_text = self.probing_gcode(storage=self.al_voronoi_geo_storage)
|
||||||
else:
|
else:
|
||||||
@@ -736,7 +742,7 @@ class ToolLevelling(AppTool, CNCjob):
|
|||||||
return
|
return
|
||||||
|
|
||||||
new_voronoi = []
|
new_voronoi = []
|
||||||
for p in voronoi_union:
|
for p in voronoi_union.geoms:
|
||||||
new_voronoi.append(p.intersection(env))
|
new_voronoi.append(p.intersection(env))
|
||||||
|
|
||||||
for pt_key in list(self.al_voronoi_geo_storage.keys()):
|
for pt_key in list(self.al_voronoi_geo_storage.keys()):
|
||||||
@@ -744,52 +750,55 @@ class ToolLevelling(AppTool, CNCjob):
|
|||||||
if self.al_voronoi_geo_storage[pt_key]['point'].within(poly):
|
if self.al_voronoi_geo_storage[pt_key]['point'].within(poly):
|
||||||
self.al_voronoi_geo_storage[pt_key]['geo'] = poly
|
self.al_voronoi_geo_storage[pt_key]['geo'] = poly
|
||||||
|
|
||||||
def generate_voronoi_geometry_2(self, pts):
|
# def generate_voronoi_geometry_2(self, pts):
|
||||||
env = self.solid_geo.envelope
|
# env = self.solid_geo.envelope
|
||||||
fact = 1 if self.units == 'MM' else 0.039
|
# fact = 1 if self.units == 'MM' else 0.039
|
||||||
env = env.buffer(fact)
|
# env = env.buffer(fact)
|
||||||
env_poly = voronoi_poly(list(env.exterior.coords))
|
# env_poly = voronoi_poly(tuple(env.exterior.coords))
|
||||||
|
#
|
||||||
new_pts = [[pt.x, pt.y] for pt in pts]
|
# new_pts = [[pt.x, pt.y] for pt in pts]
|
||||||
|
# print(new_pts)
|
||||||
# Initialize the algorithm
|
# print(env_poly)
|
||||||
v = Voronoi(env_poly)
|
#
|
||||||
|
# # Initialize the algorithm
|
||||||
# calculate the Voronoi diagram
|
# v = Voronoi(env_poly)
|
||||||
try:
|
#
|
||||||
v.create_diagram(new_pts)
|
# # calculate the Voronoi diagram
|
||||||
except AttributeError as e:
|
# try:
|
||||||
self.app.log.error("CNCJobObject.generate_voronoi_geometry_2() --> %s" % str(e))
|
# v.create_diagram(new_pts)
|
||||||
new_pts_2 = []
|
# except AttributeError as e:
|
||||||
for pt_index in range(len(new_pts)):
|
# self.app.log.error("CNCJobObject.generate_voronoi_geometry_2() --> %s" % str(e))
|
||||||
new_pts_2.append([
|
# new_pts_2 = []
|
||||||
new_pts[pt_index][0] + random.random() * 1e-03,
|
# for pt_index in range(len(new_pts)):
|
||||||
new_pts[pt_index][1] + random.random() * 1e-03
|
# new_pts_2.append([
|
||||||
])
|
# new_pts[pt_index][0] + random.random() * 1e-03,
|
||||||
|
# new_pts[pt_index][1] + random.random() * 1e-03
|
||||||
try:
|
# ])
|
||||||
v.create_diagram(new_pts_2)
|
#
|
||||||
except Exception:
|
# try:
|
||||||
print("Didn't work.")
|
# v.create_diagram(new_pts_2)
|
||||||
return
|
# except Exception:
|
||||||
|
# print("Didn't work.")
|
||||||
new_voronoi = []
|
# return
|
||||||
for p in v.points:
|
#
|
||||||
p_coords = [(coord.x, coord.y) for coord in p.get_coordinates()]
|
# new_voronoi = []
|
||||||
new_pol = Polygon(p_coords)
|
# for p in v.sites:
|
||||||
new_voronoi.append(new_pol)
|
# # p_coords = [(coord.x, coord.y) for coord in p.get_coordinates()]
|
||||||
|
# p_coords = [(p.x, p.y)]
|
||||||
new_voronoi = MultiPolygon(new_voronoi)
|
# new_pol = Polygon(p_coords)
|
||||||
|
# new_voronoi.append(new_pol)
|
||||||
# new_voronoi = []
|
#
|
||||||
# for p in voronoi_union:
|
# new_voronoi = MultiPolygon(new_voronoi)
|
||||||
# new_voronoi.append(p.intersection(env))
|
#
|
||||||
#
|
# # new_voronoi = []
|
||||||
for pt_key in list(self.al_voronoi_geo_storage.keys()):
|
# # for p in voronoi_union:
|
||||||
for poly in new_voronoi:
|
# # new_voronoi.append(p.intersection(env))
|
||||||
if self.al_voronoi_geo_storage[pt_key]['point'].within(poly) or \
|
# #
|
||||||
self.al_voronoi_geo_storage[pt_key]['point'].intersects(poly):
|
# for pt_key in list(self.al_voronoi_geo_storage.keys()):
|
||||||
self.al_voronoi_geo_storage[pt_key]['geo'] = poly
|
# for poly in new_voronoi:
|
||||||
|
# if self.al_voronoi_geo_storage[pt_key]['point'].within(poly) or \
|
||||||
|
# self.al_voronoi_geo_storage[pt_key]['point'].intersects(poly):
|
||||||
|
# self.al_voronoi_geo_storage[pt_key]['geo'] = poly
|
||||||
|
|
||||||
def generate_bilinear_geometry(self, pts):
|
def generate_bilinear_geometry(self, pts):
|
||||||
self.al_bilinear_geo_storage = pts
|
self.al_bilinear_geo_storage = pts
|
||||||
@@ -878,7 +887,7 @@ class ToolLevelling(AppTool, CNCjob):
|
|||||||
pts_list = []
|
pts_list = []
|
||||||
for k in self.al_voronoi_geo_storage:
|
for k in self.al_voronoi_geo_storage:
|
||||||
pts_list.append(self.al_voronoi_geo_storage[k]['point'])
|
pts_list.append(self.al_voronoi_geo_storage[k]['point'])
|
||||||
self.generate_voronoi_geometry_2(pts=pts_list)
|
self.generate_voronoi_geometry(pts=pts_list)
|
||||||
|
|
||||||
self.probing_gcode_text = self.probing_gcode(self.al_voronoi_geo_storage)
|
self.probing_gcode_text = self.probing_gcode(self.al_voronoi_geo_storage)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ simplejson
|
|||||||
qrcode>=6.1
|
qrcode>=6.1
|
||||||
|
|
||||||
rtree
|
rtree
|
||||||
foronoi>=1.0.3
|
# foronoi>=1.0.3
|
||||||
shapely>=1.8.0
|
shapely>=1.8.0
|
||||||
|
|
||||||
# ###############################
|
# ###############################
|
||||||
|
|||||||
Reference in New Issue
Block a user