void MainWindow::start() { if (simulationState != Stopped) stop(); initialCountSpinBox->setEnabled(false); iterationsLCD->display(iterations = 0); qDeleteAll(cells); cells.clear(); QRectF rect = dishItem->sceneBoundingRect(); int xOffset = qRound(rect.x() + (rect.width() / 2)); int yOffset = qRound(rect.y() + (rect.height() / 2)); for (int i = 0; i < initialCountSpinBox->value(); ++i) { int angle = qrand() % 360; qreal factor = qrand() % qRound(rect.width() / 2); #ifdef MSVC_COMPILER int x = qRound(factor * cos(AQP::radiansFromDegrees(angle))); int y = qRound(factor * sin(AQP::radiansFromDegrees(angle))); #else int x = qRound(factor * std::cos(AQP::radiansFromDegrees(angle))); int y = qRound(factor * std::sin(AQP::radiansFromDegrees(angle))); #endif Cell *cell = new Cell(i, dishItem); cell->setPos(x + xOffset, y + yOffset); cells << cell; } scene->invalidate(); startButton->setEnabled(false); pauseOrResumeButton->setEnabled(true); pauseOrResumeButton->setFocus(); update(); simulationState = Running; QTimer::singleShot(IterationDelay, this, SLOT(doOneIteration())); }
void MainWindow::doOneIteration() { if (simulationState != Running) return; int count = 0; QMutableListIterator<Cell*> i(cells); while (i.hasNext()) { Cell *cell = i.next(); if (!cell) continue; if (cell->shrinkOrGrow() == Cell::Die) { i.remove(); delete cell; } else ++count; } scene->invalidate(); iterationsLCD->display(++iterations); currentCountLCD->display(count); update(); if (count <= 1) stop(); if (simulationState != Running) return; QTimer::singleShot(IterationDelay, this, SLOT(doOneIteration())); }
void MainWindow::pauseOrResume() { if (pauseOrResumeButton->text() == tr("Pa&use")) { pauseOrResumeButton->setText(tr("Res&ume")); simulationState = Paused; setWindowOpacity(0.95); } else { pauseOrResumeButton->setText(tr("Pa&use")); simulationState = Running; setWindowOpacity(1.0); QTimer::singleShot(IterationDelay, this, SLOT(doOneIteration())); } update(); }
Mat StabilizerBase::nextStabilizedFrame() { // check if we've processed all frames already if (curStabilizedPos_ == curPos_ && curStabilizedPos_ != -1) { logProcessingTime(); return Mat(); } bool processed; do processed = doOneIteration(); while (processed && curStabilizedPos_ == -1); // check if the frame source is empty if (curStabilizedPos_ == -1) { logProcessingTime(); return Mat(); } return postProcessFrame(at(curStabilizedPos_, stabilizedFrames_)); }