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); }
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(); }
QCustomPlot* Plots::createChart(QVector<double> x, QVector<double> y, QString chartName) { QCustomPlot* customPlot = new QCustomPlot(); // create and configure plottables: QCPBars *bars1 = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(bars1); bars1->setWidth(0.3); bars1->setData(x, y); bars1->setPen(QPen(Qt::red)); bars1->setBrush(QColor(10, 140, 70, 160)); // set title of plot: customPlot->plotLayout()->insertRow(0); customPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(customPlot, chartName)); // set a fixed tick-step to one tick per year value: customPlot->xAxis->setAutoTickStep(false); customPlot->xAxis->setTickStep(1); customPlot->xAxis->setSubTickCount(3); // set a fixed tick-step to one tick per колво value: customPlot->yAxis->setAutoTickStep(false); customPlot->yAxis->setTickStep(10); customPlot->yAxis->setSubTickCount(3); // labels customPlot->xAxis->setLabel("Год"); customPlot->yAxis->setLabel("% человек"); customPlot->yAxis->setLabelColor(Qt::white); customPlot->xAxis->setLabelColor(Qt::white); // move bars above graphs and grid below bars: customPlot->addLayer("abovemain", customPlot->layer("main"), QCustomPlot::limAbove); customPlot->addLayer("belowmain", customPlot->layer("main"), QCustomPlot::limBelow); bars1->setLayer("abovemain"); customPlot->xAxis->grid()->setLayer("belowmain"); customPlot->yAxis->grid()->setLayer("belowmain"); // set some pens, brushes and backgrounds: customPlot->xAxis->setBasePen(QPen(Qt::white, 1)); customPlot->yAxis->setBasePen(QPen(Qt::white, 1)); customPlot->xAxis->setTickPen(QPen(Qt::white, 1)); customPlot->yAxis->setTickPen(QPen(Qt::white, 1)); customPlot->xAxis->setSubTickPen(QPen(Qt::white, 1)); customPlot->yAxis->setSubTickPen(QPen(Qt::white, 1)); customPlot->xAxis->setTickLabelColor(Qt::white); customPlot->yAxis->setTickLabelColor(Qt::white); customPlot->xAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine)); customPlot->yAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine)); customPlot->xAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine)); customPlot->yAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine)); customPlot->xAxis->grid()->setSubGridVisible(true); customPlot->yAxis->grid()->setSubGridVisible(true); customPlot->xAxis->grid()->setZeroLinePen(Qt::NoPen); customPlot->yAxis->grid()->setZeroLinePen(Qt::NoPen); customPlot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow); customPlot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow); QLinearGradient plotGradient; plotGradient.setStart(0, 0); plotGradient.setFinalStop(0, 350); plotGradient.setColorAt(0, QColor(80, 80, 80)); plotGradient.setColorAt(1, QColor(50, 50, 50)); customPlot->setBackground(plotGradient); QLinearGradient axisRectGradient; axisRectGradient.setStart(0, 0); axisRectGradient.setFinalStop(0, 350); axisRectGradient.setColorAt(0, QColor(80, 80, 80)); axisRectGradient.setColorAt(1, QColor(30, 30, 30)); customPlot->axisRect()->setBackground(axisRectGradient); customPlot->rescaleAxes(); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); return customPlot; }
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; }
SequenceDialog::SequenceDialog(QWidget &parent, CaptureFile &cf, seq_analysis_info_t *sainfo) : WiresharkDialog(parent, cf), ui(new Ui::SequenceDialog), sainfo_(sainfo), num_items_(0), packet_num_(0), node_label_w_(20) { ui->setupUi(this); QCustomPlot *sp = ui->sequencePlot; setWindowSubtitle(sainfo ? tr("Call Flow") : tr("Flow")); if (!sainfo_) { sainfo_ = sequence_analysis_info_new(); sainfo_->type = SEQ_ANALYSIS_ANY; sainfo_->all_packets = TRUE; } else { num_items_ = sequence_analysis_get_nodes(sainfo_); } seq_diagram_ = new SequenceDiagram(sp->yAxis, sp->xAxis2, sp->yAxis2); sp->addPlottable(seq_diagram_); sp->axisRect()->setRangeDragAxes(sp->xAxis2, sp->yAxis); sp->xAxis->setVisible(false); sp->xAxis->setPadding(0); sp->xAxis->setLabelPadding(0); sp->xAxis->setTickLabelPadding(0); sp->xAxis2->setVisible(true); sp->yAxis2->setVisible(true); one_em_ = QFontMetrics(sp->yAxis->labelFont()).height(); ui->horizontalScrollBar->setSingleStep(100 / one_em_); ui->verticalScrollBar->setSingleStep(100 / one_em_); sp->setInteractions(QCP::iRangeDrag); ui->gridLayout->setSpacing(0); connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), sp->yAxis2, SLOT(setRange(QCPRange))); ctx_menu_.addAction(ui->actionReset); ctx_menu_.addSeparator(); ctx_menu_.addAction(ui->actionMoveRight10); ctx_menu_.addAction(ui->actionMoveLeft10); ctx_menu_.addAction(ui->actionMoveUp10); ctx_menu_.addAction(ui->actionMoveDown10); ctx_menu_.addAction(ui->actionMoveRight1); ctx_menu_.addAction(ui->actionMoveLeft1); ctx_menu_.addAction(ui->actionMoveUp1); ctx_menu_.addAction(ui->actionMoveDown1); ctx_menu_.addSeparator(); ctx_menu_.addAction(ui->actionGoToPacket); ui->showComboBox->blockSignals(true); ui->showComboBox->setCurrentIndex(0); ui->showComboBox->blockSignals(false); ui->addressComboBox->blockSignals(true); ui->addressComboBox->setCurrentIndex(0); ui->addressComboBox->blockSignals(false); QComboBox *fcb = ui->flowComboBox; fcb->addItem(ui->actionFlowAny->text(), SEQ_ANALYSIS_ANY); fcb->addItem(ui->actionFlowTcp->text(), SEQ_ANALYSIS_TCP); ui->flowComboBox->blockSignals(true); ui->flowComboBox->setCurrentIndex(sainfo_->type); if (sainfo_->type == SEQ_ANALYSIS_VOIP) { ui->controlFrame->hide(); } else { ui->flowComboBox->blockSignals(false); } QPushButton *save_bt = ui->buttonBox->button(QDialogButtonBox::Save); save_bt->setText(tr("Save As" UTF8_HORIZONTAL_ELLIPSIS)); // XXX Use recent settings instead resize(parent.width(), parent.height() * 4 / 5); connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(hScrollBarChanged(int))); connect(ui->verticalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(vScrollBarChanged(int))); connect(sp->xAxis2, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisChanged(QCPRange))); connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(yAxisChanged(QCPRange))); connect(sp, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(diagramClicked(QMouseEvent*))); connect(sp, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoved(QMouseEvent*))); connect(sp, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(mouseReleased(QMouseEvent*))); connect(this, SIGNAL(goToPacket(int)), seq_diagram_, SLOT(setSelectedPacket(int))); disconnect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); fillDiagram(); }
SequenceDialog::SequenceDialog(QWidget *parent, capture_file *cf, SequenceType type) : QDialog(parent), ui(new Ui::SequenceDialog), cap_file_(cf), num_items_(0), packet_num_(0), node_label_w_(20) { ui->setupUi(this); QCustomPlot *sp = ui->sequencePlot; seq_diagram_ = new SequenceDiagram(sp->yAxis, sp->xAxis2, sp->yAxis2); sp->addPlottable(seq_diagram_); sp->axisRect()->setRangeDragAxes(sp->xAxis2, sp->yAxis); sp->xAxis->setVisible(false); sp->xAxis->setPadding(0); sp->xAxis->setLabelPadding(0); sp->xAxis->setTickLabelPadding(0); sp->xAxis2->setVisible(true); sp->yAxis2->setVisible(true); one_em_ = QFontMetrics(sp->yAxis->labelFont()).height(); ui->horizontalScrollBar->setSingleStep(100 / one_em_); ui->verticalScrollBar->setSingleStep(100 / one_em_); sp->setInteractions(QCP::iRangeDrag); ui->gridLayout->setSpacing(0); connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), sp->yAxis2, SLOT(setRange(QCPRange))); ctx_menu_.addAction(ui->actionReset); ctx_menu_.addSeparator(); ctx_menu_.addAction(ui->actionMoveRight10); ctx_menu_.addAction(ui->actionMoveLeft10); ctx_menu_.addAction(ui->actionMoveUp10); ctx_menu_.addAction(ui->actionMoveDown10); ctx_menu_.addAction(ui->actionMoveRight1); ctx_menu_.addAction(ui->actionMoveLeft1); ctx_menu_.addAction(ui->actionMoveUp1); ctx_menu_.addAction(ui->actionMoveDown1); ctx_menu_.addSeparator(); ctx_menu_.addAction(ui->actionGoToPacket); memset (&seq_analysis_, 0, sizeof(seq_analysis_)); ui->showComboBox->blockSignals(true); ui->showComboBox->setCurrentIndex(0); ui->showComboBox->blockSignals(false); ui->addressComboBox->blockSignals(true); ui->addressComboBox->setCurrentIndex(0); ui->addressComboBox->blockSignals(false); QComboBox *fcb = ui->flowComboBox; fcb->addItem(ui->actionFlowAny->text(), SEQ_ANALYSIS_ANY); fcb->addItem(ui->actionFlowTcp->text(), SEQ_ANALYSIS_TCP); ui->flowComboBox->blockSignals(true); switch (type) { case any: seq_analysis_.type = SEQ_ANALYSIS_ANY; ui->flowComboBox->setCurrentIndex(SEQ_ANALYSIS_ANY); break; case tcp: seq_analysis_.type = SEQ_ANALYSIS_TCP; ui->flowComboBox->setCurrentIndex(SEQ_ANALYSIS_TCP); break; case voip: seq_analysis_.type = SEQ_ANALYSIS_VOIP; ui->flowComboBox->hide(); ui->flowLabel->hide(); break; } ui->flowComboBox->blockSignals(false); seq_analysis_.all_packets = TRUE; QPushButton *save_bt = ui->buttonBox->button(QDialogButtonBox::Save); save_bt->setText(tr("Save As...")); // XXX Use recent settings instead if (parent) { resize(parent->width(), parent->height() * 4 / 5); } connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(hScrollBarChanged(int))); connect(ui->verticalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(vScrollBarChanged(int))); connect(sp->xAxis2, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisChanged(QCPRange))); connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(yAxisChanged(QCPRange))); connect(sp, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(diagramClicked(QMouseEvent*))); connect(sp, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoved(QMouseEvent*))); connect(sp, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(mouseReleased(QMouseEvent*))); connect(this, SIGNAL(goToPacket(int)), seq_diagram_, SLOT(setSelectedPacket(int))); disconnect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); fillDiagram(); }
void chartcreate::repaintplot() { QCustomPlot * customPlot = ui->chart_preview; // create empty bar chart objects: QCPBars *regen = new QCPBars(customPlot->xAxis, customPlot->yAxis); QCPBars *nuclear = new QCPBars(customPlot->xAxis, customPlot->yAxis); QCPBars *fossil = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(regen); customPlot->addPlottable(nuclear); customPlot->addPlottable(fossil); // set names and colors: QPen pen; pen.setWidthF(1.2); fossil->setName("Danone"); pen.setColor(QColor(255, 131, 0)); fossil->setPen(pen); fossil->setBrush(QColor(255, 131, 0, 50)); nuclear->setName("AuBonLait"); pen.setColor(QColor(1, 92, 191)); nuclear->setPen(pen); nuclear->setBrush(QColor(1, 92, 191, 50)); regen->setName("Yoplait"); pen.setColor(QColor(150, 222, 0)); regen->setPen(pen); regen->setBrush(QColor(150, 222, 0, 70)); // stack bars ontop of each other: nuclear->moveAbove(fossil); regen->moveAbove(nuclear); // prepare x axis with country labels: QVector<double> ticks; QVector<QString> labels; ticks << 1 << 2 ; labels << "Homme" << "Femme" ; customPlot->xAxis->setAutoTicks(false); customPlot->xAxis->setAutoTickLabels(false); customPlot->xAxis->setTickVector(ticks); customPlot->xAxis->setTickVectorLabels(labels); customPlot->xAxis->setTickLabelRotation(60); customPlot->xAxis->setSubTickCount(0); customPlot->xAxis->setTickLength(0, 4); customPlot->xAxis->grid()->setVisible(true); customPlot->xAxis->setRange(0, 8); // prepare y axis: customPlot->yAxis->setRange(0, 12.1); customPlot->yAxis->setPadding(5); // a bit more space to the left border customPlot->yAxis->setLabel("Marque de Yaourt Connu"); customPlot->yAxis->grid()->setSubGridVisible(true); QPen gridPen; gridPen.setStyle(Qt::SolidLine); gridPen.setColor(QColor(0, 0, 0, 25)); customPlot->yAxis->grid()->setPen(gridPen); gridPen.setStyle(Qt::DotLine); customPlot->yAxis->grid()->setSubGridPen(gridPen); // Add data: QVector<double> fossilData, nuclearData, regenData; fossilData << 0.86*10.5 << 0.83*5.5; nuclearData << 0.08*10.5 << 0.12*5.5; regenData << 0.06*10.5 << 0.05*5.5; fossil->setData(ticks, fossilData); nuclear->setData(ticks, nuclearData); regen->setData(ticks, regenData); // setup legend: customPlot->legend->setVisible(true); customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignHCenter); customPlot->legend->setBrush(QColor(255, 255, 255, 200)); QPen legendPen; legendPen.setColor(QColor(130, 130, 130, 200)); customPlot->legend->setBorderPen(legendPen); QFont legendFont = font(); legendFont.setPointSize(10); customPlot->legend->setFont(legendFont); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); }
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; }
LBMUIMFlowDialog::LBMUIMFlowDialog(QWidget * parent, capture_file * cfile) : QDialog(parent), m_ui(new Ui::LBMUIMFlowDialog), m_capture_file(cfile), m_num_items(0), m_packet_num(0), m_node_label_width(20) { m_ui->setupUi(this); QCustomPlot * sp = m_ui->sequencePlot; m_sequence_diagram = new SequenceDiagram(sp->yAxis, sp->xAxis2, sp->yAxis2); sp->addPlottable(m_sequence_diagram); sp->axisRect()->setRangeDragAxes(sp->xAxis2, sp->yAxis); sp->xAxis->setVisible(false); sp->xAxis->setPadding(0); sp->xAxis->setLabelPadding(0); sp->xAxis->setTickLabelPadding(0); sp->xAxis2->setVisible(true); sp->yAxis2->setVisible(true); m_one_em = QFontMetrics(sp->yAxis->labelFont()).height(); m_ui->horizontalScrollBar->setSingleStep(100 / m_one_em); m_ui->verticalScrollBar->setSingleStep(100 / m_one_em); sp->setInteractions(QCP::iRangeDrag); m_ui->gridLayout->setSpacing(0); connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), sp->yAxis2, SLOT(setRange(QCPRange))); m_context_menu.addAction(m_ui->actionReset); m_context_menu.addSeparator(); m_context_menu.addAction(m_ui->actionMoveRight10); m_context_menu.addAction(m_ui->actionMoveLeft10); m_context_menu.addAction(m_ui->actionMoveUp10); m_context_menu.addAction(m_ui->actionMoveDown10); m_context_menu.addAction(m_ui->actionMoveRight1); m_context_menu.addAction(m_ui->actionMoveLeft1); m_context_menu.addAction(m_ui->actionMoveUp1); m_context_menu.addAction(m_ui->actionMoveDown1); m_context_menu.addSeparator(); m_context_menu.addAction(m_ui->actionGoToPacket); memset(&m_sequence_analysis, 0, sizeof(m_sequence_analysis)); m_ui->showComboBox->blockSignals(true); m_ui->showComboBox->setCurrentIndex(0); m_ui->showComboBox->blockSignals(false); m_sequence_analysis.all_packets = TRUE; m_sequence_analysis.any_addr = TRUE; QPushButton * save_bt = m_ui->buttonBox->button(QDialogButtonBox::Save); save_bt->setText(tr("Save As" UTF8_HORIZONTAL_ELLIPSIS)); // XXX Use recent settings instead if (parent) { resize(parent->width(), parent->height() * 4 / 5); } connect(m_ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(hScrollBarChanged(int))); connect(m_ui->verticalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(vScrollBarChanged(int))); connect(sp->xAxis2, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisChanged(QCPRange))); connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(yAxisChanged(QCPRange))); connect(sp, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(diagramClicked(QMouseEvent*))); connect(sp, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoved(QMouseEvent*))); connect(sp, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(mouseReleased(QMouseEvent*))); connect(this, SIGNAL(goToPacket(int)), m_sequence_diagram, SLOT(setSelectedPacket(int))); disconnect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); fillDiagram(); }
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(); }
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; }