예제 #1
0
    def __init__(self, volumeProperty, reader, renWin):
        super(TransferFunctionEditor, self).__init__()
        self.volumeProperty = volumeProperty
        self.reader = reader
        self._renderWindow = renWin
        self.setWindowTitle("Transfer Function Editor")

        self.opacityfunction = self.volumeProperty.GetScalarOpacity(0)
        self.colorfunction = self.volumeProperty.GetRGBTransferFunction(0)

        self.npts = self.opacityfunction.GetSize()

        imageData = reader.GetOutput()
        self.histogramWidget = TransferFunctionWidget()
        transferFunction = TransferFunction()

        rmax = self.reader.GetOutput().GetScalarRange()[1]
        rmin = self.reader.GetOutput().GetScalarRange()[0]
        transferFunction.setRange([rmin, rmax])

        self.minimum, self.maximum = rmin, rmax

        opacityNode = np.empty((4, ))
        transferFunction.addPoint(rmin,
                                  self.opacityfunction.GetValue(rmin),
                                  color=[
                                      self.colorfunction.GetRedValue(rmin),
                                      self.colorfunction.GetGreenValue(rmin),
                                      self.colorfunction.GetBlueValue(rmin)
                                  ])
        for i in range(self.npts):
            self.opacityfunction.GetNodeValue(i, opacityNode)
            if (opacityNode[0] > rmin) and (opacityNode[0] < rmax):
                transferFunction.addPoint(
                    opacityNode[0],
                    opacityNode[1],
                    color=[
                        self.colorfunction.GetRedValue(opacityNode[0]),
                        self.colorfunction.GetGreenValue(opacityNode[0]),
                        self.colorfunction.GetBlueValue(opacityNode[0])
                    ])

        transferFunction.addPoint(rmax,
                                  self.opacityfunction.GetValue(rmax),
                                  color=[
                                      self.colorfunction.GetRedValue(rmax),
                                      self.colorfunction.GetGreenValue(rmax),
                                      self.colorfunction.GetBlueValue(rmax)
                                  ])

        transferFunction.updateTransferFunction()

        self.histogramWidget.transferFunction = transferFunction
        self.histogramWidget.setImageData(imageData)
        self.histogramWidget.transferFunction.updateTransferFunction()
        self.histogramWidget.updateNodes()

        self.histogramWidget.valueChanged.connect(self.valueChanged)

        self.resize(400, 300)
    def getParameterWidget(self):
        """
		Returns a widget with sliders / fields with which properties of this
		volume property can be adjusted.
		:rtype: QWidget
		"""
        self.histogramWidget = TransferFunctionWidget()
        self.histogramWidget.transferFunction = self.transferFunction
        self.histogramWidget.valueChanged.connect(self.valueChanged)
        if self.imageData:
            self.histogramWidget.setImageData(self.imageData)

        layout = QGridLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.histogramWidget, 0, 0, 1, 3)

        widget = QWidget()
        widget.setLayout(layout)
        return widget
    def __init__(self, volumeProperty, reader, renWin):        
        super(TransferFunctionEditor, self).__init__()    
        self.volumeProperty = volumeProperty
        self.reader = reader
        self._renderWindow = renWin
        self.setWindowTitle("Transfer Function Editor") 
        
        self.opacityfunction =  self.volumeProperty.GetScalarOpacity(0)
        self.colorfunction =  self.volumeProperty.GetRGBTransferFunction(0)

        self.npts = self.opacityfunction.GetSize()
        
        imageData = reader.GetOutput()
        self.histogramWidget = TransferFunctionWidget()
        transferFunction = TransferFunction()
        
        rmax = self.reader.GetOutput().GetScalarRange()[1] 
        rmin = self.reader.GetOutput().GetScalarRange()[0]         
        transferFunction.setRange([rmin, rmax])
        
        self.minimum, self.maximum = rmin, rmax
        
        opacityNode = np.empty((4,))
        transferFunction.addPoint(rmin, self.opacityfunction.GetValue(rmin), color=[self.colorfunction.GetRedValue(rmin), self.colorfunction.GetGreenValue(rmin), self.colorfunction.GetBlueValue(rmin)])
        for i in range(self.npts):
            self.opacityfunction.GetNodeValue(i, opacityNode)
            if (opacityNode[0] > rmin) and (opacityNode[0] < rmax):
                transferFunction.addPoint(opacityNode[0], opacityNode[1], color=[self.colorfunction.GetRedValue(opacityNode[0]), self.colorfunction.GetGreenValue(opacityNode[0]), self.colorfunction.GetBlueValue(opacityNode[0])])       
            
        transferFunction.addPoint(rmax, self.opacityfunction.GetValue(rmax), color=[self.colorfunction.GetRedValue(rmax), self.colorfunction.GetGreenValue(rmax), self.colorfunction.GetBlueValue(rmax)])
        
        transferFunction.updateTransferFunction() 
        
        self.histogramWidget.transferFunction = transferFunction 
        self.histogramWidget.setImageData(imageData)        
        self.histogramWidget.transferFunction.updateTransferFunction()        
        self.histogramWidget.updateNodes()  
        
        self.histogramWidget.valueChanged.connect(self.valueChanged)

        self.resize(400,300)
class TransferFunctionEditor(pysideQWidget): 
    def __init__(self, volumeProperty, reader, renWin):        
        super(TransferFunctionEditor, self).__init__()    
        self.volumeProperty = volumeProperty
        self.reader = reader
        self._renderWindow = renWin
        self.setWindowTitle("Transfer Function Editor") 
        
        self.opacityfunction =  self.volumeProperty.GetScalarOpacity(0)
        self.colorfunction =  self.volumeProperty.GetRGBTransferFunction(0)

        self.npts = self.opacityfunction.GetSize()
        
        imageData = reader.GetOutput()
        self.histogramWidget = TransferFunctionWidget()
        transferFunction = TransferFunction()
        
        rmax = self.reader.GetOutput().GetScalarRange()[1] 
        rmin = self.reader.GetOutput().GetScalarRange()[0]         
        transferFunction.setRange([rmin, rmax])
        
        self.minimum, self.maximum = rmin, rmax
        
        opacityNode = np.empty((4,))
        transferFunction.addPoint(rmin, self.opacityfunction.GetValue(rmin), color=[self.colorfunction.GetRedValue(rmin), self.colorfunction.GetGreenValue(rmin), self.colorfunction.GetBlueValue(rmin)])
        for i in range(self.npts):
            self.opacityfunction.GetNodeValue(i, opacityNode)
            if (opacityNode[0] > rmin) and (opacityNode[0] < rmax):
                transferFunction.addPoint(opacityNode[0], opacityNode[1], color=[self.colorfunction.GetRedValue(opacityNode[0]), self.colorfunction.GetGreenValue(opacityNode[0]), self.colorfunction.GetBlueValue(opacityNode[0])])       
            
        transferFunction.addPoint(rmax, self.opacityfunction.GetValue(rmax), color=[self.colorfunction.GetRedValue(rmax), self.colorfunction.GetGreenValue(rmax), self.colorfunction.GetBlueValue(rmax)])
        
        transferFunction.updateTransferFunction() 
        
        self.histogramWidget.transferFunction = transferFunction 
        self.histogramWidget.setImageData(imageData)        
        self.histogramWidget.transferFunction.updateTransferFunction()        
        self.histogramWidget.updateNodes()  
        
        self.histogramWidget.valueChanged.connect(self.valueChanged)

        self.resize(400,300)
        
    def getTransferFunctionWidget(self):
        return self.histogramWidget        
    
    def updateTransferFunction(self):
        if self.histogramWidget:
            self.histogramWidget.transferFunction.updateTransferFunction()
            self.colorFunction = self.histogramWidget.transferFunction.colorFunction
            self.opacityFunction = self.histogramWidget.transferFunction.opacityFunction
        else:
            # Transfer functions and properties
            self.colorFunction = vtkColorTransferFunction() # @UndefinedVariable
            self.colorFunction.AddRGBPoint(self.minimum, 0, 0, 0)
            self.colorFunction.AddRGBPoint(self.maximum, 0, 0, 0)

            self.opacityFunction = vtkPiecewiseFunction() # @UndefinedVariable
            self.opacityFunction.AddPoint(self.minimum, 0)
            self.opacityFunction.AddPoint(self.maximum, 0)

        self.volumeProperty.SetColor(self.colorFunction)
        self.volumeProperty.SetScalarOpacity(self.opacityFunction)

        self._renderWindow.Render() 
        
    def valueChanged(self, value):
        self.updateTransferFunction()
        
class VolumeVisualizationTransferFunction(VolumeVisualization):
    """
	VolumeVisualization subclass for a simple visualization.
	"""
    def __init__(self):
        super(VolumeVisualizationTransferFunction, self).__init__()

        self.visualizationType = VisualizationTypeTransferFunction

        # Create the volume property
        self.volProp = vtkVolumeProperty()
        self.volProp.SetIndependentComponents(True)
        self.volProp.SetInterpolationTypeToLinear()
        self.volProp.ShadeOn()
        self.volProp.SetAmbient(0.1)
        self.volProp.SetDiffuse(0.9)
        self.volProp.SetSpecular(0.2)
        self.volProp.SetSpecularPower(10.0)
        self.volProp.SetScalarOpacityUnitDistance(0.8919)

        self.transferFunction = TransferFunction()

        self.minimum = 0
        self.maximum = 1
        self.histogramWidget = None
        self.imageData = None

    @overrides(VolumeVisualization)
    def getParameterWidget(self):
        """
		Returns a widget with sliders / fields with which properties of this
		volume property can be adjusted.
		:rtype: QWidget
		"""
        self.histogramWidget = TransferFunctionWidget()
        self.histogramWidget.transferFunction = self.transferFunction
        self.histogramWidget.valueChanged.connect(self.valueChanged)
        if self.imageData:
            self.histogramWidget.setImageData(self.imageData)

        layout = QGridLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.histogramWidget, 0, 0, 1, 3)

        widget = QWidget()
        widget.setLayout(layout)
        return widget

    @overrides(VolumeVisualization)
    def setImageData(self, imageData):
        if imageData is None:
            self.minimum = 0.0
            self.maximum = 1.0
            self.imageData = None
            return

        self.imageData = imageData
        self.minimum, self.maximum = imageData.GetScalarRange()
        self.transferFunction.setRange([self.minimum, self.maximum])

    @overrides(VolumeVisualization)
    def setMapper(self, mapper):
        pass

    @overrides(VolumeVisualization)
    def shaderType(self):
        return 0

    @overrides(VolumeVisualization)
    def updateTransferFunction(self):
        if self.histogramWidget:
            self.histogramWidget.transferFunction.updateTransferFunction()
            self.colorFunction = self.histogramWidget.transferFunction.colorFunction
            self.opacityFunction = self.histogramWidget.transferFunction.opacityFunction
        else:
            # Transfer functions and properties
            self.colorFunction = vtkColorTransferFunction()
            self.colorFunction.AddRGBPoint(self.minimum, 0, 0, 0)
            self.colorFunction.AddRGBPoint(self.maximum, 0, 0, 0)

            self.opacityFunction = vtkPiecewiseFunction()
            self.opacityFunction.AddPoint(self.minimum, 0)
            self.opacityFunction.AddPoint(self.maximum, 0)

        self.volProp.SetColor(self.colorFunction)
        self.volProp.SetScalarOpacity(self.opacityFunction)

        self.updatedTransferFunction.emit()

    @overrides(VolumeVisualization)
    def valueChanged(self, value):
        """
		This method is called when the value of one of the sliders / fields is
		adjusted. Argument value is unused. It is just there so that it can be
		connected to the signals of the interface elements.

		:type value: int
		"""
        self.updateTransferFunction()
예제 #6
0
class TransferFunctionEditor(pysideQWidget):
    def __init__(self, volumeProperty, reader, renWin):
        super(TransferFunctionEditor, self).__init__()
        self.volumeProperty = volumeProperty
        self.reader = reader
        self._renderWindow = renWin
        self.setWindowTitle("Transfer Function Editor")

        self.opacityfunction = self.volumeProperty.GetScalarOpacity(0)
        self.colorfunction = self.volumeProperty.GetRGBTransferFunction(0)

        self.npts = self.opacityfunction.GetSize()

        imageData = reader.GetOutput()
        self.histogramWidget = TransferFunctionWidget()
        transferFunction = TransferFunction()

        rmax = self.reader.GetOutput().GetScalarRange()[1]
        rmin = self.reader.GetOutput().GetScalarRange()[0]
        transferFunction.setRange([rmin, rmax])

        self.minimum, self.maximum = rmin, rmax

        opacityNode = np.empty((4, ))
        transferFunction.addPoint(rmin,
                                  self.opacityfunction.GetValue(rmin),
                                  color=[
                                      self.colorfunction.GetRedValue(rmin),
                                      self.colorfunction.GetGreenValue(rmin),
                                      self.colorfunction.GetBlueValue(rmin)
                                  ])
        for i in range(self.npts):
            self.opacityfunction.GetNodeValue(i, opacityNode)
            if (opacityNode[0] > rmin) and (opacityNode[0] < rmax):
                transferFunction.addPoint(
                    opacityNode[0],
                    opacityNode[1],
                    color=[
                        self.colorfunction.GetRedValue(opacityNode[0]),
                        self.colorfunction.GetGreenValue(opacityNode[0]),
                        self.colorfunction.GetBlueValue(opacityNode[0])
                    ])

        transferFunction.addPoint(rmax,
                                  self.opacityfunction.GetValue(rmax),
                                  color=[
                                      self.colorfunction.GetRedValue(rmax),
                                      self.colorfunction.GetGreenValue(rmax),
                                      self.colorfunction.GetBlueValue(rmax)
                                  ])

        transferFunction.updateTransferFunction()

        self.histogramWidget.transferFunction = transferFunction
        self.histogramWidget.setImageData(imageData)
        self.histogramWidget.transferFunction.updateTransferFunction()
        self.histogramWidget.updateNodes()

        self.histogramWidget.valueChanged.connect(self.valueChanged)

        self.resize(400, 300)

    def getTransferFunctionWidget(self):
        return self.histogramWidget

    def updateTransferFunction(self):
        if self.histogramWidget:
            self.histogramWidget.transferFunction.updateTransferFunction()
            self.colorFunction = self.histogramWidget.transferFunction.colorFunction
            self.opacityFunction = self.histogramWidget.transferFunction.opacityFunction
        else:
            # Transfer functions and properties
            self.colorFunction = vtkColorTransferFunction(
            )  # @UndefinedVariable
            self.colorFunction.AddRGBPoint(self.minimum, 0, 0, 0)
            self.colorFunction.AddRGBPoint(self.maximum, 0, 0, 0)

            self.opacityFunction = vtkPiecewiseFunction()  # @UndefinedVariable
            self.opacityFunction.AddPoint(self.minimum, 0)
            self.opacityFunction.AddPoint(self.maximum, 0)

        self.volumeProperty.SetColor(self.colorFunction)
        self.volumeProperty.SetScalarOpacity(self.opacityFunction)

        self._renderWindow.Render()

    def valueChanged(self, value):
        self.updateTransferFunction()