Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

ELabelInterface.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
36 #include <ogdf/basic/GraphList.h>
37 #include <ogdf/basic/basic.h>
38 #include <ogdf/uml/PlanRepUML.h>
39 
40 namespace 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 
47 enum class LabelType {
48  End1 = 0,
49  Mult1,
50  Name,
51  End2,
52  Mult2,
53  NumLabels
54 };
55 
56 enum 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
67 template<class coordType>
69 public:
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
115  EdgeLabel(const EdgeLabel& rhs) : m_usedLabels(rhs.m_usedLabels), m_edge(rhs.m_edge) {
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) {
129  m_usedLabels = rhs.m_usedLabels;
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) {
149  m_usedLabels |= rhs.m_usedLabels;
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 
193 private:
194  static const int m_numberLabelTypes = static_cast<int>(LabelType::NumLabels);
195 
196  //the positions of the labels
197  coordType m_xPos[m_numberLabelTypes];
198  coordType m_yPos[m_numberLabelTypes];
199 
200  //the input label sizes
201  coordType m_xSize[m_numberLabelTypes];
202  coordType m_ySize[m_numberLabelTypes];
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
217 template<class coordType>
219 public:
220  //constructor
221  explicit ELabelInterface(PlanRepUML& pru) {
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) {
230  setLabel(e, EdgeLabel<coordType>(e, 0));
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) {
243  setLabel(e, EdgeLabel<coordType>(e, 0));
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 
266 private:
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 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:72
GraphAttributes.h
Declaration of class GraphAttributes which extends a Graph by additional attributes.
ogdf::ELabelInterface
Definition: ELabelInterface.h:218
ogdf::ELabelInterface::ELabelInterface
ELabelInterface(GraphAttributes &uml)
Definition: ELabelInterface.h:235
ogdf::UsedLabels::lAll
@ lAll
Graph.h
Includes declaration of graph class.
ogdf::ELabelInterface::ELabelInterface
ELabelInterface(PlanRepUML &pru)
Definition: ELabelInterface.h:221
ogdf::EdgeLabel::getHeight
coordType getHeight(LabelType elt) const
Definition: ELabelInterface.h:182
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::EdgeLabel::usedLabel
int & usedLabel()
Definition: ELabelInterface.h:190
ogdf::LabelType
LabelType
Definition: ELabelInterface.h:47
ogdf::PlanRepUML
Planarized representation (of a connected component) of a UMLGraph; allows special handling of hierar...
Definition: PlanRepUML.h:55
ogdf::EdgeLabel::setY
void setY(LabelType elt, coordType y)
Definition: ELabelInterface.h:165
PlanRepUML.h
Declaration of class PlanRepUML.
ogdf::UsedLabels::Mult2
@ Mult2
ogdf::UsedLabels::Mult1
@ Mult1
ogdf::ELabelInterface::graph
GraphAttributes & graph()
Definition: ELabelInterface.h:247
ogdf::EdgeLabel::EdgeLabel
EdgeLabel(edge e, coordType w, coordType h, int usedLabels)
Definition: ELabelInterface.h:102
ogdf::UsedLabels
UsedLabels
Definition: ELabelInterface.h:56
ogdf::ELabelInterface::getHeight
coordType getHeight(edge e, LabelType elt)
Definition: ELabelInterface.h:259
ogdf::EdgeLabel::m_yPos
coordType m_yPos[m_numberLabelTypes]
Definition: ELabelInterface.h:198
ogdf::EdgeLabel::getX
coordType getX(LabelType elt) const
Definition: ELabelInterface.h:176
ogdf::EdgeLabel::operator|=
EdgeLabel & operator|=(const EdgeLabel &rhs)
Definition: ELabelInterface.h:142
ogdf::EdgeLabel::setHeight
void setHeight(LabelType elt, coordType h)
Definition: ELabelInterface.h:167
ogdf::LabelType::Mult2
@ Mult2
ogdf::GraphAttributes::constGraph
const Graph & constGraph() const
Returns a reference to the associated graph.
Definition: GraphAttributes.h:223
ogdf::EdgeLabel::m_usedLabels
int m_usedLabels
Definition: ELabelInterface.h:205
ogdf::EdgeLabel::m_edge
edge m_edge
Definition: ELabelInterface.h:208
ogdf::LabelType::NumLabels
@ NumLabels
the number of available labels at an edge
ogdf::UsedLabels::End2
@ End2
ogdf::ELabelInterface::m_minFeatDist
coordType m_minFeatDist
Definition: ELabelInterface.h:272
ogdf::LabelType::Name
@ Name
ogdf::EdgeLabel::m_ySize
coordType m_ySize[m_numberLabelTypes]
Definition: ELabelInterface.h:202
ogdf::ELabelInterface::getLabel
EdgeLabel< coordType > & getLabel(edge e)
Definition: ELabelInterface.h:255
ogdf::UsedLabels::End1
@ End1
GraphList.h
Decralation of GraphElement and GraphList classes.
ogdf::EdgeLabel::theEdge
edge theEdge() const
Definition: ELabelInterface.h:184
ogdf::EdgeLabel::operator=
EdgeLabel & operator=(const EdgeLabel &rhs)
Definition: ELabelInterface.h:127
ogdf::EdgeLabel::setWidth
void setWidth(LabelType elt, coordType w)
Definition: ELabelInterface.h:169
ogdf::ELabelInterface::m_distDefault
coordType m_distDefault
Definition: ELabelInterface.h:271
ogdf::EdgeLabel::addType
void addType(LabelType elt)
Definition: ELabelInterface.h:173
ogdf::EdgeLabel::getWidth
coordType getWidth(LabelType elt) const
Definition: ELabelInterface.h:180
ogdf::EdgeLabel::EdgeLabel
EdgeLabel(const EdgeLabel &rhs)
Definition: ELabelInterface.h:115
ogdf::ELabelInterface::m_labels
EdgeArray< EdgeLabel< coordType > > m_labels
Definition: ELabelInterface.h:267
ogdf::ELabelInterface::minFeatDist
coordType & minFeatDist()
Definition: ELabelInterface.h:262
ogdf::ELabelInterface::m_ug
GraphAttributes * m_ug
Definition: ELabelInterface.h:269
ogdf::ELabelInterface::distDefault
coordType & distDefault()
Definition: ELabelInterface.h:264
ogdf::EdgeLabel::EdgeLabel
EdgeLabel(edge e, coordType w[], coordType h[], int usedLabels=numberUsedLabels)
Definition: ELabelInterface.h:92
ogdf::ELabelInterface::addLabel
void addLabel(const edge &e, const EdgeLabel< coordType > &el)
Definition: ELabelInterface.h:252
ogdf::LabelType::End2
@ End2
ogdf::EdgeLabel::getY
coordType getY(LabelType elt) const
Definition: ELabelInterface.h:178
ogdf::EdgeLabel::~EdgeLabel
~EdgeLabel()
Definition: ELabelInterface.h:124
ogdf::LabelType::End1
@ End1
ogdf::Graph::edges
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:935
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::EdgeLabel::EdgeLabel
EdgeLabel()
Definition: ELabelInterface.h:73
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
ogdf::EdgeLabel::setX
void setX(LabelType elt, coordType x)
Definition: ELabelInterface.h:163
ogdf::EdgeLabel::m_xPos
coordType m_xPos[m_numberLabelTypes]
Definition: ELabelInterface.h:197
ogdf::ELabelInterface::getWidth
coordType getWidth(edge e, LabelType elt)
Definition: ELabelInterface.h:257
ogdf::LabelType::Mult1
@ Mult1
ogdf::randomNumber
int randomNumber(int low, int high)
Returns random integer between low and high (including).
ogdf::EdgeLabel::EdgeLabel
EdgeLabel(edge e, int usedLabels=numberUsedLabels)
Definition: ELabelInterface.h:79
ogdf::EdgeLabel::setEdge
void setEdge(edge e)
Definition: ELabelInterface.h:171
ogdf::EdgeLabel::m_xSize
coordType m_xSize[m_numberLabelTypes]
Definition: ELabelInterface.h:201
ogdf::UsedLabels::Name
@ Name
ogdf::EdgeLabel
Definition: ELabelInterface.h:68
ogdf::EdgeLabel::usedLabel
bool usedLabel(LabelType elt) const
Definition: ELabelInterface.h:186
ogdf::GraphCopyBase::original
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:105
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
ogdf::ELabelInterface::setLabel
void setLabel(const edge &e, const EdgeLabel< coordType > &el)
Definition: ELabelInterface.h:250