void ExportImageDialog::exportSvg(const QString &fileName) { SkyMap *map = m_KStars->map(); // export as SVG QSvgGenerator svgGenerator; svgGenerator.setFileName(fileName); svgGenerator.setTitle(i18n("KStars Exported Sky Image")); svgGenerator.setDescription(i18n("KStars Exported Sky Image")); svgGenerator.setSize(QSize(map->width(), map->height())); svgGenerator.setResolution(qMax(map->logicalDpiX(), map->logicalDpiY())); svgGenerator.setViewBox(QRect(0, 0, map->width(), map->height())); SkyQPainter painter(m_KStars, &svgGenerator); painter.begin(); map->exportSkyImage(&painter); if(m_DialogUI->addLegendCheckBox->isChecked()) { addLegend(&painter); } painter.end(); }
// read a video int Flux::display(bool legend, int (*callback)(Mat&)) { video.open(path+filename); if (!video.isOpened()) { cout << "Unable to open video " << filename << " in " << path << endl; return EXIT_FAILURE; } namedWindow(filename, CV_WINDOW_AUTOSIZE); Mat picture; while (video.read(picture)) { if (legend) addLegend(picture); if (callback != NULL) (*callback)(picture); imshow(filename, picture); if (waitKey(10) >= 0) break; } destroyWindow(filename); return EXIT_SUCCESS; }
NodeGraphicsScene::NodeGraphicsScene(QObject *parent) : CommonNodeGraphicsScene(parent) { init(); addLegend(); }
void ExportImageDialog::addLegend(QPaintDevice *pd) { SkyQPainter painter(m_KStars, pd); painter.begin(); addLegend(&painter); painter.end(); }
void Plot::updateSimulation() { const auto k = legend.keys(); const auto v = session->chart->series(); for (auto i : k) if (!v.contains(i)) delete legend.take(i); for (auto i : v) if (!k.contains(i)) addLegend(i); update(); }
//MAIN RENDER CODE ================================================ void DataGrid::render() { //vector<T> xData(_xData); //Assign xData to non-const so we can pass by const reference. // Add the border if flagged if (flags & (int)o_t::BORDER) { addBorder(); const int shrink = 4; plotArea.setSize(plotArea.getWidth()-shrink, plotArea.getHeight()-shrink); plotArea.translate(shrink/2, shrink/2); } // Add the title if flagged if (flags & (int)o_t::TITLE) { addTitle(); } // Abort if series vec is empty if (series.getNumSeries()==0){ cout << "No data series available, aborting. \n"; return; } // get ranges const float xMin = series.getXmin(); const float xMax = series.getXmax(); const float yMin = series.getYmin(); const float yMax = series.getYmax(); // Another way of aliasing - pointless here bu I <3 lambdas // To use this alternative, replace xMin with xMin() below // auto xMin = [&](){return series.getXmin();}; // Add the y-axis if flagged if (flags & (int)o_t::YAXIS) { const int yaxWidth = 10; Rectangle rAx = Rectangle(plotArea.getTL(), yaxWidth, plotArea.getHeight()); addYAxis(yMin, yMax, rAx); // Shift the plot area plotArea.setWidth(plotArea.getWidth()-yaxWidth); plotArea.translate(yaxWidth, 0); } // Add simple x-axis indicators if requested if (flags & (int)o_t::XAXIS) { addXAxis(xMin, xMax, plotArea); } for (size_t ii=0; ii<series.getNumSeries(); ++ii){ // Warn if input is messed up vector<float> xData(series.getXdata(ii)); vector<float> yData(series.getYdata(ii)); if (xData.size()!=yData.size()) { cout << "WARNING: x and y data size mismatch, not plotting.\n"; return; } for(size_t nn=0; nn<xData.size(); ++nn){ int intX = mapVal( xData[nn], xMin, xMax, plotArea.getLeft(), plotArea.getRight() ); // Notice the subtle reversal of yMax and yMin here so data flipped the correct way int intY = mapVal( yData[nn], yMax, yMin, plotArea.getTop(), plotArea.getBtm() ); addPoint(Point(intX, intY), series.getMarker(ii) ); } } // Add the legend if flagged if (flags & (int)o_t::LEGEND) { addLegend(); } } // End of rendering function
void ExportImageDialog::exportRasterGraphics(const QString &fileName) { //Determine desired image format from filename extension QString ext = fileName.mid(fileName.lastIndexOf(".") + 1); // export as raster graphics const char* format = "PNG"; if(ext.toLower() == "png") {format = "PNG";} else if(ext.toLower() == "jpg" || ext.toLower() == "jpeg" ) { format = "JPG"; } else if(ext.toLower() == "gif") { format = "GIF"; } else if(ext.toLower() == "pnm") { format = "PNM"; } else if(ext.toLower() == "bmp") { format = "BMP"; } else { kWarning() << i18n("Could not parse image format of %1; assuming PNG.", fileName); } int width = m_Size.width(); int height = m_Size.height(); SkyMap *map = m_KStars->map(); QPixmap skyimage(map->width(), map->height()); QPixmap outimage(width, height); outimage.fill(); map->exportSkyImage(&skyimage); qApp->processEvents(); //skyImage is the size of the sky map. The requested image size is w x h. //If w x h is smaller than the skymap, then we simply crop the image. //If w x h is larger than the skymap, pad the skymap image with a white border. if(width == map->width() && height == map->height()) { outimage = skyimage.copy(); } else { int dx(0), dy(0), sx(0), sy(0); int sw(map->width()), sh(map->height()); if(width > map->width()) { dx = (width - map->width())/2; } else { sx = (map->width() - width)/2; sw = width; } if(height > map->height()) { dy = (height - map->height())/2; } else { sy = (map->height() - height)/2; sh = height; } QPainter p; p.begin(&outimage); p.fillRect(outimage.rect(), QBrush( Qt::white)); p.drawImage(dx, dy, skyimage.toImage(), sx, sy, sw, sh); p.end(); } if(m_DialogUI->addLegendCheckBox->isChecked()) { addLegend(&outimage); } if(!outimage.save(fileName, format)) { kDebug() << i18n("Error: Unable to save image: %1 ", fileName); } else { kDebug() << i18n("Image saved to file: %1", fileName); } }
TrafficRoadCapabilityGraphicsScene::TrafficRoadCapabilityGraphicsScene(QObject *parent) : RoadGraphicsScene(parent) { init(); addLegend(); }