在 CGAL 中将对数据类型拆分为其元素

Splitting a pair datatype into its elements in CGAL

本文关键字:拆分 元素 数据类型 CGAL      更新时间:2023-10-16

我是CGAL的新手,也是C++(实际上我是一名C开发人员,为了使用CGAL而搬到C++(。

我发现通过混合 CGAL 文档中提供的 2-3 个示例,我可以用 CGAL 做我想做的事。如果我单独运行每个代码并获取输出并将其引入第二个代码,则一切都很好。(在其中一个中,我需要手动删除随位置生成的法线向量(。

我使用1-Normal_estimation 2-edge_aware_upsampling 3-advancing_front_surface_reconstruction。我想使它们成为单个代码,因为我需要在许多样本上运行它。

问题是前两个代码处理的是pair数据类型。

typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_3  Point;
typedef K::Vector_3 Vector;    
typedef std::pair<Point, Vector> PointVectorPair;
std::list<PointVectorPair> points;

但是,最后一个代码适用于

std::vector<Point> points_n;

我想要一个函数,给我std::list<std::pair<Point , Vector>>的第一部分,即Points

points_n = magic_function(points);

什么是magic_function

您需要

遍历std::list并从每对复制Point并将其推送到向量中。如果你至少有C++ 11 个支持,你可以做这样的事情:

std::vector<Point> magic_function(const std::list<PointVectorPair>& list)
{
    std::vector<Point> out;//a temporary object to store the output
    for(auto&& p: list)// for each pair in the list
    {
        out.push_back(std::get<0>(p)); //copy the point and push it on to the vector
    }
    return out; //return the vector of points
}

或者,如果您不想复制该点,而是想移动它,您可以执行以下操作:

std::vector<Point> magic_function(const std::list<PointVectorPair>& list)
{
    std::vector<Point> out;//a temporary object to store the output
    for(auto&& p: list)// for each pair in the list
    {
        out.push_back(std::move(std::get<0>(p))); //move the point to the vector
    }
    return out; //return the vector of points
}