PCL - PCLBase代碼研讀(一)- PCLBase架構

PCL - PCLBase代碼研讀(一)- PCLBase架構

前言

PCLBase中定義了幾個成員變量和函數,在PCL的大部分模組中,都會透過繼承PCLBase來使用這些成員變量和函數。surface/include/pcl/surface/mls.h裡定義的pcl::MovingLeastSquares類別就是一個例子:

using PCLBase<PointInT>::input_;
using PCLBase<PointInT>::indices_;
using PCLBase<PointInT>::fake_indices_;
using PCLBase<PointInT>::initCompute;
using PCLBase<PointInT>::deinitCompute;

本篇的目的就是大致看一下common/include/pcl/pcl_base.h中定義的pcl::PCLBase類別的架構。

includes

引入必要的header。

#pragma once

#if defined __GNUC__
#  pragma GCC system_header
#endif

// Include PCL macros such as PCL_ERROR, PCL_MAKE_ALIGNED_OPERATOR_NEW, etc
#include <pcl/memory.h>
#include <pcl/pcl_macros.h>

// Point Cloud message includes. Needed everywhere.
#include <pcl/point_cloud.h>
#include <pcl/PointIndices.h>
#include <pcl/PCLPointCloud2.h>
#include <pcl/types.h>

namespace pcl
{
  // definitions used everywhere
  using IndicesPtr = shared_ptr<Indices>;
  using IndicesConstPtr = shared_ptr<const Indices>;

  //Used to denote that a value has not been set for an index_t variable
  static  constexpr index_t UNAVAILABLE = static_cast<index_t>(-1);

  /
  /** \brief PCL base class. Implements methods that are used by most PCL algorithms.
    * \ingroup common
    */
  template <typename PointT>
  class PCLBase
  {
    public:

using

使用using這個關鍵字做type alias(詳見Type alias, alias template (since C++11)):

      using PointCloud = pcl::PointCloud<PointT>;
      using PointCloudPtr = typename PointCloud::Ptr;
      using PointCloudConstPtr = typename PointCloud::ConstPtr;

      using PointIndicesPtr = PointIndices::Ptr;
      using PointIndicesConstPtr = PointIndices::ConstPtr;

查看common/include/pcl/point_cloud.h

      using Ptr = shared_ptr<PointCloud<PointT> >;
      using ConstPtr = shared_ptr<const PointCloud<PointT> >;

繼續查看common/include/pcl/PointIndices.h

    using Ptr = shared_ptr< ::pcl::PointIndices>;
    using ConstPtr = shared_ptr<const ::pcl::PointIndices>;

可以發現PointCloudPointIndicesPtrConstPtr的底層都是shared_ptr

注:shared_ptr相關的知識,可以通過C++ std::shared_ptr 用法與範例學習一下

constructor & destructor

      /** \brief Empty constructor. */
      PCLBase ();

      /** \brief Copy constructor. */
      PCLBase (const PCLBase& base);

      /** \brief Destructor. */
      virtual ~PCLBase () = default;

getter & setter

      /** \brief Provide a pointer to the input dataset
        * \param[in] cloud the const boost shared pointer to a PointCloud message
        */
      virtual void
      setInputCloud (const PointCloudConstPtr &cloud);

      /** \brief Get a pointer to the input point cloud dataset. */
      inline PointCloudConstPtr const
      getInputCloud () const { return (input_); }

      /** \brief Provide a pointer to the vector of indices that represents the input data.
        * \param[in] indices a pointer to the indices that represent the input data.
        */
      virtual void
      setIndices (const IndicesPtr &indices);

      /** \brief Provide a pointer to the vector of indices that represents the input data.
        * \param[in] indices a pointer to the indices that represent the input data.
        */
      virtual void
      setIndices (const IndicesConstPtr &indices);

      /** \brief Provide a pointer to the vector of indices that represents the input data.
        * \param[in] indices a pointer to the indices that represent the input data.
        */
      virtual void
      setIndices (const PointIndicesConstPtr &indices);

      /** \brief Set the indices for the points laying within an interest region of
        * the point cloud.
        * \note you shouldn't call this method on unorganized point clouds!
        * \param[in] row_start the offset on rows
        * \param[in] col_start the offset on columns
        * \param[in] nb_rows the number of rows to be considered row_start included
        * \param[in] nb_cols the number of columns to be considered col_start included
        */
      virtual void
      setIndices (std::size_t row_start, std::size_t col_start, std::size_t nb_rows, std::size_t nb_cols);

      /** \brief Get a pointer to the vector of indices used. */
      inline IndicesPtr
      getIndices () { return (indices_); }

      /** \brief Get a pointer to the vector of indices used. */
      inline IndicesConstPtr const
      getIndices () const { return (indices_); }

      /** \brief Override PointCloud operator[] to shorten code
        * \note this method can be called instead of (*input_)[(*indices_)[pos]]
        * or (*input_)[(*indices_)[pos]]
        * \param[in] pos position in indices_ vector
        */
      inline const PointT& operator[] (std::size_t pos) const
      {
        return ((*input_)[(*indices_)[pos]]);
      }

protected成員

這裡是比較重要的部分,此處定義的幾個成員變數及函數會被PCLBase的子類別繼承並使用。注意它們的access modifier都是protected,代表這些變量及函數只能給子類別存取,不能從外部接觸。

  • input_:輸入點雲,必須要存在才能開始運算
  • indices_:可能從外部傳入,或是內部自行生成的(fake)
  • use_indices_:看起來use_indices_總是等於(!fake_indices_),不知有何作用?
  • fake_indices_:如果成員變量indices_為空,就會自行創造一個虛擬的indices_,然後把fake_indices_設為true
  • initCompute:檢查input_是否存在,並準備好indices_fake_indices_等變量
  • deinitComputePCLBasedeinitCompute函數直接回傳true,不發揮任何作用
    protected:
      /** \brief The input point cloud dataset. */
      PointCloudConstPtr input_;

      /** \brief A pointer to the vector of point indices to use. */
      IndicesPtr indices_;

      /** \brief Set to true if point indices are used. */
      bool use_indices_;

      /** \brief If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud. */
      bool fake_indices_;

      /** \brief This method should get called before starting the actual computation.
        *
        * Internally, initCompute() does the following:
        *   - checks if an input dataset is given, and returns false otherwise
        *   - checks whether a set of input indices has been given. Returns true if yes.
        *   - if no input indices have been given, a fake set is created, which will be used until:
        *     - either a new set is given via setIndices(), or
        *     - a new cloud is given that has a different set of points. This will trigger an update on the set of fake indices
        */
      bool
      initCompute ();

      /** \brief This method should get called after finishing the actual computation.
        */
      bool
      deinitCompute ();

    public:
      PCL_MAKE_ALIGNED_OPERATOR_NEW
  };

PCLBase<pcl::PCLPointCloud2>

目前沒看到這個類別在哪裡被使用到,暫不展開。

  /
  template <>
  class PCL_EXPORTS PCLBase<pcl::PCLPointCloud2>
  {
    public:
      using PCLPointCloud2 = pcl::PCLPointCloud2;
      using PCLPointCloud2Ptr = PCLPointCloud2::Ptr;
      using PCLPointCloud2ConstPtr = PCLPointCloud2::ConstPtr;

      using PointIndicesPtr = PointIndices::Ptr;
      using PointIndicesConstPtr = PointIndices::ConstPtr;

      /** \brief Empty constructor. */
      PCLBase ();

      /** \brief destructor. */
      virtual ~PCLBase () = default;

      /** \brief Provide a pointer to the input dataset
        * \param cloud the const boost shared pointer to a PointCloud message
        */
      void
      setInputCloud (const PCLPointCloud2ConstPtr &cloud);

      /** \brief Get a pointer to the input point cloud dataset. */
      inline PCLPointCloud2ConstPtr const
      getInputCloud () const { return (input_); }

      /** \brief Provide a pointer to the vector of indices that represents the input data.
        * \param[in] indices a pointer to the indices that represent the input data.
        */
      void
      setIndices (const IndicesPtr &indices);

      /** \brief Provide a pointer to the vector of indices that represents the input data.
        * \param[in] indices a pointer to the indices that represent the input data.
        */
      void
      setIndices (const PointIndicesConstPtr &indices);

      /** \brief Get a pointer to the vector of indices used. */
      inline IndicesPtr const
      getIndices () const { return (indices_); }

    protected:
      /** \brief The input point cloud dataset. */
      PCLPointCloud2ConstPtr input_;

      /** \brief A pointer to the vector of point indices to use. */
      IndicesPtr indices_;

      /** \brief Set to true if point indices are used. */
      bool use_indices_;

      /** \brief If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud. */
      bool fake_indices_;

      /** \brief The size of each individual field. */
      std::vector<uindex_t> field_sizes_;

      /** \brief The x-y-z fields indices. */
      index_t x_idx_, y_idx_, z_idx_;

      /** \brief The desired x-y-z field names. */
      std::string x_field_name_, y_field_name_, z_field_name_;

      bool initCompute ();
      bool deinitCompute ();
    public:
      PCL_MAKE_ALIGNED_OPERATOR_NEW
  };
}

#ifdef PCL_NO_PRECOMPILE
#include <pcl/impl/pcl_base.hpp>
#endif
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值