def process(self): """ The PythonScriptProcessor will call this process function whenever the processor process function is called. The argument 'self' represents the PythonScriptProcessor. """ # create a small float volume filled with random noise numpy.random.seed(546465) dim = self.properties.dim.value volume = Volume( numpy.random.rand(dim[0], dim[1], dim[2]).astype(numpy.float32)) volume.dataMap.dataRange = dvec2(0.0, 1.0) volume.dataMap.valueRange = dvec2(0.0, 1.0) self.outports.outport.setData(volume) pass
def dataLoaded(self, data, extents): buffer = numpy.concatenate(data, axis=3) volume = ivw.data.Volume(buffer) if self.overwriteDataRange.value: volume.dataMap.dataRange = self.dataRange.value else: minVal = numpy.amin(buffer) maxVal = numpy.amax(buffer) volume.dataMap.dataRange = dvec2(minVal, maxVal) volume.dataMap.valueRange = volume.dataMap.dataRange if self.overwriteModel: volume.modelMatrix = self.modelMatrix.value else: volume.modelMatrix = mat4(vec4(extents[2], 0, 0, 0), vec4(0, extents[1], 0, 0), vec4(0, 0, extents[0], 0), vec4(0, 0, 0, 1)) volume.interpolation = ivw.data.InterpolationType( self.interpolation.value) volume.wrapping = [ ivw.data.Wrapping(self.wrappingX.value), ivw.data.Wrapping(self.wrappingY.value), ivw.data.Wrapping(self.wrappingZ.value) ] self.volumeOutport.setData(volume)
def process(self): """ The PythonScriptProcessor will call this process function whenever the processor process function is called. The argument 'self' represents the PythonScriptProcessor. """ if self.properties.use_nifti.value == True: print("Loading nii data at " + self.properties.location.value) img = nib.load(self.properties.location.value) print(img.header) print(img.get_data_dtype()) data = img.get_fdata() else: print("Loading numpy data at " + self.properties.location.value) data = np.load(self.properties.location.value) dim = data.shape max_desired_val = self.properties.max.value max_val = min(data.max(), max_desired_val) print("Max data value is {}, cut down to {}".format(data.max(), max_val)) data = np.where(data > max_desired_val, np.zeros_like(data), data) # data = np.where(data < (max_val / 10), np.zeros_like(data), data) volume = Volume(data.astype(np.uint16)) volume.dataMap.dataRange = dvec2(0.0, max_val) volume.dataMap.valueRange = dvec2(0.0, max_desired_val) self.outports.outport.setData(volume) # shifting the model by a set translation along all axes if self.properties.use_scan_basis.value == False: basis_vals = self.properties.basis.value volume.modelMatrix = mat4(basis_vals.x, 0, 0, 0, 0, basis_vals.y, 0, 0, 0, 0, basis_vals.z, 0, -(basis_vals.x / 2), -(basis_vals.y / 2), -(basis_vals.z / 2), 1) else: affine_trans = img.affine.transpose() volume.modelMatrix = mat4(*affine_trans.reshape(16)) volume.worldMatrix = mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
def dataLoaded(self, data, extents): volumeSequence = [] for timeStep in range(data[0].shape[3]): subData = [] for comp in data: # A bit brute force, but delivers correct data. numElems = comp.shape[0] * comp.shape[1] * comp.shape[2] subBuffer = comp.flat[(numElems * timeStep):(numElems * (timeStep + 1))] subBuffer.shape = (comp.shape[0], comp.shape[1], comp.shape[2], 1) subData.append(subBuffer) buffer = numpy.concatenate(subData, axis=3) volume = ivw.data.Volume(buffer) if self.overwriteDataRange.value: volume.dataMap.dataRange = self.dataRange.value else: minVal = numpy.amin(buffer) maxVal = numpy.amax(buffer) volume.dataMap.dataRange = dvec2(minVal, maxVal) volume.dataMap.valueRange = volume.dataMap.dataRange if self.overwriteModel: volume.modelMatrix = self.modelMatrix.value else: volume.modelMatrix = mat4(vec4(extents[2], 0, 0, 0), vec4(0, extents[1], 0, 0), vec4(0, 0, extents[0], 0), vec4(0, 0, 0, 1)) volume.interpolation = ivw.data.InterpolationType( self.interpolation.value) volume.wrapping = [ ivw.data.Wrapping(self.wrappingX.value), ivw.data.Wrapping(self.wrappingY.value), ivw.data.Wrapping(self.wrappingZ.value) ] volumeSequence.append(volume) sequence = ivw.data.VolumeSequence(volumeSequence) self.volumeOutport.setData(sequence)