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: ...@@ -50,20 +50,18 @@ class PushCutter:
def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz, draw_callback=None): def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz, draw_callback=None):
# calculate the number of steps # calculate the number of steps
num_of_layers = 1 + math.ceil((maxz - minz) / dz) num_of_layers = 1 + int(math.ceil(abs(maxz - minz) / dz))
lines_per_layer = 0 dz = abs(maxz - minz) / (num_of_layers - 1)
lines_per_layer = 0
if dx != 0: if dx != 0:
lines_per_layer += 1 + math.ceil((maxx - minx) / dx) x_lines_per_layer = 1 + int(math.ceil(abs(maxx - minx) / dx))
self.pa.dx = dx dx = abs(maxx - minx) / (x_lines_per_layer - 1)
else: lines_per_layer += x_lines_per_layer
self.pa.dx = dy
if dy != 0: if dy != 0:
lines_per_layer += 1 + math.ceil((maxy - miny) / dy) y_lines_per_layer = 1 + int(math.ceil(abs(maxy - miny) / dy))
self.pa.dy = dy dy = abs(maxy - miny) / (y_lines_per_layer - 1)
else: lines_per_layer += y_lines_per_layer
self.pa.dy = dx
progress_counter = ProgressCounter(num_of_layers * lines_per_layer) progress_counter = ProgressCounter(num_of_layers * lines_per_layer)
...@@ -73,113 +71,70 @@ class PushCutter: ...@@ -73,113 +71,70 @@ class PushCutter:
current_layer = 0 current_layer = 0
if self.physics is None: z_steps = [(maxz - i * dz) for i in range(num_of_layers)]
GenerateToolPathSlice = self.GenerateToolPathSlice_triangles for z in z_steps:
else:
GenerateToolPathSlice = self.GenerateToolPathSlice_ode
last_loop = False
while z >= minz:
# update the progress bar and check, if we should cancel the process # update the progress bar and check, if we should cancel the process
if draw_callback and draw_callback(text="PushCutter: processing" \ if draw_callback and draw_callback(text="PushCutter: processing" \
+ " layer %d/%d" % (current_layer, num_of_layers)): + " layer %d/%d" % (current_layer, num_of_layers)):
# cancel immediately # cancel immediately
z = minz - 1 break
if dy > 0: if dy > 0:
self.pa.new_direction(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) draw_callback, progress_counter)
self.pa.end_direction() self.pa.end_direction()
if dx > 0: if dx > 0:
self.pa.new_direction(1) 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) draw_callback, progress_counter)
self.pa.end_direction() self.pa.end_direction()
self.pa.finish() self.pa.finish()
if self.pa.paths: if self.pa.paths:
paths += 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 current_layer += 1
return paths 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): draw_callback=None, progress_counter=None):
""" only dx or (exclusive!) dy may be bigger than zero """ only dx or (exclusive!) dy may be bigger than zero
""" """
# max_deviation_x = dx/accuracy # max_deviation_x = dx/accuracy
accuracy = 20 accuracy = 20
max_depth = 20 max_depth = 20
x = minx
y = miny
# calculate the required number of steps in each direction # calculate the required number of steps in each direction
if dx > 0: if dx > 0:
depth_x = math.log(accuracy * (maxx-minx) / dx) / math.log(2) depth_x = math.log(accuracy * abs(maxx-minx) / dx) / math.log(2)
depth_x = max(math.ceil(int(depth_x)), 4) depth_x = max(int(math.ceil(depth_x)), 4)
depth_x = min(depth_x, max_depth) 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: else:
depth_y = math.log(accuracy * (maxy-miny) / dy) / math.log(2) 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) 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 for x, y in zip(x_steps, y_steps):
while (x <= maxx) and (y <= maxy):
points = []
self.pa.new_scanline() self.pa.new_scanline()
if dx > 0: if dx > 0:
if self.physics:
points = get_free_horizontal_paths_ode(self.physics, x, x, miny, maxy, z, depth=depth_x) points = get_free_horizontal_paths_ode(self.physics, x, x, miny, maxy, z, depth=depth_x)
else: else:
points = get_free_horizontal_paths_ode(self.physics, minx, maxx, y, y, z, depth=depth_y)
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) points = get_free_horizontal_paths_triangles(self.model, self.cutter, x, x, miny, maxy, z)
else:
if self.physics:
points = get_free_horizontal_paths_ode(self.physics, minx, maxx, y, y, z, depth=depth_y)
else: else:
points = get_free_horizontal_paths_triangles(self.model, self.cutter, minx, maxx, y, y, z) points = get_free_horizontal_paths_triangles(self.model, self.cutter, minx, maxx, y, y, z)
...@@ -189,24 +144,6 @@ class PushCutter: ...@@ -189,24 +144,6 @@ class PushCutter:
self.cutter.moveto(p) self.cutter.moveto(p)
if draw_callback: if draw_callback:
draw_callback(tool_position=p) 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() self.pa.end_scanline()
# update the progress counter # 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