2017-10-17 223 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(); 
}