31#define FONTSTASH_IMPLEMENTATION
33#pragma warning(disable: 4505 5219)
36#pragma GCC diagnostic push
37#pragma GCC diagnostic ignored "-Wunused-function"
41#define GLFONTSTASH_IMPLEMENTATION
50#define CIRCLE_RESOLUTION (double)10
73 GLdouble* vertex_data[4],
74 GLfloat weight[4], GLdouble** dataOut) {
79 vertex = (GLdouble*)malloc(7 *
sizeof(GLdouble));
81 vertex[0] = coords[0];
82 vertex[1] = coords[1];
83 vertex[2] = coords[2];
91const std::vector<std::pair<double, double> >&
121#ifdef CHECK_ELEMENTCOUNTER
185 WRITE_WARNING(
"invalid matrix counter. Check that number of pushMatrix and popMatrix functions calls are the same");
196 WRITE_WARNING(
"invalid Name counter. Check that number of pushName and popName functions calls are the same");
208 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
210 for (PositionVector::const_iterator i = v.begin(); i != v.end(); i++) {
212 glVertex2d(p.
x(), p.
y());
213#ifdef CHECK_ELEMENTCOUNTER
219 glVertex2d(p.
x(), p.
y());
220#ifdef CHECK_ELEMENTCOUNTER
233 GLUtesselator* tobj = gluNewTess();
236#pragma warning(disable: 4191)
238#if defined(__GNUC__) && __GNUC__ >= 8
239#pragma GCC diagnostic push
240#pragma GCC diagnostic ignored "-Wcast-function-type"
242 gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid(
CALLBACK*)()) &glVertex3dv);
243 gluTessCallback(tobj, GLU_TESS_BEGIN, (GLvoid(
CALLBACK*)()) &glBegin);
244 gluTessCallback(tobj, GLU_TESS_END, (GLvoid(
CALLBACK*)()) &glEnd);
246#if defined(__GNUC__) && __GNUC__ >= 8
247#pragma GCC diagnostic pop
252 gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
253 gluTessBeginPolygon(tobj,
nullptr);
254 gluTessBeginContour(tobj);
255 double* points =
new double[(v.size() + int(close)) * 3];
257 for (
int i = 0; i != (int)v.size(); ++i) {
258 points[3 * i] = v[i].x();
259 points[3 * i + 1] = v[i].y();
260 points[3 * i + 2] = 0;
261 gluTessVertex(tobj, points + 3 * i, points + 3 * i);
264 const int i = (int)v.size();
265 points[3 * i] = v[0].x();
266 points[3 * i + 1] = v[0].y();
267 points[3 * i + 2] = 0;
268 gluTessVertex(tobj, points + 3 * i, points + 3 * i);
270 gluTessEndContour(tobj);
271 gluTessEndPolygon(tobj);
279 const double halfWidth = width * 0.5;
280 const double halfHeight = height * 0.5;
282 glTranslated(center.
x(), center.
y(), 0);
284 glVertex2d(-halfWidth, halfHeight);
285 glVertex2d(-halfWidth, -halfHeight);
286 glVertex2d(halfWidth, -halfHeight);
287 glVertex2d(halfWidth, halfHeight);
290#ifdef CHECK_ELEMENTCOUNTER
297 double width,
double offset) {
299 glTranslated(beg.
x(), beg.
y(), 0);
300 glRotated(rot, 0, 0, 1);
302 glVertex2d(-width - offset, 0);
303 glVertex2d(-width - offset, -visLength);
304 glVertex2d(width - offset, -visLength);
305 glVertex2d(width - offset, 0);
308#ifdef CHECK_ELEMENTCOUNTER
316 double rot,
double visLength,
319 glTranslated((beg2.
x() + beg1.
x())*.5, (beg2.
y() + beg1.
y())*.5, 0);
320 glRotated(rot, 0, 0, 1);
322 glVertex2d(-width, 0);
323 glVertex2d(-width, -visLength);
324 glVertex2d(width, -visLength);
325 glVertex2d(width, 0);
328#ifdef CHECK_ELEMENTCOUNTER
336 double delta = angle2 - angle1;
337 while (delta > 180) {
340 while (delta < -180) {
349 const std::vector<double>& rots,
350 const std::vector<double>& lengths,
351 double width,
int cornerDetail,
double offset) {
353 int e = (int) geom.size() - 1;
354 for (
int i = 0; i < e; i++) {
355 drawBoxLine(geom[i], rots[i], lengths[i], width, offset);
358 if (cornerDetail > 0) {
359 for (
int i = 1; i < e; i++) {
361 glTranslated(geom[i].x(), geom[i].y(), 0.1);
362 double angleBeg = -rots[i - 1];
363 double angleEnd = 180 - rots[i];
371 if (angleEnd - angleBeg > 360) {
374 if (angleEnd - angleBeg < -360) {
378 if (angleEnd > angleBeg) {
390 const std::vector<double>& rots,
391 const std::vector<double>& lengths,
392 const std::vector<RGBColor>& cols,
393 double width,
int cornerDetail,
double offset) {
394 int e = (int) geom.size() - 1;
395 for (
int i = 0; i < e; i++) {
397 drawBoxLine(geom[i], rots[i], lengths[i], width, offset);
399 if (cornerDetail > 0) {
400 for (
int i = 1; i < e; i++) {
403 glTranslated(geom[i].x(), geom[i].y(), 0);
414 const std::vector<double>& rots,
415 const std::vector<double>& lengths,
417 int minS = (int)
MIN4(rots.size(), lengths.size(), geom1.size(), geom2.size());
418 for (
int i = 0; i < minS; i++) {
428 drawBoxLines(geometry.getShape(), geometry.getShapeRotations(), geometry.getShapeLengths(), width);
435 glTranslated(beg.
x(), beg.
y(), 0);
436 glRotated(rot, 0, 0, 1);
439 glVertex2d(0, -visLength);
442#ifdef CHECK_ELEMENTCOUNTER
450 double rot,
double visLength) {
452 glTranslated((beg2.
x() + beg1.
x())*.5, (beg2.
y() + beg1.
y())*.5, 0);
453 glRotated(rot, 0, 0, 1);
456 glVertex2d(0, -visLength);
459#ifdef CHECK_ELEMENTCOUNTER
469 int e = (int) v.size() - 1;
470 for (
int i = 0; i < e; ++i) {
471 glVertex2d(v[i].x(), v[i].y());
472 glVertex2d(v[i + 1].x(), v[i + 1].y());
473#ifdef CHECK_ELEMENTCOUNTER
484 int e = (int) v.size() - 1;
485 for (
int i = 0; i < e; ++i) {
487 glVertex2d(v[i].x(), v[i].y());
488 glVertex2d(v[i + 1].x(), v[i + 1].y());
489#ifdef CHECK_ELEMENTCOUNTER
500 glVertex2d(beg.
x(), beg.
y());
501 glVertex2d(end.
x(), end.
y());
503#ifdef CHECK_ELEMENTCOUNTER
511 double beg,
double end) {
550 glVertex2d(-radius, radius);
551 glVertex2d(-radius, -radius);
552 glVertex2d(radius, -radius);
553 glVertex2d(radius, radius);
556#ifdef CHECK_ELEMENTCOUNTER
571 const double inc = (end - beg) / (
double)steps;
572 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
575 for (
int i = 0; i <= steps; ++i) {
577 glBegin(GL_TRIANGLES);
578 glVertex2d(p1.first * radius, p1.second * radius);
579 glVertex2d(p2.first * radius, p2.second * radius);
583#ifdef CHECK_ELEMENTCOUNTER
598 double beg,
double end) {
599 const double inc = (end - beg) / (
double)steps;
600 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
603 for (
int i = 0; i <= steps; ++i) {
605 glBegin(GL_TRIANGLES);
606 glVertex2d(p1.first * radius, p1.second * radius);
607 glVertex2d(p2.first * radius, p2.second * radius);
608 glVertex2d(p2.first * iRadius, p2.second * iRadius);
610 glVertex2d(p2.first * iRadius, p2.second * iRadius);
611 glVertex2d(p1.first * iRadius, p1.second * iRadius);
612 glVertex2d(p1.first * radius, p1.second * radius);
616#ifdef CHECK_ELEMENTCOUNTER
625 double tWidth,
const double extraOffset) {
627 if (length < tLength) {
628 tWidth *= length / tLength;
633 glTranslated(rl.
x(), rl.
y(), 0);
635 glTranslated(0, extraOffset, 0);
636 glBegin(GL_TRIANGLES);
637 glVertex2d(0, tLength);
638 glVertex2d(-tWidth, 0);
639 glVertex2d(+tWidth, 0);
642#ifdef CHECK_ELEMENTCOUNTER
657 glGetDoublev(GL_CURRENT_COLOR, current);
658 return RGBColor(
static_cast<unsigned char>(current[0] * 255. + 0.5),
659 static_cast<unsigned char>(current[1] * 255. + 0.5),
660 static_cast<unsigned char>(current[2] * 255. + 0.5),
661 static_cast<unsigned char>(current[3] * 255. + 0.5));
680 const double width,
const double length,
const bool vehicle) {
683 const RGBColor green(0, 255, 0, 255);
686 const double w = width / 2. - 0.1 * exaggeration;
687 const double h = length;
689 geom.push_back(
Position(-w, +0, 0.));
690 geom.push_back(
Position(+w, +0, 0.));
691 geom.push_back(
Position(+w, +h, 0.));
692 geom.push_back(
Position(-w, +h, 0.));
693 geom.push_back(
Position(-w, +0, 0.));
704 glTranslated(pos.
x(), pos.
y(), pos.
z());
706 glRotated(rotation, 0, 0, 1);
730const std::vector<RGBColor>&
752 const RGBColor& col,
const double angle,
const int align,
double width) {
760 glAlphaFunc(GL_GREATER, 0.5);
761 glEnable(GL_ALPHA_TEST);
764 glRasterPos3d(pos.
x(), pos.
y(), layer);
765 GLfloat color[] = {col.
red() / 255.f, col.
green() / 255.f, col.
blue() / 255.f, col.
alpha() / 255.f};
766 gl2psTextOptColor(text.c_str(),
"Roboto", 10, align == 0 ? GL2PS_TEXT_C : align, (GLfloat) - angle, color);
771 glTranslated(pos.
x(), pos.
y(), layer);
773 glRotated(-angle, 0, 0, 1);
784 const std::string& text,
const Position& pos,
794 angle, 0, 0.2, align);
800 const double layer,
const double size,
803 const double relBorder,
804 const double relMargin,
809 if (bgColor.
alpha() != 0) {
810 const double boxAngle = 90;
812 const double borderWidth = size * relBorder;
813 const double boxHeight = size * (0.32 + 0.6 * relMargin);
814 const double boxWidth = stringWidth + size * relMargin;
816 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
817 glTranslated(pos.
x(), pos.
y(), layer);
818 glRotated(-angle, 0, 0, 1);
822 left.
add(borderWidth * 1.5, 0);
824 glTranslated(0, 0, 0.01);
825 drawBoxLine(left, boxAngle, boxWidth - 3 * borderWidth, boxHeight - 2 * borderWidth);
828 drawText(text, pos, layer + 0.02, size, txtColor, angle, align);
838 const double rot =
RAD2DEG(atan2((end.
x() - f.
x()), (f.
y() - end.
y())));
839 glTranslated(end.
x(), end.
y(), 0);
840 glRotated(rot, 0, 0, 1);
853 const std::vector<double>& lengths,
double length,
double spacing,
854 double halfWidth,
double offset,
bool lessDetail) {
857 glTranslated(0, 0, 0.1);
858 int e = (int) geom.size() - 1;
859 for (
int i = 0; i < e; ++i) {
861 glTranslated(geom[i].x(), geom[i].y(), 0.0);
862 glRotated(rots[i], 0, 0, 1);
865 for (
double t = 0; t < lengths[i]; t += spacing) {
867 glVertex2d(-halfWidth - offset, -t);
868 glVertex2d(-halfWidth - offset, -t - length);
869 glVertex2d(halfWidth - offset, -t - length);
870 glVertex2d(halfWidth - offset, -t);
872#ifdef CHECK_ELEMENTCOUNTER
879 glVertex2d(-halfWidth - offset, 0);
880 glVertex2d(-halfWidth - offset, -lengths.back());
881 glVertex2d(halfWidth - offset, -lengths.back());
882 glVertex2d(halfWidth - offset, 0);
884#ifdef CHECK_ELEMENTCOUNTER
896 const std::vector<double>& rots,
897 const std::vector<double>& lengths,
898 double maxLength,
double spacing,
899 double halfWidth,
bool cl,
bool cr,
bool lefthand,
double scale) {
908 int e = (int) geom.size() - 1;
910 for (
int i = 0; i < e; ++i) {
912 glTranslated(geom[i].x(), geom[i].y(), 2.1);
913 glRotated(rots[i], 0, 0, 1);
915 for (t = offset; t < lengths[i]; t += spacing) {
916 const double length =
MIN2((
double)maxLength, lengths[i] - t);
919 glVertex2d(-mw, -t - length);
920 glVertex2d(-mw2, -t - length);
921 glVertex2d(-mw2, -t);
923#ifdef CHECK_ELEMENTCOUNTER
928 const double length2 =
MIN2((
double)6, lengths[i] - t);
930 glVertex2d(-halfWidth + 0.02, -t - length2);
931 glVertex2d(-halfWidth + 0.02, -t - length);
932 glVertex2d(-halfWidth - 0.02, -t - length);
933 glVertex2d(-halfWidth - 0.02, -t - length2);
935#ifdef CHECK_ELEMENTCOUNTER
940 offset = t - lengths[i] - spacing;
949 for (
int i = 0; i < (int)shape.size(); ++i) {
966 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 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 void resetVertexCounter()
reset vertex counter
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 drawOutlineCircle(double radius, double iRadius, int steps=8)
Draws an unfilled 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 (for debug purposes)
static void drawFilledCircle(const double widradiusth, const int steps=8)
Draws a filled 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 contours)
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 (for debug purposes)
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 int myMatrixCounterDebug
matrix counter (for debug purposes)
static void drawBoundary(const GUIVisualizationSettings &s, const Boundary &b)
Draw a boundary (used for debugging)
static RGBColor getColor()
gets the gl-color
static int getMatrixCounter()
get matrix counter
static void drawRectangle(const Position ¢er, const double width, const double height)
Draws a rectangle line.
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 (for debug purposes)
static void debugVertices(const PositionVector &shape, const GUIVisualizationTextSettings &settings, double scale, double layer=1024)
draw vertex numbers for the given shape (in a random color)
static void drawFilledCircleDetailled(const GUIVisualizationSettings::Detail d, const double radius)
Draws a filled circle around (0,0) depending of level of detail.
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 int getVertexCounter()
get vertex counter
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)
draw
static bool initFont()
init myFont
static int myVertexCounter
matrix counter (for debug purposes)
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 void drawCrossTies(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double length, double spacing, double halfWidth, double offset, bool lessDetail)
draw crossties for railroads or pedestrian crossings
static void resetMatrixCounter()
reset matrix counter
Stores the information about how to visualize structures.
bool drawBoundaries
enable or disable draw boundaries
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 dimensions
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 (in radians bet...
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
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
FONScontext * glfonsCreate(int width, int height, int flags)
unsigned int glfonsRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void glfonsDelete(FONScontext *ctx)
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
RGBColor bgColor
background text color
double scaledSize(double scale, double constFactor=0.1) const
get scale size