我尝试进入Qt和VTK,但要实现这一目标我遇到了很多障碍。谷歌和stackoverflow帮助了我很多,但是我自己不能解决这个问题。它与QVTKOpenGLWidget有关。我不知道该怎么办,这个例子对我不起作用:
https://lorensen.github.io/VTKExamples/site/Cxx/Qt/RenderWindowUISingleInheritance/
我还必须将以下行添加到CMakeLists.txt:
SET(VTK_DIR "/path/to/cmake/vtk-8.0" CACHE PATH "VTK directory override" FORCE)
如果我尝试运行它,则会收到以下错误消息:
RenderWindowUISingleInheritance.cxx:21:53:错误:没有匹配的函数可以调用“ QVTKOpenGLWidget :: SetRenderWindow(vtkNew&)”
this-> ui-> qvtkWidget-> SetRenderWindow(renderWindow);
RenderWindowUISingleInheritance.cxx:34:33:错误:没有匹配的函数可以调用“ vtkRenderer :: AddActor(vtkNew&)”
renderer-> AddActor(sphereActor);
RenderWindowUISingleInheritance.cxx:37:64:错误:没有匹配的函数可以调用“ vtkRenderWindow :: AddRenderer(vtkNew&)”
this-> ui-> qvtkWidget-> GetRenderWindow()-> AddRenderer(renderer);
我不知道此QVTKOpenGLWidget来自何处以及如何获得它,但似乎您必须使用它而不是Qt5来使用QVTKOpenWidget,但似乎无法正常工作?总的来说,我对Qt或VTK没有太多经验。因此,可能很容易解决。
RenderWindowUISingleInheritance.cxx:
#include "RenderWindowUISingleInheritance.h"
// This is included here because it is forward declared in
// RenderWindowUISingleInheritance.h
#include "ui_RenderWindowUISingleInheritance.h"
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkSphereSource.h>
// Constructor
RenderWindowUISingleInheritance::RenderWindowUISingleInheritance()
{
this->ui = new Ui_RenderWindowUISingleInheritance;
this->ui->setupUi(this); //*1
vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
this->ui->qvtkWidget->SetRenderWindow(renderWindow); //*2
// Sphere
vtkNew<vtkSphereSource> sphereSource;
sphereSource->Update();
vtkNew<vtkPolyDataMapper> sphereMapper;
sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
vtkNew<vtkActor> sphereActor;
sphereActor->SetMapper(sphereMapper); //*3
// VTK Renderer
vtkNew<vtkRenderer> renderer;
renderer->AddActor(sphereActor); //*4
// VTK/Qt wedded
this->ui->qvtkWidget->GetRenderWindow()->AddRenderer(renderer); //*5
// Set up action signals and slots
connect(this->ui->actionExit, SIGNAL(triggered()), this, SLOT(slotExit())); //*6
}
void RenderWindowUISingleInheritance::slotExit()
{
qApp->exit(); //*7
}
它还告诉我以下内容(用// * X标记代码中的行):
类'Ui_RenderWindowUISingleInheritance'没有函数'setupUI'
类“ Ui_RenderWindowUISingleInheritance”没有字段“ qvtkWidget”
参数类型不匹配:类型'vtkMapper *'和'vtkNew'不兼容
参数类型不匹配:类型'vtkProp *'和'vtkNew'不兼容
类“ Ui_RenderWindowUISingleInheritance”没有字段“ qvtkWidget”
类“ Ui_RenderWindowUISingleInheritance”没有字段“ actionExit”
无法解析变量“ qApp”
我希望有人可以帮助我,因为我想进入VTK和Qt,这似乎是我开始与他们合作之前的最后挑战之一。即使您只能为此提供一小部分帮助,也请让我知道,因为每一个小步骤都可以帮助我自己解决其余问题!
提前致谢
最佳答案
我在自己的环境中构建了这个示例。要进行编译,您需要纠正文件RenderWindowUISingleInheritance.cxx并将.get()放入这些对象SetRenderWindow(renderWindow.Get()),SetMapper(sphereMapper.Get()),AddActor(sphereActor.Get())和AddRenderer(renderer)。得到()):
#include "RenderWindowUISingleInheritance.h"
// This is included here because it is forward declared in
// RenderWindowUISingleInheritance.h
#include "ui_RenderWindowUISingleInheritance.h"
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkSphereSource.h>
// Constructor
RenderWindowUISingleInheritance::RenderWindowUISingleInheritance()
{
this->ui = new Ui_RenderWindowUISingleInheritance;
this->ui->setupUi(this);
vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
this->ui->qvtkWidget->SetRenderWindow(renderWindow.Get());
// Sphere
vtkNew<vtkSphereSource> sphereSource;
sphereSource->Update();
vtkNew<vtkPolyDataMapper> sphereMapper;
sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
vtkNew<vtkActor> sphereActor;
sphereActor->SetMapper(sphereMapper.Get());
// VTK Renderer
vtkNew<vtkRenderer> renderer;
renderer->AddActor(sphereActor.Get());
// VTK/Qt wedded
this->ui->qvtkWidget->GetRenderWindow()->AddRenderer(renderer.Get());
// Set up action signals and slots
connect(this->ui->actionExit, SIGNAL(triggered()), this, SLOT(slotExit()));
}
void RenderWindowUISingleInheritance::slotExit()
{
qApp->exit();
}
关于c++ - VTK示例不起作用-QVTKOpenGLWidget?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46787783/