以下是一个示例代码,用于导入两种不同的点云,并将其中一种点云标记为红色:

#include <iostream>
#include <vector>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/algorithm.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/write_xyz_points.h>
#include <CGAL/pointcloudIO.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point;

int main()
{
    // 读取第一种点云
    std::vector<std::vector<Point>> points1;
    std::ifstream input1("points1.xyz");
    if (!input1)
    {
        std::cerr << "Failed to open file points1.xyz" << std::endl;
        return EXIT_FAILURE;
    }
    CGAL::read_xyz_points(input1, points1);

    // 读取第二种点云
    std::vector<std::vector<Point>> points2;
    std::ifstream input2("points2.xyz");
    if (!input2)
    {
        std::cerr << "Failed to open file points2.xyz" << std::endl;
        return EXIT_FAILURE;
    }
    CGAL::read_xyz_points(input2, points2);

    // 标记第一种点云为红色
    for (auto& vec : points1)
    {
        for (auto& p : vec)
        {
            p = Point(p.x(), p.y(), p.z(), CGAL::RED);
        }
    }

    // 输出点云
    std::ofstream output("output.xyz");
    if (!output)
    {
        std::cerr << "Failed to open file output.xyz" << std::endl;
        return EXIT_FAILURE;
    }
    CGAL::write_xyz_points(output, points1);
    CGAL::write_xyz_points(output, points2);

    return EXIT_SUCCESS;
}

请注意,此代码假定点云文件格式为XYZ格式。如果您的点云文件格式不同,请相应地更改读取和写入函数

CGAL导入两种不同的stdvectorstdvectorPoint点云为了区分两种点云给其中一种点云上红色。请附上代码并且不能使用QT。

原文地址: https://www.cveoy.top/t/topic/cuW0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录