Skip to content

Commit

Permalink
add save load tf
Browse files Browse the repository at this point in the history
  • Loading branch information
孙万捷 authored and 孙万捷 committed Jan 5, 2017
1 parent 23b3b1a commit 973c84d
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 9 deletions.
2 changes: 1 addition & 1 deletion core/VolumeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
41 changes: 40 additions & 1 deletion gui/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

#include "canvas.h"
#include "utils/stb_image_write.h"

Canvas::Canvas(const QGLFormat &format, QWidget *parent) : QGLWidget(format, parent)
{
Expand Down Expand Up @@ -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());

Expand All @@ -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());
Expand Down Expand Up @@ -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)));
}
}
void Canvas::keyPressEvent(QKeyEvent *e)
{
if(e->key() == Qt::Key_Down)
{
viewMat = glm::rotate(viewMat, static_cast<float>(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<float>(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<float>(glm::radians(-90.f)), glm::vec3(0.f, 1.f, 0.f));

UpdateCamera();
updateGL();
ReStartRender();
}

QWidget::keyPressEvent(e);
}
2 changes: 2 additions & 0 deletions gui/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();}

Expand Down
21 changes: 21 additions & 0 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
//}
}
3 changes: 3 additions & 0 deletions gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 25 additions & 7 deletions gui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-180</y>
<y>-216</y>
<width>363</width>
<height>766</height>
<height>808</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
Expand Down Expand Up @@ -250,6 +250,24 @@
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_8">
<item row="0" column="0">
<widget class="QPushButton" name="pushButton_saveTF">
<property name="text">
<string>SaveTF</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButton_loadTF">
<property name="text">
<string>LoadTF</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -315,7 +333,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>363</width>
<width>237</width>
<height>689</height>
</rect>
</property>
Expand Down Expand Up @@ -655,8 +673,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>378</width>
<height>550</height>
<width>245</width>
<height>204</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
Expand Down Expand Up @@ -781,8 +799,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>378</width>
<height>550</height>
<width>124</width>
<height>168</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
Expand Down
File renamed without changes.

0 comments on commit 973c84d

Please sign in to comment.