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_
:輸入的點對applyRejection
:applyRejection
函數調用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;
};