chiark / gitweb /
Fix the save STL function after numpy upgrade.
authordaid <daid303@gmail.com>
Thu, 26 Jul 2012 15:29:31 +0000 (17:29 +0200)
committerdaid <daid303@gmail.com>
Thu, 26 Jul 2012 15:29:31 +0000 (17:29 +0200)
Cura/gui/projectPlanner.py
Cura/util/mesh.py
Cura/util/stl.py
Cura/util/util3d.py

index f09d999a1b47c8bf9f1a468916f3ed53cff922f9..521dce3845430f67a36d447b58e7a15c9987539e 100644 (file)
@@ -307,11 +307,16 @@ class projectPlanner(wx.Frame):
                dlg.Destroy()\r
        \r
        def _saveCombinedSTL(self, filename):\r
+               totalCount = 0\r
+               for item in self.list:\r
+                       totalCount += item.vertexCount\r
                output = mesh.mesh()\r
+               output._prepareVertexCount(totalCount)\r
                for item in self.list:\r
-                       offset = util3d.Vector3(item.centerX, item.centerY, 0)\r
-                       for f in item.faces:\r
-                               output.addFace(f.v[0] * item.scale + offset, f.v[1] * item.scale + offset, f.v[2] * item.scale + offset)\r
+                       offset = numpy.array([item.centerX, item.centerY, 0])\r
+                       for v in item.vertexes:\r
+                               v0 = v * item.scale + offset\r
+                               output.addVertex(v0[0], v0[1], v0[2])\r
                stl.saveAsSTL(output, filename)\r
        \r
        def OnSaveProject(self, e):\r
index 0a943b1ef9ed4b50ed1d1362843185ae39f6255b..0705b1b808245b5789f6043a17ce64d91b706243 100644 (file)
@@ -83,22 +83,24 @@ class mesh(object):
                print "%f: " % (time.time() - t0), "Splitting a model with %d vertexes." % (len(self.vertexes))
                removeDict = {}
                tree = util3d.AABBTree()
-               off = util3d.Vector3(0.0001,0.0001,0.0001)
+               off = numpy.array([0.0001,0.0001,0.0001])
                newVertexList = []
-               for v in self.vertexes:
+               for idx in xrange(0, self.vertexCount):
+                       v = self.vertexes[idx]
                        e = util3d.AABB(v-off, v+off)
                        q = tree.query(e)
                        if len(q) < 1:
-                               e.vector = v
+                               e.idx = idx
                                tree.insert(e)
                                newVertexList.append(v)
                        else:
-                               removeDict[v] = q[0].vector
+                               removeDict[idx] = q[0].idx
                print "%f: " % (time.time() - t0), "Marked %d duplicate vertexes for removal." % (len(removeDict))
                
                #Make facelists so we can quickly remove all the vertexes.
-               for v in self.vertexes:
-                       v.faceList = []
+               vertexFaceList = []
+               for idx in xrange(0, self.vertexCount):
+                       vertexFaceList.append([])
                for f in self.faces:
                        f.v[0].faceList.append(f)
                        f.v[1].faceList.append(f)
index 7e4226793da4c9186ae4b3f6b8a4eb865be23063..9689c030f688dafa4db8845b8539baa3e23a8129 100644 (file)
@@ -49,17 +49,15 @@ def saveAsSTL(mesh, filename):
        #Write the STL binary header. This can contain any info, except for "SOLID" at the start.
        f.write(("CURA BINARY STL EXPORT. " + time.strftime('%a %d %b %Y %H:%M:%S')).ljust(80, '\000'))
        #Next follow 4 binary bytes containing the amount of faces, and then the face information.
-       f.write(struct.pack("<I", len(mesh.faces)))
-       for face in mesh.faces:
-               v1 = face.v[0]
-               v2 = face.v[1]
-               v3 = face.v[2]
-               normal = (v2 - v1).cross(v3 - v1)
-               normal.normalize()
-               f.write(struct.pack("<fff", normal.x, normal.y, normal.z))
-               f.write(struct.pack("<fff", v1.x, v1.y, v1.z))
-               f.write(struct.pack("<fff", v2.x, v2.y, v2.z))
-               f.write(struct.pack("<fff", v3.x, v3.y, v3.z))
+       f.write(struct.pack("<I", int(mesh.vertexCount/ 3)))
+       for idx in xrange(0, mesh.vertexCount, 3):
+               v1 = mesh.origonalVertexes[idx]
+               v2 = mesh.origonalVertexes[idx+1]
+               v3 = mesh.origonalVertexes[idx+2]
+               f.write(struct.pack("<fff", 0.0, 0.0, 0.0))
+               f.write(struct.pack("<fff", v1[0], v1[1], v1[2]))
+               f.write(struct.pack("<fff", v2[0], v2[1], v2[2]))
+               f.write(struct.pack("<fff", v3[0], v3[1], v3[2]))
                f.write(struct.pack("<H", 0))
        f.close()
 
@@ -67,7 +65,7 @@ if __name__ == '__main__':
        for filename in sys.argv[1:]:
                m = stlModel().load(filename)
                print("Loaded %d faces" % (m.vertexCount / 3))
-#              parts = m.splitToParts()
+               parts = m.splitToParts()
 #              for p in parts:
 #                      saveAsSTL(p, "export_%i.stl" % parts.index(p))
 
index 68f0123444a3b503422fa3b58b42014a4029dd27..92043abe067f10bebae219fb4afabff976f5a77d 100644 (file)
@@ -1,4 +1,5 @@
 import math
+import numpy
 
 class Vector3(object):
        def __init__(self, x=0.0, y=0.0, z=0.0):
@@ -83,15 +84,15 @@ class AABB(object):
                self.vMax = vMax
        
        def getPerimeter(self):
-               return (self.vMax.x - self.vMax.x) + (self.vMax.y - self.vMax.y) + (self.vMax.z - self.vMax.z)
+               return (self.vMax[0] - self.vMax[0]) + (self.vMax[1] - self.vMax[1]) + (self.vMax[2] - self.vMax[2])
        
        def combine(self, aabb):
-               return AABB(self.vMin.min(aabb.vMin), self.vMax.max(aabb.vMax))
+               return AABB(numpy.minimum(self.vMin, aabb.vMin), numpy.maximum(self.vMax, aabb.vMax))
        
        def overlap(self, aabb):
-               if aabb.vMin.x - self.vMax.x > 0.0 or aabb.vMin.y - self.vMax.y > 0.0 or aabb.vMin.z - self.vMax.z > 0.0:
+               if aabb.vMin[0] - self.vMax[0] > 0.0 or aabb.vMin[1] - self.vMax[1] > 0.0 or aabb.vMin[2] - self.vMax[2] > 0.0:
                        return False
-               if self.vMin.x - aabb.vMax.x > 0.0 or self.vMin.y - aabb.vMax.y > 0.0 or self.vMin.z - aabb.vMax.z > 0.0:
+               if self.vMin[0] - aabb.vMax[0] > 0.0 or self.vMin[1] - aabb.vMax[1] > 0.0 or self.vMin[2] - aabb.vMax[2] > 0.0:
                        return False
                return True
        
@@ -308,9 +309,9 @@ class AABBTree(object):
 
 if __name__ == '__main__':
        tree = AABBTree()
-       tree.insert(AABB(Vector3(0,0,0), Vector3(0,0,0)))
-       tree.insert(AABB(Vector3(1,1,1), Vector3(1,1,1)))
-       tree.insert(AABB(Vector3(0.5,0.5,0.5), Vector3(0.5,0.5,0.5)))
+       tree.insert(AABB(numpy.array([0,0,0]), numpy.array([0,0,0])))
+       tree.insert(AABB(numpy.array([1,1,1]), numpy.array([1,1,1])))
+       tree.insert(AABB(numpy.array([0.5,0.5,0.5]), numpy.array([0.5,0.5,0.5])))
        print(tree)
-       print(tree.query(AABB(Vector3(0,0,0), Vector3(0,0,0))))
+       print(tree.query(AABB(numpy.array([0,0,0]), numpy.array([0,0,0]))))