虽然我们在windows下安装PCL的时候就已经安装了VTK,由于跟着PCL安装的VTK是没有和QT联合编译的,所以在使用PCL和QT做点云可视化界面的时候是无法使用QT的插件QVTKWidget。
VTK 源码下载
Tags · VTK / VTK · GitLab
我这里的环境是Win10
Visual Studio:2017 Community
PCL :1.9.1
VTK:8.1.2
CMake:3.17.3
Qt:5.14.2
这里我是将原来的VTK版本备份了,然后删掉C盘PCL自带的那个。后面源码编译安装VTK放在自带的那个目录下。
1. CMake 及VS 编译完设置路径安装到C盘,没有权限;
VS以管理员方式启动。
快捷方式上 右键 打开程序位置
找到vs安装目录下的:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe
右键->兼容性疑难解答->疑难解答程序->勾选改程序需要附加权限->测试后下一步->保存设置。
2. 没有看到qt选项,configure后可以看到。千万注意是右斜,win默认拷贝路径是左斜。选择路径后,记得回车,会自动切换到右斜。(记得回车)
CMAKE_INSTALL_PREFIX: C:/Program Files/PCL 1.9.1/3rdParty/VTK
cmake prefix 右斜 /
3. Qt路径
4. VTK debug版本的文件后缀
使用 Add Entry
按钮添加缓存变量 CMAKE_DEBUG_POSTFIX,类型为 STRING,值设置为 -gd。这是为了将最后编译的 debug 文件与 release 文件区分开来。
VTK测试程序
编译完成后新建命令行控制程序。
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkProperty.h"
#include "windows.h"
#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);
int main()
{
vtkConeSource *cone = vtkConeSource::New();
cone->SetHeight(3.0);
cone->SetRadius(1.0);
cone->SetResolution(10);
vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
coneMapper->SetInputConnection(cone->GetOutputPort());
vtkActor *coneActor = vtkActor::New();
coneActor->SetMapper(coneMapper);
vtkRenderer *ren1 = vtkRenderer::New();
ren1->AddActor(coneActor);
ren1->SetBackground(0.1, 0.2, 0.4);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
renWin->SetSize(300, 300);
int i;
for (i = 0; i < 360; ++i)
{
renWin->Render();
ren1->GetActiveCamera()->Azimuth(i);
Sleep(200);
}
cone->Delete();
coneMapper->Delete();
coneActor->Delete();
ren1->Delete();
renWin->Delete();
return 0;
}
使用命令dir /b *.lib查看lib名称。填入VS链接路径(用最原始的CMD(快捷键Win + R,输入cmd),不要用Power shell 和Windows terminal,会报错)
vtkalglib-8.1.lib
vtkChartsCore-8.1.lib
vtkCommonColor-8.1.lib
vtkCommonComputationalGeometry-8.1.lib
vtkCommonCore-8.1.lib
vtkCommonDataModel-8.1.lib
vtkCommonExecutionModel-8.1.lib
vtkCommonMath-8.1.lib
vtkCommonMisc-8.1.lib
vtkCommonSystem-8.1.lib
vtkCommonTransforms-8.1.lib
vtkDICOMParser-8.1.lib
vtkDomainsChemistry-8.1.lib
vtkDomainsChemistryOpenGL2-8.1.lib
vtkexoIIc-8.1.lib
vtkexpat-8.1.lib
vtkFiltersAMR-8.1.lib
vtkFiltersCore-8.1.lib
vtkFiltersExtraction-8.1.lib
vtkFiltersFlowPaths-8.1.lib
vtkFiltersGeneral-8.1.lib
vtkFiltersGeneric-8.1.lib
vtkFiltersGeometry-8.1.lib
vtkFiltersHybrid-8.1.lib
vtkFiltersHyperTree-8.1.lib
vtkFiltersImaging-8.1.lib
vtkFiltersModeling-8.1.lib
vtkFiltersParallel-8.1.lib
vtkFiltersParallelImaging-8.1.lib
vtkFiltersPoints-8.1.lib
vtkFiltersProgrammable-8.1.lib
vtkFiltersSelection-8.1.lib
vtkFiltersSMP-8.1.lib
vtkFiltersSources-8.1.lib
vtkFiltersStatistics-8.1.lib
vtkFiltersTexture-8.1.lib
vtkFiltersTopology-8.1.lib
vtkFiltersVerdict-8.1.lib
vtkfreetype-8.1.lib
vtkGeovisCore-8.1.lib
vtkgl2ps-8.1.lib
vtkglew-8.1.lib
vtkGUISupportQt-8.1.lib
vtkGUISupportQtOpenGL-8.1.lib
vtkGUISupportQtSQL-8.1.lib
vtkhdf5-8.1.lib
vtkhdf5_hl-8.1.lib
vtkImagingColor-8.1.lib
vtkImagingCore-8.1.lib
vtkImagingFourier-8.1.lib
vtkImagingGeneral-8.1.lib
vtkImagingHybrid-8.1.lib
vtkImagingMath-8.1.lib
vtkImagingMorphological-8.1.lib
vtkImagingSources-8.1.lib
vtkImagingStatistics-8.1.lib
vtkImagingStencil-8.1.lib
vtkInfovisCore-8.1.lib
vtkInfovisLayout-8.1.lib
vtkInteractionImage-8.1.lib
vtkInteractionStyle-8.1.lib
vtkInteractionWidgets-8.1.lib
vtkIOAMR-8.1.lib
vtkIOCore-8.1.lib
vtkIOEnSight-8.1.lib
vtkIOExodus-8.1.lib
vtkIOExport-8.1.lib
vtkIOExportOpenGL2-8.1.lib
vtkIOGeometry-8.1.lib
vtkIOImage-8.1.lib
vtkIOImport-8.1.lib
vtkIOInfovis-8.1.lib
vtkIOLegacy-8.1.lib
vtkIOLSDyna-8.1.lib
vtkIOMINC-8.1.lib
vtkIOMovie-8.1.lib
vtkIONetCDF-8.1.lib
vtkIOParallel-8.1.lib
vtkIOParallelXML-8.1.lib
vtkIOPLY-8.1.lib
vtkIOSQL-8.1.lib
vtkIOTecplotTable-8.1.lib
vtkIOVideo-8.1.lib
vtkIOXML-8.1.lib
vtkIOXMLParser-8.1.lib
vtkjpeg-8.1.lib
vtkjsoncpp-8.1.lib
vtklibharu-8.1.lib
vtklibxml2-8.1.lib
vtklz4-8.1.lib
vtkmetaio-8.1.lib
vtkNetCDF-8.1.lib
vtknetcdfcpp-8.1.lib
vtkoggtheora-8.1.lib
vtkParallelCore-8.1.lib
vtkpng-8.1.lib
vtkproj4-8.1.lib
vtkRenderingAnnotation-8.1.lib
vtkRenderingContext2D-8.1.lib
vtkRenderingContextOpenGL2-8.1.lib
vtkRenderingCore-8.1.lib
vtkRenderingFreeType-8.1.lib
vtkRenderingGL2PSOpenGL2-8.1.lib
vtkRenderingImage-8.1.lib
vtkRenderingLabel-8.1.lib
vtkRenderingLOD-8.1.lib
vtkRenderingOpenGL2-8.1.lib
vtkRenderingQt-8.1.lib
vtkRenderingVolume-8.1.lib
vtkRenderingVolumeOpenGL2-8.1.lib
vtksqlite-8.1.lib
vtksys-8.1.lib
vtktiff-8.1.lib
vtkverdict-8.1.lib
vtkViewsContext2D-8.1.lib
vtkViewsCore-8.1.lib
vtkViewsInfovis-8.1.lib
vtkViewsQt-8.1.lib
vtkzlib-8.1.lib
附加包含目录:C:\Program Files\PCL 1.9.1\3rdParty\VTK\include\vtk-8.1
附加库目录:C:\Program Files\PCL 1.9.1\3rdParty\VTK\lib;C:\Program Files\PCL 1.9.1\3rdParty\VTK\lib\cmake\vtk-8.1
经测试,在windows下用CMakeLists.txt配置Qt和PCL的VTK工程较为方便。而Linux下则是Qmake方便点。