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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Some methods which help to draw certain geometrical objects in openGL
20 /****************************************************************************/
21 #ifndef GLHelper_h
22 #define GLHelper_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
35 #include <utility>
36 #include <utils/common/RGBColor.h>
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 
226 
236  static void drawFilledCircle(double width, int steps,
237  double beg, double end);
238 
239 
248  static void drawOutlineCircle(double width, double iwidth,
249  int steps = 8);
250 
251 
262  static void drawOutlineCircle(double width, double iwidth,
263  int steps, double beg, double end);
264 
265 
273  static void drawTriangleAtEnd(const Position& p1, const Position& p2,
274  double tLength, double tWidth);
275 
277  static void setColor(const RGBColor& c);
278 
280  static RGBColor getColor();
281 
282  /* @brief draw Text with given parameters
283  * when width is not given (negative) the font is scaled proportionally in
284  * height and with according to size.
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, const double angle = 0,
289  int align = 0,
290  double width = -1);
291 
293  static void drawTextBox(const std::string& text, const Position& pos,
294  const double layer, const double size,
295  const RGBColor& txtColor = RGBColor::BLACK,
296  const RGBColor& bgColor = RGBColor::WHITE,
297  const RGBColor& borderColor = RGBColor::BLACK,
298  const double angle = 0);
299 
301  static void drawTextAtEnd(const std::string& text, const PositionVector& shape, double x, double size, RGBColor color);
302 
304  static void debugVertices(const PositionVector& shape, double size, double layer = 256);
305 
307  static void resetFont();
308 
309 private:
311  static int angleLookup(double angleDeg);
312 
314  static bool rightTurn(double angle1, double angle2);
315 
317  static bool initFont();
318 
319 private:
321  static std::vector<std::pair<double, double> > myCircleCoords;
322 
324  static struct FONScontext* myFont;
325  static double myFontSize;
326 
327 };
328 
329 
330 #endif
331 
332 /****************************************************************************/
333 
static std::vector< std::pair< double, double > > myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
Definition: GLHelper.h:321
static void resetFont()
to be called when the font context is invalidated
Definition: GLHelper.cpp:466
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:183
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:543
static const RGBColor WHITE
Definition: RGBColor.h:185
static bool initFont()
init myFont
Definition: GLHelper.cpp:473
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:556
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:487
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:83
static const RGBColor BLACK
Definition: RGBColor.h:186
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:350
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:102
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:449
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
A list of positions.
static double myFontSize
Definition: GLHelper.h:325
static int angleLookup(double angleDeg)
normalize angle for lookup in myCircleCoords
Definition: GLHelper.cpp:338
static void drawOutlineCircle(double width, double iwidth, int steps=8)
Draws an unfilled circle around (0,0)
Definition: GLHelper.cpp:381
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:276
static struct FONScontext * myFont
Font context.
Definition: GLHelper.h:324
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)
draw Text box with given parameters
Definition: GLHelper.cpp:511
static bool rightTurn(double angle1, double angle2)
whether the road makes a right turn (or goes straight)
Definition: GLHelper.cpp:170
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:428
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:137
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:455