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-2020 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 public:
55  static void drawFilledPoly(const PositionVector& v, bool close);
56 
57 
65  static void drawFilledPolyTesselated(const PositionVector& v, bool close);
66 
67 
78  static void drawBoxLine(const Position& beg, double rot,
79  double visLength, double width, double offset = 0);
80 
81 
92  static void drawBoxLine(const Position& beg1, const Position& beg2,
93  double rot, double visLength, double width);
94 
95 
108  static void drawBoxLines(const PositionVector& geom,
109  const std::vector<double>& rots, const std::vector<double>& lengths,
110  double width, int cornerDetail = 0, double offset = 0);
111 
125  static void drawBoxLines(const PositionVector& geom,
126  const std::vector<double>& rots, const std::vector<double>& lengths,
127  const std::vector<RGBColor>& cols,
128  double width, int cornerDetail = 0, double offset = 0);
129 
130 
142  static void drawBoxLines(const PositionVector& geom1,
143  const PositionVector& geom2,
144  const std::vector<double>& rots, const std::vector<double>& lengths,
145  double width);
146 
147 
157  static void drawBoxLines(const PositionVector& geom, double width);
158 
159 
168  static void drawLine(const Position& beg, double rot,
169  double visLength);
170 
171 
181  static void drawLine(const Position& beg1, const Position& beg2,
182  double rot, double visLength);
183 
184 
191  static void drawLine(const PositionVector& v);
192 
193 
202  static void drawLine(const PositionVector& v, const std::vector<RGBColor>& cols);
203 
204 
212  static void drawLine(const Position& beg, const Position& end);
213 
214 
222  static void drawFilledCircle(double width, int steps = 8);
223 
224 
234  static void drawFilledCircle(double width, int steps,
235  double beg, double end);
236 
237 
246  static void drawOutlineCircle(double width, double iwidth,
247  int steps = 8);
248 
249 
260  static void drawOutlineCircle(double width, double iwidth,
261  int steps, double beg, double end);
262 
263 
271  static void drawTriangleAtEnd(const Position& p1, const Position& p2,
272  double tLength, double tWidth);
273 
275  static void setColor(const RGBColor& c);
276 
278  static RGBColor getColor();
279 
280  /* @brief draw Text with given parameters
281  * when width is not given (negative) the font is scaled proportionally in
282  * height and width according to size.
283  *
284  * align: see foreign/fontstash/fontstash.h for flags
285  */
286  static void drawText(const std::string& text, const Position& pos,
287  const double layer, const double size,
288  const RGBColor& col = RGBColor::BLACK,
289  const double angle = 0,
290  const int align = 0,
291  double width = -1);
292 
293  static void drawTextSettings(
294  const GUIVisualizationTextSettings& settings,
295  const std::string& text, const Position& pos,
296  const double scale,
297  const double angle = 0,
298  const double layer = 2048, // GLO_MAX
299  const int align = 0); // centered
300 
302  static void drawTextBox(const std::string& text, const Position& pos,
303  const double layer, const double size,
304  const RGBColor& txtColor = RGBColor::BLACK,
305  const RGBColor& bgColor = RGBColor::WHITE,
306  const RGBColor& borderColor = RGBColor::BLACK,
307  const double angle = 0,
308  const double relBorder = 0.05,
309  const double relMargin = 0.5,
310  const int align = 0);
311 
313  static void drawTextAtEnd(const std::string& text, const PositionVector& shape, double x,
314  const GUIVisualizationTextSettings& settings, const double scale);
315 
317  static void drawCrossTies(const PositionVector& geom,
318  const std::vector<double>& rots,
319  const std::vector<double>& lengths,
320  double length, double spacing, double halfWidth, bool drawForRectangleSelection);
321 
323  static void debugVertices(const PositionVector& shape, double size, double layer = 256);
324 
326  static void drawBoundary(const Boundary& b);
327 
329  static void resetFont();
330 
331  static void setGL2PS(bool active = true) {
332  myGL2PSActive = active;
333  }
334 
335 private:
337  static int angleLookup(double angleDeg);
338 
340  static bool rightTurn(double angle1, double angle2);
341 
343  static bool initFont();
344 
346  static const std::vector<RGBColor>& getDottedcontourColors(const int size);
347 
349  static std::vector<std::pair<double, double> > myCircleCoords;
350 
352  static struct FONScontext* myFont;
353  static double myFontSize;
354 
356  static bool myGL2PSActive;
357 
359  static std::vector<RGBColor> myDottedcontourColors;
360 };
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:81
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:638
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:647
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:100
static void drawCrossTies(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double length, double spacing, double halfWidth, bool drawForRectangleSelection)
draw crossties for railroads or pedestrian crossings
Definition: GLHelper.cpp:598
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:546
static std::vector< std::pair< double, double > > myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
Definition: GLHelper.h:349
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:273
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:347
static struct FONScontext * myFont
Font context.
Definition: GLHelper.h:352
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:580
static void resetFont()
to be called when the font context is invalidated
Definition: GLHelper.cpp:463
static void drawOutlineCircle(double width, double iwidth, int steps=8)
Draws an unfilled circle around (0,0)
Definition: GLHelper.cpp:378
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:484
static std::vector< RGBColor > myDottedcontourColors
static vector with a list of alternated black/white colors (used for contourns)
Definition: GLHelper.h:359
static int angleLookup(double angleDeg)
normalize angle for lookup in myCircleCoords
Definition: GLHelper.cpp:335
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:181
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:452
static void drawTriangleAtEnd(const Position &p1, const Position &p2, double tLength, double tWidth)
Draws a triangle at the end of the given line.
Definition: GLHelper.cpp:425
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:135
static bool rightTurn(double angle1, double angle2)
whether the road makes a right turn (or goes straight)
Definition: GLHelper.cpp:168
static bool myGL2PSActive
whether we are currently rendering for gl2ps
Definition: GLHelper.h:356
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:498
static bool initFont()
init myFont
Definition: GLHelper.cpp:470
static void setGL2PS(bool active=true)
Definition: GLHelper.h:331
static double myFontSize
Definition: GLHelper.h:353
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:529
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
A list of positions.
static const RGBColor WHITE
Definition: RGBColor.h:187
static const RGBColor BLACK
Definition: RGBColor.h:188
struct FONScontext FONScontext
Definition: fontstash.h:95