我如何使自定义事件与VTK
How do I make a custom event with VTK?
我正在使用VTK制作线程软件,我需要实时更改模型本身,而我需要更改他的渲染方法。一切都很好,但是,问题从interactor->start();
开始,模型数据更新得很好,但只有当我移动相机时才显示在屏幕上。此外,我还选择了一些从imagedata文件生成3D数据的方法,为此我需要关闭vtk窗口(交互器窗口),然后代码将重新打开它并将生成的新数据发送给它…
我需要这样的东西:
int force close_window = false; int refresh_interactor = false;
我设法使窗口关闭,但只使用vtkcommand::Keypressed
命令,但idk我如何使用新命令:S,我尝试了vtkcommand::UserEvent
,但我没有找到关于如何处理该数据的良好信息(如某种方式调用它)
我处理VTK的方式是两个线程,第一个,只是关于VTK iren循环,第二个将管理模型并检查iren是否需要更新。
在我的梦想代码应该是这样的:
=======================================================
bool VTKWindow()
{
...
vtkSmartPointer ator = vtkSmartPointer::New();
iren = vtkSmartPointer::New();
RenWindow = vtkSmartPointer::New();
render->SetBackground(.1, .2, .3);
RenWindow->AddRenderer(renderer);
iren->SetRenderWindow(RenWindow);
if(data_type == voxel_type)
{
Render->AddViewProp(VoxelData);
}
else
{
actor->SetMapper(PolyData);
Render->AddActor(Actor);
}
RenWindow->Render();
iren->Start();
}
void ManageVTK()
{
while true loop...
if(force close_window == true)
do some command to exit the iren loop
if(refresh_interactor == true)
do some command to refresh iren
}
对不起,英语不是我的母语,也对不起问题的格式,这是我第一次使用stackoverflow
这听起来可能很愚蠢,但是,我找到了一种解决问题的方法。我在相关链接上看到这个家伙vtkRenderWindowInteractor事件循环和线程,这几乎是相同的问题…
class VTKNewEvent : public vtkCommand{
public:
vtkTypeMacro(VTKNewEvent , vtkCommand);
static VTKNewEvent * New(){
return new VTKNewEvent ;
}
void Execute(vtkObject * caller, unsigned long vtkNotUsed(eventId), void * vtkNotUsed(callData)){
vtkRenderWindowInteractor *iren = static_cast<vtkRenderWindowInteractor*>(caller);
if (iren_close == true){
iren->GetRenderWindow()->Finalize // Stop the interactor
iren->TerminateApp();
iren_close = false;
}
if (iren_update== true){
renderJanela->Render();
iren_update= false;
}
}
};
bool VTKWindow(){
vtkSmartPointer<VTKNewEvent > IrenRefresh= vtkSmartPointer<VTKNewEvent>::New();
...
iren->CreateRepeatingTimer(1);//this makes that IrenRefresh will be called at every 1ms
iren->AddObserver(vtkCommand::TimerEvent, IrenRefresh);
iren->Start();
...
}
它很简单,但是,也许不是最好的,但它做了这项工作,我希望这个链接将帮助人们开始进入VTK世界,因为线程+渲染循环不是一个简单的工作来理解发生了什么
相关文章:
- Qt VTK交互风格的信号到小部件
- Android NDK传感器向事件队列报告奇怪的间隔
- 从文本文件中读取时钟时间和事件时间并进行处理
- WMI检测进程创建事件-c++
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 处理闪烁窗口事件
- C++Builder中的OnClick事件签名存在问题
- 跟踪滚动条上的鼠标事件
- 什么是事件表 (wxWidgets)?
- 如何在 MFCaptureEngine 中获取"Camera removed"事件
- 给定顺序中的事件处理
- 当服务中的事件被触发时,如何将响应从服务发送回客户端?
- 在 C++/CLI 中将 .NET 事件从一个 DLL 引发到另一个 DLL
- 如何创建事件驱动的 SDL2 应用程序
- Windows 进程间同步类似事件?
- 如何从C++端挂接到 QML 项的 onClick 事件
- 如何禁用VTK的热键
- 如何通过多类"Union variable" (sfml) 使用轮询事件
- 如何在Qt 4.8中阻止/忽略/丢弃早于特定超时的用户输入事件
- 我如何使自定义事件与VTK