- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我尝试使用 vtkActor::RotateZ
旋转一个 vtkActor
,然后调用 vtkRenderWindow::Render
。它工作正常(旋转 Actor )但我无法移动、调整窗口大小,甚至无法聚焦窗口。
我怀疑这是由于未捕获操作系统事件引起的,因此我添加了一个 vtkRenderWindowInteractor
到组合中。现在我可以移动窗口、调整窗口大小和聚焦窗口,但 Actor 不再旋转。
我在下面的代码片段中分离了代码,注释第 43 行以查看两种效果:
renderWindowInteractor->Start();
我正在使用 mingw-w64 (GCC 4.9.1) 编译 VTK 6.2,在 Windows 8.1 中运行。我已经在 this repo 中上传了代码使用小型 CMake 设置,以便您可以轻松地对其进行测试。
感谢您的帮助!
constexpr float planeWidth = 200.0f;
constexpr float planeHeight = 100.0f;
int main()
{
auto renderer = vtkRenderer::New();
// Create render window
auto renWin = vtkRenderWindow::New();
renWin->AddRenderer(renderer);
renWin->SetSize(600,600);
// Create a plane
auto texturedPlane = vtkActor::New();
auto plane = vtkPlaneSource::New();
plane->SetOrigin(0, planeHeight, 0);
plane->SetPoint1(planeWidth, planeHeight, 0);
plane->SetPoint2(0, 0, 0);
auto planeMapper = vtkPolyDataMapper::New();
planeMapper->SetInputConnection(plane->GetOutputPort());
texturedPlane->SetMapper(planeMapper);
texturedPlane->SetOrigin(planeWidth / 2, planeHeight, 0);
renderer->AddActor(texturedPlane);
renderer->ResetCamera();
// Create a RenderWindowInteractor
auto renderWindowInteractor = vtkRenderWindowInteractor::New();
renderWindowInteractor->SetRenderWindow(renWin);
renderWindowInteractor->Start(); // <-- Comment this line!
// Render
float rot = 0.0f;
while(true)
{
texturedPlane->SetOrientation(0,0,0);
texturedPlane->RotateZ(rot++);
renWin->Render();
}
}
使用asdfasdf的方案解决:(代码在this repo)
constexpr float planeWidth = 200.0f;
constexpr float planeHeight = 100.0f;
vtkActor * texturedPlane;
vtkRenderWindowInteractor * renderWindowInteractor;
vtkRenderWindow * renWin;
float rot = 0.0f;
class RotateCommand : public vtkCommand
{
public:
vtkTypeMacro(RotateCommand, vtkCommand);
static RotateCommand * New()
{
return new RotateCommand;
}
void Execute(vtkObject * vtkNotUsed(caller),
unsigned long vtkNotUsed(eventId),
void * vtkNotUsed(callData))
{
texturedPlane->SetOrientation(0,0,0);
texturedPlane->RotateZ(rot++);
renWin->Render();
}
};
int main()
{
auto renderer = vtkRenderer::New();
// Create render window
renWin = vtkRenderWindow::New();
renWin->AddRenderer(renderer);
renWin->SetSize(600,600);
// Create a plane
texturedPlane = vtkActor::New();
auto plane = vtkPlaneSource::New();
plane->SetOrigin(0, planeHeight, 0);
plane->SetPoint1(planeWidth, planeHeight, 0);
plane->SetPoint2(0, 0, 0);
auto planeMapper = vtkPolyDataMapper::New();
planeMapper->SetInputConnection(plane->GetOutputPort());
texturedPlane->SetMapper(planeMapper);
texturedPlane->SetOrigin(planeWidth / 2, planeHeight, 0);
renderer->AddActor(texturedPlane);
renderer->ResetCamera();
// Create a RenderWindowInteractor
renderWindowInteractor = vtkRenderWindowInteractor::New();
renderWindowInteractor->SetRenderWindow(renWin);
renderWindowInteractor->Initialize();
renderWindowInteractor->CreateRepeatingTimer(1);
RotateCommand * rotateCallback = RotateCommand::New();
renderWindowInteractor->AddObserver(vtkCommand::TimerEvent, rotateCallback );
renderWindowInteractor->Start();
}
最佳答案
破解以解决部分问题。
vtkRenderWindowInteractor * renderWindowInteractor;
constexpr float planeWidth = 200.0f;
constexpr float planeHeight = 100.0f;
class CommandSubclass2 : public vtkCommand
{
public:
vtkTypeMacro(CommandSubclass2, vtkCommand);
static CommandSubclass2 *New()
{
return new CommandSubclass2;
}
void Execute(vtkObject *vtkNotUsed(caller), unsigned long vtkNotUsed(eventId),
void *vtkNotUsed(callData))
{
std::cout << "timer callback" << std::endl;
renderWindowInteractor->ExitCallback();
}
};
int main()
{
auto renderer = vtkRenderer::New();
// Create render window
auto renWin = vtkRenderWindow::New();
renWin->AddRenderer(renderer);
renWin->SetSize(600,600);
// Create a plane
auto texturedPlane = vtkActor::New();
auto plane = vtkPlaneSource::New();
plane->SetOrigin(0, planeHeight, 0);
plane->SetPoint1(planeWidth, planeHeight, 0);
plane->SetPoint2(0, 0, 0);
auto planeMapper = vtkPolyDataMapper::New();
planeMapper->SetInputConnection(plane->GetOutputPort());
texturedPlane->SetMapper(planeMapper);
texturedPlane->SetOrigin(planeWidth / 2, planeHeight, 0);
renderer->AddActor(texturedPlane);
renderer->ResetCamera();
// Create a RenderWindowInteractor
renderWindowInteractor = vtkRenderWindowInteractor::New();
renderWindowInteractor->SetRenderWindow(renWin);
renderWindowInteractor->Initialize();
renderWindowInteractor->CreateRepeatingTimer(1);
vtkSmartPointer<CommandSubclass2> timerCallback = vtkSmartPointer<CommandSubclass2>::New();
renderWindowInteractor->AddObserver ( vtkCommand::TimerEvent, timerCallback );
// Render
float rot = 0.0f;
while(true)
{
renderWindowInteractor->Start(); // <-- Comment this line!
texturedPlane->SetOrientation(0,0,0);
texturedPlane->RotateZ(rot++);
renWin->Render();
}
}
如果我没有给你任何其他回复,我很抱歉,但是由于这个解决方案很糟糕,我一直在等待其他人找到更好的解决方案,但似乎没有人回答你,所以这里是我会做什么。
您几乎可以猜到它的作用。开始交互后,每隔 1 ms,调用一个回调来停止交互,并进行轮换。
关于c++ - VTK:在 vtkRenderWindowInteractor 处于事件状态时以编程方式旋转 Actor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31075569/
我正在尝试在 IN sql 条件下使用数据库字段。我的字段是一串由逗号分隔的值(如 it,en,fr,de),我必须在 WHERE 子句中使用它,如下所示: WHERE d.iso639code =
他大家 我的以下代码有问题: import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp e
在处理 ReadOnlyMany 存储时,我正在努力理解 PersistentVolume 上的容量参数的概念,以及 PersistentVolumeClaim 上的存储请求。如果存储以只读方式安装
我试图让一个 while 循环在另一个 while 循环中工作,我之前已经让它工作过,但无法再次管理它。 我试图计算航类查询中的总记录,然后在小时记录中尝试添加时间。我已经让所有查询单独工作,但是当我
我们的数据库更新性能偶尔会大幅下降。 例如,表 FooTable 我们有大约 40 列与 varchar PK 此外还有 10 个索引。以下查询用时 44 秒,而在其他时候它几乎立即运行。在减速期间,
我可以在 Release模式下使用 Trace.WriteLine 吗? Trace.Write 和 Debug.Write 之间的主要区别是什么? 最佳答案 不同之处在于 Release模式。 当未
我刚刚遇到了一个非常奇怪的场景,并且在其他地方找不到任何相关信息。当 Xcode 在我的断点处中断时,整个系统的所有键盘输入都没有响应。我可以切换到另一个应用程序,但没有记录任何击键。 Xcode 本
我一直在尝试在一组 Raspberry Pi 上设置 K8s 集群。这是我的 GitHub 页面的链接,描述了整个设置: https://github.com/joesan/plant-infra/b
我的 pod 处于 Pending 状态,因为提到的所有答案我都试图获得描述输出但不知道为什么它保持在 Pending 状态: k8s@k8s-master:~/deployment$ kubectl
我已经开发了一个非消耗性的应用内购买iOS应用程序。我已经获取了应用内购买的 bundle 包标识符,并编写了代码并将其提交给appstore ...提交应用程序后,其状态显示在-App Purcha
我有 2 个具有一对多关系的实体,一个地址可以是多个员工。 MySQL 数据库: 地址 address_id INT PK AutoIncr 城市 VARCHAR 国家/地区 VARCHAR 员工 i
我想在我的项目中使用 ProGuard。我激活了选项 minifyEnabled。当我打开使用库 Retrofit2 的 Activity 时,应用程序崩溃并显示: 无法为接口(interface)
我刚刚在 MVC 应用程序中启用了 Application Insights,并注意到在本地调试时,我的 Azure Application Insight 中会捕获跟踪信息。 处于 Debug模式时
我正在使用一个启动和结束线程的类。线程是在构造函数中创建的。只要标志为 TRUE,线程函数就会继续循环。该标志是该类的静态成员。解构器将标志设置为 FALSE。这样,该类的每个实例都有一个关联的线程,
我有一个 Angular PWA。在我从 Angular 5.0 升级到 7.2 之前,它的 service worker 工作完美 升级后,我在/ngsw/state中看到以下错误 Driver s
可能有一些背景:当用户单击它时,我试图在可滚动的全屏 EditText 上方显示一个特定的键盘 View 。问题是如果光标位于 EditText 的底部,它会被弹出的键盘 View 隐藏。 与常规 I
当进度条处于 Activity 状态时禁用后台交互的正确方法是什么。 Box( modifier = Modifier.fillMaxSize(), contentAlignmen
这个问题在这里已经有了答案: Draw Rectangle inside picture box SizeMode Zoom (1 个回答) 关闭 3 年前。 我有一个 PictureBox1,其
我们刚刚开始在 kubernetes 上创建我们的集群。 现在我们尝试部署分蘖,但出现错误: NetworkPlugin cni failed to set up pod "tiller-deploy
我使用 NRPE 插件将一台 Linux 主机配置为 Nagios 监控服务器。 为此,我遵循以下 URL http://www.tecmint.com/how-to-add-linux-host-t
我是一名优秀的程序员,十分优秀!