|

楼主 |
发表于 2024-11-1 09:25:27
|
显示全部楼层
#include <opennurbs.h>
#include <vector>
// 初始化 OpenNURBS 库
void InitializeOpenNURBS() {
ON::Begin();
}
// 终止 OpenNURBS 库
void TerminateOpenNURBS() {
ON::End();
}
// 使用点云数据创建 NURBS 曲面
ON_NurbsSurface CreateNURBSFromPointCloud(const pcl::PointCloud<PointType>::Ptr& cloud) {
int point_count = static_cast<int>(cloud->points.size());
int u_degree = 3; // NURBS 曲面 U 方向的度数
int v_degree = 3; // NURBS 曲面 V 方向的度数
int u_control_points = 10; // U 方向控制点数量
int v_control_points = 10; // V 方向控制点数量
// 创建一个 NURBS 曲面
ON_NurbsSurface nurbs(3, false, u_degree + 1, v_degree + 1, u_control_points, v_control_points);
// 生成控制点
for (int i = 0; i < u_control_points; ++i) {
for (int j = 0; j < v_control_points; ++j) {
int index = i * v_control_points + j;
if (index < point_count) {
const auto& pt = cloud->points[index];
nurbs.SetCV(i, j, ON_3dPoint(pt.x, pt.y, pt.z));
}
}
}
// 设置 U 和 V 方向的节点矢量
nurbs.MakeClampedUniformKnotVector(0, u_degree + 1); // U 方向节点矢量
nurbs.MakeClampedUniformKnotVector(1, v_degree + 1); // V 方向节点矢量
return nurbs;
}
|
|