some pep 8 formatting and obsolete code removal

pull/200/head
palain 2022-01-18 12:06:07 -04:00
rodzic 304b37df30
commit 3b0450da10
1 zmienionych plików z 11 dodań i 57 usunięć

Wyświetl plik

@ -34,16 +34,11 @@ import numpy
def getPathPatternParallel(o, angle): def getPathPatternParallel(o, angle):
# minx,miny,minz,maxx,maxy,maxz=o.min.x,o.min.y,o.min.z,o.max.x,o.max.y,o.max.z
# ob=o.object
zlevel = 1 zlevel = 1
pathd = o.dist_between_paths pathd = o.dist_between_paths
pathstep = o.dist_along_paths pathstep = o.dist_along_paths
pathchunks = [] pathchunks = []
# progress(o.max.x,stepx)
# progress(o.max.y,stepy)
# angle=(angle/360)*2*math.pi
xm = (o.max.x + o.min.x) / 2 xm = (o.max.x + o.min.x) / 2
ym = (o.max.y + o.min.y) / 2 ym = (o.max.y + o.min.y) / 2
vm = Vector((xm, ym, 0)) vm = Vector((xm, ym, 0))
@ -51,12 +46,7 @@ def getPathPatternParallel(o, angle):
ydim = o.max.y - o.min.y ydim = o.max.y - o.min.y
dim = (xdim + ydim) / 2.0 dim = (xdim + ydim) / 2.0
e = Euler((0, 0, angle)) e = Euler((0, 0, angle))
v = Vector((1, 0, 0))
reverse = False reverse = False
# if o.movement_type=='CONVENTIONAL'
# ar=numpy.array((1.1,1.1))
# ar.resize()
# defaultar=numpy.arange(int(-dim/pathd), int(dim/pathd)).tolist()
if bpy.app.debug_value == 0: # by default off if bpy.app.debug_value == 0: # by default off
# this is the original pattern method, slower, but well tested: # this is the original pattern method, slower, but well tested:
dirvect = Vector((0, 1, 0)) dirvect = Vector((0, 1, 0))
@ -66,7 +56,6 @@ def getPathPatternParallel(o, angle):
for a in range(int(-dim / pathd), for a in range(int(-dim / pathd),
int(dim / pathd)): # this is highly ineffective, computes path2x the area needed... int(dim / pathd)): # this is highly ineffective, computes path2x the area needed...
chunk = camPathChunk([]) chunk = camPathChunk([])
# chunk=camPathChunk(defaultar.copy())
v = Vector((a * pathd, int(-dim / pathstep) * pathstep, 0)) v = Vector((a * pathd, int(-dim / pathstep) * pathstep, 0))
v.rotate(e) v.rotate(e)
v += vm # shifting for the rotation, so pattern rotates around middle... v += vm # shifting for the rotation, so pattern rotates around middle...
@ -75,7 +64,6 @@ def getPathPatternParallel(o, angle):
if v.x > o.min.x and v.x < o.max.x and v.y > o.min.y and v.y < o.max.y: if v.x > o.min.x and v.x < o.max.x and v.y > o.min.y and v.y < o.max.y:
chunk.points.append((v.x, v.y, zlevel)) chunk.points.append((v.x, v.y, zlevel))
# chunk.points[a]=(v.x,v.y,zlevel)
if (reverse and o.movement_type == 'MEANDER') or ( if (reverse and o.movement_type == 'MEANDER') or (
o.movement_type == 'CONVENTIONAL' and o.spindle_rotation_direction == 'CW') or ( o.movement_type == 'CONVENTIONAL' and o.spindle_rotation_direction == 'CW') or (
o.movement_type == 'CLIMB' and o.spindle_rotation_direction == 'CCW'): o.movement_type == 'CLIMB' and o.spindle_rotation_direction == 'CCW'):
@ -84,7 +72,9 @@ def getPathPatternParallel(o, angle):
if len(chunk.points) > 0: if len(chunk.points) > 0:
pathchunks.append(chunk) pathchunks.append(chunk)
if len(pathchunks) > 1 and reverse and o.parallel_step_back and not o.use_layers: if len(pathchunks) > 1 and reverse and o.parallel_step_back and not o.use_layers:
# parallel step back - for finishing, best with climb movement, saves cutter life by going into material with climb, while using move back on the surface to improve finish(which would otherwise be a conventional move in the material) # parallel step back - for finishing, best with climb movement, saves cutter life by going into
# material with climb, while using move back on the surface to improve finish
# (which would otherwise be a conventional move in the material)
if o.movement_type == 'CONVENTIONAL' or o.movement_type == 'CLIMB': if o.movement_type == 'CONVENTIONAL' or o.movement_type == 'CLIMB':
pathchunks[-2].points.reverse() pathchunks[-2].points.reverse()
@ -97,30 +87,20 @@ def getPathPatternParallel(o, angle):
else: # alternative algorithm with numpy, didn't work as should so blocked now... else: # alternative algorithm with numpy, didn't work as should so blocked now...
v = Vector((0, 1, 0)) v = Vector((0, 1, 0))
# e.z=-e.z
v.rotate(e) v.rotate(e)
e1 = Euler((0, 0, -math.pi / 2)) e1 = Euler((0, 0, -math.pi / 2))
v1 = v.copy() v1 = v.copy()
v1.rotate(e1) v1.rotate(e1)
a1res = int(dim / pathd) - int(-dim / pathd)
a2res = int(dim / pathstep) - int(-dim / pathstep)
axis_across_paths = numpy.array((numpy.arange(int(-dim / pathd), int(dim / pathd)) * pathd * v1.x + xm, axis_across_paths = numpy.array((numpy.arange(int(-dim / pathd), int(dim / pathd)) * pathd * v1.x + xm,
numpy.arange(int(-dim / pathd), int(dim / pathd)) * pathd * v1.y + ym, numpy.arange(int(-dim / pathd), int(dim / pathd)) * pathd * v1.y + ym,
numpy.arange(int(-dim / pathd), int(dim / pathd)) * 0)) numpy.arange(int(-dim / pathd), int(dim / pathd)) * 0))
# axis_across_paths=axis_across_paths.swapaxes(0,1)
# progress(axis_across_paths)
axis_along_paths = numpy.array((numpy.arange(int(-dim / pathstep), int(dim / pathstep)) * pathstep * v.x, axis_along_paths = numpy.array((numpy.arange(int(-dim / pathstep), int(dim / pathstep)) * pathstep * v.x,
numpy.arange(int(-dim / pathstep), int(dim / pathstep)) * pathstep * v.y, numpy.arange(int(-dim / pathstep), int(dim / pathstep)) * pathstep * v.y,
numpy.arange(int(-dim / pathstep), numpy.arange(int(-dim / pathstep),
int(dim / pathstep)) * 0 + zlevel)) # rotate this first int(dim / pathstep)) * 0 + zlevel)) # rotate this first
progress(axis_along_paths) progress(axis_along_paths)
# axis_along_paths = axis_along_paths.swapaxes(0,1)
# progress(axis_along_paths)
# chunks=numpy.array((1.0))
# chunks.resize(3,a1res,a2res)
chunks = [] chunks = []
for a in range(0, len(axis_across_paths[0])): for a in range(0, len(axis_across_paths[0])):
# progress(chunks[a,...,...].shape) # progress(chunks[a,...,...].shape)
@ -133,8 +113,6 @@ def getPathPatternParallel(o, angle):
# progress(nax.shape) # progress(nax.shape)
# progress(chunks.shape) # progress(chunks.shape)
# progress(chunks[...,a,...].shape) # progress(chunks[...,a,...].shape)
# if v.x>o.min.x and v.x<o.max.x and v.y>o.min.y and v.y<o.max.y:
xfitmin = nax[0] > o.min.x xfitmin = nax[0] > o.min.x
xfitmax = nax[0] < o.max.x xfitmax = nax[0] < o.max.x
xfit = xfitmin & xfitmax xfit = xfitmin & xfitmax
@ -146,18 +124,11 @@ def getPathPatternParallel(o, angle):
nax = numpy.array([nax[0][yfit], nax[1][yfit], nax[2][yfit]]) nax = numpy.array([nax[0][yfit], nax[1][yfit], nax[2][yfit]])
chunks.append(nax.swapaxes(0, 1)) chunks.append(nax.swapaxes(0, 1))
# chunks # chunks
# print(chunks)
# chunks=chunks.swapaxes(0,1)
# chunks=chunks.swapaxes(1,2)
# print(chunks)
pathchunks = [] pathchunks = []
for ch in chunks: for ch in chunks:
ch = ch.tolist() ch = ch.tolist()
pathchunks.append(camPathChunk(ch)) pathchunks.append(camPathChunk(ch))
# print (ch) # print (ch)
return pathchunks return pathchunks
@ -235,8 +206,6 @@ def getPathPattern(operation):
for si in range(0, len(chunk.points)): for si in range(0, len(chunk.points)):
s = chunk.points[si] s = chunk.points[si]
chunk.points[si] = (o.max.x + o.min.x - s[0], s[1], s[2]) chunk.points[si] = (o.max.x + o.min.x - s[0], s[1], s[2])
# if insideout:
# chunk.reverse()
pathchunks = [chunk] pathchunks = [chunk]
elif o.strategy == 'SPIRAL': elif o.strategy == 'SPIRAL':
@ -281,7 +250,6 @@ def getPathPattern(operation):
s = chunk.points[si] s = chunk.points[si]
chunk.points[si] = (o.max.x + o.min.x - s[0], s[1], s[2]) chunk.points[si] = (o.max.x + o.min.x - s[0], s[1], s[2])
elif o.strategy == 'CIRCLES': elif o.strategy == 'CIRCLES':
pathd = o.dist_between_paths pathd = o.dist_between_paths
@ -291,9 +259,6 @@ def getPathPattern(operation):
rx = o.max.x - o.min.x rx = o.max.x - o.min.x
ry = o.max.y - o.min.y ry = o.max.y - o.min.y
maxr = math.sqrt(rx * rx + ry * ry) maxr = math.sqrt(rx * rx + ry * ry)
# x=pathd/4
# y=pathd/4
v = Vector((1, 0, 0))
# progress(x,y,midx,midy) # progress(x,y,midx,midy)
e = Euler((0, 0, 0)) e = Euler((0, 0, 0))
@ -304,8 +269,6 @@ def getPathPattern(operation):
r = 0 r = 0
while r < maxr: while r < maxr:
# v.x=x-midx
# v.y=y-midy
r += pathd r += pathd
chunk = camPathChunk([]) chunk = camPathChunk([])
firstchunk = chunk firstchunk = chunk
@ -357,24 +320,21 @@ def getPathPattern(operation):
pathchunks = [] pathchunks = []
chunks = [] chunks = []
for p in polys: for p in polys:
p = p.buffer(-o.dist_between_paths / 10, p = p.buffer(-o.dist_between_paths / 10, o.circle_detail)
o.circle_detail) # first, move a bit inside, because otherwise the border samples go crazy very often changin between hit/non hit and making too many jumps in the path. # first, move a bit inside, because otherwise the border samples go crazy very often changin between
# hit/non hit and making too many jumps in the path.
chunks.extend(shapelyToChunks(p, 0)) chunks.extend(shapelyToChunks(p, 0))
pathchunks.extend(chunks) pathchunks.extend(chunks)
lastchunks = chunks lastchunks = chunks
firstchunks = chunks firstchunks = chunks
# for ch in chunks:
# if len(ch.points)>2:
# polys.extend()
approxn = (min(maxx - minx, maxy - miny) / o.dist_between_paths) / 2 approxn = (min(maxx - minx, maxy - miny) / o.dist_between_paths) / 2
i = 0 i = 0
for porig in polys: for porig in polys:
p = porig p = porig
while not p.is_empty: #:p.nPoints()>0: while not p.is_empty:
p = p.buffer(-o.dist_between_paths, o.circle_detail) p = p.buffer(-o.dist_between_paths, o.circle_detail)
if not p.is_empty: if not p.is_empty:
@ -399,7 +359,9 @@ def getPathPattern(operation):
dist = d dist = d
if a == int(o.cutter_diameter / 2 / o.dist_between_paths): if a == int(o.cutter_diameter / 2 / o.dist_between_paths):
if o.use_exact: if o.use_exact:
dist += o.pixsize * 0.85 # this is here only because silhouette is still done with zbuffer method, even if we use bullet collisions. dist += o.pixsize * 0.85
# this is here only because silhouette is still done with zbuffer method,
# even if we use bullet collisions.
else: else:
dist += o.pixsize * 2.5 dist += o.pixsize * 2.5
p = p.buffer(dist, o.circle_detail) p = p.buffer(dist, o.circle_detail)
@ -422,7 +384,6 @@ def getPathPattern(operation):
o.movement_type == 'CONVENTIONAL' and o.spindle_rotation_direction == 'CCW'): o.movement_type == 'CONVENTIONAL' and o.spindle_rotation_direction == 'CCW'):
chunk.points.reverse() chunk.points.reverse()
# parentChildPoly(pathchunks,pathchunks,o)
chunksRefine(pathchunks, o) chunksRefine(pathchunks, o)
progress(time.time() - t) progress(time.time() - t)
return pathchunks return pathchunks
@ -452,11 +413,7 @@ def getPathPattern4axis(operation):
o.max.z = o.maxz o.max.z = o.maxz
# set radius for all types of operation # set radius for all types of operation
m1 = max(abs(o.min[a2]), abs(o.max[a2])) radius = max(o.max.z, 0.0001)
m2 = max(abs(o.min[a3]), abs(o.max[a3]))
radius = max(o.max.z,
0.0001) # math.sqrt(m1*m1+m2*m2)+operation.cutter_diameter*2#max radius estimation, but the minimum is object
radiusend = o.min.z radiusend = o.min.z
mradius = max(radius, radiusend) mradius = max(radius, radiusend)
@ -543,8 +500,6 @@ def getPathPattern4axis(operation):
chunk.rotations.append(rot) chunk.rotations.append(rot)
chunk.depth = radiusend - radius chunk.depth = radiusend - radius
# last point = first
pathchunks.append(chunk) pathchunks.append(chunk)
if (reverse and o.movement_type == 'MEANDER') or ( if (reverse and o.movement_type == 'MEANDER') or (
@ -584,7 +539,6 @@ def getPathPattern4axis(operation):
cutterend.rotate(e) cutterend.rotate(e)
chunk.depth = radiusend - radius chunk.depth = radiusend - radius
# last point = first
pathchunks.append(chunk) pathchunks.append(chunk)
# print(chunk.startpoints) # print(chunk.startpoints)