CGAL::Voronoi_diagram_2 错误地四舍五入为整数
CGAL::Voronoi_diagram_2 rounding to integers incorrectly
我正在尝试使用以下代码从线段创建 Voronoi 图。
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Segment_Delaunay_graph_Linf_filtered_traits_2.h>
#include <CGAL/Segment_Delaunay_graph_Linf_2.h>
#include <CGAL/Voronoi_diagram_2.h>
#include <CGAL/Segment_Delaunay_graph_adaptation_traits_2.h>
#include <CGAL/Segment_Delaunay_graph_adaptation_policies_2.h>
using Traits=CGAL::Segment_Delaunay_graph_Linf_filtered_traits_2<CGAL::Exact_predicates_inexact_constructions_kernel>;
using DelaunayGraph=CGAL::Segment_Delaunay_graph_Linf_2<Traits>;
using AdaptationTraits=CGAL::Segment_Delaunay_graph_adaptation_traits_2<DelaunayGraph>;
using AdaptationPolicy=CGAL::Segment_Delaunay_graph_degeneracy_removal_policy_2<DelaunayGraph>;
using VoronoiDiagram=CGAL::Voronoi_diagram_2<DelaunayGraph,AdaptationTraits,AdaptationPolicy>;
using VoronoiSite=AdaptationTraits::Site_2;
using VoronoiPoint=VoronoiSite::Point_2;
int main(int argc, char** argv)
{
VoronoiDiagram vd;
VoronoiPoint pt0(0.0, 0.0), pt1(5.0, 0.0), pt2(2.0, 2.0), pt3(4.0, 4.0);
vd.insert(VoronoiSite::construct_site_2(pt0, pt1));
vd.insert(VoronoiSite::construct_site_2(pt2, pt3));
int c = 0;
for (auto it = vd.edges_begin(); it != vd.edges_end(); it++)
{
std::cout << "Edge #" << c++ << std::endl;
if (it->has_source())
std::cout << "\t" << it->source()->point();
else
std::cout << "\tInfinity";
std::cout << std::endl;
if (it->has_target())
std::cout << "\t" << it->target()->point();
else
std::cout << "\tInfinity";
std::cout << std::endl;
}
return 0;
}
输出以
开头
Edge #0
0 2
Infinity
Edge #1
6 2
Infinity
Edge #2
5 1.66667
Infinity
...
This is my custom visualization of what it looks like.
我希望边 #1 是与 (4, 4) 和 (5, 0) 等距的边,但是点 (6, 2) 与这两个点不等距。我预计该点大致为 (5.7, 2.3)。
根据边 2,我知道所有数字都不是整数,但似乎其中一些数字被四舍五入了。明确地说,我很可能缺乏一些非常基本的 CGAL/Kernel 知识。我尝试在 Cartesian<double>
内核中交换,但这并没有改变结果。
为了跟进 Marc 的评论,我需要更改顶部的定义。有效的结果是
#include <iostream>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Segment_Delaunay_graph_filtered_traits_2.h>
#include <CGAL/Segment_Delaunay_graph_2.h>
#include <CGAL/Voronoi_diagram_2.h>
#include <CGAL/Segment_Delaunay_graph_adaptation_traits_2.h>
#include <CGAL/Segment_Delaunay_graph_adaptation_policies_2.h>
using CartesianKernel=CGAL::Simple_cartesian<double>;
using Traits=CGAL::Segment_Delaunay_graph_filtered_traits_2<CartesianKernel,CGAL::Field_with_sqrt_tag>;
using DelaunayGraph=CGAL::Segment_Delaunay_graph_2<Traits>;
using AdaptationTraits=CGAL::Segment_Delaunay_graph_adaptation_traits_2<DelaunayGraph>;
using AdaptationPolicy=CGAL::Segment_Delaunay_graph_degeneracy_removal_policy_2<DelaunayGraph>;
using VoronoiDiagram=CGAL::Voronoi_diagram_2<DelaunayGraph,AdaptationTraits,AdaptationPolicy>;
using VoronoiSite=AdaptationTraits::Site_2;
using VoronoiPoint=VoronoiSite::Point_2;
我正在尝试使用以下代码从线段创建 Voronoi 图。
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Segment_Delaunay_graph_Linf_filtered_traits_2.h>
#include <CGAL/Segment_Delaunay_graph_Linf_2.h>
#include <CGAL/Voronoi_diagram_2.h>
#include <CGAL/Segment_Delaunay_graph_adaptation_traits_2.h>
#include <CGAL/Segment_Delaunay_graph_adaptation_policies_2.h>
using Traits=CGAL::Segment_Delaunay_graph_Linf_filtered_traits_2<CGAL::Exact_predicates_inexact_constructions_kernel>;
using DelaunayGraph=CGAL::Segment_Delaunay_graph_Linf_2<Traits>;
using AdaptationTraits=CGAL::Segment_Delaunay_graph_adaptation_traits_2<DelaunayGraph>;
using AdaptationPolicy=CGAL::Segment_Delaunay_graph_degeneracy_removal_policy_2<DelaunayGraph>;
using VoronoiDiagram=CGAL::Voronoi_diagram_2<DelaunayGraph,AdaptationTraits,AdaptationPolicy>;
using VoronoiSite=AdaptationTraits::Site_2;
using VoronoiPoint=VoronoiSite::Point_2;
int main(int argc, char** argv)
{
VoronoiDiagram vd;
VoronoiPoint pt0(0.0, 0.0), pt1(5.0, 0.0), pt2(2.0, 2.0), pt3(4.0, 4.0);
vd.insert(VoronoiSite::construct_site_2(pt0, pt1));
vd.insert(VoronoiSite::construct_site_2(pt2, pt3));
int c = 0;
for (auto it = vd.edges_begin(); it != vd.edges_end(); it++)
{
std::cout << "Edge #" << c++ << std::endl;
if (it->has_source())
std::cout << "\t" << it->source()->point();
else
std::cout << "\tInfinity";
std::cout << std::endl;
if (it->has_target())
std::cout << "\t" << it->target()->point();
else
std::cout << "\tInfinity";
std::cout << std::endl;
}
return 0;
}
输出以
开头Edge #0
0 2
Infinity
Edge #1
6 2
Infinity
Edge #2
5 1.66667
Infinity
...
This is my custom visualization of what it looks like.
我希望边 #1 是与 (4, 4) 和 (5, 0) 等距的边,但是点 (6, 2) 与这两个点不等距。我预计该点大致为 (5.7, 2.3)。
根据边 2,我知道所有数字都不是整数,但似乎其中一些数字被四舍五入了。明确地说,我很可能缺乏一些非常基本的 CGAL/Kernel 知识。我尝试在 Cartesian<double>
内核中交换,但这并没有改变结果。
为了跟进 Marc 的评论,我需要更改顶部的定义。有效的结果是
#include <iostream>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Segment_Delaunay_graph_filtered_traits_2.h>
#include <CGAL/Segment_Delaunay_graph_2.h>
#include <CGAL/Voronoi_diagram_2.h>
#include <CGAL/Segment_Delaunay_graph_adaptation_traits_2.h>
#include <CGAL/Segment_Delaunay_graph_adaptation_policies_2.h>
using CartesianKernel=CGAL::Simple_cartesian<double>;
using Traits=CGAL::Segment_Delaunay_graph_filtered_traits_2<CartesianKernel,CGAL::Field_with_sqrt_tag>;
using DelaunayGraph=CGAL::Segment_Delaunay_graph_2<Traits>;
using AdaptationTraits=CGAL::Segment_Delaunay_graph_adaptation_traits_2<DelaunayGraph>;
using AdaptationPolicy=CGAL::Segment_Delaunay_graph_degeneracy_removal_policy_2<DelaunayGraph>;
using VoronoiDiagram=CGAL::Voronoi_diagram_2<DelaunayGraph,AdaptationTraits,AdaptationPolicy>;
using VoronoiSite=AdaptationTraits::Site_2;
using VoronoiPoint=VoronoiSite::Point_2;