将一对数据类型拆分为CGAL

时间:2017-02-07 19:52:10

标签: c++ cgal std-pair

我是CGAL和C ++的新手(实际上我是C开发人员,为了使用CGAL而转移到C ++)。

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

我用 1-Normal_estimation 2-edge_aware_upsampling 3-advanceancing_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

1 个答案:

答案 0 :(得分:2)

您需要遍历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
}
相关问题