我正在使用集成 Qt-VTK 小部件 (QVTKWidget),而我想要可视化的 VTK 对象不会以它们应该的方式显示。
我已经修改了位于 VTKExamples 站点上的CylinderRenderingPropertiesExample的代码。
编码
#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;
}
问题
圆柱体在其自己的窗口中呈现的方式,在主窗口之外。(使用渲染窗口->渲染();)
如何使圆柱体在主窗口内正确渲染?
.pro,以防万一
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 \
对于任何想知道的人... QVTKOpenGlWidget 对我来说不是一个选择。原因是我什至无法编译集成它的示例,我无法解决这个问题。
我的配置
- VTK 8.0.1
- Qt 5.9.1
- Cmake 3.5.2