33 #ifdef OGDF_INCLUDE_CGAL
45 template<
typename Kernel,
typename Graph,
typename CRegion = CrossingMinimalRegion<Kernel, Graph>>
46 class CrossingMinimalPositionRnd {
48 using Point = geometry::Point_t<Kernel>;
49 using Segment = geometry::LineSegment_t<Kernel>;
50 using Polygon = geometry::Polygon_t<Kernel>;
51 using Drawing = graph::GeometricDrawing<Kernel, Graph>;
52 using Node =
typename Graph::Node;
53 using Edge =
typename Graph::Edge;
56 static Point compute(
const Drawing& d,
const Node& v,
const std::vector<Edge>& sample,
57 const unsigned int random_draws,
const unsigned int neighbor_threshold,
58 geometry::Rectangle_t<Kernel>& rect_box,
61 std::mt19937_64& rnd) {
62 unsigned int dump_a, dump_b;
64 std::vector<Node> neighbors;
65 for (Node u : d.get_graph().neighbors(v)) {
66 neighbors.push_back(u);
69 std::shuffle(neighbors.begin(), neighbors.end(), rnd);
71 std::vector<Node> current;
74 Point p = d.get_point(v);
75 auto count = [&](
Point p_v) {
76 unsigned int n_cr = 0;
77 for (
auto edge : d.get_graph().edges()) {
79 Segment s = d.get_segment(
edge);
80 for (
auto u : d.get_graph().neighbors(v)) {
82 Segment s_f(p_v, d.get_point(u));
83 n_cr += CGAL::do_intersect(s, s_f);
91 unsigned int min_cr = count(p);
93 for (
size_t i = 0; i < neighbors.size(); i = i + neighbor_threshold) {
96 neighbors.begin() + std::min(i + neighbor_threshold, neighbors.size()),
97 std::back_inserter(current));
101 auto region = cr.compute(d, v, current, sample, rect_box, dump_a, dump_b);
103 OGDF_ASSERT(!CGAL::is_zero(CGAL::abs(region.area())));
105 if (geometry::is_clockwise(region)) {
109 if (region.size() > 2) {
110 for (
unsigned int x = 0; x < random_draws; ++x) {
111 Point p_v = geometry::random_point_in_polygon(region, rnd);
112 unsigned int n_cr = count(p_v);
122 cr.build_bd(d, v, current, sample, rect_box, dump_a, dump_b);
124 auto rnd_points = RandomPointsInCell<Kernel>::compute(cr.bd, cr.left_to_right_cost,
125 d.get_point(v), random_draws, rnd);
127 for (
auto p_v : rnd_points) {
128 unsigned int n_cr = count(p_v);
139 p =
Point(CGAL::to_double(p.x()), CGAL::to_double(p.y()));