From 4253a3f9efc26167b3ecd4458fe49a2591d7e2a5 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Tue, 12 Apr 2016 15:40:10 +0200 Subject: [PATCH] Round convex hull data to 0.1mm, then remove duplicates This greatly reduces convex hull complexity while at the same time not introducing much error into the convex hull. This keeps things responsive when dealing with more complex models. Contributes to CURA-1387 --- cura/ConvexHullJob.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cura/ConvexHullJob.py b/cura/ConvexHullJob.py index 98f2deee30..2a943253fb 100644 --- a/cura/ConvexHullJob.py +++ b/cura/ConvexHullJob.py @@ -40,6 +40,14 @@ class ConvexHullJob(Job): vertex_data = mesh.getTransformed(self._node.getWorldTransformation()).getVertices() # Don't use data below 0. TODO; We need a better check for this as this gives poor results for meshes with long edges. vertex_data = vertex_data[vertex_data[:,1] >= 0] + + # Round the vertex data to 1/10th of a mm, then remove all duplicate vertices + # This is done to greatly speed up further convex hull calculations as the convex hull + # becomes much less complex when dealing with highly detailed models. + vertex_data = numpy.round(vertex_data, 1) + duplicates = (vertex_data[:,0] == vertex_data[:,1]) | (vertex_data[:,1] == vertex_data[:,2]) | (vertex_data[:,0] == vertex_data[:,2]) + vertex_data = numpy.delete(vertex_data, numpy.where(duplicates), axis = 0) + hull = Polygon(vertex_data[:, [0, 2]]) # First, calculate the normal convex hull around the points