vtkRenderWindowInteractor event loop and threading

℡╲_俬逩灬. 提交于 2019-12-04 04:16:01

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/31158342/vtkrenderwindowinteractor-event-loop-and-threading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!