pcl_codec模块:
1. 进入mian()函数,调用encode函数对点云帧进行编码。
encode ( inFile, outFile, codecParams );
infile表示输ply入文件,outfile 表示输出pcc文件,codecParams表示编码参数。
2.进入encode函数,调用两个主要的函数;
loadPLY ( inFile, pointSet, NULL );//加载ply文件;
encodeData ( pointSet, encodedData, codecParams );//进行编码的主体函数;
3.进入encodeDaTa();
pcl::fromPCLPointCloud2 ( mesh.cloud, *l_ptr );//将mesh.cloud中的数据加载到到l_ptr中;
#if __cplusplus >= 201103L
auto l_codec_encoder = generatePCLOctreeCodecV2
#else
boost::shared_ptr
#endif//__cplusplus < 201103L
codecParams->octreeBits,
codecParams->enhBits,
codecParams->colorBits,
codecParams->dunno,
codecParams->colorCodingType,
codecParams->keepCentroid
);//只是设置了一些参数;
tt.tic ();
l_codec_encoder->encodePointCloud ( l_ptr ,l_output_base);//真正的编码点云的函数,哈哈哈;
4.进入encodePointCloud();
deleteCurrentBuffer();
deleteTree();
// initialize octree
setInputCloud (cloud_arg);
// CWI added, when encoding hte output variable stores the (simplified icloud)
output_ = PointCloudPtr(new PointCloud());
// add point to octree
addPointsFromInputCloud ();//构建八叉树的主函数,将ply文件中的一个个点按照坐标放进八叉树中,八叉树是由一个个体素组成的;
// make sure cloud contains points
if (leaf_count_>0) {
// color field analysis
cloud_with_color_ = false;
std::vector
int rgba_index = -1;
rgba_index = pcl::getFieldIndex (*input_, "rgb", fields);
if (rgba_index == -1)
{
rgba_index = pcl::getFieldIndex (*input_, "rgba", fields);
}
if (rgba_index >= 0)
{
point_color_offset_ = static_cast
cloud_with_color_ = true;
}
// apply encoding configuration
cloud_with_color_ &= do_color_encoding_;
// if octree depth changed, we enforce I-frame encoding
i_frame_ |= (recent_tree_depth != getTreeDepth ());// | !(iFrameCounter%10);
// enable I-frame rate
if (i_frame_counter_++==i_frame_rate_)
{
i_frame_counter_ =0;
i_frame_ = true;
}
// increase frameID
frame_ID_++;
// do octree encoding
if (!do_voxel_grid_enDecoding_)
{
point_count_data_vector_.clear ();
point_count_data_vector_.reserve (cloud_arg->points.size ());
}
// initialize color encoding (including new color coding based on jpeg)
if(!color_coding_type_){
color_coder_.initializeEncoding ();
color_coder_.setPointCount (static_cast
color_coder_.setVoxelCount (static_cast
}else
{ // new jpeg color coding
jp_color_coder_.initializeEncoding ();//初始化就是清空;
jp_color_coder_.setPointCount (static_cast
jp_color_coder_.setVoxelCount (static_cast
}
// initialize point encoding (including new centroid encoder)
point_coder_.initializeEncoding ();
centroid_coder_.initializeEncoding ();
point_coder_.setPointCount (static_cast
centroid_coder_.initializeEncoding ();
centroid_coder_.setPointCount( static_cast
// serialize octree
if (i_frame_)
// i-frame encoding - encode tree structure without referencing previous buffer
serializeTree (binary_tree_data_vector_, false);//构建完八叉树后,对八叉树进行处理,一是深度优先遍历得到八叉树结构的一维表示,二是计算八叉树中的每个体素的质心来表示体素,并计算质心与每个体素左下角坐标计算差分值;三是计算每个体素内所有点的颜色均值;
else
// p-frame encoding - XOR encoded tree structure
serializeTree (binary_tree_data_vector_, true);
// write frame header information to stream
writeFrameHeader (compressed_tree_data_out_arg);//写头信息;
// apply entropy coding to the content of all data vectors and send data to output stream
entropyEncoding(compressed_tree_data_out_arg, compressed_tree_data_out_arg);//对上面说的三部分数据进行熵编码,用的方法是range coding,编码完成后得到三个数据,一个是表示八叉树结构的,一个是表示每个体素质心的,一个是每个体素的颜色均值,然后把这些数据加上一些头信息传给解码端就可以进行解码。