Visualisierung 2
Comparison of Hue Preserving Rendering to Alpha Composing
MainWindow.cpp
Go to the documentation of this file.
1 
8 #include "MainWindow.h"
9 #include <QFileDialog>
10 #include <QPainter>
11 #include <QMessageBox>
12 
13 #include "Renderable.h"
14 
15 MainWindow::MainWindow(QWidget *parent)
16  : QMainWindow(parent), volume(0)
17 {
18  mainWindow = new Ui::MainWindow();
19  mainWindow->setupUi(this);
20 
21  connect(mainWindow->actionOpen, SIGNAL(triggered()), this, SLOT(openFileAction()));
22  connect(mainWindow->actionClose, SIGNAL(triggered()), this, SLOT(closeAction()));
23 }
24 
26 {
27  delete volume;
28 }
29 
30 void MainWindow::on_renderButton_clicked()
31 {
32  if(readyToDraw){
33  // pass transfer function parameters
34  mainWindow->AlphaCompositingOpenGLWidget->setRegion(regionSeperator,regionColor1,regionColor2);
35  mainWindow->HuePreservingOpenGLWidget->setRegion(regionSeperator,regionColor1,regionColor2);
36 
37  // render full screen quad on both widgets
38  std::vector<glm::vec3> vertices = { glm::vec3(-1.0f, -1.0f, 0.0f), glm::vec3(1.0f, -1.0f, 0.0f), glm::vec3(-1.0f, 1.0f, 0.0f),glm::vec3(1.0f, 1.0f, 0.0f) };
39  std::vector<unsigned int> indices = { 0, 1, 2, 1, 3, 2};
40  RenderData data = { vertices, indices };
41  mainWindow->AlphaCompositingOpenGLWidget->setShader("shader/passthrough.vert", "shader/alpha.frag");
42  mainWindow->AlphaCompositingOpenGLWidget->setRenderObject(data);
43  mainWindow->AlphaCompositingOpenGLWidget->setOrientation(mainWindow->orientationBox->currentIndex());
44  mainWindow->AlphaCompositingOpenGLWidget->update();
45  mainWindow->HuePreservingOpenGLWidget->setShader("shader/passthrough.vert", "shader/hue.frag");
46  mainWindow->HuePreservingOpenGLWidget->setRenderObject(data);
47  mainWindow->HuePreservingOpenGLWidget->setOrientation(mainWindow->orientationBox->currentIndex());
48  mainWindow->HuePreservingOpenGLWidget->update();
49  }
50  else
51  {
52  QMessageBox msgBox;
53  msgBox.setText("Please select a data set to render!");
54  msgBox.exec();
55  }
56 }
57 
59 {
60  QString filename = QFileDialog::getOpenFileName(this, "Data File", 0, tr("Data Files (*.dat *.gri *.csv)"));
61 
62  if (!filename.isEmpty()){
63  string fn = filename.toStdString();
64  bool success = false;
65  mainWindow->progressBar->setEnabled(true);
66  mainWindow->labelTop->setText("Loading data ...");
67 
68 
69  if (fn.substr(fn.find_last_of(".") + 1) == "dat"){
70  volume = new Volume();
71  success = volume->loadFromFile(filename,mainWindow->progressBar);
72  }
73 
74  mainWindow->progressBar->setEnabled(false);
75 
76  if (success) {
77  auto tex = volume->generate3DTex();
78  if (tex->isCreated()) {
79  // set volume
80  mainWindow->AlphaCompositingOpenGLWidget->setVolumeTexture(tex);
81  mainWindow->HuePreservingOpenGLWidget->setVolumeTexture(tex);
82  }
83  }
84 
85  if (success){
86  mainWindow->labelTop->setText("File LOADED [" + filename + "]");
87  readyToDraw = true;
88  }
89  else{
90  mainWindow->labelTop->setText("ERROR loading file " + filename + "!");
91  mainWindow->progressBar->setValue(0);
92  }
93  }
94 }
95 
97 {
98  close();
99 }
100 
101 void MainWindow::on_color1Button_clicked()
102 {
103  QColor color = QColorDialog::getColor(Qt::red,this,"Choose a color for region 1");
104  if(color.isValid()){
105  QString qss = QString("background-color: %1").arg(color.name());
106  mainWindow->color1Button->setStyleSheet(qss);
107  regionColor1 = color;
108  updateBothViews();
109  }
110 }
111 
112 void MainWindow::on_color2Button_clicked()
113 {
114  QColor color = QColorDialog::getColor(Qt::red,this,"Choose a color for region 2");
115  if(color.isValid()){
116  QString qss = QString("background-color: %1").arg(color.name());
117  mainWindow->color2Button->setStyleSheet(qss);
118  regionColor2 = color;
119  updateBothViews();
120  }
121 }
122 
123 void MainWindow::on_region1Slider_valueChanged()
124 {
125  float val = mainWindow->region1Slider->value();
126  QString string = "[0,";
127  string.append(QString::number(val/100));
128  string.append(")");
129  mainWindow->region1RangeLabel->setText(string);
130 
131  string = "[";
132  string.append(QString::number(val/100));
133  string.append(",1]");
134  mainWindow->region2RangeLabel->setText(string);
135  regionSeperator = val/100;
136 }
137 
138 void MainWindow::on_region1Slider_sliderReleased(){
139  updateBothViews();
140 }
141 
142 void MainWindow::updateBothViews(){
143  mainWindow->AlphaCompositingOpenGLWidget->setRegion(regionSeperator,regionColor1,regionColor2);
144  mainWindow->HuePreservingOpenGLWidget->setRegion(regionSeperator,regionColor1,regionColor2);
145  mainWindow->AlphaCompositingOpenGLWidget->update();
146  mainWindow->HuePreservingOpenGLWidget->update();
147 }
148 
149 void MainWindow::on_orientationBox_currentIndexChanged(int index)
150 {
151  mainWindow->AlphaCompositingOpenGLWidget->setOrientation(index);
152  mainWindow->HuePreservingOpenGLWidget->setOrientation(index);
153  updateBothViews();
154 }
out vec4 color
Definition: alpha.frag:12
Modified volume loader class from Vis 1.
Definition: Volume.h:76
void closeAction()
closeAction terminates the program whenever the "Close" option in the drop down menu is selected...
Definition: MainWindow.cpp:96
QOpenGLTexture * generate3DTex()
generate3DTex transforms the loaded volume data set into a 3D texture which can be sampled in the gls...
Definition: Volume.cpp:257
bool loadFromFile(QString filename, QProgressBar *progressBar)
Definition: Volume.cpp:182
uniform sampler3D volume
Definition: alpha.frag:16
void openFileAction()
openFileAction opens a file-chooser dialogue whenever the "Open..." option in the drop down menu is s...
Definition: MainWindow.cpp:58
MainWindow(QWidget *parent=0)
Definition: MainWindow.cpp:15
Helper struct for passing renderable data in the application.
Definition: Renderable.h:17