用增量计算从点到voronoi单元的距离

问题描述 投票:0回答:1

晚安。有谁遇到过类似的问题?

构建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;
}
c++ boost voronoi boost-geometry
1个回答
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_idreverse_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`)

© www.soinside.com 2019 - 2024. All rights reserved.