Qt 5.9 using VTK display point clouds

note:

1. The following tutorial first portion for mounting PCL reference, using the second portion of the effective measurement Qt affinity in VS; portion has third and fourth problems, it is desirable to understand how to use this tutorial by Qt visual point cloud may be disappointed, If you realize you still please let us know.

2. At present myself to both use Qt Designer interface can use PCL library practice is to use in VS PCL library and Qt library, if you want to visualize point clouds may need to define the visual classes and controls, and finally I do that again make up tutorial.

3. Based on file in VS using Qt libraries and library generation PCL want to release Qt is also similar with the general procedures required windeployqt * .exe command can be configured to perform using Qt Qt comes with command line exe file directory under dll; you can also run your own to see what is missing exe and dll find copied to the current folder, too. If you want to make the installation package, you can use your setupfactory packaged exe build the installation, I am familiar with this later also added a tutorial.

1.PCL installation and use of the PCL in VS2013

  (1) download PCL, Download link: https://pan.baidu.com/s/123QD1iKa5tfLPTwquP3j7Q  Password: v5q6. Click the PCL-1.8.0-AllInOne-msvc2015- win32.exe installed.

 

  (2) configuration environment variable. Add the environment variable name:

  PCL_ROOT, the path is set to PCL installation root directory.

  path环境变量添加 %PCL_ROOT%\bin;%PCL_ROOT%\3rdParty\FLANN\bin;%PCL_ROOT%\3rdParty\Qhull\bin;%PCL_ROOT%\3rdParty\VTK\bin;%PCL_ROOT%\3rdParty\OpenNI2\Tools。

 

  (3) Project Properties configuration. It could have in the project - set the properties in the properties, but every time we set would be too much trouble, so here to open the installation package PCLdebug.props and PCLrelease.props documentation that came directly import settings (if not also attribute table new projects), open method to open the properties Manager, right-corresponding solution platform to add an existing property sheet, and then Debug | Win32 add PCLdebug.props, Release | Win32 can add PCLrelease.props. as follows

                     

  Add attribute table here is not set, so in fact their new property sheet is the same, then we have to double-click to debug, release properties of the final table were set up to save directly to the next table you can add this property, do not set more than once. Double-click Configuration Properties property sheet click -VC ++ directory attribute setting, add the following directory in the directory that contains the library catalog, respectively,

  

  In the property sheet - Linker - Additional Dependencies inputs add the following dependency, if only to add to the corresponding folder in the other versions of the file lib dependencies can, as quickly export these lib file name, you can use batch command to export the reference https://www.cnblogs.com/blog-vincent-0x1F7/p/9646358.html .

//debug模式下添加的附加依赖项:

pcl_common_debug.lib
pcl_features_debug.lib
pcl_filters_debug.lib
pcl_io_debug.lib
pcl_io_ply_debug.lib
pcl_kdtree_debug.lib
pcl_keypoints_debug.lib
pcl_ml_debug.lib
pcl_octree_debug.lib
pcl_outofcore_debug.lib
pcl_people_debug.lib
pcl_recognition_debug.lib
pcl_registration_debug.lib
pcl_sample_consensus_debug.lib
pcl_search_debug.lib
pcl_segmentation_debug.lib
pcl_stereo_debug.lib
pcl_surface_debug.lib
pcl_tracking_debug.lib
pcl_visualization_debug.lib
libboost_atomic-vc120-mt-gd-1_59.lib
libboost_chrono-vc120-mt-gd-1_59.lib
libboost_container-vc120-mt-gd-1_59.lib
libboost_context-vc120-mt-gd-1_59.lib
libboost_coroutine-vc120-mt-gd-1_59.lib
libboost_date_time-vc120-mt-gd-1_59.lib
libboost_exception-vc120-mt-gd-1_59.lib
libboost_filesystem-vc120-mt-gd-1_59.lib
libboost_graph-vc120-mt-gd-1_59.lib
libboost_iostreams-vc120-mt-gd-1_59.lib
libboost_locale-vc120-mt-gd-1_59.lib
libboost_log-vc120-mt-gd-1_59.lib
libboost_log_setup-vc120-mt-gd-1_59.lib
libboost_math_c99-vc120-mt-gd-1_59.lib
libboost_math_c99f-vc120-mt-gd-1_59.lib
libboost_math_c99l-vc120-mt-gd-1_59.lib
libboost_math_tr1-vc120-mt-gd-1_59.lib
libboost_math_tr1f-vc120-mt-gd-1_59.lib
libboost_math_tr1l-vc120-mt-gd-1_59.lib
libboost_mpi-vc120-mt-gd-1_59.lib
libboost_prg_exec_monitor-vc120-mt-gd-1_59.lib
libboost_program_options-vc120-mt-gd-1_59.lib
libboost_random-vc120-mt-gd-1_59.lib
libboost_regex-vc120-mt-gd-1_59.lib
libboost_serialization-vc120-mt-gd-1_59.lib
libboost_signals-vc120-mt-gd-1_59.lib
libboost_system-vc120-mt-gd-1_59.lib
libboost_test_exec_monitor-vc120-mt-gd-1_59.lib
libboost_thread-vc120-mt-gd-1_59.lib
libboost_timer-vc120-mt-gd-1_59.lib
libboost_unit_test_framework-vc120-mt-gd-1_59.lib
libboost_wave-vc120-mt-gd-1_59.lib
libboost_wserialization-vc120-mt-gd-1_59.lib
vtkalglib-7.0-gd.lib
vtkChartsCore-7.0-gd.lib
vtkCommonCore-7.0-gd.lib
vtkCommonColor-7.0-gd.lib
vtkCommonComputationalGeometry-7.0-gd.lib
vtkCommonDataModel-7.0-gd.lib
vtkCommonExecutionModel-7.0-gd.lib
vtkCommonMath-7.0-gd.lib
vtkCommonMisc-7.0-gd.lib
vtkCommonSystem-7.0-gd.lib
vtkCommonTransforms-7.0-gd.lib
vtkDICOMParser-7.0-gd.lib
vtkDomainsChemistry-7.0-gd.lib
vtkexoIIc-7.0-gd.lib
vtkexpat-7.0-gd.lib
vtkFiltersAMR-7.0-gd.lib
vtkFiltersCore-7.0-gd.lib
vtkFiltersExtraction-7.0-gd.lib
vtkFiltersFlowPaths-7.0-gd.lib
vtkFiltersGeneral-7.0-gd.lib
vtkFiltersGeneric-7.0-gd.lib
vtkFiltersGeometry-7.0-gd.lib
vtkFiltersHybrid-7.0-gd.lib
vtkFiltersHyperTree-7.0-gd.lib
vtkFiltersImaging-7.0-gd.lib
vtkFiltersModeling-7.0-gd.lib
vtkFiltersParallel-7.0-gd.lib
vtkFiltersParallelImaging-7.0-gd.lib
vtkFiltersProgrammable-7.0-gd.lib
vtkFiltersSelection-7.0-gd.lib
vtkFiltersSMP-7.0-gd.lib
vtkFiltersSources-7.0-gd.lib
vtkFiltersStatistics-7.0-gd.lib
vtkFiltersTexture-7.0-gd.lib
vtkFiltersVerdict-7.0-gd.lib
vtkfreetype-7.0-gd.lib
vtkGeovisCore-7.0-gd.lib
vtkhdf5-7.0-gd.lib
vtkhdf5_hl-7.0-gd.lib
vtkImagingColor-7.0-gd.lib
vtkImagingCore-7.0-gd.lib
vtkImagingFourier-7.0-gd.lib
vtkImagingGeneral-7.0-gd.lib
vtkImagingHybrid-7.0-gd.lib
vtkImagingMath-7.0-gd.lib
vtkImagingMorphological-7.0-gd.lib
vtkImagingSources-7.0-gd.lib
vtkImagingStatistics-7.0-gd.lib
vtkImagingStencil-7.0-gd.lib
vtkInfovisCore-7.0-gd.lib
vtkInfovisLayout-7.0-gd.lib
vtkInteractionImage-7.0-gd.lib
vtkInteractionStyle-7.0-gd.lib
vtkInteractionWidgets-7.0-gd.lib
vtkIOAMR-7.0-gd.lib
vtkIOCore-7.0-gd.lib
vtkIOEnSight-7.0-gd.lib
vtkIOExodus-7.0-gd.lib
vtkIOExport-7.0-gd.lib
vtkIOGeometry-7.0-gd.lib
vtkIOImage-7.0-gd.lib
vtkIOImport-7.0-gd.lib
vtkIOInfovis-7.0-gd.lib
vtkIOLegacy-7.0-gd.lib
vtkIOLSDyna-7.0-gd.lib
vtkIOMINC-7.0-gd.lib
vtkIOMovie-7.0-gd.lib
vtkIONetCDF-7.0-gd.lib
vtkIOParallel-7.0-gd.lib
vtkIOParallelXML-7.0-gd.lib
vtkIOPLY-7.0-gd.lib
vtkIOSQL-7.0-gd.lib
vtkIOVideo-7.0-gd.lib
vtkIOXML-7.0-gd.lib
vtkIOXMLParser-7.0-gd.lib
vtkjpeg-7.0-gd.lib
vtkjsoncpp-7.0-gd.lib
vtklibxml2-7.0-gd.lib
vtkmetaio-7.0-gd.lib
vtkNetCDF-7.0-gd.lib
vtkNetCDF_cxx-7.0-gd.lib
vtkoggtheora-7.0-gd.lib
vtkParallelCore-7.0-gd.lib
vtkpng-7.0-gd.lib
vtkproj4-7.0-gd.lib
vtkRenderingAnnotation-7.0-gd.lib
vtkRenderingContext2D-7.0-gd.lib
vtkRenderingContextOpenGL2-7.0-gd.lib
vtkRenderingCore-7.0-gd.lib
vtkRenderingFreeType-7.0-gd.lib
vtkRenderingImage-7.0-gd.lib
vtkRenderingLabel-7.0-gd.lib
vtkRenderingLOD-7.0-gd.lib
vtkRenderingOpenGL2-7.0-gd.lib
vtkRenderingVolume-7.0-gd.lib
vtkRenderingVolumeOpenGL2-7.0-gd.lib
vtksqlite-7.0-gd.lib
vtksys-7.0-gd.lib
vtktiff-7.0-gd.lib
vtkverdict-7.0-gd.lib
vtkViewsContext2D-7.0-gd.lib
vtkViewsCore-7.0-gd.lib
vtkViewsInfovis-7.0-gd.lib
vtkzlib-7.0-gd.lib
vtkGUISupportQt-7.0-gd.lib
vtkRenderingQt-7.0-gd.lib
vtkViewsQt-7.0-gd.lib
flann_cpp_s-gd.lib
qhullstatic-gd.lib
OpenNI2.lib

//release模式下添加的附加依赖项:

pcl_common_release.lib
pcl_features_release.lib
pcl_filters_release.lib
pcl_io_release.lib
pcl_io_ply_release.lib
pcl_kdtree_release.lib
pcl_keypoints_release.lib
pcl_ml_release.lib
pcl_octree_release.lib
pcl_outofcore_release.lib
pcl_people_release.lib
pcl_recognition_release.lib
pcl_registration_release.lib
pcl_sample_consensus_release.lib
pcl_search_release.lib
pcl_segmentation_release.lib
pcl_stereo_release.lib
pcl_surface_release.lib
pcl_tracking_release.lib
pcl_visualization_release.lib
libboost_atomic-vc120-mt-1_59.lib
libboost_chrono-vc120-mt-1_59.lib
libboost_container-vc120-mt-1_59.lib
libboost_context-vc120-mt-1_59.lib
libboost_coroutine-vc120-mt-1_59.lib
libboost_date_time-vc120-mt-1_59.lib
libboost_exception-vc120-mt-1_59.lib
libboost_filesystem-vc120-mt-1_59.lib
libboost_graph-vc120-mt-1_59.lib
libboost_iostreams-vc120-mt-1_59.lib
libboost_locale-vc120-mt-1_59.lib
libboost_log-vc120-mt-1_59.lib
libboost_log_setup-vc120-mt-1_59.lib
libboost_math_c99-vc120-mt-1_59.lib
libboost_math_c99f-vc120-mt-1_59.lib
libboost_math_c99l-vc120-mt-1_59.lib
libboost_math_tr1-vc120-mt-1_59.lib
libboost_math_tr1f-vc120-mt-1_59.lib
libboost_math_tr1l-vc120-mt-1_59.lib
libboost_mpi-vc120-mt-1_59.lib
libboost_prg_exec_monitor-vc120-mt-1_59.lib
libboost_program_options-vc120-mt-1_59.lib
libboost_random-vc120-mt-1_59.lib
libboost_regex-vc120-mt-1_59.lib
libboost_serialization-vc120-mt-1_59.lib
libboost_signals-vc120-mt-1_59.lib
libboost_system-vc120-mt-1_59.lib
libboost_test_exec_monitor-vc120-mt-1_59.lib
libboost_thread-vc120-mt-1_59.lib
libboost_timer-vc120-mt-1_59.lib
libboost_unit_test_framework-vc120-mt-1_59.lib
libboost_wave-vc120-mt-1_59.lib
libboost_wserialization-vc120-mt-1_59.lib
vtkalglib-7.0.lib
vtkChartsCore-7.0.lib
vtkCommonCore-7.0.lib
vtkCommonColor-7.0.lib
vtkCommonComputationalGeometry-7.0.lib
vtkCommonDataModel-7.0.lib
vtkCommonExecutionModel-7.0.lib
vtkCommonMath-7.0.lib
vtkCommonMisc-7.0.lib
vtkCommonSystem-7.0.lib
vtkCommonTransforms-7.0.lib
vtkDICOMParser-7.0.lib
vtkDomainsChemistry-7.0.lib
vtkexoIIc-7.0.lib
vtkexpat-7.0.lib
vtkFiltersAMR-7.0.lib
vtkFiltersCore-7.0.lib
vtkFiltersExtraction-7.0.lib
vtkFiltersFlowPaths-7.0.lib
vtkFiltersGeneral-7.0.lib
vtkFiltersGeneric-7.0.lib
vtkFiltersGeometry-7.0.lib
vtkFiltersHybrid-7.0.lib
vtkFiltersHyperTree-7.0.lib
vtkFiltersImaging-7.0.lib
vtkFiltersModeling-7.0.lib
vtkFiltersParallel-7.0.lib
vtkFiltersParallelImaging-7.0.lib
vtkFiltersProgrammable-7.0.lib
vtkFiltersSelection-7.0.lib
vtkFiltersSMP-7.0.lib
vtkFiltersSources-7.0.lib
vtkFiltersStatistics-7.0.lib
vtkFiltersTexture-7.0.lib
vtkFiltersVerdict-7.0.lib
vtkfreetype-7.0.lib
vtkGeovisCore-7.0.lib
vtkhdf5-7.0.lib
vtkhdf5_hl-7.0.lib
vtkImagingColor-7.0.lib
vtkImagingCore-7.0.lib
vtkImagingFourier-7.0.lib
vtkImagingGeneral-7.0.lib
vtkImagingHybrid-7.0.lib
vtkImagingMath-7.0.lib
vtkImagingMorphological-7.0.lib
vtkImagingSources-7.0.lib
vtkImagingStatistics-7.0.lib
vtkImagingStencil-7.0.lib
vtkInfovisCore-7.0.lib
vtkInfovisLayout-7.0.lib
vtkInteractionImage-7.0.lib
vtkInteractionStyle-7.0.lib
vtkInteractionWidgets-7.0.lib
vtkIOAMR-7.0.lib
vtkIOCore-7.0.lib
vtkIOEnSight-7.0.lib
vtkIOExodus-7.0.lib
vtkIOExport-7.0.lib
vtkIOGeometry-7.0.lib
vtkIOImage-7.0.lib
vtkIOImport-7.0.lib
vtkIOInfovis-7.0.lib
vtkIOLegacy-7.0.lib
vtkIOLSDyna-7.0.lib
vtkIOMINC-7.0.lib
vtkIOMovie-7.0.lib
vtkIONetCDF-7.0.lib
vtkIOParallel-7.0.lib
vtkIOParallelXML-7.0.lib
vtkIOPLY-7.0.lib
vtkIOSQL-7.0.lib
vtkIOVideo-7.0.lib
vtkIOXML-7.0.lib
vtkIOXMLParser-7.0.lib
vtkjpeg-7.0.lib
vtkjsoncpp-7.0.lib
vtklibxml2-7.0.lib
vtkmetaio-7.0.lib
vtkNetCDF-7.0.lib
vtkNetCDF_cxx-7.0.lib
vtkoggtheora-7.0.lib
vtkParallelCore-7.0.lib
vtkpng-7.0.lib
vtkproj4-7.0.lib
vtkRenderingAnnotation-7.0.lib
vtkRenderingContext2D-7.0.lib
vtkRenderingContextOpenGL2-7.0.lib
vtkRenderingCore-7.0.lib
vtkRenderingFreeType-7.0.lib
vtkRenderingImage-7.0.lib
vtkRenderingLabel-7.0.lib
vtkRenderingLOD-7.0.lib
vtkRenderingOpenGL2-7.0.lib
vtkRenderingVolume-7.0.lib
vtkRenderingVolumeOpenGL2-7.0.lib
vtksqlite-7.0.lib
vtksys-7.0.lib
vtktiff-7.0.lib
vtkverdict-7.0.lib
vtkViewsContext2D-7.0.lib
vtkViewsCore-7.0.lib
vtkViewsInfovis-7.0.lib
vtkzlib-7.0.lib
vtkGUISupportQt-7.0.lib
vtkRenderingQt-7.0.lib
vtkViewsQt-7.0.lib
flann_cpp_s.lib
qhullstatic.lib
OpenNI2.lib

Write test code, create a c ++ program in win32 console, change the code as follows:

#include "stdafx.h"
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>

int user_data;

void viewerOneOff(pcl::visualization::PCLVisualizer& viewer)
{
    viewer.setBackgroundColor(1.0, 0.5, 1.0);
    pcl::PointXYZ o;
    o.x = 1.0;
    o.y = 0;
    o.z = 0;
    viewer.addSphere(o, 0.25, "sphere", 0);
    std::cout << "i only run once" << std::endl;

}

void viewerPsycho(pcl::visualization::PCLVisualizer& viewer)
{
    static unsigned count = 0;
    std::stringstream ss;
    ss << "Once per viewer loop: " << count++;
    viewer.removeShape("text", 0);
    viewer.addText(ss.str(), 200, 300, "text", 0);

    //FIXME: possible race condition here:
    user_data++;
}

int _tmain(int argc, _TCHAR* argv[])
{
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGBA>);
    pcl::io::loadPCDFile("example.pcd的位置", *cloud);

    pcl::visualization::CloudViewer viewer("Cloud Viewer");

    //blocks until the cloud is actually rendered
    viewer.showCloud(cloud);

    //use the following functions to get access to the underlying more advanced/powerful
    //PCLVisualizer

    //This will only get called once
    viewer.runOnVisualizationThreadOnce(viewerOneOff);

    //This will get called once per visualization iteration
    viewer.runOnVisualizationThread(viewerPsycho);
    while (!viewer.wasStopped())
    {
        //you can also do cool processing here
        //FIXME: Note that this is running in a separate thread from viewerPsycho
        //and you should guard against race conditions yourself...
        user_data++;
    }
    return 0;
}

This time run a test program is likely to throw an error c4996 error, simply in the project - property -C / C ++ - preprocessor - Add _SCL_SECURE_NO_WARNINGS processor can be pre-defined.

 

  After completion of the above settings do not forget to save the attribute table, right-click the attribute table can be saved. After the above steps, if you are lucky, PCL library can be used, and bad luck can only find out what the problem of your mother.

 

 

2.Vs2013 collaboration with Qt

  Tool - to expand and update - Online search can find Qt Qt visual studio Tools, click to download, then install it.

  安装完毕之后在界面菜单栏上会多一个Qt VS Tools菜单,点击Qt Options在Qt version中添加一项名称随意,路径设为Qt的安装目录下相应目录,即指定了Qt版本,这时候可以使用Qt了。

  

  测试一下,现在在文件-新建-项目向导中已经有Qt的内容,可以选择Qt GUI Application,就可以开发带有GUI界面的Qt程序。

  

  现在可以在VS中写代码,双击.ui文件可打开Qt Designer设计界面。

 

 

 

3.编译vtk

  参考https://blog.csdn.net/jepco1/article/details/80628026。原地址讲解会更详细。

  使用CMAKE配置VTK for Qt的编译环境,cmake版本为3.11.3,下载地址为https://cmake.org/download/。VTK使用版本为8.1.1,下载地址为https://www.vtk.org/download/

  下载VTK-8.1.1.zip和VTKData-8.1.1.zip于同一目录,解压到当前目录,二者会合并成一个文件夹,即编译源码所在目录。

 

  打开cmake,选择源码目录和构建目录(构建目录自己建一个),点击configure。

  选择visual studio 12 2013 win 32(对应版本的编译器,不然在Qt中没法使用)。

  选择BUILD_EXAMPLES,BUUILD_SHARED_LIBS,BUILD_TESTING。

  CMAKE_INSTALL_PREFIX选择VTK的安装目录。

  选择VTK_Group_Qt。点击configure。

  这里一般都会自动设置好。Qt5_DIR选择路径为F:/Qt/5.9.4/msvc2015_64/lib/cmake/Qt5。点击configure,configure done后点击generate。

  Generate done后点击Open Project即可在VS2015中打开项目。选择ALL_BUILD右键生成,生成完毕后改为release再生成一次release版本。这个过程会比较长。

 

  至此编译完成,将build/bin/release下的QVTKWidget.dll复制到Qt安装目录的plugins/designer下,这样打开Qt Designer就可以看到工具箱里有QVTKWidget控件了(在Qt Creator中是看不到的,在Qt Creator中使用QVTKWidget可以使用Widget代替,然后提升为QVTKWidget)。

 

4.在vs2013下使用vtk,Qt显示点云

  目前无法使用QVTKWidget,在VS2015中可以使用Qt Designer拖动QVTKWidget设计界面,但是运行时会出现错误,debug模式下调试出现error LNK2019: 无法解析的外部符号错误,看起来貌似是加载dll文件时无法识别QVTKWidget中的函数;release模式下则报错fatal error C1083: 无法打开包括文件: “QVTKWidget.h,看起来是不能找到头文件,即使是在项目属性的VC++目录的包含目录中添加相应包含目录也不成,添加包含目录后debug与release模式下均显示error LNK2019。

 

 

  

  而Qt下也不可使用QVTKWidget,Qt Creator中工具箱中没有QVTKWidget,虽可通过提升的方式使用QVTKWidget,但是运行的时候同样遇到问题。debug与release模式下都出现LNK 2019无法解析的外部符号问题,看起来貌似与visual studio中的报错是一样的。

  

  目前尚不知为何,有待进一步解决。

发布了28 篇原创文章 · 获赞 14 · 访问量 2万+

Guess you like

Origin blog.csdn.net/liyunxin_c_language/article/details/83188693