C++ 将非几何信息与CGAL Voronoi图中的位置(面)关联

C++ 将非几何信息与CGAL Voronoi图中的位置(面)关联,c++,cgal,voronoi,C++,Cgal,Voronoi,注意:有关解决我问题的代码,请参阅本文底部的“编辑” 我正在用CGAL构建一个Voronoi图。我的图表中的每个站点都有一些与之相关的非几何信息(如城市人口或某个位置的温度)。在构建Voronoi图之后,我将对其执行位置查询,并且我需要能够从查询结果中恢复这些非几何信息。CGAL似乎有能力做到这一点;这将在Delaunay三角剖分的背景下进行讨论。但我不知道如何将此技术应用于Voronoi图。以下是我尝试过的,但编译失败: 已删除损坏的代码。请参阅下面的工作代码示例 问题的其余部分已删除,因为它

注意:有关解决我问题的代码,请参阅本文底部的“编辑”

我正在用CGAL构建一个Voronoi图。我的图表中的每个站点都有一些与之相关的非几何信息(如城市人口或某个位置的温度)。在构建Voronoi图之后,我将对其执行位置查询,并且我需要能够从查询结果中恢复这些非几何信息。CGAL似乎有能力做到这一点;这将在Delaunay三角剖分的背景下进行讨论。但我不知道如何将此技术应用于Voronoi图。以下是我尝试过的,但编译失败:

已删除损坏的代码。请参阅下面的工作代码示例

问题的其余部分已删除,因为它涉及已删除、已损坏的代码。请参阅下面的工作代码示例

编辑1:修复了Slorio指出的错误,包括完整的编译器输出

编辑2:在一篇评论中,Fabri博士建议我从修改CGAL示例vd_2_point_location.cpp开始。按照他的建议,我在这里发布了一个工作代码。这是对vd_2_point_location.cpp的一个稍加修改的版本

// standard includes
#include <iostream>
#include <fstream>
#include <cassert>
// includes for defining the Voronoi diagram adaptor
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <CGAL/Voronoi_diagram_2.h>
#include <CGAL/Delaunay_triangulation_adaptation_traits_2.h>
#include <CGAL/Delaunay_triangulation_adaptation_policies_2.h>
// typedefs for defining the adaptor
typedef CGAL::Exact_predicates_inexact_constructions_kernel                  K;
typedef CGAL::Triangulation_vertex_base_with_info_2<int, K>                  VB;
typedef CGAL::Triangulation_data_structure_2<VB>                             TDS;
typedef CGAL::Delaunay_triangulation_2<K,TDS>                                DT;
typedef CGAL::Delaunay_triangulation_adaptation_traits_2<DT>                 AT;
typedef CGAL::Delaunay_triangulation_caching_degeneracy_removal_policy_2<DT> AP;
typedef CGAL::Voronoi_diagram_2<DT,AT,AP>                                    VD;
// typedef for the result type of the point location
typedef AT::Site_2                    Site_2;
typedef AT::Point_2                   Point_2;
typedef VD::Locate_result             Locate_result;
typedef VD::Vertex_handle             Vertex_handle;
typedef VD::Face_handle               Face_handle;
typedef VD::Halfedge_handle           Halfedge_handle;
typedef VD::Ccb_halfedge_circulator   Ccb_halfedge_circulator;
void print_endpoint(Halfedge_handle e, bool is_src) {
  std::cout << "\t";
  if ( is_src ) {
    if ( e->has_source() )  std::cout << e->source()->point() << std::endl;
    else  std::cout << "point at infinity" << std::endl;
  } else {
    if ( e->has_target() )  std::cout << e->target()->point() << std::endl;
    else  std::cout << "point at infinity" << std::endl;
  }
}
int main()
{
  std::ifstream ifs("data/data1.dt.cin");
  assert( ifs );
  VD vd;
  Site_2 t;
  int ctr=0;
  while ( ifs >> t ) { 
      Face_handle fh = vd.insert(t); // Add the site...
      fh->dual()->info() = ctr++;    // ...attach some info to it
  }
  ifs.close();
  assert( vd.is_valid() );
  std::ifstream ifq("data/queries1.dt.cin");
  assert( ifq );
  Point_2 p;
  while ( ifq >> p ) {
    std::cout << "Query point (" << p.x() << "," << p.y()
              << ") lies on a Voronoi " << std::flush;
    Locate_result lr = vd.locate(p);
    if ( Vertex_handle* v = boost::get<Vertex_handle>(&lr) ) {
      std::cout << "vertex." << std::endl;
      std::cout << "The Voronoi vertex is:" << std::endl;
      std::cout << "\t" << (*v)->point() << std::endl;
    } else if ( Halfedge_handle* e = boost::get<Halfedge_handle>(&lr) ) {
      std::cout << "edge." << std::endl;
      std::cout << "The source and target vertices "
                << "of the Voronoi edge are:" << std::endl;
      print_endpoint(*e, true);
      print_endpoint(*e, false);
    } else if ( Face_handle* f = boost::get<Face_handle>(&lr) ) {
      std::cout << "face." << std::endl;
      std::cout << "The info associated with this face is " 
                << (*f)->dual()->info() << std::endl;
      std::cout << "The vertices of the Voronoi face are"
                << " (in counterclockwise order):" << std::endl;
      Ccb_halfedge_circulator ec_start = (*f)->ccb();
      Ccb_halfedge_circulator ec = ec_start;
      do {
        print_endpoint(ec, false);
      } while ( ++ec != ec_start );
    }
    std::cout << std::endl;
  }
  ifq.close();
  return 0;
}
//标准包括
#包括
#包括
#包括
//包括用于定义Voronoi图适配器的
#包括
#包括
#包括
#包括
#包括
#包括
//用于定义适配器的typedef
typedef CGAL::精确谓词不精确结构内核K;
typedef CGAL::三角剖分(顶点、底面和信息)VB;
typedef CGAL::三角测量数据结构TDS;
typedef CGAL::Delaunay_三角剖分_2DT;
typedef CGAL::Delaunay_三角剖分_适应_特征_2 AT;
typedef CGAL::Delaunay_三角剖分_缓存_退化_删除_策略_2 AP;
typedef CGAL::Voronoi_图2 VD;
//点位置的结果类型的typedef
typedef AT::Site_2 Site_2;
typedef AT::Point_2 Point_2;
typedef VD::Locate_result Locate_result;
typedef VD::顶点句柄顶点句柄;
typedef VD::面\手柄面\手柄;
typedef VD::半边\手柄半边\手柄;
类型定义VD::Ccb_半边缘_循环器Ccb_半边缘_循环器;
无效打印\u端点(半边\u句柄e,布尔值为\u src){
std::cout有_source())std::cout source()->point()info()=ctr++;//…给它附加一些信息
}
ifs.close();
断言(vd.is_valid());
标准::ifstream ifq(“数据/查询1.dt.cin”);
断言(ifq);
点2 p;
而(ifq>>p){

std::cout什么是编译器错误?@tinkertime:编译器错误在示例代码中生成错误的那一行给出。我将在这里再次复制它:
vdtst.cxx:18:error:在“您至少需要添加
\include
\include
”之前需要初始值设定项。Slorio:您是正确的,但添加了“include”无法解决问题。我已修改我的问题,将缺少的#includes包含在内。您还缺少
#include
和一个
,在typedef
AP
之后。编译器错误是什么?@tinkertime:编译器错误在示例代码中生成错误的行中给出。我将在这里再次复制它:
 vdtst.cxx:18:错误:在“您至少需要添加
#include
#include
@slorio”之前应使用初始值设定项:您是对的,但是添加#include并不能解决问题。我已修改了我的问题,以包含缺少的#include。您还缺少
#include
和一个
edef
AP