VTK示例不起作用 - QVTKOpenGLWidget?

时间:2017-10-17 10:17:12

标签: c++ qt vtk

我尝试进入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&)'的匹配函数    这 - > UI-> qvtkWidget-> SetRenderWindow(RenderWindow的);

RenderWindowUISingleInheritance.cxx:34:33:错误:没有匹配函数来调用'vtkRenderer :: AddActor(vtkNew&)'    renderer-> AddActor(sphereActor);

RenderWindowUISingleInheritance.cxx:37:64:错误:没有匹配函数来调用'vtkRenderWindow :: AddRenderer(vtkNew&)'    这 - > UI-> qvtkWidget-> GetRenderWindow() - > AddRenderer(渲染);

我不知道这个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标记代码中的行):

  1. Class'Ui_RenderWindowUISingleInheritance'没有'setupUI'功能
  2. Class'Ui_RenderWindowUISingleInheritance'没有字段'qvtkWidget'
  3. 参数类型不匹配:类型'vtkMapper *'和'vtkNew'不兼容
  4. 参数类型不匹配:类型'vtkProp *'和'vtkNew'不兼容
  5. Class'Ui_RenderWindowUISingleInheritance'没有字段'qvtkWidget'
  6. Class'Ui_RenderWindowUISingleInheritance'没有字段'actionExit'
  7. 无法解析变量'qApp'
  8. 我希望有人可以帮助我,因为我想进入VTK和Qt,这似乎是我开始使用它们之前的最后挑战之一。即使你只能帮助我解决这个问题的一小部分,请告诉我,因为每一个小步骤都可以帮助我自己解决剩下的问题!

    提前致谢

1 个答案:

答案 0 :(得分:1)

我在我的环境中构建了这个例子。要编译,您需要更正文件 RenderWindowUISingleInheritance.cxx .get()放在这些对象中SetRenderWindow( renderWindow.Get()),SetMapper ( sphereMapper.Get()),AddActor( sphereActor.Get())和AddRenderer( renderer.Get()):

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