PCL - ICP代碼研讀(十 ) - Correspondence架構
前言
Correspondence
結構體表示兩點雲間的一組配對,它的架構主要寫在correspondence.h
中。
Correspondence
必要的include:
#pragma once
#ifdef __GNUC__
#pragma GCC system_header
#endif
#include <pcl/pcl_base.h>
#include <pcl/memory.h>
#include <pcl/types.h>
#include <Eigen/StdVector>
#include <Eigen/Geometry>
#include <pcl/pcl_exports.h>
namespace pcl
{
Correspondence
結構體的定義:
/**
* distance表示的是距離平方?
* 1. correspondence_estimation.hpp裡面的CorrespondenceEstimation::determineCorrespondences是把距離平方assign給distance?
* 2. default_convergence_criteria.h裡面的DefaultConvergenceCriteria::calculateMSE也是拿當distance距離平方來用?
**/
/** \brief Correspondence represents a match between two entities (e.g., points, descriptors, etc). This is
* represented via the indices of a \a source point and a \a target point, and the distance between them.
*
* \author Dirk Holz, Radu B. Rusu, Bastian Steder
* \ingroup common
*/
struct Correspondence
{
source點雲中的第index_query
個點和target點雲中的第index_match
個點是一個配對:
// (index_query,index_match)分別表示source和target點雲中配對點的索引
/** \brief Index of the query (source) point. */
index_t index_query = 0;
/** \brief Index of the matching (target) point. Set to -1 if no correspondence found. */
index_t index_match = UNAVAILABLE;
此處用到了C++ union,其用法詳見c++ --> union介绍。
這裡把距離(對照後面correspondence_estimation.h
的代碼來看,應該是距離平方)及權重一同用union
管理->不太懂這麼做的用意。
// 註解錯了,應該是距離平方,還是要把變數名改掉?
/** \brief Distance between the corresponding points, or the weight denoting the confidence in correspondence estimation */
// union?待研究
union
{
float distance = std::numeric_limits<float>::max();
float weight;
};
Correspondence
建構子,可選擇是否傳入兩配對點索引及它們之間的距離:
/** \brief Standard constructor.
* Sets \ref index_query to 0, \ref index_match to -1, and \ref distance to FLT_MAX.
*/
inline Correspondence () = default;
/** \brief Constructor. */
inline Correspondence (index_t _index_query, index_t _index_match, float _distance) :
index_query (_index_query), index_match (_index_match), distance (_distance)
{}
PCL_MAKE_ALIGNED_OPERATOR_NEW
};
overload <<
運算子:
/** \brief overloaded << operator */
PCL_EXPORTS std::ostream& operator << (std::ostream& os, const Correspondence& c);
定義名稱,方便後續使用:
// 多個Correspoondence構成的向量
using Correspondences = std::vector< pcl::Correspondence, Eigen::aligned_allocator<pcl::Correspondence> >;
using CorrespondencesPtr = shared_ptr<Correspondences>;
using CorrespondencesConstPtr = shared_ptr<const Correspondences >;
getRejectedQueryIndices
用於尋找被拒絕的點對:
/**
* \brief Get the query points of correspondences that are present in
* one correspondence vector but not in the other, e.g., to compare
* correspondences before and after rejection.
* \param[in] correspondences_before Vector of correspondences before rejection
* \param[in] correspondences_after Vector of correspondences after rejection
* \param[out] indices Query point indices of correspondences that have been rejected
* \param[in] presorting_required Enable/disable internal sorting of vectors.
* By default (true), vectors are internally sorted before determining their difference.
* If the order of correspondences in \a correspondences_after is not different (has not been changed)
* from the order in \b correspondences_before this pre-processing step can be disabled
* in order to gain efficiency. In order to disable pre-sorting set \a presorting_required to false.
*/
// 比較correspondences_before和correspondences_after,找出是哪個點對被拒絕了
// 在找差集之前是否要先排序,預設是要
void
getRejectedQueryIndices (const pcl::Correspondences &correspondences_before,
const pcl::Correspondences &correspondences_after,
Indices& indices,
bool presorting_required = true);
目前沒看到這些定義在哪裡被用到,暫時略過:
/**
* \brief Representation of a (possible) correspondence between two 3D points in two different coordinate frames
* (e.g. from feature matching)
* \ingroup common
*/
// 為何要用兩個坐標系?
struct PointCorrespondence3D : public Correspondence
{
Eigen::Vector3f point1; //!< The 3D position of the point in the first coordinate frame
Eigen::Vector3f point2; //!< The 3D position of the point in the second coordinate frame
PCL_MAKE_ALIGNED_OPERATOR_NEW
};
using PointCorrespondences3DVector = std::vector<PointCorrespondence3D, Eigen::aligned_allocator<PointCorrespondence3D> >;
/**
* \brief Representation of a (possible) correspondence between two points (e.g. from feature matching),
* that encode complete 6DOF transformations.
* \ingroup common
*/
// 將點由坐標系二轉換到坐標系一?
struct PointCorrespondence6D : public PointCorrespondence3D
{
Eigen::Affine3f transformation; //!< The transformation to go from the coordinate system
//!< of point2 to the coordinate system of point1
PCL_MAKE_ALIGNED_OPERATOR_NEW
};
using PointCorrespondences6DVector = std::vector<PointCorrespondence6D, Eigen::aligned_allocator<PointCorrespondence6D> >;
isBetterCorrespondence
函數比較兩個Correspondence,如果第一個Correspondence的distance
較大,則回傳true。(?)目前沒看到這個函數在哪裡被用到。
/**
* \brief Comparator to enable us to sort a vector of PointCorrespondences according to their scores using
* std::sort (begin(), end(), isBetterCorrespondence);
* \ingroup common
*/
// 距離大的反而是好的配對?
inline bool
isBetterCorrespondence (const Correspondence &pc1, const Correspondence &pc2)
{
return (pc1.distance > pc2.distance);
}
}