30 #define FONTSTASH_IMPLEMENTATION
32 #pragma warning(disable: 4505)
35 #pragma GCC diagnostic push
36 #pragma GCC diagnostic ignored "-Wunused-function"
40 #define GLFONTSTASH_IMPLEMENTATION
49 #define CIRCLE_RESOLUTION (double)10
69 GLdouble* vertex_data[4],
70 GLfloat weight[4], GLdouble** dataOut) {
75 vertex = (GLdouble*)malloc(7 *
sizeof(GLdouble));
77 vertex[0] = coords[0];
78 vertex[1] = coords[1];
79 vertex[2] = coords[2];
87 const std::vector<std::pair<double, double> >&
153 WRITE_WARNING(
"invalid matrix counter. Check that number of pushMatrix and popMatrix functions calls are the same");
163 WRITE_WARNING(
"invalid Name counter. Check that number of pushName and popName functions calls are the same");
174 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
176 for (PositionVector::const_iterator i = v.begin(); i != v.end(); i++) {
178 glVertex2d(p.
x(), p.
y());
182 glVertex2d(p.
x(), p.
y());
193 GLUtesselator* tobj = gluNewTess();
194 #if defined(__GNUC__) && __GNUC__ >= 8
195 #pragma GCC diagnostic push
196 #pragma GCC diagnostic ignored "-Wcast-function-type"
198 gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid(
CALLBACK*)()) &glVertex3dv);
199 gluTessCallback(tobj, GLU_TESS_BEGIN, (GLvoid(
CALLBACK*)()) &glBegin);
200 gluTessCallback(tobj, GLU_TESS_END, (GLvoid(
CALLBACK*)()) &glEnd);
202 #if defined(__GNUC__) && __GNUC__ >= 8
203 #pragma GCC diagnostic pop
205 gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
206 gluTessBeginPolygon(tobj,
nullptr);
207 gluTessBeginContour(tobj);
208 double* points =
new double[(v.size() + int(close)) * 3];
210 for (
int i = 0; i != (int)v.size(); ++i) {
211 points[3 * i] = v[i].x();
212 points[3 * i + 1] = v[i].y();
213 points[3 * i + 2] = 0;
214 gluTessVertex(tobj, points + 3 * i, points + 3 * i);
217 const int i = (int)v.size();
218 points[3 * i] = v[0].x();
219 points[3 * i + 1] = v[0].y();
220 points[3 * i + 2] = 0;
221 gluTessVertex(tobj, points + 3 * i, points + 3 * i);
223 gluTessEndContour(tobj);
224 gluTessEndPolygon(tobj);
232 double width,
double offset) {
234 glTranslated(beg.
x(), beg.
y(), 0);
235 glRotated(rot, 0, 0, 1);
237 glVertex2d(-width - offset, 0);
238 glVertex2d(-width - offset, -visLength);
239 glVertex2d(width - offset, -visLength);
240 glVertex2d(width - offset, 0);
248 double rot,
double visLength,
251 glTranslated((beg2.
x() + beg1.
x())*.5, (beg2.
y() + beg1.
y())*.5, 0);
252 glRotated(rot, 0, 0, 1);
254 glVertex2d(-width, 0);
255 glVertex2d(-width, -visLength);
256 glVertex2d(width, -visLength);
257 glVertex2d(width, 0);
265 double delta = angle2 - angle1;
266 while (delta > 180) {
269 while (delta < -180) {
278 const std::vector<double>& rots,
279 const std::vector<double>& lengths,
280 double width,
int cornerDetail,
double offset) {
282 int e = (int) geom.size() - 1;
283 for (
int i = 0; i < e; i++) {
284 drawBoxLine(geom[i], rots[i], lengths[i], width, offset);
287 if (cornerDetail > 0) {
288 for (
int i = 1; i < e; i++) {
290 glTranslated(geom[i].x(), geom[i].y(), 0.1);
291 double angleBeg = -rots[i - 1];
292 double angleEnd = 180 - rots[i];
294 std::swap(angleBeg, angleEnd);
300 if (angleEnd - angleBeg > 360) {
303 if (angleEnd - angleBeg < -360) {
307 if (angleEnd > angleBeg) {
319 const std::vector<double>& rots,
320 const std::vector<double>& lengths,
321 const std::vector<RGBColor>& cols,
322 double width,
int cornerDetail,
double offset) {
323 int e = (int) geom.size() - 1;
324 for (
int i = 0; i < e; i++) {
326 drawBoxLine(geom[i], rots[i], lengths[i], width, offset);
328 if (cornerDetail > 0) {
329 for (
int i = 1; i < e; i++) {
332 glTranslated(geom[i].x(), geom[i].y(), 0);
344 const std::vector<double>& rots,
345 const std::vector<double>& lengths,
347 int minS = (int)
MIN4(rots.size(), lengths.size(), geom1.size(), geom2.size());
348 for (
int i = 0; i < minS; i++) {
356 int e = (int) geom.size() - 1;
357 for (
int i = 0; i < e; i++) {
371 glTranslated(beg.
x(), beg.
y(), 0);
372 glRotated(rot, 0, 0, 1);
375 glVertex2d(0, -visLength);
383 double rot,
double visLength) {
385 glTranslated((beg2.
x() + beg1.
x())*.5, (beg2.
y() + beg1.
y())*.5, 0);
386 glRotated(rot, 0, 0, 1);
389 glVertex2d(0, -visLength);
399 int e = (int) v.size() - 1;
400 for (
int i = 0; i < e; ++i) {
401 glVertex2d(v[i].x(), v[i].y());
402 glVertex2d(v[i + 1].x(), v[i + 1].y());
411 int e = (int) v.size() - 1;
412 for (
int i = 0; i < e; ++i) {
414 glVertex2d(v[i].x(), v[i].y());
415 glVertex2d(v[i + 1].x(), v[i + 1].y());
424 glVertex2d(beg.
x(), beg.
y());
425 glVertex2d(end.
x(), end.
y());
438 const double inc = (end - beg) / (
double)steps;
439 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
442 for (
int i = 0; i <= steps; ++i) {
444 glBegin(GL_TRIANGLES);
445 glVertex2d(p1.first * width, p1.second * width);
446 glVertex2d(p2.first * width, p2.second * width);
462 double beg,
double end) {
463 const double inc = (end - beg) / (
double)steps;
464 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
467 for (
int i = 0; i <= steps; ++i) {
469 glBegin(GL_TRIANGLES);
470 glVertex2d(p1.first * width, p1.second * width);
471 glVertex2d(p2.first * width, p2.second * width);
472 glVertex2d(p2.first * iwidth, p2.second * iwidth);
474 glVertex2d(p2.first * iwidth, p2.second * iwidth);
475 glVertex2d(p1.first * iwidth, p1.second * iwidth);
476 glVertex2d(p1.first * width, p1.second * width);
486 double tWidth,
const double extraOffset) {
488 if (length < tLength) {
489 tWidth *= length / tLength;
494 glTranslated(rl.
x(), rl.
y(), 0);
496 glTranslated(0, extraOffset, 0);
497 glBegin(GL_TRIANGLES);
498 glVertex2d(0, tLength);
499 glVertex2d(-tWidth, 0);
500 glVertex2d(+tWidth, 0);
515 glGetDoublev(GL_CURRENT_COLOR, current);
516 return RGBColor(
static_cast<unsigned char>(current[0] * 255. + 0.5),
517 static_cast<unsigned char>(current[1] * 255. + 0.5),
518 static_cast<unsigned char>(current[2] * 255. + 0.5),
519 static_cast<unsigned char>(current[3] * 255. + 0.5));
538 const double width,
const double length,
const bool vehicle) {
541 const RGBColor green(0, 255, 0, 255);
544 const double w = width / 2. - 0.1 * exaggeration;
545 const double h = length;
547 geom.push_back(
Position(-w, +0, 0.));
548 geom.push_back(
Position(+w, +0, 0.));
549 geom.push_back(
Position(+w, +h, 0.));
550 geom.push_back(
Position(-w, +h, 0.));
551 geom.push_back(
Position(-w, +0, 0.));
562 glTranslated(pos.
x(), pos.
y(), pos.
z());
564 glRotated(rotation, 0, 0, 1);
588 const std::vector<RGBColor>&
610 const RGBColor& col,
const double angle,
const int align,
double width) {
618 glAlphaFunc(GL_GREATER, 0.5);
619 glEnable(GL_ALPHA_TEST);
622 glRasterPos3d(pos.
x(), pos.
y(), layer);
623 GLfloat color[] = {col.
red() / 255.f, col.
green() / 255.f, col.
blue() / 255.f, col.
alpha() / 255.f};
624 gl2psTextOptColor(text.c_str(),
"Roboto", 10, align == 0 ? GL2PS_TEXT_C : align, (GLfloat) - angle, color);
629 glTranslated(pos.
x(), pos.
y(), layer);
631 glRotated(-angle, 0, 0, 1);
642 const std::string& text,
const Position& pos,
652 angle, 0, 0.2, align);
658 const double layer,
const double size,
661 const double relBorder,
662 const double relMargin,
667 if (bgColor.
alpha() != 0) {
668 const double boxAngle = 90;
670 const double borderWidth = size * relBorder;
671 const double boxHeight = size * (0.32 + 0.6 * relMargin);
672 const double boxWidth = stringWidth + size * relMargin;
674 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
675 glTranslated(pos.
x(), pos.
y(), layer);
676 glRotated(-angle, 0, 0, 1);
680 left.
add(borderWidth * 1.5, 0);
682 glTranslated(0, 0, 0.01);
683 drawBoxLine(left, boxAngle, boxWidth - 3 * borderWidth, boxHeight - 2 * borderWidth);
686 drawText(text, pos, layer + 0.02, size, txtColor, angle, align);
696 const double rot =
RAD2DEG(atan2((end.
x() - f.
x()), (f.
y() - end.
y())));
697 glTranslated(end.
x(), end.
y(), 0);
698 glRotated(rot, 0, 0, 1);
710 const std::vector<double>& rots,
711 const std::vector<double>& lengths,
712 double length,
double spacing,
713 double halfWidth,
bool drawForSelection) {
716 glTranslated(0, 0, 0.1);
717 int e = (int) geom.size() - 1;
718 for (
int i = 0; i < e; ++i) {
720 glTranslated(geom[i].x(), geom[i].y(), 0.0);
721 glRotated(rots[i], 0, 0, 1);
723 if (!drawForSelection) {
724 for (
double t = 0; t < lengths[i]; t += spacing) {
726 glVertex2d(-halfWidth, -t);
727 glVertex2d(-halfWidth, -t - length);
728 glVertex2d(halfWidth, -t - length);
729 glVertex2d(halfWidth, -t);
735 glVertex2d(-halfWidth, 0);
736 glVertex2d(-halfWidth, -lengths.back());
737 glVertex2d(halfWidth, -lengths.back());
738 glVertex2d(halfWidth, 0);
749 const std::vector<double>& rots,
750 const std::vector<double>& lengths,
751 double maxLength,
double spacing,
752 double halfWidth,
bool cl,
bool cr,
bool lefthand,
double scale) {
761 int e = (int) geom.size() - 1;
762 for (
int i = 0; i < e; ++i) {
764 glTranslated(geom[i].x(), geom[i].y(), 2.1);
765 glRotated(rots[i], 0, 0, 1);
766 for (
double t = 0; t < lengths[i]; t += spacing) {
767 const double length =
MIN2((
double)maxLength, lengths[i] - t);
770 glVertex2d(-mw, -t - length);
771 glVertex2d(-mw2, -t - length);
772 glVertex2d(-mw2, -t);
776 const double length2 =
MIN2((
double)6, lengths[i] - t);
778 glVertex2d(-halfWidth + 0.02, -t - length2);
779 glVertex2d(-halfWidth + 0.02, -t - length);
780 glVertex2d(-halfWidth - 0.02, -t - length);
781 glVertex2d(-halfWidth - 0.02, -t - length2);
794 for (
int i = 0; i < (int)shape.size(); ++i) {
805 glTranslated(0, 0, 1024);
void CALLBACK combCallback(GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], GLdouble **dataOut)
#define CIRCLE_RESOLUTION
#define WRITE_WARNING(msg)
static unsigned int data_font_Roboto_Medium_ttf_len
static unsigned char data_font_Roboto_Medium_ttf[]
T MIN4(T a, T b, T c, T d)
#define UNUSED_PARAMETER(x)
const double SUMO_const_laneMarkWidth
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A class that stores a 2D geometrical boundary.
double ymin() const
Returns minimum y-coordinate.
double xmin() const
Returns minimum x-coordinate.
double ymax() const
Returns maximum y-coordinate.
double xmax() const
Returns maximum x-coordinate.
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
static void debugVertices(const PositionVector &shape, double size, double layer=256)
draw vertex numbers for the given shape (in a random color)
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
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
static std::vector< std::pair< double, double > > myCircleCoords
Storage for precomputed sin/cos-values describing a circle.
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
static struct FONScontext * myFont
Font context.
static void drawTriangleAtEnd(const Position &p1, const Position &p2, double tLength, double tWidth, const double extraOffset=0)
Draws a triangle at the end of the given line.
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
static void resetFont()
to be called when the font context is invalidated
static void pushName(unsigned int name)
push Name
static void checkCounterMatrix()
check counter matrix
static void drawOutlineCircle(double width, double iwidth, int steps=8)
Draws an unfilled circle around (0,0)
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...
static std::vector< RGBColor > myDottedcontourColors
static vector with a list of alternated black/white colors (used for contourns)
static int angleLookup(double angleDeg)
normalize angle for lookup in myCircleCoords
static double getTextWidth(const std::string &text, double size)
get required width of text
static int myMatrixCounter
matrix counter
static void popMatrix()
pop matrix
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.
static RGBColor getColor()
gets the gl-color
static void drawCrossTies(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double length, double spacing, double halfWidth, bool drawForSelection)
draw crossties for railroads or pedestrian crossings
static const std::vector< std::pair< double, double > > & getCircleCoords()
Storage for precomputed sin/cos-values describing a circle.
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
static void checkCounterName()
check counter name
static void popName()
pop Name
static bool rightTurn(double angle1, double angle2)
whether the road makes a right turn (or goes straight)
static int myNameCounter
name counter
static void pushMatrix()
push matrix
static void setGL2PS(bool active=true)
set GL2PS
static void drawInverseMarkings(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double maxLength, double spacing, double halfWidth, bool cl, bool cr, bool lefthand, double scale)
@bried draw the space between markings (in road color)
static bool myGL2PSActive
whether we are currently rendering for gl2ps
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)
static void drawSpaceOccupancies(const double exaggeration, const Position &pos, const double rotation, const double width, const double length, const bool vehicle)
darw
static bool initFont()
init myFont
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)
static double naviDegree(const double angle)
A point in 2D or 3D with translation and scaling methods.
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
double x() const
Returns the x-position.
void add(const Position &pos)
Adds the given position to this one.
double z() const
Returns the z-position.
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position
double y() const
Returns the y-position.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
static const RGBColor WHITE
unsigned char red() const
Returns the red-amount of the color.
unsigned char alpha() const
Returns the alpha-amount of the color.
static const RGBColor INVISIBLE
unsigned char green() const
Returns the green-amount of the color.
unsigned char blue() const
Returns the blue-amount of the color.
static const RGBColor BLACK
static const RGBColor MAGENTA
static RGBColor randomHue(double s=1, double v=1)
Return color with random hue.
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_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
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