mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-14 12:28:02 +08:00
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
# Copyright (c) 2015 Ultimaker B.V.
|
|
# Cura is released under the terms of the AGPLv3 or higher.
|
|
|
|
from UM.Job import Job
|
|
from UM.Application import Application
|
|
from UM.Math.Polygon import Polygon
|
|
|
|
import numpy
|
|
|
|
from . import ConvexHullNode
|
|
|
|
class ConvexHullJob(Job):
|
|
def __init__(self, node):
|
|
super().__init__()
|
|
|
|
self._node = node
|
|
|
|
def run(self):
|
|
if not self._node or not self._node.getMeshData():
|
|
return
|
|
|
|
mesh = self._node.getMeshData()
|
|
vertex_data = mesh.getTransformed(self._node.getWorldTransformation()).getVertices()
|
|
|
|
hull = Polygon(numpy.rint(vertex_data[:, [0, 2]]).astype(int))
|
|
|
|
# First, calculate the normal convex hull around the points
|
|
hull = hull.getConvexHull()
|
|
# Then, do a Minkowski hull with a simple 1x1 quad to outset and round the normal convex hull.
|
|
hull = hull.getMinkowskiHull(Polygon(numpy.array([[-1, -1], [-1, 1], [1, 1], [1, -1]], numpy.float32)))
|
|
|
|
hull_node = ConvexHullNode.ConvexHullNode(self._node, hull, Application.getInstance().getController().getScene().getRoot())
|
|
|
|
self._node._convex_hull = hull
|
|
delattr(self._node, "_convex_hull_job")
|