int main() { std::cout << "Hello world! This is a test program for outputting a gradient to a PPM image file." << std::endl; srand(time(NULL)); initGradient(); char *memblock; std::ofstream output; output.open("image.ppm", std::ios::binary); if (output.is_open()) { output << "P5\n" << img_width << " " << img_height << "\n" << 255 << "\n"; int size = img_width * img_height; memblock = new char[size]; for (int y = 0; y < img_height; ++y) { for (int x = 0; x < img_width; ++x) { getValue(Vector2(x, y)); } } normalizeArray(); for (int y = 0; y < img_height; ++y) { for (int x = 0; x < img_width; ++x) { std::cout << ImagePoints[x][y] << "\n"; } } for (int y = 0; y < img_height; ++y) { for (int x = 0; x < img_width; ++x) { memblock[(y * img_width) + x] = ImagePoints[x][y]; } } output.write(memblock, size); } else { std::cout << "Error opening file" << std::endl; } output.close(); return 0; }
arnTimeBasedVectorPlot::arnTimeBasedVectorPlot(QWidget *parent): QwtPlot(parent), d_paintedPoints(0), d_interval(0.0, 5.0) //CanvasInitialized(0) { d_directPainter = new QwtPlotDirectPainter(); grid = new QwtPlotGrid(); d_origin = new QwtPlotMarker(); d_curve = new QwtPlotCurve(); initCanvas(); initGradient(); }
Plot::Plot(QWidget *parent): QwtPlot(parent), d_paintedPoints(0), d_interval(0.0, 10.0), d_timerId(-1) { d_directPainter = new QwtPlotDirectPainter(); setAutoReplot(false); // The backing store is important, when working with widget // overlays ( f.e rubberbands for zooming ). // Here we don't have them and the internal // backing store of QWidget is good enough. canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, false); #if defined(Q_WS_X11) // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent // works on X11. This has a nice effect on the performance. canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); // Disabling the backing store of Qt improves the performance // for the direct painter even more, but the canvas becomes // a native window of the window system, receiving paint events // for resize and expose operations. Those might be expensive // when there are many points and the backing store of // the canvas is disabled. So in this application // we better don't both backing stores. if ( canvas()->testPaintAttribute( QwtPlotCanvas::BackingStore ) ) { canvas()->setAttribute(Qt::WA_PaintOnScreen, true); canvas()->setAttribute(Qt::WA_NoSystemBackground, true); } #endif initGradient(); plotLayout()->setAlignCanvasToScales(true); setAxisTitle(QwtPlot::xBottom, "Time [s]"); setAxisScale(QwtPlot::xBottom, d_interval.minValue(), d_interval.maxValue()); setAxisScale(QwtPlot::yLeft, -200.0, 200.0); QwtPlotGrid *grid = new QwtPlotGrid(); grid->setPen(QPen(Qt::gray, 0.0, Qt::DotLine)); grid->enableX(true); grid->enableXMin(true); grid->enableY(true); grid->enableYMin(false); grid->attach(this); d_origin = new QwtPlotMarker(); d_origin->setLineStyle(QwtPlotMarker::Cross); d_origin->setValue(d_interval.minValue() + d_interval.width() / 2.0, 0.0); d_origin->setLinePen(QPen(Qt::gray, 0.0, Qt::DashLine)); d_origin->attach(this); d_curve = new QwtPlotCurve(); d_curve->setStyle(QwtPlotCurve::Lines); d_curve->setPen(QPen(Qt::green)); #if 1 d_curve->setRenderHint(QwtPlotItem::RenderAntialiased, true); #endif #if 1 d_curve->setPaintAttribute(QwtPlotCurve::ClipPolygons, false); #endif d_curve->setData(new CurveData()); d_curve->attach(this); }
Plot::Plot(QWidget *parent): QwtPlot(parent), d_paintedPoints0(0), d_paintedPoints1(0), d_interval(0.0, 25.0), d_timerId(-1) { d_directPainter0 = new QwtPlotDirectPainter(); setAutoReplot(false); canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, false); #if defined(Q_WS_X11) canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); if ( canvas()->testPaintAttribute( QwtPlotCanvas::BackingStore ) ) { canvas()->setAttribute(Qt::WA_PaintOnScreen, true); canvas()->setAttribute(Qt::WA_NoSystemBackground, true); } #endif initGradient(); plotLayout()->setAlignCanvasToScales(true); setAxisTitle(QwtPlot::xBottom, "Time [s]"); setAxisScale(QwtPlot::xBottom, d_interval.minValue(), d_interval.maxValue()); setAxisScale(QwtPlot::yLeft, 0, 10.0); QwtPlotGrid *grid = new QwtPlotGrid(); grid->setPen(QPen(Qt::green, 0.0, Qt::DotLine)); grid->enableX(true); grid->enableXMin(true); grid->enableY(true); grid->enableYMin(false); grid->attach(this); d_origin = new QwtPlotMarker(); d_origin->setLineStyle(QwtPlotMarker::Cross); d_origin->setValue(d_interval.minValue() + d_interval.width() / 2.0, 0.0); d_origin->setLinePen(QPen(Qt::red, 0.0, Qt::DashLine)); d_origin->attach(this); d_curve0 = new QwtPlotCurve(); d_curve0->setStyle(QwtPlotCurve::Lines); d_curve0->setPen(QPen(Qt::green,3)); #if 1 d_curve0->setRenderHint(QwtPlotItem::RenderAntialiased, true); #endif #if 1 d_curve0->setPaintAttribute(QwtPlotCurve::ClipPolygons, false); #endif d_curve0->setData(new CurveData()); d_curve0->attach(this); d_curve1 = new QwtPlotCurve(); d_curve1->setStyle(QwtPlotCurve::Lines); d_curve1->setPen(QPen(Qt::red,3)); #if 1 d_curve1->setRenderHint(QwtPlotItem::RenderAntialiased, true); #endif #if 1 d_curve1->setPaintAttribute(QwtPlotCurve::ClipPolygons, false); #endif d_curve1->setData(new CurveData()); d_curve1->attach(this); }