Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ELabelInterface.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Graph.h>
37#include <ogdf/basic/basic.h>
38#include <ogdf/uml/PlanRepUML.h>
39
40namespace ogdf {
41
42// the available labels
43// the five basic labels are not allowed to be changed,
44// cause they have a special meaning/position, insert
45// other labels between mult1/End2
46
47enum class LabelType {
48 End1 = 0,
49 Mult1,
50 Name,
51 End2,
52 Mult2,
54};
55
56enum class UsedLabels {
57 End1 = (1 << static_cast<int>(LabelType::End1)), // 1
58 Mult1 = (1 << static_cast<int>(LabelType::Mult1)), // 2
59 Name = (1 << static_cast<int>(LabelType::Name)), // 4
60 End2 = (1 << static_cast<int>(LabelType::End2)), // 8
61 Mult2 = (1 << static_cast<int>(LabelType::Mult2)), // 16
62 lAll = (1 << static_cast<int>(LabelType::NumLabels)) - 1, // 31
63};
64
65// the basic single label defining class
66// holds info about all labels for one edge
67template<class coordType>
68class EdgeLabel {
69public:
70 static const int numberUsedLabels = static_cast<int>(UsedLabels::lAll);
71
72 //construction and destruction
74 m_edge = nullptr;
75 m_usedLabels = 0;
76 }
77
78 //bit pattern 2^labelenumpos bitwise
79 explicit EdgeLabel(edge e, int usedLabels = numberUsedLabels)
80 : m_usedLabels(usedLabels), m_edge(e) {
81 for (int i = 0; i < m_numberLabelTypes; i++) {
82 //zu testzwecken randoms
83 m_xSize[i] = double(randomNumber(5, 13)) / 50.0; //1
84 m_ySize[i] = double(randomNumber(3, 7)) / 50.0; //1
85
86 m_xPos[i] = 0;
87 m_yPos[i] = 0;
88 }
89 }
90
91 // Construction with specification of label sizes in arrays of length labelnum
92 EdgeLabel(edge e, coordType w[], coordType h[], int usedLabels = numberUsedLabels)
93 : m_usedLabels(usedLabels), m_edge(e) {
94 for (int i = 0; i < m_numberLabelTypes; i++) {
95 m_xSize[i] = w[i];
96 m_ySize[i] = h[i];
97 m_xPos[i] = 0;
98 m_yPos[i] = 0;
99 }
100 }
101
102 EdgeLabel(edge e, coordType w, coordType h, int usedLabels)
103 : m_usedLabels(usedLabels), m_edge(e) {
104 for (int i = 0; i < m_numberLabelTypes; i++) {
105 if (m_usedLabels & (1 << i)) {
106 m_xPos[i] = 0.0;
107 m_yPos[i] = 0.0;
108 m_xSize[i] = w;
109 m_ySize[i] = h;
110 }
111 }
112 }
113
114 //copy constructor
116 for (int i = 0; i < m_numberLabelTypes; i++) {
117 m_xPos[i] = rhs.m_xPos[i];
118 m_yPos[i] = rhs.m_yPos[i];
119 m_xSize[i] = rhs.m_xSize[i];
120 m_ySize[i] = rhs.m_ySize[i];
121 }
122 }
123
125
126 //assignment
128 if (this != &rhs) {
130 m_edge = rhs.m_edge;
131 int i;
132 for (i = 0; i < m_numberLabelTypes; i++) {
133 m_xPos[i] = rhs.m_xPos[i];
134 m_yPos[i] = rhs.m_yPos[i];
135 m_xSize[i] = rhs.m_xSize[i];
136 m_ySize[i] = rhs.m_ySize[i];
137 }
138 }
139 return *this;
140 }
141
143 if (m_edge) {
144 OGDF_ASSERT(m_edge == rhs.m_edge);
145 } else {
146 m_edge = rhs.m_edge;
147 }
148 if (this != &rhs) {
150 for (int i = 0; i < m_numberLabelTypes; i++) {
151 if (rhs.m_usedLabels & (1 << i)) {
152 m_xPos[i] = rhs.m_xPos[i];
153 m_yPos[i] = rhs.m_yPos[i];
154 m_xSize[i] = rhs.m_xSize[i];
155 m_ySize[i] = rhs.m_ySize[i];
156 }
157 }
158 }
159 return *this;
160 }
161
162 //set
163 void setX(LabelType elt, coordType x) { m_xPos[static_cast<int>(elt)] = x; }
164
165 void setY(LabelType elt, coordType y) { m_yPos[static_cast<int>(elt)] = y; }
166
167 void setHeight(LabelType elt, coordType h) { m_ySize[static_cast<int>(elt)] = h; }
168
169 void setWidth(LabelType elt, coordType w) { m_xSize[static_cast<int>(elt)] = w; }
170
171 void setEdge(edge e) { m_edge = e; }
172
173 void addType(LabelType elt) { m_usedLabels |= (1 << static_cast<int>(elt)); }
174
175 //get
176 coordType getX(LabelType elt) const { return m_xPos[static_cast<int>(elt)]; }
177
178 coordType getY(LabelType elt) const { return m_yPos[static_cast<int>(elt)]; }
179
180 coordType getWidth(LabelType elt) const { return m_xSize[static_cast<int>(elt)]; }
181
182 coordType getHeight(LabelType elt) const { return m_ySize[static_cast<int>(elt)]; }
183
184 edge theEdge() const { return m_edge; }
185
186 bool usedLabel(LabelType elt) const {
187 return (m_usedLabels & (1 << static_cast<int>(elt))) > 0;
188 }
189
190 int& usedLabel() { return m_usedLabels; }
191
192
193private:
194 static const int m_numberLabelTypes = static_cast<int>(LabelType::NumLabels);
195
196 //the positions of the labels
199
200 //the input label sizes
203
204 //which labels have to be placed bit pattern 2^labelenumpos bitwise
205 int m_usedLabels; //1 = only name, 5 = name and end2, ...
206
207 //the edge of heaven
209
210 //the label text
211#if 0
212 string m_string;
213#endif
214};
215
216//Interface to algorithm
217template<class coordType>
219public:
220 //constructor
222 //the PRU should not work with real world data but with
223 //normalized integer values
224 m_distDefault = 2;
225 m_minFeatDist = 1;
226 m_labels.init(pru.original());
227 m_ug = nullptr;
228
229 for (edge e : pru.original().edges) {
231 }
232 }
233
234 //constructor on GraphAttributes
235 explicit ELabelInterface(GraphAttributes& uml) : m_ug(&uml) {
236 //the GraphAttributes should work on real world data,
237 //which can be floats or ints
238 m_distDefault = 0.002;
239 m_minFeatDist = 0.003;
240 m_labels.init(uml.constGraph());
241
242 for (edge e : uml.constGraph().edges) {
244 }
245 }
246
247 GraphAttributes& graph() { return *m_ug; }
248
249 //set new EdgeLabel
250 void setLabel(const edge& e, const EdgeLabel<coordType>& el) { m_labels[e] = el; }
251
252 void addLabel(const edge& e, const EdgeLabel<coordType>& el) { m_labels[e] |= el; }
253
254 //get info about current EdgeLabel
256
257 coordType getWidth(edge e, LabelType elt) { return m_labels[e].getWidth(elt); }
258
259 coordType getHeight(edge e, LabelType elt) { return m_labels[e].getHeight(elt); }
260
261 //get general information
262 coordType& minFeatDist() { return m_minFeatDist; }
263
264 coordType& distDefault() { return m_distDefault; }
265
266private:
267 EdgeArray<EdgeLabel<coordType>> m_labels; //holds all labels for original edges
268 //the base graph
270
271 coordType m_distDefault; //default distance label/edge for positioner
272 coordType m_minFeatDist; //min Distance label/feature in candidate posit.
273};
274
275}
Includes declaration of graph class.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Decralation of GraphElement and GraphList classes.
Declaration of class PlanRepUML.
Basic declarations, included by all source files.
GraphAttributes * m_ug
void setLabel(const edge &e, const EdgeLabel< coordType > &el)
ELabelInterface(GraphAttributes &uml)
GraphAttributes & graph()
coordType getWidth(edge e, LabelType elt)
coordType getHeight(edge e, LabelType elt)
void addLabel(const edge &e, const EdgeLabel< coordType > &el)
EdgeLabel< coordType > & getLabel(edge e)
EdgeArray< EdgeLabel< coordType > > m_labels
ELabelInterface(PlanRepUML &pru)
Class for the representation of edges.
Definition Graph_d.h:364
coordType m_xSize[m_numberLabelTypes]
void addType(LabelType elt)
EdgeLabel(edge e, coordType w, coordType h, int usedLabels)
coordType getWidth(LabelType elt) const
void setX(LabelType elt, coordType x)
coordType getHeight(LabelType elt) const
EdgeLabel & operator=(const EdgeLabel &rhs)
EdgeLabel(edge e, coordType w[], coordType h[], int usedLabels=numberUsedLabels)
void setWidth(LabelType elt, coordType w)
edge theEdge() const
EdgeLabel(const EdgeLabel &rhs)
coordType getY(LabelType elt) const
coordType m_xPos[m_numberLabelTypes]
EdgeLabel & operator|=(const EdgeLabel &rhs)
void setY(LabelType elt, coordType y)
EdgeLabel(edge e, int usedLabels=numberUsedLabels)
void setEdge(edge e)
coordType m_ySize[m_numberLabelTypes]
static const int numberUsedLabels
bool usedLabel(LabelType elt) const
coordType m_yPos[m_numberLabelTypes]
coordType getX(LabelType elt) const
static const int m_numberLabelTypes
void setHeight(LabelType elt, coordType h)
Stores additional attributes of a graph (like layout information).
const Graph & constGraph() const
Returns a reference to the associated graph.
virtual void init(const Graph &G, long attr)
Initializes the graph attributes for graph G.
const Graph & original() const
Returns a reference to the original graph.
Definition GraphCopy.h:104
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition Graph_d.h:932
Planarized representation (of a connected component) of a UMLGraph; allows special handling of hierar...
Definition PlanRepUML.h:55
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
int randomNumber(int low, int high)
Returns random integer between low and high (including).
The namespace for all OGDF objects.
@ NumLabels
the number of available labels at an edge