diff --git a/core/VolumeReader.cpp b/core/VolumeReader.cpp index 0a9b506..b0fe17a 100644 --- a/core/VolumeReader.cpp +++ b/core/VolumeReader.cpp @@ -8,7 +8,7 @@ #include "VolumeReader.h" #define STB_IMAGE_WRITE_IMPLEMENTATION -#include "utils/std_image_write.h" +#include "utils/stb_image_write.h" void VolumeReader::Read(std::string filename) { diff --git a/gui/canvas.cpp b/gui/canvas.cpp index 72fb8ec..911e8e4 100644 --- a/gui/canvas.cpp +++ b/gui/canvas.cpp @@ -3,6 +3,7 @@ // #include "canvas.h" +#include "utils/stb_image_write.h" Canvas::Canvas(const QGLFormat &format, QWidget *parent) : QGLWidget(format, parent) { @@ -93,6 +94,14 @@ void Canvas::paintGL() else { render_pathtracer(img, renderParams); + if(renderParams.frameNo == 0) + { + char* data = new char[WIDTH * HEIGHT * 4]; + cudaMemcpy(data, img, sizeof(glm::u8vec4) * WIDTH * HEIGHT, cudaMemcpyDeviceToHost); + + stbi_write_tga("0.tga", WIDTH, HEIGHT, 4, data); + delete []data; + } } checkCudaErrors(cudaDeviceSynchronize()); @@ -109,6 +118,7 @@ void Canvas::paintGL() void Canvas::mousePressEvent(QMouseEvent *e) { + this->setFocus(); if((e->buttons() & Qt::LeftButton) || (e->buttons() & Qt::MidButton)) { mouseStartPoint = PixelPosToViewPos(e->posF()); @@ -184,4 +194,33 @@ void Canvas::ZoomToExtent() auto maxSpan = fmaxf(extent.x, fmaxf(extent.y, extent.z)); maxSpan *= 1.5f; // enlarge it slightly eyeDist = maxSpan / (2 * tan(glm::radians(fov * 0.5f))); -} \ No newline at end of file +} +void Canvas::keyPressEvent(QKeyEvent *e) +{ + if(e->key() == Qt::Key_Down) + { + viewMat = glm::rotate(viewMat, static_cast(glm::radians(180.f)), glm::vec3(0.f, 1.f, 0.f)); + + UpdateCamera(); + updateGL(); + ReStartRender(); + } + else if(e->key() == Qt::Key_Left) + { + viewMat = glm::rotate(viewMat, static_cast(glm::radians(90.f)), glm::vec3(0.f, 1.f, 0.f)); + + UpdateCamera(); + updateGL(); + ReStartRender(); + } + else if(e->key() == Qt::Key_Right) + { + viewMat = glm::rotate(viewMat, static_cast(glm::radians(-90.f)), glm::vec3(0.f, 1.f, 0.f)); + + UpdateCamera(); + updateGL(); + ReStartRender(); + } + + QWidget::keyPressEvent(e); +} diff --git a/gui/canvas.h b/gui/canvas.h index 7a39b1e..4bd0b78 100644 --- a/gui/canvas.h +++ b/gui/canvas.h @@ -191,6 +191,8 @@ class Canvas : public QGLWidget void mouseMoveEvent(QMouseEvent* e); void wheelEvent(QWheelEvent* e); + void keyPressEvent(QKeyEvent *e); + // timer void timerEvent(QTimerEvent* e) {this->update();} diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 8a078e0..dd0af8a 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -75,6 +75,9 @@ void MainWindow::ConfigureTransferFunction() connect(ui->SliderWidget_DensityScale, SIGNAL(valueChanged(double)), this, SLOT(onDensityScaleChanged(double))); connect(ui->SliderWidget_GradientFactor, SIGNAL(valueChanged(double)), this, SLOT(onGradientFactorChanged(double))); + + connect(ui->pushButton_saveTF, SIGNAL(clicked()), this, SLOT(onSaveTF())); + connect(ui->pushButton_loadTF, SIGNAL(clicked()), this, SLOT(onLoadTF())); } void MainWindow::onTransferFunctionChanged() @@ -478,3 +481,21 @@ void MainWindow::onGradientFactorChanged(double g) { canvas->SetGradientFactor(g); } + +void MainWindow::onSaveTF() +{ + //QString filename = QFileDialog::getSaveFileName(this, tr("Save TF"), "", tr("TF file (*.tf)")); + //if(!filename.isNull()) + //{ + tf->SaveCurrentTFConfiguration(); + //} +} + +void MainWindow::onLoadTF() +{ + //QString filename = QFileDialog::getOpenFileName(this, tr("Load TF"), "", tr("TF file (*.tf)")); + //if(!filename.isNull()) + //{ + tf->LoadExistingTFConfiguration(); + //} +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 103c716..ba5f677 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -75,6 +75,9 @@ private slots: void onYClipChanged(double min, double max); void onZClipChanged(double min, double max); + void onSaveTF(); + void onLoadTF(); + private: Ui::MainWindow *ui; diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index becd54b..8566024 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -110,9 +110,9 @@ 0 - -180 + -216 363 - 766 + 808 @@ -250,6 +250,24 @@ + + + + + + SaveTF + + + + + + + LoadTF + + + + + @@ -315,7 +333,7 @@ 0 0 - 363 + 237 689 @@ -655,8 +673,8 @@ 0 0 - 378 - 550 + 245 + 204 @@ -781,8 +799,8 @@ 0 0 - 378 - 550 + 124 + 168 diff --git a/utils/std_image_write.h b/utils/stb_image_write.h similarity index 100% rename from utils/std_image_write.h rename to utils/stb_image_write.h