PCL - ICP代碼研讀(十六 ) - CorrespondenceRejector架構

前言

CorrespondenceRejector會接受點對input_correspondences_當作輸入,然後以一定的條件(由CorrespondenceRejector的各子類別自行定義)拒絕其中部分點對,最後輸出剩下的點對。

本篇對應到correspondence_rejection.h這個檔案。

CorrespondenceRejector

#pragma once

#include <pcl/console/print.h>
#include <pcl/registration/correspondence_sorting.h>
#include <pcl/registration/correspondence_types.h>
#include <pcl/search/kdtree.h>
#include <pcl/point_cloud.h>

namespace pcl {
namespace registration {
/** @b CorrespondenceRejector represents the base class for correspondence rejection
 * methods \author Dirk Holz \ingroup registration
 */
class CorrespondenceRejector {
public:

using

定義名稱,方便後續使用:

  using Ptr = shared_ptr<CorrespondenceRejector>;
  using ConstPtr = shared_ptr<const CorrespondenceRejector>;

constructor和destructor

  /** \brief Empty constructor. */
  CorrespondenceRejector() {}

  /** \brief Empty destructor. */
  virtual ~CorrespondenceRejector() {}

輸入點對的setter和getter

  /** \brief Provide a pointer to the vector of the input correspondences.
   * \param[in] correspondences the const shared pointer to a correspondence vector
   */
  virtual inline void
  setInputCorrespondences(const CorrespondencesConstPtr& correspondences)
  {
    input_correspondences_ = correspondences;
  };

  /** \brief Get a pointer to the vector of the input correspondences.
   * \return correspondences the const shared pointer to a correspondence vector
   */
  inline CorrespondencesConstPtr
  getInputCorrespondences()
  {
    return input_correspondences_;
  };

配對拒絕相關函數

getCorrespondences函數首先檢查input_correspondences_是否為空,然後調用applyRejection實際運行拒絕點對的過程。

  /** \brief Run correspondence rejection
   * \param[out] correspondences Vector of correspondences that have not been rejected.
   */
  // 實際運行拒絕correspondence的過程
  inline void
  getCorrespondences(pcl::Correspondences& correspondences)
  {
    // correspondences跟input_correspondences_的關係為何?
    // 如果輸入配對指標input_correspondences_為空,則直接返回
    if (!input_correspondences_ || (input_correspondences_->empty()))
      return;

    // applyRejection函數會調用getRemainingCorrespondences
    applyRejection(correspondences);
  }

getRemainingCorrespondences函數是CorrespondenceRejector類別的核心。它接受original_correspondences,使用一定的判斷條件拒絕掉部分點對,最後將結果保存到remaining_correspondences裡。

  /** \brief Get a list of valid correspondences after rejection from the original set
   * of correspondences. Pure virtual. Compared to \a getCorrespondences this function
   * is stateless, i.e., input correspondences do not need to be provided beforehand,
   * but are directly provided in the function call.
   * \param[in] original_correspondences the set of initial correspondences given
   * \param[out] remaining_correspondences the resultant filtered set of remaining
   * correspondences
   */
  // 跟getCorrespondences的區別為:它是stateless的,能動態地接受輸入(original_correspondences)
  virtual inline void
  getRemainingCorrespondences(const pcl::Correspondences& original_correspondences,
                              pcl::Correspondences& remaining_correspondences) = 0;

getRejectedQueryIndices函數對input_correspondences_和輸入的correspondences調用pcl::getRejectedQueryIndices,獲取中被拒絕點對的索引,並輸出至indices

  /** \brief Determine the indices of query points of
   * correspondences that have been rejected, i.e., the difference
   * between the input correspondences (set via \a setInputCorrespondences)
   * and the given correspondence vector.
   * \param[in] correspondences Vector of correspondences after rejection
   * \param[out] indices Vector of query point indices of those correspondences
   * that have been rejected.
   */
  // 與correspondences比較,獲取input_correspondences_中被拒絕的索引,存入indices
  inline void
  getRejectedQueryIndices(const pcl::Correspondences& correspondences,
                          pcl::Indices& indices)
  {
    if (!input_correspondences_ || input_correspondences_->empty()) {
      PCL_WARN("[pcl::registration::%s::getRejectedQueryIndices] Input correspondences "
               "not set (lookup of rejected correspondences _not_ possible).\n",
               getClassName().c_str());
      return;
    }

    pcl::getRejectedQueryIndices(*input_correspondences_, correspondences, indices);
  }

getClassName

返回點對拒絕器的名稱:

  /** \brief Get a string representation of the name of this class. */
  inline const std::string&
  getClassName() const
  {
    return (rejection_name_);
  }

點雲,法向量設定相關函數

CorrespondenceRejector類別中,不需要點雲和法向量,所以此處的requireXxx函數都回傳false。

注意這些函數都被宣告為virtual的,如此一來,CorrespondenceRejector的各個子類別便可以自行決定是否需要點雲和法向量。

  /** \brief See if this rejector requires source points */
  virtual bool
  requiresSourcePoints() const
  {
    return (false);
  }

  /** \brief Abstract method for setting the source cloud */
  virtual void setSourcePoints(pcl::PCLPointCloud2::ConstPtr /*cloud2*/)
  {
    PCL_WARN("[pcl::registration::%s::setSourcePoints] This class does not require an "
             "input source cloud\n",
             getClassName().c_str());
  }

  /** \brief See if this rejector requires source normals */
  virtual bool
  requiresSourceNormals() const
  {
    return (false);
  }

  /** \brief Abstract method for setting the source normals */
  virtual void setSourceNormals(pcl::PCLPointCloud2::ConstPtr /*cloud2*/)
  {
    PCL_WARN("[pcl::registration::%s::setSourceNormals] This class does not require "
             "input source normals\n",
             getClassName().c_str());
  }
  /** \brief See if this rejector requires a target cloud */
  virtual bool
  requiresTargetPoints() const
  {
    return (false);
  }

  /** \brief Abstract method for setting the target cloud */
  virtual void setTargetPoints(pcl::PCLPointCloud2::ConstPtr /*cloud2*/)
  {
    PCL_WARN("[pcl::registration::%s::setTargetPoints] This class does not require an "
             "input target cloud\n",
             getClassName().c_str());
  }

  /** \brief See if this rejector requires target normals */
  virtual bool
  requiresTargetNormals() const
  {
    return (false);
  }

  /** \brief Abstract method for setting the target normals */
  virtual void setTargetNormals(pcl::PCLPointCloud2::ConstPtr /*cloud2*/)
  {
    PCL_WARN("[pcl::registration::%s::setTargetNormals] This class does not require "
             "input target normals\n",
             getClassName().c_str());
  }

protected成員

  • rejection_name_:點對拒絕器的名稱
  • input_correspondences_:輸入的點對
  • applyRejectionapplyRejection函數調用getRemainingCorrespondences,實際執行拒絕點對的過程
protected:
  /** \brief The name of the rejection method. */
  std::string rejection_name_;

  /** \brief The input correspondences. */
  CorrespondencesConstPtr input_correspondences_;

  /** \brief Abstract rejection method. */
  virtual void
  applyRejection(Correspondences& correspondences) = 0;
};
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值