赞
踩
参考:
VTK8.2.0在Windows10+VS2017+Qt 5.12环境下编译安装_annjeff的博客-CSDN博客
WIN 10 + Qt 5.12 + CMake 2.23 + VS2022 + VTK 8.2 教程 - 知乎
VTK笔记-Qt5.12.11编译VTK9.0.3-QVTKOpenGLNativeWidget_黑山老妖的博客的博客-CSDN博客
下载VTK之后解压,新建三个文件夹分别命名
管理员方式打开Cmake,填写要编译的源文件和放的位置点configure
选VS和x64
configure后会有爆红
1,prefix选新建的放debug的文件夹,是安装的文件夹
2,example不选会没有后面的例子测试
3,group_qt要选上
4,qt5-dir要选上如图的位置,可能要configure好几遍,也可能一次搜不出来,configure之后再搜
5,CMAKE_DEBUG_POSTFIX后面添加-d这样进行Debug版本编译时会在库文件名后面多个-d(这一步我没有)
6,还有一个VTK_QT_VERSION 5 要选5,可能搜不到,那就不管
出现 configure done 之后没有红色,就点击generate。
找到vtk.sln文件双击点开
点击最上面选项栏的生成,点击批生成
先release,但是会被放到debug的文件夹里
生成的文件在刚刚设定的文件里,剪切到Release里,重复上面的all-build和install,改成debug。
将Release 版本下 VTK-8.2.0-Install-VS2017-x64-Release\plugins\designer\QVTKWidgetPlugin.dll复制到 Qt Creator的5.12.0\msvc2017_64\plugins\designer\文件夹下
打开Qt designer,会看到新的vtk插件
选一个example,这里选的cube
ctrl+f5
左键右键快乐滑滑
1,新建Qt项目(全都默认也可以)
2,点击pro文件,更改pro。添加vtk源和vtk库 可以用之前release的源和库也可以是debug的源和库。加哪一种运行的时候就用哪种模式。
获取lib文件下的目录:Windows+R调用出cmd命令行,输入dir E:\2022-software\VTK\VTK-8.2.0-Install-VS2017-x64-Release\lib /b >E:\2022-software\VTK\VTK-8.2.0-Install-VS2017-x64-Release\lib\libsname.txt
参考这个
dos读取文件夹的所有文件名_dadadaXJ的博客-CSDN博客_dos命令获取文件夹下文件名
- #//2022年7月17日21:30:08更改
- INCLUDEPATH += "E:/2022-software/VTK/VTK-8.2.0-Install-VS2017-x64-Release/include/vtk-8.2/"
- INCLUDEPATH += "E:/2022-software/VTK/VTK-8.2.0-Install-VS2017-x64-Release/include/vtk-8.2/vtkhdf5"
-
- LIBS += -L$$quote("E:/2022-software/VTK/VTK-8.2.0-Install-VS2017-x64-Release/lib/")
- LIBS += vtkChartsCore-8.2.lib\
- vtkCommonColor-8.2.lib\
- vtkCommonComputationalGeometry-8.2.lib\
- vtkCommonCore-8.2.lib\
- vtkCommonDataModel-8.2.lib\
- vtkCommonExecutionModel-8.2.lib\
- vtkCommonMath-8.2.lib\
- vtkCommonMisc-8.2.lib\
- vtkCommonSystem-8.2.lib\
- vtkCommonTransforms-8.2.lib\
- vtkDICOMParser-8.2.lib\
- vtkDomainsChemistry-8.2.lib\
- vtkDomainsChemistryOpenGL2-8.2.lib\
- vtkdoubleconversion-8.2.lib\
- vtkexodusII-8.2.lib\
- vtkexpat-8.2.lib\
- vtkFiltersAMR-8.2.lib\
- vtkFiltersCore-8.2.lib\
- vtkFiltersExtraction-8.2.lib\
- vtkFiltersFlowPaths-8.2.lib\
- vtkFiltersGeneral-8.2.lib\
- vtkFiltersGeneric-8.2.lib\
- vtkFiltersGeometry-8.2.lib\
- vtkFiltersHybrid-8.2.lib\
- vtkFiltersHyperTree-8.2.lib\
- vtkFiltersImaging-8.2.lib\
- vtkFiltersModeling-8.2.lib\
- vtkFiltersParallel-8.2.lib\
- vtkFiltersParallelImaging-8.2.lib\
- vtkFiltersPoints-8.2.lib\
- vtkFiltersProgrammable-8.2.lib\
- vtkFiltersSelection-8.2.lib\
- vtkFiltersSMP-8.2.lib\
- vtkFiltersSources-8.2.lib\
- vtkFiltersStatistics-8.2.lib\
- vtkFiltersTexture-8.2.lib\
- vtkFiltersTopology-8.2.lib\
- vtkFiltersVerdict-8.2.lib\
- vtkfreetype-8.2.lib\
- vtkGeovisCore-8.2.lib\
- vtkgl2ps-8.2.lib\
- vtkglew-8.2.lib\
- vtkGUISupportQt-8.2.lib\
- vtkGUISupportQtSQL-8.2.lib\
- vtkhdf5-8.2.lib\
- vtkhdf5_hl-8.2.lib\
- vtkImagingColor-8.2.lib\
- vtkImagingCore-8.2.lib\
- vtkImagingFourier-8.2.lib\
- vtkImagingGeneral-8.2.lib\
- vtkImagingHybrid-8.2.lib\
- vtkImagingMath-8.2.lib\
- vtkImagingMorphological-8.2.lib\
- vtkImagingSources-8.2.lib\
- vtkImagingStatistics-8.2.lib\
- vtkImagingStencil-8.2.lib\
- vtkInfovisCore-8.2.lib\
- vtkInfovisLayout-8.2.lib\
- vtkInteractionImage-8.2.lib\
- vtkInteractionStyle-8.2.lib\
- vtkInteractionWidgets-8.2.lib\
- vtkIOAMR-8.2.lib\
- vtkIOAsynchronous-8.2.lib\
- vtkIOCityGML-8.2.lib\
- vtkIOCore-8.2.lib\
- vtkIOEnSight-8.2.lib\
- vtkIOExodus-8.2.lib\
- vtkIOExport-8.2.lib\
- vtkIOExportOpenGL2-8.2.lib\
- vtkIOExportPDF-8.2.lib\
- vtkIOGeometry-8.2.lib\
- vtkIOImage-8.2.lib\
- vtkIOImport-8.2.lib\
- vtkIOInfovis-8.2.lib\
- vtkIOLegacy-8.2.lib\
- vtkIOLSDyna-8.2.lib\
- vtkIOMINC-8.2.lib\
- vtkIOMovie-8.2.lib\
- vtkIONetCDF-8.2.lib\
- vtkIOParallel-8.2.lib\
- vtkIOParallelXML-8.2.lib\
- vtkIOPLY-8.2.lib\
- vtkIOSegY-8.2.lib\
- vtkIOSQL-8.2.lib\
- vtkIOTecplotTable-8.2.lib\
- vtkIOVeraOut-8.2.lib\
- vtkIOVideo-8.2.lib\
- vtkIOXML-8.2.lib\
- vtkIOXMLParser-8.2.lib\
- vtkjpeg-8.2.lib\
- vtkjsoncpp-8.2.lib\
- vtklibharu-8.2.lib\
- vtklibxml2-8.2.lib\
- vtkLocalExample-8.2.lib\
- vtklz4-8.2.lib\
- vtklzma-8.2.lib\
- vtkmetaio-8.2.lib\
- vtkNetCDF-8.2.lib\
- vtkogg-8.2.lib\
- vtkParallelCore-8.2.lib\
- vtkpng-8.2.lib\
- vtkproj-8.2.lib\
- vtkpugixml-8.2.lib\
- vtkRenderingAnnotation-8.2.lib\
- vtkRenderingContext2D-8.2.lib\
- vtkRenderingContextOpenGL2-8.2.lib\
- vtkRenderingCore-8.2.lib\
- vtkRenderingFreeType-8.2.lib\
- vtkRenderingGL2PSOpenGL2-8.2.lib\
- vtkRenderingImage-8.2.lib\
- vtkRenderingLabel-8.2.lib\
- vtkRenderingLOD-8.2.lib\
- vtkRenderingOpenGL2-8.2.lib\
- vtkRenderingQt-8.2.lib\
- vtkRenderingVolume-8.2.lib\
- vtkRenderingVolumeOpenGL2-8.2.lib\
- vtksqlite-8.2.lib\
- vtksys-8.2.lib\
- vtktheora-8.2.lib\
- vtktiff-8.2.lib\
- vtkverdict-8.2.lib\
- vtkViewsContext2D-8.2.lib\
- vtkViewsCore-8.2.lib\
- vtkViewsInfovis-8.2.lib\
- vtkViewsQt-8.2.lib\
- vtkzlib-8.2.lib\
-
-
- #//到这里为止
3,更改mainwindow.h
- #ifndef INITIAL_OPENGL
- #define INITIAL_OPENGL
- #include <vtkAutoInit.h>
- VTK_MODULE_INIT(vtkRenderingOpenGL2)
- VTK_MODULE_INIT(vtkInteractionStyle)
- VTK_MODULE_INIT(vtkRenderingFreeType)
- #endif
斜杠如果放到lib前面可能会有无法解析的情况
4,mainwindow.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 = "E:/Qtwork/firstVTK/iphone1.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);
-
- setCentralWidget(ui->widget);
- ui->widget->SetRenderWindow(window);
-
-
- }
-
- MainWindow::~MainWindow()
- {
- delete ui;
- }
stl 文件的下载地址
GitHub - kingarthas37/3d-printer-files: 3d打印的stl、max文件存储
5,进入UI界面
选择widget或者OpenGl widget拖到框里,这里选的是widget
右键选择提升为,填写QVTKOpenGLWidget和QVTKOpenGLWidget.h点击添加,就会加到上面的框框里,选择之后点提升,就可以使用了。
6,选择运行模式运行
7,出现程序运行错误 The process was ended forcefully
点击生成的程序,把E:\2022-software\VTK\VTK-8.2.0-Install-VS2017-x64-Release\bin里面的lib文件都复制到E:\Qtwork\build-firstVTK-Desktop_Qt_5_12_8_MSVC2017_64bit-Release\release中,这个build-firstVTK-Desktop_Qt_5_12_8_MSVC2017_64bit-Release是在运行后生成的文件。
如果是debug模式就复制debug下的lib进去
8, QWidget: Must construct a QApplication before a QWidget
还出现了这个错误,但是啥也没改,就是把lib重新复制了一遍就好了
9,mainwindow.cpp:50:14: error: no member named 'widget' in 'Ui::MainWindow'
解决:重构就可以
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。