将一对数据类型拆分为 CGAL 中的元素

Splitting a pair datatype into its elements in CGAL

我是 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
}