def exportSvx(voxels, bounding_box, outputFilePath, scale, shift): size = str(len(str(bounding_box[2])) + 1) root = ET.Element( "grid", attrib={ "gridSizeX": str(bounding_box[0]), "gridSizeY": str(bounding_box[2]), "gridSizeZ": str(bounding_box[1]), "voxelSize": str(1.0 / scale[0] / 1000), #STL is probably in mm, and svx needs meters "subvoxelBits": "8", "originX": str(-shift[0]), "originY": str(-shift[2]), "originZ": str(-shift[1]), }) channels = ET.SubElement(root, "channels") channel = ET.SubElement(channels, "channel", attrib={ "type": "DENSITY", "slices": "density/slice%0" + size + "d.png" }) manifest = ET.tostring(root) with ZipFile(outputFilePath, 'w', zipfile.ZIP_DEFLATED) as zipFile: for height in range(bounding_box[2]): img = Image.new('L', (bounding_box[0], bounding_box[1]), 'black') # create a new black image pixels = img.load() arrayToWhiteGreyscalePixel(voxels[height], pixels) output = io.BytesIO() img.save(output, format="PNG") zipFile.writestr(("density/slice%0" + size + "d.png") % height, output.getvalue()) zipFile.writestr("manifest.xml", manifest)
def exportSvx(voxels, bounding_box, outputFilePath, scale, shift): size = str(len(str(bounding_box[2]))+1) root = ET.Element("grid", attrib={"gridSizeX": str(bounding_box[0]), "gridSizeY": str(bounding_box[2]), "gridSizeZ": str(bounding_box[1]), "voxelSize": str(1.0/scale[0]/1000), #STL is probably in mm, and svx needs meters "subvoxelBits": "8", "originX": str(-shift[0]), "originY": str(-shift[2]), "originZ": str(-shift[1]), }) channels = ET.SubElement(root, "channels") channel = ET.SubElement(channels, "channel", attrib={ "type":"DENSITY", "slices":"density/slice%0" + size + "d.png" }) manifest = ET.tostring(root) with ZipFile(outputFilePath, 'w', zipfile.ZIP_DEFLATED) as zipFile: for height in range(bounding_box[2]): img = Image.new('L', (bounding_box[0], bounding_box[1]), 'black') # create a new black image pixels = img.load() arrayToWhiteGreyscalePixel(voxels[height], pixels) output = io.BytesIO() img.save(output, format="PNG") zipFile.writestr(("density/slice%0" + size + "d.png")%height, output.getvalue()) zipFile.writestr("manifest.xml",manifest)
def exportPngs(voxels, bounding_box, outputFilePath): size = str(len(str(bounding_box[2]))+1) outputFilePattern, outputFileExtension = os.path.splitext(outputFilePath) for height in range(bounding_box[2]): img = Image.new('L', (bounding_box[0], bounding_box[1]), 'black') # create a new black image pixels = img.load() arrayToWhiteGreyscalePixel(voxels[height], pixels) path = (outputFilePattern + "%0" + size + "d.png")%height img.save(path)
def exportPngs(voxels, bounding_box, outputFilePath): size = str(len(str(bounding_box[2]))+1) outputFilePattern, outputFileExtension = os.path.splitext(outputFilePath) for height in range(bounding_box[2]): img = Image.new('L', (bounding_box[0], bounding_box[1]), 'black') # create a new black image pixels = img.load() arrayToWhiteGreyscalePixel(voxels[height], pixels) path = (outputFilePattern + "%0" + size + "d.png")%height img.save(path)