From ad2a2735c936c5183bf7c0a4013a302379e403e6 Mon Sep 17 00:00:00 2001 From: Nicholas Bottone Date: Wed, 13 Dec 2023 01:51:07 -0500 Subject: Setup save image button and setup settings for bulk exporting --- src/mainwindow.cpp | 127 +++++++++++++++++++++++++++-------------------------- 1 file changed, 65 insertions(+), 62 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f096b7e..d96314c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -47,9 +47,13 @@ void MainWindow::initialize() { w_label->setText("W value:"); w_label->setFont(font); - QLabel *rotation_label = new QLabel(); // Rotation label - rotation_label->setText("Time value:"); - rotation_label->setFont(font); + QLabel *curr_time_label = new QLabel(); // Current Time label + curr_time_label->setText("Curr Time: 0"); + curr_time_label->setFont(font); + + QLabel *max_time_label = new QLabel(); // Max Time label + max_time_label->setText("Max Time:"); + max_time_label->setFont(font); // Create file uploader for scene file @@ -59,7 +63,11 @@ void MainWindow::initialize() { saveImage = new QPushButton(); saveImage->setText(QStringLiteral("Save image")); - QGroupBox *xyLayout = new QGroupBox(); // horizonal w slider alignment + // Select directory for bulk output + bulkRender = new QPushButton(); + bulkRender->setText(QStringLiteral("Bulk Render")); + + QGroupBox *xyLayout = new QGroupBox(); // horizontal w slider alignment QHBoxLayout *lxy = new QHBoxLayout(); xySlider = new QSlider(Qt::Orientation::Horizontal); // XY value slider @@ -79,7 +87,7 @@ void MainWindow::initialize() { xyLayout->setLayout(lxy); // XZ Slider - QGroupBox *xzLayout = new QGroupBox(); // horizonal w slider alignment + QGroupBox *xzLayout = new QGroupBox(); // horizontal w slider alignment QHBoxLayout *lxz = new QHBoxLayout(); xzSlider = new QSlider(Qt::Orientation::Horizontal); // XY value slider @@ -99,7 +107,7 @@ void MainWindow::initialize() { xzLayout->setLayout(lxz); // XW Slider - QGroupBox *xwLayout = new QGroupBox(); // horizonal w slider alignment + QGroupBox *xwLayout = new QGroupBox(); // horizontal w slider alignment QHBoxLayout *lxw = new QHBoxLayout(); xwSlider = new QSlider(Qt::Orientation::Horizontal); // XY value slider @@ -119,7 +127,7 @@ void MainWindow::initialize() { xwLayout->setLayout(lxw); // YZ Slider - QGroupBox *yzLayout = new QGroupBox(); // horizonal w slider alignment + QGroupBox *yzLayout = new QGroupBox(); // horizontal w slider alignment QHBoxLayout *lyz = new QHBoxLayout(); yzSlider = new QSlider(Qt::Orientation::Horizontal); // XY value slider @@ -139,7 +147,7 @@ void MainWindow::initialize() { yzLayout->setLayout(lyz); // YW Slider - QGroupBox *ywLayout = new QGroupBox(); // horizonal w slider alignment + QGroupBox *ywLayout = new QGroupBox(); // horizontal w slider alignment QHBoxLayout *lyw = new QHBoxLayout(); ywSlider = new QSlider(Qt::Orientation::Horizontal); // XY value slider @@ -159,7 +167,7 @@ void MainWindow::initialize() { ywLayout->setLayout(lyw); // ZW Slider - QGroupBox *zwLayout = new QGroupBox(); // horizonal w slider alignment + QGroupBox *zwLayout = new QGroupBox(); // horizontal w slider alignment QHBoxLayout *lzw = new QHBoxLayout(); zwSlider = new QSlider(Qt::Orientation::Horizontal); // XY value slider @@ -178,33 +186,33 @@ void MainWindow::initialize() { lzw->addWidget(zwBox); zwLayout->setLayout(lzw); - // Rotation Slider - QGroupBox *rotationLayout = new QGroupBox(); // horizonal w slider alignment - QHBoxLayout *lrotation = new QHBoxLayout(); + // Max Time Slider + QGroupBox *maxTimeGroupBox = new QGroupBox(); // horizontal + QHBoxLayout *maxTimeLayout = new QHBoxLayout(); - rotationSlider = new QSlider(Qt::Orientation::Horizontal); // XY value slider - rotationSlider->setTickInterval(1); - rotationSlider->setMinimum(0); - rotationSlider->setMaximum(18000); - rotationSlider->setValue(1); + maxTimeSlider = new QSlider(Qt::Orientation::Horizontal); + maxTimeSlider->setTickInterval(1); + maxTimeSlider->setMinimum(0); + maxTimeSlider->setMaximum(18000); + maxTimeSlider->setValue(1); - rotationBox = new QDoubleSpinBox(); - rotationBox->setMinimum(0.0f); - rotationBox->setMaximum(600.f); - rotationBox->setSingleStep(1.f); - rotationBox->setValue(settings.rotation); + maxTimeSpinBox = new QSpinBox(); + maxTimeSpinBox->setMinimum(0); + maxTimeSpinBox->setMaximum(600); + maxTimeSpinBox->setSingleStep(1); + maxTimeSpinBox->setValue(settings.rotation); - lrotation->addWidget(rotationSlider); - lrotation->addWidget(rotationBox); - rotationLayout->setLayout(lrotation); + maxTimeLayout->addWidget(maxTimeSlider); + maxTimeLayout->addWidget(maxTimeSpinBox); + maxTimeGroupBox->setLayout(maxTimeLayout); - // checkbox - rotateNegative = new QCheckBox(); - rotateNegative->setText(QStringLiteral("Reverse Rotation")); - rotateNegative->setChecked(false); + // // checkbox + // rotateNegative = new QCheckBox(); + // rotateNegative->setText(QStringLiteral("Reverse Rotation")); + // rotateNegative->setChecked(false); // w Slider - QGroupBox *wLayout = new QGroupBox(); // horizonal w slider alignment + QGroupBox *wLayout = new QGroupBox(); // horizontal w slider alignment QHBoxLayout *lw = new QHBoxLayout(); wSlider = new QSlider(Qt::Orientation::Horizontal); // XY value slider @@ -240,11 +248,12 @@ void MainWindow::initialize() { vLayout->addWidget(zwLayout); vLayout->addWidget(w_label); vLayout->addWidget(wLayout); - vLayout->addWidget(rotation_label); - vLayout->addWidget(rotationLayout); - - vLayout->addWidget(rotateNegative); + vLayout->addWidget(curr_time_label); + vLayout->addWidget(max_time_label); + vLayout->addWidget(maxTimeGroupBox); + vLayout->addWidget(bulkRender); + // vLayout->addWidget(rotateNegative); connectUIElements(); @@ -265,7 +274,7 @@ void MainWindow::connectUIElements() { connectyz(); connectyw(); connectzw(); - connectRotationSlider(); + connectMaxTimeSlider(); connectNegativeRotation(); connect(rayTracer, &RayTracer::xyRotationChanged, this, &MainWindow::updateXySlider); connect(rayTracer, &RayTracer::xzRotationChanged, this, &MainWindow::updateXzSlider); @@ -321,10 +330,10 @@ void MainWindow::connectzw() { this, &MainWindow::onValChangezwBox); } -void MainWindow::connectRotationSlider() { - connect(rotationSlider, &QSlider::valueChanged, this, &MainWindow::onValChangeRotationSlider); - connect(rotationBox, static_cast(&QDoubleSpinBox::valueChanged), - this, &MainWindow::onValChangeRotationBox); +void MainWindow::connectMaxTimeSlider() { + connect(maxTimeSlider, &QSlider::valueChanged, this, &MainWindow::onValChangeMaxTimeSlider); + connect(maxTimeSpinBox, static_cast(&QSpinBox::valueChanged), + this, &MainWindow::onValChangeMaxTimeBox); } void MainWindow::connectNegativeRotation() { @@ -360,24 +369,18 @@ void MainWindow::onUploadFile() { } void MainWindow::onSaveImage() { - if (settings.sceneFilePath.empty()) { - std::cout << "No scene file loaded." << std::endl; - return; - } + // if (settings.sceneFilePath.empty()) { + // std::cout << "No scene file loaded." << std::endl; + // return; + // } std::string sceneName = settings.sceneFilePath.substr(0, settings.sceneFilePath.find_last_of(".")); sceneName = sceneName.substr(sceneName.find_last_of("/")+1); QString filePath = QFileDialog::getSaveFileName(this, tr("Save Image"), QDir::currentPath() - .append(QDir::separator()) - .append("student_outputs") - .append(QDir::separator()) - .append("lights-camera") - .append(QDir::separator()) - .append("required") .append(QDir::separator()) .append(sceneName), tr("Image Files (*.png)")); std::cout << "Saving image to: \"" << filePath.toStdString() << "\"." << std::endl; -// realtime->saveViewportImage(filePath.toStdString()); + rayTracer->saveViewportImage(filePath.toStdString()); } void MainWindow::onValChangexySlider(int newValue) { @@ -464,18 +467,18 @@ void MainWindow::onValChangezwBox(double newValue) { // rayTracer->settingsChanged(imageLabel); } -void MainWindow::onValChangeRotationSlider(int newValue) { +void MainWindow::onValChangeMaxTimeSlider(int newValue) { //wSlider->setValue(newValue); - rotationBox->setValue(newValue/100.f); - settings.rotation = rotationBox->value(); - // rayTracer->settingsChanged(imageLabel); + maxTimeSpinBox->setValue(newValue/100.f); + settings.maxTime = maxTimeSpinBox->value(); + rayTracer->settingsChanged(imageLabel); } -void MainWindow::onValChangeRotationBox(double newValue) { - rotationSlider->setValue(int(newValue*100.f)); +void MainWindow::onValChangeMaxTimeBox(double newValue) { + maxTimeSlider->setValue(int(newValue*100.f)); //wBox->setValue(newValue); - settings.rotation = rotationBox->value(); - // rayTracer->settingsChanged(imageLabel); + settings.rotation = maxTimeSpinBox->value(); + rayTracer->settingsChanged(imageLabel); } void MainWindow::onValChangeWSlider(int newValue) { @@ -536,7 +539,7 @@ void MainWindow::updateZwSlider(double value) { } void MainWindow::updateRotationSlider(float value) { - rotationSlider->setValue(int(value*100.f)); - rotationBox->setValue(value); - // rayTracer->settingsChanged(imageLabel); -} \ No newline at end of file + maxTimeSlider->setValue(int(value*100.f)); + maxTimeSpinBox->setValue(value); + rayTracer->settingsChanged(imageLabel); +} -- cgit v1.2.3-70-g09d2 From 9f0490eab74aafd867ba2a82d7180f89faedcbf7 Mon Sep 17 00:00:00 2001 From: Nicholas Bottone Date: Wed, 13 Dec 2023 02:02:13 -0500 Subject: Add bulk rendering functionality --- .gitignore | 1 + src/mainwindow.cpp | 20 +++++++++++++++++++- src/mainwindow.h | 2 ++ src/raytracer/raytracer.cpp | 4 ++-- src/settings.h | 2 +- 5 files changed, 25 insertions(+), 4 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/.gitignore b/.gitignore index bd664f2..bdc990e 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ build/ .vscode/ .DS_Store +**/.DS_Store diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d96314c..f76f13a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -216,7 +216,7 @@ void MainWindow::initialize() { QHBoxLayout *lw = new QHBoxLayout(); wSlider = new QSlider(Qt::Orientation::Horizontal); // XY value slider - wSlider->setTickInterval(0.01); + wSlider->setTickInterval(1); wSlider->setMinimum(-10000); wSlider->setMaximum(10000); wSlider->setValue(0); @@ -268,6 +268,7 @@ void MainWindow::finish() { void MainWindow::connectUIElements() { connectUploadFile(); connectSaveImage(); + connectBulkRender(); connectxy(); connectxz(); connectxw(); @@ -294,6 +295,10 @@ void MainWindow::connectSaveImage() { connect(saveImage, &QPushButton::clicked, this, &MainWindow::onSaveImage); } +void MainWindow::connectBulkRender() { + connect(bulkRender, &QPushButton::clicked, this, &MainWindow::onBulkRender); +} + void MainWindow::connectxy() { connect(xySlider, &QSlider::valueChanged, this, &MainWindow::onValChangexySlider); connect(xyBox, static_cast(&QDoubleSpinBox::valueChanged), @@ -383,6 +388,19 @@ void MainWindow::onSaveImage() { rayTracer->saveViewportImage(filePath.toStdString()); } +void MainWindow::onBulkRender() { + // if (settings.sceneFilePath.empty()) { + // std::cout << "No scene file loaded." << std::endl; + // return; + // } + std::string sceneName = settings.sceneFilePath.substr(0, settings.sceneFilePath.find_last_of(".")); + sceneName = sceneName.substr(sceneName.find_last_of("/")+1); + QString folderPath = QFileDialog::getExistingDirectory(this, tr("Select Directory for Bulk Render"), + QDir::currentPath()); + std::cout << "Setting bulk output path to: \"" << folderPath.toStdString() << "\"." << std::endl; + settings.bulkOutputFolderPath = folderPath.toStdString(); +} + void MainWindow::onValChangexySlider(int newValue) { //wSlider->setValue(newValue); xyBox->setValue(newValue/100.f); diff --git a/src/mainwindow.h b/src/mainwindow.h index db7b096..1c2485c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -23,6 +23,7 @@ private: void connectUIElements(); void connectUploadFile(); void connectSaveImage(); + void connectBulkRender(); void connectxy(); void connectxz(); void connectxw(); @@ -60,6 +61,7 @@ private: private slots: void onUploadFile(); void onSaveImage(); + void onBulkRender(); void onValChangexySlider(int newValue); void onValChangexyBox(double newValue); void onValChangexzSlider(int newValue); diff --git a/src/raytracer/raytracer.cpp b/src/raytracer/raytracer.cpp index f831f82..8f4a190 100644 --- a/src/raytracer/raytracer.cpp +++ b/src/raytracer/raytracer.cpp @@ -69,9 +69,9 @@ void RayTracer::render(RGBA *imageData, const RayTraceScene &scene) { } } - if (settings.bulkOutputFilePath.size() > 0) { // means we are doing bulk rendering + if (settings.bulkOutputFolderPath.size() > 0) { // means we are doing bulk rendering // save the image to the bulk directory - std::string filePath = settings.bulkOutputFilePath + QDir::separator().toLatin1() + std::to_string(settings.currentTime) + ".png"; + std::string filePath = settings.bulkOutputFolderPath + QDir::separator().toLatin1() + std::to_string(settings.currentTime) + ".png"; saveViewportImage(filePath); if (settings.currentTime < settings.maxTime) { // still more to render // render the next frame diff --git a/src/settings.h b/src/settings.h index 0865e44..32c6484 100644 --- a/src/settings.h +++ b/src/settings.h @@ -17,7 +17,7 @@ struct Settings { float w = 0.f; int currentTime = 0; int maxTime = 0; - std::string bulkOutputFilePath; + std::string bulkOutputFolderPath; }; -- cgit v1.2.3-70-g09d2