Eclipse SUMO - Simulation of Urban MObility
GLHelper.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // Some methods which help to draw certain geometrical objects in openGL
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <cassert>
25 #include <utils/geom/GeomHelper.h>
26 #include <utils/common/StdDefs.h>
28 #include <utils/common/ToString.h>
30 #define FONTSTASH_IMPLEMENTATION // Expands implementation
31 #ifdef _MSC_VER
32 #pragma warning(disable: 4505) // do not warn about unused functions
33 #endif
34 #if __GNUC__ > 3
35 #pragma GCC diagnostic push
36 #pragma GCC diagnostic ignored "-Wunused-function"
37 #endif
40 #define GLFONTSTASH_IMPLEMENTATION // Expands implementation
42 #include <utils/geom/Boundary.h>
43 #ifdef HAVE_GL2PS
44 #include <gl2ps.h>
45 #endif
46 #include "Roboto.h"
47 #include "GLHelper.h"
48 
49 #define CIRCLE_RESOLUTION (double)10 // inverse in degrees
50 
51 // ===========================================================================
52 // static member definitions
53 // ===========================================================================
54 std::vector<std::pair<double, double> > GLHelper::myCircleCoords;
55 std::vector<RGBColor> GLHelper::myDottedcontourColors;
56 FONScontext* GLHelper::myFont = nullptr;
57 double GLHelper::myFontSize = 50.0;
58 bool GLHelper::myGL2PSActive = false;
59 
60 void APIENTRY combCallback(GLdouble coords[3],
61  GLdouble* vertex_data[4],
62  GLfloat weight[4], GLdouble** dataOut) {
63  UNUSED_PARAMETER(weight);
64  UNUSED_PARAMETER(*vertex_data);
65  GLdouble* vertex;
66 
67  vertex = (GLdouble*)malloc(7 * sizeof(GLdouble));
68 
69  vertex[0] = coords[0];
70  vertex[1] = coords[1];
71  vertex[2] = coords[2];
72  *dataOut = vertex;
73 }
74 
75 // ===========================================================================
76 // method definitions
77 // ===========================================================================
78 
79 
80 void
82  if (v.size() == 0) {
83  return;
84  }
85  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
86  glBegin(GL_POLYGON);
87  for (PositionVector::const_iterator i = v.begin(); i != v.end(); i++) {
88  const Position& p = *i;
89  glVertex2d(p.x(), p.y());
90  }
91  if (close) {
92  const Position& p = *(v.begin());
93  glVertex2d(p.x(), p.y());
94  }
95  glEnd();
96 }
97 
98 
99 void
101  if (v.size() == 0) {
102  return;
103  }
104  GLUtesselator* tobj = gluNewTess();
105  gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid(APIENTRY*)()) &glVertex3dv);
106  gluTessCallback(tobj, GLU_TESS_BEGIN, (GLvoid(APIENTRY*)()) &glBegin);
107  gluTessCallback(tobj, GLU_TESS_END, (GLvoid(APIENTRY*)()) &glEnd);
108  gluTessCallback(tobj, GLU_TESS_COMBINE, (GLvoid(APIENTRY*)()) &combCallback);
109  gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
110  gluTessBeginPolygon(tobj, nullptr);
111  gluTessBeginContour(tobj);
112  double* points = new double[(v.size() + int(close)) * 3];
113 
114  for (int i = 0; i != (int)v.size(); ++i) {
115  points[3 * i] = v[i].x();
116  points[3 * i + 1] = v[i].y();
117  points[3 * i + 2] = 0;
118  gluTessVertex(tobj, points + 3 * i, points + 3 * i);
119  }
120  if (close) {
121  const int i = (int)v.size();
122  points[3 * i] = v[0].x();
123  points[3 * i + 1] = v[0].y();
124  points[3 * i + 2] = 0;
125  gluTessVertex(tobj, points + 3 * i, points + 3 * i);
126  }
127  gluTessEndContour(tobj);
128  gluTessEndPolygon(tobj);
129  gluDeleteTess(tobj);
130  delete[] points;
131 }
132 
133 
134 void
135 GLHelper::drawBoxLine(const Position& beg, double rot, double visLength,
136  double width, double offset) {
137  glPushMatrix();
138  glTranslated(beg.x(), beg.y(), 0);
139  glRotated(rot, 0, 0, 1);
140  glBegin(GL_QUADS);
141  glVertex2d(-width - offset, 0);
142  glVertex2d(-width - offset, -visLength);
143  glVertex2d(width - offset, -visLength);
144  glVertex2d(width - offset, 0);
145  glEnd();
146  glPopMatrix();
147 }
148 
149 
150 void
151 GLHelper::drawBoxLine(const Position& beg1, const Position& beg2,
152  double rot, double visLength,
153  double width) {
154  glPushMatrix();
155  glTranslated((beg2.x() + beg1.x())*.5, (beg2.y() + beg1.y())*.5, 0);
156  glRotated(rot, 0, 0, 1);
157  glBegin(GL_QUADS);
158  glVertex2d(-width, 0);
159  glVertex2d(-width, -visLength);
160  glVertex2d(width, -visLength);
161  glVertex2d(width, 0);
162  glEnd();
163  glPopMatrix();
164 }
165 
166 
167 bool
168 GLHelper::rightTurn(double angle1, double angle2) {
169  double delta = angle2 - angle1;
170  while (delta > 180) {
171  delta -= 360;
172  }
173  while (delta < -180) {
174  delta += 360;
175  }
176  return delta <= 0;
177 }
178 
179 
180 void
182  const std::vector<double>& rots,
183  const std::vector<double>& lengths,
184  double width, int cornerDetail, double offset) {
185  // draw the lane
186  int e = (int) geom.size() - 1;
187  for (int i = 0; i < e; i++) {
188  drawBoxLine(geom[i], rots[i], lengths[i], width, offset);
189  }
190  // draw the corner details
191  if (cornerDetail > 0) {
192  for (int i = 1; i < e; i++) {
193  glPushMatrix();
194  glTranslated(geom[i].x(), geom[i].y(), 0.1);
195  double angleBeg = -rots[i - 1];
196  double angleEnd = 180 - rots[i];
197  if (rightTurn(rots[i - 1], rots[i])) {
198  std::swap(angleBeg, angleEnd);
199  }
200  // only draw the missing piece
201  angleBeg -= 90;
202  angleEnd += 90;
203  // avoid drawing more than 360 degrees
204  if (angleEnd - angleBeg > 360) {
205  angleBeg += 360;
206  }
207  if (angleEnd - angleBeg < -360) {
208  angleEnd += 360;
209  }
210  // draw the right way around
211  if (angleEnd > angleBeg) {
212  angleEnd -= 360;
213  }
214  drawFilledCircle(width + offset, cornerDetail, angleBeg, angleEnd);
215  glPopMatrix();
216  }
217  }
218 }
219 
220 
221 void
223  const std::vector<double>& rots,
224  const std::vector<double>& lengths,
225  const std::vector<RGBColor>& cols,
226  double width, int cornerDetail, double offset) {
227  int e = (int) geom.size() - 1;
228  for (int i = 0; i < e; i++) {
229  setColor(cols[i]);
230  drawBoxLine(geom[i], rots[i], lengths[i], width, offset);
231  }
232  if (cornerDetail > 0) {
233  for (int i = 1; i < e; i++) {
234  glPushMatrix();
235  setColor(cols[i]);
236  glTranslated(geom[i].x(), geom[i].y(), 0);
237  drawFilledCircle(width, cornerDetail);
238  glEnd();
239  glPopMatrix();
240  }
241  }
242 }
243 
244 
245 void
247  const PositionVector& geom2,
248  const std::vector<double>& rots,
249  const std::vector<double>& lengths,
250  double width) {
251  int minS = (int) MIN4(rots.size(), lengths.size(), geom1.size(), geom2.size());
252  for (int i = 0; i < minS; i++) {
253  GLHelper::drawBoxLine(geom1[i], geom2[i], rots[i], lengths[i], width);
254  }
255 }
256 
257 
258 void
259 GLHelper::drawBoxLines(const PositionVector& geom, double width) {
260  int e = (int) geom.size() - 1;
261  for (int i = 0; i < e; i++) {
262  const Position& f = geom[i];
263  const Position& s = geom[i + 1];
264  drawBoxLine(f,
265  RAD2DEG(atan2((s.x() - f.x()), (f.y() - s.y()))),
266  f.distanceTo(s),
267  width);
268  }
269 }
270 
271 
272 void
273 GLHelper::drawLine(const Position& beg, double rot, double visLength) {
274  glPushMatrix();
275  glTranslated(beg.x(), beg.y(), 0);
276  glRotated(rot, 0, 0, 1);
277  glBegin(GL_LINES);
278  glVertex2d(0, 0);
279  glVertex2d(0, -visLength);
280  glEnd();
281  glPopMatrix();
282 }
283 
284 
285 void
286 GLHelper::drawLine(const Position& beg1, const Position& beg2,
287  double rot, double visLength) {
288  glPushMatrix();
289  glTranslated((beg2.x() + beg1.x())*.5, (beg2.y() + beg1.y())*.5, 0);
290  glRotated(rot, 0, 0, 1);
291  glBegin(GL_LINES);
292  glVertex2d(0, 0);
293  glVertex2d(0, -visLength);
294  glEnd();
295  glPopMatrix();
296 }
297 
298 
299 
300 void
302  glBegin(GL_LINES);
303  int e = (int) v.size() - 1;
304  for (int i = 0; i < e; ++i) {
305  glVertex2d(v[i].x(), v[i].y());
306  glVertex2d(v[i + 1].x(), v[i + 1].y());
307  }
308  glEnd();
309 }
310 
311 
312 void
313 GLHelper::drawLine(const PositionVector& v, const std::vector<RGBColor>& cols) {
314  glBegin(GL_LINES);
315  int e = (int) v.size() - 1;
316  for (int i = 0; i < e; ++i) {
317  setColor(cols[i]);
318  glVertex2d(v[i].x(), v[i].y());
319  glVertex2d(v[i + 1].x(), v[i + 1].y());
320  }
321  glEnd();
322 }
323 
324 
325 void
326 GLHelper::drawLine(const Position& beg, const Position& end) {
327  glBegin(GL_LINES);
328  glVertex2d(beg.x(), beg.y());
329  glVertex2d(end.x(), end.y());
330  glEnd();
331 }
332 
333 
334 int
335 GLHelper::angleLookup(double angleDeg) {
336  const int numCoords = (int)myCircleCoords.size() - 1;
337  int index = ((int)(floor(angleDeg * CIRCLE_RESOLUTION + 0.5))) % numCoords;
338  if (index < 0) {
339  index += numCoords;
340  }
341  assert(index >= 0);
342  return (int)index;
343 }
344 
345 
346 void
347 GLHelper::drawFilledCircle(double width, int steps) {
348  drawFilledCircle(width, steps, 0, 360);
349 }
350 
351 
352 void
353 GLHelper::drawFilledCircle(double width, int steps, double beg, double end) {
354  if (myCircleCoords.size() == 0) {
355  for (int i = 0; i <= (int)(360 * CIRCLE_RESOLUTION); ++i) {
356  const double x = (double) sin(DEG2RAD(i / CIRCLE_RESOLUTION));
357  const double y = (double) cos(DEG2RAD(i / CIRCLE_RESOLUTION));
358  myCircleCoords.push_back(std::pair<double, double>(x, y));
359  }
360  }
361  const double inc = (end - beg) / (double)steps;
362  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
363  std::pair<double, double> p1 = myCircleCoords[angleLookup(beg)];
364 
365  for (int i = 0; i <= steps; ++i) {
366  const std::pair<double, double>& p2 = myCircleCoords[angleLookup(beg + i * inc)];
367  glBegin(GL_TRIANGLES);
368  glVertex2d(p1.first * width, p1.second * width);
369  glVertex2d(p2.first * width, p2.second * width);
370  glVertex2d(0, 0);
371  glEnd();
372  p1 = p2;
373  }
374 }
375 
376 
377 void
378 GLHelper::drawOutlineCircle(double width, double iwidth, int steps) {
379  drawOutlineCircle(width, iwidth, steps, 0, 360);
380 }
381 
382 
383 void
384 GLHelper::drawOutlineCircle(double width, double iwidth, int steps,
385  double beg, double end) {
386  if (myCircleCoords.size() == 0) {
387  for (int i = 0; i < 360; i += 10) {
388  double x = (double) sin(DEG2RAD(i));
389  double y = (double) cos(DEG2RAD(i));
390  myCircleCoords.push_back(std::pair<double, double>(x, y));
391  }
392  }
393  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
394  std::pair<double, double> p1 =
395  beg == 0 ? myCircleCoords[0] : myCircleCoords[((int) beg / 10) % 36];
396  for (int i = (int)(beg / 10); i < steps && (36.0 / (double) steps * (double) i) * 10 < end; i++) {
397  const std::pair<double, double>& p2 =
398  myCircleCoords[(int)(36.0 / (double) steps * (double) i)];
399  glBegin(GL_TRIANGLES);
400  glVertex2d(p1.first * width, p1.second * width);
401  glVertex2d(p2.first * width, p2.second * width);
402  glVertex2d(p2.first * iwidth, p2.second * iwidth);
403 
404  glVertex2d(p2.first * iwidth, p2.second * iwidth);
405  glVertex2d(p1.first * iwidth, p1.second * iwidth);
406  glVertex2d(p1.first * width, p1.second * width);
407  glEnd();
408  p1 = p2;
409  }
410  const std::pair<double, double>& p2 =
411  end == 360 ? myCircleCoords[0] : myCircleCoords[((int) end / 10) % 36];
412  glBegin(GL_TRIANGLES);
413  glVertex2d(p1.first * width, p1.second * width);
414  glVertex2d(p2.first * width, p2.second * width);
415  glVertex2d(p2.first * iwidth, p2.second * iwidth);
416 
417  glVertex2d(p2.first * iwidth, p2.second * iwidth);
418  glVertex2d(p1.first * iwidth, p1.second * iwidth);
419  glVertex2d(p1.first * width, p1.second * width);
420  glEnd();
421 }
422 
423 
424 void
426  double tLength, double tWidth) {
427  const double length = p1.distanceTo(p2);
428  if (length < tLength) {
429  tWidth *= length / tLength;
430  tLength = length;
431  }
432  Position rl(PositionVector::positionAtOffset(p1, p2, length - tLength));
433  glPushMatrix();
434  glTranslated(rl.x(), rl.y(), 0);
435  glRotated(-GeomHelper::naviDegree(p1.angleTo2D(p2)), 0, 0, 1);
436  glBegin(GL_TRIANGLES);
437  glVertex2d(0, tLength);
438  glVertex2d(-tWidth, 0);
439  glVertex2d(+tWidth, 0);
440  glEnd();
441  glPopMatrix();
442 }
443 
444 
445 void
447  glColor4ub(c.red(), c.green(), c.blue(), c.alpha());
448 }
449 
450 
451 RGBColor
453  GLdouble current[4];
454  glGetDoublev(GL_CURRENT_COLOR, current);
455  return RGBColor(static_cast<unsigned char>(current[0] * 255. + 0.5),
456  static_cast<unsigned char>(current[1] * 255. + 0.5),
457  static_cast<unsigned char>(current[2] * 255. + 0.5),
458  static_cast<unsigned char>(current[3] * 255. + 0.5));
459 }
460 
461 
462 void
465  myFont = nullptr;
466 }
467 
468 
469 bool
471  if (myFont == nullptr) {
473  if (myFont != nullptr) {
475  fonsSetFont(myFont, fontNormal);
476  fonsSetSize(myFont, (float)myFontSize);
477  }
478  }
479  return myFont != nullptr;
480 }
481 
482 
483 const std::vector<RGBColor>&
485  // check if more colors has to be added
486  while ((int)myDottedcontourColors.size() < size) {
489  } else {
491  }
492  }
493  return myDottedcontourColors;
494 }
495 
496 
497 void
498 GLHelper::drawText(const std::string& text, const Position& pos, const double layer, const double size,
499  const RGBColor& col, const double angle, const int align, double width) {
500  if (width <= 0) {
501  width = size;
502  }
503  if (!initFont()) {
504  return;
505  }
506  glPushMatrix();
507  glAlphaFunc(GL_GREATER, 0.5);
508  glEnable(GL_ALPHA_TEST);
509 #ifdef HAVE_GL2PS
510  if (myGL2PSActive) {
511  glRasterPos3d(pos.x(), pos.y(), layer);
512  GLfloat color[] = {col.red() / 255.f, col.green() / 255.f, col.blue() / 255.f, col.alpha() / 255.f};
513  gl2psTextOptColor(text.c_str(), "Roboto", 10, align == 0 ? GL2PS_TEXT_C : align, (GLfloat) - angle, color);
514  glPopMatrix();
515  return;
516  }
517 #endif
518  glTranslated(pos.x(), pos.y(), layer);
519  glScaled(width / myFontSize, size / myFontSize, 1.);
520  glRotated(-angle, 0, 0, 1);
521  fonsSetAlign(myFont, align == 0 ? FONS_ALIGN_CENTER | FONS_ALIGN_MIDDLE : align);
522  fonsSetColor(myFont, glfonsRGBA(col.red(), col.green(), col.blue(), col.alpha()));
523  fonsDrawText(myFont, 0., 0., text.c_str(), nullptr);
524  glPopMatrix();
525 }
526 
527 
528 void
530  const GUIVisualizationTextSettings& settings,
531  const std::string& text, const Position& pos,
532  const double scale,
533  const double angle,
534  const double layer,
535  const int align) {
536  drawTextBox(text, pos, layer,
537  settings.scaledSize(scale),
538  settings.color,
539  settings.bgColor,
541  angle, 0, 0.2, align);
542 }
543 
544 
545 void
546 GLHelper::drawTextBox(const std::string& text, const Position& pos,
547  const double layer, const double size,
548  const RGBColor& txtColor, const RGBColor& bgColor, const RGBColor& borderColor,
549  const double angle,
550  const double relBorder,
551  const double relMargin,
552  const int align) {
553  if (!initFont()) {
554  return;
555  };
556  if (bgColor.alpha() != 0) {
557  const double boxAngle = 90;
558  const double stringWidth = size / myFontSize * fonsTextBounds(myFont, 0, 0, text.c_str(), nullptr, nullptr);
559  const double borderWidth = size * relBorder;
560  const double boxHeight = size * (0.32 + 0.6 * relMargin);
561  const double boxWidth = stringWidth + size * relMargin;
562  glPushMatrix();
563  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
564  glTranslated(pos.x(), pos.y(), layer);
565  glRotated(-angle, 0, 0, 1);
566  Position left(-boxWidth * 0.5, 0);
567  setColor(borderColor);
568  drawBoxLine(left, boxAngle, boxWidth, boxHeight);
569  left.add(borderWidth * 1.5, 0);
570  setColor(bgColor);
571  glTranslated(0, 0, 0.01);
572  drawBoxLine(left, boxAngle, boxWidth - 3 * borderWidth, boxHeight - 2 * borderWidth);
573  glPopMatrix();
574  }
575  drawText(text, pos, layer + 0.02, size, txtColor, angle, align);
576 }
577 
578 
579 void
580 GLHelper::drawTextAtEnd(const std::string& text, const PositionVector& shape, double x,
581  const GUIVisualizationTextSettings& settings, const double scale) {
582  glPushMatrix();
583  const Position& end = shape.back();
584  const Position& f = shape[-2];
585  const double rot = RAD2DEG(atan2((end.x() - f.x()), (f.y() - end.y())));
586  glTranslated(end.x(), end.y(), 0);
587  glRotated(rot, 0, 0, 1);
588  drawTextBox(text, Position(x, 0.26), 0,
589  settings.scaledSize(scale, 0.01),
590  settings.color,
591  settings.bgColor,
593  180, 0, 0.2);
594  glPopMatrix();
595 }
596 
597 void
599  const std::vector<double>& rots,
600  const std::vector<double>& lengths,
601  double length, double spacing,
602  double halfWidth, bool drawForRectangleSelection) {
603  glPushMatrix();
604  // draw on top of of the white area between the rails
605  glTranslated(0, 0, 0.1);
606  int e = (int) geom.size() - 1;
607  for (int i = 0; i < e; ++i) {
608  glPushMatrix();
609  glTranslated(geom[i].x(), geom[i].y(), 0.0);
610  glRotated(rots[i], 0, 0, 1);
611  // draw crossing depending if isn't being drawn for selecting
612  if (!drawForRectangleSelection) {
613  for (double t = 0; t < lengths[i]; t += spacing) {
614  glBegin(GL_QUADS);
615  glVertex2d(-halfWidth, -t);
616  glVertex2d(-halfWidth, -t - length);
617  glVertex2d(halfWidth, -t - length);
618  glVertex2d(halfWidth, -t);
619  glEnd();
620  }
621  } else {
622  // only draw a single rectangle if it's being drawn only for selecting
623  glBegin(GL_QUADS);
624  glVertex2d(-halfWidth, 0);
625  glVertex2d(-halfWidth, -lengths.back());
626  glVertex2d(halfWidth, -lengths.back());
627  glVertex2d(halfWidth, 0);
628  glEnd();
629  }
630  // pop three draw matrix
631  glPopMatrix();
632  }
633  glPopMatrix();
634 }
635 
636 
637 void
638 GLHelper::debugVertices(const PositionVector& shape, double size, double layer) {
639  RGBColor color = RGBColor::randomHue();
640  for (int i = 0; i < (int)shape.size(); ++i) {
641  GLHelper::drawText(toString(i), shape[i], layer, size, color, 0);
642  }
643 }
644 
645 
646 void
648  glPushMatrix();
650  // draw on top
651  glTranslated(0, 0, 1024);
652  drawLine(Position(b.xmin(), b.ymax()), Position(b.xmax(), b.ymax()));
653  drawLine(Position(b.xmax(), b.ymax()), Position(b.xmax(), b.ymin()));
654  drawLine(Position(b.xmax(), b.ymin()), Position(b.xmin(), b.ymin()));
655  drawLine(Position(b.xmin(), b.ymin()), Position(b.xmin(), b.ymax()));
656  glPopMatrix();
657 }
658 
659 
660 /****************************************************************************/
#define CIRCLE_RESOLUTION
Definition: GLHelper.cpp:49
void APIENTRY combCallback(GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], GLdouble **dataOut)
Definition: GLHelper.cpp:60
#define DEG2RAD(x)
Definition: GeomHelper.h:35
#define RAD2DEG(x)
Definition: GeomHelper.h:36
unsigned int data_font_Roboto_Medium_ttf_len
Definition: Roboto.h:14362
unsigned char data_font_Roboto_Medium_ttf[]
Definition: Roboto.h:21
T MIN4(T a, T b, T c, T d)
Definition: StdDefs.h:100
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:29
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:129
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:117
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:135
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:123
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:81
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:638
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:647
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:100
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:598
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, const int align=0)
draw Text box with given parameters
Definition: GLHelper.cpp:546
static std::vector< std::pair< double, double > > myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
Definition: GLHelper.h:349
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:273
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:347
static struct FONScontext * myFont
Font context.
Definition: GLHelper.h:352
static void drawTextAtEnd(const std::string &text, const PositionVector &shape, double x, const GUIVisualizationTextSettings &settings, const double scale)
draw text and the end of shape
Definition: GLHelper.cpp:580
static void resetFont()
to be called when the font context is invalidated
Definition: GLHelper.cpp:463
static void drawOutlineCircle(double width, double iwidth, int steps=8)
Draws an unfilled circle around (0,0)
Definition: GLHelper.cpp:378
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:484
static std::vector< RGBColor > myDottedcontourColors
static vector with a list of alternated black/white colors (used for contourns)
Definition: GLHelper.h:359
static int angleLookup(double angleDeg)
normalize angle for lookup in myCircleCoords
Definition: GLHelper.cpp:335
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:181
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:452
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:425
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:135
static bool rightTurn(double angle1, double angle2)
whether the road makes a right turn (or goes straight)
Definition: GLHelper.cpp:168
static bool myGL2PSActive
whether we are currently rendering for gl2ps
Definition: GLHelper.h:356
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, const int align=0, double width=-1)
Definition: GLHelper.cpp:498
static bool initFont()
init myFont
Definition: GLHelper.cpp:470
static double myFontSize
Definition: GLHelper.h:353
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048, const int align=0)
Definition: GLHelper.cpp:529
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:192
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:231
double x() const
Returns the x-position.
Definition: Position.h:54
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:124
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position
Definition: Position.h:251
double y() const
Returns the y-position.
Definition: Position.h:59
A list of positions.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
static const RGBColor WHITE
Definition: RGBColor.h:187
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:52
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:73
static const RGBColor INVISIBLE
Definition: RGBColor.h:190
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:59
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:66
static const RGBColor BLACK
Definition: RGBColor.h:188
static const RGBColor MAGENTA
Definition: RGBColor.h:185
static RGBColor randomHue(double s=1, double v=1)
Return color with random hue.
Definition: RGBColor.cpp:329
@ FONS_ZERO_BOTTOMLEFT
Definition: fontstash.h:37
FONS_DEF void fonsSetSize(FONScontext *s, float size)
FONS_DEF float fonsDrawText(FONScontext *s, float x, float y, const char *string, const char *end)
FONS_DEF float fonsTextBounds(FONScontext *s, float x, float y, const char *string, const char *end, float *bounds)
@ FONS_ALIGN_MIDDLE
Definition: fontstash.h:47
@ FONS_ALIGN_CENTER
Definition: fontstash.h:43
FONS_DEF void fonsSetColor(FONScontext *s, unsigned int color)
FONS_DEF void fonsSetAlign(FONScontext *s, int align)
FONS_DEF int fonsAddFontMem(FONScontext *s, const char *name, unsigned char *data, int ndata, int freeData)
FONS_DEF void fonsSetFont(FONScontext *s, int font)
struct FONScontext FONScontext
Definition: fontstash.h:95
unsigned int glfonsRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void glfonsDelete(FONScontext *ctx)
FONScontext * glfonsCreate(int width, int height, int flags)
RGBColor bgColor
background text color
double scaledSize(double scale, double constFactor=0.1) const
get scale size