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 __init__(self, id, name): genericnetcdfsource.GenericNetCDFSource.__init__(self, id, name, outputDimension=3) self.volumeOutport = ivw.data.VolumeOutport("data3D") self.addOutport(self.volumeOutport, owner=False) self.interpolation = OptionPropertyInt( "interpolation", "Interpolation", options(ivw.data.InterpolationType), 0) self.addProperty(self.interpolation) self.wrappingX = OptionPropertyInt("wrappingX", "Wrapping X", options(ivw.data.Wrapping), 0) self.addProperty(self.wrappingX) self.wrappingY = OptionPropertyInt("wrappingY", "Wrapping Y", options(ivw.data.Wrapping), 0) self.addProperty(self.wrappingY) self.wrappingZ = OptionPropertyInt("wrappingZ", "Wrapping Z", options(ivw.data.Wrapping), 0) self.addProperty(self.wrappingZ) self.overwriteDataRange = BoolProperty("overwriteDataRange", "Overwrite Data Range", False) self.addProperty(self.overwriteDataRange) self.dataRange = DoubleMinMaxProperty("dataRange", "Data Range", 0.0, 0.0, -1.70e308, 1.79e308) self.addProperty(self.dataRange) self.dataRange.readOnly = True self.dataRange.semantics = ivw.properties.PropertySemantics("Text") self.dataRange.readonlyDependsOn(self.overwriteDataRange, lambda x: not x.value) self.overwriteModel = BoolProperty("overwriteModel", "Overwrite Model Matrix", False) self.addProperty(self.overwriteModel) self.modelMatrix = FloatMat4Property("modelMatrix", "Model Matrix", mat4(10.0), mat4(0) - 10e20, mat4(0) + 10e20) self.addProperty(self.modelMatrix) self.modelMatrix.readOnly = True self.modelMatrix.semantics = ivw.properties.PropertySemantics("Text") self.modelMatrix.readonlyDependsOn(self.overwriteModel, lambda x: not x.value)
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 getRotation(self): viewDir = self.master.lookTo - self.master.lookFrom rightDir = glm.cross(viewDir, self.master.lookUp) tilt = glm.rotate(glm.mat4(1.0), self.tilt.value * math.pi / 180, rightDir) leftRot = glm.rotate(tilt, math.pi / 4, self.master.lookUp) if self.current.selectedValue == 0 or self.current.selectedValue == 4: return leftRot if self.current.selectedValue == 1 or self.current.selectedValue == 5: return glm.rotate(leftRot, -math.pi / 2, self.master.lookUp) if self.current.selectedValue == 2 or self.current.selectedValue == 6: return glm.rotate(leftRot, math.pi / 2, rightDir) if self.current.selectedValue == 3 or self.current.selectedValue == 7: return glm.rotate(leftRot, -math.pi / 2, rightDir)
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)