连接用户自定义函数以使用 Qt Widgets 修改 VTK 对象

Connect user custome function to modify VTK object with Qt Widgets

我目前正在转换最初在 python 下创建的项目,允许使用基本上由滑块组成的 Qt 界面修改 .vtk 文件的可视化。 python下的项目可以正常使用,可以在这里查阅:

[https://github.com/sebgra/VTK_modelisation/blob/master/Projet_Modelisation_Bovio_Gradit.py][1]

我在使用“个人”功能将滑块连接到 vtk 渲染器时遇到问题。在 python 下,只需使用 :

即可完成连接
def modif1():
        contour_bone.SetValue(0, Slider_1.value())
        iren.ReInitialize()
 
Slider_1 = QSlider(QtCore.Qt.Horizontal)
    Slider_1.setMinimum(0)
    Slider_1.setMaximum(200)
    Slider_1.setValue(90)
    Slider_1.valueChanged.connect(Display_1.display)
    Slider_1.valueChanged.connect(modif1)
 
# avec iren défini comme
 
mapper_bone=vtk.vtkPolyDataMapper()
    mapper_bone.SetInputConnection(contour_bone.GetOutputPort())  
    mapper_bone.SetLookupTable(lut_bone)
 
    mapper_skin=vtk.vtkPolyDataMapper()
    mapper_skin.SetInputConnection(contour_skin.GetOutputPort())
    mapper_skin.SetLookupTable(lut_skin)
 
    actor_bone=vtk.vtkActor()
    actor_bone.SetMapper(mapper_bone)
 
    actor_skin=vtk.vtkActor()
    actor_skin.SetMapper(mapper_skin)
 
    ren = vtk.vtkRenderer()
    vtkWidget.GetRenderWindow().AddRenderer(ren)
 
    iren = vtkWidget.GetRenderWindow().GetInteractor()
 
 
 
    ren.AddActor(actor_bone)
    ren.AddActor(actor_skin)
    ren.ResetCamera()
    frame.setLayout(vl)
    #setCentralWidget(self.frame)
    #show()
    iren.Initialize()
    iren.Start()
    iren.ReInitialize()

此 repo 上提供了 C++ 等价物:

[https://github.com/sebgra/VTK_Modelisation_CPP/blob/master/src/StructuredPointsReader.cxx][1]

通过 main 中的 modif_1 定义:

void modif_1(QSlider *m_Slider, vtkSmartPointer<vtkContourFilter> m_ContourFilter, vtkRenderWindowInteractor* m_iren  ){
 
  // m_ContourFilter -> setValue(0,m_Slider -> value());
  // m_iren -> ReInitialize();
  std::cout << "done" << endl;
}

有:

QSlider *Slider_1 = new QSlider(Qt::Horizontal, 0);
 
vtkSmartPointer<vtkStructuredPointsReader> reader =
    vtkSmartPointer<vtkStructuredPointsReader>::New();
  reader->SetFileName(inputFilename.c_str());
  reader->Update();
 
vtkSmartPointer<vtkContourFilter> contour_skin =
    vtkSmartPointer<vtkContourFilter>::New();
 
  contour_skin -> SetInputConnection(reader -> GetOutputPort());
  contour_skin -> SetNumberOfContours(1);
  contour_skin -> SetValue(0,50.0);
 
 
vtkSmartPointer<vtkPolyDataMapper> mapper_skin =
  vtkSmartPointer<vtkPolyDataMapper>::New();
 
  mapper_skin -> SetInputConnection(contour_skin -> GetOutputPort());
  mapper_skin -> SetLookupTable(lut_skin);
 
vtkSmartPointer<vtkActor> actor_skin =
  vtkSmartPointer<vtkActor>::New();
 
  actor_skin -> SetMapper(mapper_skin);
 
vtkSmartPointer<vtkRenderer> renderer =
  vtkSmartPointer<vtkRenderer>::New();
 
  widget -> GetRenderWindow() -> AddRenderer(renderer);
 
 
vtkRenderWindowInteractor* iren = widget->GetRenderWindow()->GetInteractor();// Get interactor
 
  iren -> Initialize();
  iren -> Start();
 
 
  QObject::connect(Slider_1, SIGNAL(valueChanged(int)), Display_1,SLOT(display(int)));
  QObject::connect(Slider_1, SIGNAL(valueChanged(int)), iren, SLOT(modif_1(&Slider_1, &contour_bone, &iren)));
 
 iren -> ReInitialize();

终端returns我:

"no matching function for call to ‘QObject::connect(QSlider*&, const char [19], vtkRenderWindowInteractor*&, const char [42])"

有人可以帮助我将 modif_1 连接到 vtk 渲染器 (iren) 吗?

提前致谢

只需使用新的 signal/slot syntaxlambda...

 QObject::connect(Slider_1, &QSlider::valueChanged,
                  [&Slider_1, &iren, &contour_bone](int value)
                  {
                      modif_1(&Slider_1, &contour_bone, &iren);
                  });

但请注意,仅使用 QSlider::valueChanged 信号的值而不是将指针传递给关联的 QSlider...

可能更简单
void modif_1(int value, vtkSmartPointer<vtkContourFilter> m_ContourFilter, vtkRenderWindowInteractor *m_iren);

    .
    .
    .

QObject::connect(Slider_1, &QSlider::valueChanged,
                  [&iren, &contour_bone](int value)
                  {
                      modif_1(value, &contour_bone, &iren);
                  });