PCL - MLS代碼研讀(十二)- addProjectedPointNormal及copyMissingFields函數
前言
在PCL - MLS代碼研讀(十)- performProcessing函數和PCL - MLS代碼研讀(十一)- computeMLSPointNormal函數這兩篇文章中,時不時能看見到addProjectedPointNormal
和copyMissingFields
這兩個函數的蹤影。這兩個函數相較於之前介紹過的幾個函數較沒那麼重要,因此在這篇文章中一併介紹。
addProjectedPointNormal
addProjectedPointNormal
函數有index
,point
,normal
,curvature
四個入參,這個函數會將他們轉成合適的型別後,再新增到projected_points
, projected_points_normals
, corresponding_input_indices
這三個數據結構中。
template <typename PointInT, typename PointOutT> void
pcl::MovingLeastSquares<PointInT, PointOutT>::addProjectedPointNormal (pcl::index_t index,
const Eigen::Vector3d &point,
const Eigen::Vector3d &normal,
double curvature,
PointCloudOut &projected_points,
NormalCloud &projected_points_normals,
PointIndices &corresponding_input_indices) const
{
輸入點point
跟輸出點的類型可能不同,所以這裡建立一個新的:
PointOutT aux;
然後把輸入點point
裡的內容複製到PointOutT
的aux
裡面:
aux.x = static_cast<float> (point[0]);
aux.y = static_cast<float> (point[1]);
aux.z = static_cast<float> (point[2]);
如果有RGBA等欄位的話,就複製過去:
// Copy additional point information if available
copyMissingFields ((*input_)[index], aux);
更新projected_points
及corresponding_input_indices.indices
:
// aux表示投影點
// corresponding_input_indices要跟projected_points一起看,表示該投影點對應的輸入點的索引?
projected_points.push_back (aux);
corresponding_input_indices.indices.push_back (index);
如果compute_normals_
為true,則複製法向量及曲率到pcl::Normal
的點內,並更新projected_points_normals
:
if (compute_normals_)
{
pcl::Normal aux_normal;
aux_normal.normal_x = static_cast<float> (normal[0]);
aux_normal.normal_y = static_cast<float> (normal[1]);
aux_normal.normal_z = static_cast<float> (normal[2]);
aux_normal.curvature = curvature;
projected_points_normals.push_back (aux_normal);
}
}
copyMissingFields
如果point_in
有RGBA
欄位,則將他們複製到point_out
中。
template <typename PointInT, typename PointOutT> void
pcl::MovingLeastSquares<PointInT, PointOutT>::copyMissingFields (const PointInT &point_in,
PointOutT &point_out) const
{
PointOutT temp = point_out;
copyPoint (point_in, point_out);
point_out.x = temp.x;
point_out.y = temp.y;
point_out.z = temp.z;
}