mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Funed arranger for better performance. CURA-3239
This commit is contained in:
parent
099752125b
commit
9db816b0fc
2 changed files with 10 additions and 9 deletions
|
@ -124,13 +124,13 @@ class Arrange:
|
||||||
return np.sum(prio_slice[np.where(shape_arr.arr == 1)])
|
return np.sum(prio_slice[np.where(shape_arr.arr == 1)])
|
||||||
|
|
||||||
## Find "best" spot
|
## 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)
|
start_idx_list = np.where(self._priority_unique_values == start_prio)
|
||||||
if start_idx_list:
|
if start_idx_list:
|
||||||
start_idx = start_idx_list[0]
|
start_idx = start_idx_list[0]
|
||||||
else:
|
else:
|
||||||
start_idx = 0
|
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)
|
tryout_idx = np.where(self._priority == prio)
|
||||||
for idx in range(len(tryout_idx[0])):
|
for idx in range(len(tryout_idx[0])):
|
||||||
x = tryout_idx[0][idx]
|
x = tryout_idx[0][idx]
|
||||||
|
|
|
@ -894,7 +894,7 @@ class CuraApplication(QtApplication):
|
||||||
return offset_shape_arr, hull_shape_arr
|
return offset_shape_arr, hull_shape_arr
|
||||||
|
|
||||||
@classmethod
|
@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
|
# offset_shape_arr, hull_shape_arr, arranger -> nodes, arranger
|
||||||
nodes = []
|
nodes = []
|
||||||
start_prio = 0
|
start_prio = 0
|
||||||
|
@ -903,7 +903,7 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
Logger.log("d", " # Finding spot for %s" % new_node)
|
Logger.log("d", " # Finding spot for %s" % new_node)
|
||||||
x, y, penalty_points, start_prio = arranger.bestSpot(
|
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
|
transformation = new_node._transformation
|
||||||
if x is not None: # We could find a place
|
if x is not None: # We could find a place
|
||||||
transformation._data[0][3] = x
|
transformation._data[0][3] = x
|
||||||
|
@ -1105,12 +1105,13 @@ class CuraApplication(QtApplication):
|
||||||
nodes_arr.sort(key = lambda item: item[0])
|
nodes_arr.sort(key = lambda item: item[0])
|
||||||
nodes_arr.reverse()
|
nodes_arr.reverse()
|
||||||
|
|
||||||
|
start_prio = 0
|
||||||
for size, node, offset_shape_arr, hull_shape_arr in nodes_arr:
|
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(
|
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
|
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
|
arranger.place(x, y, hull_shape_arr) # take place before the next one
|
||||||
|
|
||||||
node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator)
|
node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator)
|
||||||
|
@ -1384,7 +1385,6 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
arranger = self._prepareArranger()
|
arranger = self._prepareArranger()
|
||||||
min_offset = 8
|
min_offset = 8
|
||||||
total_time = 0
|
|
||||||
|
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
node.setSelectable(True)
|
node.setSelectable(True)
|
||||||
|
@ -1412,7 +1412,8 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
# find node location
|
# find node location
|
||||||
offset_shape_arr, hull_shape_arr = self._nodeAsShapeArr(node, min_offset = min_offset)
|
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:
|
for new_node in nodes:
|
||||||
op = AddSceneNodeOperation(new_node, scene.getRoot())
|
op = AddSceneNodeOperation(new_node, scene.getRoot())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue