OutputIterator到底是什么,以及如何构建一个用于CGAL Kd_tree::search的OutputIte
What exactly is an OutputIterator and how to build one for use with CGAL Kd_tree::search?
我使用CGAL的Kd-tree实现以及模糊球体作为查询对象,以获得以点为中心的半径为r_max
的球体中包含的点。下面是这个最小的工作示例:
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Kd_tree.h>
#include <CGAL/Search_traits_2.h>
#include <CGAL/Fuzzy_sphere.h>
#include <iostream>
#include <fstream>
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_2 Point;
typedef CGAL::Search_traits_2<K> TreeTraits;
typedef CGAL::Kd_tree<TreeTraits> Kd_tree;
typedef Kd_tree::Tree Tree;
typedef CGAL::Fuzzy_sphere<TreeTraits> Sphere;
int main(int argc, char* argv[])
{
double r_max;
Tree tree;
/* ... fill the tree with points, set the value of r_max ...*/
// Report indices for the neighbors within a sphere
unsigned int idc_query = tree.size()/2; // test index
Tree::iterator kti = idc_query + tree.begin();
Sphere s_query(*kti, r_max);
// Print points
tree.search(std::ostream_iterator<Point>(std::cout, "n"), s_query);
return 0;
}
我从CGAL的示例(我的版本是3.9)的Spatial_searching文件夹下的nearest_neighbor_searching.cpp文件中获取并改编了注释"Print points"下面的行。
问题是:是否有一种方法可以让我设置一个不同的OutputIterator
(而不是std::ostream_iterator
),将指针/迭代器/句柄存储到从排序容器中搜索得到的点,而不是将点的坐标打印到标准输出?谢谢你。
在c++标准库中,有五种迭代器:
- 输入迭代器输出迭代器
- 向前迭代器 双向迭代器
- 随机访问迭代器
更多信息请参见cplusplus.com
在您的例子中,您需要一个输出迭代器,即:,一个对象it
,它可以被加(++it
)和解引用(*it
)来获得一个非const引用,可以被写入。
您可以使用std::back_inserter
:
#include <iterator>
#include <vector>
...
std::vector<Point> points;
tree.search(std::back_inserter(points), s_query);
东西在CGAL中已经进化了,那就是你可以存储除了点以外的其他东西。请看用户手册中使用任意点类型和点属性映射的例子。
相关文章:
- CGAL:如何创建填充边界曲线的曲面网格?
- CGAL:添加要素失败
- CGAL:在浏览平面地图时使用类型"标记"
- Python3.6 模板中的 CGAL C++ 集成错误
- 如何在 cuda 中将 kd 树从主机复制到驱动程序
- 是否可以制作没有内部分割的cgal 3d多多马因网格?
- 如何使用CGAL::D ereference_property_map进行简化?
- CGAL 示例上的编译错误
- 从 CGAL 3D 网格生成中获取顶点坐标的 -6.27744e+66:mesh_implicit_sphere示例
- CGAL:无法打开 .xyz 文件
- 在同一项目中使用 CGAL 和 PCL
- CGAL - 表面网格参数化
- CGAL-三角网格,返回面对面映射
- cgal多边形网格中的tet网格密度分级
- 如何访问CGAL三维三角测量中的面
- 如何设置一个简单的CGAL+Qt程序
- CGAL中的椭球网格生成
- 在 CGAL 中使用Efficient_Ransac时出现问题
- 想要将 CGAL 与四元数相结合是否合乎逻辑
- Cgal表面连通性