QVTKWidget not displaying objects wall's

一曲冷凌霜 提交于 2020-06-26 07:05:12

问题


I'm using the integration Qt-VTK widget (QVTKWidget) and the VTK objects i want to visualize do not display the way they supposed to.

I have modified the code of the CylinderRenderingPropertiesExample located on VTKExamples site.

The code

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <vtkCylinderSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkProperty.h>
#include <vtkCamera.h>
#include <vtkSmartPointer.h>
#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)


MainWindow::MainWindow(QWidget *parent): QMainWindow(parent),ui(new Ui::MainWindow){
    ui->setupUi(this);
    vtkSmartPointer<vtkCylinderSource> cylinder = vtkSmartPointer<vtkCylinderSource>::New();
    cylinder->SetResolution(8);
    vtkSmartPointer<vtkPolyDataMapper> cylinderMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    cylinderMapper->SetInputConnection(cylinder->GetOutputPort());
    vtkSmartPointer<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::New();
    cylinderActor->SetMapper(cylinderMapper);
    cylinderActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
    cylinderActor->RotateX(30.0);
    cylinderActor->RotateY(-45.0);
    vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor(cylinderActor);
    renderer->SetBackground(0.1, 0.2, 0.4);
    renderer->ResetCamera();
    renderer->GetActiveCamera()->Zoom(1.5);
    vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->SetSize(200, 200);
    renderWindow->AddRenderer(renderer);
    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    renderWindowInteractor->SetRenderWindow(renderWindow);
    ui->qvtkWidget->GetRenderWindow()->AddRenderer(renderer);
}

MainWindow::~MainWindow(){
    delete ui;
}

The problem

The way a cylinder renders in it's own window, outside main window. (Using renderWindow->Render();)

The way it's being rendered inside the main window As you can see the cillinder wall is transparent.

How can i make the cylinder render correctly inside the main window?


The .pro, just in case

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = QTVKApp
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS

SOURCES += \
        main.cpp \
        mainwindow.cpp

HEADERS += \
        mainwindow.h

FORMS += \
        mainwindow.ui

INCLUDEPATH += /usr/local/include/vtk-8.0
LIBS += -L/usr/local/lib

LIBS += -lvtkRenderingLabel-8.0 \
-lvtkRenderingLOD-8.0 \
-lvtkRenderingOpenGL2-8.0 \
-lvtkRenderingQt-8.0 \
-lvtkRenderingVolume-8.0 \
-lvtkRenderingVolumeOpenGL2-8.0 \
-lvtksqlite-8.0 \
-lvtksys-8.0 \
#-lvtkTestingGenericBridge-8.0 \
#-lvtkTestingIOSQL-8.0 \
#-lvtkTestingRendering-8.0 \
-lvtktiff-8.0 \
-lvtkverdict-8.0 \
-lvtkViewsContext2D-8.0 \
-lvtkViewsCore-8.0 \
-lvtkViewsInfovis-8.0 \
-lvtkViewsQt-8.0 \
-lvtkzlib-8.0 \
-lvtkalglib-8.0 \
-lvtkChartsCore-8.0 \
-lvtkCommonColor-8.0 \
-lvtkCommonComputationalGeometry-8.0 \
-lvtkCommonCore-8.0 \
-lvtkCommonDataModel-8.0 \
-lvtkCommonExecutionModel-8.0 \
-lvtkCommonMath-8.0 \
-lvtkCommonMisc-8.0 \
-lvtkCommonSystem-8.0 \
-lvtkCommonTransforms-8.0 \
-lvtkDICOMParser-8.0 \
-lvtkDomainsChemistry-8.0 \
-lvtkDomainsChemistryOpenGL2-8.0 \
-lvtkexoIIc-8.0 \
-lvtkexpat-8.0 \
-lvtkFiltersAMR-8.0 \
-lvtkFiltersCore-8.0 \
-lvtkFiltersExtraction-8.0 \
-lvtkFiltersFlowPaths-8.0 \
-lvtkFiltersGeneral-8.0 \
-lvtkFiltersGeneric-8.0 \
-lvtkFiltersGeometry-8.0 \
-lvtkFiltersHybrid-8.0 \
-lvtkFiltersHyperTree-8.0 \
-lvtkFiltersImaging-8.0 \
-lvtkFiltersModeling-8.0 \
-lvtkFiltersParallel-8.0 \
-lvtkFiltersParallelImaging-8.0 \
-lvtkFiltersPoints-8.0 \
-lvtkFiltersProgrammable-8.0 \
-lvtkFiltersSelection-8.0 \
-lvtkFiltersSMP-8.0 \
-lvtkFiltersSources-8.0 \
-lvtkFiltersStatistics-8.0 \
-lvtkFiltersTexture-8.0 \
-lvtkFiltersTopology-8.0 \
-lvtkFiltersVerdict-8.0 \
-lvtkfreetype-8.0 \
-lvtkGeovisCore-8.0 \
-lvtkgl2ps-8.0 \
-lvtkglew-8.0 \
-lvtkGUISupportQt-8.0 \
-lvtkGUISupportQtSQL-8.0 \
-lvtkhdf5_hl-8.0 \
-lvtkhdf5-8.0 \
-lvtkImagingColor-8.0 \
-lvtkImagingCore-8.0 \
-lvtkImagingFourier-8.0 \
-lvtkImagingGeneral-8.0 \
-lvtkImagingHybrid-8.0 \
-lvtkImagingMath-8.0 \
-lvtkImagingMorphological-8.0 \
-lvtkImagingSources-8.0 \
-lvtkImagingStatistics-8.0 \
-lvtkImagingStencil-8.0 \
-lvtkInfovisCore-8.0 \
-lvtkInfovisLayout-8.0 \
-lvtkInteractionImage-8.0 \
-lvtkInteractionStyle-8.0 \
-lvtkInteractionWidgets-8.0 \
-lvtkIOAMR-8.0 \
-lvtkIOCore-8.0 \
-lvtkIOEnSight-8.0 \
-lvtkIOExodus-8.0 \
-lvtkIOExport-8.0 \
-lvtkIOExportOpenGL2-8.0 \
-lvtkIOGeometry-8.0 \
-lvtkIOImage-8.0 \
-lvtkIOImport-8.0 \
-lvtkIOInfovis-8.0 \
-lvtkIOLegacy-8.0 \
-lvtkIOLSDyna-8.0 \
-lvtkIOMINC-8.0 \
-lvtkIOMovie-8.0 \
-lvtkIONetCDF-8.0 \
-lvtkIOParallel-8.0 \
-lvtkIOParallelXML-8.0 \
-lvtkIOPLY-8.0 \
-lvtkIOSQL-8.0 \
-lvtkIOTecplotTable-8.0 \
-lvtkIOVideo-8.0 \
-lvtkIOXML-8.0 \
-lvtkIOXMLParser-8.0 \
-lvtkjpeg-8.0 \
-lvtkjsoncpp-8.0 \
-lvtklibharu-8.0 \
-lvtklibxml2-8.0 \
#-lvtkLocalExample-8.0 \
-lvtklz4-8.0 \
-lvtkmetaio-8.0 \
-lvtknetcdf_c++ \
-lvtkNetCDF-8.0 \
-lvtkoggtheora-8.0 \
-lvtkParallelCore-8.0 \
-lvtkpng-8.0 \
-lvtkproj4-8.0 \
-lvtkRenderingAnnotation-8.0 \
-lvtkRenderingContext2D-8.0 \
-lvtkRenderingContextOpenGL2-8.0 \
-lvtkRenderingCore-8.0 \
-lvtkRenderingFreeType-8.0 \
-lvtkRenderingGL2PSOpenGL2-8.0 \
-lvtkRenderingImage-8.0 \

For anyone who wonders...The QVTKOpenGlWidget is not an option for me. The reason is that i cannot even compile the examples that integrate it, and i wasn't able to solve that.

My config

  • VTK 8.0.1
  • Qt 5.9.1
  • Cmake 3.5.2

来源:https://stackoverflow.com/questions/46837776/qvtkwidget-not-displaying-objects-walls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!