0

我目前正在转换最初在 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 by 中定义 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();

终端返回我:

“没有匹配函数调用 'QObject::connect(QSlider*&, const char [19], vtkRenderWindowInteractor*&, const char [42])”

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

提前致谢

4

1 回答 1

1

只需使用新的信号/槽语法lambda...

 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);
                  });
于 2021-04-12T08:02:12.053 回答