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 void checkCounterMatrix();
70 
72  static void checkCounterName();
73 
80  static void drawFilledPoly(const PositionVector& v, bool close);
81 
82 
90  static void drawFilledPolyTesselated(const PositionVector& v, bool close);
91 
92 
103  static void drawBoxLine(const Position& beg, double rot,
104  double visLength, double width, double offset = 0);
105 
106 
117  static void drawBoxLine(const Position& beg1, const Position& beg2,
118  double rot, double visLength, double width);
119 
120 
133  static void drawBoxLines(const PositionVector& geom,
134  const std::vector<double>& rots, const std::vector<double>& lengths,
135  double width, int cornerDetail = 0, double offset = 0);
136 
150  static void drawBoxLines(const PositionVector& geom,
151  const std::vector<double>& rots, const std::vector<double>& lengths,
152  const std::vector<RGBColor>& cols,
153  double width, int cornerDetail = 0, double offset = 0);
154 
155 
167  static void drawBoxLines(const PositionVector& geom1,
168  const PositionVector& geom2,
169  const std::vector<double>& rots, const std::vector<double>& lengths,
170  double width);
171 
172 
182  static void drawBoxLines(const PositionVector& geom, double width);
183 
184 
193  static void drawLine(const Position& beg, double rot,
194  double visLength);
195 
196 
206  static void drawLine(const Position& beg1, const Position& beg2,
207  double rot, double visLength);
208 
209 
216  static void drawLine(const PositionVector& v);
217 
218 
227  static void drawLine(const PositionVector& v, const std::vector<RGBColor>& cols);
228 
229 
237  static void drawLine(const Position& beg, const Position& end);
238 
239 
247  static void drawFilledCircle(double width, int steps = 8);
248 
249 
259  static void drawFilledCircle(double width, int steps,
260  double beg, double end);
261 
262 
271  static void drawOutlineCircle(double width, double iwidth,
272  int steps = 8);
273 
274 
285  static void drawOutlineCircle(double width, double iwidth,
286  int steps, double beg, double end);
287 
288 
297  static void drawTriangleAtEnd(const Position& p1, const Position& p2, double tLength,
298  double tWidth, const double extraOffset = 0);
299 
301  static void setColor(const RGBColor& c);
302 
304  static RGBColor getColor();
305 
307  static double getTextWidth(const std::string& text, double size);
308 
309  /* @brief draw Text with given parameters
310  * when width is not given (negative) the font is scaled proportionally in
311  * height and width according to size.
312  *
313  * align: see foreign/fontstash/fontstash.h for flags
314  */
315  static void drawText(const std::string& text, const Position& pos,
316  const double layer, const double size,
317  const RGBColor& col = RGBColor::BLACK,
318  const double angle = 0,
319  const int align = 0,
320  double width = -1);
321 
322  static void drawTextSettings(
323  const GUIVisualizationTextSettings& settings,
324  const std::string& text, const Position& pos,
325  const double scale,
326  const double angle = 0,
327  const double layer = 2048, // GLO_MAX
328  const int align = 0); // centered
329 
331  static void drawTextBox(const std::string& text, const Position& pos,
332  const double layer, const double size,
333  const RGBColor& txtColor = RGBColor::BLACK,
334  const RGBColor& bgColor = RGBColor::WHITE,
335  const RGBColor& borderColor = RGBColor::BLACK,
336  const double angle = 0,
337  const double relBorder = 0.05,
338  const double relMargin = 0.5,
339  const int align = 0);
340 
342  static void drawTextAtEnd(const std::string& text, const PositionVector& shape, double x,
343  const GUIVisualizationTextSettings& settings, const double scale);
344 
346  static void drawCrossTies(const PositionVector& geom,
347  const std::vector<double>& rots,
348  const std::vector<double>& lengths,
349  double length, double spacing, double halfWidth, bool drawForSelection);
350 
352  static void drawInverseMarkings(const PositionVector& geom,
353  const std::vector<double>& rots,
354  const std::vector<double>& lengths,
355  double maxLength, double spacing,
356  double halfWidth, bool cl, bool cr, bool lefthand, double scale);
357 
359  static void debugVertices(const PositionVector& shape, double size, double layer = 256);
360 
362  static void drawBoundary(const Boundary& b);
363 
365  static void resetFont();
366 
368  static void setGL2PS(bool active = true);
369 
371  static void drawSpaceOccupancies(const double exaggeration, const Position& pos, const double rotation,
372  const double width, const double length, const bool vehicle);
373 
374 private:
376  static bool rightTurn(double angle1, double angle2);
377 
379  static bool initFont();
380 
382  static const std::vector<RGBColor>& getDottedcontourColors(const int size);
383 
385  static int myMatrixCounter;
386 
388  static int myNameCounter;
389 
391  static std::vector<std::pair<double, double> > myCircleCoords;
392 
394  static struct FONScontext* myFont;
395  static double myFontSize;
396 
398  static bool myGL2PSActive;
399 
401  static std::vector<RGBColor> myDottedcontourColors;
402 };
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:170
static void debugVertices(const PositionVector &shape, double size, double layer=256)
draw vertex numbers for the given shape (in a random color)
Definition: GLHelper.cpp:792
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:801
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:189
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:657
static std::vector< std::pair< double, double > > myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
Definition: GLHelper.h:391
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:369
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:431
static struct FONScontext * myFont
Font context.
Definition: GLHelper.h:394
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:485
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:691
static void resetFont()
to be called when the font context is invalidated
Definition: GLHelper.cpp:524
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void checkCounterMatrix()
check counter matrix
Definition: GLHelper.cpp:150
static void drawOutlineCircle(double width, double iwidth, int steps=8)
Draws an unfilled circle around (0,0)
Definition: GLHelper.cpp:455
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:589
static std::vector< RGBColor > myDottedcontourColors
static vector with a list of alternated black/white colors (used for contourns)
Definition: GLHelper.h:401
static int angleLookup(double angleDeg)
normalize angle for lookup in myCircleCoords
Definition: GLHelper.cpp:102
static double getTextWidth(const std::string &text, double size)
get required width of text
Definition: GLHelper.cpp:603
static int myMatrixCounter
matrix counter
Definition: GLHelper.h:385
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
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:277
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:513
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:709
static const std::vector< std::pair< double, double > > & getCircleCoords()
Storage for precomputed sin/cos-values describing a circle.
Definition: GLHelper.cpp:88
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:231
static void checkCounterName()
check counter name
Definition: GLHelper.cpp:160
static void popName()
pop Name
Definition: GLHelper.cpp:141
static bool rightTurn(double angle1, double angle2)
whether the road makes a right turn (or goes straight)
Definition: GLHelper.cpp:264
static int myNameCounter
name counter
Definition: GLHelper.h:388
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
static void setGL2PS(bool active=true)
set GL2PS
Definition: GLHelper.cpp:531
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:748
static bool myGL2PSActive
whether we are currently rendering for gl2ps
Definition: GLHelper.h:398
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:609
static void drawSpaceOccupancies(const double exaggeration, const Position &pos, const double rotation, const double width, const double length, const bool vehicle)
darw
Definition: GLHelper.cpp:537
static bool initFont()
init myFont
Definition: GLHelper.cpp:575
static double myFontSize
Definition: GLHelper.h:395
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:640
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