SISL 插值、近似 example 运行测试

news/2024/9/20 5:38:10 标签: b样条
void
VisualizeSISLCurve(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_cv, double r, double g, double b, bool show_cps)
{
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
    cloud->clear();
    //输入点数
    const int number = cloud_cv->size();
    //三次四阶
    const int order = 4;
    std::vector<double> coef;
    
    for (int j = 0; j < cloud_cv->size(); j++)
    {
        auto&pnt=cloud_cv->at(j);
        coef.push_back(pnt.x);
        coef.push_back(pnt.y);
        coef.push_back(pnt.z);


    }
   
    //节点向量的大小似乎不能初始化为number+order-3
    int no_repeate_nknot = number-(order-1)+1;
    std::vector<double> knots(no_repeate_nknot + 2 * (order - 1), 0);
    for (int j = order - 1,k=0; j < order - 1 + no_repeate_nknot; ++j,++k)
    {
        knots[j] = k;
    }
    for (int j = order - 1 + no_repeate_nknot; j < knots.size(); ++j)
    {
        knots[j] = knots[order - 1 + no_repeate_nknot-1];
    }
    //创建开口曲线
    SISLCurve* curve = newCurve(number, // number of control points
        order,  // order of spline curve (degree + 1)
        knots.data(),  // pointer to knot vector (parametrization)
        coef.data(),   // pointer to coefficient vector (control points)
        1,      // kind = polynomial B-spline curve
        3,      // dimension
        0);     // no copying of information, 'borrow' arrays
    if (!curve) {
        throw std::runtime_error("Error occured while generating curve.");
    }
    freeCurve(curve);
   
    double astpar = 0.0;
    int iopen = -1;
    int idim = 3;
    int ik = 4;
    curve = NULL;
    int jstat = 0;
    //将数据作为控制点创建封闭曲线
    s1630(coef.data(), number, astpar, iopen, idim, ik, &curve, &jstat);
    freeCurve(curve);
    curve = NULL;
    //插值封闭曲线
    {
        
        std::vector<int> nptyp(number,1);
        int icnsta = 0;
        int icnend = 0;
        int iopen = -1;
      
        double astpar = 0.0;
        double cendpar = 0.0;
       
        double* gpar = NULL;
        int jnbpar = 0;
        int jstat = 0;
        s1356(coef.data(), number, idim, nptyp.data(), icnsta, icnend, iopen, ik, astpar, &cendpar, &curve, &gpar, &jnbpar, &jstat);
           
        
    }
    freeCurve(curve);
    curve = NULL;
    //生成近似曲线,拟合?噪声点的影响如何消除,SISL 中有没有类似pcl中样条曲线拟合的接口?
    {
        const double tolerance = 1.0e-5; // pointwise tolerance
        const double afctol = 0.1; // number between 0 and 1 describing how tolerance
        // is to be distributed in two different steps of the
        // algorithm.
        const int max_iterations = 6;
        std::vector<double> tolerance_vec(number, tolerance); // same tolerance for all samples
        std::vector<double> emxerr(number);
        int jstat = 0;
        int iopen = -1;// Produce closed, periodic curve if possible 没有强制闭合
        int ik = 4;
        s1961(coef.data(), // array of points to be approximated
            number,              // number of sample points
            3,                        // dimension of Euclidean space
            2,                        // flag indicating uniform parametrization
            NULL,                     // we do not use this argument
            &tolerance_vec[0],        // the pointwise tolerance
            0,                        // number of fixed derivatives at left
            0,                        // number of fixed derivatives at right
            iopen,                        // flag indicating that we want an open curve
            afctol,                   // distribution of tolerance
            max_iterations,           // maximum number of iterations in the routine
            ik,                        // polynomial order of approximation
            &curve,            // pointer to the generated curve
            &emxerr[0],               // reporting the max deviation in each point
            &jstat);                  // status variable

        if (jstat < 0) {
            throw std::runtime_error("Error occured inside call to SISL routine s1961.");
        }
        else if (jstat > 0) {
            cerr << "WARNING: warning occured inside call to SISL routine s1961. \n"
                << endl;
        }
    }




//输出曲线500离散点
#define CURVE_EVALUATIONS 500
    
    double discr_curve[3 * CURVE_EVALUATIONS];
    int left = 0;
    for (int j = 0; j < CURVE_EVALUATIONS; j++)
    {
        double t =
            curve->et[curve->ik - 1] +
            (curve->et[curve->in] - curve->et[curve->ik - 1]) *
            j / (CURVE_EVALUATIONS - 1.0);
        {
            int stat;

            s1227(curve, 0, t, &left, discr_curve + 3 * j, &stat);
            if (stat != 0)
                printf("s1227 returned status %d.\n", stat);
        }
    }
        
    for (int j = 0; j < CURVE_EVALUATIONS; j++)
    {
        pcl::PointXYZRGB p;

        p.x = static_cast<float> (discr_curve[3 * j+0]);
        p.y = static_cast<float> (discr_curve[3 * j + 1]);
        p.z = static_cast<float> (discr_curve[3 * j + 2]);
        p.r = 255;
        p.g = 0;
        p.b = 0;
        cloud->push_back(p);
       
    }
    
    freeCurve(curve);



    for (std::size_t i = 0; i < cloud->size() - 1; i++)
    {
        pcl::PointXYZRGB& p1 = cloud->at(i);
        pcl::PointXYZRGB& p2 = cloud->at(i + 1);
        std::ostringstream os;
        os << "line_" << r << "_" << g << "_" << b << "_" << i;
        viewer.addLine<pcl::PointXYZRGB>(p1, p2, r, g, b, os.str());

    }
    /*if (show_cps)
    {
        pcl::PointCloud<pcl::PointXYZ>::Ptr cps(new pcl::PointCloud<pcl::PointXYZ>);
        for (int i = 0; i < cloud_cv->size(); i++)
        {
            pcl::PointXYZ& p1 = cloud_cv->at(i);
            ON_3dPoint cp(p1.x, p1.y, p1.z);


            pcl::PointXYZ p;
            p.x = float(cp.x);
            p.y = float(cp.y);
            p.z = float(cp.z);
            cps->push_back(p);
        }
        pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> handler(cps, 255 * r, 255 * g, 255 * b);
        viewer.addPointCloud<pcl::PointXYZ>(cps, handler, "cloud_cps");
    }*/
}

s1356 example02 的结果

s1961 example14 的结果


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

相关文章

『C/C++』整型和字符串相互转换

■函数名:itoa 功 能:把整数转换为字符串。 原型: char *itoa(int value, char *string, int radix); ◎value: 待转化的整数。 ◎radix: 是基数的意思,即先将value转化为radix进制的数&#xff0c;范围介于2-36&#xff0c;比如10表示10进制。 ◎string: 保存转换后得…

Leetcode面试经典150题-130.被围绕的区域

给你一个 m x n 的矩阵 board &#xff0c;由若干字符 X 和 O 组成&#xff0c;捕获 所有 被围绕的区域&#xff1a; 连接&#xff1a;一个单元格与水平或垂直方向上相邻的单元格连接。区域&#xff1a;连接所有 O 的单元格来形成一个区域。围绕&#xff1a;如果您可以用 X 单…

供方软件供应链安全保障要求及开源场景对照自评表(下)

国标《信息安全技术 软件供应链安全要求》确立了软件供应链安全目标&#xff0c;规定了软件供应链安全风险管理要求和供需双方的组织管理和供应活动管理安全要求。 开源软件供应链作为软件供应链的一种特殊形式&#xff0c;该国标亦适用于指导开源软件供应链中的供需双方开展组…

FPGA开发-0到1

FPGA开发-0到1 文章目录 FPGA开发-0到1前言一、FPGA资源/资源评估1.1 硬件资源1.1.1 BANK的划分1.1.2 布线资源1.1.3 逻辑资源1.1.4 时钟资源1.1.5 存储资源1.1.3 GT资源1.2 资源评估1.2.1 评估步骤1.2.2 评估方法二 代码架构/代码规范三 时钟四 复位五 跨时钟域处理六 常用功能…

双光吊舱应用行业!!

1. 军事领域 侦察与监视&#xff1a;双光吊舱能够全天候、全气候地提供高清图像数据&#xff0c;支持军事侦察和监视任务。通过可见光相机和红外热成像仪的结合&#xff0c;吊舱可以在白天和夜晚、晴天和恶劣天气条件下&#xff0c;为无人机等空中平台提供清晰的战场图像&…

CentOS5.2中安装并设置TFTP服务

在CentOS5.2中安装并设置TFTP服务,下面安装TFTP服务必须能联网,因为是使用yum安装,如果使用rpm从光盘安装则不需要。下面是步骤: 安装TFTP服务器: yum install tftp-server 安装TFTP客户端: yum install tftp 执行上面的命令后会自动搜索相应的最新版软件并自动下…

《高等代数》范德蒙德行列式(应用)

说明&#xff1a;此文章用于本人复习巩固&#xff0c;如果也能帮助到大家那就更加有意义了。 注&#xff1a;1&#xff09;此题中的行列式是缺失了一行的范德蒙德行列式&#xff0c;解题思路是将其与范德蒙德行列式进行对比&#xff0c;我们将其添上一行和一列补成范德蒙德行列…

GO CronGin

文章目录 Robfig Cron介绍1. **安装 robfig/cron**2. **基本用法**示例&#xff1a;创建一个简单的定时任务3. **Cron 表达式**常用的 Cron 表达式示例&#xff1a;4. **添加和管理任务**5. **上下文支持**6. **使用场景**7. **高级用法**总结 Cron 在Gin中实践使用1. **安装 r…