Commit 593cc9d2 authored by sumpfralle's avatar sumpfralle

further code simplification


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@360 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 96c99d84
......@@ -50,20 +50,18 @@ class PushCutter:
def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz, draw_callback=None):
# calculate the number of steps
num_of_layers = 1 + math.ceil((maxz - minz) / dz)
lines_per_layer = 0
num_of_layers = 1 + int(math.ceil(abs(maxz - minz) / dz))
dz = abs(maxz - minz) / (num_of_layers - 1)
lines_per_layer = 0
if dx != 0:
lines_per_layer += 1 + math.ceil((maxx - minx) / dx)
self.pa.dx = dx
else:
self.pa.dx = dy
x_lines_per_layer = 1 + int(math.ceil(abs(maxx - minx) / dx))
dx = abs(maxx - minx) / (x_lines_per_layer - 1)
lines_per_layer += x_lines_per_layer
if dy != 0:
lines_per_layer += 1 + math.ceil((maxy - miny) / dy)
self.pa.dy = dy
else:
self.pa.dy = dx
y_lines_per_layer = 1 + int(math.ceil(abs(maxy - miny) / dy))
dy = abs(maxy - miny) / (y_lines_per_layer - 1)
lines_per_layer += y_lines_per_layer
progress_counter = ProgressCounter(num_of_layers * lines_per_layer)
......@@ -73,140 +71,79 @@ class PushCutter:
current_layer = 0
if self.physics is None:
GenerateToolPathSlice = self.GenerateToolPathSlice_triangles
else:
GenerateToolPathSlice = self.GenerateToolPathSlice_ode
last_loop = False
while z >= minz:
z_steps = [(maxz - i * dz) for i in range(num_of_layers)]
for z in z_steps:
# update the progress bar and check, if we should cancel the process
if draw_callback and draw_callback(text="PushCutter: processing" \
+ " layer %d/%d" % (current_layer, num_of_layers)):
# cancel immediately
z = minz - 1
break
if dy > 0:
self.pa.new_direction(0)
GenerateToolPathSlice(minx, maxx, miny, maxy, z, 0, dy,
self.GenerateToolPathSlice(minx, maxx, miny, maxy, z, 0, dy,
draw_callback, progress_counter)
self.pa.end_direction()
if dx > 0:
self.pa.new_direction(1)
GenerateToolPathSlice(minx, maxx, miny, maxy, z, dx, 0,
self.GenerateToolPathSlice(minx, maxx, miny, maxy, z, dx, 0,
draw_callback, progress_counter)
self.pa.end_direction()
self.pa.finish()
if self.pa.paths:
paths += self.pa.paths
z -= dz
if (z < minz) and not last_loop:
# never skip the outermost bounding limit - reduce the step size if required
z = minz
# stop after the next loop
last_loop = True
current_layer += 1
return paths
def GenerateToolPathSlice_ode(self, minx, maxx, miny, maxy, z, dx, dy,
def GenerateToolPathSlice(self, minx, maxx, miny, maxy, z, dx, dy,
draw_callback=None, progress_counter=None):
""" only dx or (exclusive!) dy may be bigger than zero
"""
# max_deviation_x = dx/accuracy
accuracy = 20
max_depth = 20
x = minx
y = miny
# calculate the required number of steps in each direction
if dx > 0:
depth_x = math.log(accuracy * (maxx-minx) / dx) / math.log(2)
depth_x = max(math.ceil(int(depth_x)), 4)
depth_x = math.log(accuracy * abs(maxx-minx) / dx) / math.log(2)
depth_x = max(int(math.ceil(depth_x)), 4)
depth_x = min(depth_x, max_depth)
num_of_x_lines = 1 + int(math.ceil(abs(maxx - minx) / dx))
x_step = abs(maxx - minx) / (num_of_x_lines - 1)
x_steps = [minx + i * x_step for i in range(num_of_x_lines)]
y_steps = [miny] * num_of_x_lines
else:
depth_y = math.log(accuracy * (maxy-miny) / dy) / math.log(2)
depth_y = max(math.ceil(int(depth_y)), 4)
depth_y = max(int(math.ceil(depth_y)), 4)
depth_y = min(depth_y, max_depth)
num_of_y_lines = 1 + int(math.ceil(abs(maxy - miny) / dy))
y_step = abs(maxy - miny) / (num_of_y_lines - 1)
y_steps = [miny + i * y_step for i in range(num_of_y_lines)]
x_steps = [minx] * num_of_y_lines
last_loop = False
while (x <= maxx) and (y <= maxy):
points = []
for x, y in zip(x_steps, y_steps):
self.pa.new_scanline()
if dx > 0:
points = get_free_horizontal_paths_ode(self.physics, x, x, miny, maxy, z, depth=depth_x)
if self.physics:
points = get_free_horizontal_paths_ode(self.physics, x, x, miny, maxy, z, depth=depth_x)
else:
points = get_free_horizontal_paths_triangles(self.model, self.cutter, x, x, miny, maxy, z)
else:
points = get_free_horizontal_paths_ode(self.physics, minx, maxx, y, y, z, depth=depth_y)
if self.physics:
points = get_free_horizontal_paths_ode(self.physics, minx, maxx, y, y, z, depth=depth_y)
else:
points = get_free_horizontal_paths_triangles(self.model, self.cutter, minx, maxx, y, y, z)
for p in points:
self.pa.append(p)
if points:
self.cutter.moveto(points[-1])
if draw_callback:
draw_callback(tool_position=points[-1])
self.pa.end_scanline()
if dx > 0:
x += dx
if (x > maxx) and not last_loop:
last_loop = True
x = maxx
else:
y += dy
if (y > maxy) and not last_loop:
last_loop = True
y = maxy
# update the progress counter
if not progress_counter is None:
progress_counter.next()
if draw_callback:
draw_callback(percent=progress_counter.get_percent())
def GenerateToolPathSlice_triangles(self, minx, maxx, miny, maxy, z, dx, dy,
draw_callback=None, progress_counter=None):
x = minx
y = miny
last_loop = False
while x <= maxx and y <= maxy:
self.pa.new_scanline()
if dx > 0:
points = get_free_horizontal_paths_triangles(self.model, self.cutter, x, x, miny, maxy, z)
else:
points = get_free_horizontal_paths_triangles(self.model, self.cutter, minx, maxx, y, y, z)
if points:
for p in points:
self.pa.append(p)
self.cutter.moveto(p)
if draw_callback:
draw_callback(tool_position=p)
if dx != 0:
x += dx
# never skip the outermost bounding limit - reduce the step size if required
if (x > maxx) and not last_loop:
x = maxx
last_loop = True
else:
x = minx
if dy != 0:
y += dy
# never skip the outermost bounding limit - reduce the step size if required
if (y > maxy) and not last_loop:
y = maxy
last_loop = True
else:
y = miny
self.pa.end_scanline()
# update the progress counter
......
Markdown is supported
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