CGAL - Retrieve Vertex Index After Delaunay Triangulation

后端 未结 1 1773
盖世英雄少女心
盖世英雄少女心 2020-12-14 13:22

I am computing the 2D delaunay triangulation of a few thousand points. Each point has more data associated with it beyond x and y coordinates. Therefore, I was wondering if

1条回答
  •  佛祖请我去吃肉
    2020-12-14 13:24

    You can attach any information to vertices in a triangulation. For example to add indices (unsigned int) you could do the following:

    #include 
    #include 
    #include 
    #include 
    
    typedef CGAL::Exact_predicates_inexact_constructions_kernel            Kernel;
    typedef CGAL::Triangulation_vertex_base_with_info_2 Vb;
    typedef CGAL::Triangulation_data_structure_2                       Tds;
    typedef CGAL::Delaunay_triangulation_2                    Delaunay;
    typedef Kernel::Point_2                                                Point;
    
    int main() {
    
      std::vector< std::pair > points;
      points.push_back( std::make_pair( Point(1,1), 0 ) );
      points.push_back( std::make_pair( Point(1,2), 1 ) );
      points.push_back( std::make_pair( Point(1,3), 2 ) );
      points.push_back( std::make_pair( Point(2,1), 3 ) );
      points.push_back( std::make_pair( Point(2,2), 4 ) );
      points.push_back( std::make_pair( Point(2,3), 5 ) );
    
      Delaunay triangulation;
      triangulation.insert(points.begin(),points.end());
    
      for(Delaunay::Finite_faces_iterator fit = triangulation.finite_faces_begin();
          fit != triangulation.finite_faces_end(); ++fit) {
    
        Delaunay::Face_handle face = fit;
        std::cout << "Triangle:\t" << triangulation.triangle(face) << std::endl;
        std::cout << "Vertex 0:\t" << triangulation.triangle(face)[0] << std::endl;
        std::cout << "Vertex 0:\t" << face->vertex(0)->info() << std::endl;
      }
    }
    

    0 讨论(0)
提交回复
热议问题