晚安。有人遇到过类似的问题吗?
构建Voronoi图没有引起问题。Voronoi cell是一个多边形,至少对我来说是这样。该库还允许您查找从点到多边形的距离。但是库函数不想使用该单元格。编译器用Elvish生成一些东西。开个玩笑。简而言之,编译器的输出帮不了我。有没有一种方法可以从单元中生成多边形?
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;
}发布于 2014-12-15 18:00:44
这条信息是
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断言。为reverse_dispatch执行geometry_id时发生了这种情况
/*!
\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>不是一种已知的几何类型来提升几何。
我建议使用而不是来混用这些库,除非你知道为什么要这样做。
在我看来,一个voronoi细胞可以不仅仅是一个单一的东西(contains_segment()和contains_point()是指示)。您可能需要编写一些切换逻辑来单独处理可能的情况,并可能在此过程中使用Boost Polygon中的euclidean_distance (而不是boost::geometry::distance`)
https://stackoverflow.com/questions/27476080
复制相似问题