[vtkusers] Trouble using VTK Widget with QVTK

andyjk andrewkeeling at hotmail.com
Thu Jul 5 04:23:46 EDT 2018


Hi

Old post but I am having the same issue too, with the same example - the
contour widget point placer found here :
https://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolygonalSurfaceContourLineInterpolator
<https://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolygonalSurfaceContourLineInterpolator>  

The issue seems to be that you cannot define a new interactor for a qvtk
widget. ie you cannot do :

vtkSmartPointer<vtkRenderWindowInteractor> interactor = 
       vtkSmartPointer<vtkRenderWindowInteractor>::New(); 
this->ui->qvtkWidget->GetRenderWindow()->SetInteractor(interactor);

This breaks the qvtkwidget (nothing appears on screen), even if you call:
ui->qvtkwidget->update();

or (out of desparation!) :

interactor->Initialise();
ui->qvtkwidget->update();
interactor->Start()

However, you can grab the exisiting qvtkwidget interactor and work with it
for some widgets:

vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
this->ui->qvtkWidget->GetRenderWindow()->GetInteractor();

BUT This doesn't work for the contour widget.

Heres what I tried (mostly from the example posted above). This version
won't even display my QT ui....

vtkSmartPointer<vtkRenderWindow> renderWindow =
this->ui->qvtkWidget->GetRenderWindow();
	vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
	interactor->SetRenderWindow(renderWindow);
/*
         // I already have a renderer set up with an actor
	// Add the actors to the renderer, set the background and size
	renderer->AddActor(tw_data_.pre_actor);
	renderer->SetBackground(.3, .4, .5);
*/
	// Here comes the contour widget stuff...
	vtkSmartPointer<vtkContourWidget> contourWidget =
vtkSmartPointer<vtkContourWidget>::New();
	contourWidget->SetInteractor(interactor);
	vtkSmartPointer<vtkOrientedGlyphContourRepresentation> rep =
		vtkOrientedGlyphContourRepresentation::SafeDownCast(
			contourWidget->GetRepresentation());
	rep->GetLinesProperty()->SetColor(0, 0, 1.0);
	rep->GetLinesProperty()->SetLineWidth(3.0);
	rep->GetProperty()->SetPointSize(10);
	rep->GetProperty()->SetRenderPointsAsSpheres(1);

	vtkSmartPointer<vtkPolygonalSurfacePointPlacer> pointPlacer =
vtkSmartPointer<vtkPolygonalSurfacePointPlacer>::New();
	pointPlacer->AddProp(tw_data_.pre_actor);
	pointPlacer->GetPolys()->AddItem(tw_data_.pre_poly);
	rep->SetPointPlacer(pointPlacer);
	
	this->ui->qvtkWidget->GetRenderWindow()->SetInteractor(interactor);
	this->ui->qvtkWidget->update();
	
	renderWindow->Render();
	interactor->Initialize();
	contourWidget->EnabledOn();
	renderer_->ResetCamera();
	interactor->Start();
	
If I comment out :
	// this->ui->qvtkWidget->GetRenderWindow()->SetInteractor(interactor);

and change:
contourWidget->SetInteractor(interactor);
to
contourWidget->SetInteractor(this->ui->qvtkWidget->GetRenderWindow()->GetInteractor());

then I get the QT ui displaying, and normal interaction working but no
contour widget.

If I set everything up on a separate vtk renderer/renderwindow (ie like a
non-QT pop-up window, the contour widget works fine).


Can anyone helps as to why QVTK interactor  doesn't work with contour
widget? 
It seems that the contourwidget requires an uninitialised interactor, but
the qvtkwidget interactor is always initialised before we can do anything
with it.





--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list