这是什么错误?:未绑定方法需要 vtkRenderingCorePython.vtkAbstractMapper 作为第一个参数

瑞奇

我现在在 Python 中使用 VTK。这是我第一次用 Python 编程。输出 3D 对象后,我们要使用该AddClippingPlane函数输出对象的横截面但是会显示如下错误,不会执行:

TypeError: unbound method 需要一个 vtkRenderingCorePython.vtkAbstractMapper 作为第一个参数。

当你看到附加的代码时,你能告诉我有什么问题吗?我将不胜感激您的帮助。

import vtk
import sys
from PyQt5 import QtCore,QtWidgets
from PyQt5.QtGui import  *
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
from PyQt5.QtWidgets import QMainWindow, QApplication
from foo import Ui_MainWindow
from PyQt5 import Qt

class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setMouseTracking(True)
        self.setupUi(self) 
        self.pushButton.clicked.connect(self.OpenVTK)     
        self.pushButton2.clicked.connect(
            QtCore.QCoreApplication.instance().quit)


    def OpenVTK(self):
        self.setMouseTracking(True)

        self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
        self.vl = Qt.QVBoxLayout()
        self.vl.addWidget(self.vtkWidget)
        self.ren = vtk.vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()

        reader = vtk.vtkDICOMImageReader()
        reader.SetDirectoryName(FilePath)

        reader.Update()
        colors = vtk.vtkNamedColors()
        colors.SetColor("BkgColor", [51, 77, 102, 255])
        boneExtractor = vtk.vtkMarchingCubes()
        boneExtractor.SetInputConnection(reader.GetOutputPort())
        boneExtractor.SetValue(0, 1000)
        boneStripper = vtk.vtkStripper()
        boneStripper.SetInputConnection(boneExtractor.GetOutputPort())
        boneMapper = vtk.vtkPolyDataMapper()
        boneMapper.SetInputConnection(boneStripper.GetOutputPort())
        boneMapper.ScalarVisibilityOff()
        plane1 = vtk.vtkPlane()
        plane1.SetOrigin(0.05, 0.0, 0.0)  # [*1]
        plane1.SetNormal(-1.0, 0.0, 0.0)

        bone = vtk.vtkActor()
        bone.SetMapper(boneMapper)
        bone.GetProperty().SetDiffuseColor(colors.GetColor3d("Ivory"))
        bone = vtk.vtkAbstractMapper.AddClippingPlane(plane1)

        bwLut = vtk.vtkLookupTable()
        bwLut.SetTableRange(0, 2000)
        bwLut.SetSaturationRange(0, 1)
        bwLut.SetHueRange(0, 0)
        bwLut.SetValueRange(0, 1)
        bwLut.Build() 

        sagittalColors = vtk.vtkImageMapToColors()
        sagittalColors.SetInputConnection(reader.GetOutputPort())
        sagittalColors.SetLookupTable(bwLut)
        sagittalColors.Update()

        sagittal = vtk.vtkImageActor()
        sagittal.GetMapper().SetInputConnection(sagittalColors.GetOutputPort())
        sagittal.SetDisplayExtent(250, 250, 0, 501, 0, 500) 

        aCamera = vtk.vtkCamera()
        aCamera.SetViewUp(0, 0, -1)
        aCamera.SetPosition(0, -1, 0)
        aCamera.SetFocalPoint(0, 0, 0)
        aCamera.ComputeViewPlaneNormal()
        aCamera.Azimuth(0.0)
        aCamera.Elevation(0.0)


        self.ren.AddActor(sagittal)
        self.ren.AddActor(bone)
        self.ren.SetActiveCamera(aCamera)
        self.show()
        self.ren.ResetCamera()
        self.frame.setLayout(self.vl)
        aCamera.Dolly(1.0)

        self.ren.ResetCameraClippingRange()
        self.show()
        self.iren.Initialize()
        self.iren.Start()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())
迪米特里·厄诺特

您的错误来自行bone = vtk.vtkAbstractMapper.AddClippingPlane(plane1)

AddClippingPlane()是一个实例方法,必须应用于对象。

它应该是这样的 boneMapper.AddClippingPlane(plane1)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

未绑定的方法f()必须以fibo_实例作为第一个参数调用(取而代之的是class classobj实例)

为什么建议使用ctx作为第一个参数?

必须以实例作为第一个参数调用未绑定方法-python

将对象指针作为成员函数的第一个参数传递:这是标准的吗?

必须以实例作为第一个参数调用未绑定方法

我可以将hash作为方法中的第一个参数吗?

“ [`”的第一个参数的名字是什么?

必须以MyModel实例作为第一个参数来调用未绑定方法save()

为什么Blob构造函数只将数组作为第一个参数?

为什么fputs()需要常量作为第一个参数而不是fputc()?

仅更改列表中第一个元素的方法(将列表作为参数传递)

ADO未传递第一个参数值

为什么线性回归不接受系列数据作为第一个参数?

为什么.fit()需要2D数组作为第一个参数?

数组作为Rails.cache.fetch方法中的第一个参数

错误:必须使用“类名”实例作为第一个参数来调用未绑定方法“方法名”(取而代之的是classobj实例)

未绑定的方法必须以实例作为第一个参数来调用

未绑定的方法equaldigits()必须以sut实例作为第一个参数来调用(取而代之的是int实例)

如何修复TypeError:必须使用Dropper实例作为第一个参数来调用未绑定方法

MATLAB ERROR Feval需要将函数句柄作为第一个参数

LLVMBlockAddress() 第一个参数是什么?

类型错误:必须使用 Link 实例作为第一个参数调用未绑定的方法 set_rank()(什么都没有)

方法应该有“self”作为第一个参数:装饰器的pylint错误

必须使用 Tk 实例作为第一个参数调用未绑定的方法 mainloop()(什么都没有)

类型错误:必须使用 Vars 实例作为第一个参数调用未绑定的方法 SendVars()(改为使用 bool 实例)

必须使用 UserLoginForm 实例作为第一个参数调用未绑定的方法 is_valid() (什么都没有)

Python 错误:必须使用 Point 实例作为第一个参数调用未绑定的方法 distance()(改为使用 classobj 实例)

mapstruct 1.3 无法获取 Enum 作为第一个方法参数

为什么 FormRecord 不允许使用对象作为第一个参数?