def _make_reader(self, filename): "Internal function." extension = None parts = filename.split('.') if len(parts) > 1: extension = parts[-1] else: raise RuntimeError( "Filename has no extension, please guess reader to use") if extension == 'png': return vtkPNGReader() elif extension == 'bmp': return vtkBMPReader() elif extension == 'ppm': return vtkPNMReader() elif extension == 'tif' or extension == 'tiff': return vtkTIFFReader() elif extension == 'jpg' or extension == 'jpeg': return vtkJPEGReader() elif extension == 'vti': return vtkXMLImageDataReader() # noqa: F821 else: raise RuntimeError("Cannot infer filetype from extension:", extension)
def __init__(self, directory): self.basePath = directory self.layers = [] self.data = [] self.imageReader = vtkPNGReader() # Load JSON metadata with open(os.path.join(directory, "config.json"), "r") as f: self.config = json.load(f) self.nbLayers = len(self.config['scene']) while len(self.layers) < self.nbLayers: self.layers.append({}) with open(os.path.join(directory, "index.json"), "r") as f: self.info = json.load(f) with open(os.path.join(directory, "offset.json"), "r") as f: offsets = json.load(f) for key, value in iteritems(offsets): meta = key.split('|') if len(meta) == 2: self.layers[int(meta[0])][meta[1]] = value elif meta[1] in self.layers[int(meta[0])]: self.layers[int(meta[0])][meta[1]][int(meta[2])] = value else: self.layers[int(meta[0])][meta[1]] = [value, value, value] self.composite = CompositeJSON(len(self.layers))
def _make_reader(self, filename): "Internal function." extension = None parts = filename.split('.') if len(parts) > 1: extension = parts[-1] else: raise RuntimeError( "Filename has no extension, please guess reader to use") if extension == 'png': return vtkPNGReader() elif extension == 'bmp': return vtkBMPReader() elif extension == 'ppm': return vtkPNMReader() elif extension == 'tif' or extension == 'tiff': return vtkTIFFReader() elif extension == 'jpg' or extension == 'jpeg': return vtkJPEGReader() elif extension == 'vti': return vtkXMLImageDataReader() # noqa: F821 else: raise RuntimeError( "Cannot infer filetype from extension:", extension)
def SaveAndCheckSize(filename, layout, resolution): SaveScreenshot(filename, layout, SaveAllViews=1, ImageResolution=resolution) from paraview.vtk.vtkIOImage import vtkPNGReader reader = vtkPNGReader() reader.SetFileName(filename) reader.Update() assert (reader.GetOutput().GetDimensions()[0:2] == resolution)
def __init__(self, isWriter=True, removePNG=True): self.view = simple.CreateView('RenderView') self.view.Background = [0.0, 0.0, 0.0] self.view.CenterAxesVisibility = 0 self.view.OrientationAxesVisibility = 0 self.reader = vtkPNGReader() self.cleanAfterMe = removePNG self.canWrite = isWriter
def SaveAndCheckSize(filename, layout, resolution): SaveScreenshot(filename, layout, SaveAllViews=1, ImageResolution=resolution) from paraview.vtk.vtkIOImage import vtkPNGReader reader = vtkPNGReader() reader.SetFileName(filename) reader.Update() assert (reader.GetOutput().GetDimensions()[0:2] == resolution)
def __init__(self, directory): self.basePath = directory self.layers = [] self.data = [] self.imageReader = vtkPNGReader() # Load JSON metadata with open(os.path.join(directory, "config.json"), "r") as f: self.config = json.load(f) self.nbLayers = len(self.config['scene']) while len(self.layers) < self.nbLayers: self.layers.append({}) with open(os.path.join(directory, "index.json"), "r") as f: self.info = json.load(f)
def convertImageToFloat(srcPngImage, destFile, scalarRange=[0.0, 1.0]): reader = vtkPNGReader() reader.SetFileName(srcPngImage) reader.Update() rgbArray = reader.GetOutput().GetPointData().GetArray(0) stackSize = rgbArray.GetNumberOfTuples() size = reader.GetOutput().GetDimensions() outputArray = vtkFloatArray() outputArray.SetNumberOfComponents(1) outputArray.SetNumberOfTuples(stackSize) for idx in range(stackSize): outputArray.SetTuple1( idx, getScalarFromRGB(rgbArray.GetTuple(idx), scalarRange)) # Write float file with open(destFile, 'wb') as f: f.write(buffer(outputArray)) return size