Пример #1
0
    def __init__(self, parent=None):

        super(VTK_Widget1, self).__init__(parent)
        self.source_is_connected = False
        
        # vtk to point data
        self.c2p = vtk.vtkCellDataToPointData()
        self.opacityTransferFunction = vtk.vtkPiecewiseFunction()
        self.colorTransferFunction = vtk.vtkColorTransferFunction()

        # create a volume property for describing how the data will look
        self.volumeProperty = vtk.vtkVolumeProperty()
        self.volumeProperty.SetColor(self.colorTransferFunction)
        self.volumeProperty.SetScalarOpacity(self.opacityTransferFunction)
        self.volumeProperty.ShadeOn()
        self.volumeProperty.SetInterpolationTypeToLinear()
        
        # convert to unstructured grid volume
        self.triangleFilter = vtk.vtkDataSetTriangleFilter()
        self.triangleFilter.TetrahedraOnlyOn()
        self.triangleFilter.SetInputConnection(self.c2p.GetOutputPort())

        # create a ray cast mapper
        self.compositeFunction = vtk.vtkUnstructuredGridBunykRayCastFunction()
        self.volumeMapper = vtk.vtkUnstructuredGridVolumeRayCastMapper()
        self.volumeMapper.SetRayCastFunction(self.compositeFunction)
        self.volumeMapper.SetInputConnection(self.triangleFilter.GetOutputPort())
        
        # create a volume
        self.volume = vtk.vtkVolume()
        self.volume.SetMapper(self.volumeMapper)
        self.volume.SetProperty(self.volumeProperty)
        self.volume.VisibilityOff()
        
        # create the VTK widget for rendering
        self.vtkw=QVTKRenderWindowInteractor(self)
        self.ren = vtk.vtkRenderer()
        self.vtkw.GetRenderWindow().AddRenderer(self.ren)
        self.ren.AddVolume(self.volume)
        
        self.alphaSlider = QSlider(Qt.Horizontal)
        self.alphaSlider.setValue(50)
        self.alphaSlider.setRange(0,100)
        self.alphaSlider.setTickPosition(QSlider.NoTicks) 
        self.connect(self.alphaSlider,SIGNAL("valueChanged(int)"),self.AdjustAlpha)
        
        self.alphaLabel = QLabel("alpha: ")
        
        # layout manager
        self.layout = QVBoxLayout()
        self.layout2 = QHBoxLayout()
        self.layout2.addWidget(self.alphaLabel)
        self.layout2.addWidget(self.alphaSlider)
        self.layout.addWidget(self.vtkw)
        self.layout.addSpacing(34)
        self.layout.addLayout(self.layout2)
        
        self.setLayout(self.layout)
        
        # initialize the interactor
        self.vtkw.Initialize()
        self.vtkw.Start()