Commit b293a66a authored by sumpfralle's avatar sumpfralle

removed the necessity for a lock during collision detection (for multiprocessing)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@733 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent ef92a990
...@@ -94,15 +94,11 @@ class BaseCutter(object): ...@@ -94,15 +94,11 @@ class BaseCutter(object):
def get_required_distance(self): def get_required_distance(self):
return self.required_distance return self.required_distance
def moveto(self, location, keep_lock=False): def moveto(self, location):
# "moveto" is used for collision detection calculation. # "moveto" is used for collision detection calculation.
# We need to prevent multiple changes during one calculation.
pycam.Utils.threading.acquire_lock()
self.location = location self.location = location
for shape, set_pos_func in self.shape.values(): for shape, set_pos_func in self.shape.values():
set_pos_func(location.x, location.y, location.z) set_pos_func(location.x, location.y, location.z)
if not keep_lock:
pycam.Utils.threading.release_lock()
def intersect(self, direction, triangle, start=None): def intersect(self, direction, triangle, start=None):
raise NotImplementedError("Inherited class of BaseCutter does not " \ raise NotImplementedError("Inherited class of BaseCutter does not " \
......
...@@ -60,12 +60,10 @@ def get_free_paths_triangles(model, cutter, p1, p2, return_triangles=False): ...@@ -60,12 +60,10 @@ def get_free_paths_triangles(model, cutter, p1, p2, return_triangles=False):
maxy + cutter.distance_radius, INFINITE) maxy + cutter.distance_radius, INFINITE)
for t in triangles: for t in triangles:
cutter.moveto(p1, keep_lock=True) (cl1, d1, cp1) = cutter.intersect(backward, t, start=p1)
(cl1, d1, cp1) = cutter.intersect(backward, t)
(cl2, d2, cp2) = cutter.intersect(forward, t)
pycam.Utils.threading.release_lock()
if cl1: if cl1:
hits.append(Hit(cl1, cp1, t, -d1, backward)) hits.append(Hit(cl1, cp1, t, -d1, backward))
(cl2, d2, cp2) = cutter.intersect(forward, t, start=p1)
if cl2: if cl2:
hits.append(Hit(cl2, cp2, t, d2, forward)) hits.append(Hit(cl2, cp2, t, d2, forward))
...@@ -221,14 +219,12 @@ def get_max_height_triangles(model, cutter, x, y, minz, maxz, order=None, ...@@ -221,14 +219,12 @@ def get_max_height_triangles(model, cutter, x, y, minz, maxz, order=None,
box_z_max = maxz box_z_max = maxz
triangles = model.triangles(box_x_min, box_y_min, box_z_min, box_x_max, triangles = model.triangles(box_x_min, box_y_min, box_z_min, box_x_max,
box_y_max, box_z_max) box_y_max, box_z_max)
cutter.moveto(p, keep_lock=True)
for t in triangles: for t in triangles:
cut = cutter.drop(t) cut = cutter.drop(t, start=p)
if cut and ((height_max is None) or (cut.z > height_max)): if cut and ((height_max is None) or (cut.z > height_max)):
height_max = cut.z height_max = cut.z
cut_max = cut cut_max = cut
triangle_max = t triangle_max = t
pycam.Utils.threading.release_lock()
# don't do a complete boundary check for the height # don't do a complete boundary check for the height
# this avoids zero-cuts for models that exceed the bounding box height # this avoids zero-cuts for models that exceed the bounding box height
if not cut_max or cut_max.z < minz + epsilon: if not cut_max or cut_max.z < minz + epsilon:
......
...@@ -37,11 +37,9 @@ __multiprocessing = None ...@@ -37,11 +37,9 @@ __multiprocessing = None
# needs to be initialized, if multiprocessing is enabled # needs to be initialized, if multiprocessing is enabled
__num_of_processes = None __num_of_processes = None
__lock = None
def init_threading(number_of_processes=None): def init_threading(number_of_processes=None):
global __multiprocessing, __num_of_processes, __lock global __multiprocessing, __num_of_processes
try: try:
import multiprocessing import multiprocessing
mp_is_available = True mp_is_available = True
...@@ -67,7 +65,6 @@ def init_threading(number_of_processes=None): ...@@ -67,7 +65,6 @@ def init_threading(number_of_processes=None):
if __multiprocessing is False: if __multiprocessing is False:
log.info("Disabled multi-threading") log.info("Disabled multi-threading")
else: else:
__lock = multiprocessing.Lock()
log.info("Enabled multi-threading with %d parallel processes" % __num_of_processes) log.info("Enabled multi-threading with %d parallel processes" % __num_of_processes)
...@@ -92,11 +89,3 @@ def run_in_parallel(func, args, unordered=False, disable_multiprocessing=False): ...@@ -92,11 +89,3 @@ def run_in_parallel(func, args, unordered=False, disable_multiprocessing=False):
for arg in args: for arg in args:
yield func(arg) yield func(arg)
def acquire_lock():
if __multiprocessing:
__lock.acquire()
def release_lock():
if __multiprocessing:
__lock.release()
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