Skip to content

Commit

Permalink
Update to v0.38
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhouser committed Nov 24, 2019
1 parent fe384ce commit 41f7479
Show file tree
Hide file tree
Showing 9 changed files with 1,125 additions and 441 deletions.
12 changes: 12 additions & 0 deletions Change_Log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,15 @@ Version 0.35:
Version 0.36:
- Fixed rapid motion problems during and at end of raster engraving with certain settings. (Especially when raster engraving bottom up.)

Version 0.37:
- Fixed another occurrence of "float() argument must be a string or number error" for some SVG files.

Version 0.38:
- Fixed call to Inkscape so it works with Inkscape Version 1.0 Beta
- Replaced USB menu with Tools menu and added additional tools (trace and compute raster time)
- Added Trace boundary option to Tools menu (traces around convex hull of the design)
- Added shortcut keys so that number pad can be used to control laser head position
- Added post run options in General settings (home, beep, display report, execute batch file)
- Improved time estimates for raster engraving (Now uses actual laser path data.)
- Added option to control timeout time for Inkscape subprocess execution
- Added command line option for smaller display (-p or --pi)
70 changes: 70 additions & 0 deletions convex_hull.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
2D Convex Hull Code from Wikibooks
https://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain
"""

class hull2D:

def convex_hull(self,points):
"""Computes the convex hull of a set of 2D points.
Input: an iterable sequence of (x, y) pairs representing the points.
Output: a list of vertices of the convex hull in counter-clockwise order,
starting from the vertex with the lexicographically smallest coordinates.
Implements Andrew's monotone chain algorithm. O(n log n) complexity.
"""

# Sort the points lexicographically (tuples are compared lexicographically).
# Remove duplicates to detect the case we have just one unique point.
points = sorted(set(points))

# Boring case: no points or a single point, possibly repeated multiple times.
if len(points) <= 1:
return points

# 2D cross product of OA and OB vectors, i.e. z-component of their 3D cross product.
# Returns a positive value, if OAB makes a counter-clockwise turn,
# negative for clockwise turn, and zero if the points are collinear.
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])

# Build lower hull
lower = []
for p in points:
while len(lower) >= 2 and cross(lower[-2], lower[-1], p) <= 0:
lower.pop()
lower.append(p)

# Build upper hull
upper = []
for p in reversed(points):
while len(upper) >= 2 and cross(upper[-2], upper[-1], p) <= 0:
upper.pop()
upper.append(p)

# Concatenation of the lower and upper hulls gives the convex hull.
# Last point of each list is omitted because it is repeated at the beginning of the other list.
return lower[:-1] + upper[:-1]


def convexHullecoords(self,ecoords):
p=[]
for line in ecoords:
p.append((line[0],line[1]))

hull_data = self.convex_hull(p)
ecoords=[]
for i in range(0,len(hull_data)):
ecoords.append([hull_data[i][0],hull_data[i][1],1])
ecoords.append(ecoords[0])
return ecoords

######################################################################


if __name__ == '__main__':
my_hull=hull2D()
p = [(1,1),(0,3),(0,0),(4,5),(10,10)]
c = my_hull.convex_hull(p)
print(p)
print(c)
13 changes: 9 additions & 4 deletions ecoords.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ def reset(self):

def reset_path(self):
self.ecoords = []
self.len = 0
self.len = None
self.move = 0
self.sorted = False
self.rpaths = False
self.bounds = (0,0,0,0)
self.gcode_time = 0
self.gcode_time = 0
self.hull_coords= []
self.n_scanlines= 0

def make_ecoords(self,coords,scale=1):
self.reset()
Expand Down Expand Up @@ -82,12 +85,14 @@ def set_ecoords(self,ecoords,data_sorted=False):

def set_image(self,PIL_image):
self.image = PIL_image
self.reset_path()

def computeEcoordsLen(self):
def computeEcoordsLen(self):
xmax, ymax = -1e10, -1e10
xmin, ymin = 1e10, 1e10

if self.ecoords == [] :
if self.ecoords == [] :
self.len=0
return
on = 0
move = 0
Expand Down
7 changes: 4 additions & 3 deletions egv.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ def make_egv_data(self, ecoords_in,
update_gui=None,
stop_calc=None,
FlipXoffset=0,
Rapid_Feed_Rate=0):
Rapid_Feed_Rate=0,
use_laser=True):

#print("make_egv_data",Rapid_Feed_Rate,len(ecoords_in))
#print("Rapid_Feed_Rate=",Rapid_Feed_Rate)
Expand All @@ -305,7 +306,7 @@ def make_egv_data(self, ecoords_in,

########################################################
variable_feed_scale=None
Spindle = True
Spindle = True and use_laser
if Feed==None:
variable_feed_scale = 25.4/60.0
Feed = round(ecoords_in[0][3]*variable_feed_scale,2)
Expand Down Expand Up @@ -360,7 +361,7 @@ def make_egv_data(self, ecoords_in,
if laser:
if variable_feed_scale!=None:
Feed_current = round(ecoords_in[i][3]*variable_feed_scale,2)
Spindle = ecoords_in[i][4] > 0
Spindle = ecoords_in[i][4] > 0 and use_laser
if Feed != Feed_current:
Feed = Feed_current
self.flush()
Expand Down
Loading

0 comments on commit 41f7479

Please sign in to comment.