工具:Qt Creator4.7.1 + 已编译生成的vtk8.2
#vtk部分#
详见---->https://wenku.baidu.com/view/ef13a7c94a7302768f9939ad.html
#QT部分#
1、首先创建一个Qt Widgets Application工程
点击完成(F)
后,便创建好项目,生成的工程文件如下
2、在xxx.pro文件添加一些语句
INCLUDEPATH +="C:\Program Files\VTK\vtk_release\include\vtk-8.2"
INCLUDEPATH +="C:\Program Files\VTK\vtk_release\include\vtk-8.2\vtkhdf5"
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkChartsCore-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkCommonColor-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkCommonComputationalGeometry-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkCommonCore-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkCommonDataModel-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkCommonExecutionModel-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkCommonMath-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkCommonMisc-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkCommonSystem-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkCommonTransforms-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkDICOMParser-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkDomainsChemistry-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkDomainsChemistryOpenGL2-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkdoubleconversion-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkexodusII-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkexpat-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersAMR-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersCore-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersExtraction-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersFlowPaths-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersGeneral-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersGeneric-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersGeometry-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersHybrid-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersHyperTree-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersImaging-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersModeling-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersParallel-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersParallelImaging-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersPoints-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersProgrammable-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersSelection-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersSMP-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersSources-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersStatistics-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersTexture-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersTopology-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkFiltersVerdict-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkfreetype-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkGeovisCore-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkgl2ps-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkglew-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkGUISupportQt-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkGUISupportQtSQL-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkhdf5-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkhdf5_hl-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkImagingColor-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkImagingCore-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkImagingFourier-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkImagingGeneral-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkImagingHybrid-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkImagingMath-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkImagingMorphological-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkImagingSources-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkImagingStatistics-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkImagingStencil-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkInfovisCore-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkInfovisLayout-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkInteractionImage-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkInteractionStyle-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkInteractionWidgets-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOAMR-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOAsynchronous-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOCityGML-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOCore-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOEnSight-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOExodus-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOExport-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOExportOpenGL2-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOExportPDF-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOGeometry-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOImage-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOImport-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOInfovis-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOLegacy-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOLSDyna-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOMINC-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOMovie-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIONetCDF-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOParallel-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOParallelXML-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOPLY-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOSegY-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOSQL-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOTecplotTable-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOVeraOut-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOVideo-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOXML-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkIOXMLParser-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkjpeg-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkjsoncpp-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtklibharu-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtklibxml2-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtklz4-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtklzma-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkmetaio-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkNetCDF-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkogg-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkParallelCore-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkpng-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkproj-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkpugixml-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkRenderingAnnotation-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkRenderingContext2D-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkRenderingContextOpenGL2-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkRenderingCore-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkRenderingFreeType-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkRenderingGL2PSOpenGL2-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkRenderingImage-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkRenderingLabel-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkRenderingLOD-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkRenderingOpenGL2-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkRenderingQt-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkRenderingVolume-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkRenderingVolumeOpenGL2-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtksqlite-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtksys-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtktheora-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtktiff-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkverdict-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkViewsContext2D-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkViewsCore-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkViewsInfovis-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkViewsQt-8.2.lib)
win32:LIBS += $$quote(C:\Program Files\VTK\vtk_release\lib\vtkzlib-8.2.lib)
诸多libs复制会花费大量时间,可以用cmd读取,详见https://blog.csdn.net/qq_41747960/article/details/104234991
3、在MainWindows.h添加语句
#ifndef INITIAL_OPENGL
#define INITIAL_OPENGL
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)
#endif
4、双击MainWindow.ui文件,进行界面的编辑
拖拽Widget控件到界面上
鼠标点击Widget控件,右键提升槽(promote to),在窗口中加入QVTKOpenGLWidget继承自QOpenGLWidget。注意其头文件为QVTKOpenGLWidget.h
添加后,再点击提升
至此QT实现vtk的可视化就配置好了。
#例子#
MainWindows.cpp
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <vtkPolyData.h>
#include <vtkSTLReader.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkGenericOpenGLRenderWindow.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
std::string inputFilename = "C:/Users/DALEE/Pictures/1.stl";//读取的stl文件
//读取文件
vtkSmartPointer<vtkSTLReader> reader =
vtkSmartPointer<vtkSTLReader>::New();
reader->SetFileName(inputFilename.c_str());
reader->Update();
//将source转换成mapper
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(reader->GetOutputPort());
//送入渲染引擎进行显示
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
//渲染
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
renderer->SetBackground(.0,.0,.0);
//设置渲染窗口
vtkSmartPointer<vtkGenericOpenGLRenderWindow> window =
vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
window->AddRenderer(renderer);
ui->widget->SetRenderWindow(window);
}
MainWindow::~MainWindow()
{
delete ui;
}
运行时可能没错误但不弹出窗口,可以更改为Release进行编译
结果图
来源:CSDN
作者:dadadaXJ
链接:https://blog.csdn.net/qq_41747960/article/details/104471790