From 32f606d84caf2d89337dd2ca27faa05d4e762fe4 Mon Sep 17 00:00:00 2001 From: daid303 Date: Wed, 1 May 2013 17:18:45 +0200 Subject: [PATCH] Save a lot of memory by storing the loaded GCode as numpy arrays instead of python arrays. --- Cura/gui/sceneView.py | 4 ++-- Cura/util/gcodeInterpreter.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cura/gui/sceneView.py b/Cura/gui/sceneView.py index 72ed1b03..22961d9e 100644 --- a/Cura/gui/sceneView.py +++ b/Cura/gui/sceneView.py @@ -1030,7 +1030,7 @@ void main(void) pointList = numpy.zeros((0,3), numpy.float32) for path in layer: if path.type == 'extrude' and path.pathType == extrudeType: - a = numpy.array(path.points, numpy.float32) + a = path.points a = numpy.concatenate((a[:-1], a[1:]), 1) a = a.reshape((len(a) * 2, 3)) pointList = numpy.concatenate((pointList, a)) @@ -1046,7 +1046,7 @@ void main(void) pointList = numpy.zeros((0,3), numpy.float32) for path in layer: if path.type == 'extrude' and path.pathType == extrudeType: - a = numpy.array(path.points, numpy.float32) + a = path.points if extrudeType == 'FILL': a[:,2] += 0.01 diff --git a/Cura/util/gcodeInterpreter.py b/Cura/util/gcodeInterpreter.py index 5348c3ce..e119f85f 100644 --- a/Cura/util/gcodeInterpreter.py +++ b/Cura/util/gcodeInterpreter.py @@ -4,6 +4,7 @@ import sys import math import os import time +import numpy from Cura.util import profile @@ -88,13 +89,18 @@ class gcode(object): elif comment == 'skirt': pathType = 'SKIRT' if comment.startswith('LAYER:'): + currentPath = gcodePath(moveType, pathType, layerThickness, currentPath.points[-1]) + currentPath.extruder = currentExtruder + for path in currentLayer: + path.points = numpy.array(path.points, numpy.float32) + path.extrusion = numpy.array(path.extrusion, numpy.float32) self.layerList.append(currentLayer) if self.progressCallback is not None: if self.progressCallback(float(gcodeFile.tell()) / float(self._fileSize)): #Abort the loading, we can safely return as the results here will be discarded gcodeFile.close() return - currentLayer = [] + currentLayer = [currentPath] line = line[0:line.find(';')] T = getCodeInt(line, 'T') if T is not None: @@ -254,6 +260,9 @@ class gcode(object): extrudeAmountMultiply = s / 100.0 else: print "Unknown M code:" + str(M) + for path in currentLayer: + path.points = numpy.array(path.points, numpy.float32) + path.extrusion = numpy.array(path.extrusion, numpy.float32) self.layerList.append(currentLayer) if self.progressCallback is not None and self._fileSize > 0: self.progressCallback(float(gcodeFile.tell()) / float(self._fileSize)) -- 2.30.2