문제

나는 수천 포인트의 2D Delaunay 삼각 측량을 계산하고 있습니다. 각 지점에는 x 및 y 좌표를 넘어서 더 많은 데이터가 있습니다. 따라서 다른 벡터에서 내 포인트 구조물에 액세스 할 수 있도록 각 점의 인덱스를 검색 할 수 있는지 궁금했습니다.

현재 Face_handle의 정점에 액세스 할 때 포인트 (예 : x, y 좌표) x, y 좌표 대신 ID (index)로 각 정점을 어떻게 반환 할 수 있습니까? 고맙습니다.

#include <vector>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Delaunay_triangulation_2<Kernel> Delaunay;
typedef Kernel::Point_2 Point;

void example() {

  std::vector<Point> points;
  points.push_back(Point(1,1)); //index 0
  points.push_back(Point(1,2)); //index 1
  points.push_back(Point(1,3)); //index 2
  points.push_back(Point(2,1)); //index 3
  points.push_back(Point(2,2)); //index 4
  points.push_back(Point(2,3)); //index 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;
  }
}

출력 (x, y 좌표) :

Triangle:   1 3 1 2 2 2
Vertex 0:   1 3
Triangle:   1 2 1 1 2 1
Vertex 0:   1 2
Triangle:   1 3 2 2 2 3
Vertex 0:   1 3
Triangle:   1 2 2 1 2 2
Vertex 0:   1 2

원하는 출력 (지수) :

Triangle:   2   1   4
Vertex 0:   2
Triangle:   1   0   3
Vertex 0:   1 
Triangle:   2   4   5
Vertex 0:   2
Triangle:   1   3   4
Vertex 0:   1
도움이 되었습니까?

해결책

삼각 측량의 정점에 정보를 첨부 할 수 있습니다. 예를 들어 인덱스를 추가하려면 (unsigned int) 다음을 수행 할 수 있습니다.

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <vector>

typedef CGAL::Exact_predicates_inexact_constructions_kernel            Kernel;
typedef CGAL::Triangulation_vertex_base_with_info_2<unsigned int, Kernel> Vb;
typedef CGAL::Triangulation_data_structure_2<Vb>                       Tds;
typedef CGAL::Delaunay_triangulation_2<Kernel, Tds>                    Delaunay;
typedef Kernel::Point_2                                                Point;

int main() {

  std::vector< std::pair<Point,unsigned> > 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;
  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top