Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
graphics.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Logger.h>
35#include <ogdf/basic/basic.h>
36
37#include <map>
38#include <typeinfo>
39
40namespace ogdf {
41
43
46enum class StrokeType : unsigned char {
47 None,
48 Solid,
49 Dash,
50 Dot,
51 Dashdot,
53};
54
56OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const StrokeType& st);
57
59
63
65
68enum class StrokeLineCap : unsigned char { Butt, Round, Square };
69
70
72
75enum class StrokeLineJoin : unsigned char { Miter, Round, Bevel };
76
77
79
82enum class FillPattern {
83 None,
84 Solid,
85 Dense1,
86 Dense2,
87 Dense3,
88 Dense4,
89 Dense5,
90 Dense6,
91 Dense7,
94 Cross,
98};
99
101
103OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const FillPattern& fp);
104
106
110
111
113
116enum class Shape {
117 Rect,
119 Ellipse,
120 Triangle,
121 Pentagon,
122 Hexagon,
123 Octagon,
124 Rhomb,
125 Trapeze,
128 InvTrapeze,
130 Image
131};
132
134OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const Shape& shape);
135
136
138
141enum class EdgeArrow {
142 None,
143 Last,
144 First,
145 Both,
147};
148
150OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const EdgeArrow& ea);
151
153
161 uint8_t m_red, m_green, m_blue, m_alpha;
162
163public:
165 enum class Name {
166 Aliceblue,
167 Antiquewhite,
168 Aqua,
169 Aquamarine,
170 Azure,
171 Beige,
172 Bisque,
173 Black,
174 Blanchedalmond,
175 Blue,
176 Blueviolet,
177 Brown,
178 Burlywood,
179 Cadetblue,
180 Chartreuse,
181 Chocolate,
182 Coral,
183 Cornflowerblue,
184 Cornsilk,
185 Crimson,
186 Cyan,
187 Darkblue,
188 Darkcyan,
189 Darkgoldenrod,
190 Darkgray,
191 Darkgreen,
192 Darkgrey,
193 Darkkhaki,
194 Darkmagenta,
195 Darkolivegreen,
196 Darkorange,
197 Darkorchid,
198 Darkred,
199 Darksalmon,
200 Darkseagreen,
201 Darkslateblue,
202 Darkslategray,
203 Darkslategrey,
204 Darkturquoise,
205 Darkviolet,
206 Deeppink,
207 Deepskyblue,
208 Dimgray,
209 Dimgrey,
210 Dodgerblue,
211 Firebrick,
212 Floralwhite,
213 Forestgreen,
214 Fuchsia,
215 Gainsboro,
216 Ghostwhite,
217 Gold,
218 Goldenrod,
219 Gray,
220 Green,
221 Greenyellow,
222 Grey,
223 Honeydew,
224 Hotpink,
225 Indianred,
226 Indigo,
227 Ivory,
228 Khaki,
229 Lavender,
230 Lavenderblush,
231 Lawngreen,
232 Lemonchiffon,
233 Lightblue,
234 Lightcoral,
235 Lightcyan,
236 Lightgoldenrodyellow,
237 Lightgray,
238 Lightgreen,
239 Lightgrey,
240 Lightpink,
241 Lightsalmon,
242 Lightseagreen,
243 Lightskyblue,
244 Lightslategray,
245 Lightslategrey,
246 Lightsteelblue,
247 Lightyellow,
248 Lime,
249 Limegreen,
250 Linen,
251 Magenta,
252 Maroon,
253 Mediumaquamarine,
254 Mediumblue,
255 Mediumorchid,
256 Mediumpurple,
257 Mediumseagreen,
258 Mediumslateblue,
259 Mediumspringgreen,
260 Mediumturquoise,
261 Mediumvioletred,
262 Midnightblue,
263 Mintcream,
264 Mistyrose,
265 Moccasin,
266 Navajowhite,
267 Navy,
268 Oldlace,
269 Olive,
270 Olivedrab,
271 Orange,
272 Orangered,
273 Orchid,
274 Palegoldenrod,
275 Palegreen,
276 Paleturquoise,
277 Palevioletred,
278 Papayawhip,
279 Peachpuff,
280 Peru,
281 Pink,
282 Plum,
283 Powderblue,
284 Purple,
285 Red,
286 Rosybrown,
287 Royalblue,
288 Saddlebrown,
289 Salmon,
290 Sandybrown,
291 Seagreen,
292 Seashell,
293 Sienna,
294 Silver,
295 Skyblue,
296 Slateblue,
297 Slategray,
298 Slategrey,
299 Snow,
300 Springgreen,
301 Steelblue,
302 Tan,
303 Teal,
304 Thistle,
305 Tomato,
306 Turquoise,
307 Violet,
308 Wheat,
309 White,
310 Whitesmoke,
311 Yellow,
312 Yellowgreen
313 };
314
316 Color() : m_red(0), m_green(0), m_blue(0), m_alpha(255) { }
317
320 : m_red(r), m_green(g), m_blue(b), m_alpha(a) { }
321
323 Color(int r, int g, int b, int a = 255)
324 : m_red((uint8_t)r), m_green((uint8_t)g), m_blue((uint8_t)b), m_alpha((uint8_t)a) { }
325
328
330 Color(const string& str) { fromString(str); }
331
333 Color(const char* str) { fromString(string(str)); }
334
336 uint8_t red() const { return m_red; }
337
339 uint8_t green() const { return m_green; }
340
342 uint8_t blue() const { return m_blue; }
343
345 uint8_t alpha() const { return m_alpha; }
346
348 void red(uint8_t r) { m_red = r; }
349
351 void green(uint8_t g) { m_green = g; }
352
354 void blue(uint8_t b) { m_blue = b; }
355
357 void alpha(uint8_t a) { m_alpha = a; }
358
360
365 string toString() const;
366
368
374 bool fromString(const string& str);
375
377 bool operator==(const Color& c) const {
378 return m_red == c.m_red && m_green == c.m_green && m_blue == c.m_blue && m_alpha == c.m_alpha;
379 }
380
382 bool operator!=(const Color& c) const { return !operator==(c); }
383
385 friend std::ostream& operator<<(std::ostream& os, const Color& c) { return os << c.toString(); }
386};
387
389
394 float m_width;
398
400 : m_color(Color::Name::Black)
401 , m_width(1.0f)
402 , m_type(StrokeType::Solid)
403 , m_cap(StrokeLineCap::Butt)
404 , m_join(StrokeLineJoin::Miter) { }
405
407 : m_color(c)
408 , m_width(1.0f)
409 , m_type(StrokeType::Solid)
410 , m_cap(StrokeLineCap::Butt)
411 , m_join(StrokeLineJoin::Miter) { }
412};
413
415
422
424 : m_color(Color::Name::White), m_bgColor(Color::Name::Black), m_pattern(FillPattern::Solid) { }
425
426 Fill(Color c) : m_color(c), m_bgColor(Color::Name::Black), m_pattern(FillPattern::Solid) { }
427
429 : m_color(c), m_bgColor(Color::Name::Black), m_pattern(pattern) { }
430
432 : m_color(c), m_bgColor(bgColor), m_pattern(pattern) { }
433};
434
435namespace graphics {
436extern OGDF_EXPORT std::map<Shape, string> fromShape;
437extern OGDF_EXPORT std::map<string, Shape> toShape;
438
439extern OGDF_EXPORT std::map<StrokeType, string> fromStrokeType;
440extern OGDF_EXPORT std::map<string, StrokeType> toStrokeType;
441
442extern OGDF_EXPORT std::map<FillPattern, string> fromFillPattern;
443extern OGDF_EXPORT std::map<string, FillPattern> toFillPattern;
444
445template<class Enum>
446inline void init() {};
447
448template<class Enum>
449inline void initSecondMap(std::map<Enum, string>& fromMap, std::map<string, Enum>& toMap) {
450 for (auto it : fromMap) {
451 toMap.emplace(it.second, it.first);
452 }
453}
454
455template<>
456inline void init<StrokeType>() {
457 fromStrokeType.emplace(StrokeType::None, "None");
458 fromStrokeType.emplace(StrokeType::Solid, "Solid");
459 fromStrokeType.emplace(StrokeType::Dash, "Dash");
460 fromStrokeType.emplace(StrokeType::Dot, "Dot");
461 fromStrokeType.emplace(StrokeType::Dashdot, "Dashdot");
462 fromStrokeType.emplace(StrokeType::Dashdotdot, "Dashdotdot");
463
465}
466
467template<>
468inline void init<FillPattern>() {
469 fromFillPattern.emplace(FillPattern::None, "None");
470 fromFillPattern.emplace(FillPattern::Solid, "Solid");
471 fromFillPattern.emplace(FillPattern::Dense1, "Dense1");
472 fromFillPattern.emplace(FillPattern::Dense2, "Dense2");
473 fromFillPattern.emplace(FillPattern::Dense3, "Dense3");
474 fromFillPattern.emplace(FillPattern::Dense4, "Dense4");
475 fromFillPattern.emplace(FillPattern::Dense5, "Dense5");
476 fromFillPattern.emplace(FillPattern::Dense6, "Dense6");
477 fromFillPattern.emplace(FillPattern::Dense7, "Dense7");
478 fromFillPattern.emplace(FillPattern::Horizontal, "Horizontal");
479 fromFillPattern.emplace(FillPattern::Vertical, "Vertical");
480 fromFillPattern.emplace(FillPattern::Cross, "Cross");
481 fromFillPattern.emplace(FillPattern::BackwardDiagonal, "BackwardDiagonal");
482 fromFillPattern.emplace(FillPattern::ForwardDiagonal, "ForwardDiagonal");
483 fromFillPattern.emplace(FillPattern::DiagonalCross, "DiagonalCross");
484
486}
487
488template<>
489inline void init<Shape>() {
490 fromShape.emplace(Shape::Rect, "Rect");
491 fromShape.emplace(Shape::RoundedRect, "RoundedRect");
492 fromShape.emplace(Shape::Ellipse, "Ellipse");
493 fromShape.emplace(Shape::Triangle, "Triangle");
494 fromShape.emplace(Shape::Pentagon, "Pentagon");
495 fromShape.emplace(Shape::Hexagon, "Hexagon");
496 fromShape.emplace(Shape::Octagon, "Octagon");
497 fromShape.emplace(Shape::Rhomb, "Rhomb");
498 fromShape.emplace(Shape::Trapeze, "Trapeze");
499 fromShape.emplace(Shape::Parallelogram, "Parallelogram");
500 fromShape.emplace(Shape::InvTriangle, "InvTriangle");
501 fromShape.emplace(Shape::InvTrapeze, "InvTrapeze");
502 fromShape.emplace(Shape::InvParallelogram, "InvParallelogram");
503 fromShape.emplace(Shape::Image, "Image");
504
506 toShape.emplace("rectangle", Shape::Rect);
507 toShape.emplace("box", Shape::Image);
508}
509
510template<class ToClass>
511inline std::map<string, ToClass>* getMapToEnum() {
512 std::cout << "getMapToEnum was wrongly called\n";
513 OGDF_ASSERT(false);
514 return nullptr;
515};
516
517template<class FromClass>
518inline std::map<FromClass, string>* getMapToString() {
520 std::cout << "getMapToString was wrongly called " << typeid(fc).name() << "\n";
521 OGDF_ASSERT(false);
522 return nullptr;
523};
524
525template<>
526inline std::map<string, FillPattern>* getMapToEnum() {
527 return &toFillPattern;
528};
529
530template<>
531inline std::map<string, Shape>* getMapToEnum() {
532 return &toShape;
533};
534
535template<>
536inline std::map<string, StrokeType>* getMapToEnum() {
537 return &toStrokeType;
538};
539
540template<>
541inline std::map<FillPattern, string>* getMapToString() {
542 return &fromFillPattern;
543};
544
545template<>
546inline std::map<Shape, string>* getMapToString() {
547 return &fromShape;
548};
549
550template<>
551inline std::map<StrokeType, string>* getMapToString() {
552 return &fromStrokeType;
553};
554}
555
556template<class FromClass>
557inline string toString(FromClass key) {
558 auto* map = graphics::getMapToString<FromClass>();
559 if (map->empty()) {
560 graphics::init<FromClass>();
561 }
562 auto it = map->find(key);
563 OGDF_ASSERT(it != map->end());
564 return (*it).second;
565};
566
567template<class ToClass>
568inline ToClass fromString(string key) {
569 auto map = graphics::getMapToEnum<ToClass>();
570 if (map->empty()) {
571 graphics::init<ToClass>();
572 }
573 auto it = map->find(key);
574 if (it != map->end()) {
575 return (*it).second;
576 } else {
577 Logger::slout() << "Encountered invalid " << typeid((*map->begin()).second).name() << ": "
578 << key << " " << map->size() << " " << map->empty() << std::endl;
579 return static_cast<ToClass>(std::numeric_limits<int>::min());
580 }
581};
582}
Contains logging functionality.
Basic declarations, included by all source files.
Colors represented as RGBA values.
Definition graphics.h:160
Color(Color::Name name)
Creates a color from given color name name.
bool operator==(const Color &c) const
Returns true iff c and this color are equal in every component.
Definition graphics.h:377
uint8_t m_alpha
Definition graphics.h:161
Color(const char *str)
Crates a color from string str.
Definition graphics.h:333
uint8_t m_red
Definition graphics.h:161
uint8_t blue() const
Returns the blue component.
Definition graphics.h:342
void alpha(uint8_t a)
Sets the alpha channel to a.
Definition graphics.h:357
Name
Named colors (same as SVG color keywords).
Definition graphics.h:165
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Creates a color from given RGBA-values.
Definition graphics.h:319
uint8_t red() const
Returns the red component.
Definition graphics.h:336
uint8_t green() const
Returns the green component.
Definition graphics.h:339
bool operator!=(const Color &c) const
Returns true iff c and this color differ in any component.
Definition graphics.h:382
uint8_t m_blue
Definition graphics.h:161
Color(const string &str)
Crates a color from string str.
Definition graphics.h:330
void blue(uint8_t b)
Sets the blue component to b.
Definition graphics.h:354
void red(uint8_t r)
Sets the red component to r.
Definition graphics.h:348
uint8_t alpha() const
Returns the alpha channel.
Definition graphics.h:345
Color(int r, int g, int b, int a=255)
Creates a color from given RGBA-values.
Definition graphics.h:323
bool fromString(const string &str)
Sets this color to the color defined by str.
friend std::ostream & operator<<(std::ostream &os, const Color &c)
Writes the string representation of color c to output stream os.
Definition graphics.h:385
uint8_t m_green
Definition graphics.h:161
Color()
Creates an opaque black color.
Definition graphics.h:316
void green(uint8_t g)
Sets the green component to g.
Definition graphics.h:351
string toString() const
Converts the color to a string and returns it.
static std::ostream & slout(Level level=Level::Default)
stream for logging-output (global)
Definition Logger.h:167
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
StrokeType intToStrokeType(int i)
Converts integer i to stroke type.
StrokeLineJoin
Line join types of strokes.
Definition graphics.h:75
FillPattern
Fill patterns.
Definition graphics.h:82
FillPattern intToFillPattern(int i)
Converts integer i to fill pattern.
StrokeLineCap
Line cap types of strokes.
Definition graphics.h:68
StrokeType
Line types of strokes.
Definition graphics.h:46
Shape
Types for node shapes.
Definition graphics.h:116
EdgeArrow
Types for edge arrows.
Definition graphics.h:141
@ Dash
dashed line
@ Dashdotdot
line style "dash dot dot dash dot dot ..."
@ Dashdot
line style "dash dot dash dot ..."
@ Dot
dotted line
@ Solid
solid line
@ InvTrapeze
inverted trapeze (upper side longer)
@ Pentagon
pentagon
@ Ellipse
ellipse
@ Hexagon
hexagon
@ RoundedRect
rectangle with rounded corners
@ Octagon
octagon
@ Rhomb
rhomb (=diamond)
@ InvParallelogram
inverted parallelogram (slanted to the left)
@ Triangle
isosceles triangle (base side down)
@ Rect
rectangle
@ Trapeze
trapeze (upper side shorter)
@ Parallelogram
parallelogram (slanted to the right)
@ InvTriangle
isosceles triangle (base side up)
@ Both
edge arrow at target and source node of the edge
@ First
edge arrow at source node of the edge
@ Last
edge arrow at target node of the edge
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
int r[]
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
std::map< string, FillPattern > toFillPattern
void init< StrokeType >()
Definition graphics.h:456
void initSecondMap(std::map< Enum, string > &fromMap, std::map< string, Enum > &toMap)
Definition graphics.h:449
void init< FillPattern >()
Definition graphics.h:468
std::map< string, ToClass > * getMapToEnum()
Definition graphics.h:511
std::map< Shape, string > fromShape
std::map< FromClass, string > * getMapToString()
Definition graphics.h:518
std::map< FillPattern, string > fromFillPattern
void init< Shape >()
Definition graphics.h:489
std::map< StrokeType, string > fromStrokeType
std::map< string, Shape > toShape
std::map< string, StrokeType > toStrokeType
The namespace for all OGDF objects.
@ None
Two geometric objects do not intersect.
void initFillPatternHashing()
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:978
bool operator==(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Equality operator for 2-tuples.
Definition tuples.h:80
string toString(FromClass key)
Definition graphics.h:557
ToClass fromString(string key)
Definition graphics.h:568
Properties of fills.
Definition graphics.h:418
FillPattern m_pattern
fill pattern
Definition graphics.h:421
Fill(Color c, FillPattern pattern)
Definition graphics.h:428
Fill(Color c, Color bgColor, FillPattern pattern)
Definition graphics.h:431
Color m_color
fill color
Definition graphics.h:419
Fill(Color c)
Definition graphics.h:426
Color m_bgColor
background color of fill pattern
Definition graphics.h:420
Properties of strokes.
Definition graphics.h:392
float m_width
stroke width
Definition graphics.h:394
Color m_color
stroke color
Definition graphics.h:393
StrokeLineJoin m_join
line-join of the stroke
Definition graphics.h:397
StrokeType m_type
stroke type (e.g.
Definition graphics.h:395
StrokeLineCap m_cap
line-cap of the stroke
Definition graphics.h:396
Stroke(Color c)
Definition graphics.h:406