2017-10-17 225 views
0

我试图进入Qt和VTK,并且我有很多障碍来实现这一目标。谷歌和stackoverflow帮助我很多,但我不能自己解决这个问题。这是关于QVTKOpenGLWidget。我不知道如何得到这个和这个例子是不是为我工作:VTK示例不起作用 - 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) 

如果我尝试运行它,我得到以下errormessages:

RenderWindowUISingleInheritance.cxx:21:53:错误:调用 'QVTKOpenGLWidget :: SetRenderWindow(vtkNew &)' 不匹配函数 这个 - >用户界面 - > QV tkWidget-> SetRenderWindow(RenderWindow的);

RenderWindowUISingleInheritance.cxx:34:33:错误:用于调用“vtkRenderer :: AddActor(vtkNew &)” renderer-> AddActor(sphereActor)无匹配功能;

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

我不知道这个QVTKOpenGLWidget来自哪里以及我如何得到它,但似乎你必须使用这个而不是QtTKOpenWidget与Qt5,但它似乎不工作?我对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. 班 'Ui_RenderWindowUISingleInheritance' 不有一个函数'setupUI'
  2. 类'Ui_RenderWindowUISingleInheritance'没有字段'qvtkWidget'
  3. 参数类型不匹配:类型'v tkMapper *“和‘vtkNew’不兼容
  4. 参数类型不匹配:类型‘vtkProp *’和‘vtkNew’不兼容
  5. 班‘Ui_RenderWindowUISingleInheritance’没有场‘qvtkWidget’
  6. 类” Ui_RenderWindowUISingleInheritance”没有场‘actionExit’
  7. 无法解析变量‘qApp’

我希望有人能帮助我,因为我想进入VTK和Qt,这似乎是一个在我可以开始与他们合作之前的最后挑战。即使你只能帮助一小部分,请让我知道,因为每一个小步骤都可以帮助我自己解决其余的问题!

在此先感谢

+0

我也有类似的问题。安装这两个是非常痛苦的。我读到QVTKWidget正在被弃用,所以所有的例子都使用QVTKOpenGlWidget。但几乎没有关于如何使它们一起工作的文档 – Hernan

回答

0

我在我的环境中构建此示例。编译你将需要更正RenderWindowUISingleInheritance文件。CXX获得()在这些对象SetRenderWindow(renderWindow.Get()),SetMapper(sphereMapper.Get()),AddActor(sphereActor.Get())和AddRenderer(渲染器。获取()):

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