MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), _ui(new Ui::MainWindow), _nextScene(QString::null) { _ui->setupUi(this); Camera* camera = new Camera; camera->set(config->defaultCameraVerticalFOV(), config->defaultCameraAspectRatio()); camera->setAperture(config->defaultCameraAperture()); camera->setFocalPlane(config->defaultCameraFocusPlane()); _ui->renderer->setCamera(camera); _setConfig(); _ui->sceneNames->addItems(sceneGenerator->scenes()); _ui->sceneNames->setCurrentIndex(0); logger->setConsole(_ui->console); logger->setStatusBar(_ui->statusBar); onLoadScene(); connect(_ui->action_Save, SIGNAL(triggered()), SLOT(onSaveImage())); connect(_ui->action_Play_Pause, SIGNAL(triggered()), SLOT(onPlayPause())); connect(_ui->action_Stop, SIGNAL(triggered()), SLOT(onStop())); connect(_ui->action_Reload, SIGNAL(triggered()), SLOT(onLoadScene())); connect(_ui->sceneNames, SIGNAL(currentIndexChanged(QString)), SLOT(onLoadScene())); connect(_ui->integrator, SIGNAL(currentTextChanged(QString)), SLOT(onIntegratorChanged())); connect(_ui->renderer, SIGNAL(renderingFinished()), SLOT(onRenderingFinished())); connect(_ui->renderer, SIGNAL(renderingStarted()), SLOT(onRenderingStarted())); connect(_ui->renderer, SIGNAL(clicked(Intersection)), SLOT(onClick(Intersection))); QTimer* progressTimer = new QTimer(this); connect(progressTimer, SIGNAL(timeout()), SLOT(onUpdateProgress())); progressTimer->start(35); }
void Renderer::_computeImage() { if (!_integrator) { return ; } int s = qSqrt(config->renderingTaskNumber()); QSize imageSize = _image.size(); QSize sectionSize = imageSize / s; sectionSize.setWidth(qMax(sectionSize.width(), 1)); sectionSize.setHeight(qMax(sectionSize.height(), 1)); QList<QRect> tasks; for (int x = 0; x < imageSize.width(); x += sectionSize.width()) { for (int y = 0; y < imageSize.height(); y += sectionSize.height()) { QRect newTask(QPoint(x, y), sectionSize); newTask.setRight(qMin(newTask.right(), imageSize.width() - 1)); newTask.setBottom(qMin(newTask.bottom(), imageSize.height() - 1)); tasks.append(newTask); } } _imageColors.resize(imageSize.width() * imageSize.height()); _imageColors.fill(Color::BLACK); _elapsedTime = 0; _sampleNumber = 0; _renderingTime.restart(); _integrator->preprocess(_scene, _camera); _renderingTime.restart(); emit renderingStarted(); QTime saveTime; saveTime.restart(); while (_stopThread == false) { _renderingTasks = tasks; std::random_shuffle(_renderingTasks.begin(), _renderingTasks.end()); for (int i = 0; i < config->threadNumber(); ++i) { _computingThreads.append(new std::thread(&Renderer::_computeSections, this)); } for (std::thread* computingThread : _computingThreads) { computingThread->join(); delete computingThread; } _computingThreads.clear(); _renderingTasks.clear(); ++_sampleNumber; _elapsedTime += _renderingTime.elapsed(); if (saveTime.elapsed() > 10000) { saveTime.restart(); _image.save(config->outputDir() + "/last.bmp"); } _pauseMutex.lock(); _pauseMutex.unlock(); _renderingTime.restart(); } emit renderingFinished(); _isRendering = false; }
void WhittedRenderer::render(Scene* scene) { if (m_viewer) connect(m_viewer, &HdrViewer::clicked, this, &WhittedRenderer::onPicked); // TODO: this stuff should go to the base class qDebug() << Q_FUNC_INFO; qDebug() << "Rendering with" << m_hwThreadCount << "threads"; m_activeCamera = scene->activeCamera(); m_shapes.clear(); m_shapes = scene->gatherShapes(); m_lights.clear(); m_lights = scene->gatherLights(); qDebug() << "Rendering" << m_shapes.count() << "shapes with" << m_lights.count() << "lights"; if (m_activeCamera->fov() <=0) { qCritical() << "Active camera has invalid fov"; return; } if (m_buffer) delete m_buffer; m_buffer = new float[m_renderedWidth * m_renderedHeight * 3]; emit renderingStarted(); do { qDebug() << "Starting new frame" << scene->time(); QElapsedTimer elapsed; elapsed.start(); QElapsedTimer gridTime; gridTime.start(); if (m_grid) delete m_grid; m_grid = new RegularGrid(); m_grid->initialize(m_shapes); qDebug() << "Generated acceleration structure in" << gridTime.elapsed() << "ms"; auto pool = QThreadPool::globalInstance(); for (int i=0; i < m_hwThreadCount; i++) { WhittedRunnable* runnable = new WhittedRunnable(this, i, m_hwThreadCount); runnable->setAutoDelete(true); pool->start(runnable); } // TODO: write a thread pool that sends a signal when job is complete while (!pool->waitForDone(25)) { qApp->processEvents(); } qDebug() << "Frame complete in:" << elapsed.elapsed() << "ms"; emit frameComplete(); qApp->processEvents(); } while(scene->advanceFrame()); emit renderingComplete(); }
SettingsWidget::SettingsWidget(MandelbrotWidget *mandelbrot, QWidget *parent) : QDockWidget(parent), m_mandelbrot(mandelbrot), m_started(false) { setWindowTitle(tr("Settings")); m_renderTimer = new QTime; QVBoxLayout *layout = new QVBoxLayout; QWidget *widget = new QWidget(this); widget->setLayout(layout); setWidget(widget); QGroupBox *areaGroupBox = new QGroupBox(tr("Area")); QGroupBox *outputGroupBox = new QGroupBox(tr("Output settings")); QGroupBox *threadsGroupBox = new QGroupBox(tr("Threads")); QGroupBox *iterationsGroupBox = new QGroupBox(tr("Iterations")); layout->addWidget(areaGroupBox); layout->addWidget(outputGroupBox); layout->addWidget(threadsGroupBox); layout->addWidget(iterationsGroupBox); m_leftSpinBox = new QDoubleSpinBox; m_leftSpinBox->setDecimals(SpinBoxDecimals); m_leftSpinBox->setRange(-10, 10); m_leftSpinBox->setValue(m_defaultLeft); m_topSpinBox = new QDoubleSpinBox; m_topSpinBox->setDecimals(SpinBoxDecimals); m_topSpinBox->setRange(-10, 10); m_topSpinBox->setValue(m_defaultTop); m_widthSpinBox = new QDoubleSpinBox; m_widthSpinBox->setDecimals(SpinBoxDecimals); m_widthSpinBox->setRange(0.00000001, 10); m_widthSpinBox->setValue(m_defaultWidth); m_heightSpinBox = new QDoubleSpinBox; m_heightSpinBox->setDecimals(SpinBoxDecimals); m_heightSpinBox->setRange(0.00000001, 10); m_heightSpinBox->setValue(m_defaultHeight); QFormLayout *areaLayout = new QFormLayout; areaGroupBox->setLayout(areaLayout); areaLayout->addRow(tr("&Left"), m_leftSpinBox); areaLayout->addRow(tr("&Top"), m_topSpinBox); areaLayout->addRow(tr("&Width"), m_widthSpinBox); areaLayout->addRow(tr("&Height"), m_heightSpinBox); m_renderWidthSpinBox = new QSpinBox; m_renderWidthSpinBox->setRange(1, 8192); m_renderWidthSpinBox->setValue(m_defaultRenderWidth); m_renderHeightSpinBox = new QSpinBox; m_renderHeightSpinBox->setRange(1, 8192); m_renderHeightSpinBox->setValue(m_defaultRenderHeight); QFormLayout *outputLayout = new QFormLayout; outputGroupBox->setLayout(outputLayout); outputLayout->addRow(tr("W&idth"), m_renderWidthSpinBox); outputLayout->addRow(tr("H&eight"), m_renderHeightSpinBox); m_threadSpinBox = new QSpinBox; m_threadSpinBox->setRange(1, 255); m_threadSpinBox->setValue(m_defaultThreadCount); m_segmentWidthSpinBox = new QSpinBox; m_segmentWidthSpinBox->setRange(1, 8192); m_segmentWidthSpinBox->setValue(m_defaultSegmentWidth); m_segmentHeightSpinBox = new QSpinBox; m_segmentHeightSpinBox->setRange(1, 8192); m_segmentHeightSpinBox->setValue(m_defaultSegmentHeight); QFormLayout *threadsLayout = new QFormLayout; threadsGroupBox->setLayout(threadsLayout); threadsLayout->addRow(tr("&Number of threads"), m_threadSpinBox); threadsLayout->addRow(tr("&Segment width"), m_segmentWidthSpinBox); threadsLayout->addRow(tr("Se&gment height"), m_segmentHeightSpinBox); m_iterationsSpinBox = new QSpinBox; m_iterationsSpinBox->setRange(1, 8192); m_iterationsSpinBox->setValue(1000); QFormLayout *iterationsLayout = new QFormLayout; iterationsGroupBox->setLayout(iterationsLayout); iterationsLayout->addRow(tr("&Max iterations"), m_iterationsSpinBox); m_useGmp = new QPushButton(tr("&Use GMP")); m_useGmp->setCheckable(true); m_useGmp->setChecked(true); layout->addWidget(m_useGmp); layout->addStretch(); m_timeLabel = new QLabel; m_timeLabel->setFrameShape(QFrame::StyledPanel); m_timeLabel->setFrameShadow(QFrame::Plain); layout->addWidget(m_timeLabel); QHBoxLayout *btnLayout = new QHBoxLayout(); layout->addLayout(btnLayout); m_startBtn = new QPushButton(tr("Start")); m_stopBtn = new QPushButton(tr("Stop")); btnLayout->addWidget(m_startBtn); btnLayout->addWidget(m_stopBtn); connect(m_startBtn, SIGNAL(clicked()), SLOT(start())); connect(m_stopBtn, SIGNAL(clicked()), SLOT(stop())); connect(m_mandelbrot, SIGNAL(renderingStarted()), SLOT(setRunningState())); connect(m_mandelbrot, SIGNAL(renderingStopped()), SLOT(setStoppedState())); setState(Finished); }
MainWindow::MainWindow(QThread *atermThread): m_fileDialog("", this) { m_ui.setupUi(this); m_ltsManager = new LtsManager(this, &m_settings, atermThread); m_markManager = new MarkManager(this, m_ltsManager); m_infoDock = new InfoDock(this, m_ltsManager, m_markManager); m_markDock = new MarkDock(this, m_markManager); m_simDock = new SimDock(this, m_ltsManager); m_settingsDock = new SettingsDock(this, &m_settings); m_settingsDialog = new SettingsDialog(this, &m_settings); m_ltsCanvas = new LtsCanvas(this, &m_settings, m_ltsManager, m_markManager); setCentralWidget(m_ltsCanvas); m_progressDialog = new QProgressDialog("", QString(), 0, 6, this); m_progressDialog->setMinimumDuration(0); m_ui.informationDock->setWidget(m_infoDock); m_ui.simulationDock->setWidget(m_simDock); m_ui.markDock->setWidget(m_markDock); m_ui.settingsDock->setWidget(m_settingsDock); m_ui.viewMenu->insertAction(m_ui.preferences, m_ui.informationDock->toggleViewAction()); m_ui.viewMenu->insertAction(m_ui.preferences, m_ui.simulationDock->toggleViewAction()); m_ui.viewMenu->insertAction(m_ui.preferences, m_ui.markDock->toggleViewAction()); m_ui.viewMenu->insertAction(m_ui.preferences, m_ui.settingsDock->toggleViewAction()); m_ui.viewMenu->insertSeparator(m_ui.preferences); mcrl2::log::logger::register_output_policy(m_logRelay); connect(&m_logRelay, SIGNAL(logMessage(QString, QString, QDateTime, QString)), this, SLOT(logMessage(QString, QString, QDateTime, QString))); connect(m_ui.open, SIGNAL(triggered()), this, SLOT(open())); connect(m_ui.openTrace, SIGNAL(triggered()), this, SLOT(openTrace())); connect(m_ui.exportBitmap, SIGNAL(triggered()), this, SLOT(exportBitmap())); connect(m_ui.exportText, SIGNAL(triggered()), this, SLOT(exportText())); connect(m_ui.exportVector, SIGNAL(triggered()), this, SLOT(exportVector())); connect(m_ui.exit, SIGNAL(triggered()), QApplication::instance(), SLOT(quit())); connect(m_ui.resetViewpoint, SIGNAL(triggered()), m_ltsCanvas, SLOT(resetView())); connect(m_ui.zoomIntoAbove, SIGNAL(triggered()), m_ltsManager, SLOT(zoomInAbove())); connect(m_ui.zoomIntoBelow, SIGNAL(triggered()), m_ltsManager, SLOT(zoomInBelow())); connect(m_ui.zoomOut, SIGNAL(triggered()), m_ltsManager, SLOT(zoomOut())); connect(m_ui.displayStates, SIGNAL(triggered(bool)), &m_settings.displayStates, SLOT(setValue(bool))); connect(&m_settings.displayStates, SIGNAL(changed(bool)), m_ui.displayStates, SLOT(setChecked(bool))); connect(m_ui.displayTransitions, SIGNAL(triggered(bool)), &m_settings.displayTransitions, SLOT(setValue(bool))); connect(&m_settings.displayTransitions, SIGNAL(changed(bool)), m_ui.displayTransitions, SLOT(setChecked(bool))); connect(m_ui.displayBackpointers, SIGNAL(triggered(bool)), &m_settings.displayBackpointers, SLOT(setValue(bool))); connect(&m_settings.displayBackpointers, SIGNAL(changed(bool)), m_ui.displayBackpointers, SLOT(setChecked(bool))); connect(m_ui.displayWireframe, SIGNAL(triggered(bool)), &m_settings.displayWireframe, SLOT(setValue(bool))); connect(&m_settings.displayWireframe, SIGNAL(changed(bool)), m_ui.displayWireframe, SLOT(setChecked(bool))); connect(m_ui.preferences, SIGNAL(triggered()), m_settingsDialog, SLOT(show())); connect(m_ltsManager, SIGNAL(loadingLts()), this, SLOT(loadingLts())); connect(m_ltsManager, SIGNAL(rankingStates()), this, SLOT(rankingStates())); connect(m_ltsManager, SIGNAL(clusteringStates()), this, SLOT(clusteringStates())); connect(m_ltsManager, SIGNAL(computingClusterInfo()), this, SLOT(computingClusterInfo())); connect(m_ltsManager, SIGNAL(positioningClusters()), this, SLOT(positioningClusters())); connect(m_ltsManager, SIGNAL(positioningStates()), this, SLOT(positioningStates())); connect(m_ltsManager, SIGNAL(ltsStructured()), this, SLOT(hideProgressDialog())); connect(m_ltsManager, SIGNAL(errorLoadingLts()), this, SLOT(hideProgressDialog())); connect(m_ltsManager, SIGNAL(startStructuring()), this, SLOT(startStructuring())); connect(m_ltsManager, SIGNAL(stopStructuring()), this, SLOT(stopStructuring())); connect(m_ltsManager, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); connect(m_ltsManager, SIGNAL(ltsZoomed(LTS *)), this, SLOT(zoomChanged())); m_ui.zoomIntoAbove->setEnabled(false); m_ui.zoomIntoBelow->setEnabled(false); m_ui.zoomOut->setEnabled(false); connect(m_ltsCanvas, SIGNAL(renderingStarted()), this, SLOT(startRendering())); connect(m_ltsCanvas, SIGNAL(renderingFinished()), this, SLOT(clearStatusBar())); QSettings settings("mCRL2", "LTSView"); restoreGeometry(settings.value("geometry").toByteArray()); restoreState(settings.value("windowState").toByteArray()); }