PCL Notes 1

Just start to learn PCL in C++. Previously I was justing using the PCL python bindings to do a little bit of calculations. However, encountered with the ray tracing problem, I did’t think Python PCL has it implemented.

Basic Structures

A point cloud is a C++ class which contains the following data fields:

  • width
  • height(set to 1 for unorganized datasets)
    However, there is a helper function: isOrganized to check whether the point cloud is organized rather than checking heigh equals to 1 or not.
  • points(std::vector < PointT >)
  • is_dense: specifies if all the data in points is finite(true) or whether the XYZ values of certain points might contain Inf/NaN values(false)
  • sensor_origin: specifies the sensor acquisition pose(origin/translation). This member is usually optional.
  • sensor_orientation:specifies the sensor acquisition pose(orientation). This member is usually optional.

Compiling the codes:

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(MY_GRAND_PROJECT)
find_package(PCL 1.3 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcd_write_test pcd_write.cpp)
target_link_libraries(pcd_write_test ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})

cmake_minimum_required is mandatory for cmake
project(MY_GRAND_PROJECT) names your project and sets some useful make variables such as those to refer to the source directory(MY_GRAND_PROJECT_SOURCE_DIR) and the directory from which you are invoking cmake (MY_GRAND_PROJECT_BINARY_DIR).
`find_package(PCL 1.3 REQUIRED COMPONENTS common io): We are requesting to find the PCL package at minimum vision 1.3. We also say that it is REQUIRED meaning that cmake will fail gracefully if it can’t be found. As PCL is modular one can request:

  • only one component find_package(PCL 1.3 REQUIRED COMPONENTS io)
  • several: find_package(PCL 1.3 REQUIRED COMPONENTS io common)
  • all existing: find_package(PCL 1.3 REQUIRED)

include_directories, link_directories, add_definitions: When PCL is found, several related variables are set:

  • PCL_FOUND: set to 1 if PCL is found, otherwise unset
  • PCL_INCLUDE_DIRS: set to the paths to PCL installed headers and the dependency headers
  • PCL_LIBRARIES: set to the file names of the built and installed PCL libraries
  • PCL_LIBRARY_DIRS: set to the paths to where PCL libraries and 3rd party dependencies reside
  • PCL_VERSION: the version of the found PCL
  • PCL_COMPONENTS: lists all available components
  • PCL_DEFINITIONS: lists the needed preprocess definition and compiler flags
    To let cmake know about external headers you include in your project, one needs to use include_directories() macro. In our case PCL_INCLUDE_DIRS, contains exactly what we need, thus we ask cmake to search the path it contains for a header potentially included.

add_executable: Here, we tell cmake that we are trying to make an executable file named pcd_write\ _test from one single source file pcd_write.cpp. CMake will take care of the suffix and the permissions.
target_link_libraries() : The executable we are building makes call to PCL functions. So far, we have only included the PCL headers so the compilers knows about the methods we are calling. We need also to make the linker know about the libraries we are linking against. As said before, PCL found libraries referred to using PCL_LIBRARIES variables, all that remains is to trigger the link operation which we do calling target_link_libraries() macro.

#include <iostream>
#include <pcl/io/pcd_io.h> 
#include <pcl/point_types.h>

int main (int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZ> cloud;

  // Fill in the cloud data
  cloud.width    = 5;
  cloud.height   = 1;
  cloud.is_dense = false;
  cloud.points.resize (cloud.width * cloud.height);

  for (size_t i = 0; i < cloud.points.size (); ++i)
  {
    cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
  }

  pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
  std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << std::endl;

  for (size_t i = 0; i < cloud.points.size (); ++i)
    std::cerr << "    " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;

  return (0);
}

We wrote the above codes in pcd_write.cpp.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值