在 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
}
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 使用strcpy将char数组的元素复制到另一个数组
- 使用不带参数的函数访问结构元素
- 给定n个元素的m个集合.在C++中找到出现在最大集合数中的元素
- C++如何通过用户输入删除列表元素
- lower_bound()返回最后一个元素
- 基于多个条件处理地图中的所有元素
- 调整大小后指向元素值的指针unordered_map有效?
- 使用std::transform将一个范围的元素添加到另一个范围中
- 使用函数"remove"删除重复元素
- 具有最大子序列大小的序列,每个元素都相同
- C++17 在逗号上拆分 constexpr 字符串并在编译时有元素的数量?
- 使用 std::regex 拆分一行并丢弃空元素
- 在 CGAL 中将对数据类型拆分为其元素
- 矢量拆分/移位元素
- 编辑:根据偶数和奇数元素将数组拆分为两个
- 在空格处拆分字符串并返回C++中的第一个元素
- 将QStringList元素拆分为更多元素
- 字符串拆分为矢量<字符*>覆盖矢量元素