void FFT::output(const QString &text) { ApplicationWindow *app = (ApplicationWindow *)parent(); QString tableName = app->generateUniqueName(QString(objectName())); d_result_table = app->newHiddenTable(tableName, d_explanation, d_n, 5, text); if (d_graphics_display){ MultiLayer *ml = 0; if (!d_output_graph){ ml = createOutputGraph(); d_output_graph = ml->activeGraph(); } d_output_graph->setTitle(QString()); if (!d_inverse) d_output_graph->setXAxisTitle(tr("Frequency") + " (" + tr("Hz") + ")"); else d_output_graph->setXAxisTitle(tr("Time") + + " (" + tr("s") + ")"); d_output_graph->setYAxisTitle(tr("Amplitude")); d_output_graph->insertCurve(d_result_table, 0, tableName + "_" + tr("Amplitude"), 0); d_output_graph->setCurvePen(d_output_graph->curves() - 1, QPen(ColorBox::color(d_curveColorIndex), 1)); d_output_graph->replot(); if (ml) ml->showMaximized(); } }
void Correlation::addResultCurve() { int cols = d_table->tableCols(); int cols2 = cols+1; d_table->addCol(); d_table->addCol(); int n = d_table->tableRows()/2; for (int i = 0; i<d_table->tableRows(); i++) { double y = 0; if(i < n) y = d_x[d_n - n + i]; else y = d_x[i-n]; d_table->setText(i, cols, QString::number(i - n)); d_table->setText(i, cols2, QString::number(y)); } QStringList l = d_table->colNames().grep(tr("Lag")); QString id = QString::number((int)l.size()+1); QString label = name() + id; d_table->setColName(cols, tr("Lag") + id); d_table->setColName(cols2, label); d_table->setColPlotDesignation(cols, Table::X); d_table->setHeaderColType(); ApplicationWindow *app = (ApplicationWindow *)parent(); MultiLayer *ml = app->newGraph(name() + tr("Plot")); ml->activeGraph()->insertCurve(d_table, d_table->name() + "_" + label, 0); }
void FFT::output(QList<Column *> columns) { ApplicationWindow *app = (ApplicationWindow *)parent(); QString tableName = app->generateUniqueName(objectName()); Table *t = app->newHiddenTable(tableName, d_explanation, columns); MultiLayer *ml = app->multilayerPlot( t, QStringList() << tableName + "_" + tr("Amplitude"), 0); if (!ml) return; Graph *g = ml->activeGraph(); if (g) { g->setCurvePen(0, QPen(ColorBox::color(d_curveColorIndex), 1)); Plot *plot = g->plotWidget(); plot->setTitle(QString()); if (!d_inverse) plot->setAxisTitle(QwtPlot::xBottom, tr("Frequency") + " (" + tr("Hz") + ")"); else plot->setAxisTitle(QwtPlot::xBottom, tr("Time") + +" (" + tr("s") + ")"); plot->setAxisTitle(QwtPlot::yLeft, tr("Amplitude")); plot->replot(); } ml->showMaximized(); }
void Correlation::addResultCurve() { ApplicationWindow *app = (ApplicationWindow *)parent(); if (!app) return; int rows = d_table->numRows(); int cols = d_table->numCols(); int cols2 = cols+1; d_table->addCol(); d_table->addCol(); int n = rows/2; double x_temp[rows], y_temp[rows]; for (int i = 0; i<rows; i++) { x_temp[i] = i - n; if(i < n) y_temp[i] = d_x[d_n - n + i]; else y_temp[i] = d_x[i-n]; d_table->column(cols)->setValueAt(i, x_temp[i]); d_table->column(cols2)->setValueAt(i, y_temp[i]); } QStringList l = d_table->colNames().grep(tr("Lag")); QString id = QString::number((int)l.size()+1); QString label = name() + id; d_table->setColName(cols, tr("Lag") + id); d_table->setColName(cols2, label); d_table->setColPlotDesignation(cols, SciDAVis::X); MultiLayer *ml = app->newGraph(name() + tr("Plot")); if (!ml) return; DataCurve *c = new DataCurve(d_table, d_table->colName(cols), d_table->colName(cols2)); c->setData(x_temp, y_temp, rows); c->setPen(QPen(ColorBox::color(d_curveColorIndex), 1)); ml->activeGraph()->insertPlotItem(c, Graph::Line); ml->activeGraph()->updatePlot(); }
MultiLayer * Filter::createOutputGraph() { ApplicationWindow *app = dynamic_cast<ApplicationWindow *>(this->parent()); if (!app) { throw std::logic_error("Parent of Filter is not ApplicationWindow as expected."); } MultiLayer *ml = app->newGraph(objectName() + tr("Plot")); d_output_graph = ml->activeGraph(); return ml; }
/** Creates a MultiLayer graph and plots this MantidMatrix as a Spectrogram. @param type :: The "curve" type. @return Pointer to the created graph. */ MultiLayer *MantidMatrix::plotGraph2D(Graph::CurveType type) { if (numRows() == 1) { QMessageBox::critical(0, "MantidPlot - Error", "Cannot plot a workspace with only one spectrum."); return NULL; } QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); ApplicationWindow *a = applicationWindow(); MultiLayer *g = a->multilayerPlot(a->generateUniqueName(tr("Graph"))); attachMultilayer(g); //#799 fix for multiple dialog creation on double clicking/ on right click // menu scale on 2d plot // a->connectMultilayerPlot(g); Graph *plot = g->activeGraph(); plotSpectrogram(plot, a, type, false, NULL); // g->confirmClose(false); QApplication::restoreOverrideCursor(); return g; }
void FFT::output(const QString &text) { ApplicationWindow *app = (ApplicationWindow *)parent(); QString tableName = app->generateUniqueName(QString(name())); Table *t = app->newHiddenTable(tableName, d_explanation, d_n, 5, text); MultiLayer *ml = app->multilayerPlot(t, QStringList() << tableName + "_" + tr("Amplitude"), 0); if (!ml) return; Graph* g = ml->activeGraph(); if ( g ) { Plot* plot = g->plotWidget(); plot->setTitle(QString()); if (!d_inverse) plot->setAxisTitle(QwtPlot::xBottom, tr("Frequency") + " (" + tr("Hz") + ")"); else plot->setAxisTitle(QwtPlot::xBottom, tr("Time") + + " (" + tr("s") + ")"); plot->setAxisTitle(QwtPlot::yLeft, tr("Amplitude")); plot->replot(); } ml->showMaximized(); }
MultiLayer * Filter::createOutputGraph() { MultiLayer *ml = ((ApplicationWindow *)parent())->newGraph(objectName() + tr("Plot")); d_output_graph = ml->activeGraph(); return ml; }
void LineProfileTool::calculateLineProfile(const QPoint& start, const QPoint& end) { QRect rect = d_target->rect(); if (!rect.contains(start) || !rect.contains(end)){ QMessageBox::warning(d_graph, tr("QtiPlot - Pixel selection warning"), tr("Please select the end line point inside the image rectangle!")); return; } QPoint o = d_target->origin(); QPixmap pic = d_target->pixmap(); QImage image = pic.convertToImage(); int x1 = start.x()-o.x(); int x2 = end.x()-o.x(); int y1 = start.y()-o.y(); int y2 = end.y()-o.y(); QSize realSize = pic.size(); QSize actualSize = d_target->size(); if (realSize != actualSize){ double ratioX = (double)realSize.width()/(double)actualSize.width(); double ratioY = (double)realSize.height()/(double)actualSize.height(); x1 = int(x1*ratioX); x2 = int(x2*ratioX); y1 = int(y1*ratioY); y2 = int(y2*ratioY); } QString text = tr("pixel") + "\tx\ty\t" + tr("intensity") + "\n"; //uses the fast Bresenham's line-drawing algorithm #define sgn(x) ((x<0)?-1:((x>0)?1:0)) int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py,n; dx=x2-x1; //the horizontal distance of the line dy=y2-y1; //the vertical distance of the line dxabs=abs(dx); dyabs=abs(dy); sdx=sgn(dx); sdy=sgn(dy); x=dyabs>>1; y=dxabs>>1; px=x1; py=y1; if (dxabs>=dyabs){ //the line is more horizontal than vertical for(i=0;i<dxabs;i++){ y+=dyabs; if (y>=dxabs){ y-=dxabs; py+=sdy; } px+=sdx; n=dxabs; text+=QString::number(i)+"\t"; text+=QString::number(px)+"\t"; text+=QString::number(py)+"\t"; text+=QString::number(averageImagePixel(image, px, py, true))+"\n"; } } else {// the line is more vertical than horizontal for(i=0;i<dyabs;i++){ x+=dxabs; if (x>=dyabs){ x-=dyabs; px+=sdx; } py+=sdy; n=dyabs; text+=QString::number(i)+"\t"; text+=QString::number(px)+"\t"; text+=QString::number(py)+"\t"; text+=QString::number(averageImagePixel(image, px, py, false))+"\n"; } } Table *t = d_app->newTable(tr("Table") + "1", n, 4, text); MultiLayer* plot = d_app->multilayerPlot(t, QStringList(QString(t->objectName())+"_intensity"), 0); Graph *g = (Graph*)plot->activeGraph(); if (g){ g->setTitle(""); g->setXAxisTitle(tr("pixels")); g->setYAxisTitle(tr("pixel intensity (a.u.)")); } }