Point cloud library PCL environment configuration: QT 5.9.2+ msvc2017 + PCL1.8.1 + VTK8.0

1. Background:

Since the project needs to filter, calculate, display and other operations on the sensor data, the existing lines that make up the surface are sequentially processed by the recursive median average filtering algorithm, the surface shape is not smooth enough, and the effect is relatively poor. Therefore, after consulting the data, I decided to try the point cloud library for related processing. It has been tested and solved the problem that the surface shape is not smooth enough. (PS: Data filtering and smoothing using moving least squares fitting MLS.)

2. Configuration steps and main issues:

The environment of QT 5.9.2 + msvc2017 was configured before, so I won’t introduce too much, mainly introduce the installation and configuration of PCL1.8.1 + VTK8.0.

1. Installation of PCL1.8.1

Note that the version of VC, PCL and QT must be consistent during installation, and the 32-bit and 64-bit must be consistent, choose 64-bit.

Double-click “PCL-1.8.1-AllInOne-msvc2017-win64.exe” to install. Note: In the case of joint development of pcl and QT, because QT does not support paths with Chinese and spaces, for example, you can install pcl on the D drive Under the root directory, as shown in the figure

This step is selected during installation:

During the installation process, the OpenNI2 installation window will pop up. I did not notice the directory “D:\PCL1.8.1\OpenNI2” was selected last time. In fact, it can be set in “D:\PCL1.8.1\3rdParty\OpenNI2”. When installing OpenNI2, it may prompt that the file path is too long, just click OK at this time.

After the installation is complete, to add the PCL environment variable, check the following path and add it to the system variable:

Unzip “PCL-1.8.1-pdb-msvc2017-win64.zip”, and copy all the .pdb files inside to the bin folder under the PCL installation path.

2. VTK8.0 configuration

VTK compilation, there is already VTK in PCL Why do you need to manually compile VTK?

PCL depends on VTK, you can see VTK in its 3rdParty directory. Then why do you have to manually compile VTK yourself? This is because the VTK in the PCL installation directory is not complete, and there are missing Qt-related modules, which are required for CloudViewer to compile and run (such as QVTKWidget). So we need to manually compile VTK and replace the VTK under PCL3rdParty.

It can be found that PCL1.8.1 depends on VTK8.0, so we compile this version of VTK (if you are using other versions of PCL, please compile the corresponding version of VTK). The source code of the corresponding version of VTK can be obtained from the release page under VTK Github. Before that, it is assumed that you have installed cmake and Visual Studio, the former is used to generate platform-dependent solutions, and the latter is used for compilation.

I found the VTK8.0 library compiled for win10\win11 from the Internet and downloaded it for direct use, so I skipped this step of compilation. If necessary, I can query the compilation steps and compilation precautions online.

Compiled library:

Replace all the files in the “D:\PCL1.8.1\3rdParty\VTK” directory with the Release version of the compiled or downloaded VTK file, integrate the files in the Debug lib into Also put it in the bin folder of Release.

Put the file “QVTKWidgetPlugin.dll” under the directory “D:\PCL1.8.1\3rdParty\VTK\plugins\designer” into this place under the QT installation directory “D:\Qt\Qt5.9.2 \5.9.2\msvc2017_64\plugins\designer”? ? ?

“QVTKWidgetPlugin-gd.dll” can not be put? ? ?

So far the VTK8.0 configuration is complete

3. QT5.9.2 project configuration uses PCL

Create a new text file, then write the following file, change the suffix to .pri, and then add the .pri file to the project. Comment out a few lines, because the file downloaded from the Internet may not be able to find these referenced files because of version or other issues.

INCLUDEPATH + = D:\PCL1.8.1\include\pcl-1.8

INCLUDEPATH + = D:\PCL1.8.1\include\pcl-1.8\pcl

INCLUDEPATH + = D:\PCL1.8.1\3rdParty\Boost\include\boost-1_64

INCLUDEPATH + = D:\PCL1.8.1\3rdParty\Boost\include\boost-1_64\boost

INCLUDEPATH + = D:\PCL1.8.1\3rdParty\Eigen\eigen3

INCLUDEPATH + = D:\PCL1.8.1\3rdParty\FLANN\include

INCLUDEPATH + = D:\PCL1.8.1\3rdParty\FLANN\include\flann

INCLUDEPATH + = D:\PCL1.8.1\OpenNI2\Include

INCLUDEPATH + = D:\PCL1.8.1\3rdParty\Qhull\include

INCLUDEPATH + = D:\PCL1.8.1\3rdParty\VTK\include\vtk-8.0


CONFIG(debug,debug|release){


LIBS + = -LD:\PCL1.8.1\lib\
        -lpcl_common_debug \
        -lpcl_features_debug \
        -lpcl_filters_debug\
        -lpcl_io_debug \
        -lpcl_io_ply_debug \
        -lpcl_kdtree_debug \
        -lpcl_keypoints_debug \
        -lpcl_ml_debug \
        -lpcl_octree_debug \
        -lpcl_outofcore_debug \
        -lpcl_people_debug \
        -lpcl_recognition_debug \
        -lpcl_registration_debug\
        -lpcl_sample_consensus_debug\
        -lpcl_search_debug \
        -lpcl_segmentation_debug\
        -lpcl_stereo_debug \
        -lpcl_surface_debug \
        -lpcl_tracking_debug \
        -lpcl_visualization_debug

LIBS + = -LD:\PCL1.8.1\3rdParty\Boost\lib\
        -llibboost_atomic-vc141-mt-gd-1_64\
        -llibboost_bzip2-vc141-mt-gd-1_64\
        -llibboost_chrono-vc141-mt-gd-1_64\
        -llibboost_container-vc141-mt-gd-1_64\
        -llibboost_context-vc141-mt-gd-1_64\
        -llibboost_coroutine-vc141-mt-gd-1_64\
        -llibboost_date_time-vc141-mt-gd-1_64\
        -llibboost_exception-vc141-mt-gd-1_64\
        -llibboost_fiber-vc141-mt-gd-1_64\
        -llibboost_filesystem-vc141-mt-gd-1_64\
        -llibboost_graph-vc141-mt-gd-1_64\
        -llibboost_graph_parallel-vc141-mt-gd-1_64\
        -llibboost_iostreams-vc141-mt-gd-1_64\
        -llibboost_locale-vc141-mt-gd-1_64\
        -llibboost_log-vc141-mt-gd-1_64\
        -llibboost_log_setup-vc141-mt-gd-1_64\
        -llibboost_math_c99-vc141-mt-gd-1_64\
        -llibboost_math_c99f-vc141-mt-gd-1_64\
        -llibboost_math_c99l-vc141-mt-gd-1_64\
        -llibboost_math_tr1-vc141-mt-gd-1_64\
        -llibboost_math_tr1f-vc141-mt-gd-1_64\
        -llibboost_math_tr1l-vc141-mt-gd-1_64\
        -llibboost_mpi-vc141-mt-gd-1_64\
        -llibboost_numpy-vc141-mt-gd-1_64\
        -llibboost_numpy3-vc141-mt-gd-1_64\
        -llibboost_prg_exec_monitor-vc141-mt-gd-1_64\
        -llibboost_program_options-vc141-mt-gd-1_64\
        -llibboost_python-vc141-mt-gd-1_64\
        -llibboost_python3-vc141-mt-gd-1_64\
        -llibboost_random-vc141-mt-gd-1_64\
        -llibboost_regex-vc141-mt-gd-1_64\
        -llibboost_serialization-vc141-mt-gd-1_64\
        -llibboost_signals-vc141-mt-gd-1_64\
        -llibboost_system-vc141-mt-gd-1_64\
        -llibboost_test_exec_monitor-vc141-mt-gd-1_64\
        -llibboost_thread-vc141-mt-gd-1_64\
        -llibboost_timer-vc141-mt-gd-1_64\
        -llibboost_type_erasure-vc141-mt-gd-1_64\
        -llibboost_unit_test_framework-vc141-mt-gd-1_64\
        -llibboost_wave-vc141-mt-gd-1_64\
        -llibboost_wserialization-vc141-mt-gd-1_64\
        -llibboost_zlib-vc141-mt-gd-1_64

LIBS + = -LD:\PCL1.8.1\3rdParty\FLANN\lib\
        -lflann-gd\
        -lflann_cpp-gd \
        -lflann_cpp_s-gd \
        -lflann_s-gd

LIBS + = -LD:\PCL1.8.1\OpenNI2\Lib\
        -lOpenNI2

LIBS + = -LD:\PCL1.8.1\3rdParty\Qhull\lib\
        -lqhull_d\
        -lqhullcpp_d\
        -lqhullstatic_d\
        -lqhullstatic_r_d\
        -lqhull_p_d\
        -lqhull_r_d

LIBS + = -LD:\PCL1.8.1\3rdParty\VTK\lib\
        -lvtkalglib-8.0-gd\
        -lvtkChartsCore-8.0-gd\
        -lvtkCommonColor-8.0-gd\
        -lvtkCommonComputationalGeometry-8.0-gd\
        -lvtkCommonCore-8.0-gd\
        -lvtkCommonDataModel-8.0-gd\
        -lvtkCommonExecutionModel-8.0-gd\
        -lvtkCommonMath-8.0-gd\
        -lvtkCommonMisc-8.0-gd\
        -lvtkCommonSystem-8.0-gd\
        -lvtkCommonTransforms-8.0-gd\
        -lvtkDICOMParser-8.0-gd\
        -lvtkDomainsChemistry-8.0-gd\
        -lvtkexoIIc-8.0-gd\
        -lvtkexpat-8.0-gd\
        -lvtkFiltersAMR-8.0-gd\
        -lvtkFiltersCore-8.0-gd\
        -lvtkFiltersExtraction-8.0-gd\
        -lvtkFiltersFlowPaths-8.0-gd\
        -lvtkFiltersGeneral-8.0-gd\
        -lvtkFiltersGeneric-8.0-gd\
        -lvtkFiltersGeometry-8.0-gd\
        -lvtkFiltersHybrid-8.0-gd\
        -lvtkFiltersHyperTree-8.0-gd\
        -lvtkFiltersImaging-8.0-gd\
        -lvtkFiltersModeling-8.0-gd\
        -lvtkFiltersParallel-8.0-gd\
        -lvtkFiltersParallelImaging-8.0-gd\
        -lvtkFiltersPoints-8.0-gd\
        -lvtkFiltersProgrammable-8.0-gd\
        -lvtkFiltersSelection-8.0-gd\
        -lvtkFiltersSMP-8.0-gd\
        -lvtkFiltersSources-8.0-gd\
        -lvtkFiltersStatistics-8.0-gd\
        -lvtkFiltersTexture-8.0-gd\
        -lvtkFiltersTopology-8.0-gd\
        -lvtkFiltersVerdict-8.0-gd\
        -lvtkfreetype-8.0-gd\
        -lvtkGeovisCore-8.0-gd\
        -lvtkgl2ps-8.0-gd\
        -lvtkGUISupportQt-8.0-gd\
        #-lvtkGUISupportQtOpenGL-8.0-gd\
        -lvtkGUISupportQtSQL-8.0-gd\
        -lvtkhdf5-8.0-gd\
        -lvtkhdf5_hl-8.0-gd\
        -lvtkImagingColor-8.0-gd\
        -lvtkImagingCore-8.0-gd\
        -lvtkImagingFourier-8.0-gd\
        -lvtkImagingGeneral-8.0-gd\
        -lvtkImagingHybrid-8.0-gd\
        -lvtkImagingMath-8.0-gd\
        -lvtkImagingMorphological-8.0-gd\
        -lvtkImagingSources-8.0-gd\
        -lvtkImagingStatistics-8.0-gd\
        -lvtkImagingStencil-8.0-gd\
        -lvtkInfovisCore-8.0-gd\
        -lvtkInfovisLayout-8.0-gd\
        -lvtkInteractionImage-8.0-gd\
        -lvtkInteractionStyle-8.0-gd\
        -lvtkInteractionWidgets-8.0-gd\
        -lvtkIOAMR-8.0-gd\
        -lvtkIOCore-8.0-gd\
        -lvtkIOEnSight-8.0-gd\
        -lvtkIOExodus-8.0-gd\
        -lvtkIOExport-8.0-gd\
        #-lvtkIOExportOpenGL-8.0-gd\
-lvtkIOExportOpenGL2-8.0-gd\
        -lvtkIOGeometry-8.0-gd\
        -lvtkIOImage-8.0-gd\
        -lvtkIOImport-8.0-gd\
        -lvtkIOInfovis-8.0-gd\
        -lvtkIOLegacy-8.0-gd\
        -lvtkIOLSDyna-8.0-gd\
        -lvtkIOMINC-8.0-gd\
        -lvtkIOMovie-8.0-gd\
        -lvtkIONetCDF-8.0-gd\
        -lvtkIOParallel-8.0-gd\
        -lvtkIOParallelXML-8.0-gd\
        -lvtkIOPLY-8.0-gd\
        -lvtkIOSQL-8.0-gd\
        -lvtkIOTecplotTable-8.0-gd\
        -lvtkIOVideo-8.0-gd\
        -lvtkIOXML-8.0-gd\
        -lvtkIOXMLParser-8.0-gd\
        -lvtkjpeg-8.0-gd\
        -lvtkjsoncpp-8.0-gd\
        -lvtklibharu-8.0-gd\
        -lvtklibxml2-8.0-gd\
        -lvtklz4-8.0-gd\
        -lvtkmetaio-8.0-gd\
        -lvtkNetCDF-8.0-gd \
        -lvtknetcdf_c++ -gd\
        -lvtkoggtheora-8.0-gd\
        -lvtkParallelCore-8.0-gd\
        -lvtkpng-8.0-gd\
        -lvtkproj4-8.0-gd\
        -lvtkRenderingAnnotation-8.0-gd\
        -lvtkRenderingContext2D-8.0-gd\
        #-lvtkRenderingContextOpenGL-8.0-gd\
-lvtkRenderingContextOpenGL2-8.0-gd\
        -lvtkRenderingCore-8.0-gd\
        -lvtkRenderingFreeType-8.0-gd\
        #-lvtkRenderingGL2PS-8.0-gd\
-lvtkRenderingGL2PSOpenGL2-8.0-gd\
        -lvtkRenderingImage-8.0-gd\
        -lvtkRenderingLabel-8.0-gd\
        #-lvtkRenderingLIC-8.0-gd\
        -lvtkRenderingLOD-8.0-gd\
        #-lvtkRenderingOpenGL-8.0-gd\
-lvtkRenderingOpenGL2-8.0-gd\
        -lvtkRenderingQt-8.0-gd \
        -lvtkRenderingVolume-8.0-gd\
        #-lvtkRenderingVolumeOpenGL-8.0-gd\
-lvtkRenderingVolumeOpenGL2-8.0-gd\
        -lvtksqlite-8.0-gd\
        -lvtksys-8.0-gd\
        -lvtktiff-8.0-gd\
        -lvtkverdict-8.0-gd\
        -lvtkViewsContext2D-8.0-gd\
        -lvtkViewsCore-8.0-gd\
        -lvtkViewsInfovis-8.0-gd\
        -lvtkViewsQt-8.0-gd\
        -lvtkzlib-8.0-gd\
} else {
LIBS + = -LD:\PCL1.8.1\lib\
        -lpcl_common_release\
        -lpcl_features_release\
        -lpcl_filters_release\
        -lpcl_io_ply_release \
        -lpcl_io_release\
        -lpcl_kdtree_release\
        -lpcl_keypoints_release\
        -lpcl_ml_release\
        -lpcl_octree_release\
        -lpcl_outofcore_release\
        -lpcl_people_release\
        -lpcl_recognition_release\
        -lpcl_registration_release\
        -lpcl_sample_consensus_release\
        -lpcl_search_release\
        -lpcl_segmentation_release\
        -lpcl_stereo_release\
        -lpcl_surface_release\
        -lpcl_tracking_release\
        -lpcl_visualization_release

LIBS + = -LD:\PCL1.8.1\3rdParty\Boost\lib\
        -llibboost_atomic-vc141-mt-1_64\
        -llibboost_bzip2-vc141-mt-1_64\
        -llibboost_chrono-vc141-mt-1_64\
        -llibboost_container-vc141-mt-1_64\
        -llibboost_context-vc141-mt-1_64\
        -llibboost_coroutine-vc141-mt-1_64\
        -llibboost_date_time-vc141-mt-1_64\
        -llibboost_exception-vc141-mt-1_64\
        -llibboost_fiber-vc141-mt-1_64\
        -llibboost_filesystem-vc141-mt-1_64\
        -llibboost_graph-vc141-mt-1_64\
        -llibboost_graph_parallel-vc141-mt-1_64\
        -llibboost_iostreams-vc141-mt-1_64\
        -llibboost_locale-vc141-mt-1_64\
        -llibboost_log-vc141-mt-1_64\
        -llibboost_log_setup-vc141-mt-1_64\
        -llibboost_math_c99-vc141-mt-1_64\
        -llibboost_math_c99f-vc141-mt-1_64\
        -llibboost_math_c99l-vc141-mt-1_64\
        -llibboost_math_tr1-vc141-mt-1_64\
        -llibboost_math_tr1f-vc141-mt-1_64\
        -llibboost_math_tr1l-vc141-mt-1_64\
        -llibboost_mpi-vc141-mt-1_64\
        -llibboost_numpy-vc141-mt-1_64\
        -llibboost_numpy3-vc141-mt-1_64\
        -llibboost_prg_exec_monitor-vc141-mt-1_64\
        -llibboost_program_options-vc141-mt-1_64\
        -llibboost_python-vc141-mt-1_64\
        -llibboost_python3-vc141-mt-1_64\
        -llibboost_random-vc141-mt-1_64\
        -llibboost_regex-vc141-mt-1_64\
        -llibboost_serialization-vc141-mt-1_64\
        -llibboost_signals-vc141-mt-1_64\
        -llibboost_system-vc141-mt-1_64\
        -llibboost_test_exec_monitor-vc141-mt-1_64\
        -llibboost_thread-vc141-mt-1_64\
        -llibboost_timer-vc141-mt-1_64\
        -llibboost_type_erasure-vc141-mt-1_64\
        -llibboost_unit_test_framework-vc141-mt-1_64\
        -llibboost_wave-vc141-mt-1_64\
        -llibboost_wserialization-vc141-mt-1_64\
        -llibboost_zlib-vc141-mt-1_64

LIBS + = -LD:\PCL1.8.1\3rdParty\FLANN\lib\
        -lflann\
        -lflann_cpp\
        -lflann_cpp_s\
        -lflann_s

LIBS + = -LD:\PCL1.8.1\OpenNI2\Lib\
        -lOpenNI2

LIBS + = -LD:\PCL1.8.1\3rdParty\Qhull\lib\
        -lqhull\
        -lqhullcpp\
        -lqhullstatic\
        -lqhullstatic_r\
        -lqhull_p\
        -lqhull_r

LIBS + = -LD:\PCL1.8.1\3rdParty\VTK\lib\
        -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\
        -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\
        -lvtkGUISupportQt-8.0\
        #-lvtkGUISupportQtOpenGL-8.0\
        -lvtkGUISupportQtSQL-8.0\
        -lvtkhdf5-8.0\
        -lvtkhdf5_hl-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\
        #-lvtkIOExportOpenGL-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\
        -lvtklz4-8.0\
        -lvtkmetaio-8.0\
        -lvtkNetCDF-8.0\
        -lvtknetcdf_c++ \
        -lvtkoggtheora-8.0\
        -lvtkParallelCore-8.0\
        -lvtkpng-8.0\
        -lvtkproj4-8.0\
        -lvtkRenderingAnnotation-8.0\
        -lvtkRenderingContext2D-8.0\
        #-lvtkRenderingContextOpenGL-8.0\
-lvtkRenderingContextOpenGL2-8.0\
        -lvtkRenderingCore-8.0\
        -lvtkRenderingFreeType-8.0\
        #-lvtkRenderingGL2PS-8.0\
-lvtkRenderingGL2PSOpenGL2-8.0\
        -lvtkRenderingImage-8.0\
        -lvtkRenderingLabel-8.0\
        #-lvtkRenderingLIC-8.0\
        -lvtkRenderingLOD-8.0\
        #-lvtkRenderingOpenGL-8.0\
-lvtkRenderingOpenGL2-8.0\
        -lvtkRenderingQt-8.0\
        -lvtkRenderingVolume-8.0\
        #-lvtkRenderingVolumeOpenGL-8.0\
-lvtkRenderingVolumeOpenGL2-8.0\
        -lvtksqlite-8.0\
        -lvtksys-8.0\
        -lvtktiff-8.0\
        -lvtkverdict-8.0\
        -lvtkViewsContext2D-8.0\
        -lvtkViewsCore-8.0\
        -lvtkViewsInfovis-8.0\
        -lvtkViewsQt-8.0\
        -lvtkzlib-8.0\
        
}

4. Simple test, requires rabbit.pcd

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

void viewerOneOff(pcl::visualization::PCLVisualizer & amp; viewer)
{
    viewer.setBackgroundColor(0.5, 0.9, 0.5); //Set the background color
}
int main()
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
    char strfilepath[256] = "rabbit.pcd";//fill point cloud path here
    pcl::io::loadPCDFile(strfilepath, *cloud);
    pcl::visualization::CloudViewer viewer("Cloud Viewer"); //create viewer object
    viewer.showCloud(cloud);
    viewer.runOnVisualizationThreadOnce(viewerOneOff);
    pcl::io::savePCDFile("Savepcd.pcd", *cloud);
    system("pause");
    return 0;
}

5. The most correct way to add VTK to QT (this method is the correct way to use VTK in Designer)

This should be the most correct way. The core of the method is to promote QWidget to a custom control.

QVTKOpenGLNativeWidget is actually a custom control written by VTK, which inherits from the QWidget class, so you only need to upgrade the QWdiget class to the QVTKOpenGLNativeWidget class.

1. Use Designer to open the interface file of the project (.ui suffix file)

2. In the control bar on the left, drag the “Widget” control under Containers into the user interface, and then you can find the QWidget control object you dragged in in the object viewer on the right.

3. Right-click the object and select “Promote to”. It is understandable that the control class that comes with QT is promoted to a custom control class written by the developer. And QVTKOpenGLNativeWidget is a custom control class written by VTK.


4. Then fill in “QVTKOpenGLNativeWidget” for the upgraded class name and “QVTKOpenGLNativeWidget.h” for the header file. The base class chooses QWidget. Then click “Add” -> “Promote”

Promoted class name: refers to the class name of the custom control, and the custom class name provided by VTK is QVTKOpenGLNativeWidget.
Header file: refers to the header file of the custom control. The header file of the custom control class provided by VTK is QVTKOpenGLNativeWidget.h. Pay attention to capitalization. If it does not correspond, it will fail.
Base class name: refers to who is the base class of the custom control class, and the base class of QVTKOpenGLNativeWidget is QWidget. It won’t work if you choose the wrong one.
Add: refers to saving this setting, which can be used directly next time without re-entering the above information.
Upgrade: refers to the QWidget control that you drag into the UI, and turns it into a custom control class you wrote, here is to change the QWidget class into the QVTKOpenGLNativeWidget class.

5. Rename the object name of the window control to identify it when writing code. What you see online is usually named “qvtkWidget”

6. Finally, call the member variable of ui under your main window class to successfully call out the vtk window control qvtkWidget.

In fact, the above is the definition process of the custom control class. The difference is that the custom control class does not need to write a class by itself, but VTK has been written and provided to us, and we can directly use it to improve it.

6. The most convenient method, without using Designer, directly use code to implement the way of adding VTK window (the most recommended method)

This is the easiest way, do not use .ui files, do not need to use Designer, use it directly on the code. There is no need to upgrade the class, just include the header file and use it.

Write code in the constructor of MainWindow: (no need to copy, just understand what the following lines of code are doing)

 //Initialize the VTK window and name it qvtkWidget (the principle is the same as QPushButton, which comes with QT, but the control is provided by VTK, and the usage is the same as QPushButton)
QVTKOpenGLNativeWidget* qvtkWidget = new QVTKOpenGLNativeWidget();
//Initialize the renderer of VTK, usually use vtkRenderWindow, but in QT, use vtkGenericOpenGLRenderWindow, which is essentially the same function as vtkRenderWindow
vtkGenericOpenGLRenderWindow* renderWindow = vtkGenericOpenGLRenderWindow()::New();
//Add the renderer to the VTK window. You can write this line first, and then add the prepared vtkRenderer to renderWindow to synchronize data
qvtkWidget->setRenderWindow(renderWindow);
//Create a grid layout, just for the convenience of the layout, in fact, you can directly call the baseSize function of qvtkwidget to specify the window size
QGridLayout* displayGrid = new QGridLayout(this);
displayGrid->addWidget(qvtkWidget);
this->setLayout(displayGrid);

The vtkGenericOpenGLRenderWindow.h and QVTKOpenGLNativeWidget.h header files need to be included in the MainWindow header file.

Understand the above code and use it in the MainWindow constructor (it’s okay to use it in other places, the usage is the same)

—————
Copyright statement: This article is an original article of CSDN blogger “864306337”, which follows the CC 4.0 BY-SA copyright agreement. For reprinting, please attach the original source link and this statement.
Original link: https://blog.csdn.net/qq_37366618/article/details/124926853