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 /****************************************************************************/
16 // Some methods which help to draw certain geometrical objects in openGL
17 /****************************************************************************/
18 #ifndef GLHelper_h
19 #define GLHelper_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <vector>
28 #include <utility>
29 #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 void drawShapeDottedContourAroundShape(const GUIVisualizationSettings& s, const int type, const PositionVector& shape, const double width);
286 
288  static void drawShapeDottedContourAroundClosedShape(const GUIVisualizationSettings& s, const int type, const PositionVector& shape);
289 
291  static void drawShapeDottedContourBetweenLanes(const GUIVisualizationSettings& s, const int type, const PositionVector& frontLaneShape, const double offsetFrontLaneShape, const PositionVector& backLaneShape, const double offsetBackLaneShape);
292 
294  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);
295 
297  static void drawShapeDottedContourPartialShapes(const GUIVisualizationSettings& s, const int type, const Position& begin, const Position& end, const double width);
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 drawForRectangleSelection);
340 
342  static void debugVertices(const PositionVector& shape, double size, double layer = 256);
343 
345  static void drawBoundary(const Boundary& b);
346 
348  static void resetFont();
349 
350  static void setGL2PS(bool active = true) {
351  myGL2PSActive = active;
352  }
353 
354 private:
356  static int angleLookup(double angleDeg);
357 
359  static bool rightTurn(double angle1, double angle2);
360 
362  static bool initFont();
363 
365  static const std::vector<RGBColor>& getDottedcontourColors(const int size);
366 
368  static std::vector<std::pair<double, double> > myCircleCoords;
369 
371  static struct FONScontext* myFont;
372  static double myFontSize;
373 
375  static bool myGL2PSActive;
376 
378  static std::vector<RGBColor> myDottedcontourColors;
379 };
380 
381 
382 #endif
383 
384 /****************************************************************************/
385 
GLHelper::debugVertices
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:808
GLHelper::drawTextSettings
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:706
GLHelper::getColor
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:627
GLHelper::initFont
static bool initFont()
init myFont
Definition: GLHelper.cpp:645
RGBColor::BLACK
static const RGBColor BLACK
Definition: RGBColor.h:197
GLHelper::drawBoxLines
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
GLHelper::drawCrossTies
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:768
GLHelper::myCircleCoords
static std::vector< std::pair< double, double > > myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
Definition: GLHelper.h:368
GLHelper::resetFont
static void resetFont()
to be called when the font context is invalidated
Definition: GLHelper.cpp:638
GUIVisualizationTextSettings
Definition: GUIVisualizationSettings.h:50
GUIVisualizationSettings.h
PositionVector
A list of positions.
Definition: PositionVector.h:45
GLHelper::drawFilledPoly
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:82
GLHelper::myGL2PSActive
static bool myGL2PSActive
whether we are currently rendering for gl2ps
Definition: GLHelper.h:375
GLHelper::setColor
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:621
RGBColor.h
GLHelper::drawBoundary
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:817
GLHelper::drawFilledCircle
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:348
GLHelper::drawText
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:673
RGBColor
Definition: RGBColor.h:39
GLHelper::angleLookup
static int angleLookup(double angleDeg)
normalize angle for lookup in myCircleCoords
Definition: GLHelper.cpp:336
GLHelper::drawOutlineCircle
static void drawOutlineCircle(double width, double iwidth, int steps=8)
Draws an unfilled circle around (0,0)
Definition: GLHelper.cpp:393
GLHelper::myFontSize
static double myFontSize
Definition: GLHelper.h:372
GLHelper::drawFilledCircleReturnVertices
static std::vector< Position > drawFilledCircleReturnVertices(double width, int steps=8)
Draws a filled circle around (0,0) returning circle vertex.
Definition: GLHelper.cpp:354
GLHelper::myFont
static struct FONScontext * myFont
Font context.
Definition: GLHelper.h:371
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
GLHelper::drawShapeDottedContourAroundClosedShape
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
GLHelper::drawShapeDottedContourRectangle
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:560
GLHelper::drawShapeDottedContourBetweenLanes
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
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
GLHelper::drawFilledPolyTesselated
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:101
GLHelper::drawLine
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:274
FONScontext
struct FONScontext FONScontext
Definition: fontstash.h:95
GLHelper::drawShapeDottedContourAroundShape
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
GLHelper::drawBoxLine
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:136
GLHelper::rightTurn
static bool rightTurn(double angle1, double angle2)
whether the road makes a right turn (or goes straight)
Definition: GLHelper.cpp:169
config.h
GLHelper::myDottedcontourColors
static std::vector< RGBColor > myDottedcontourColors
static vector with a list of alternated black/white colors (used for contourns)
Definition: GLHelper.h:378
GLHelper::drawShapeDottedContourPartialShapes
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:593
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:345
GLHelper::getDottedcontourColors
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:659
PositionVector.h
GLHelper::setGL2PS
static void setGL2PS(bool active=true)
Definition: GLHelper.h:350
GLHelper::drawTextBox
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:722
RGBColor::WHITE
static const RGBColor WHITE
Definition: RGBColor.h:196
GLHelper::drawTextAtEnd
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:755
GLHelper
Some methods which help to draw certain geometrical objects in openGL.
Definition: GLHelper.h:49
GLHelper::drawTriangleAtEnd
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