def create(cls, scene_root = None, fixed_nodes = None, scale = 0.5, x = 350, y = 250, min_offset = 8): arranger = Arrange(x, y, x // 2, y // 2, scale = scale) arranger.centerFirst() if fixed_nodes is None: fixed_nodes = [] for node_ in DepthFirstIterator(scene_root): # Only count sliceable objects if node_.callDecoration("isSliceable"): fixed_nodes.append(node_) # Place all objects fixed nodes for fixed_node in fixed_nodes: vertices = fixed_node.callDecoration("getConvexHullHead") or fixed_node.callDecoration("getConvexHull") if not vertices: continue vertices = vertices.getMinkowskiHull(Polygon.approximatedCircle(min_offset)) points = copy.deepcopy(vertices._points) # After scaling (like up to 0.1 mm) the node might not have points if len(points) == 0: continue shape_arr = ShapeArray.fromPolygon(points, scale = scale) arranger.place(0, 0, shape_arr) # If a build volume was set, add the disallowed areas if Arrange.build_volume: disallowed_areas = Arrange.build_volume.getDisallowedAreasNoBrim() for area in disallowed_areas: points = copy.deepcopy(area._points) shape_arr = ShapeArray.fromPolygon(points, scale = scale) arranger.place(0, 0, shape_arr, update_empty = False) return arranger
def create(cls, scene_root=None, fixed_nodes=None, scale=0.5, x=220, y=220): arranger = Arrange(x, y, x // 2, y // 2, scale=scale) arranger.centerFirst() if fixed_nodes is None: fixed_nodes = [] for node_ in DepthFirstIterator(scene_root): # Only count sliceable objects if node_.callDecoration("isSliceable"): fixed_nodes.append(node_) # place all objects fixed nodes for fixed_node in fixed_nodes: vertices = fixed_node.callDecoration("getConvexHull") if not vertices: continue points = copy.deepcopy(vertices._points) shape_arr = ShapeArray.fromPolygon(points, scale=scale) arranger.place(0, 0, shape_arr) # If a build volume was set, add the disallowed areas if Arrange.build_volume: disallowed_areas = Arrange.build_volume.getDisallowedAreas() for area in disallowed_areas: points = copy.deepcopy(area._points) shape_arr = ShapeArray.fromPolygon(points, scale=scale) arranger.place(0, 0, shape_arr, update_empty=False) return arranger
def create(cls, scene_root = None, fixed_nodes = None, scale = 0.5, x = 350, y = 250, min_offset = 8): arranger = Arrange(x, y, x // 2, y // 2, scale = scale) arranger.centerFirst() if fixed_nodes is None: fixed_nodes = [] for node_ in DepthFirstIterator(scene_root): # Only count sliceable objects if node_.callDecoration("isSliceable"): fixed_nodes.append(node_) # Place all objects fixed nodes for fixed_node in fixed_nodes: vertices = fixed_node.callDecoration("getConvexHullHead") or fixed_node.callDecoration("getConvexHull") if not vertices: continue vertices = vertices.getMinkowskiHull(Polygon.approximatedCircle(min_offset)) points = copy.deepcopy(vertices._points) # After scaling (like up to 0.1 mm) the node might not have points if not points.size: continue shape_arr = ShapeArray.fromPolygon(points, scale = scale) arranger.place(0, 0, shape_arr) # If a build volume was set, add the disallowed areas if Arrange.build_volume: disallowed_areas = Arrange.build_volume.getDisallowedAreasNoBrim() for area in disallowed_areas: points = copy.deepcopy(area._points) shape_arr = ShapeArray.fromPolygon(points, scale = scale) arranger.place(0, 0, shape_arr, update_empty = False) return arranger
def create(cls, scene_root = None, fixed_nodes = None, scale = 0.5, x = 220, y = 220): arranger = Arrange(x, y, x // 2, y // 2, scale = scale) arranger.centerFirst() if fixed_nodes is None: fixed_nodes = [] for node_ in DepthFirstIterator(scene_root): # Only count sliceable objects if node_.callDecoration("isSliceable"): fixed_nodes.append(node_) # Place all objects fixed nodes for fixed_node in fixed_nodes: vertices = fixed_node.callDecoration("getConvexHull") if not vertices: continue points = copy.deepcopy(vertices._points) shape_arr = ShapeArray.fromPolygon(points, scale = scale) arranger.place(0, 0, shape_arr) # If a build volume was set, add the disallowed areas if Arrange.build_volume: disallowed_areas = Arrange.build_volume.getDisallowedAreas() for area in disallowed_areas: points = copy.deepcopy(area._points) shape_arr = ShapeArray.fromPolygon(points, scale = scale) arranger.place(0, 0, shape_arr, update_empty = False) return arranger
def create(cls, scene_root=None, fixed_nodes=None, scale=0.5, x=350, y=250, min_offset=8) -> "Arrange": """Helper to create an :py:class:`cura.Arranging.Arrange.Arrange` instance Either fill in scene_root and create will find all sliceable nodes by itself, or use fixed_nodes to provide the nodes yourself. :param scene_root: Root for finding all scene nodes default = None :param fixed_nodes: Scene nodes to be placed default = None :param scale: default = 0.5 :param x: default = 350 :param y: default = 250 :param min_offset: default = 8 """ arranger = Arrange(x, y, x // 2, y // 2, scale=scale) arranger.centerFirst() if fixed_nodes is None: fixed_nodes = [] for node_ in DepthFirstIterator(scene_root): # Only count sliceable objects if node_.callDecoration("isSliceable"): fixed_nodes.append(node_) # Place all objects fixed nodes for fixed_node in fixed_nodes: vertices = fixed_node.callDecoration( "getConvexHullHead") or fixed_node.callDecoration( "getConvexHull") if not vertices: continue vertices = vertices.getMinkowskiHull( Polygon.approximatedCircle(min_offset)) points = copy.deepcopy(vertices._points) # After scaling (like up to 0.1 mm) the node might not have points if not points.size: continue try: shape_arr = ShapeArray.fromPolygon(points, scale=scale) except ValueError: Logger.logException("w", "Unable to create polygon") continue arranger.place(0, 0, shape_arr) # If a build volume was set, add the disallowed areas if Arrange.build_volume: disallowed_areas = Arrange.build_volume.getDisallowedAreasNoBrim() for area in disallowed_areas: points = copy.deepcopy(area._points) shape_arr = ShapeArray.fromPolygon(points, scale=scale) arranger.place(0, 0, shape_arr, update_empty=False) return arranger
def test_parts_of_fromNode2(): from UM.Math.Polygon import Polygon p = Polygon(numpy.array([[-2, -2], [2, -2], [2, 2], [-2, 2]], dtype=numpy.int32) * 2) # 4x4 offset = 13.3 scale = 0.5 p_offset = p.getMinkowskiHull(Polygon.approximatedCircle(offset)) shape_arr1 = ShapeArray.fromPolygon(p._points, scale = scale) shape_arr2 = ShapeArray.fromPolygon(p_offset._points, scale = scale) assert shape_arr1.arr.shape[0] >= (4 * scale) - 1 # -1 is to account for rounding errors assert shape_arr2.arr.shape[0] >= (2 * offset + 4) * scale - 1
def create(cls, scene_root=None, fixed_nodes=None, scale=1.0): global_stack = Application.getInstance().getGlobalContainerStack() machine_width = int(global_stack.getProperty("machine_width", "value")) machine_depth = int(global_stack.getProperty("machine_depth", "value")) arranger = Arrange(machine_depth, machine_width, int(machine_width / 2), int(machine_depth / 2), scale=scale) arranger.centerFirst() if fixed_nodes is None: fixed_nodes = [] for node_ in DepthFirstIterator(scene_root): # Only count sliceable objects if node_.callDecoration("isSliceable") and not isinstance( node_, DuplicatedNode): fixed_nodes.append(node_) # Place all objects fixed nodes for fixed_node in fixed_nodes: arrange_align = Preferences.getInstance().getValue( "mesh/arrange_align") if arrange_align: bb = fixed_node.getBoundingBox() points = numpy.array( [[bb.right, bb.back], [bb.left, bb.back], [bb.left, bb.front], [bb.right, bb.front]], dtype=numpy.float32) else: vertices = fixed_node.callDecoration("getConvexHull") if not vertices: continue points = copy.deepcopy(vertices._points) shape_arr = ShapeArray.fromPolygon(points, scale=scale) arranger.place(0, 0, shape_arr) # If a build volume was set, add the disallowed areas if Arrange.build_volume: disallowed_areas = Arrange.build_volume.getDisallowedAreas() for area in disallowed_areas: points = copy.deepcopy(area._points) shape_arr = ShapeArray.fromPolygon(points, scale=scale) arranger.place(0, 0, shape_arr, update_empty=False) return arranger
def test_fromPolygon(): vertices = numpy.array([[0, 0.5], [0, 0], [0.5, 0]]) array = ShapeArray.fromPolygon(vertices, scale=0.5) assert numpy.any(array.arr)
def gimmeShapeArraySquare(scale = 1.0): vertices = gimmeSquare() shape_arr = ShapeArray.fromPolygon(vertices, scale = scale) return shape_arr
def gimmeShapeArray(scale = 1.0): vertices = gimmeTriangle() shape_arr = ShapeArray.fromPolygon(vertices, scale = scale) return shape_arr
def gimmeShapeArray(): vertices = numpy.array([[-3, 1], [3, 1], [0, -3]]) shape_arr = ShapeArray.fromPolygon(vertices) return shape_arr
def gimmeShapeArray(): vertices = numpy.array([[-3, 1], [3, 1], [0, -3]]) shape_arr = ShapeArray.fromPolygon(vertices) return shape_arr