zoukankan      html  css  js  c++  java
  • 填写类的内容(2)

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

    到现在为止都是最普通的C++代码,除了构造函数BilateralFilter (),这里我们给了两个参数默认值。因为我们的类是从pcl::Filter继承的,而pcl::Filter是从pcl::PCLBase继承的,可以用setInputCloud()方法给算法传递输入数据(作为input_存储),因此下面我们增加了一个using声明:

    ...
    template<typename PointT>
    class BilateralFilter:public Filter<PointT>
       {
    using Filter<PointT>::input_;
    public:
           BilateralFilter () : sigma_s_ (0),
    ...

    使用using声明确保我们的类能够不需键入完整引用方式就可以访问成员其父类的成员变量input_,下面我们定义applyFilter函数,由于其是纯虚函数,所有从pcl::Filter继承的类都必须实现该方法成员,因此我们有如下声明:

    ...
    using Filter<PointT>::input_;
    typedef typename Filter<PointT>::PointCloud PointCloud;
    public:
           BilateralFilter () : sigma_s_ (0),
                                sigma_r_ (std::numeric_limits<double>::max ())
           {
           }
    void
    applyFilter (PointCloud &output);
    ...

    后面在bilateral.hpp 文件中会给出applyFilter的具体实现。其中构造了一个类型定义(typedef)这样就不用键入整个引用就能使用PointCloud类。在例子中查看原始代码,我们注意到该算法是由对点云中每个点进行相同的操作组成的,为保持applyFilter清晰,我们声明一个叫做computePointWeight的方法:

    ...
    void
    applyFilter (PointCloud &output);
    double
    computePointWeight (const int pid, const std::vector<int> &indices, const std::vector<float> &distances);

    此外,我们注意到例子中构造了一个Kd树对象,用于获取给定点的近邻,因此我们增加下面的内容:

    #include
     ...
    using Filter<PointT>::input_;
    typedeftypename Filter<PointT>::PointCloud PointCloud;
    typedeftypename pcl::KdTree<PointT>::Ptr KdTreePtr;
    public:
     ...
    void
    setSearchMethod (const KdTreePtr &tree)
         {
           tree_ = tree;
         }
    private:
     ...
         KdTreePtr tree_;
     ...

    最后,增加核心计算函数G (float x, float sigma)为内联(inline)函数,以便能够加速滤波的计算, 因为该方法仅仅在该算法的环境里有用,我们把它设置为私有,完整的头文件见本章源码文件1.0文件夹下bilateral.h。 

       未完待续,敬请关注“填写类的内容(3)”的其他内容。

    敬请关注PCL(Point Cloud Learning)中国更多的点云库PCL(Point Cloud Library)相关官方教程。

    参考文献:

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

  • 相关阅读:
    runtime iOS 运行时机制
    iOS 文件操作
    responseCode 状态吗查询
    iOS常用宏定义
    Block里用self造成循环引用
    iOS Block全面分析
    OC与Swift混编
    iOS打包app发给测试人员测试
    Swift UITextField
    sqilite学习
  • 原文地址:https://www.cnblogs.com/flyinggod/p/8596425.html
Copyright © 2011-2022 走看看