Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

CountCrossings.h
Go to the documentation of this file.
1 
31 #pragma once
32 
33 #ifdef OGDF_INCLUDE_CGAL
34 
38 
39 namespace ogdf {
40 namespace internal {
41 namespace gcm {
42 namespace geometry {
43 template<typename Kernel>
44 int count_crossings(std::vector<LineSegment_t<Kernel>>& segments) {
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 
55 template<typename Kernel, typename Graph>
56 int 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  }
62  return count_crossings(segments);
63 }
64 
65 template<typename Kernel, typename Graph>
66 int 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 
76 template<typename Kernel, typename Graph>
77 std::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 
91 template<typename Kernel, typename Graph>
92 int 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 
109 template<typename Kernel, typename Graph>
110 int 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
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
OGDFVector.h
LineSegment.h
GeometricDrawing.h