Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GLHelper.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// Some methods which help to draw certain geometrical objects in openGL
21/****************************************************************************/
22#pragma once
23#include <config.h>
24
25#include <vector>
26#include <utility>
30
31
32// ===========================================================================
33// class declarations
34// ===========================================================================
36
37
38// ===========================================================================
39// class definitions
40// ===========================================================================
47class GLHelper {
48
49public:
51 static const std::vector<std::pair<double, double> >& getCircleCoords();
52
54 static int angleLookup(double angleDeg);
55
57 static void pushMatrix();
58
60 static void popMatrix();
61
63 static void pushName(unsigned int name);
64
66 static void popName();
67
69 static int getMatrixCounter();
70
72 static void resetMatrixCounter();
73
75 static int getVertexCounter();
76
78 static void resetVertexCounter();
79
81 static void checkCounterMatrix();
82
84 static void checkCounterName();
85
92 static void drawFilledPoly(const PositionVector& v, bool close);
93
94
102 static void drawFilledPolyTesselated(const PositionVector& v, bool close);
103
112 static void drawRectangle(const Position& center, const double width, const double height);
113
124 static void drawBoxLine(const Position& beg, double rot,
125 double visLength, double width, double offset = 0);
126
127
138 static void drawBoxLine(const Position& beg1, const Position& beg2,
139 double rot, double visLength, double width);
140
141
154 static void drawBoxLines(const PositionVector& geom,
155 const std::vector<double>& rots, const std::vector<double>& lengths,
156 double width, int cornerDetail = 0, double offset = 0);
157
171 static void drawBoxLines(const PositionVector& geom,
172 const std::vector<double>& rots, const std::vector<double>& lengths,
173 const std::vector<RGBColor>& cols,
174 double width, int cornerDetail = 0, double offset = 0);
175
176
188 static void drawBoxLines(const PositionVector& geom1,
189 const PositionVector& geom2,
190 const std::vector<double>& rots, const std::vector<double>& lengths,
191 double width);
192
193
203 static void drawBoxLines(const PositionVector& geom, double width);
204
205
214 static void drawLine(const Position& beg, double rot,
215 double visLength);
216
217
227 static void drawLine(const Position& beg1, const Position& beg2,
228 double rot, double visLength);
229
230
237 static void drawLine(const PositionVector& v);
238
239
248 static void drawLine(const PositionVector& v, const std::vector<RGBColor>& cols);
249
250
258 static void drawLine(const Position& beg, const Position& end);
259
266 static void drawFilledCircleDetailled(const GUIVisualizationSettings::Detail d, const double radius);
267
276 static void drawFilledCircleDetailled(const GUIVisualizationSettings::Detail d, const double radius,
277 double beg, double end);
278
286 static void drawFilledCircle(const double widradiusth, const int steps = 8);
287
297 static void drawFilledCircle(double radius, int steps,
298 double beg, double end);
299
300
309 static void drawOutlineCircle(double radius, double iRadius,
310 int steps = 8);
311
312
323 static void drawOutlineCircle(double radius, double iRadius,
324 int steps, double beg, double end);
325
326
335 static void drawTriangleAtEnd(const Position& p1, const Position& p2, double tLength,
336 double tWidth, const double extraOffset = 0);
337
339 static void setColor(const RGBColor& c);
340
342 static RGBColor getColor();
343
345 static double getTextWidth(const std::string& text, double size);
346
347 /* @brief draw Text with given parameters
348 * when width is not given (negative) the font is scaled proportionally in
349 * height and width according to size.
350 *
351 * align: see foreign/fontstash/fontstash.h for flags
352 */
353 static void drawText(const std::string& text, const Position& pos,
354 const double layer, const double size,
355 const RGBColor& col = RGBColor::BLACK,
356 const double angle = 0,
357 const int align = 0,
358 double width = -1);
359
360 static void drawTextSettings(
361 const GUIVisualizationTextSettings& settings,
362 const std::string& text, const Position& pos,
363 const double scale,
364 const double angle = 0,
365 const double layer = 2048, // GLO_MAX
366 const int align = 0); // centered
367
369 static void drawTextBox(const std::string& text, const Position& pos,
370 const double layer, const double size,
371 const RGBColor& txtColor = RGBColor::BLACK,
372 const RGBColor& bgColor = RGBColor::WHITE,
373 const RGBColor& borderColor = RGBColor::BLACK,
374 const double angle = 0,
375 const double relBorder = 0.05,
376 const double relMargin = 0.5,
377 const int align = 0);
378
380 static void drawTextAtEnd(const std::string& text, const PositionVector& shape, double x,
381 const GUIVisualizationTextSettings& settings, const double scale);
382
384 static void drawCrossTies(const PositionVector& geom,
385 const std::vector<double>& rots,
386 const std::vector<double>& lengths,
387 double length, double spacing, double halfWidth,
388 double offset, bool lessDetail);
389
391 static void drawInverseMarkings(const PositionVector& geom,
392 const std::vector<double>& rots,
393 const std::vector<double>& lengths,
394 double maxLength, double spacing,
395 double halfWidth, bool cl, bool cr, bool lefthand, double scale);
396
398 static void debugVertices(const PositionVector& shape, const GUIVisualizationTextSettings& settings, double scale, double layer = 1024);
399
401 static void drawBoundary(const GUIVisualizationSettings& s, const Boundary& b);
402
404 static void resetFont();
405
407 static void setGL2PS(bool active = true);
408
410 static void drawSpaceOccupancies(const double exaggeration, const Position& pos, const double rotation,
411 const double width, const double length, const bool vehicle);
412
413private:
415 static bool rightTurn(double angle1, double angle2);
416
418 static bool initFont();
419
421 static const std::vector<RGBColor>& getDottedcontourColors(const int size);
422
424 static int myMatrixCounter;
425
427 static int myVertexCounter;
428
431
433 static int myNameCounter;
434
436 static std::vector<std::pair<double, double> > myCircleCoords;
437
439 static struct FONScontext* myFont;
440 static double myFontSize;
441
443 static bool myGL2PSActive;
444
446 static std::vector<RGBColor> myDottedcontourColors;
447};
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
Some methods which help to draw certain geometrical objects in openGL.
Definition GLHelper.h:47
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition GLHelper.cpp:203
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition GLHelper.cpp:228
static void drawTextBox(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &txtColor=RGBColor::BLACK, const RGBColor &bgColor=RGBColor::WHITE, const RGBColor &borderColor=RGBColor::BLACK, const double angle=0, const double relBorder=0.05, const double relMargin=0.5, const int align=0)
draw Text box with given parameters
Definition GLHelper.cpp:804
static void resetVertexCounter()
reset vertex counter
Definition GLHelper.cpp:175
static std::vector< std::pair< double, double > > myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
Definition GLHelper.h:436
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition GLHelper.cpp:438
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:654
static void drawOutlineCircle(double radius, double iRadius, int steps=8)
Draws an unfilled circle around (0,0)
Definition GLHelper.cpp:596
static struct FONScontext * myFont
Font context.
Definition GLHelper.h:439
static void drawTriangleAtEnd(const Position &p1, const Position &p2, double tLength, double tWidth, const double extraOffset=0)
Draws a triangle at the end of the given line.
Definition GLHelper.cpp:629
static void drawTextAtEnd(const std::string &text, const PositionVector &shape, double x, const GUIVisualizationTextSettings &settings, const double scale)
draw text and the end of shape
Definition GLHelper.cpp:838
static void resetFont()
to be called when the font context is invalidated
Definition GLHelper.cpp:671
static void pushName(unsigned int name)
push Name
Definition GLHelper.cpp:139
static void checkCounterMatrix()
check counter matrix (for debug purposes)
Definition GLHelper.cpp:181
static void drawFilledCircle(const double widradiusth, const int steps=8)
Draws a filled circle around (0,0)
Definition GLHelper.cpp:569
static const std::vector< RGBColor > & getDottedcontourColors(const int size)
get dotted contour colors (black and white). Vector will be automatically increased if current size i...
Definition GLHelper.cpp:736
static std::vector< RGBColor > myDottedcontourColors
static vector with a list of alternated black/white colors (used for contours)
Definition GLHelper.h:446
static int angleLookup(double angleDeg)
normalize angle for lookup in myCircleCoords
Definition GLHelper.cpp:105
static double getTextWidth(const std::string &text, double size)
get required width of text
Definition GLHelper.cpp:750
static int myMatrixCounter
matrix counter (for debug purposes)
Definition GLHelper.h:424
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition GLHelper.cpp:347
static int myMatrixCounterDebug
matrix counter (for debug purposes)
Definition GLHelper.h:430
static void drawBoundary(const GUIVisualizationSettings &s, const Boundary &b)
Draw a boundary (used for debugging)
Definition GLHelper.cpp:966
static RGBColor getColor()
gets the gl-color
Definition GLHelper.cpp:660
static int getMatrixCounter()
get matrix counter
Definition GLHelper.cpp:157
static void drawRectangle(const Position &center, const double width, const double height)
Draws a rectangle line.
Definition GLHelper.cpp:277
static const std::vector< std::pair< double, double > > & getCircleCoords()
Storage for precomputed sin/cos-values describing a circle.
Definition GLHelper.cpp:91
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:295
static void checkCounterName()
check counter name (for debug purposes)
Definition GLHelper.cpp:192
static void debugVertices(const PositionVector &shape, const GUIVisualizationTextSettings &settings, double scale, double layer=1024)
draw vertex numbers for the given shape (in a random color)
Definition GLHelper.cpp:953
static void drawFilledCircleDetailled(const GUIVisualizationSettings::Detail d, const double radius)
Draws a filled circle around (0,0) depending of level of detail.
Definition GLHelper.cpp:539
static void popName()
pop Name
Definition GLHelper.cpp:148
static bool rightTurn(double angle1, double angle2)
whether the road makes a right turn (or goes straight)
Definition GLHelper.cpp:334
static int myNameCounter
name counter
Definition GLHelper.h:433
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
static void setGL2PS(bool active=true)
set GL2PS
Definition GLHelper.cpp:678
static int getVertexCounter()
get vertex counter
Definition GLHelper.cpp:169
static void drawInverseMarkings(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double maxLength, double spacing, double halfWidth, bool cl, bool cr, bool lefthand, double scale)
@bried draw the space between markings (in road color)
Definition GLHelper.cpp:900
static bool myGL2PSActive
whether we are currently rendering for gl2ps
Definition GLHelper.h:443
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, const int align=0, double width=-1)
Definition GLHelper.cpp:756
static void drawSpaceOccupancies(const double exaggeration, const Position &pos, const double rotation, const double width, const double length, const bool vehicle)
draw
Definition GLHelper.cpp:684
static bool initFont()
init myFont
Definition GLHelper.cpp:722
static double myFontSize
Definition GLHelper.h:440
static int myVertexCounter
matrix counter (for debug purposes)
Definition GLHelper.h:427
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048, const int align=0)
Definition GLHelper.cpp:787
static void drawCrossTies(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double length, double spacing, double halfWidth, double offset, bool lessDetail)
draw crossties for railroads or pedestrian crossings
Definition GLHelper.cpp:857
static void resetMatrixCounter()
reset matrix counter
Definition GLHelper.cpp:163
Stores the information about how to visualize structures.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
static const RGBColor WHITE
Definition RGBColor.h:192
static const RGBColor BLACK
Definition RGBColor.h:193
struct FONScontext FONScontext
Definition fontstash.h:95