void AdgprsResults::ReadResults(QString file_path) { if (file_path.split(".SIM.H5").length() == 1) file_path = file_path + ".SIM.H5"; // Append the suffix if it's not already there file_path_ = file_path; summary_reader_ = new AdgprsResultsReader::AdgprsResultsReader(file_path); // In Simulation/results/adgprsresults.cpp // Print summary data for performance check QVector<double> *FOPT = summary_reader_->results() ->GetFieldProperty(keys_[Results::Property::CumulativeOilProduction]); QVector<double> *FWPT = summary_reader_->results() ->GetFieldProperty(keys_[Results::Property::CumulativeWaterProduction]); QVector<double> *FGPT = summary_reader_->results() ->GetFieldProperty(keys_[Results::Property::CumulativeGasProduction]); auto aa = FOPT->last(); auto bb = FWPT->last(); auto NPV = aa - 0.2*bb; // foreach (double number, *FOPT) { QString out_string = "FOPT:\t" + QString::number(FOPT->last()) + "\tFWPT:\t" + QString::number(FWPT->last()) + "\tFGPT:\t" + QString::number(FGPT->last()) + "\tNPV:\t" + QString::number(NPV); QString file_path_out = "/home/bellout/git/PCG/FieldOpt/examples/test-ADGPRS-5SPOT_WPLC-A"; Utilities::FileHandling::WriteLineToFile(out_string, file_path_out + "/log_npv.out"); // } setAvailable(); }
GameVersionChoiceDialog::GameVersionChoiceDialog(const QList <BTech::GameVersion> &allowedVersions) : QDialog() { setFixedSize(200, 300); QVBoxLayout *checkBoxLayout = new QVBoxLayout; checkBoxLayout->setAlignment(Qt::AlignTop); QVector <QCheckBox *> checkBox; group = new QButtonGroup; group->setExclusive(true); for (BTech::GameVersion version : allowedVersions) { checkBox << new QCheckBox(BTech::gameVersionStringChange[version]); group->addButton(checkBox.last()); checkBoxLayout->addWidget(checkBox.last()); } checkBox.first()->setChecked(true); QVBoxLayout *layout = new QVBoxLayout; layout->addItem(checkBoxLayout); confirmButton = new QPushButton(BTech::Strings::ButtonConfirm); connect(confirmButton, &QPushButton::pressed, this, &GameVersionChoiceDialog::accept); layout->addWidget(confirmButton); setLayout(layout); }
void PlotterWindow::plotSpectr(HyperCube *ptrCube, uint dataX, uint dataY) { quint16 Chnls = ptrCube->GetCountofChannels(); qint16* pSpectrValues = new qint16[Chnls]; try{ //если можем получить точку гиперкуба ptrCube->GetSpectrumPoint(dataX, dataY,pSpectrValues); // записали в pSpectrValues из гиперкуба QVector<double> xArr(Chnls), yArr(Chnls); for (quint16 i = 0; i < Chnls; ++i ) { xArr[i] = i; yArr[i] = pSpectrValues[i]; } QVector<double> sortedYArr; sortedYArr = yArr; qSort(sortedYArr); if (sortedYArr.first() < minY ) minY = sortedYArr.first(); if (sortedYArr.last() > maxY ) maxY = sortedYArr.last(); QString grafName; grafName.append("X:"); grafName.append(QString::number(dataX)); grafName.append(" Y:"); grafName.append(QString::number(dataY)); m_customPlot->setInteraction(QCP::iRangeDrag , true); m_customPlot->setInteraction(QCP::iRangeZoom , true); m_customPlot->legend->setVisible(true); if (!m_hold) m_customPlot->clearGraphs(); m_customPlot->addGraph(); if (m_customPlot->graphCount() == 1) // первый график всегда черного цвета, остальные - рандомные m_customPlot->graph()->setPen(QPen(Qt::black)); else { QColor color; int limit = 256; int randR = qrand() % limit; int randG = qrand() % limit; int randB = qrand() % limit; color.setRgb(randR,randG,randB); m_customPlot->graph()->setPen(QPen(color)); } m_customPlot->graph()->setName(grafName); m_customPlot->graph()->setData(xArr,yArr); m_customPlot->xAxis->setRange(xArr.first(),xArr.last()); m_customPlot->yAxis->setRange(minY,maxY); m_customPlot->replot(); }catch(...){ m_customPlot->replot(); } delete pSpectrValues; }
/** * @return - vector that is storing x[] */ static QVector<T> calculate(QList<T> &a, QList<T> &b, QList<T> &c, QList<T> &f) { QVector<T> x; QVector<T> alpha; QVector<T> beta; int i; int size = b.size(); Q_ASSERT(a.size() == size - 1 && c.size() == size - 1 && f.size() == size); x.resize(size); /** * Check for special case when * order of the matrix is equal to 1 */ if (size == 1) { x[0] = f[0] / b[0]; return x; } /** * Common case */ alpha.resize(size); beta.resize(size); alpha[1] = -c[0] / b[0]; beta[1] = f[0] / b[0]; for (i = 1; i < size - 1; i++) { alpha[i+1] = -c[i] / (a[i-1] * alpha[i] + b[i]); beta[i+1] = (f[i] - a[i-1] * beta[i]) / (a[i-1] * alpha[i] + b[i]); } x.last() = (f.last() - a.last() * beta.last()) / (b.last() + a.last() * alpha.last()); for (i = size - 2; i >= 0; i--) x[i] = alpha[i+1] * x[i+1] + beta[i+1]; return x; }
LayerTileSet LayerTileSet::fromLayer(const Layer &layer) { const QVector<Tile> tiles = layer.tiles(); const int cols = Tile::roundTiles(layer.width()); Q_ASSERT(!tiles.isEmpty()); QVector<TileRun> runs; // First, Run Length Encode the tile vector runs << TileRun { tiles.first(), 0, 0, 1, tiles.first().solidColor() }; for(int i=1;i<tiles.size();++i) { if(runs.last().len < 0xffff && runs.last().tile.equals(tiles.at(i))) { runs.last().len++; } else { runs << TileRun { tiles.at(i), i%cols, i/cols, 1, tiles.at(i).solidColor() }; } } // Count the number of solid color tiles. QHash<quint32, int> colors; for(const TileRun &tr : runs) { if(tr.color.isValid()) colors[tr.color.rgba()] += tr.len; } // If half of the tiles are of the same // solid color, use that as the background color. // Otherwise, transparency is a safe default choice. QColor background = Qt::transparent; const int treshold = tiles.length() / 2; for(QHash<quint32, int>::const_iterator i = colors.constBegin();i!=colors.constEnd();++i) { if(i.value() >= treshold) { background = QColor::fromRgba(i.key()); break; } } // Remove solid color tiles that match the background QMutableVectorIterator<TileRun> tri(runs); while(tri.hasNext()) { if(tri.next().color == background) tri.remove(); } // All done! return LayerTileSet { runs, background }; }
QPointF RoundCornersCommand::tangentAtEnd(const KoPathSegment &s) { QVector<QPointF> cp = s.controlPoints(); QPointF tn = cp[cp.count()-2] - cp.last(); qreal length = sqrt(tn.x() * tn.x() + tn.y() * tn.y()); return tn / length; }
// Compute the average value of a property over a given depth range. double CrustalModel::averageValue(const QVector<double> & thickness, const QVector<double> & property, const double maxDepth) { // Depth to the base of the current layer double depth = 0; double sum = 0; for (int i = 0; i < thickness.size(); ++i) { depth += thickness.at(i); // Partial layer if (maxDepth < depth) { sum += (thickness.at(i) - (depth - maxDepth)) * property.at(i); break; } // Final infinite layer if (i == thickness.size()-1) { sum += (maxDepth - depth) * property.last(); break; } sum += thickness.at(i) * property.at(i); } return sum / maxDepth; }
QVector<double> ActorHighLevel::lowPass(QVector<double> in, double alpha) { int l = in.length(); if (l == 0) return QVector< double >(); // Gewichtung berechnen, falls auf default (0) if(alpha == 0){ double rate = 1.0 / config::actorPeriodMotionControl; double slowRate = 1.0 / (config::actorPeriodMotionControl+1); alpha = rate / (rate + slowRate); } // Vorwärts filtern QVector< double > forward(l); forward.first() = in.first(); for(int i=1; i < l; ++i){ forward[i] = alpha * in[i] + (1-alpha) * in[i-1]; } // Rückwärts filtern QVector< double > backward(l); backward.last() = in.last(); for(int i=l-2; i >= 0; --i){ backward[i] = alpha * in[i] + (1-alpha) * in[i+1]; } // Überlagern QVector< double > out(l); for(int i=0; i < l; ++i){ out[i] = (forward[i] + backward[i] ) / 2; } return out; }
void MapOverview::ShowPositionHistory(QVector<Eigen::Affine2d> positions) { if(positions.isEmpty()) { mPlannedTrajectory->setPath(QPainterPath()); return; } QPainterPath path({positions[0].translation().x(), positions[0].translation().y()}); for(int i = 1; i < positions.size(); i++) { auto pt = positions[i]; path.lineTo(pt.translation().x(), pt.translation().y()); } trajectoryPath->setPath(path); auto& last = positions.last(); Rotation2Dd rotation2D(0); rotation2D.fromRotationMatrix(last.linear()); mRobotInstance->setPos(last.translation().x(), last.translation().y()); mRobotInstance->setRotation(rotation2D.angle() * 180 / M_PI); //mSampleDetections->setPos(mRobotInstance->pos()); //mSampleDetections->setRotation(mRobotInstance->rotation()); }
LongInt Algorithm::Modular_exponentiation(LongInt a,LongInt m, LongInt r) { //qDebug()<<"algorithm.cpp: Modular_exponentiation"<<a<<m<<r; if(r==0) { //qDebug()<<"algorithm.cpp: Modular_exponentiation :( 1 )"; return LongInt(1); } QVector<LongInt> part; part<<1; LongInt a_k(1),k(1); while(1) { //qDebug()<<a_k<<a<<m; a_k=((a_k*a)%m); part<<a_k; if(part.last()==1) { part.removeLast(); //qDebug()<<"algorithm.cpp: Modular_exponentiation :"<<part.value( ((r % LongInt(part.length()))).toInt()); return part.value( ((r % LongInt(part.length()))).toInt()); } k+=1; if(k>r) { //qDebug()<<"algorithm.cpp: Modular_exponentiation :"<<part.value( ((r % LongInt(part.length()))).toInt()); return part.value( ((r % LongInt(part.length()))).toInt()); return a_k; } } }
QVector<qreal> QQuickAndroid9PatchDivs::coordsForSize(qreal size) const { // n = number of stretchable sections // We have to compensate when adding 0 and/or // the source image width to the divs vector. const int l = data.size(); const int n = (inverted ? l - 1 : l) >> 1; const qreal stretchAmount = (size - data.last()) / n; QVector<qreal> coords; coords.reserve(l); coords.append(0); bool stretch = !inverted; for (int i = 1; i < l; ++i) { qreal advance = data[i] - data[i - 1]; if (stretch) advance += stretchAmount; coords.append(coords.last() + advance); stretch = !stretch; } return coords; }
void ParserTests::testMemcheckSample2() { MSKIP_SINGLE("testfile does not exist"); initTest(QLatin1String("memcheck-output-sample2.xml")); Valgrind::XmlProtocol::Parser parser; Recorder rec(&parser); parser.parse(m_socket); m_process->waitForFinished(); QCOMPARE(m_process->exitStatus(), QProcess::NormalExit); QCOMPARE(m_process->state(), QProcess::NotRunning); QVERIFY2(parser.errorString().isEmpty(), qPrintable(parser.errorString())); //tests: multiple stacks with auxwhat == stack count - 1. //the first auxwhat should be assigned to the _second_ stack. const QList<Error> errors = rec.errors; QCOMPARE(errors.size(), 1); const QVector<Stack> stacks = errors.first().stacks(); QCOMPARE(stacks.size(), 2); QCOMPARE(stacks.first().auxWhat(), QString()); QCOMPARE(stacks.last().auxWhat(), QLatin1String("Address 0x11b66c50 is 0 bytes inside a block of size 16 free'd")); }
void KTracks::on_acSelect_triggered() { QModelIndexList selection = ui->tvTracks->selectionModel()->selectedRows(); QAbstractItemModel *model = ui->tvTracks->model(); if (!selection.isEmpty()) { QList<QGeoPositionInfo> trackList; trackList.clear(); trackList = sql.selTrack(model->data(model->index(selection.at(0).row(),0)).toInt()); ui->cpPlot->clearGraphs(); ui->cpPlot->addGraph(); QGeoPositionInfo tp; QVector<double> x; QVector<double> y; int cnt = trackList.count(); x.resize(cnt); y.resize(cnt); //options int pType; if (ui->miAltitude->isChecked()) { ui->cpPlot->yAxis->setLabel("Altitude [m]"); pType = 1; } if (ui->miDistance->isChecked()) { ui->cpPlot->yAxis->setLabel("Distance [m]"); pType = 2; } if (ui->miSpeed->isChecked()) { ui->cpPlot->yAxis->setLabel("Speed [m/s]"); pType = 3; } ui->cpPlot->xAxis->setLabel("time [hh:mm:ss]"); for (int i=0; i<cnt; i++) { tp = trackList.value(i); x[i] = tp.timestamp().toTime_t(); switch (pType) { case 1: { y[i] = tp.coordinate().altitude(); break; } case 2: { y[i] = tp.coordinate().distanceTo(trackList.value(0).coordinate()); break; } case 3: { y[i] = tp.attribute(QGeoPositionInfo::GroundSpeed); break; } } //switch } //for to ui->cpPlot->graph(0)->setData(x,y); // set axes ranges, so we see all data: ui->cpPlot->xAxis->setRange(x[0],x[cnt-1]); qSort(y.begin(), y.end()); ui->cpPlot->yAxis->setRange(y.first(),y.last()); //repaint ui->cpPlot->replot(); } //selection.isempty }
void TimeSeriesMotion::ifft(const QVector<std::complex<double> >& in, QVector<double>& out ) const { /* #ifdef USE_IFFTW // Copy the input QVector into a double array fftw_complex* inArray = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * in.size()); for( int i = 0; i < in.size(); i++ ) { inArray[i][0] = in.at(i).real(); inArray[i][1] = in.at(i).imag(); } // Allocate the space for the output int n = 2 * (in.size() - 1); double* outArray = (double*)fftw_malloc(sizeof(double) * n); // Create the plan and execute the FFT fftw_plan p = fftw_plan_dft_c2r_1d(n, inArray, outArray, FFTW_ESTIMATE); fftw_execute(p); // Copy the data to the output QVector and normalize by QVector length out.resize(n); for (int i = 0; i < out.size(); i++) { out[i] = outArray[i] / out.size(); } // Free the memory fftw_destroy_plan(p); fftw_free(inArray); fftw_free(outArray); */ const int n = 2 * (in.size() - 1); double *d = new double[n]; d[0] = in.first().real(); for (int i = 1; i < in.size(); ++i) { d[i] = in.at(i).real(); d[n - i] = in.at(i).imag(); } d[n / 2] = in.last().real(); #if USE_FFTW fftw_plan p = fftw_plan_r2r_1d(n, d, d, FFTW_HC2R, FFTW_ESTIMATE); fftw_execute(p); for (int i = 0; i < n; ++i) { // Scale by n d[i] /= n; } #else gsl_fft_halfcomplex_radix2_inverse(d, 1, n); #endif // Copy results to output out.resize(n); memcpy(out.data(), d, n * sizeof(double)); delete [] d; }
QVector<ProfileItem> CardOCR::scanLeftProfile(const BoolMatrix & imgMatrix) { //дальше сравнене по профилям //сканирование левого профиля const int w = imgMatrix.width(); const int h = imgMatrix.height(); int min_x = w, max_x = 0; QVector<int> x_array; for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { if (imgMatrix.at(x, y) == 1) { if (x < min_x) min_x = x; if (x > max_x) max_x = x; x_array.push_back(x); break; } } } //определяем середину int x_border = min_x + (max_x - min_x) / 2; //формируем портрет профиля QVector<bool> prof; QVector<ProfileItem> profile; //qDebug() << x_array; int ccnt = 0; bool item = true; foreach (int x, x_array) { item = (x > x_border); if (prof.size() == 0) { prof.push_back(item); ccnt++; } else { if (prof.last() != item) { ProfileItem it; it.item = !item; it.value = qreal(ccnt) / qreal(h); profile.push_back(it); prof.push_back(item); ccnt = 1; } else { ccnt++; } } }
void EditorArea::paintEdges(QPainter &painter) { bool firstTime = true; QVector<int> edgesIds = workspace->getEdgesIds(); for (int i=0; i < edgesIds.size(); i++) { QPoint nodesOfEdge = workspace->getNodesOfEdge(edgesIds[i]); QPointF screenXYFirst = graph2screen(workspace->getNodePosition(nodesOfEdge.x())); QPointF screenXYSecond = graph2screen(workspace->getNodePosition(nodesOfEdge.y())); QPointF screenMidPoint = graph2screen(workspace->getThirdPointPos(edgesIds[i])); QPainterPath path; path.moveTo(screenXYFirst); path.quadTo(screenMidPoint, screenXYSecond); path.quadTo(screenMidPoint, screenXYFirst); painter.drawPath(path); QVector<QPointF> pointsOnBezier; QVector<float> sOnEdge; for (int k = 0; k < edgeDiscretization + 1; k++) { float t = float(k) / edgeDiscretization; QPointF coord = (1 - t) * (1 - t) * screenXYFirst + 2 * (1 - t) * t * screenMidPoint + t * t * screenXYSecond; pointsOnBezier << coord; } for (int k = 0; k < pointsOnBezier.size(); k++) { if (k == 0) { sOnEdge << 0.0; } else { float sJesima = workspace->distance(pointsOnBezier[k], pointsOnBezier[k - 1]); sOnEdge << sJesima; } } for (int k = 1; k < pointsOnBezier.size(); k++) { sOnEdge[k] = sOnEdge[k] + sOnEdge[k - 1]; } float length = sOnEdge.last(); for (int k = 0; k < sOnEdge.size(); k++) { sOnEdge[k] = sOnEdge[k] / length; } sOnBezier.insert(edgesIds[i], sOnEdge); if (path.intersects(QRectF(mouseCurrentPos.x() - 7, mouseCurrentPos.y() - 7, 14, 14))) { if (firstTime) { firstTime = false; hitElements.clear(); } QPoint temp(2, edgesIds[i]); hitElements.append(temp); } } }
// SLOT PersonalProfileWidget::jobToRemove void PersonalProfileWidget::jobToRemoveSlot( const SmartLavoro& sl ) { ProfileWidget::user->removeExperience( sl ); QVector<SmartLavoro> experiencesList = ProfileWidget::user->getExperiencesList(); if( experiencesList.size() == 0 ) { lastExperienceLabel->setText( "--" ); } else updateLastJobInfoSlot( experiencesList.last() ); }
// SLOT PersonalProfileWidget::titleToRemoveSlot void PersonalProfileWidget::titleToRemoveSlot( const SmartTitolo& st ) { ProfileWidget::user->removeEducation( st ); QVector<SmartTitolo> educationsList = ProfileWidget::user->getEducationsList(); if( educationsList.size() == 0 ) { lastEducationLabel->setText( "--" ); } else updateLastTitleInfoSlot( educationsList.last() ); }
bool SWINGTEXT_keypress(struct Tracker_Windows *window, struct WBlocks *wblock, struct WTracks *wtrack, int realline, const Place *place, int key){ int subsubtrack = SWINGTEXT_subsubtrack(window, wtrack); if (subsubtrack==-1) return false; struct Blocks *block = wblock->block; struct Tracks *track = wtrack==NULL ? NULL : wtrack->track; QVector<Swing*> swings = Swings_get(wblock, track, realline); if (swings.size() == 0) { // NO ELEMENTS if (key == EVENT_DEL) return true; data_as_text_t dat = DAT_get_newvalue(subsubtrack, key, 1, LOGTYPE_HOLD, 1, 99, 1, 99, false, true, false); if (dat.is_valid==false) return false; ADD_UNDO(Swings_CurrPos(window)); AddSwing(block, track, *place, dat.value, dat.logtype); } else { // ONE ELEMENT (or more than one element) struct Swing *swing = swings.last(); if (key == EVENT_DEL) { ADD_UNDO(Swings_CurrPos(window)); RemoveSwing(block, track, swing); } else { data_as_text_t dat = DAT_get_overwrite(swing->weight, swing->logtype, subsubtrack, key, 1, 99, 1, 99, false, false); if (dat.is_valid==false) return false; if (dat.value==swing->weight && dat.logtype==swing->logtype) return true; // I.e. although the user didn't change anything, the key was valid so we still eat it (by returning true instead of false). ADD_UNDO(Swings_CurrPos(window)); AddSwing(block, track, swing->l.p, dat.value, dat.logtype); } } return true; }
QPolygonF jpsRoom::RoomAsSortedPolygon() const { QList<jpsLineItem*> lines = item_list; for (jpsCrossing* crossing:_doorList) { lines.push_back(crossing->get_cLine()); } // std::cout << lines.size() << std::endl; QVector<QPointF> points; points.push_back(lines.first()->get_line()->line().p1()); points.push_back(lines.first()->get_line()->line().p2()); lines.pop_front(); for (int i=0; i<lines.size(); i++) { if (lines[i]->get_line()->line().p1() == points.last()) { //points.push_back(line->get_line()->line().p1()); points.push_back(lines[i]->get_line()->line().p2()); lines.removeOne(lines[i]); i=-1; } else if (lines[i]->get_line()->line().p2() == points.last()) { //points.push_back(line->get_line()->line().p1()); points.push_back(lines[i]->get_line()->line().p1()); lines.removeOne(lines[i]); i=-1; } } for (QPointF point:points) { std::cout << point.x() << " " << point.y() << std::endl; } std::cout << "----------------------------" << std::endl; return QPolygonF(points); }
void GameThousand::calculatePoints() { QMap<quint16, CardPack>::iterator it = mapPlayer2Trick.begin(); for (; it != mapPlayer2Trick.end(); ++it) { int sum = 0; int tempSum = 0; quint16 currentPlayerID = it.key(); // считаем сразу сколько набрал игрок CardPack vector = it.value(); for (int i = 0; i < vector.size(); i++) tempSum += vector.at(i).second; tempSum += _mPlayerLaud.value(currentPlayerID); QVector<qint16> playerScore = score.value(currentPlayerID); int prevScore = playerScore.isEmpty() ? 0 : playerScore.last(); // проверка на факт сидения игрока на бочке if (_mBarrelPlayer.contains(currentPlayerID)) { if (currentPlayerID != _mWidowBringer) { int vecSize = playerScore.size(); //если три раза не берет прикуп, то -100 sum = (playerScore.at(vecSize - 1) == playerScore.at(vecSize - 2) && playerScore.at(vecSize - 2) == playerScore.at(vecSize - 3)) ? -100 : 0; } //случай, когда игрок взял прикуп и объявил конкретное количество очков(случай бочки) else { //минимум 100 очков, поэтому если набрал, то будет победителем if (tempSum >= _mPointOrdered) { winnerExist = true; _mWinner = currentPlayerID; playerScore.append(1000); continue; } else sum = 0 - tempSum; } } //случай без бочки else { if (currentPlayerID != _mWidowBringer) { int vecSize = playerScore.size(); //если три болт, то -100 sum = (playerScore.at(vecSize - 1) == playerScore.at(vecSize - 2) && playerScore.at(vecSize - 2) == playerScore.at(vecSize - 3)) ? -100 : tempSum; } //случай, когда игрок взял прикуп и объявил конкретное количество очков else { if (tempSum >= _mPointOrdered) sum = _mPointOrdered; else sum = 0 - tempSum; } } //производим обнуление очков if (_mBarrelPlayer.count(currentPlayerID) && sum == -100) playerScore.append(0); else playerScore.append(prevScore + sum); } }
void Sbs2EmocapDataReader::udpDataReceived(QUdpSocket *rawDataUdpInputSocket) { //0 :: last - sizeof(int): data from the oldest to the newest //last - sizeof(int) :: last - 1: rawDataCounter divided into 8 bit chunks //last - 1: sizeof(int) (size of int in this implementation) //last: rawDataSize (size of a single data chunk, usually 32 bytes) while (rawDataUdpInputSocket->hasPendingDatagrams()) { QByteArray datagram; datagram.resize(rawDataUdpInputSocket->pendingDatagramSize()); QHostAddress sender; quint16 senderPort; rawDataUdpInputSocket->readDatagram(datagram.data(), datagram.size(),&sender, &senderPort); int rawDataSize = datagram.data()[datagram.size()-1]; int intSize = datagram.data()[datagram.size()-2]; int currentCounter = 1; int noPackets = (datagram.size() - 1 - intSize)/rawDataSize; for (int i=intSize-1; i>=0; --i) { int v = (int)datagram.data()[datagram.size()-3-i]; if (v < 0) v+= 256; currentCounter += v * pow(2,(double)8*(intSize-i-1)); } QVector<char*>* data = new QVector<char*>; for (int i= 0; i<noPackets; ++i) { data->append(new char[rawDataSize]); char* buff = data->last(); for (int k = 0; k<rawDataSize; ++k) { buff[k] = datagram.data()[i*rawDataSize+k]; } } if (currentCounter > lastReceiveRawDataCounter) { lastReceiveRawDataCounter = currentCounter; udpDataReceived(data,currentCounter); } } }
bool WireCreator::calcAllPathes(QVector<int> currPath, QVector<QPair<int,int>> usedEdges, QPair<int,int> nextEdge) { qDebug()<<"in creator currPath"<<currPath; /*if(containsAllE(currPath)){ qDebug()<<"success: "<<currPath; allPathes.push_back(currPath); return true; }*/ int nextPoint=-1; if(currPath.last()==nextEdge.first)nextPoint=nextEdge.second; if(currPath.last()==nextEdge.second)nextPoint=nextEdge.first; if(nextPoint!=-1){ currPath.append(nextPoint); usedEdges.push_back(nextEdge); } if(containsAllE(currPath)){ qDebug()<<currPath; allPathes.push_back(currPath); return true; } if(deadEnds.indexOf(nextPoint)!=-1){ qDebug()<<"Deadend"; currPath.append(traceBackDE(nextPoint)); } for(auto edge: edges){ if(usedEdges.indexOf(edge)==-1){ if(edge.first==currPath.last() || edge.second==currPath.last()){ calcAllPathes(currPath, usedEdges, edge); } } } qDebug()<<currPath; return false; }
void StatisticWindow::onExportCategoriesCSVPress() { QString FileName = QFileDialog::getSaveFileName(0,tr("Select categories file"),"categories.csv","Comma Separated Values(*.csv)"); if (!FileName.isEmpty()){ QVector<sStatisticItem*> items; items.resize(m_Categories.size()+1); for (int i = 0; i<m_Categories.size(); i++) items[i] = &m_Categories[i]; items.last() = &m_Uncategorized; saveToCSV(items,FileName); } }
/** * @brief Graph::Graph * Widget that contains the graphical elements displayed to the user * @param bourse * @param parent */ Graph::Graph(Bourse* bourse, QWidget *parent) : QWidget(parent) { this->bourse = bourse; customPlot = new QCustomPlot(); QVector<double> x; QVector<double> y; QMap<int, double>::iterator i; QMap<int, double> cours = bourse->getCours(); int j = 0; for (i = cours.begin(); i != cours.end(); ++i) { QDateTime dateTime(QDate::fromJulianDay(i.key())); x.append(dateTime.toTime_t()); y.append(i.value()); j++; } customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime); customPlot->xAxis->setTickLabelRotation(90); customPlot->xAxis->setDateTimeFormat("dd'-'MM'-'yyyy"); customPlot->xAxis->setAutoTickStep(false); customPlot->xAxis->setAutoSubTicks(false); customPlot->xAxis->setSubTickCount(7); customPlot->xAxis->setTickStep(3600*24*7*4); customPlot->addGraph(); customPlot->graph(0)->setData(x, y); customPlot->xAxis->setLabel("Date"); customPlot->yAxis->setLabel("Price"); customPlot->xAxis->setRange(x.last(), x.first()); customPlot->yAxis->setRange(bourse->getMin(), bourse->getMax()); customPlot->replot(); labelPeriod = new QLabel(bourse->getMaxInflation()); labelYear = new QLabel(bourse->getMaxYearInflation()); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(customPlot,2); layout->addWidget(labelPeriod, 0); layout->addWidget(labelYear, 0); setLayout(layout); }
ProbeABI findBestMatchingABI(const ProbeABI &targetABI, const QVector<ProbeABI> &availableABIs) { QVector<ProbeABI> compatABIs; foreach (const ProbeABI &abi, availableABIs) { if (targetABI.isCompatible(abi)) compatABIs.push_back(abi); } if (compatABIs.isEmpty()) return ProbeABI(); std::sort(compatABIs.begin(), compatABIs.end()); return compatABIs.last(); }
QModelIndex cast( NifModel * nif, const QModelIndex & index ) override final { QModelIndex iData = getStripsData( nif, index ); QModelIndex iLength = nif->getIndex( iData, "Strip Lengths" ); QModelIndex iPoints = nif->getIndex( iData, "Points" ); if ( !( iLength.isValid() && iPoints.isValid() ) ) return index; QList<QVector<quint16> > strips; for ( int r = 0; r < nif->rowCount( iPoints ); r++ ) strips += nif->getArray<quint16>( iPoints.child( r, 0 ) ); if ( strips.isEmpty() ) return index; QVector<quint16> strip = strips.first(); strips.pop_front(); for ( const QVector<quint16>& s : strips ) { // TODO: optimize this if ( strip.count() & 1 ) strip << strip.last() << s.first() << s.first() << s; else strip << strip.last() << s.first() << s; } nif->set<int>( iData, "Num Strips", 1 ); nif->updateArray( iLength ); nif->set<int>( iLength.child( 0, 0 ), strip.size() ); nif->updateArray( iPoints ); nif->updateArray( iPoints.child( 0, 0 ) ); nif->setArray<quint16>( iPoints.child( 0, 0 ), strip ); return index; }
int tsanalitics::getMVL(){ QVector<int> vec; int max=0; for(int i=0;i<ts_row_data->size();i++){ if ( abs(ts_row_data->at(i))>5 ){ vec.push_back(i); }else{ if(vec.size()>15){ max+=ts_row_data->at(vec.last()); } vec.remove(0,vec.size()); vec.clear(); } } return max; }
/* static */ int UINetworkReplyPrivateThread::applyRawHeaders(RTHTTP pHttp, const QList<QByteArray> &headers, const QNetworkRequest &request) { /* Make sure HTTP is created: */ if (!pHttp) return VERR_INVALID_POINTER; /* We should format them first: */ QVector<QByteArray> formattedHeaders; QVector<const char*> formattedHeaderPointers; foreach (const QByteArray &header, headers) { /* Prepare formatted representation: */ QString strFormattedString = QString("%1: %2").arg(QString(header), QString(request.rawHeader(header))); formattedHeaders << strFormattedString.toAscii(); formattedHeaderPointers << formattedHeaders.last().constData(); }
void SymmetryGroup::process(QVector<Primitive*> segments) { // Store the nodes Group::process(segments); // Compute the symmetry plane Primitive * a = segments.first(); Primitive * b = segments.last(); Point cA = a->centerPoint(); Point cB = b->centerPoint(); Point point = (cA + cB) * 0.5; Normal normal = (cA - cB).normalized(); symmetryPlane = Plane(normal, point); // Representative points of two primitives std::vector<Vec3d> pointsA = a->points(); std::vector<Vec3d> pointsB = b->points(); // Correspondences from both directions correspondence[a->id].resize(pointsA.size()); correspondence[b->id].resize(pointsB.size()); for(int i = 0; i < pointsA.size(); i++) { pointsA[i] = symmetryPlane.reflection(pointsA[i]); double dist = DBL_MAX; int id_closest = -1; // Find the point on \b closest to the reflected point on \a for(int j = 0; j < pointsB.size(); j++) { double currDist = (pointsA[i] - pointsB[j]).norm(); if(currDist < dist) { id_closest = j; dist = currDist; } } correspondence[a->id][i] = id_closest; correspondence[b->id][id_closest] = i; } }