将文件BMP链读入VTK并通过Python + QT渲染体积3d

时间:2018-12-09 17:35:55

标签: python 3d vtk bmp

我想删除立方体的黑色部分,只留下橙色。 但是我不知道怎么做。 我的代码在下面。

enter image description here enter image description here

         self.ren = vtk.vtkRenderer()
         self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
         self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
         reader = vtk.vtkBMPReader()
         reader.SetFilePrefix("C:/Users/tia chop/Documents/cttrung/")
         reader.SetFilePattern("%s%d.bmp")
         reader.SetFileNameSliceOffset(0)
         #reader.SetFileNameSliceSpacing(1)
         #reader.GetDataScalarType()
         reader.SetDataSpacing(400,400,400)
         reader.SetDataExtent(0,399,0,399,0,399)
         reader.Update()

        colors = vtk.vtkNamedColors()
        colors.SetColor("BkgColor", [51, 77, 102, 255])
        volumeMapper = vtk.vtkGPUVolumeRayCastMapper()
        volumeMapper.SetInputConnection(reader.GetOutputPort())

        volumeColor = vtk.vtkColorTransferFunction()
        volumeColor.AddRGBPoint(500, 1.0, 0.5, 0.3)
        volumeColor.AddRGBPoint(1000, 1.0, 0.5, 0.3)
        volumeColor.AddRGBPoint(1150, 1.0, 1.0, 0.9)

        volumeScalarOpacity = vtk.vtkPiecewiseFunction()
        volumeScalarOpacity.AddPoint(0, 0.00)
        volumeScalarOpacity.AddPoint(500, 0.1)
        volumeScalarOpacity.AddPoint(1500, 0.15)
        volumeScalarOpacity.AddPoint(2150, .9)

        volumeGradientOpacity = vtk.vtkPiecewiseFunction()
        volumeGradientOpacity.AddPoint(10, 0.0)
        volumeGradientOpacity.AddPoint(100, 0.5)
        volumeGradientOpacity.AddPoint(200, 1.0)



        volumeProperty = vtk.vtkVolumeProperty()
        volumeProperty.SetColor(volumeColor)
        volumeProperty.SetScalarOpacity(volumeScalarOpacity)

        volumeProperty.SetInterpolationTypeToLinear()
        volumeProperty.ShadeOn()
        volumeProperty.SetAmbient(0.4)
        volumeProperty.SetDiffuse(0.6)
        volumeProperty.SetSpecular(0.2)

        volume = vtk.vtkVolume()
        volume.SetMapper(volumeMapper)
        volume.SetProperty(volumeProperty)

       self.ren.AddViewProp(volume)

1 个答案:

答案 0 :(得分:0)

已解决。在读取bmp文件时,我添加了“ reader.Allow8BitBMPOn()”。 结果如下:enter image description here