Commit 43896244 authored by sumpfralle's avatar sumpfralle

added support for the multiprocessing module (uses multiple processes for...

added support for the multiprocessing module (uses multiple processes for calculating ContourFollow toolpaths)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@725 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 56cee7f2
...@@ -42,6 +42,34 @@ _DEBUG_DISBALE_WATERLINE_SHIFT = False ...@@ -42,6 +42,34 @@ _DEBUG_DISBALE_WATERLINE_SHIFT = False
log = pycam.Utils.log.get_logger() log = pycam.Utils.log.get_logger()
# We need to use a global function here - otherwise it does not work with
# the multiprocessing Pool.
def _process_one_triangle((obj, triangle, z)):
result = []
if id(triangle) in obj._processed_triangles:
# skip triangles that are known to cause no collision
return result
# ignore triangles below the z level
if triangle.maxz < z:
# Case 1a
return result
# ignore triangles pointing upwards or downwards
if triangle.normal.cross(obj._up_vector).norm == 0:
# Case 1b
return result
edge_collisions = obj.get_collision_waterline_of_triangle(triangle, z)
if not edge_collisions:
return result
for cutter_location, edge in edge_collisions:
shifted_edge = obj.get_shifted_waterline(edge, cutter_location)
if not shifted_edge is None:
if _DEBUG_DISBALE_WATERLINE_SHIFT:
result.append((edge, edge))
else:
result.append((edge, shifted_edge))
return result
class CollisionPaths: class CollisionPaths:
def __init__(self): def __init__(self):
...@@ -256,33 +284,29 @@ class ContourFollow: ...@@ -256,33 +284,29 @@ class ContourFollow:
lines = [] lines = []
waterline_triangles = CollisionPaths() waterline_triangles = CollisionPaths()
projected_waterlines = [] projected_waterlines = []
for triangle in self.model.triangles(minx=minx, miny=miny, maxx=maxx, maxy=maxy): triangles = self.model.triangles(minx=minx, miny=miny, maxx=maxx,
if id(triangle) in self._processed_triangles: maxy=maxy)
# skip triangles that are known to cause no collision try:
continue # try a multi-threading approach to use multiple CPUs
if not progress_counter is None: import multiprocessing
if progress_counter.increment(): # use the number of available CPUs
# quit requested pool = multiprocessing.Pool()
break results_it = pool.imap_unordered(_process_one_triangle,
# ignore triangles below the z level [(self, t, z) for t in triangles])
if triangle.maxz < z: except ImportError:
# Case 1a # use a single-threaded approach
continue def single_generator(triangles):
# ignore triangles pointing upwards or downwards for t in triangles:
if triangle.normal.cross(self._up_vector).norm == 0: # an iterator is expected - thus we use a generator
# Case 1b yield _process_one_triangle((self, t, z))
continue results_it = single_generator(triangles)
edge_collisions = self.get_collision_waterline_of_triangle(triangle, z) for result in results_it:
if not edge_collisions: for edge, shifted_edge in result:
continue waterline_triangles.add(edge, shifted_edge)
for cutter_location, edge in edge_collisions: if (not progress_counter is None) \
shifted_edge = self.get_shifted_waterline(edge, cutter_location) and (progress_counter.increment()):
if shifted_edge is None: # quit requested
continue break
if _DEBUG_DISBALE_WATERLINE_SHIFT:
waterline_triangles.add(edge, edge)
else:
waterline_triangles.add(edge, shifted_edge)
if not _DEBUG_DISABLE_EXTEND_LINES: if not _DEBUG_DISABLE_EXTEND_LINES:
waterline_triangles.extend_shifted_lines() waterline_triangles.extend_shifted_lines()
result = [] result = []
......
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