void GUISUMOAbstractView::displayLegend() { // compute the scale bar length size_t length = 1; const std::string text("10000000000"); size_t noDigits = 1; size_t pixelSize = (size_t) m2p((SUMOReal) length); while (pixelSize <= 20) { length *= 10; noDigits++; if (noDigits > text.length()) { return; } pixelSize = (size_t) m2p((SUMOReal) length); } SUMOReal lineWidth = 1.0; glLineWidth((SUMOReal) lineWidth); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // draw the scale bar glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); SUMOReal len = (SUMOReal) pixelSize / (SUMOReal)(getWidth() - 1) * (SUMOReal) 2.0; glColor3d(0, 0, 0); double o = double(15) / double(getHeight()); double o2 = o + o; double oo = double(5) / double(getHeight()); glBegin(GL_LINES); // vertical glVertex2d(-.98, -1. + o); glVertex2d(-.98 + len, -1. + o); // tick at begin glVertex2d(-.98, -1. + o); glVertex2d(-.98, -1. + o2); // tick at end glVertex2d(-.98 + len, -1. + o); glVertex2d(-.98 + len, -1. + o2); glEnd(); SUMOReal w = SUMOReal(35) / SUMOReal(getWidth()); SUMOReal h = SUMOReal(35) / SUMOReal(getHeight()); pfSetPosition(SUMOReal(-0.99), SUMOReal(1. - o2 - oo)); pfSetScaleXY(w, h); glRotated(180, 1, 0, 0); pfDrawString("0m"); glRotated(-180, 1, 0, 0); pfSetPosition(SUMOReal(-.99 + len), SUMOReal(1. - o2 - oo)); glRotated(180, 1, 0, 0); pfDrawString((text.substr(0, noDigits) + "m").c_str()); glRotated(-180, 1, 0, 0); // restore matrices glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
std::string GUISUMOAbstractView::makeSnapshot(const std::string& destFile) { std::string errorMessage; FXString ext = FXPath::extension(destFile.c_str()); const bool useGL2PS = ext == "ps" || ext == "eps" || ext == "pdf" || ext == "svg" || ext == "tex" || ext == "pgf"; #ifdef HAVE_FFMPEG const bool useVideo = destFile == "" || ext == "h264" || ext == "hevc"; #endif for (int i = 0; i < 10 && !makeCurrent(); ++i) { FXSingleEventThread::sleep(100); } // draw glClearColor( myVisualizationSettings->backgroundColor.red() / 255., myVisualizationSettings->backgroundColor.green() / 255., myVisualizationSettings->backgroundColor.blue() / 255., myVisualizationSettings->backgroundColor.alpha() / 255.); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if (myVisualizationSettings->dither) { glEnable(GL_DITHER); } else { glDisable(GL_DITHER); } if (myVisualizationSettings->antialiase) { glEnable(GL_BLEND); glEnable(GL_POLYGON_SMOOTH); glEnable(GL_LINE_SMOOTH); } else { glDisable(GL_BLEND); glDisable(GL_POLYGON_SMOOTH); glDisable(GL_LINE_SMOOTH); } applyGLTransform(); if (useGL2PS) { GLint format = GL2PS_PS; if (ext == "ps") { format = GL2PS_PS; } else if (ext == "eps") { format = GL2PS_EPS; } else if (ext == "pdf") { format = GL2PS_PDF; } else if (ext == "tex") { format = GL2PS_TEX; } else if (ext == "svg") { format = GL2PS_SVG; } else if (ext == "pgf") { format = GL2PS_PGF; } else { return "Could not save '" + destFile + "'.\n Unrecognized format '" + std::string(ext.text()) + "'."; } FILE* fp = fopen(destFile.c_str(), "wb"); if (fp == 0) { return "Could not save '" + destFile + "'.\n Could not open file for writing"; } GLint buffsize = 0, state = GL2PS_OVERFLOW; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); while (state == GL2PS_OVERFLOW) { buffsize += 1024 * 1024; gl2psBeginPage(destFile.c_str(), "sumo-gui; http://sumo.dlr.de", viewport, format, GL2PS_SIMPLE_SORT, GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT, GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.eps"); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); // compute lane width // draw decals (if not in grabbing mode) if (!myUseToolTips) { drawDecals(); if (myVisualizationSettings->showGrid) { paintGLGrid(); } } glLineWidth(1); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); Boundary viewPort = myChanger->getViewport(); float minB[2]; float maxB[2]; minB[0] = viewPort.xmin(); minB[1] = viewPort.ymin(); maxB[0] = viewPort.xmax(); maxB[1] = viewPort.ymax(); myVisualizationSettings->scale = m2p(SUMO_const_laneWidth); glEnable(GL_POLYGON_OFFSET_FILL); glEnable(GL_POLYGON_OFFSET_LINE); myGrid->Search(minB, maxB, *myVisualizationSettings); if (myVisualizationSettings->showSizeLegend) { displayLegend(); } state = gl2psEndPage(); glFinish(); } fclose(fp); } else { doPaintGL(GL_RENDER, myChanger->getViewport()); if (myVisualizationSettings->showSizeLegend) { displayLegend(); } swapBuffers(); glFinish(); FXColor* buf; FXMALLOC(&buf, FXColor, getWidth()*getHeight()); // read from the back buffer glReadBuffer(GL_BACK); // Read the pixels glReadPixels(0, 0, getWidth(), getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)buf); makeNonCurrent(); update(); // mirror size_t mwidth = getWidth(); size_t mheight = getHeight(); FXColor* paa = buf; FXColor* pbb = buf + mwidth * (mheight - 1); do { FXColor* pa = paa; paa += mwidth; FXColor* pb = pbb; pbb -= mwidth; do { FXColor t = *pa; *pa++ = *pb; *pb++ = t; } while (pa < paa); } while (paa < pbb); try { #ifdef HAVE_FFMPEG if (useVideo) { try { saveFrame(destFile, buf); errorMessage = "video"; } catch (std::runtime_error& err) { errorMessage = err.what(); } } else #endif if (!MFXImageHelper::saveImage(destFile, getWidth(), getHeight(), buf)) { errorMessage = "Could not save '" + destFile + "'."; } } catch (InvalidArgument& e) { errorMessage = "Could not save '" + destFile + "'.\n" + e.what(); } FXFREE(&buf); } return errorMessage; }
int GUIViewTraffic::doPaintGL(int mode, SUMOReal scale) { // init view settings glRenderMode(mode); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); GLdouble sxmin = myCX - myX1; GLdouble sxmax = myCX + myX1; GLdouble symin = myCY - myY1; GLdouble symax = myCY + myY1; // compute lane width ?? ACE ?? SUMOReal lw = m2p(3.0) * scale; // draw decals (if not in grabbing mode) if (!myUseToolTips) { drawDecals(); if (myVisualizationSettings->showGrid) { paintGLGrid(); } } glLineWidth(1); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); float minB[2]; float maxB[2]; minB[0] = sxmin; minB[1] = symin; maxB[0] = sxmax; maxB[1] = symax; myVisualizationSettings->needsGlID = myUseToolTips; myVisualizationSettings->scale = lw; glEnable(GL_POLYGON_OFFSET_FILL); glEnable(GL_POLYGON_OFFSET_LINE); int hits2 = myGrid->Search(minB, maxB, *myVisualizationSettings); // glTranslated(0, 0, -.01); for (std::vector<VehicleOps>::iterator i=myVehicleOps.begin(); i!=myVehicleOps.end(); ++i) { const VehicleOps &vo = *i; switch (vo.type) { case VO_SHOW_ROUTE: { if (vo.routeNo>=0) { drawRoute(vo, vo.routeNo, 0.25); } else { if (vo.vehicle->hasCORNIntValue(MSCORN::CORN_VEH_NUMBERROUTE)) { int noReroutePlus1 = vo.vehicle->getCORNIntValue(MSCORN::CORN_VEH_NUMBERROUTE) + 1; for (int i=noReroutePlus1-1; i>=0; i--) { SUMOReal darken = SUMOReal(0.4) / SUMOReal(noReroutePlus1) * SUMOReal(i); drawRoute(vo, i, darken); } } else { drawRoute(vo, 0, 0.25); } } } break; case VO_SHOW_BEST_LANES: { drawBestLanes(vo); break; } break; default: break; } } glTranslated(0, 0, .01); glPopMatrix(); /* // draw legends glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslated(1.-.2, 1.-.5, 0.); glScaled(.2, .5, 1.); GUIColoringSchemesMap<GUILaneWrapper> &sm = GUIViewTraffic::getLaneSchemesMap(); //!!! sm.getColorer(myVisualizationSettings->laneEdgeMode)->drawLegend(); */ return hits2; }