本文整理汇总了C++中QVector::last方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector::last方法的具体用法?C++ QVector::last怎么用?C++ QVector::last使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVector
的用法示例。
在下文中一共展示了QVector::last方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadResults
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();
}
示例2: QDialog
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);
}
示例3: plotSpectr
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;
}
示例4: calculate
/**
* @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;
}
示例5: fromLayer
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
};
}
示例6: tangentAtEnd
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;
}
示例7: averageValue
// 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;
}
示例8: forward
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;
}
示例9: ShowPositionHistory
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());
}
示例10: Modular_exponentiation
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;
}
}
}
示例11:
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;
}
示例12: rec
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"));
}
示例13: on_acSelect_triggered
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
}
示例14: ifft
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;
}
示例15: foreach
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++;
}
}
}