[英]Edges of CGAL hyperbolic Delaunay triangulation
我正在嘗試使用 CGAL 進行雙曲 Delaunay 三角剖分。 下面是我的代碼。 Rcpp
是一個將 C++ 與 R 結合使用的庫。
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Hyperbolic_Delaunay_triangulation_2.h>
#include <CGAL/Hyperbolic_Delaunay_triangulation_traits_2.h>
#include <CGAL/Triangulation_vertex_base_with_id_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Hyperbolic_Delaunay_triangulation_traits_2<K> HDtt;
typedef HDtt::Point_2 HPoint;
typedef CGAL::Triangulation_data_structure_2<
CGAL::Triangulation_vertex_base_with_id_2<HDtt>,
CGAL::Hyperbolic_triangulation_face_base_2<HDtt>>
HTds;
typedef CGAL::Hyperbolic_Delaunay_triangulation_2<HDtt, HTds> HDt;
Rcpp::IntegerMatrix htest(const Rcpp::NumericMatrix points) {
std::vector<HPoint> hpts;
const unsigned npoints = points.ncol();
hpts.reserve(npoints);
for(unsigned i = 0; i != npoints; i++) {
const Rcpp::NumericVector pt = points(Rcpp::_, i);
hpts.emplace_back(HPoint(pt(0), pt(1)));
}
HDt hdt;
hdt.insert(hpts.begin(), hpts.end());
const size_t nedges = hdt.number_of_hyperbolic_edges();
Rcpp::IntegerMatrix Edges(2, nedges);
size_t i = 0;
for(HDt::All_edges_iterator ed = hdt.all_edges_begin();
ed != hdt.all_edges_end(); ++ed) {
Rcpp::IntegerVector edge_i(2);
HDt::Vertex_handle sVertex = ed->first->vertex(HDt::cw(ed->second));
edge_i(0) = sVertex->id();
HDt::Vertex_handle tVertex = ed->first->vertex(HDt::ccw(ed->second));
edge_i(1) = tVertex->id();
Edges(Rcpp::_, i) = edge_i;
i++;
}
return Edges;
}
我用單位圓中的一些點來提供這個函數。 然后它返回一個整數矩陣,它應該是邊,但是我得到的矩陣的所有條目都等於一個巨大的整數。 我還嘗試std::cout << sVertex->id()
並打印了這個巨大的整數。
存在孤立邊是因為作者選擇過濾掉外接圓“不緊湊”的三角形(即,它不包含在龐加萊圓盤中)。
參見用戶手冊https://doc.cgal.org/latest/Hyperbolic_triangulation_2/index.html#HT2_Euclidean_and_hyperbolic_Delaunay_triangulations “如果外接圓包含在 ℍ2 中,則歐幾里德 Delaunay 面是雙曲線的。”
更多詳情: https ://jocg.org/index.php/jocg/article/view/2926
好的,我找到了方法。 必須設置 id,它們沒有設置,這就是為什么我得到一個巨大的整數。 還必須取三角剖分的頂點,因為雖然這些頂點與輸入頂點相同,但它們的順序不同。
......
HDt hdt;
hdt.insert(hpts.begin(), hpts.end());
Rcpp::NumericMatrix Vertices(2, npoints);
int index = 0;
for(HDt::All_vertices_iterator vd = hdt.all_vertices_begin();
vd != hdt.all_vertices_end(); ++vd){
vd->id() = index;
HPoint pt = vd->point();
Vertices(0, index) = pt.x();
Vertices(1, index) = pt.y();
index++;
}
......
但是我不知道為什么會有一個孤立的邊緣:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.