vtkRenderWindowInteractor事件循环和线程 [英] vtkRenderWindowInteractor event loop and threading

查看:3577
本文介绍了vtkRenderWindowInteractor事件循环和线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用vtk进行交互和渲染的应用程序中尝试做的是具有两个不同的部分:
1 - 与Rendering和vtkRenderWindowInteractor的线程与鼠标交互。
2 - 调用VTK线程中定义的数据的一些修饰符函数的线程。

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.

从我在研究中得到的东西似乎相当复杂,VTK不是线程安全的。现在我偶然发现了这个帖子( http:// vtk。 1045678.n5.nabble.com/Multi-threaded-VTK-td4514620.html )在VTK邮件列表上建议使用Qt信号和插槽。第一个问题是,仍然是好的解决方案?

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?

第二个问题仍然链接到这个问题,我遇到的问题是 start() vtkRenderWindowInteractor 是阻塞。到目前为止,无论我尝试了什么,只要start()方法被调用(因为我进入一个渲染循环),所有通过旋转或平移或缩放功能所做的修改都不会完成。
我的问题会是:如果我使用Qt信号和老虎机会阻止我的问题?

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?

这里是我迄今为止的基本代码用于渲染和修改vtkRenderWindowInteractor:

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();

所以我可以总结一下:Qt允许我必须调用转换函数vtk的渲染和交互线程使用 vtkRenderWindowInteractor 的阻塞 start()方法运行?如果没有,我应该更改我的代码,并考虑不同的可能性与我的对象在VTK交互。

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?

推荐答案

在调用 start()后执行旋转,但在我的情况下从同一个线程。

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

使用 vtkCommand 并在 vtkRenderWindowInteractor 中设置一个计时器来调用该命令。

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.

你可以在这个线程

关于多线程方法,也许你可以让渲染线程在 vtkCommand :: Execute 中等待,直到修改线程完成。如果你能够使用C ++ 11,你可以使用STL中提供的许多新工具。

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.

这篇关于vtkRenderWindowInteractor事件循环和线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆