PCL基础

博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=264

许可

建议每一个文件包含一个描述代码作者的许可,这对于用户了解使用该代码会受到何种约束是十分有用的,PCL是100%的BSD许可的,我们在文件中以C++注释的形式嵌入该许可证,详细见本章源码文件夹下License.txt。如果需要声明其他的版权,添加其他类似的内容就行了(或者原始著作权被改变)

* Copyright (c) XXX, respective authors.

合理命名

到目前为止我们在例程中使用诸如setSigmaS或setSigmaR等简单的词汇来命名set和get功能的函数,在实际中,应该使用更好的命名方法,以便能够真正表示对应参数的功能,在代码的最终版本中我们将重新把setters和getters命名成set/getHalfSize和set/getStdDev以及类似的名字。

代码注释

PCL试图在用户和API文档方面保持高标准,支持Doxygen的文档生成的注释已经在上面的例子中删减掉。实际中,我们的bilateral.h头文件类部分如下:

...
/** \brief Compute the intensity average for a single point
         * \param[in] pid the point index to compute the weight for
         * \param[in] indices the set of nearest neighor indices
         * \param[in] distances the set of nearest neighbor distances
         * \return the intensity average at a given point index
         */
double
computePointWeight (const int pid, const std::vector<int> &indices, const std::vector<float> &distances);
 
/** \brief Set the half size of the Gaussian bilateral filter window.
         * \param[in] sigma_s the half size of the Gaussian bilateral filter window to use
         */
inline void
setHalfSize (const double sigma_s)
       {
         sigma_s_ = sigma_s;
       }
...
 #endif // PCL_FILTERS_BILATERAL_H_

很明显比上面的代码中的注释多了不少,并且都符合一定的格式,这样就是标准的PCL编码风格了,即方便代码的维护,又方便用户的使用和学习,bilateral.hpp文件部分如下:

...
// Copy the input data into the output
output=*input_;
 
// For all the indices given (equal to the entire cloud if none given)
for (size_t i =0; i < indices_->size (); ++i)
   {
// Perform a radius search to find the nearest neighbors
     tree_->radiusSearch ((*indices_)[i], sigma_s_ *2, k_indices, k_distances);
...
 #endif // PCL_FILTERS_BILATERAL_H_

完成的bilateral.h和bilateral.hpp文件见本章源码文件夹下3.0文件夹。

测试新建的类

测试新的类很容易,我们用上面提到的第一个代码段作为例子,转而使用pcl::BilateralFilter类,利用光盘提供的CMakeLists.txt和testfilter.cpp文件,在cmake中建立工程文件,并生成相应的可执行文件,生成执行文件后,就可以运行测试前面定义的类。敬请关注PCL(Point Cloud Learning)中国更多的点云库PCL(Point Cloud Library)相关官方教程。

 

参考文献:

1.朱德海、郭浩、苏伟.点云库PCL学习教程(ISBN 978-7-5124-0954-5)北京航空航天出版社2012-10

 

posted @ 2018-03-18 15:52  采男孩的小蘑菇  阅读(662)  评论(0编辑  收藏  举报