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
61 GLdouble* vertex_data[4],
62 GLfloat weight[4], GLdouble** dataOut) {
67 vertex = (GLdouble*)malloc(7 *
sizeof(GLdouble));
69 vertex[0] = coords[0];
70 vertex[1] = coords[1];
71 vertex[2] = coords[2];
85 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
87 for (PositionVector::const_iterator i = v.begin(); i != v.end(); i++) {
89 glVertex2d(p.
x(), p.
y());
93 glVertex2d(p.
x(), p.
y());
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];
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);
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);
127 gluTessEndContour(tobj);
128 gluTessEndPolygon(tobj);
136 double width,
double offset) {
138 glTranslated(beg.
x(), beg.
y(), 0);
139 glRotated(rot, 0, 0, 1);
141 glVertex2d(-width - offset, 0);
142 glVertex2d(-width - offset, -visLength);
143 glVertex2d(width - offset, -visLength);
144 glVertex2d(width - offset, 0);
152 double rot,
double visLength,
155 glTranslated((beg2.
x() + beg1.
x())*.5, (beg2.
y() + beg1.
y())*.5, 0);
156 glRotated(rot, 0, 0, 1);
158 glVertex2d(-width, 0);
159 glVertex2d(-width, -visLength);
160 glVertex2d(width, -visLength);
161 glVertex2d(width, 0);
169 double delta = angle2 - angle1;
170 while (delta > 180) {
173 while (delta < -180) {
182 const std::vector<double>& rots,
183 const std::vector<double>& lengths,
184 double width,
int cornerDetail,
double offset) {
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);
191 if (cornerDetail > 0) {
192 for (
int i = 1; i < e; i++) {
194 glTranslated(geom[i].x(), geom[i].y(), 0.1);
195 double angleBeg = -rots[i - 1];
196 double angleEnd = 180 - rots[i];
198 std::swap(angleBeg, angleEnd);
204 if (angleEnd - angleBeg > 360) {
207 if (angleEnd - angleBeg < -360) {
211 if (angleEnd > angleBeg) {
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++) {
230 drawBoxLine(geom[i], rots[i], lengths[i], width, offset);
232 if (cornerDetail > 0) {
233 for (
int i = 1; i < e; i++) {
236 glTranslated(geom[i].x(), geom[i].y(), 0);
248 const std::vector<double>& rots,
249 const std::vector<double>& lengths,
251 int minS = (int)
MIN4(rots.size(), lengths.size(), geom1.size(), geom2.size());
252 for (
int i = 0; i < minS; i++) {
260 int e = (int) geom.size() - 1;
261 for (
int i = 0; i < e; i++) {
275 glTranslated(beg.
x(), beg.
y(), 0);
276 glRotated(rot, 0, 0, 1);
279 glVertex2d(0, -visLength);
287 double rot,
double visLength) {
289 glTranslated((beg2.
x() + beg1.
x())*.5, (beg2.
y() + beg1.
y())*.5, 0);
290 glRotated(rot, 0, 0, 1);
293 glVertex2d(0, -visLength);
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());
315 int e = (int) v.size() - 1;
316 for (
int i = 0; i < e; ++i) {
318 glVertex2d(v[i].x(), v[i].y());
319 glVertex2d(v[i + 1].x(), v[i + 1].y());
328 glVertex2d(beg.
x(), beg.
y());
329 glVertex2d(end.
x(), end.
y());
361 const double inc = (end - beg) / (
double)steps;
362 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
365 for (
int i = 0; i <= steps; ++i) {
367 glBegin(GL_TRIANGLES);
368 glVertex2d(p1.first * width, p1.second * width);
369 glVertex2d(p2.first * width, p2.second * width);
385 double beg,
double end) {
387 for (
int i = 0; i < 360; i += 10) {
388 double x = (double) sin(
DEG2RAD(i));
389 double y = (double) cos(
DEG2RAD(i));
393 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
394 std::pair<double, double> p1 =
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 =
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);
404 glVertex2d(p2.first * iwidth, p2.second * iwidth);
405 glVertex2d(p1.first * iwidth, p1.second * iwidth);
406 glVertex2d(p1.first * width, p1.second * width);
410 const std::pair<double, double>& p2 =
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);
417 glVertex2d(p2.first * iwidth, p2.second * iwidth);
418 glVertex2d(p1.first * iwidth, p1.second * iwidth);
419 glVertex2d(p1.first * width, p1.second * width);
426 double tLength,
double tWidth) {
428 if (length < tLength) {
429 tWidth *= length / tLength;
434 glTranslated(rl.
x(), rl.
y(), 0);
436 glBegin(GL_TRIANGLES);
437 glVertex2d(0, tLength);
438 glVertex2d(-tWidth, 0);
439 glVertex2d(+tWidth, 0);
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));
483 const std::vector<RGBColor>&
499 const RGBColor& col,
const double angle,
const int align,
double width) {
507 glAlphaFunc(GL_GREATER, 0.5);
508 glEnable(GL_ALPHA_TEST);
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);
518 glTranslated(pos.
x(), pos.
y(), layer);
520 glRotated(-angle, 0, 0, 1);
531 const std::string& text,
const Position& pos,
541 angle, 0, 0.2, align);
547 const double layer,
const double size,
550 const double relBorder,
551 const double relMargin,
556 if (bgColor.
alpha() != 0) {
557 const double boxAngle = 90;
559 const double borderWidth = size * relBorder;
560 const double boxHeight = size * (0.32 + 0.6 * relMargin);
561 const double boxWidth = stringWidth + size * relMargin;
563 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
564 glTranslated(pos.
x(), pos.
y(), layer);
565 glRotated(-angle, 0, 0, 1);
569 left.
add(borderWidth * 1.5, 0);
571 glTranslated(0, 0, 0.01);
572 drawBoxLine(left, boxAngle, boxWidth - 3 * borderWidth, boxHeight - 2 * borderWidth);
575 drawText(text, pos, layer + 0.02, size, txtColor, angle, align);
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);
599 const std::vector<double>& rots,
600 const std::vector<double>& lengths,
601 double length,
double spacing,
602 double halfWidth,
bool drawForRectangleSelection) {
605 glTranslated(0, 0, 0.1);
606 int e = (int) geom.size() - 1;
607 for (
int i = 0; i < e; ++i) {
609 glTranslated(geom[i].x(), geom[i].y(), 0.0);
610 glRotated(rots[i], 0, 0, 1);
612 if (!drawForRectangleSelection) {
613 for (
double t = 0; t < lengths[i]; t += spacing) {
615 glVertex2d(-halfWidth, -t);
616 glVertex2d(-halfWidth, -t - length);
617 glVertex2d(halfWidth, -t - length);
618 glVertex2d(halfWidth, -t);
624 glVertex2d(-halfWidth, 0);
625 glVertex2d(-halfWidth, -lengths.back());
626 glVertex2d(halfWidth, -lengths.back());
627 glVertex2d(halfWidth, 0);
640 for (
int i = 0; i < (int)shape.size(); ++i) {
651 glTranslated(0, 0, 1024);
#define CIRCLE_RESOLUTION
void APIENTRY combCallback(GLdouble coords[3], GLdouble *vertex_data[4], GLfloat weight[4], GLdouble **dataOut)
unsigned int data_font_Roboto_Medium_ttf_len
unsigned char data_font_Roboto_Medium_ttf[]
T MIN4(T a, T b, T c, T d)
#define UNUSED_PARAMETER(x)
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 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
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 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 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 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 drawTriangleAtEnd(const Position &p1, const Position &p2, double tLength, double tWidth)
Draws a triangle at the end of the given line.
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
static bool rightTurn(double angle1, double angle2)
whether the road makes a right turn (or goes straight)
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 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 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