Eclipse SUMO - Simulation of Urban MObility
GLHelper.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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>
27 #include <utils/common/RGBColor.h>
30 
31 
32 // ===========================================================================
33 // class declarations
34 // ===========================================================================
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
47 class GLHelper {
48 
49 public:
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 
104 
115  static void drawBoxLine(const Position& beg, double rot,
116  double visLength, double width, double offset = 0);
117 
118 
129  static void drawBoxLine(const Position& beg1, const Position& beg2,
130  double rot, double visLength, double width);
131 
132 
145  static void drawBoxLines(const PositionVector& geom,
146  const std::vector<double>& rots, const std::vector<double>& lengths,
147  double width, int cornerDetail = 0, double offset = 0);
148 
162  static void drawBoxLines(const PositionVector& geom,
163  const std::vector<double>& rots, const std::vector<double>& lengths,
164  const std::vector<RGBColor>& cols,
165  double width, int cornerDetail = 0, double offset = 0);
166 
167 
179  static void drawBoxLines(const PositionVector& geom1,
180  const PositionVector& geom2,
181  const std::vector<double>& rots, const std::vector<double>& lengths,
182  double width);
183 
184 
194  static void drawBoxLines(const PositionVector& geom, double width);
195 
196 
205  static void drawLine(const Position& beg, double rot,
206  double visLength);
207 
208 
218  static void drawLine(const Position& beg1, const Position& beg2,
219  double rot, double visLength);
220 
221 
228  static void drawLine(const PositionVector& v);
229 
230 
239  static void drawLine(const PositionVector& v, const std::vector<RGBColor>& cols);
240 
241 
249  static void drawLine(const Position& beg, const Position& end);
250 
251 
259  static void drawFilledCircle(double width, int steps = 8);
260 
261 
271  static void drawFilledCircle(double width, int steps,
272  double beg, double end);
273 
274 
283  static void drawOutlineCircle(double width, double iwidth,
284  int steps = 8);
285 
286 
297  static void drawOutlineCircle(double width, double iwidth,
298  int steps, double beg, double end);
299 
300 
309  static void drawTriangleAtEnd(const Position& p1, const Position& p2, double tLength,
310  double tWidth, const double extraOffset = 0);
311 
313  static void setColor(const RGBColor& c);
314 
316  static RGBColor getColor();
317 
319  static double getTextWidth(const std::string& text, double size);
320 
321  /* @brief draw Text with given parameters
322  * when width is not given (negative) the font is scaled proportionally in
323  * height and width according to size.
324  *
325  * align: see foreign/fontstash/fontstash.h for flags
326  */
327  static void drawText(const std::string& text, const Position& pos,
328  const double layer, const double size,
329  const RGBColor& col = RGBColor::BLACK,
330  const double angle = 0,
331  const int align = 0,
332  double width = -1);
333 
334  static void drawTextSettings(
335  const GUIVisualizationTextSettings& settings,
336  const std::string& text, const Position& pos,
337  const double scale,
338  const double angle = 0,
339  const double layer = 2048, // GLO_MAX
340  const int align = 0); // centered
341 
343  static void drawTextBox(const std::string& text, const Position& pos,
344  const double layer, const double size,
345  const RGBColor& txtColor = RGBColor::BLACK,
346  const RGBColor& bgColor = RGBColor::WHITE,
347  const RGBColor& borderColor = RGBColor::BLACK,
348  const double angle = 0,
349  const double relBorder = 0.05,
350  const double relMargin = 0.5,
351  const int align = 0);
352 
354  static void drawTextAtEnd(const std::string& text, const PositionVector& shape, double x,
355  const GUIVisualizationTextSettings& settings, const double scale);
356 
358  static void drawCrossTies(const PositionVector& geom,
359  const std::vector<double>& rots,
360  const std::vector<double>& lengths,
361  double length, double spacing, double halfWidth, bool drawForSelection);
362 
364  static void drawInverseMarkings(const PositionVector& geom,
365  const std::vector<double>& rots,
366  const std::vector<double>& lengths,
367  double maxLength, double spacing,
368  double halfWidth, bool cl, bool cr, bool lefthand, double scale);
369 
371  static void debugVertices(const PositionVector& shape, const GUIVisualizationTextSettings& settings, double scale, double layer = 1024);
372 
374  static void drawBoundary(const Boundary& b);
375 
377  static void resetFont();
378 
380  static void setGL2PS(bool active = true);
381 
383  static void drawSpaceOccupancies(const double exaggeration, const Position& pos, const double rotation,
384  const double width, const double length, const bool vehicle);
385 
386 private:
388  static bool rightTurn(double angle1, double angle2);
389 
391  static bool initFont();
392 
394  static const std::vector<RGBColor>& getDottedcontourColors(const int size);
395 
397  static int myMatrixCounter;
398 
400  static int myVertexCounter;
401 
404 
406  static int myNameCounter;
407 
409  static std::vector<std::pair<double, double> > myCircleCoords;
410 
412  static struct FONScontext* myFont;
413  static double myFontSize;
414 
416  static bool myGL2PSActive;
417 
419  static std::vector<RGBColor> myDottedcontourColors;
420 };
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 drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:894
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:733
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:409
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:421
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:583
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:498
static struct FONScontext * myFont
Font context.
Definition: GLHelper.h:412
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:558
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:767
static void resetFont()
to be called when the font context is invalidated
Definition: GLHelper.cpp:600
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 drawOutlineCircle(double width, double iwidth, int steps=8)
Draws an unfilled circle around (0,0)
Definition: GLHelper.cpp:525
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:665
static std::vector< RGBColor > myDottedcontourColors
static vector with a list of alternated black/white colors (used for contours)
Definition: GLHelper.h:419
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:679
static int myMatrixCounter
matrix counter (for debug purposes)
Definition: GLHelper.h:397
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:329
static int myMatrixCounterDebug
matrix counter (for debug purposes)
Definition: GLHelper.h:403
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:589
static int getMatrixCounter()
get matrix counter
Definition: GLHelper.cpp:157
static void drawCrossTies(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double length, double spacing, double halfWidth, bool drawForSelection)
draw crossties for railroads or pedestrian crossings
Definition: GLHelper.cpp:785
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:277
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:880
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:316
static int myNameCounter
name counter
Definition: GLHelper.h:406
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
static void setGL2PS(bool active=true)
set GL2PS
Definition: GLHelper.cpp:607
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:830
static bool myGL2PSActive
whether we are currently rendering for gl2ps
Definition: GLHelper.h:416
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:685
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:613
static bool initFont()
init myFont
Definition: GLHelper.cpp:651
static double myFontSize
Definition: GLHelper.h:413
static int myVertexCounter
matrix counter (for debug purposes)
Definition: GLHelper.h:400
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:716
static void resetMatrixCounter()
reset matrix counter
Definition: GLHelper.cpp:163
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