Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vtkRenderWindowInteractor event loop and threading

What I am trying to do in an application using vtk for both interacting and rendering is to have two different parts: 1 - A thread with Rendering and vtkRenderWindowInteractor for interaction with mouse. 2 - A thread that call some modifier functions of the data defined in the VTK Thread.

From what I've gotten so far in my research it seems rather complicated and VTK is not thread safe. Now I've stumbled upon this post (http://vtk.1045678.n5.nabble.com/Multi-threaded-VTK-td4514620.html) on the VTK mailing list that suggests using Qt Signals and Slots. A first question would be is that still the good solution?

A second question which is still linked to that and to a problem that I've encountered before is that the start()of the vtkRenderWindowInteractor is blocking. And so far, no matter what I've tried all the modification done by rotation or translation or scaling functions are not done as long as the start() method is called (because I enter a rendering loop). My question would then be: If I use Qt Signals and Slots will that prevent me from that problem?

Here is the basic code that I have so far for rendering and lauching the vtkRenderWindowInteractor:

std::string filename = BUNNY;
// Read all the data from the file
vtkSmartPointer<vtkXMLPolyDataReader> reader =vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(filename.c_str());
reader->Update();
inputPolyData = reader->GetOutput();

cout << "File Found and Loaded : " << filename << endl ;

vtkSmartPointer<vtkTransform> translation = vtkSmartPointer<vtkTransform>::New();
translation->Translate(0.3, -0.05, 0);
transformFilter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
//transformFilter->SetInputConnection(reader->GetOutputPort());
transformFilter->SetInputData(inputPolyData);
transformFilter->SetTransform(translation);
//transformFilter->Update();

vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transformFilter->GetOutputPort());

mainActor = vtkSmartPointer<vtkActor>::New();
mainActor->SetMapper(mapper);

ren->AddActor(mainActor);

vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(win);
vtkInteractorStyleMultiTouchCamera *style =
vtkInteractorStyleMultiTouchCamera::New();
iren->SetInteractorStyle(style);

//Start the event loop
iren->Initialize();
iren->Start();

//defineClipping();
win->PolygonSmoothingOn();
win->Render();
win->Start();

ctxView->Render();

So that I could sum it up by asking: will Qt allow me to have to call transforming functions while the rendering and interacting thread of vtk is running with the blocking start() method of vtkRenderWindowInteractor? If not should I change my code and think about different possibilities for interacting with my objects in VTK?

like image 870
LBes Avatar asked Jul 01 '15 10:07

LBes


People also ask

What is vtkrenderwindowinteractor?

platform-independent render window interaction including picking and frame rate control. vtkRenderWindowInteractor provides a platform-independent interaction mechanism for mouse/key/time events.

How to detect the loop of renderwindow-interactor?

This Method detects loops of RenderWindow-Interactor, so objects are freed properly. More... Start the event loop. More... Run the event loop and return. More... Is the interactor loop done. More... Enable/Disable interactions. More... Event loop notification member for window size change. More...

How to manipulate timer in vtkxrenderwindowinteractor?

Reimplemented in vtkXRenderWindowInteractor. This class provides two groups of methods for manipulating timers. The first group (CreateTimer (timerType) and DestroyTimer ()) implicitly use an internal timer id (and are present for backward compatibility).

What is updatesize in vtkrenderwindowinteractor?

Definition at line 776 of file vtkRenderWindowInteractor.h. This methods sets the Size ivar of the interactor without actually changing the size of the window. Normally application programmers would use UpdateSize if anything.


1 Answers

I've been able to do rotations after calling start(), but in my case from the same thread.

The trick is to use a vtkCommand and set a timer in the vtkRenderWindowInteractor to call that command. That command is basically a callback that will be able to modify your actors.

You can see a working example of this in this thread.

Regarding the multi-threading approach you're using, maybe you could keep the rendering thread waiting in vtkCommand::Execute until the modifying thread is done. If you're able to use C++11 you could use a lot of the new tools available in the STL.

like image 190
Blito Avatar answered Oct 10 '22 02:10

Blito