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 definitions
36 // ===========================================================================
43 class GLHelper {
44 public:
51  static void drawFilledPoly(const PositionVector& v, bool close);
52 
53 
61  static void drawFilledPolyTesselated(const PositionVector& v, bool close);
62 
63 
74  static void drawBoxLine(const Position& beg, double rot,
75  double visLength, double width, double offset = 0);
76 
77 
88  static void drawBoxLine(const Position& beg1, const Position& beg2,
89  double rot, double visLength, double width);
90 
91 
104  static void drawBoxLines(const PositionVector& geom,
105  const std::vector<double>& rots, const std::vector<double>& lengths,
106  double width, int cornerDetail = 0, double offset = 0);
107 
121  static void drawBoxLines(const PositionVector& geom,
122  const std::vector<double>& rots, const std::vector<double>& lengths,
123  const std::vector<RGBColor>& cols,
124  double width, int cornerDetail = 0, double offset = 0);
125 
126 
138  static void drawBoxLines(const PositionVector& geom1,
139  const PositionVector& geom2,
140  const std::vector<double>& rots, const std::vector<double>& lengths,
141  double width);
142 
143 
153  static void drawBoxLines(const PositionVector& geom, double width);
154 
155 
164  static void drawLine(const Position& beg, double rot,
165  double visLength);
166 
167 
177  static void drawLine(const Position& beg1, const Position& beg2,
178  double rot, double visLength);
179 
180 
187  static void drawLine(const PositionVector& v);
188 
189 
198  static void drawLine(const PositionVector& v, const std::vector<RGBColor>& cols);
199 
200 
208  static void drawLine(const Position& beg, const Position& end);
209 
210 
218  static void drawFilledCircle(double width, int steps = 8);
219 
227  static std::vector<Position> drawFilledCircleReturnVertices(double width, int steps = 8);
228 
238  static void drawFilledCircle(double width, int steps,
239  double beg, double end);
240 
241 
250  static void drawOutlineCircle(double width, double iwidth,
251  int steps = 8);
252 
253 
264  static void drawOutlineCircle(double width, double iwidth,
265  int steps, double beg, double end);
266 
267 
275  static void drawTriangleAtEnd(const Position& p1, const Position& p2,
276  double tLength, double tWidth);
277 
279  static const std::vector<RGBColor>& getDottedcontourColors(const int size);
280 
282  static void drawShapeDottedContour(const int type, const PositionVector& shape, const double width);
283 
285  static void drawShapeDottedContour(const int type, const PositionVector& shape);
286 
288  static void drawShapeDottedContour(const int type, const PositionVector& frontShape, const double offsetFrontShape, const PositionVector& backShape, const double offsetBackShape);
289 
291  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);
292 
294  static void setColor(const RGBColor& c);
295 
297  static RGBColor getColor();
298 
299  /* @brief draw Text with given parameters
300  * when width is not given (negative) the font is scaled proportionally in
301  * height and with according to size.
302  */
303  static void drawText(const std::string& text, const Position& pos,
304  const double layer, const double size,
305  const RGBColor& col = RGBColor::BLACK, const double angle = 0,
306  int align = 0,
307  double width = -1);
308 
310  static void drawTextBox(const std::string& text, const Position& pos,
311  const double layer, const double size,
312  const RGBColor& txtColor = RGBColor::BLACK,
313  const RGBColor& bgColor = RGBColor::WHITE,
314  const RGBColor& borderColor = RGBColor::BLACK,
315  const double angle = 0);
316 
318  static void drawTextAtEnd(const std::string& text, const PositionVector& shape, double x, double size, RGBColor color);
319 
321  static void drawCrossTies(const PositionVector& geom,
322  const std::vector<double>& rots,
323  const std::vector<double>& lengths,
324  double length, double spacing, double halfWidth, bool drawForSelecting);
325 
327  static void debugVertices(const PositionVector& shape, double size, double layer = 256);
328 
330  static void resetFont();
331 
332 private:
334  static int angleLookup(double angleDeg);
335 
337  static bool rightTurn(double angle1, double angle2);
338 
340  static bool initFont();
341 
342 private:
344  static std::vector<std::pair<double, double> > myCircleCoords;
345 
347  static struct FONScontext* myFont;
348  static double myFontSize;
349 
351  static std::vector<RGBColor> myDottedcontourColors;
352 };
353 
354 
355 #endif
356 
357 /****************************************************************************/
358 
static std::vector< std::pair< double, double > > myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
Definition: GLHelper.h:344
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 drawTextAtEnd(const std::string &text, const PositionVector &shape, double x, double size, RGBColor color)
draw text and the end of shape
Definition: GLHelper.cpp:667
static const RGBColor WHITE
Definition: RGBColor.h:179
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:720
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:180
Some methods which help to draw certain geometrical objects in openGL.
Definition: GLHelper.h:43
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:348
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:347
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:635
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:680
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:351
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