晚安。有没有人遇到类似的问题?
构建Voronoi图并没有引起问题。 Voronoi单元格是一个多边形,至少对我而言。该库还允许您查找从点到多边形的距离。但库函数不想使用单元格。编译器在精灵语中产生一些东西。玩笑。总之,编译器输出无法帮助我。 有没有办法从单元格制作多边形?
Voronoi图是在vpoints上构建的。程序应该计算从qpoints元素到相应单元格的距离。 这是我的代码:
#include <iostream>
#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/polygon/voronoi.hpp>
namespace bg = boost::geometry;
using boost::polygon::voronoi_diagram;
typedef voronoi_diagram<double>::cell_type cell_type;
typedef voronoi_diagram<double>::edge_type edge_type;
typedef voronoi_diagram<double>::vertex_type vertex_type;
typedef boost::polygon::point_data<double> point_type;
using namespace std;
int main() {
vector< point_type > vpoints;
vpoints.push_back(point_type(0.0, 0.0));
vpoints.push_back(point_type(0.0, 4.0));
vpoints.push_back(point_type(4.0, 4.0));
vpoints.push_back(point_type(4.0, 0.0));
vpoints.push_back(point_type(2.0, 2.0));
vector< point_type > qpoints;
qpoints.push_back(point_type(0.0, 0.0));
qpoints.push_back(point_type(0.0, 2.0));
qpoints.push_back(point_type(3.0, 3.0));
qpoints.push_back(point_type(5.0, 5.0));
qpoints.push_back(point_type(5.0, 5.0));
voronoi_diagram<double> vd;
construct_voronoi(vpoints.begin(), vpoints.end(), &vd);
for (int i = 0; i < qpoints.size(); i++) {
for (voronoi_diagram<double>::const_cell_iterator it = vd.cells().begin();
it != vd.cells().end(); ++it) {
if (i == it->source_index()) {
cout << "v[i]=(" << vpoints[i].x() << "," << vpoints[i].y() << ")\t";
cout << "q[i]=(" << qpoints[i].x() << "," << qpoints[i].y() << ")\t";
cout << "Distance=";
cout << bg::distance(qpoints[i], *it) << endl;
cout << endl;
break;
}
}
}
return 0;
}
答案 0 :(得分:0)
消息是
boost_1_57_0/boost/geometry/core/geometry_id.hpp|37 col 5| error: no matching function for call to ‘assertion_failed(mpl_::failed************ (boost::geometry::core_dispatch::geometry_id<void>::NOT_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE::************)(mpl_::assert_::types<void, mpl_::na, mpl_::na, mpl_::na>))’
哪个是NOT_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
断言。对geometry_id
执行reverse_dispatch
时会发生这种情况:
/*!
\brief Meta-function returning the id of a geometry type
\details The meta-function geometry_id defines a numerical ID (based on
boost::mpl::int_<...> ) for each geometry concept. A numerical ID is
sometimes useful, and within Boost.Geometry it is used for the
reverse_dispatch metafuntion.
\note Used for e.g. reverse meta-function
\ingroup core
*/
template <typename Geometry>
struct geometry_id : core_dispatch::geometry_id<typename tag<Geometry>::type>
{};
执行
时会触发相同的警告 cout << distance(qpoints[i], qpoints[i]) << endl;
所以问题是你的点类型不是一个重新命名的几何。包括
#include <boost/geometry/geometries/adapted/boost_polygon.hpp>
进行编译,但当然
cout << distance(qpoints[i], *it) << endl;
仍然失败,这次因为const boost::polygon::voronoi_cell<double>
不是Boost Geometry的已知几何类型。
我建议不混合库,除非你知道为什么要这样做。
在我看来,voronoi单元不仅仅是一件事(contains_segment()
和contains_point()
是指示)。您可能必须编写一些切换逻辑来单独处理可能的情况,并且可能在此过程中使用来自Boost Polygon的euclidean_distance
(而不是boost :: geometry :: distance`)