// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void StatsGenPlotWidget::createPowerCurve(int tableRow, float& xMax, float& yMax) { QwtPlotCurve* curve = m_PlotCurves[tableRow]; int err = 0; float alpha = m_TableModel->getDataValue(SGPowerLawTableModel::Alpha, tableRow); float k = m_TableModel->getDataValue(SGPowerLawTableModel::K, tableRow); float beta = m_TableModel->getDataValue(SGPowerLawTableModel::Beta, tableRow); int size = 256; QwtArray<float> x; QwtArray<float> y; err = StatsGen::GenPowerLawPlotData<QwtArray<float > > (alpha, k, beta, x, y, size); if (err == 1) { //TODO: Present Error Message return; } QwtArray<double> xD(size); QwtArray<double> yD(size); for (int i = 0; i < size; ++i) { // qDebug() << x[i] << " " << y[i] << "\n"; if (x[i] > xMax) { xMax = x[i]; } if (y[i] > yMax) { yMax = y[i]; } xD[i] = static_cast<double>(x[i]); yD[i] = static_cast<double>(y[i]); } #if QWT_VERSION >= 0x060000 curve->setSamples(xD, yD); #else curve->setData(xD, yD); #endif m_PlotView->setAxisScale(QwtPlot::yLeft, 0.0, yMax); m_PlotView->setAxisScale(QwtPlot::xBottom, 0.0, xMax); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void StatsGenRDFWidget::updateRDFPlot(QVector<float>& freqs) { // These are the output vectors QwtArray<double> xD(static_cast<int>(freqs.size())); QwtArray<double> yD(static_cast<int>(freqs.size())); QLocale loc = QLocale::system(); bool ok = false; float minDist = loc.toFloat(minDistLE->text(), &ok); float maxDist = loc.toFloat(maxDistLE->text(), &ok); const int numValues = freqs.size(); float increment = (maxDist - minDist) / numValues; double pos = minDist; for (qint32 i = 0; i < numValues; ++i) { xD[i] = pos; yD[i] = static_cast<double>(freqs.at(i)); pos = pos + increment; } // This will actually plot the XY data in the Qwt plot widget QwtPlotCurve* curve = m_PlotCurve; #if QWT_VERSION >= 0x060000 curve->setSamples(xD, yD); #else curve->setData(xD, yD); #endif curve->setStyle(QwtPlotCurve::Lines); //Use Antialiasing to improve plot render quality curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); QPen pen; pen.setColor(Qt::white); pen.setWidth(2); curve->setPen(pen);//Set colour and thickness for drawing the curve curve->attach(m_RDFPlot); m_RDFPlot->replot(); }
void Dialog::mkSensor() { QCPGraph * gr; QPen pn; int steps = (20) + 1; double stepTemp = 0.47; QVector<double> xLabels; QVector<double> yLabels; QVector<double> xD(steps), yD(steps),yDlin(steps); for (int x=0; x<steps; x++) { //xD[x] = 30.0 + (stepTemp * (double)x) + 0.5 * ((double)(100 - qrand()%200) / 100.0); xD[x] = 30.0 + x; yD[x] = 158 + floor( ((double)x / 0.47) + 1.5 * ((double)(100 - qrand()%200) / 100.0) ); yDlin[x] = 158.0 + ((double)x / 0.47); //if (((int)yD[x])%50 == 0) yLabels.push_back(yD[x]); //if (((int)xD[x])%10 == 0) xLabels.push_back(xD[x]); } for (int x=150; x<=210; x+=10) { yLabels.push_back(x); } for (int x=30; x<=50; x+=1) { xLabels.push_back(x); } qDebug() << yD; qDebug() << xD; gr = ui->plot->addGraph(); gr->setData(xD, yD); pn.setColor(Qt::red); pn.setWidth(3); gr->setPen(pn); gr = ui->plot->addGraph(); gr->setData(xD, yDlin); pn.setColor(0x008080); pn.setWidth(1); pn.setStyle(Qt::DashLine); gr->setPen(pn); ui->plot->xAxis->setLabel("Температура, °C"); ui->plot->xAxis->setRange(30, 50); ui->plot->xAxis->setAutoTicks(false); ui->plot->xAxis->setTickVector(xLabels); ui->plot->yAxis->setLabel("Сигнал АЦП"); ui->plot->yAxis->setRange(145, 215); ui->plot->yAxis->setAutoTicks(false); ui->plot->yAxis->setTickVector(yLabels); ui->plot->replot(); ui->plot->savePdf("graph-sensor.pdf", false, 800, 400); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void StatsGenMDFWidget::updateMDFPlot(QVector<float>& odf) { int err = 0; int size = 100000; // These are the input vectors QVector<float> angles; QVector<float> axes; QVector<float> weights; angles = m_MDFTableModel->getData(SGMDFTableModel::Angle); weights = m_MDFTableModel->getData(SGMDFTableModel::Weight); axes = m_MDFTableModel->getData(SGMDFTableModel::Axis); // These are the output vectors QVector<float> x; QVector<float> y; if ( Ebsd::CrystalStructure::Cubic_High == m_CrystalStructure ) { // Allocate a new vector to hold the mdf data QVector<float> mdf(CubicOps::k_MdfSize); // Calculate the MDF Data using the ODF data and the rows from the MDF Table model Texture::CalculateMDFData<float, CubicOps>(angles.data(), axes.data(), weights.data(), odf.data(), mdf.data(), static_cast<size_t>(angles.size())); // Now generate the actual XY point data that gets plotted. int npoints = 13; x.resize(npoints); y.resize(npoints); err = StatsGen::GenCubicMDFPlotData(mdf.data(), x.data(), y.data(), npoints, size); if (err < 0) { return; } } else if ( Ebsd::CrystalStructure::Hexagonal_High == m_CrystalStructure ) { // Allocate a new vector to hold the mdf data QVector<float> mdf(HexagonalOps::k_MdfSize); // Calculate the MDF Data using the ODF data and the rows from the MDF Table model Texture::CalculateMDFData<float, HexagonalOps>(angles.data(), axes.data(), weights.data(), odf.data(), mdf.data(), static_cast<size_t>(angles.size())); // Now generate the actual XY point data that gets plotted. int npoints = 20; x.resize(npoints); y.resize(npoints); err = StatsGen::GenHexMDFPlotData(mdf.data(), x.data(), y.data(), npoints, size); if (err < 0) { return; } } QwtArray<double> xD(static_cast<int>(x.size())); QwtArray<double> yD(static_cast<int>(x.size())); for (qint32 i = 0; i < x.size(); ++i) { xD[i] = static_cast<double>(x.at(i)); yD[i] = static_cast<double>(y.at(i)); } // This will actually plot the XY data in the Qwt plot widget QwtPlotCurve* curve = m_PlotCurve; #if QWT_VERSION >= 0x060000 curve->setSamples(xD, yD); #else curve->setData(xD, yD); #endif QColor color = QColor("DodgerBlue"); curve->setPen(color, 2); curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); curve->setStyle(QwtPlotCurve::Lines); QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::white ), QPen( color, 2 ), QSize( 8, 8 ) ); curve->setSymbol( symbol ); curve->attach(m_MDFPlot); m_MDFPlot->replot(); }