PointCloud和PCLPointCloud2差別:
一、PointCloud:
Public Attributes:
pcl::PCLHeader header( The point cloud header. )
std::vector< PointT, Eigen::aligned_allocator< PointT > >points( The point data. )
uint32_t width (The point cloud width (if organized as an image-structure).)
uint32_t height (The point cloud height (if organized as an image-structure). )
bool is_dense (True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields). )
Eigen::Vector4f sensor_origin_(Sensor acquisition pose (origin/translation). )
Eigen::Quaternionf sensor_orientation_(Sensor acquisition pose (rotation). )
二、PCLPointCloud2:
Public Attributes:
::pcl::PCLHeader header
pcl::uint32_t height
pcl::uint32_t width
std::vector< ::pcl::PCLPointField > fields
pcl::uint8_t is_bigendian
pcl::uint32_t point_step
pcl::uint32_t row_step
std::vector< pcl::uint8_t > data
pcl::uint8_t is_dense
三、PCLPointCloud2轉換為PointCloud:
主要函數:
void pcl::fromPCLPointCloud2 ( const pcl::PCLPointCloud2 & msg,pcl::PointCloud< PointT > & cloud, const MsgFieldMap &field_map )
Parameters:
[in] msg the PCLPointCloud2 binary blob
[out] cloud the resultant pcl::PointCloud
[in] field_map a MsgFieldMap object
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud object using a field_map.
四、GreedyProjectionTriangulation()
head file:
#include<pcl/surface/gp3.h>
Constructor:
pcl::GreedyProjectionTriangulation< PointInT > Class Template Reference
GreedyProjectionTriangulation is an implementation of a greedy triangulation algorithm for 3D points based on local 2D projections.(貪婪投影算法)
code:
// triangulation_test.cpp: 定義控制台應用程式的入口點。
//
#include "stdafx.h"
#include<iostream>
#include<pcl/point_types.h>
#include<pcl/io/pcd_io.h>
#include<pcl/kdtree/kdtree_flann.h>
#include<pcl/features/normal_3d.h>
#include<pcl/surface/gp3.h> //貪婪投影三角化算法
#include<pcl/visualization/pcl_visualizer.h>
#include<boost/math/special_functions/round.hpp>
using namespace std;
int main()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PCLPointCloud2 cloud_blob;
pcl::io::loadPCDFile("cloud11.pcd", cloud_blob);
pcl::fromPCLPointCloud2(cloud_blob, *cloud);
//Normal estimation
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal>n; //法線估計對象
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>); //存儲法線的向量
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
tree->setInputCloud(cloud);
n.setInputCloud(cloud);
n.setSearchMethod(tree);
n.setKSearch(20);
n.compute(*normals); //估計法線存儲位置
//Concatenate the XYZ and normal field
pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals(new pcl::PointCloud<pcl::PointNormal>);
pcl::concatenateFields(*cloud, *normals, *cloud_with_normals); //連接配接字段
//point_with_normals = cloud + normals
//定義搜尋樹對象
pcl::search::KdTree<pcl::PointNormal>::Ptr tree2(new pcl::search::KdTree<pcl::PointNormal>);
tree2->setInputCloud(cloud_with_normals); //點雲搜尋樹
//Initialize objects
pcl::GreedyProjectionTriangulation<pcl::PointNormal>gp3; //定義三角化對象
pcl::PolygonMesh triangles; //定義最終三角化的網絡模型
gp3.setSearchRadius(0.75); //設定連接配接點之間的最大距離(即為三角形的最大邊長)
//設定各參數值
gp3.setMu(2.5); //設定被樣本點搜尋其最近鄰點的最遠距離,為了使用點雲密度的變化
gp3.setMaximumNearestNeighbors(100); //樣本點可搜尋的領域個數
gp3.setMaximumSurfaceAngle(M_PI / 4); //某點法向量方向偏離樣本點法線的最大角度45°
gp3.setMinimumAngle(M_PI / 18); //設定三角化後得到的三角形内角最小角度為10°
gp3.setMaximumAngle(2 * M_PI / 3); //設定三角化後得到的三角形内角的最大角度為120°
gp3.setNormalConsistency(false); //設定該參數保證法線朝向一緻
//Get Result
gp3.setInputCloud(cloud_with_normals); //設定輸入點雲為有向點雲
gp3.setSearchMethod(tree2); //設定搜尋方式
gp3.reconstruct(triangles); //重建提取三角化
//附加頂點資訊
vector<int>parts = gp3.getPartIDs();
vector<int>states = gp3.getPointStates();
//Viewer
pcl::visualization::PCLVisualizer viewer("viewer");
viewer.addPolygonMesh(triangles);
viewer.spin();
return 0;
}
result:
