如何选择vtkVolumeMapper使用的标量

时间:2019-05-17 14:41:21

标签: python vtk

我有一个包含多个数据数组的卷,并使用vtkVolumeMapper(vtkFixedPointVolumeRayCastMapper)对其进行渲染。

如何告诉映射器将特定数组用作标量? (SelectColorArray不是vtkVolumeMapper的函数)

我正在使用VTK 6

    # Create the reader for the data
    reader = vtk.vtkXMLImageDataReader()
    reader.SetFileName(self.scan_analysis.content.vtk_path)
    reader.GetOutput().GetPointData().SetActiveScalars('smooth')

    # Create transfer mapping scalar value to opacity
    opacityTransferFunction = vtk.vtkPiecewiseFunction()
    opacityTransferFunction.AddPoint(5, 0.0)
    opacityTransferFunction.AddPoint(80, 0.4)
    opacityTransferFunction.AddPoint(81, 0.0)
    opacityTransferFunction.AddPoint(100, 0.0)

    # Create transfer mapping scalar value to color
    lut = vtk.vtkColorTransferFunction()
    lut.AddRGBPoint(0.0, 0.0, 0.0, 1.0)
    lut.AddRGBPoint(50.0, 1.0, 1.0, 1.0)
    lut.AddRGBPoint(100.0, 1.0, 0.0, 0.0)

    # The property describes how the data will look
    volumeProperty = vtk.vtkVolumeProperty()
    volumeProperty.SetColor(lut)
    volumeProperty.SetScalarOpacity(opacityTransferFunction)
    volumeProperty.ShadeOn()
    volumeProperty.SetInterpolationTypeToLinear()

    # The mapper / ray cast function know how to render the data
    #volumeMapper = vtk.vtkGPUVolumeRayCastMapper()
    #volumeMapper = vtk.vtkSmartVolumeMapper()
    volumeMapper = vtk.vtkFixedPointVolumeRayCastMapper()
    volumeMapper.SetBlendModeToComposite()
    volumeMapper.SetInputConnection(reader.GetOutputPort())
    volumeMapper.SelectColorArray('smooth') ## -> exception

    # The volume holds the mapper and the property and
    # can be used to position/orient the volume
    volume = vtk.vtkVolume()
    volume.SetMapper(volumeMapper)
    volume.SetProperty(volumeProperty)

此外,是否可以将单元标量用于体积映射器?

谢谢

1 个答案:

答案 0 :(得分:1)

我使用 SetScalarsName 找到了以下解决方案:

class People(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, 
     unique=True)
    phone_number = models.CharField(max_length=200, blank=True, 
     null=True)
    #department = models.CharField(max_length=200, blank=True, null=True)
    title = models.CharField(max_length=200, choices= titles, blank=True, 
    null=True)

解决方案在这里找到:
https://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/DataManipulation/Python/pointToCellData.py