<commit_before>from UM.Job import Job
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from UM.Scene.SceneNode import SceneNode
from UM.Application import Application
from UM.Mesh.MeshData import MeshData

from . import LayerData

import numpy
import struct

class ProcessSlicedObjectListJob(Job):
    def __init__(self, message, center):
        super().__init__(description = 'Processing sliced object')
        self._message = message
        self._scene = Application.getInstance().getController().getScene()
        self._center = center

    def run(self):
        objectIdMap = {}
        new_node = SceneNode()
        ## Put all nodes in a dict identified by ID
        for node in DepthFirstIterator(self._scene.getRoot()):
            if type(node) is SceneNode and node.getMeshData():
                if hasattr(node.getMeshData(), "layerData"):
                    self._scene.getRoot().removeChild(node)
                else:
                    objectIdMap[id(node)] = node

        layerHeight = Application.getInstance().getActiveMachine().getSettingValueByKey('layer_height')

        for object in self._message.objects:
            try:        
                node = objectIdMap[object.id]
            except KeyError:
                continue
            
            mesh = MeshData()

            layerData = LayerData.LayerData()
            for layer in object.layers:
                for polygon in layer.polygons:
                    points = numpy.fromstring(polygon.points, dtype='i8') # Convert bytearray to numpy array
                    points = points.reshape((-1,2)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly.
                    points = numpy.asarray(points, dtype=numpy.float32)
                    points /= 1000
                    points = numpy.insert(points, 1, layer.id * layerHeight, axis = 1)

                    points[:,0] -= self._center.x
                    points[:,2] -= self._center.z

                    #points = numpy.pad(points, ((0,0), (0,1)), 'constant', constant_values=(0.0, 1.0))
                    #inverse = node.getWorldTransformation().getInverse().getData()
                    #points = points.dot(inverse)
                    #points = points[:,0:3]

                    layerData.addPolygon(layer.id, polygon.type, points)

            mesh.layerData = layerData
            
        new_node.setMeshData(mesh)
        new_node.setParent(self._scene.getRoot())<commit_msg>Correct for inverted Z in ProcessSlicedObjectListJob<commit_after>from UM.Job import Job
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from UM.Scene.SceneNode import SceneNode
from UM.Application import Application
from UM.Mesh.MeshData import MeshData

from . import LayerData

import numpy
import struct

class ProcessSlicedObjectListJob(Job):
    def __init__(self, message, center):
        super().__init__(description = 'Processing sliced object')
        self._message = message
        self._scene = Application.getInstance().getController().getScene()
        self._center = center

    def run(self):
        objectIdMap = {}
        new_node = SceneNode()
        ## Put all nodes in a dict identified by ID
        for node in DepthFirstIterator(self._scene.getRoot()):
            if type(node) is SceneNode and node.getMeshData():
                if hasattr(node.getMeshData(), "layerData"):
                    self._scene.getRoot().removeChild(node)
                else:
                    objectIdMap[id(node)] = node

        layerHeight = Application.getInstance().getActiveMachine().getSettingValueByKey('layer_height')

        for object in self._message.objects:
            try:        
                node = objectIdMap[object.id]
            except KeyError:
                continue
            
            mesh = MeshData()

            layerData = LayerData.LayerData()
            for layer in object.layers:
                for polygon in layer.polygons:
                    points = numpy.fromstring(polygon.points, dtype='i8') # Convert bytearray to numpy array
                    points = points.reshape((-1,2)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly.
                    points = numpy.asarray(points, dtype=numpy.float32)
                    points /= 1000
                    points = numpy.insert(points, 1, layer.id * layerHeight, axis = 1)

                    points[:,0] -= self._center.x
                    points[:,2] -= self._center.z

                    points[:,2] *= -1

                    #points = numpy.pad(points, ((0,0), (0,1)), 'constant', constant_values=(0.0, 1.0))
                    #inverse = node.getWorldTransformation().getInverse().getData()
                    #points = points.dot(inverse)
                    #points = points[:,0:3]

                    layerData.addPolygon(layer.id, polygon.type, points)

            mesh.layerData = layerData
            
        new_node.setMeshData(mesh)
        new_node.setParent(self._scene.getRoot())
{'fraction_non_alphanumeric': 0.09710824540836265, 'fraction_numerical': 0.009378663540445486, 'mean_word_length': 1.964099594672843, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '899167', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1285, 'n_words': 330}