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-2019 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>
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
50 class GLHelper {
51 public:
58  static void drawFilledPoly(const PositionVector& v, bool close);
59 
60 
68  static void drawFilledPolyTesselated(const PositionVector& v, bool close);
69 
70 
81  static void drawBoxLine(const Position& beg, double rot,
82  double visLength, double width, double offset = 0);
83 
84 
95  static void drawBoxLine(const Position& beg1, const Position& beg2,
96  double rot, double visLength, double width);
97 
98 
111  static void drawBoxLines(const PositionVector& geom,
112  const std::vector<double>& rots, const std::vector<double>& lengths,
113  double width, int cornerDetail = 0, double offset = 0);
114 
128  static void drawBoxLines(const PositionVector& geom,
129  const std::vector<double>& rots, const std::vector<double>& lengths,
130  const std::vector<RGBColor>& cols,
131  double width, int cornerDetail = 0, double offset = 0);
132 
133 
145  static void drawBoxLines(const PositionVector& geom1,
146  const PositionVector& geom2,
147  const std::vector<double>& rots, const std::vector<double>& lengths,
148  double width);
149 
150 
160  static void drawBoxLines(const PositionVector& geom, double width);
161 
162 
171  static void drawLine(const Position& beg, double rot,
172  double visLength);
173 
174 
184  static void drawLine(const Position& beg1, const Position& beg2,
185  double rot, double visLength);
186 
187 
194  static void drawLine(const PositionVector& v);
195 
196 
205  static void drawLine(const PositionVector& v, const std::vector<RGBColor>& cols);
206 
207 
215  static void drawLine(const Position& beg, const Position& end);
216 
217 
225  static void drawFilledCircle(double width, int steps = 8);
226 
234  static std::vector<Position> drawFilledCircleReturnVertices(double width, int steps = 8);
235 
245  static void drawFilledCircle(double width, int steps,
246  double beg, double end);
247 
248 
257  static void drawOutlineCircle(double width, double iwidth,
258  int steps = 8);
259 
260 
271  static void drawOutlineCircle(double width, double iwidth,
272  int steps, double beg, double end);
273 
274 
282  static void drawTriangleAtEnd(const Position& p1, const Position& p2,
283  double tLength, double tWidth);
284 
286  static void drawShapeDottedContourAroundShape(const GUIVisualizationSettings& s, const int type, const PositionVector& shape, const double width);
287 
289  static void drawShapeDottedContourAroundClosedShape(const GUIVisualizationSettings& s, const int type, const PositionVector& shape);
290 
292  static void drawShapeDottedContourBetweenLanes(const GUIVisualizationSettings& s, const int type, const PositionVector& frontLaneShape, const double offsetFrontLaneShape, const PositionVector& backLaneShape, const double offsetBackLaneShape);
293 
295  static void drawShapeDottedContourRectangle(const GUIVisualizationSettings& s, const int type, const Position& center, const double width, const double height, const double rotation = 0, const double offsetX = 0, const double offsetY = 0);
296 
298  static void drawShapeDottedContourPartialShapes(const GUIVisualizationSettings& s, const int type, const Position& begin, const Position& end, const double width);
299 
301  static void setColor(const RGBColor& c);
302 
304  static RGBColor getColor();
305 
306  /* @brief draw Text with given parameters
307  * when width is not given (negative) the font is scaled proportionally in
308  * height and with according to size.
309  */
310  static void drawText(const std::string& text, const Position& pos,
311  const double layer, const double size,
312  const RGBColor& col = RGBColor::BLACK, const double angle = 0,
313  int align = 0,
314  double width = -1);
315 
316  static void drawTextSettings(
317  const GUIVisualizationTextSettings& settings,
318  const std::string& text, const Position& pos,
319  const double scale,
320  const double angle = 0,
321  const double layer = 2048); // GLO_MAX
322 
324  static void drawTextBox(const std::string& text, const Position& pos,
325  const double layer, const double size,
326  const RGBColor& txtColor = RGBColor::BLACK,
327  const RGBColor& bgColor = RGBColor::WHITE,
328  const RGBColor& borderColor = RGBColor::BLACK,
329  const double angle = 0,
330  const double relBorder = 0.05,
331  const double relMargin = 0.5);
332 
334  static void drawTextAtEnd(const std::string& text, const PositionVector& shape, double x, double size, RGBColor color);
335 
337  static void drawCrossTies(const PositionVector& geom,
338  const std::vector<double>& rots,
339  const std::vector<double>& lengths,
340  double length, double spacing, double halfWidth, bool drawForSelecting);
341 
343  static void debugVertices(const PositionVector& shape, double size, double layer = 256);
344 
346  static void drawBoundary(const Boundary& b);
347 
349  static void resetFont();
350 
351  static void setGL2PS(bool active = true) {
352  myGL2PSActive = active;
353  }
354 
355 private:
357  static int angleLookup(double angleDeg);
358 
360  static bool rightTurn(double angle1, double angle2);
361 
363  static bool initFont();
364 
366  static const std::vector<RGBColor>& getDottedcontourColors(const int size);
367 
369  static std::vector<std::pair<double, double> > myCircleCoords;
370 
372  static struct FONScontext* myFont;
373  static double myFontSize;
374 
376  static bool myGL2PSActive;
377 
379  static std::vector<RGBColor> myDottedcontourColors;
380 };
381 
382 
383 #endif
384 
385 /****************************************************************************/
386 
static std::vector< std::pair< double, double > > myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
Definition: GLHelper.h:369
static void resetFont()
to be called when the font context is invalidated
Definition: GLHelper.cpp:633
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:182
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:717
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:750
static const RGBColor WHITE
Definition: RGBColor.h:197
static bool initFont()
init myFont
Definition: GLHelper.cpp:640
Stores the information about how to visualize structures.
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:803
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:701
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:668
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:82
static const RGBColor BLACK
Definition: RGBColor.h:198
Some methods which help to draw certain geometrical objects in openGL.
Definition: GLHelper.h:50
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:348
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
static bool myGL2PSActive
whether we are currently rendering for gl2ps
Definition: GLHelper.h:376
static void drawShapeDottedContourBetweenLanes(const GUIVisualizationSettings &s, const int type, const PositionVector &frontLaneShape, const double offsetFrontLaneShape, const PositionVector &backLaneShape, const double offsetBackLaneShape)
draw a dotted contour around the given lane shapes
Definition: GLHelper.cpp:523
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:101
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:812
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
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:354
static double myFontSize
Definition: GLHelper.h:373
static int angleLookup(double angleDeg)
normalize angle for lookup in myCircleCoords
Definition: GLHelper.cpp:336
static void drawShapeDottedContourAroundClosedShape(const GUIVisualizationSettings &s, const int type, const PositionVector &shape)
draw a dotted contour around the given closed shape with certain width
Definition: GLHelper.cpp:496
static void drawOutlineCircle(double width, double iwidth, int steps=8)
Draws an unfilled circle around (0,0)
Definition: GLHelper.cpp:393
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:274
static void drawShapeDottedContourAroundShape(const GUIVisualizationSettings &s, 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:461
static struct FONScontext * myFont
Font context.
Definition: GLHelper.h:372
static void drawShapeDottedContourRectangle(const GUIVisualizationSettings &s, const int type, const Position &center, const double width, const double height, const double rotation=0, const double offsetX=0, const double offsetY=0)
draw a dotted contour around the given Position with certain width and height
Definition: GLHelper.cpp:555
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:763
static bool rightTurn(double angle1, double angle2)
whether the road makes a right turn (or goes straight)
Definition: GLHelper.cpp:169
static std::vector< RGBColor > myDottedcontourColors
static vector with a list of alternated black/white colors (used for contourns)
Definition: GLHelper.h:379
static void drawShapeDottedContourPartialShapes(const GUIVisualizationSettings &s, const int type, const Position &begin, const Position &end, const double width)
draw a dotted contour in a partial shapes
Definition: GLHelper.cpp:588
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:440
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:136
static void setGL2PS(bool active=true)
Definition: GLHelper.h:351
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:654
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:622