QT中配置LASLib實現.las格式點雲文件讀取

任何一個點雲處理軟件一定少不了.las格式點雲文件的讀取,而讀取.las文件主要依靠LASLib庫,網上有不少在VS中配置LASLib的博客,但在QT中配置LASLib的博客卻很少,因此今天來寫一下,總的來說很簡單,用半天左右時間即可完成。

在配置LASLib之前,首先要對LASLib進行編譯,我是在VS2017+WIN10的環境下進行編譯的。

編譯過程主要參考了這兩篇博客。

博客1:https://blog.csdn.net/xujie126/article/details/80769484

博客2:https://blog.csdn.net/qq_34719188/article/details/83474188?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

這兩篇博客寫的很好,按照他的步驟進行編譯無任何問題。

如果最後出現這個問題。

直接忽略好了,沒錯,它對後續步驟無影響,至少在QT中的配置是這樣的。只要有下圖這樣的項目生成成功就好。

這樣就完成了對LASLib的編譯,之後就要進行QT中的LASLib配置。

首先新建工程,完成後修改.pro文件。

首先要把這兩個文件中的東西包含進來D:\LAStools\LASzip\src 和 D:\LAStools\LASlib\inc(這是我的文件路徑,根據各自的文件路徑進行修改),包含方法就是在.pro文件中添加如下兩句代碼。


INCLUDEPATH += D:/LAStools/LASzip/src

INCLUDEPATH += D:/LAStools/LASlib/inc

接着在庫包含中添加LASLib庫,添加方法即在.pro文件中添加如下代碼

LIBS += -LD:\LAStools\LASlib\lib\

        -lLASlib

這裏我將我的.pro文件全部粘上來。

QT       += core gui

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


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


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


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


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


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


INCLUDEPATH += D:/TOOL/PCL1.8.1/3rdParty/OpenNI2/Include\


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


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


INCLUDEPATH += D:/LAStools/LASzip/src


INCLUDEPATH += D:/LAStools/LASlib/inc


CONFIG(debug,debug|release){
LIBS += -LD:/TOOL/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:/TOOL/PCL1.8.1/3rdParty/Boost/lib\
        -llibboost_atomic-vc140-mt-gd-1_64\
        -llibboost_bzip2-vc140-mt-gd-1_64\
        -llibboost_chrono-vc140-mt-gd-1_64\
        -llibboost_container-vc140-mt-gd-1_64\
        -llibboost_context-vc140-mt-gd-1_64\
        -llibboost_coroutine-vc140-mt-gd-1_64\
        -llibboost_date_time-vc140-mt-gd-1_64\
        -llibboost_exception-vc140-mt-gd-1_64\
        -llibboost_fiber-vc140-mt-gd-1_64\
        -llibboost_filesystem-vc140-mt-gd-1_64\
        -llibboost_graph-vc140-mt-gd-1_64\
        -llibboost_graph_parallel-vc140-mt-gd-1_64\
        -llibboost_iostreams-vc140-mt-gd-1_64\
        -llibboost_locale-vc140-mt-gd-1_64\
        -llibboost_log-vc140-mt-gd-1_64\
        -llibboost_log_setup-vc140-mt-gd-1_64\
        -llibboost_math_c99-vc140-mt-gd-1_64\
        -llibboost_math_c99f-vc140-mt-gd-1_64\
        -llibboost_math_c99l-vc140-mt-gd-1_64\
        -llibboost_math_tr1-vc140-mt-gd-1_64\
        -llibboost_math_tr1f-vc140-mt-gd-1_64\
        -llibboost_math_tr1l-vc140-mt-gd-1_64\
        -llibboost_mpi-vc140-mt-gd-1_64\
        -llibboost_numpy-vc140-mt-gd-1_64\
        -llibboost_numpy3-vc140-mt-gd-1_64\
        -llibboost_prg_exec_monitor-vc140-mt-gd-1_64\
        -llibboost_program_options-vc140-mt-gd-1_64\
        -llibboost_python-vc140-mt-gd-1_64\
        -llibboost_python3-vc140-mt-gd-1_64\
        -llibboost_random-vc140-mt-gd-1_64\
        -llibboost_regex-vc140-mt-gd-1_64\
        -llibboost_serialization-vc140-mt-gd-1_64\
        -llibboost_signals-vc140-mt-gd-1_64\
        -llibboost_system-vc140-mt-gd-1_64\
        -llibboost_test_exec_monitor-vc140-mt-gd-1_64\
        -llibboost_thread-vc140-mt-gd-1_64\
        -llibboost_timer-vc140-mt-gd-1_64\
        -llibboost_type_erasure-vc140-mt-gd-1_64\
        -llibboost_unit_test_framework-vc140-mt-gd-1_64\
        -llibboost_wave-vc140-mt-gd-1_64\
        -llibboost_wserialization-vc140-mt-gd-1_64\
        -llibboost_zlib-vc140-mt-gd-1_64\

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

LIBS += -LD:/TOOL/PCL1.8.1/3rdParty/OpenNI2/Lib\
        -lOpenNI2

LIBS += -LD:\LAStools\LASlib\lib\
        -lLASlib

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

LIBS += -LD:/TOOL/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\
        -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\
        -lvtkRenderingCore-8.0-gd\
        -lvtkRenderingFreeType-8.0-gd\
        -lvtkRenderingGL2PS-8.0-gd\
        -lvtkRenderingImage-8.0-gd\
        -lvtkRenderingLabel-8.0-gd\
        -lvtkRenderingLIC-8.0-gd\
        -lvtkRenderingLOD-8.0-gd\
        -lvtkRenderingOpenGL-8.0-gd\
        -lvtkRenderingQt-8.0-gd\
        -lvtkRenderingVolume-8.0-gd\
        -lvtkRenderingVolumeOpenGL-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:/TOOL/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:/TOOL/PCL1.8.1/3rdParty/Boost/lib\
        -llibboost_atomic-vc140-mt-1_64\
        -llibboost_bzip2-vc140-mt-1_64\
        -llibboost_chrono-vc140-mt-1_64\
        -llibboost_container-vc140-mt-1_64\
        -llibboost_context-vc140-mt-1_64\
        -llibboost_coroutine-vc140-mt-1_64\
        -llibboost_date_time-vc140-mt-1_64\
        -llibboost_exception-vc140-mt-1_64\
        -llibboost_fiber-vc140-mt-1_64\
        -llibboost_filesystem-vc140-mt-1_64\
        -llibboost_graph-vc140-mt-1_64\
        -llibboost_graph_parallel-vc140-mt-1_64\
        -llibboost_iostreams-vc140-mt-1_64\
        -llibboost_locale-vc140-mt-1_64\
        -llibboost_log-vc140-mt-1_64\
        -llibboost_log_setup-vc140-mt-1_64\
        -llibboost_math_c99-vc140-mt-1_64\
        -llibboost_math_c99f-vc140-mt-1_64\
        -llibboost_math_c99l-vc140-mt-1_64\
        -llibboost_math_tr1-vc140-mt-1_64\
        -llibboost_math_tr1f-vc140-mt-1_64\
        -llibboost_math_tr1l-vc140-mt-1_64\
        -llibboost_mpi-vc140-mt-1_64\
        -llibboost_numpy-vc140-mt-1_64\
        -llibboost_numpy3-vc140-mt-1_64\
        -llibboost_prg_exec_monitor-vc140-mt-1_64\
        -llibboost_program_options-vc140-mt-1_64\
        -llibboost_python-vc140-mt-1_64\
        -llibboost_python3-vc140-mt-1_64\
        -llibboost_random-vc140-mt-1_64\
        -llibboost_regex-vc140-mt-1_64\
        -llibboost_serialization-vc140-mt-1_64\
        -llibboost_signals-vc140-mt-1_64\
        -llibboost_system-vc140-mt-1_64\
        -llibboost_test_exec_monitor-vc140-mt-1_64\
        -llibboost_thread-vc140-mt-1_64\
        -llibboost_timer-vc140-mt-1_64\
        -llibboost_type_erasure-vc140-mt-1_64\
        -llibboost_unit_test_framework-vc140-mt-1_64\
        -llibboost_wave-vc140-mt-1_64\
        -llibboost_wserialization-vc140-mt-1_64\
        -llibboost_zlib-vc140-mt-1_64\

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

LIBS += -LD:/TOOL/PCL1.8.1/3rdParty/OpenNI2/Lib\
        -lOpenNI2

LIBS += -LD:\LAStools\LASlib\lib\
        -lLASlib

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

LIBS += -LD:/TOOL/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\
        -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\
        -lvtkRenderingCore-8.0\
        -lvtkRenderingFreeType-8.0\
        -lvtkRenderingGL2PS-8.0\
        -lvtkRenderingImage-8.0\
        -lvtkRenderingLabel-8.0\
        -lvtkRenderingLIC-8.0\
        -lvtkRenderingLOD-8.0\
        -lvtkRenderingOpenGL-8.0\
        -lvtkRenderingQt-8.0\
        -lvtkRenderingVolume-8.0\
        -lvtkRenderingVolumeOpenGL-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
}

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    mainwindow.h

FORMS += \
    mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

在我的.pro文件中還進行了PCL庫的配置,所以看起來比較多。

最後一步,即把工程的運行配置改爲release模式,這是因爲我們在編譯LASLib的時候就是在release模式下。

如果不進行此配置,便會出現下圖的錯誤。

這樣就完成了全部的配置,可進行.las格式點雲文件的讀寫。

我這裏進行了一個將.las格式點雲文件轉換爲.pcd格式文件的試驗。

下面我將代碼粘上來。

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <vtkRenderWindow.h>
#include <vtkAutoInit.h>

VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);

#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/common/common.h>
#include <pcl/common/transforms.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/statistical_outlier_removal.h>
#include <lasreader.hpp>
#include <laswriter.hpp>
#include <Eigen/Core>
#include <QFile>
#include <QMessageBox>
#include <QColorDialog>
#include <QInputDialog>
#include <QProgressDialog>
#include <QProgressBar>
#include <QTextStream>
#include <QFileDialog>
#include <QTextCodec>
#include <iostream>
#include <vector>

using namespace std;

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointptr;
    boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
};
#endif // MAINWINDOW_H

mainwindow.c

#include "mainwindow.h"
#include "ui_mainwindow.h"

int BGR=0;
int BGG=255;
int BGB=0;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    LASreadOpener lasreadopener;
    lasreadopener.set_file_name("C:\\Users\\applepc\\Desktop\\HanV2.0\\rabbit.las");
    LASreader* lasreader = lasreadopener.open();
    size_t ct = lasreader->header.number_of_point_records;
    pointptr.reset(new pcl::PointCloud<pcl::PointXYZRGB>);
    pointptr->resize(ct);
    pointptr->width = 1;
    pointptr->height = ct;
    pointptr->is_dense = false;
    size_t i = 0;
    while(lasreader->read_point() && i < ct)
    {
        pointptr->points[i].x = lasreader->point.get_x();
        pointptr->points[i].y = lasreader->point.get_y();
        pointptr->points[i].z = lasreader->point.get_z();
        ++i;
    }
    viewer.reset(new pcl::visualization::PCLVisualizer("viewer", false));
    viewer->addPointCloud(pointptr, "cloud");
    viewer->setBackgroundColor (BGR, BGG, BGB);
          //  viewer->resetCamera();
    ui->widget->SetRenderWindow(viewer->getRenderWindow());
    viewer->setupInteractor(ui->widget->GetInteractor(), ui->widget->GetRenderWindow());
    ui->widget->update();
}

MainWindow::~MainWindow()
{
    delete ui;
}

有一點要注意的是讀取.las格式文件時,文件路徑中必須使用"\\",而不能用"\",不然無法識別,我將讀取的.las格式點雲文件轉換成pcd格式,並放入QVTKWidget中顯示,效果如下圖:

這樣就全部完成了,歡迎大家與我交流,QQ:1826380364

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章