las2pcd.cpp如下:
#include <iostream>
#include <cstdlib>
#include <liblas/liblas.hpp>//liblas tou wen jin
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <liblas/reader.hpp>
#include <liblas/factory.hpp>
#include <liblas/detail/fwd.hpp>
#include <liblas/point.hpp>
using namespace std;
int main (int argc, char** argv)
{
std::ifstream ifs(argv[1], std::ios::in | std::ios::binary); // 打开las文件
liblas::ReaderFactory f;
liblas::Reader reader = f.CreateWithStream(ifs); // 读取las文件
unsigned long int nbPoints=reader.GetHeader().GetPointRecordsCount();//获取las数据点的个数
pcl::PointCloud<pcl::PointXYZRGB> cloud;
cloud.width = nbPoints; //保证与las数据点的个数一致
cloud.height = 1;
cloud.is_dense = false;
cloud.points.resize (cloud.width * cloud.height);
int i=0;
uint16_t r1, g1, b1;
int r2, g2, b2;
uint32_t rgb;
while(reader.ReadNextPoint())
{
// 获取las数据的x,y,z信息
cloud.points[i].x = (reader.GetPoint().GetX());
cloud.points[i].y = (reader.GetPoint().GetY());
cloud.points[i].z = (reader.GetPoint().GetZ());
//获取las数据的r,g,b信息
r1 = (reader.GetPoint().GetColor().GetRed());
g1 = (reader.GetPoint().GetColor().GetGreen());
b1 = (reader.GetPoint().GetColor().GetBlue());
r2 = ceil(((float)r1/65536)*(float)256);
g2 = ceil(((float)g1/65536)*(float)256);
b2 = ceil(((float)b1/65536)*(float)256);
rgb = ((int)r2) << 16 | ((int)g2) << 8 | ((int)b2);
cloud.points[i].rgb = *reinterpret_cast<float*>(&rgb);
i++;
}
pcl::io::savePCDFileASCII ("pointcloud.pcd", cloud);//存储为pcd类型文件
return (0);
}
CMakeLists.txt如下:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(las2pcd)
find_package(PCL 1.7 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/libLAS/include")
link_directories(${PCL_LIBRARY_DIRS})
link_directories("${CMAKE_CURRENT_SOURCE_DIR}/libLAS/lib")
add_definitions(${PCL_DEFINITIONS})
add_executable (las2pcd las2pcd.cpp)
target_link_libraries (las2pcd ${PCL_LIBRARIES})
target_link_libraries (las2pcd "${CMAKE_CURRENT_SOURCE_DIR}/libLAS/lib/liblas.lib" )
target_link_libraries (las2pcd "${CMAKE_CURRENT_SOURCE_DIR}/libLAS/lib/liblas_c.lib" )
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(DLL_LIBLAS "${CMAKE_CURRENT_SOURCE_DIR}/libLAS/dll/liblas.dll" "${CMAKE_CURRENT_SOURCE_DIR}/libLAS/dll/gdal111.dll" "${CMAKE_CURRENT_SOURCE_DIR}/libLAS/dll/geotiff.dll" "${CMAKE_CURRENT_SOURCE_DIR}/libLAS/dll/libtiff.dll")
file(COPY ${DLL_LIBLAS} DESTINATION ${EXECUTABLE_OUTPUT_PATH}/release)
file(COPY ${DLL_LIBLAS} DESTINATION ${EXECUTABLE_OUTPUT_PATH}/debug)
错误如下:
[ 50%] Building CXX object CMakeFiles/las2pcd.dir/las2pcd.cpp.o
[100%] Linking CXX executable ../bin/las2pcd
CMakeFiles/las2pcd.dir/las2pcd.cpp.o:在函数‘main’中:
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:19:对‘liblas::ReaderFactory::CreateWithStream(std::istream&)’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:21:对‘liblas::Reader::GetHeader() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:21:对‘liblas::Header::GetPointRecordsCount() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:34:对‘liblas::Reader::ReadNextPoint()’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:37:对‘liblas::Reader::GetPoint() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:37:对‘liblas::Point::GetX() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:38:对‘liblas::Reader::GetPoint() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:38:对‘liblas::Point::GetY() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:39:对‘liblas::Reader::GetPoint() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:39:对‘liblas::Point::GetZ() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:42:对‘liblas::Reader::GetPoint() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:42:对‘liblas::Point::GetColor() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:43:对‘liblas::Reader::GetPoint() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:43:对‘liblas::Point::GetColor() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:44:对‘liblas::Reader::GetPoint() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:44:对‘liblas::Point::GetColor() const’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:19:对‘liblas::Reader::~Reader()’未定义的引用
/home/s/pcl_study/chapter3/5/source/las2pcd.cpp:19:对‘liblas::Reader::~Reader()’未定义的引用
collect2: error: ld returned 1 exit status
CMakeFiles/las2pcd.dir/build.make:357: recipe for target '../bin/las2pcd' failed
make[3]: *** [../bin/las2pcd] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/las2pcd.dir/all' failed
make[2]: *** [CMakeFiles/las2pcd.dir/all] Error 2
CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/las2pcd.dir/rule' failed
make[1]: *** [CMakeFiles/las2pcd.dir/rule] Error 2
Makefile:118: recipe for target 'las2pcd' failed
make: *** [las2pcd] Error 2