I'm currently working on the conversion of a project initially made under python, allowing to modify the visualization of a .vtk file with a Qt interface essentially made of sliders. The project under python is functional and can be consulted here :
[https://github.com/sebgra/VTK_modelisation/blob/master/Projet_Modelisation_Bovio_Gradit.py][1]
I have a problem with the connection of the sliders to the vtk renderer, using a "personal" function. Under python the connection is simply done with :
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()
The C++ equivalent is available on this repo :
[https://github.com/sebgra/VTK_Modelisation_CPP/blob/master/src/StructuredPointsReader.cxx][1]
With the definition of modif_1 out of main by :
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;
}
With :
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();
The terminal returns me :
"no matching function for call to ‘QObject::connect(QSlider*&, const char [19], vtkRenderWindowInteractor*&, const char [42])"
Does someone can help me to connect modif_1 to the vtk renderer (iren) ?
Thanks in advance
Just use the new signal/slot syntax and a lambda
...
QObject::connect(Slider_1, &QSlider::valueChanged,
[&Slider_1, &iren, &contour_bone](int value)
{
modif_1(&Slider_1, &contour_bone, &iren);
});
Note, though, that it might be simpler to just use the value from the QSlider::valueChanged
signal rather than passing a pointer to the associated 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);
});