1

NOTE: See edit at the bottom of this post for code that solves my problem.

I am constructing a Voronoi diagram in CGAL. Each site in my diagram has some non-geometric information associated with it (like the population of a city, or the temperature at a certain location). After I construct the Voronoi diagram, I will perform location queries on it, and I will need to be able to recover this non-geometric information from the query results. It seems that CGAL has the capability to do this; this is discussed for example here in the context of Delaunay triangulations. But I cannot figure out how to apply this technique for Voronoi diagrams. Here's what I tried, which fails to compile:

Broken code removed. See working code example below.

Remainder of question deleted, since it pertains to deleted, broken code. See working code example below.

EDIT 1: Fixed errors pointed pointed out by sloriot, and included complete compiler output.

EDIT 2: In a comment, Dr. Fabri suggested that I start by modifying the CGAL example vd_2_point_location.cpp. Following his advice, I here post a working code. This is a very lightly modified version of 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;
}
Ryan
  • 25
  • 6
  • whats the compiler error? – tinkertime Feb 03 '17 at 22:22
  • @tinkertime: The compiler error is given in the example code, at the line that generates the error. I'll reproduce it again here: `vdtst.cxx:18: error: expected initializer before ‘<’ token`. – Ryan Feb 03 '17 at 22:41
  • You at least need to add `#include ` and `#include ` – sloriot Feb 06 '17 at 07:27
  • @sloriot: You are correct, but adding the #includes does not resolve the problem. I have modified my question to include the missing #includes. – Ryan Feb 06 '17 at 19:19
  • You are also missing `#include ` and a `;` after the typedef `AP`. – sloriot Feb 07 '17 at 07:22
  • You should have added your include and the typedefs for the TDS to the example vd_2_point_location.cpp and it would have worked. And to access the info you have to write for example `vd.bounded_face()->dual()->info();` – Andreas Fabri Feb 07 '17 at 10:45
  • Dr. Fabri: your was an excellent suggestion and by following it I was able to quickly solve my problem. I modified my original question to include my working code. If you post your comment in the form of an answer, I will accept it. – Ryan Feb 08 '17 at 18:36

0 Answers0