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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Some methods which help to draw certain geometrical objects in openGL
18 /****************************************************************************/
19 #ifndef GLHelper_h
20 #define GLHelper_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
29 #include <utility>
30 #include <utils/common/RGBColor.h>
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
38 
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
49 class GLHelper {
50 public:
57  static void drawFilledPoly(const PositionVector& v, bool close);
58 
59 
67  static void drawFilledPolyTesselated(const PositionVector& v, bool close);
68 
69 
80  static void drawBoxLine(const Position& beg, double rot,
81  double visLength, double width, double offset = 0);
82 
83 
94  static void drawBoxLine(const Position& beg1, const Position& beg2,
95  double rot, double visLength, double width);
96 
97 
110  static void drawBoxLines(const PositionVector& geom,
111  const std::vector<double>& rots, const std::vector<double>& lengths,
112  double width, int cornerDetail = 0, double offset = 0);
113 
127  static void drawBoxLines(const PositionVector& geom,
128  const std::vector<double>& rots, const std::vector<double>& lengths,
129  const std::vector<RGBColor>& cols,
130  double width, int cornerDetail = 0, double offset = 0);
131 
132 
144  static void drawBoxLines(const PositionVector& geom1,
145  const PositionVector& geom2,
146  const std::vector<double>& rots, const std::vector<double>& lengths,
147  double width);
148 
149 
159  static void drawBoxLines(const PositionVector& geom, double width);
160 
161 
170  static void drawLine(const Position& beg, double rot,
171  double visLength);
172 
173 
183  static void drawLine(const Position& beg1, const Position& beg2,
184  double rot, double visLength);
185 
186 
193  static void drawLine(const PositionVector& v);
194 
195 
204  static void drawLine(const PositionVector& v, const std::vector<RGBColor>& cols);
205 
206 
214  static void drawLine(const Position& beg, const Position& end);
215 
216 
224  static void drawFilledCircle(double width, int steps = 8);
225 
233  static std::vector<Position> drawFilledCircleReturnVertices(double width, int steps = 8);
234 
244  static void drawFilledCircle(double width, int steps,
245  double beg, double end);
246 
247 
256  static void drawOutlineCircle(double width, double iwidth,
257  int steps = 8);
258 
259 
270  static void drawOutlineCircle(double width, double iwidth,
271  int steps, double beg, double end);
272 
273 
281  static void drawTriangleAtEnd(const Position& p1, const Position& p2,
282  double tLength, double tWidth);
283 
285  static const std::vector<RGBColor>& getDottedcontourColors(const int size);
286 
288  static void drawShapeDottedContour(const int type, const PositionVector& shape, const double width);
289 
291  static void drawShapeDottedContour(const int type, const PositionVector& shape);
292 
294  static void drawShapeDottedContour(const int type, const PositionVector& frontShape, const double offsetFrontShape, const PositionVector& backShape, const double offsetBackShape);
295 
297  static void drawShapeDottedContour(const int type, const Position& center, const double width, const double height, const double rotation = 0, const double offsetX = 0, const double offsetY = 0);
298 
300  static void setColor(const RGBColor& c);
301 
303  static RGBColor getColor();
304 
305  /* @brief draw Text with given parameters
306  * when width is not given (negative) the font is scaled proportionally in
307  * height and with according to size.
308  */
309  static void drawText(const std::string& text, const Position& pos,
310  const double layer, const double size,
311  const RGBColor& col = RGBColor::BLACK, const double angle = 0,
312  int align = 0,
313  double width = -1);
314 
315  static void drawTextSettings(
316  const GUIVisualizationTextSettings& settings,
317  const std::string& text, const Position& pos,
318  const double scale,
319  const double angle = 0,
320  const double layer = 2048); // GLO_MAX
321 
323  static void drawTextBox(const std::string& text, const Position& pos,
324  const double layer, const double size,
325  const RGBColor& txtColor = RGBColor::BLACK,
326  const RGBColor& bgColor = RGBColor::WHITE,
327  const RGBColor& borderColor = RGBColor::BLACK,
328  const double angle = 0,
329  const double relBorder = 0.05,
330  const double relMargin = 0.5);
331 
333  static void drawTextAtEnd(const std::string& text, const PositionVector& shape, double x, double size, RGBColor color);
334 
336  static void drawCrossTies(const PositionVector& geom,
337  const std::vector<double>& rots,
338  const std::vector<double>& lengths,
339  double length, double spacing, double halfWidth, bool drawForSelecting);
340 
342  static void debugVertices(const PositionVector& shape, double size, double layer = 256);
343 
345  static void resetFont();
346 
347 private:
349  static int angleLookup(double angleDeg);
350 
352  static bool rightTurn(double angle1, double angle2);
353 
355  static bool initFont();
356 
357 private:
359  static std::vector<std::pair<double, double> > myCircleCoords;
360 
362  static struct FONScontext* myFont;
363  static double myFontSize;
364 
366  static std::vector<RGBColor> myDottedcontourColors;
367 };
368 
369 
370 #endif
371 
372 /****************************************************************************/
373 
static std::vector< std::pair< double, double > > myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
Definition: GLHelper.h:359
static void resetFont()
to be called when the font context is invalidated
Definition: GLHelper.cpp:590
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:178
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)
draw Text box with given parameters
Definition: GLHelper.cpp:651
static void drawTextAtEnd(const std::string &text, const PositionVector &shape, double x, double size, RGBColor color)
draw text and the end of shape
Definition: GLHelper.cpp:683
static const RGBColor WHITE
Definition: RGBColor.h:191
static bool initFont()
init myFont
Definition: GLHelper.cpp:597
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:736
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048)
Definition: GLHelper.cpp:635
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, int align=0, double width=-1)
Definition: GLHelper.cpp:611
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:78
static const RGBColor BLACK
Definition: RGBColor.h:192
Some methods which help to draw certain geometrical objects in openGL.
Definition: GLHelper.h:49
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:344
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:97
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
A list of positions.
static std::vector< Position > drawFilledCircleReturnVertices(double width, int steps=8)
Draws a filled circle around (0,0) returning circle vertex.
Definition: GLHelper.cpp:350
static double myFontSize
Definition: GLHelper.h:363
static int angleLookup(double angleDeg)
normalize angle for lookup in myCircleCoords
Definition: GLHelper.cpp:332
static void drawOutlineCircle(double width, double iwidth, int steps=8)
Draws an unfilled circle around (0,0)
Definition: GLHelper.cpp:389
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:270
static struct FONScontext * myFont
Font context.
Definition: GLHelper.h:362
static void drawShapeDottedContour(const int type, const PositionVector &shape, const double width)
draw a dotted contour around the given Non closed shape with certain width
Definition: GLHelper.cpp:471
static void drawCrossTies(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double length, double spacing, double halfWidth, bool drawForSelecting)
draw crossties for railroads or pedestrian crossings
Definition: GLHelper.cpp:696
static bool rightTurn(double angle1, double angle2)
whether the road makes a right turn (or goes straight)
Definition: GLHelper.cpp:165
static std::vector< RGBColor > myDottedcontourColors
static vector with a list of alternated black/white colors (used for contourns)
Definition: GLHelper.h:366
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:436
struct FONScontext FONScontext
Definition: fontstash.h:95
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:132
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:457
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:579