void SetRange(QCustomPlot& plot, int index, QVariantMap range, QCPAxis::AxisType type)
{
	auto g = plot.graph(index);
	
	auto it = range.find("lo");
	if (it != range.end())
	{
		switch (type)
		{
		case QCPAxis::atLeft:
			g->valueAxis()->setRangeLower(it->toReal());
			break;
		case QCPAxis::atBottom:
			g->keyAxis()->setRangeLower(it->toReal());
			break;
		}
	}
	it = range.find("up");
	if (it != range.end())
	{
		switch (type)
		{
		case QCPAxis::atLeft:
			g->valueAxis()->setRangeUpper(it->toReal());
			break;
		case QCPAxis::atBottom:
			g->keyAxis()->setRangeUpper(it->toReal());
			break;
		}
	}
}
void MainWindow::addToPlot(std::vector<double> *x, std::vector<double> *y, int graphNum, AlgorithmFactory::ALGORITHM alg)
{
    QCustomPlot *cp = this->ui->plotter;

    QVector<double> __x = QVector<double>::fromStdVector(*x);
    QVector<double> __y = QVector<double>::fromStdVector(*y);

    cp->graph(graphNum)->setData(__x, __y);
    switch (alg)
    {
    default:
    case AlgorithmFactory::SPHERE:
        cp->graph(graphNum)->setName("Esfera");
        break;
    case AlgorithmFactory::ROTATED_RASTRIGIN:
        cp->graph(graphNum)->setName("Rot Rastrigin");
        break;
    case AlgorithmFactory::ROSENBROCK:
        cp->graph(graphNum)->setName("Rosenbrock");
        break;
    }
    cp->rescaleAxes(true);

    cp->replot();
}
Beispiel #3
0
bool TimeseriesGraph::update(const GRT::VectorDouble &sample ){

    if( !initialized ) return false;

    //Add the new sample to the buffer
    data.push_back( sample );

    //If the plot is hidden then there is no point in updating the graph
    if( this->isHidden() ){
        if( !lockRanges ){
            //Reset the min and max values
            minRange = 99e+99;
            maxRange = -minRange;
        }
        return true;
    }

    QCustomPlot *plot = ui->graph;

    //Clear any previous graphs
    plot->clearGraphs();

    //Get the data to plot
    QVector<double> x( graphWidth );
    vector< QVector<double> > y(numDimensions, QVector<double>(graphWidth) );

    for (unsigned int i=0; i<graphWidth; i++)
    {
      x[i] = i;
      for(unsigned int j=0; j<numDimensions; j++){
          y[j][i] = data[i][j];
          if( !lockRanges ){
            if( data[i][j] < minRange ) minRange = data[i][j];
            else if( data[i][j] > maxRange ) maxRange = data[i][j];
          }
      }
    }

    //Create the graphs
    for(unsigned int j=0; j<numDimensions; j++){
        plot->addGraph();
        plot->graph(j)->setPen( QPen( colors[j%colors.size()] ));
        plot->graph(j)->setData(x, y[j]);
    }

    // give the axes some labels:
    plot->xAxis->setLabel("Time");
    plot->yAxis->setLabel("Values");

    // set axes ranges, so we see all data:
    plot->xAxis->setRange(0, graphWidth);
    plot->yAxis->setRange(minRange, maxRange);
    plot->replot();

    return true;
}
Beispiel #4
0
void CurrencyPane::UpdateGraph(const QMap<double, double> map) {
    QCustomPlot* customPlot = ui->plotWidget;

    if (map.size() < 2) {
        customPlot->hide();
        return;
    }
    if (customPlot->isHidden()) {
        customPlot->show();
    }

    //customPlot->setBackground(Qt::transparent);

    double lastDate = map.lastKey();
    double weekAgo = QDateTime(QDate::currentDate()).addDays(-7).toTime_t();

    double highestVal = 0;
    if (!map.isEmpty()) {
        highestVal = from(map.values().toVector().toStdVector()).max();
    }

    if (customPlot->graphCount() > 0) {
        customPlot->removeGraph(0);
    }
    customPlot->addGraph();
    customPlot->graph()->setName("Net Worth");
    QPen pen;
    pen.setColor(QColor(0, 0, 255, 200));
    customPlot->graph()->setLineStyle(QCPGraph::lsLine);
    customPlot->graph()->setPen(pen);
    customPlot->graph()->setBrush(QBrush(QColor(255/4.0,160,50,150)));
    customPlot->graph()->setData(map.keys().toVector(), map.values().toVector());

    // configure bottom axis to show date and time instead of number:
    customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    customPlot->xAxis->setDateTimeFormat("ddd");
    // set a more compact font size for bottom and left axis tick labels:
    customPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 8));
    customPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 8));
    // set axis labels:
    customPlot->xAxis->setLabel("Date");
    customPlot->yAxis->setLabel("Total Worth in Chaos");
    // make top and right axes visible but without ticks and labels:
    customPlot->xAxis2->setVisible(true);
    customPlot->yAxis2->setVisible(true);
    customPlot->xAxis2->setTicks(false);
    customPlot->yAxis2->setTicks(false);
    customPlot->xAxis2->setTickLabels(false);
    customPlot->yAxis2->setTickLabels(false);
    // set axis ranges to show all data:
    customPlot->xAxis->setRange(weekAgo, lastDate);
    customPlot->yAxis->setRange(0, highestVal);
    // show legend:
    customPlot->legend->setVisible(true);
}
void MainWindow::initPlotter()
{
    QCustomPlot *cp = this->ui->plotter;
    cp->addGraph();
    cp->addGraph();
    cp->addGraph();
    cp->xAxis->setLabel("Epoch");
    cp->yAxis->setLabel("fitness");
    cp->graph(0)->setPen(QPen(Qt::blue));
    cp->graph(1)->setPen(QPen(Qt::red));
    cp->graph(2)->setPen(QPen(Qt::green));
    cp->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
    cp->setLocale(QLocale(QLocale::Portuguese, QLocale::Brazil));
    cp->legend->setVisible(true);
}
Beispiel #6
0
int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  QMainWindow window;
  
  // setup customPlot as central widget of window:
  QCustomPlot customPlot;
  window.setCentralWidget(&customPlot);
  
  // create plot (from quadratic plot example):
  QVector<double> x(101), y(101);
  for (int i=0; i<101; ++i)
  {
    x[i] = i/50.0 - 1;
    y[i] = x[i]*x[i];
  }
  customPlot.addGraph();
  customPlot.graph(0)->setData(x, y);
  customPlot.xAxis->setLabel(QLatin1String("x"));
  customPlot.yAxis->setLabel(QLatin1String("y"));
  customPlot.rescaleAxes();
  
  window.setGeometry(100, 100, 500, 400);
  window.show();
  return a.exec();
}
MissionElevationDisplay::MissionElevationDisplay(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MissionElevationDisplay),
    m_uasInterface(NULL),
    m_uasWaypointMgr(NULL),
    m_totalDistance(0),
    m_elevationData(NULL),
    m_useHomeAltOffset(false),
    m_homeAltOffset(0.0),
    m_elevationShown(false)
{
    ui->setupUi(this);

    ui->sampleSpinBox->setEnabled(false);

    QCustomPlot* customPlot = ui->customPlot;
    customPlot->addGraph(); // Mission Elevation Graph (ElevationGraphMissionId)
    customPlot->graph(ElevationGraphMissionId)->setPen(QPen(Qt::blue)); // line color blue for mission data
    customPlot->graph(ElevationGraphMissionId)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue

    customPlot->addGraph(); // Google Elevation Graph (ElevationGraphElevationId)
    customPlot->graph(ElevationGraphElevationId)->setPen(QPen(Qt::red)); // line color red for elevation data
    customPlot->graph(ElevationGraphElevationId)->setBrush(QBrush(QColor(255, 0, 0, 20))); // first graph will be filled with translucent blue
    customPlot->graph(ElevationGraphElevationId)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDiamond, 10));
    customPlot->xAxis->setLabel("distance (m)");
    customPlot->yAxis->setLabel("altitude (m)");
    // set default ranges for Alt and distance
    customPlot->xAxis->setRange(0,ElevationDefaultDistanceMax); //m
    customPlot->yAxis->setRange(ElevationDefaultAltMin,ElevationDefaultAltMax); //m

    QFont legendFont = font();
    legendFont.setPointSize(9);
    customPlot->legend->setFont(legendFont);

    // set a more compact font size for bottom and left axis tick labels:
    customPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 9));
    customPlot->xAxis->setLabelFont(QFont(QFont().family(), 9));
    customPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 9));
    customPlot->yAxis->setLabelFont(QFont(QFont().family(), 9));

    customPlot->replot();

    connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(activeUASSet(UASInterface*)));
    activeUASSet(UASManager::instance()->getActiveUAS());

    connect(ui->infoButton, SIGNAL(clicked()), this, SLOT(showInfoBox()));
}
Beispiel #8
0
void Graph::createGraph(const std::string& name, QColor color) {
    if (name.length() > 255) {
        std::cout << "LiveGrapher: Graph::createGraph(): "
                  << "name exceeds 255 characters" << std::endl;
        return;
    }
    m_dataSets.emplace_back();

    QCustomPlot* customPlot = m_window->m_ui->plot;
    customPlot->addGraph();
    customPlot->graph()->setName(QString::fromUtf8(name.c_str()));
    customPlot->graph()->setAntialiasedFill(false);
    customPlot->setNoAntialiasingOnDrag(true);

    QPen pen(color);
    customPlot->graph()->setPen(pen);
}
void CompassMotorCalibrationDialog::compassMotCalibration(mavlink_compassmot_status_t *compassmot_status)
{
    if (!m_uasInterface)
        return; // no active UAS.

    QCustomPlot* customPlot = ui->customPlot;

    int index = compassmot_status->throttle/10;
    customPlot->graph(GRAPH_ID_CURRENT)->addData(index, compassmot_status->current);
    customPlot->graph(GRAPH_ID_INTERFERENCE)->addData(index, compassmot_status->interference);
    customPlot->replot();

    x_scalar = compassmot_status->CompensationX;
    y_scalar = compassmot_status->CompensationY;
    z_scalar = compassmot_status->CompensationZ;

}
CompassMotorCalibrationDialog::CompassMotorCalibrationDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CompassMotorCalibrationDialog),
    m_uasInterface(NULL)
{
    ui->setupUi(this);

    QCustomPlot* customPlot = ui->customPlot;
    customPlot->addGraph();
    customPlot->graph(GRAPH_ID_INTERFERENCE)->setPen(QPen(GRAPH_COLOR_INTERFERENCE)); // line color blue for first graph
    customPlot->graph(GRAPH_ID_INTERFERENCE)->setBrush(QBrush(GRAPH_COLOR_INTERFERENCE_FILL)); // first graph will be filled with translucent blue

    customPlot->xAxis->setLabel("Throttle (%)");

    customPlot->yAxis->setLabel("Interference (%)");
    customPlot->yAxis->setLabelColor(GRAPH_COLOR_INTERFERENCE);
    customPlot->xAxis->setRange(0,100);
    customPlot->yAxis->setRange(0,100);

    customPlot->addGraph();
    customPlot->graph(GRAPH_ID_CURRENT)->setPen(QPen(GRAPH_COLOR_CURRENT)); // line color red for second graph
    customPlot->graph(GRAPH_ID_CURRENT)->setBrush(QBrush(GRAPH_COLOR_CURRENT_FILL));

    customPlot->yAxis2->setVisible(true);
    customPlot->yAxis2->setLabel("Amps (A)");
    customPlot->yAxis2->setLabelColor(GRAPH_COLOR_CURRENT);
    customPlot->xAxis2->setRange(0,100);
    customPlot->yAxis2->setRange(0,50);

    customPlot->replot();

    connect(ui->okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
    connect(this, SIGNAL(about), this, SLOT(rejected()));
    connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(activeUASSet(UASInterface*)));
    activeUASSet(UASManager::instance()->getActiveUAS());

    int ok = QMessageBox::warning(this, "Compass Motor Calibration", tr("CAUTION: Starting the compass motor calibration arms the motors.\n"
                                                               "Please make sure you have read and followed all instructions"
                                                               "before untertaking the calibration as serious injury could occur!"),
                         QMessageBox::Ok, QMessageBox::Cancel);
    if (ok == QMessageBox::Cancel){
        QTimer::singleShot(100, this, SLOT(cancelCalibration()));
    }

}
void viewGVpropertieslayout::refreshLog(logData * log) {
    if (log->setupFromXML()) {

        // find graphs from this log

        // get a list of the MDI windows
        QList<QMdiSubWindow *> subWins = viewGV->mdiarea->subWindowList();

        // loop and extract the plot
        for (int i = 0; i < subWins.size(); ++i) {
            QCustomPlot * currPlot = (QCustomPlot *) subWins[i]->widget();

            // loop through graphs in the plot
            for (int j = 0; j < currPlot->graphCount(); ++j) {

                // if the graph is from this log
                if (currPlot->graph(j)->property("source").toString() == log->logFileXMLname) {

                    // extract remaining graph data
                    QString type = currPlot->graph(j)->property("type").toString();

                    if (type == "linePlot") {

                        // get index
                        int index = currPlot->graph(j)->property("index").toInt();
                        log->plotLine(currPlot, index, j);

                    } else if (type == "rasterPlot") {

                        // get indices
                        QList < QVariant > indices = currPlot->graph(j)->property("indices").toList();
                        log->plotRaster(currPlot, indices, j);

                    }

                }

            }
        }


    } else
        return;
}
Beispiel #12
0
void ChartPage::addChartPoints()
{
    if (this->buildingChart)
        return;

    this->buildingChart=true;

    ClientModel *model = this->clientModel;
    QCustomPlot *customPlot = ui->chartBlock;

    // generate some data:
    QVector<double> x(250), y(250);
    int maxBlocks = 0;
    maxBlocks = model->getNumBlocks() - this->lastBlockHeight;
    if (maxBlocks == 0)
        return;
    if (maxBlocks > 250)
    {
          maxBlocks = 250;
    } else {
        this->timer->stop();
    }

    int i;
    for (i = 0; i < maxBlocks; i++)
    {
      CBlock blk = model->getBlock(i + this->lastBlockHeight);
      CBlockIndex* cIndex = model->getBlockIndex(i + this->lastBlockHeight);
      x[i]=blk.GetBlockTime();
      y[i]=model->getDiff(cIndex);

    }

    if (this->lastBlockHeight > 0) {
        customPlot->graph(0)->addData(x, y);
    } else {
        customPlot->graph(0)->setData(x, y);
    }

    customPlot->xAxis->setRange(x[i-1] - rangeChoice, x[i-1]);
    customPlot->replot();
    this->buildingChart=false;
    this->lastBlockHeight += i;
}
Beispiel #13
0
void Snakes::drawPlot(std::vector<double> inputX, std::vector<double> inputY) {

	QCustomPlot *customPlot = new QCustomPlot();
	customPlot->resize(500, 500);
	
	QVector<double> x = QVector<double>::fromStdVector(inputX);
	QVector<double> y = QVector<double>::fromStdVector(inputY);

	customPlot->addGraph();
	customPlot->graph(0)->setData(x, y);
	customPlot->xAxis->setLabel("x");
	customPlot->yAxis->setLabel("y");
	customPlot->xAxis->setRange(inputX.front(), inputX.back());
	customPlot->yAxis->setRange(inputY.front(), inputY.back());
	customPlot->replot();

	customPlot->show();
}
Beispiel #14
0
void MainWindow::runOptimization() {
	if (m_CostFunc.IsNull() || g_pointList.size() == 0) {
		return;
	}

    OptimizerParameters initialParams;
    ConvertListOfPointVectorsToParameters(g_pointList, initialParams);

	OptimizerProgress::Pointer progress = OptimizerProgress::New();
    progress->SetParticlesHistory(&g_pointHistory);
    
    OptimizerParameters result;
    if (ui.optiCG->isChecked()) {
        result = optimizeByFRPR(m_CostFunc, initialParams, progress);
    } else if (ui.optiGD->isChecked()) {
        result = optimizeByGD(m_CostFunc, initialParams, progress);
    } else if (ui.optiLBFGS->isChecked()) {
        result = optimizeByLBFGS(m_CostFunc, initialParams, progress);
    }

    // draw cost function
    ConvertParametersToListOfPointVectors(result, g_pointList.size(), g_pointList[0].size(), g_pointList);
    QVector<double> x(g_costHistory.size()), y(g_costHistory.size()); // initialize with entries 0..100
    for (int i = 0; i < x.count(); ++i)
    {
        x[i] = i;
        y[i] = g_costHistory[i];
    }

    QCustomPlot* customPlot = ui.customPlot;
    customPlot->clearGraphs();
    // create graph and assign data to it:
    customPlot->addGraph();
    customPlot->graph(0)->setData(x, y);
    customPlot->rescaleAxes();

    // give the axes some labels:
    customPlot->xAxis->setLabel("iteration");
    customPlot->yAxis->setLabel("cost");
    customPlot->replot();

	updateScene();
}
Beispiel #15
0
void MainWindow::maximizarGrafico1(QMouseEvent* e) {

    QVector<double> x(100);
    QVector<double> y(100);
    wgraficos *w = new wgraficos();
    w->exec();

    QCustomPlot * graph = w->getDatos();

    graph->addGraph();
    for (int i = 0; i < 100; ++i) {
        x[i] = i;
        y[i] = rand();
    }

    graph->graph(0)->setData(x,y);
    graph->replot();

}
void MainWindow::initPlot()
{
  QCustomPlot* customPlot = ui->customPlot;
  //QCPScatterStyle myScatter;
  //customPlot->addGraph(); // blue line
  //customPlot->graph(0)->setPen(QPen(Qt::blue));
  //customPlot->graph(0)->setAntialiasedFill(false);
  //customPlot->graph(0)->setLineStyle(QCPGraph::lsNone);
  //customPlot->graph(0)->setScatterStyle(QCPScatterStyle::ssDisc);
  //customPlot->graph(0)->setScatterStyle(QCPScatterStyle);
  customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, Qt::blue, Qt::transparent, radius));

  customPlot->xAxis->setRange(-1,1);
  customPlot->yAxis->setRange(-1,1);

  // make left and bottom axes transfer their ranges to right and top axes:
  //connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
  //connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));
}
void BasicGraph::Demo()
{
   QCustomPlot* customPlot = ui.basicGraph;

   // add two new graphs and set their look:
   customPlot->addGraph();
   customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
   customPlot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue
   customPlot->addGraph();
   customPlot->graph(1)->setPen(QPen(Qt::red)); // line color red for second graph
   // generate some points of data (y0 for first, y1 for second graph):
   QVector<double> x(250), y0(250), y1(250);
   for (int i = 0; i<250; ++i)
   {
      x[i] = i;
      y0[i] = exp(-i / 150.0)*cos(i / 10.0); // exponentially decaying cosine
      y1[i] = exp(-i / 150.0); // exponential envelope
   }
   // configure right and top axis to show ticks but no labels:
   // (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
   customPlot->xAxis2->setVisible(true);
   customPlot->xAxis2->setTickLabels(false);
   customPlot->yAxis2->setVisible(true);
   customPlot->yAxis2->setTickLabels(false);
   // make left and bottom axes always transfer their ranges to right and top axes:
   connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
   connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));
   // pass data points to graphs:
   customPlot->graph(0)->setData(x, y0);
   customPlot->graph(1)->setData(x, y1);
   // let the ranges scale themselves so graph 0 fits perfectly in the visible area:
   customPlot->graph(0)->rescaleAxes();
   // same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0):
   customPlot->graph(1)->rescaleAxes(true);
   // Note: we could have also just called customPlot->rescaleAxes(); instead
   // Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
   customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

   

   ExternalReplot();
}
BOOL BasicGraph::LoadCSVDataFile(QString filename, TimeSeriesData* pOutputData)
{
   int rc;
   char tempString[64];
   FILE* pFile;
   // errno_t err = fopen_s(&pFile, filename.toLatin1().data(), "rt");
   errno_t err = fopen_s(&pFile, "C:/trainingdata/8286/TimeSeries/Average_Z.csv", "rt");
   if (err == 13)
   {
      CJTRACE(TRACE_ERROR_LEVEL, "ERROR: Failed to open file: PERMISSION DENIED", filename.toLatin1().data());
      return FALSE;
   }
   else if (err != 0)
   {
      CJTRACE(TRACE_ERROR_LEVEL, "ERROR: Failed to open file. err=%d, file=%s", err, filename.toLatin1().data());
      return FALSE;
   }
   pOutputData->filename = filename;

   // Get data name
   fscanf_s(pFile, "%s", tempString, 64);
   pOutputData->name.fromLatin1(tempString);
   pOutputData->name.remove(0, 5);
   CJTRACE(TRACE_ERROR_LEVEL, "Loading data file: %s", filename.toLatin1().data());
   CJTRACE(TRACE_ERROR_LEVEL, "   Name:  %s", pOutputData->name.toLatin1().data());

   // Get time delta in X axis
   fscanf_s(pFile, "%s", tempString, 64);
   pOutputData->timedelta = atof(&tempString[6]);
   CJTRACE(TRACE_ERROR_LEVEL, "   Delta: %.10lf (sec)", pOutputData->timedelta);

   // Get first X axis value
   fscanf_s(pFile, "%s", tempString, 64);
   pOutputData->timestart = atof(&tempString[5]);
   CJTRACE(TRACE_ERROR_LEVEL, "   Start: %.10lf (sec)", pOutputData->timestart);

   // Get X axis label
   fscanf_s(pFile, "%s", tempString, 64);
   pOutputData->Xaxislabel.fromLatin1(tempString);
   pOutputData->Xaxislabel.remove(0, 7);
   CJTRACE(TRACE_ERROR_LEVEL, "   X Axis: %s", pOutputData->Xaxislabel.toLatin1().data());

   // Get Y axis label
   fscanf_s(pFile, "%s", tempString, 64);
   pOutputData->Yaxislabel.fromLatin1(tempString);
   pOutputData->Yaxislabel.remove(0, 7);
   CJTRACE(TRACE_ERROR_LEVEL, "   Y Axis: %s", pOutputData->Yaxislabel.toLatin1().data());

   while (strcmp(tempString, "Values") != 0)
   {
      fscanf_s(pFile, "%s", tempString, 64);  // Data Notes (skip for now)
   }
   
   // Get data values
   rc = 0;
   int count = 0;
   QVector<double> time(0); 
   double nextTime = pOutputData->timestart;

   while (rc != EOF)
   {
      rc = fscanf_s(pFile, "%s", tempString, 64);
      pOutputData->pData.append(atof(tempString));
      time.append(nextTime);
      nextTime += pOutputData->timedelta;
      count++;
      if ((count < 50) || (count % 500 == 0))
      CJTRACE(TRACE_ERROR_LEVEL, "   Value: %d, %.10lf", count, pOutputData->timedelta);
   }
   CJTRACE(TRACE_ERROR_LEVEL, "Data File Read (%d entries)", count);

   QCustomPlot* customPlot = ui.basicGraph;

   // add two new graphs and set their look:
   customPlot->addGraph();
   customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
   // configure right and top axis to show ticks but no labels:
   // (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
   customPlot->xAxis2->setVisible(true);
   customPlot->xAxis2->setTickLabels(false);
   customPlot->yAxis2->setVisible(true);
   customPlot->yAxis2->setTickLabels(false);
   // make left and bottom axes always transfer their ranges to right and top axes:
   connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
   connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));
   // pass data points to graphs:
   customPlot->graph(0)->setData(time, pOutputData->pData);

   // let the ranges scale themselves so graph 0 fits perfectly in the visible area:
   customPlot->graph(0)->rescaleAxes();
   // same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0):
   //customPlot->graph(1)->rescaleAxes(true);
   // Note: we could have also just called customPlot->rescaleAxes(); instead
   // Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
   customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

   ExternalReplot();

   return TRUE;
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QCustomPlot *customPlot = (QCustomPlot*) (ui->graph);
    // set locale to english, so we get english month names:
      customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom));
      // seconds of current time, we'll use it as starting point in time for data:
      double now = QDateTime::currentDateTime().toTime_t();
      srand(8); // set the random seed, so we always get the same random data
      // create multiple graphs:
      for (int gi=0; gi<5; ++gi)
      {
        customPlot->addGraph();
        QPen pen;
        pen.setColor(QColor(0, 0, 255, 200));
        customPlot->graph()->setLineStyle(QCPGraph::lsLine);
        customPlot->graph()->setPen(pen);
        customPlot->graph()->setBrush(QBrush(QColor(255/4.0*gi,160,50,150)));
        // generate random walk data:
        QVector<double> time(250), value(250);
        for (int i=0; i<250; ++i)
        {
          time[i] = now + 24*3600*i;
          if (i == 0)
            value[i] = (i/50.0+1)*(rand()/(double)RAND_MAX-0.5);
          else
            value[i] = fabs(value[i-1])*(1+0.02/4.0*(4-gi)) + (i/50.0+1)*(rand()/(double)RAND_MAX-0.5);
        }
        customPlot->graph()->setData(time, value);
      }
      // configure bottom axis to show date and time instead of number:
      customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
      customPlot->xAxis->setDateTimeFormat("MMMM\nyyyy");
      // set a more compact font size for bottom and left axis tick labels:
      customPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 8));
      customPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 8));
      // set a fixed tick-step to one tick per month:
      customPlot->xAxis->setAutoTickStep(false);
      customPlot->xAxis->setTickStep(2628000); // one month in seconds
      customPlot->xAxis->setSubTickCount(3);
      // apply manual tick and tick label for left axis:
      customPlot->yAxis->setAutoTicks(false);
      customPlot->yAxis->setAutoTickLabels(false);
      customPlot->yAxis->setTickVector(QVector<double>() << 5 << 55);
      customPlot->yAxis->setTickVectorLabels(QVector<QString>() << "Not so\nhigh" << "Very\nhigh");
      // set axis labels:
      customPlot->xAxis->setLabel("Date");
      customPlot->yAxis->setLabel("Random wobbly lines value");
      // make top and right axes visible but without ticks and labels:
      customPlot->xAxis2->setVisible(true);
      customPlot->yAxis2->setVisible(true);
      customPlot->xAxis2->setTicks(false);
      customPlot->yAxis2->setTicks(false);
      customPlot->xAxis2->setTickLabels(false);
      customPlot->yAxis2->setTickLabels(false);
      // set axis ranges to show all data:
      customPlot->xAxis->setRange(now, now+24*3600*249);
      customPlot->yAxis->setRange(0, 60);
      // show legend:
      customPlot->legend->setVisible(true);
}
Beispiel #20
0
bool FeaturePlot::plot(){

    if( !initialized ) return false;

    QCustomPlot *plot = ui->plot;

    //Clear any previous graphs
    plot->clearGraphs();

    const unsigned int M = data.getNumSamples();
    const unsigned int K = data.getNumClasses();
    const unsigned int N = data.getNumDimensions();
    GRT::Vector< GRT::MinMax > ranges = data.getRanges();
    GRT::Vector< unsigned int > classLabels = data.getClassLabels();
    GRT::Vector< GRT::ClassTracker > classTracker = data.getClassTracker();
    double minRange = GRT::grt_numeric_limits<double>::max();
    double maxRange = -minRange;

    //Add a new graph for each class
    for(unsigned int k=0; k<K; k++){
        const unsigned int numSamplesInClass = classTracker[k].counter;

        if( numSamplesInClass > 0 ){
            QVector< double > x( numSamplesInClass );
            QVector< double > y( numSamplesInClass );
            plot->addGraph();
            plot->graph(k)->setPen( QPen( classColors[ k % classColors.size() ] ) );
            plot->graph(k)->setLineStyle( QCPGraph::lsNone );
            plot->graph(k)->setScatterStyle( QCPScatterStyle(QCPScatterStyle::ssCross, 4) );

            unsigned int index = 0;
            for(unsigned int i=0; i<M; i++)
            {
                if( data[i].getClassLabel() == classTracker[k].classLabel ){
                    x[ index ] = data[i][ axisIndexX ];
                    y[ index ] = data[i][ axisIndexY ];
                    index++;

                    for(unsigned int j=0; j<N; j++){
                        if( data[i][j] > maxRange ){
                            maxRange = data[i][j];
                        }else if( data[i][j] < minRange ){
                            minRange = data[i][j];
                        }
                    }
                }
            }

            // pass data points to graphs:
            plot->graph( k )->setData(x, y);
        }
    }

    //Add 20% to the min and max range
    minRange += minRange * 0.2;
    maxRange += maxRange * 0.2;

    plot->xAxis->setVisible( true );
    plot->xAxis->setTickLabels( true );
    plot->yAxis->setVisible( true );
    plot->yAxis->setTickLabels( true );
    plot->xAxis->setLabel( QString::fromStdString("X Axis Index: "  + GRT::Util::toString(axisIndexX)) );
    plot->yAxis->setLabel( QString::fromStdString("Y Axis Index: "  + GRT::Util::toString(axisIndexY)) );
    plot->xAxis->setRange(minRange, maxRange);
    plot->yAxis->setRange(minRange, maxRange);
    plot->replot();

    plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

    return true;
}
void TCPStreamDialog::fillGraph()
{
    QCustomPlot *sp = ui->streamPlot;

    if (sp->graphCount() < 1) return;

    base_graph_->setLineStyle(QCPGraph::lsNone);
    tracer_->setGraph(NULL);

    // base_graph_ is always visible.
    for (int i = 0; i < sp->graphCount(); i++) {
        sp->graph(i)->clearData();
        sp->graph(i)->setVisible(i == 0 ? true : false);
    }

    base_graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, pkt_point_size_));

    sp->xAxis->setLabel(time_s_label_);
    sp->xAxis->setNumberFormat("gb");
    sp->xAxis->setNumberPrecision(6);
    sp->yAxis->setNumberFormat("f");
    sp->yAxis->setNumberPrecision(0);
    sp->yAxis2->setVisible(false);
    sp->yAxis2->setLabel(QString());

    if (!cap_file_) {
        QString dlg_title = QString(tr("No Capture Data"));
        setWindowTitle(dlg_title);
        title_->setText(dlg_title);
        sp->setEnabled(false);
        sp->yAxis->setLabel(QString());
        sp->replot();
        return;
    }

    ts_offset_ = 0;
    seq_offset_ = 0;
    bool first = true;
    guint64 bytes_fwd = 0;
    guint64 bytes_rev = 0;
    int pkts_fwd = 0;
    int pkts_rev = 0;

    time_stamp_map_.clear();
    for (struct segment *seg = graph_.segments; seg != NULL; seg = seg->next) {
        if (!compareHeaders(seg)) {
            bytes_rev += seg->th_seglen;
            pkts_rev++;
            continue;
        }
        bytes_fwd += seg->th_seglen;
        pkts_fwd++;
        double ts = seg->rel_secs + seg->rel_usecs / 1000000.0;
        if (first) {
            if (ts_origin_conn_) ts_offset_ = ts;
            if (seq_origin_zero_) seq_offset_ = seg->th_seq;
            first = false;
        }
        time_stamp_map_.insertMulti(ts - ts_offset_, seg);
    }

    switch (graph_.type) {
    case GRAPH_TSEQ_STEVENS:
        fillStevens();
        break;
    case GRAPH_TSEQ_TCPTRACE:
        fillTcptrace();
        break;
    case GRAPH_THROUGHPUT:
        fillThroughput();
        break;
    case GRAPH_RTT:
        fillRoundTripTime();
        break;
    case GRAPH_WSCALE:
        fillWindowScale();
        break;
    default:
        break;
    }
    sp->setEnabled(true);

    stream_desc_ = tr("%1 %2 pkts, %3 %4 %5 pkts, %6 ")
            .arg(UTF8_RIGHTWARDS_ARROW)
            .arg(gchar_free_to_qstring(format_size(pkts_fwd, format_size_unit_none|format_size_prefix_si)))
            .arg(gchar_free_to_qstring(format_size(bytes_fwd, format_size_unit_bytes|format_size_prefix_si)))
            .arg(UTF8_LEFTWARDS_ARROW)
            .arg(gchar_free_to_qstring(format_size(pkts_rev, format_size_unit_none|format_size_prefix_si)))
            .arg(gchar_free_to_qstring(format_size(bytes_rev, format_size_unit_bytes|format_size_prefix_si)));
    mouseMoved(NULL);
    resetAxes();
    tracer_->setGraph(base_graph_);

    // XXX QCustomPlot doesn't seem to draw any sort of focus indicator.
    sp->setFocus();
}
Beispiel #22
0
void ChartPage::setupChart()
{
  this->buildingChart=true;

  QCustomPlot *customPlot = ui->chartBlock;
  customPlot->setInteraction(QCP::iRangeDrag, true);
  customPlot->setInteraction(QCP::iSelectPlottables, true);
  customPlot->setInteraction(QCP::iSelectItems, true);
  customPlot->setInteraction(QCP::iRangeZoom, true);
  customPlot->legend->setVisible(true);
  customPlot->legend->setFont(QFont("Helvetica",9));
  // set locale to english, so we get english decimal separator:
  customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom));



  // create graph and assign data to it:
  customPlot->addGraph();
  customPlot->graph(0)->setName("Difficulty");
//  customPlot->graph(0)->setData(x, y);
  // give the axes some labels:
  customPlot->xAxis->setLabel("Date");
  customPlot->yAxis->setLabel("Difficulty");
  customPlot->legend->setSelectableParts(QCPLegend::spItems);
  customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables);
  customPlot->axisRect()->setupFullAxesBox();
  customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
  customPlot->xAxis->setDateTimeFormat("dd/MM/yyyy");
  customPlot->xAxis->setAutoTickCount(5);
  //customPlot->yAxis->setAutoTickCount(5);

  // set axes ranges, so we see all data:
  customPlot->yAxis->setRange(-0.1, 3);

  ClientModel *model = this->clientModel;
  // generate some data:
  QVector<double> x(1000), y(1000); //, y1(50000);
  int maxBlocks;
  maxBlocks = model->getNumBlocks();

  if (maxBlocks > 1000)
  {
        maxBlocks=1000;
  }

  int i = 0;
  if (maxBlocks > 0) {
      for (i = 0; i < maxBlocks; i++)
      {
        CBlock blk = model->getBlock(i);
        CBlockIndex* cIndex = model->getBlockIndex(i);
        x[i]=blk.GetBlockTime();
        y[i]=model->getDiff(cIndex);
      }
      customPlot->graph(0)->setData(x, y);
      customPlot->xAxis->setRange(x[i-1]-(60*60*24), x[i-1]);
      this->lastBlockHeight = i;
  }



  customPlot->replot();
  this->buildingChart=false;

}
// Fill in graph data based upon what was read into the rlc_graph struct.
void LteRlcGraphDialog::fillGraph()
{
    QCustomPlot *sp = ui->rlcPlot;

    // We should always have 4 graphs, but cover case if no channel was chosen.
    if (sp->graphCount() < 1) {
        return;
    }

    tracer_->setGraph(NULL);

    base_graph_->setLineStyle(QCPGraph::lsNone);       // dot
    reseg_graph_->setLineStyle(QCPGraph::lsNone);      // dot
    acks_graph_->setLineStyle(QCPGraph::lsStepLeft);   // to get step effect...
    nacks_graph_->setLineStyle(QCPGraph::lsNone);      // dot, but bigger.

    // Will show all graphs with data we find.
    for (int i = 0; i < sp->graphCount(); i++) {
        sp->graph(i)->clearData();
        sp->graph(i)->setVisible(true);
    }

    // N.B. ssDisc is really too slow. TODO: work out how to turn off aliasing, or experiment
    // with ssCustom.  Other styles tried didn't look right.
    // GTK version was speeded up noticibly by turning down aliasing level...
    base_graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, pkt_point_size_));
    reseg_graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, pkt_point_size_));
    acks_graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, pkt_point_size_));
    // NACKs are shown bigger than others.
    nacks_graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, pkt_point_size_*2));

    // Map timestamps -> segments in first pass.
    time_stamp_map_.clear();
    for (struct rlc_segment *seg = graph_.segments; seg != NULL; seg = seg->next) {
        if (!compareHeaders(seg)) {
            continue;
        }
        double ts = seg->rel_secs + seg->rel_usecs / 1000000.0;

        time_stamp_map_.insertMulti(ts, seg);
    }

    // Now sequence numbers.
    QVector<double> seq_time, seq,
                    reseg_seq_time, reseg_seq,
                    acks_time, acks,
                    nacks_time, nacks;
    for (struct rlc_segment *seg = graph_.segments; seg != NULL; seg = seg->next) {
        double ts = seg->rel_secs + seg->rel_usecs / 1000000.0;
        if (compareHeaders(seg)) {
            if (!seg->isControlPDU) {
                // Data
                if (seg->isResegmented) {
                    reseg_seq_time.append(ts);
                    reseg_seq.append(seg->SN);
                }
                else {
                    seq_time.append(ts);
                    seq.append(seg->SN);
                }
            }
            else {
                // Status (ACKs/NACKs)
                acks_time.append(ts);
                acks.append(seg->ACKNo-1);
                for (int n=0; n < seg->noOfNACKs; n++) {
                    nacks_time.append(ts);
                    nacks.append(seg->NACKs[n]);
                }
            }
        }
    }

    // Add the data from the graphs.
    base_graph_->setData(seq_time, seq);
    reseg_graph_->setData(reseg_seq_time, reseg_seq);
    acks_graph_->setData(acks_time, acks);
    nacks_graph_->setData(nacks_time, nacks);

    sp->setEnabled(true);

    // Auto-size...
    mouseMoved(NULL);
    resetAxes();

    tracer_->setGraph(base_graph_);

    // XXX QCustomPlot doesn't seem to draw any sort of focus indicator.
    sp->setFocus();
}
void convert::force(int nn,double D,double rho,double Cd,double Cm){
    // Define Pi
    //
    const double PI = 4.0*atan(1.0);


    // To cover-up for previous lazyness are we now making local
    // copies of the fields we need - sorry!
    //
    std::vector<double> tmp_;
    tmp_.resize(nt);
    for (int i=0;i<nt;i++){
        tmp_[i] = eta[i*nx*ny+nn];
    }

    // deta/dt
    //
    std::vector<double> detadt;
   detadt.resize(nt);
   gradient(detadt,tmp_,dt,nt);

    // dz/dt
    //
   Double2d dzdt(boost::extents[nz][nt]);
    for (int k=0;k<nz;k++){
        for (int i=0;i<nt;i++){
         dzdt[k][i] = detadt[i]*sigma[k];
        }
    }

    // du/dt on the sigma grid
    //
    Double2d dudt(boost::extents[nz][nt]);
    for (int k=0;k<nz;k++){
        for (int i=0;i<nt;i++){
            tmp_[i] = u[i*nx*ny*nz+nn*nz+k];
        }
        gradient(&dudt[k][0],tmp_,dt,nt); // To-do: this is super sluppy and error prone
     }



    // Acceleration
    //
    Double2d acc(boost::extents[nz][nt]);
    for (int k=0;k<nz;k++){
        for (int i=0;i<nt;i++){
            acc[k][i] = dudt[k][i]-uz[i*nx*ny*nz+nn*nz+k]*dzdt[k][i];
        }
    }

    // The inline force
    //
    double dz,Fd,Fi;
    int index;
    F.resize(nt);

    for (int i=0;i<nt;i++){
        F[i] = 0;
        for (int k=1;k<nz-1;k++){// we ignore the ghost points
            index = i*nx*ny*nz+nn*nz+k;
            dz = (sigma[k+1]-sigma[k])*(eta[i*nx*ny+nn]+h[nn]);

            Fd = 0.5*rho*Cd*D*(u[index]*std::abs(u[index])+u[index+1]*std::abs(u[index+1]))/2;
            Fi = rho*Cm*(PI/4)*pow(D,2)*(acc[k][i]+acc[k+1][i])/2;

            F[i] += (Fd+Fi)*dz;
        }

    }


    QFileInfo fileInfo =  QFileInfo(fileName);
    std::ofstream morisonForce;
    morisonForce.open(fileInfo.baseName().toLatin1() + ".force");
    morisonForce << "time F" << std::endl;
    QVector<double> QV_t,QV_F;
    QV_t.resize(nt);
    QV_F.resize(nt);
    for (int i=1;i<nt-1;i++){
        morisonForce << std::setiosflags(std::ios::fixed) << std::setprecision(10) << t[i] << " " << F[i] << std::endl;
        QV_t[i] = t[i];
        QV_F[i] = F[i];
    }
    morisonForce.close();

    // plot solution
    QCustomPlot *cPlot = new QCustomPlot;
    QWidget *plotWindow = new QWidget;
    QHBoxLayout *plotWindow_layout = new QHBoxLayout;
    plotWindow_layout->addWidget(cPlot);
    plotWindow->setLayout(plotWindow_layout);

    plotWindow->resize(800,400);

    plotWindow->show();
    cPlot->clearGraphs();

    cPlot->addGraph();
    cPlot->graph()->setData(QV_t,QV_F);
    cPlot->xAxis->setLabel("Time, t s");
    cPlot->yAxis->setLabel("Inline force, F N");
    QVector<double>::iterator Xmin = std::min_element(QV_t.begin(), QV_t.end());
    QVector<double>::iterator Xmax = std::max_element(QV_t.begin(), QV_t.end());
    QVector<double>::iterator Ymin = std::min_element(QV_F.begin(), QV_F.end());
    QVector<double>::iterator Ymax = std::max_element(QV_F.begin(), QV_F.end());
    cPlot->xAxis->setRange(*Xmin,*Xmax);
    cPlot->yAxis->setRange(*Ymin,*Ymax);
    cPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
    cPlot->replot();


}