1. B样条曲线
基于点距离最小化的三维B样条曲线拟合:
fitting_curve_pdm.h
fitting_curve_pdm.cpp
主要函数:
1)求点 x i xi xi在节点向量的哪个区间:
/** \brief Find the element in which the parameter xi lies.
* \param[in] xi value in parameter domain of the B-Spline curve.
* \param[in] elements the vector of elements of the curve.
* \return index of the element with respect to elements.
*/
static int
findElement (double xi, const std::vector<double> &elements);
2)通过每两个节点间插入中间节点修正曲线:
/** \brief Refines curve by inserting a knot in the middle of each element. */
void
refine ();
3)根据约束条件,给定系统方程组:
/** \brief Assemble the system of equations for fitting
* - for large point-clouds this is time consuming.
* - should be done once before refinement to initialize the starting points for point inversion.
*/
void
assemble (const Parameter ¶meter);
4)求解系统方程组,可以选择使用Eigen或UmfPack:
/** \brief Solve system of equations using Eigen or UmfPack (can be defined in on_nurbs.cmake),
* and updates B-Spline curve if a solution can be obtained.
*/
void
solve (double damp = 1.0);
5)更新曲线:
/** \brief Update curve according to the current system of equations.
* \param[in] damp damping factor from one iteration to the other.
*/
void
updateCurve (double damp);
6)使用边界点构成的圆或者PCA初始化曲线:
/** \brief Initialize a closed B-Spline curve using the bounding circle of the point-cloud.
* \param[in] order polynomial order of the curve.
* \param[in] data 3D point-cloud
* \return B-Spline curve.
*/
static ON_NurbsCurve
initNurbsCurve2D (int order, const vector_vec2d &data);
/** \brief Initialize a closed B-Spline curve using the eigenvalues as elliptic parameters (z=0).
* \param[in] order polynomial order of the curve.
* \param[in] data 3D point-cloud
* \return B-Spline curve.
*/
static ON_NurbsCurve
initNurbsCurvePCA (int order, const vector_vec3d &data, int ncps = 0, double rf = 1.0);
7)点反演,给定一个点pt,使用牛顿法、L2范数,求取曲线上最近的点:
/** \brief Inverse mapping / point inversion: Given a point pt, this function finds the closest
* point on the B-Spline curve using Newtons method and point-distance (L2-, Euclidean norm).
* \param[in] nurbs the B-Spline curve.
* \param[in] pt the point to which the closest point on the curve will be computed.
* \param[in] hint the starting point in parametric domain (warning: may lead to convergence at local minima).
* \param[in] error the distance between the point pt and p after convergence.
* \param[in] p closest point on curve.
* \param[in] t the tangent vector at point p.
* \param[in] maxSteps maximum number of iterations.
* \param[in] accuracy convergence criteria: if error is lower than accuracy the function returns
* \return closest point on curve in parametric domain.
*/
static double
inverseMapping (const ON_NurbsCurve &nurbs, const Eigen::Vector3d &pt, const double &hint, double &error,
Eigen::Vector3d &p, Eigen::Vector3d &t, int maxSteps = 100, double accuracy = 1e-6,
bool quiet = true);
总结:
PCL中B样条曲线拟合的思路是,对初始化的曲线,通过不断插入中间节点来修正曲线,每次求解过程通过点线距离约束,构造矩阵方程组,求解得到控制点,不断迭代修正,对于稠密点云,求解线性方程组的过程较慢,导致拟合速度较慢,使用UmfPack可加快求解速度。
2. B样条曲面
主要用到pdm、sdm两种距离度量:
fitting_surface_pdm.h、fitting_surface_pdm.cpp
fitting_surface_sdm.h、fitting_surface_sdm.cpp
主要函数:
1)得到某个维度上的节点向量:
/** \brief Get the elements of a B-Spline surface.*/
static std::vector<double>
getElementVector (const ON_NurbsSurface &nurbs, int dim);
2)初始化曲面,可以使用4个角点、PCA或者PCA+边界点:
/** \brief Initializing a B-Spline surface using 4 corners */
static ON_NurbsSurface
initNurbs4Corners (int order, ON_3dPoint ll, ON_3dPoint lr, ON_3dPoint ur, ON_3dPoint ul);
/** \brief Initializing a B-Spline surface using principal-component-analysis and eigen values */
static ON_NurbsSurface
initNurbsPCA (int order, NurbsDataSurface *data, Eigen::Vector3d z = Eigen::Vector3d (0.0, 0.0, 1.0));
/** \brief Initializing a B-Spline surface using principal-component-analysis and bounding box of points */
static ON_NurbsSurface
initNurbsPCABoundingBox (int order, NurbsDataSurface *data, Eigen::Vector3d z = Eigen::Vector3d (0.0, 0.0, 1.0));
3)给定一个点pt,使用牛顿法,pdm距离或者sdm距离求解曲面上的最近一点:
/** \brief Inverse mapping / point inversion: Given a point pt, this function finds the closest
* point on the B-Spline surface using Newtons method and point-distance (L2-, Euclidean norm).
* \param[in] nurbs the B-Spline surface.
* \param[in] pt the point to which the closest point on the surface will be computed.
* \param[in] hint the starting point in parametric domain (warning: may lead to convergence at local minima).
* \param[in] error the distance between the point pt and p after convergence.
* \param[in] p closest point on surface.
* \param[in] tu the tangent vector at point p in u-direction.
* \param[in] tv the tangent vector at point p in v-direction.
* \param[in] maxSteps maximum number of iterations.
* \param[in] accuracy convergence criteria: if error is lower than accuracy the function returns
* \return closest point on surface in parametric domain.
*/
static Eigen::Vector2d
inverseMapping (const ON_NurbsSurface &nurbs, const Eigen::Vector3d &pt, const Eigen::Vector2d &hint,
double &error, Eigen::Vector3d &p, Eigen::Vector3d &tu, Eigen::Vector3d &tv, int maxSteps = 100,
double accuracy = 1e-6, bool quiet = true);
static Eigen::Vector2d
inverseMapping (const ON_NurbsSurface &nurbs, const Eigen::Vector3d &pt, const Eigen::Vector2d &hint,
Eigen::Vector3d &p, int maxSteps, double accuracy, bool quiet);
4)给定一个点pt,使用牛顿法,pdm距离或者sdm距离求解曲面边界上的最近一点:
/** \brief Inverse mapping / point inversion: Given a point pt, this function finds the closest
* point on the boundary of the B-Spline surface using Newtons method and point-distance (L2-, Euclidean norm).
* \param[in] nurbs the B-Spline surface.
* \param[in] pt the point to which the closest point on the surface will be computed.
* \param[in] error the distance between the point pt and p after convergence.
* \param[in] p closest boundary point on surface.
* \param[in] tu the tangent vector at point p in u-direction.
* \param[in] tv the tangent vector at point p in v-direction.
* \param[in] maxSteps maximum number of iterations.
* \param[in] accuracy convergence criteria: if error is lower than accuracy the function returns
* \return closest point on surface in parametric domain.
*/
static Eigen::Vector2d
inverseMappingBoundary (const ON_NurbsSurface &nurbs, const Eigen::Vector3d &pt, double &error,
Eigen::Vector3d &p, Eigen::Vector3d &tu, Eigen::Vector3d &tv, int maxSteps = 100,
double accuracy = 1e-6, bool quiet = true);
/** \brief Inverse mapping / point inversion: Given a point pt, this function finds the closest
* point on one side of the boundary of the B-Spline surface using Newtons method and
* point-distance (L2-, Euclidean norm).
* \param[in] nurbs the B-Spline surface.
* \param[in] pt the point to which the closest point on the surface will be computed.
* \param[in] side the side of the boundary (NORTH, SOUTH, EAST, WEST)
* \param[in] hint the starting point in parametric domain (warning: may lead to convergence at local minima).
* \param[in] error the distance between the point pt and p after convergence.
* \param[in] p closest boundary point on surface.
* \param[in] tu the tangent vector at point p in u-direction.
* \param[in] tv the tangent vector at point p in v-direction.
* \param[in] maxSteps maximum number of iterations.
* \param[in] accuracy convergence criteria: if error is lower than accuracy the function returns
* \return closest point on surface in parametric domain.
*/
static Eigen::Vector2d
inverseMappingBoundary (const ON_NurbsSurface &nurbs, const Eigen::Vector3d &pt, int side, double hint,
double &error, Eigen::Vector3d &p, Eigen::Vector3d &tu, Eigen::Vector3d &tv,
int maxSteps = 100, double accuracy = 1e-6, bool quiet = true);
5)根据约束条件,设定待求解的系统方程:
/** \brief Assemble the system of equations for fitting
* - for large point-clouds this is time consuming.
* - should be done once before refinement to initialize the starting points for point inversion.
*/
virtual void
assemble (Parameter param = Parameter ());
6)系统方程的求解,使用Eigen或者UmfPack,UmfPack可以加速求解稀疏矩阵方程组:
/** \brief Solve system of equations using Eigen or UmfPack (can be defined in on_nurbs.cmake),
* and updates B-Spline surface if a solution can be obtained.
*/
virtual void
solve (double damp = 1.0);
7)曲面的更新:
/** \brief Update surface according to the current system of equations.
* \param[in] damp damping factor from one iteration to the other.
*/
virtual void
updateSurf (double damp);
8)通过插入中间节点修正曲面:
/** \brief Refines surface by inserting a knot in the middle of each element.
* \param[in] dim dimension of refinement (0,1)
*/
void
refine (int dim);
static void
refine (ON_NurbsSurface &nurbs, int dim);
总结:
PCL中B样条曲面拟合的思路是,对初始化的曲面,通过在两个维度上,不断插入中间节点来修正曲面,每次求解过程通过点线距离约束或者切线距离约束,构造矩阵方程组,求解得到控制点,不断迭代修正,对于稠密点云,求解矩阵方程组的过程较慢,导致拟合速度较慢,使用UmfPack可加快求解速度。
3. 多个B样条曲面的全局优化
global_optimization_pdm.h、global_optimization_pdm.cpp
global_optimization_sdm.h、global_optimization_sdm.cpp
在单个方程组中使用点距离或切线距离最小化法,从全局的三维点云中拟合和优化多个B样条曲面.
主要函数:
设置两个B样条曲面的共同边界点
/** \brief Set common boundary points two NURBS should lie on
* \param[in] boundary vector of boundary points.
* \param[in] nurbs_indices vector of 2 NURBS indices sharing the boundary point. */
void
setCommonBoundary (const vector_vec3d &boundary, const vector_vec2i &nurbs_indices);
其他函数与单个B样条曲面拟合基本相同。
参考
https://github.com/PointCloudLibrary/pcl/tree/master/surface
321



被折叠的 条评论
为什么被折叠?



