Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
CountCrossings.h
Go to the documentation of this file.
1
31#pragma once
32
33#ifdef OGDF_INCLUDE_CGAL
34
38
39namespace ogdf {
40namespace internal {
41namespace gcm {
42namespace geometry {
43template<typename Kernel>
45 unsigned int crossings = 0;
46 for (unsigned int i = 0; i + 1 < segments.size(); ++i) {
47 for (unsigned int j = i + 1; j < segments.size(); ++j) {
48 crossings += geometry::do_intersect_open(segments[i], segments[j]);
49 }
50 }
51
52 return crossings;
53}
54
55template<typename Kernel, typename Graph>
56int count_crossings(graph::GeometricDrawing<Kernel, Graph>& drawing) {
57 std::vector<LineSegment_t<Kernel>> segments;
58
59 for (auto e : drawing.get_graph().edges()) {
60 segments.push_back(drawing.get_segment(e));
61 }
63}
64
65template<typename Kernel, typename Graph>
66int count_crossings(graph::GeometricDrawing<Kernel, Graph>& d, typename Graph::Node& v) {
67 int cr = 0;
68 for (auto f : d.get_graph().edges()) {
69 for (auto e : d.get_graph().edges(v)) {
70 cr += (f != e) && geometry::do_intersect_open(d.get_segment(e), d.get_segment(f));
71 }
72 }
73 return cr;
74}
75
76template<typename Kernel, typename Graph>
77std::vector<int> count_crossings_vec(const graph::GeometricDrawing<Kernel, Graph>& d,
78 const typename Graph::Node& v) {
79 std::vector<int> cr(v->degree(), 0);
80
81 for (auto f : d.get_graph().edges()) {
82 unsigned int i = 0;
83 for (auto e : d.get_graph().edges(v)) {
84 cr[i] += (f != e) && geometry::do_intersect_open(d.get_segment(e), d.get_segment(f));
85 ++i;
86 }
87 }
88 return cr;
89}
90
91template<typename Kernel, typename Graph>
92int count_crossing_edges(graph::GeometricDrawing<Kernel, Graph>& d, typename Graph::Node& v) {
93 int cr = 0;
94 auto& g = d.get_graph();
95
96 for (auto f : g.edges()) {
97 bool counted = false;
98 for (auto e : g.edges(v)) {
99 if ((f != e) && !counted
100 && geometry::do_intersect_open(d.get_segment(e), d.get_segment(f))) {
101 ++cr;
102 counted = true;
103 }
104 }
105 }
106 return cr;
107}
108
109template<typename Kernel, typename Graph>
110int count_crossings(graph::GeometricDrawing<Kernel, Graph>& d, typename Graph::Edge& e) {
111 int cr = 0;
112 for (auto f : d.get_graph().edges()) {
113 cr += (f != e) && (f->commonNode(e) == nullptr)
114 && geometry::do_intersect_open(d.get_segment(e), d.get_segment(f));
115 }
116 return cr;
117}
118
119}
120}
121}
122}
123
124#endif
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.