From: daid Date: Fri, 29 Nov 2013 09:51:30 +0000 (+0100) Subject: Fix the push-free for convex polygons. Fix the objectOrderFinder to handle the case... X-Git-Tag: 14.01~48 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=baeb0093352770604486288f153d098ccadf9b40;p=cura.git Fix the push-free for convex polygons. Fix the objectOrderFinder to handle the case where you cannot print one at a time (old version hanged in this case) --- diff --git a/Cura/util/objectScene.py b/Cura/util/objectScene.py index 947bc95b..e118a3b3 100644 --- a/Cura/util/objectScene.py +++ b/Cura/util/objectScene.py @@ -36,6 +36,12 @@ class _objectOrderFinder(object): for b in initialList: self._hitMap[a][b] = self._checkHit(a, b) + #Check if we have 2 files that overlap so that they can never be printed one at a time. + for a in initialList: + if self._hitMap[a][b] and self._hitMap[b][a]: + self.order = None + return + initialList.sort(self._objIdxCmp) n = 0 @@ -155,7 +161,6 @@ class Scene(object): self.pushFree() def pushFree(self): - return n = 1000 while self._pushFree(): n -= 1 @@ -193,25 +198,13 @@ class Scene(object): def _pushFree(self): for a in self._objectList: for b in self._objectList: - if not self._checkHit(a, b): + if a == b: + continue + v = polygon.polygonCollisionPushVector(a._boundaryHull + a.getPosition(), b._boundaryHull + b.getPosition()) + if type(v) is bool: continue - posDiff = a.getPosition() - b.getPosition() - if posDiff[0] == 0.0 and posDiff[1] == 0.0: - posDiff[1] = 1.0 - if abs(posDiff[0]) > abs(posDiff[1]): - axis = 0 - else: - axis = 1 - aPos = a.getPosition() - bPos = b.getPosition() - center = (aPos[axis] + bPos[axis]) / 2 - distance = (a.getSize()[axis] + b.getSize()[axis]) / 2 + 0.1 + self._sizeOffsets[axis] + self._headSizeOffsets[axis] - if posDiff[axis] < 0: - distance = -distance - aPos[axis] = center + distance / 2 - bPos[axis] = center - distance / 2 - a.setPosition(aPos) - b.setPosition(bPos) + a.setPosition(a.getPosition() + v / 2.0) + b.setPosition(b.getPosition() - v / 2.0) return True return False diff --git a/Cura/util/polygon.py b/Cura/util/polygon.py index 746fb0ed..8da33639 100644 --- a/Cura/util/polygon.py +++ b/Cura/util/polygon.py @@ -82,3 +82,42 @@ def polygonCollision(polyA, polyB): if aMax < bMin: return False return True + +def polygonCollisionPushVector(polyA, polyB): + retSize = 10000000.0 + ret = False + for n in xrange(0, len(polyA)): + p0 = polyA[n-1] + p1 = polyA[n] + normal = (p1 - p0)[::-1] + normal[1] = -normal[1] + normal /= numpy.linalg.norm(normal) + aMin, aMax = projectPoly(polyA, normal) + bMin, bMax = projectPoly(polyB, normal) + if aMin > bMax: + return False + if bMin > aMax: + return False + size = min(bMax, bMax) - max(aMin, bMin) + if size < retSize: + ret = normal * (size + 0.1) + retSize = size + for n in xrange(0, len(polyB)): + p0 = polyB[n-1] + p1 = polyB[n] + normal = (p1 - p0)[::-1] + normal[1] = -normal[1] + normal /= numpy.linalg.norm(normal) + aMin, aMax = projectPoly(polyA, normal) + bMin, bMax = projectPoly(polyB, normal) + if aMin > bMax: + return False + if aMax < bMin: + return False + size = min(bMax, bMax) - max(aMin, bMin) + if size < retSize: + ret = normal * -(size + 0.1) + retSize = size + #ret = ret[::-1] + #ret[1] = -ret[1] + return ret