PCL - MLS代碼研讀(三)- 坐標計算函數

news/2024/7/23 18:40:28 标签: pcl, mls, 点云

PCL - MLS代碼研讀(三)- 坐標計算函數

    • 前言
    • 三維getMLSCoordinates
    • 二維getMLSCoordinates
    • getPolynomialValue

前言

本篇延續PCL - MLS代碼研讀(二),繼續介紹坐標計算函數。

三維getMLSCoordinates

此函數計算全局坐標系下的三維點pt在局部坐標系(u,v,w坐標系)下的表示:

void
pcl::MLSResult::getMLSCoordinates (const Eigen::Vector3d &pt, double &u, double &v, double &w) const
{
  //mean: 所有鄰居的重心,即擬合平面座標系的原點
  //獲取pt在局部座標系下的三維座標
  Eigen::Vector3d delta = pt - mean;
  u = delta.dot (u_axis);
  v = delta.dot (v_axis);
  w = delta.dot (plane_normal);
}

首先將pt減去局部坐標系原點mean的坐標,得到delta。然後計算deltau_axisv_axisplane_normal三個方向上的投影(有號)長度,即為u,v,w坐標。

注:代碼中用到的mean成員變數是在pcl::MLSResult::computeMLSSurface函數中計算出來的。

二維getMLSCoordinates

與上面的函數類似,只是少算了w坐標。

void
pcl::MLSResult::getMLSCoordinates (const Eigen::Vector3d &pt, double &u, double &v) const
{
  //獲取pt在局部座標系下的二維座標
  Eigen::Vector3d delta = pt - mean;
  u = delta.dot (u_axis);
  v = delta.dot (v_axis);
}

getPolynomialValue

double
pcl::MLSResult::getPolynomialValue (const double u, const double v) const
{
  // Compute the polynomial's terms at the current point
  // Example for second order: z = a + b*y + c*y^2 + d*x + e*x*y + f*x^2
  //在二階的情況下:(ui, vi) = (0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (2, 0)
  int j = 0;
  double u_pow = 1;
  double result = 0;
  for (int ui = 0; ui <= order; ++ui)
  {
    double v_pow = 1;
    for (int vi = 0; vi <= order - ui; ++vi)
    {
      result += c_vec[j++] * u_pow * v_pow;
      v_pow *= v;
    }
    u_pow *= u;
  }

  return (result);
}

如果曲面多項式的階數為二,那麼我們可以用 w = a + b ∗ v + c ∗ v 2 + d ∗ u + e ∗ u ∗ v + f ∗ u 2 w = a + b*v + c*v^2 + d*u + e*u*v + f*u^2 w=a+bv+cv2+du+euv+fu2來表示它。

代碼中的u_pow便表示數學式中的 1 1 1, u u u,或 u 2 u^2 u2,它會在迭代過程中動態改變,v_pow亦然。

result便是對多項式的係數c_vec[j]u_powv_pow的乘積做累加,得到最終的多項式值。

注:代碼中用到的c_vec成員變數是在pcl::MLSResult::computeMLSSurface函數中計算出來的。


http://www.niftyadmin.cn/n/778422.html

相关文章

PCL - MLS代碼研讀(四)- 偏微分計算函數

PCL - MLS代碼研讀&#xff08;四&#xff09;- 偏微分計算函數前言getPolynomialPartialDerivative前言 本篇延續PCL - MLS代碼研讀&#xff08;二&#xff09;&#xff0c;繼續介紹偏微分計算函數。 getPolynomialPartialDerivative 還記得在PCL - MLS代碼研讀&#xff08…

PCL - MLS代碼研讀(五)- 曲率計算函數

PCL - MLS代碼研讀&#xff08;五&#xff09;- 曲率計算函數前言calculatePrincipalCurvatures參考連結前言 本篇延續PCL - MLS代碼研讀&#xff08;二&#xff09;&#xff0c;繼續介紹曲率計算函數。 calculatePrincipalCurvatures Eigen::Vector2f pcl::MLSResult::calc…

PCL - MLS代碼研讀(六)- 各式投影函數

PCL - MLS代碼研讀&#xff08;六&#xff09;- 各式投影函數前言projectPointToMLSPlaneprojectPointSimpleToPolynomialSurfaceprojectPointOrthogonalToPolynomialSurfaceprojectPointprojectQueryPoint前言 本篇終於接近MLS模塊的核心部分&#xff0c;主要介紹各式投影函數…

.template cast<>中template的作用

.template cast<>中template的作用PCL中的surface/include/pcl/surface/impl/mls.hpp裡有這麼一段代碼&#xff1a; query_point cloud[index].getVector3fMap ().template cast<double> ();第一次看到.template cast<>這種寫法一定覺得不明所以&#xff0…

PCL - MLS代碼研讀(七)- 曲面擬合函數

PCL - MLS代碼研讀&#xff08;七&#xff09;- 曲面擬合函數computeMLSSurface宣告兩個變數計算鄰域內所有點的重心計算平面參數model_coefficients被投影點query_point檢查eigen_vector合理性計算局部坐標系原點計算曲率計算局部坐標系的三個軸向設定三個變數權重函數宣告四個…

C++ using - 繼承共同行為 改變成員的訪問權限

C using - 繼承共同行為 & 改變成員的訪問權限前言繼承關係讓變數/函數變成dependent name繼承共同行為改變成員的訪問權限範例程序前言 PCL中的surface/include/pcl/surface/mls.h裡宣告的pcl::MovingLeastSquares類別有這麼一段代碼&#xff1a; namespace pcl {templa…

C++ typename使用時機

C typename使用時機前言KdTreePtrKdTree範例程序前言 PCL中的surface/include/pcl/surface/mls.h裡宣告的pcl::MovingLeastSquares類別有這麼一段代碼&#xff1a; using KdTree pcl::search::Search<PointInT>; //typename specifies that it is the name of a type …

PCL - MLS代碼研讀(八)- MovingLeastSquares

PCL - MLS代碼研讀&#xff08;八&#xff09;- MovingLeastSquares前言pcl::MovingLeastSquaresUpsamplingMethodMLSVoxelGridtypedefusingprotected成員變量public成員函數constructor和destructorgetter和setterprocessprotected成員函數private成員前言 本篇介紹MLS的第二…