Funed arranger for better performance. CURA-3239

This commit is contained in:
Jack Ha 2017-03-30 17:26:56 +02:00
parent 099752125b
commit 9db816b0fc
2 changed files with 10 additions and 9 deletions

View file

@ -124,13 +124,13 @@ class Arrange:
return np.sum(prio_slice[np.where(shape_arr.arr == 1)])
## Find "best" spot
def bestSpot(self, shape_arr, start_prio = 0):
def bestSpot(self, shape_arr, start_prio = 0, step = 1):
start_idx_list = np.where(self._priority_unique_values == start_prio)
if start_idx_list:
start_idx = start_idx_list[0]
else:
start_idx = 0
for prio in self._priority_unique_values[start_idx:]:
for prio in self._priority_unique_values[start_idx::step]:
tryout_idx = np.where(self._priority == prio)
for idx in range(len(tryout_idx[0])):
x = tryout_idx[0][idx]

View file

@ -894,7 +894,7 @@ class CuraApplication(QtApplication):
return offset_shape_arr, hull_shape_arr
@classmethod
def _findNodePlacements(cls, arranger, node, offset_shape_arr, hull_shape_arr, count = 1):
def _findNodePlacements(cls, arranger, node, offset_shape_arr, hull_shape_arr, count = 1, step = 1):
# offset_shape_arr, hull_shape_arr, arranger -> nodes, arranger
nodes = []
start_prio = 0
@ -903,7 +903,7 @@ class CuraApplication(QtApplication):
Logger.log("d", " # Finding spot for %s" % new_node)
x, y, penalty_points, start_prio = arranger.bestSpot(
offset_shape_arr, start_prio = start_prio)
offset_shape_arr, start_prio = start_prio, step = step)
transformation = new_node._transformation
if x is not None: # We could find a place
transformation._data[0][3] = x
@ -1105,12 +1105,13 @@ class CuraApplication(QtApplication):
nodes_arr.sort(key = lambda item: item[0])
nodes_arr.reverse()
start_prio = 0
for size, node, offset_shape_arr, hull_shape_arr in nodes_arr:
Logger.log("d", "Placing object sized: %s" % size)
# we assume that when a location does not fit, it will also not fit for the next
# object (while what can be untrue). That saves a lot of time.
x, y, penalty_points, start_prio = arranger.bestSpot(
offset_shape_arr)
offset_shape_arr, start_prio = start_prio)
if x is not None: # We could find a place
Logger.log("d", "Best place is: %s %s (points = %s)" % (x, y, penalty_points))
arranger.place(x, y, hull_shape_arr) # take place before the next one
node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator)
@ -1384,7 +1385,6 @@ class CuraApplication(QtApplication):
arranger = self._prepareArranger()
min_offset = 8
total_time = 0
for node in nodes:
node.setSelectable(True)
@ -1412,7 +1412,8 @@ class CuraApplication(QtApplication):
# find node location
offset_shape_arr, hull_shape_arr = self._nodeAsShapeArr(node, min_offset = min_offset)
nodes = self._findNodePlacements(arranger, node, offset_shape_arr, hull_shape_arr, count = 1)
# step is for skipping tests to make it a lot faster. it also makes the outcome somewhat rougher
nodes = self._findNodePlacements(arranger, node, offset_shape_arr, hull_shape_arr, count = 1, step = 10)
for new_node in nodes:
op = AddSceneNodeOperation(new_node, scene.getRoot())