1 |
#include "mainwindow.h" |
2 |
#include "ui_mainwindow.h" |
3 |
#include "ui_exposuredialog.h" |
4 |
#include "ui_parameterdialog.h" |
5 |
#include "ui_viewdialog.h" |
6 |
#include "ui_incrementsdialog.h" |
7 |
#include "ui_commandsdialog.h" |
8 |
|
9 |
#include <QtGui/QMessageBox> |
10 |
#include <QtGui/QLineEdit> |
11 |
#include <QtGui/QCloseEvent> |
12 |
#include <QtGui/QFileDialog> |
13 |
#include <QtGui/QInputDialog> |
14 |
#include <QtCore/QDebug> |
15 |
#include <QtCore/QTime> |
16 |
#include <QtCore/QTextStream> |
17 |
|
18 |
#include <iostream> |
19 |
|
20 |
// Process a command |
21 |
extern "C" void qt_process_command(const char*); |
22 |
// set the abort flag to stop a render in progress |
23 |
extern "C" void qt_set_abort(int ); |
24 |
extern "C" |
25 |
{ |
26 |
//externs for exposure dialog |
27 |
extern VIEW ourview; |
28 |
extern double exposure; |
29 |
//externs for parameters dialog |
30 |
extern COLOR ambval; /* ambient value */ |
31 |
extern int ambvwt; /* initial weight for ambient value */ |
32 |
extern double ambacc; /* ambient accuracy */ |
33 |
extern int ambres; /* ambient resolution */ |
34 |
extern int ambdiv; /* ambient divisions */ |
35 |
extern int ambssamp; /* ambient super-samples */ |
36 |
extern int ambounce; /* ambient bounces */ |
37 |
extern double shadcert; /* shadow testing certainty */ |
38 |
extern double shadthresh; /* shadow threshold */ |
39 |
extern int directvis; /* light sources visible to eye? */ |
40 |
extern COLOR cextinction; /* global extinction coefficient */ |
41 |
extern COLOR salbedo; /* global scattering albedo */ |
42 |
extern double seccg; /* global scattering eccentricity */ |
43 |
extern double ssampdist; /* scatter sampling distance */ |
44 |
extern double specthresh; /* specular sampling threshold */ |
45 |
extern double specjitter; /* specular sampling jitter */ |
46 |
extern int maxdepth; /* maximum recursion depth */ |
47 |
extern double minweight; /* minimum ray weight */ |
48 |
extern double dstrsrc; /* square source distribution */ |
49 |
extern double srcsizerat; /* maximum source size/dist. ratio */ |
50 |
extern int psample; /* pixel sample size */ |
51 |
extern double maxdiff; /* max. sample difference */ |
52 |
void quit(int code); |
53 |
} |
54 |
MainWindow::MainWindow(int width, int height, const char* name, const char* id) |
55 |
{ |
56 |
m_ui = new Ui::MainWindow; |
57 |
m_ui->setupUi(this); |
58 |
m_exposureDialog = new QDialog(); |
59 |
m_exposureDialogUi = new Ui::exposureDialog; |
60 |
m_exposureDialogUi->setupUi(m_exposureDialog); |
61 |
m_parameterDialog = new QDialog(); |
62 |
m_parameterDialogUi = new Ui::parameterDialog; |
63 |
m_parameterDialogUi->setupUi(m_parameterDialog); |
64 |
m_viewDialog = new QDialog(); |
65 |
m_viewDialogUi = new Ui::viewDialog; |
66 |
m_viewDialogUi->setupUi(m_viewDialog); |
67 |
this->smallIncrement = 0.1; |
68 |
this->largeIncrement = 0.5; |
69 |
m_incrementsDialog = new QDialog(); |
70 |
m_incrementsDialogUi = new Ui::incrementsDialog; |
71 |
m_incrementsDialogUi->setupUi(m_incrementsDialog); |
72 |
m_commandsDialog = new QDialog(); |
73 |
m_commandsDialogUi = new Ui::commandsDialog; |
74 |
m_commandsDialogUi->setupUi(m_commandsDialog); |
75 |
this->currentImageName = ""; |
76 |
createActions(); |
77 |
connectSlots(); |
78 |
m_ui->progressBar->setMinimum(0); |
79 |
m_ui->progressBar->setMaximum(100); |
80 |
setWindowTitle(tr(id)); |
81 |
resize(width, height); |
82 |
updatePositionLabels(); |
83 |
} |
84 |
|
85 |
MainWindow::~MainWindow() |
86 |
{ |
87 |
delete m_ui; |
88 |
delete m_exposureDialog; |
89 |
delete m_parameterDialog; |
90 |
delete m_viewDialog; |
91 |
delete m_incrementsDialog; |
92 |
delete m_commandsDialog; |
93 |
} |
94 |
|
95 |
void MainWindow::setProgress(int p) |
96 |
{ |
97 |
m_ui->progressBar->setValue(p); |
98 |
} |
99 |
|
100 |
RvuWidget* MainWindow::getRvuWidget() const |
101 |
{ |
102 |
return m_ui->rvuWidget; |
103 |
} |
104 |
|
105 |
void MainWindow::closeEvent(QCloseEvent *event) |
106 |
{ |
107 |
// Here is a good spot to shut down the rest of the code before exit. |
108 |
this->m_exposureDialog->close(); |
109 |
this->m_parameterDialog->close(); |
110 |
this->m_viewDialog->close(); |
111 |
this->m_incrementsDialog->close(); |
112 |
this->m_commandsDialog->close(); |
113 |
} |
114 |
|
115 |
void MainWindow::createActions() |
116 |
{ |
117 |
m_minimizeAction = new QAction(tr("Mi&nimize"), this); |
118 |
connect(m_minimizeAction, SIGNAL(triggered()), this, SLOT(hide())); |
119 |
|
120 |
m_maximizeAction = new QAction(tr("Ma&ximize"), this); |
121 |
connect(m_maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized())); |
122 |
|
123 |
m_restoreAction = new QAction(tr("&Restore"), this); |
124 |
connect(m_restoreAction, SIGNAL(triggered()), this, SLOT(showNormal())); |
125 |
} |
126 |
|
127 |
void MainWindow::connectSlots() |
128 |
{ |
129 |
connect(m_ui->exit, SIGNAL(triggered()), qApp, SLOT(quit())); |
130 |
connect(m_ui->pushButton, SIGNAL(clicked()), this, SLOT(buttonPressed())); |
131 |
connect(m_ui->lineEdit, SIGNAL(returnPressed()), |
132 |
this, SLOT(buttonPressed())); |
133 |
connect(m_ui->redraw, SIGNAL(triggered()), this, SLOT(redraw())); |
134 |
connect(m_ui->trace, SIGNAL(triggered()), this, SLOT(traceRay())); |
135 |
connect(m_ui->toggleToolBar, SIGNAL(triggered()), |
136 |
this, SLOT(toggleToolBar())); |
137 |
connect(m_ui->toggleStatusBar, SIGNAL(triggered()), |
138 |
this, SLOT(toggleStatusBar())); |
139 |
connect(m_ui->toggleTranslateTool, SIGNAL(triggered()), |
140 |
this, SLOT(toggleTranslateTool())); |
141 |
connect(m_ui->exposure, SIGNAL(triggered()), |
142 |
this, SLOT(showExposureDialog())); |
143 |
connect(m_ui->parameters, SIGNAL(triggered()), |
144 |
this, SLOT(showParameterDialog())); |
145 |
connect(m_ui->view, SIGNAL(triggered()), |
146 |
this, SLOT(showViewDialog())); |
147 |
connect(m_ui->saveImage, SIGNAL(triggered()), |
148 |
this, SLOT(saveCurrentImage())); |
149 |
connect(m_ui->saveImageAs, SIGNAL(triggered()), |
150 |
this, SLOT(saveImage())); |
151 |
connect(m_ui->loadView, SIGNAL(triggered()), |
152 |
this, SLOT(loadView())); |
153 |
connect(m_ui->loadRif, SIGNAL(triggered()), |
154 |
this, SLOT(loadRif())); |
155 |
connect(m_ui->backfaceVisibility, SIGNAL(triggered()), |
156 |
this, SLOT(toggleBackfaceVisibility())); |
157 |
connect(m_ui->grayscale, SIGNAL(triggered()), |
158 |
this, SLOT(toggleGrayscale())); |
159 |
connect(m_ui->irradiance, SIGNAL(triggered()), |
160 |
this, SLOT(toggleIrradiance())); |
161 |
connect(m_ui->appendToRif, SIGNAL(triggered()), |
162 |
this, SLOT(appendToRif())); |
163 |
connect(m_ui->appendToView, SIGNAL(triggered()), |
164 |
this, SLOT(appendToView())); |
165 |
connect(m_ui->GUI_Increments, SIGNAL(triggered()), |
166 |
this, SLOT(showIncrementsDialog())); |
167 |
connect(m_ui->commands, SIGNAL(triggered()), |
168 |
this, SLOT(showCommandsDialog())); |
169 |
connect(m_ui->aboutRvu, SIGNAL(triggered()), |
170 |
this, SLOT(showAbout())); |
171 |
|
172 |
//movement buttons |
173 |
connect(m_ui->xPlus1Button, SIGNAL(clicked()), |
174 |
this, SLOT(moveXPlusOne())); |
175 |
connect(m_ui->xPlus2Button, SIGNAL(clicked()), |
176 |
this, SLOT(moveXPlusTwo())); |
177 |
connect(m_ui->xMinus1Button, SIGNAL(clicked()), |
178 |
this, SLOT(moveXMinusOne())); |
179 |
connect(m_ui->xMinus2Button, SIGNAL(clicked()), |
180 |
this, SLOT(moveXMinusTwo())); |
181 |
connect(m_ui->yPlus1Button, SIGNAL(clicked()), |
182 |
this, SLOT(moveYPlusOne())); |
183 |
connect(m_ui->yPlus2Button, SIGNAL(clicked()), |
184 |
this, SLOT(moveYPlusTwo())); |
185 |
connect(m_ui->yMinus1Button, SIGNAL(clicked()), |
186 |
this, SLOT(moveYMinusOne())); |
187 |
connect(m_ui->yMinus2Button, SIGNAL(clicked()), |
188 |
this, SLOT(moveYMinusTwo())); |
189 |
connect(m_ui->zPlus1Button, SIGNAL(clicked()), |
190 |
this, SLOT(moveZPlusOne())); |
191 |
connect(m_ui->zPlus2Button, SIGNAL(clicked()), |
192 |
this, SLOT(moveZPlusTwo())); |
193 |
connect(m_ui->zMinus1Button, SIGNAL(clicked()), |
194 |
this, SLOT(moveZMinusOne())); |
195 |
connect(m_ui->zMinus2Button, SIGNAL(clicked()), |
196 |
this, SLOT(moveZMinusTwo())); |
197 |
|
198 |
//exposure dialog |
199 |
connect(m_exposureDialogUi->exposureButtonBox, SIGNAL(accepted()), |
200 |
this, SLOT(adjustExposure())); |
201 |
connect(m_exposureDialogUi->exposureButtonBox, SIGNAL(rejected()), |
202 |
this, SLOT(hideExposureDialog())); |
203 |
connect(m_exposureDialogUi->natural, SIGNAL(toggled(bool)), |
204 |
this, SLOT(updatePointRadio())); |
205 |
connect(m_exposureDialogUi->relative, SIGNAL(toggled(bool)), |
206 |
this, SLOT(updatePointRadio())); |
207 |
|
208 |
//parameter dialog |
209 |
connect(m_parameterDialogUi->buttonBox, SIGNAL(accepted()), |
210 |
this, SLOT(adjustParameters())); |
211 |
connect(m_parameterDialogUi->buttonBox, SIGNAL(rejected()), |
212 |
this, SLOT(hideParameterDialog())); |
213 |
|
214 |
//view dialog |
215 |
connect(m_viewDialogUi->buttonBox, SIGNAL(accepted()), |
216 |
this, SLOT(adjustView())); |
217 |
connect(m_viewDialogUi->buttonBox, SIGNAL(rejected()), |
218 |
this, SLOT(hideViewDialog())); |
219 |
|
220 |
//increments dialog |
221 |
connect(m_incrementsDialogUi->buttonBox, SIGNAL(accepted()), |
222 |
this, SLOT(adjustIncrements())); |
223 |
connect(m_incrementsDialogUi->buttonBox, SIGNAL(rejected()), |
224 |
this, SLOT(hideIncrementsDialog())); |
225 |
} |
226 |
|
227 |
void MainWindow::doSubmit() |
228 |
{ |
229 |
QString command = m_ui->lineEdit->text(); |
230 |
bool centerCrossHairs = false; |
231 |
if(command == "aim") |
232 |
{ |
233 |
centerCrossHairs = true; |
234 |
} |
235 |
m_ui->lineEdit->setText(""); |
236 |
m_ui->progressBar->setEnabled(true); |
237 |
this->setProgress(0); |
238 |
QTime t; |
239 |
t.start(); |
240 |
if (command.isEmpty()) |
241 |
{ |
242 |
this->m_ui->pushButton->setText("Submit"); |
243 |
enableInterface(true); |
244 |
return; |
245 |
} |
246 |
qt_process_command(command.toAscii()); |
247 |
QString msg; |
248 |
QTextStream(&msg) << "Render Time: " << t.elapsed() << " ms"; |
249 |
m_ui->messageBox->appendPlainText(msg); |
250 |
this->m_ui->pushButton->setText("Submit"); |
251 |
enableInterface(true); |
252 |
if(centerCrossHairs) |
253 |
{ |
254 |
QPoint p = this->m_ui->rvuWidget->geometry().center(); |
255 |
this->m_ui->rvuWidget->setPosition(p.x(), p.y()); |
256 |
} |
257 |
updatePositionLabels(); |
258 |
} |
259 |
|
260 |
|
261 |
void MainWindow::buttonPressed() |
262 |
{ |
263 |
if( m_ui->pushButton->text() == QString("Submit") ) |
264 |
{ |
265 |
qt_set_abort(0); |
266 |
this->m_ui->pushButton->setText("Abort"); |
267 |
enableInterface(false); |
268 |
this->doSubmit(); |
269 |
} |
270 |
else if( m_ui->pushButton->text() == QString("Abort") ) |
271 |
{ |
272 |
qt_set_abort(1); |
273 |
this->m_ui->pushButton->setText("Submit"); |
274 |
enableInterface(true); |
275 |
} |
276 |
} |
277 |
|
278 |
void MainWindow::resizeImage(int width, int height) |
279 |
{ |
280 |
int pad = m_ui->lineEdit->size().height(); |
281 |
pad += m_ui->menubar->size().height(); |
282 |
pad += m_ui->messageBox->size().height(); |
283 |
this->resize(width+4, height+pad+4); |
284 |
this->m_ui->rvuWidget->resizeImage(width, height); |
285 |
} |
286 |
|
287 |
void MainWindow::setStatus(const char* m) |
288 |
{ |
289 |
m_ui->messageBox->appendPlainText(QString(m).trimmed()); |
290 |
} |
291 |
|
292 |
void MainWindow::redraw() |
293 |
{ |
294 |
runCommand("redraw"); |
295 |
} |
296 |
|
297 |
void MainWindow::traceRay() |
298 |
{ |
299 |
runCommand("t"); |
300 |
} |
301 |
|
302 |
void MainWindow::toggleToolBar() |
303 |
{ |
304 |
m_ui->toolBar->setVisible(m_ui->toggleToolBar->isChecked()); |
305 |
} |
306 |
|
307 |
void MainWindow::toggleStatusBar() |
308 |
{ |
309 |
m_ui->messageBox->setVisible(m_ui->toggleStatusBar->isChecked()); |
310 |
} |
311 |
|
312 |
void MainWindow::toggleTranslateTool() |
313 |
{ |
314 |
m_ui->xWidget->setVisible(m_ui->toggleTranslateTool->isChecked()); |
315 |
m_ui->yWidget->setVisible(m_ui->toggleTranslateTool->isChecked()); |
316 |
m_ui->zWidget->setVisible(m_ui->toggleTranslateTool->isChecked()); |
317 |
} |
318 |
|
319 |
void MainWindow::refreshView(VIEW *nv) |
320 |
{ |
321 |
if (waitrays() < 0) /* clear ray queue */ |
322 |
quit(1); |
323 |
newview(nv); |
324 |
this->redraw(); |
325 |
} |
326 |
|
327 |
void MainWindow::move(int direction, float amount) |
328 |
{ |
329 |
if( m_ui->pushButton->text() == QString("Abort") ) |
330 |
{ |
331 |
qt_set_abort(1); |
332 |
return; |
333 |
} |
334 |
VIEW nv = ourview; |
335 |
nv.vp[direction] = nv.vp[direction] + amount; |
336 |
this->refreshView(&nv); |
337 |
updatePositionLabels(); |
338 |
} |
339 |
|
340 |
void MainWindow::moveXPlusOne() |
341 |
{ |
342 |
this->move(0, this->smallIncrement); |
343 |
} |
344 |
|
345 |
void MainWindow::moveXPlusTwo() |
346 |
{ |
347 |
this->move(0, this->largeIncrement); |
348 |
} |
349 |
|
350 |
void MainWindow::moveXMinusOne() |
351 |
{ |
352 |
this->move(0, -1 * this->smallIncrement); |
353 |
} |
354 |
|
355 |
void MainWindow::moveXMinusTwo() |
356 |
{ |
357 |
this->move(0, -1 * this->largeIncrement); |
358 |
} |
359 |
|
360 |
void MainWindow::moveYPlusOne() |
361 |
{ |
362 |
this->move(1, this->smallIncrement); |
363 |
} |
364 |
|
365 |
void MainWindow::moveYPlusTwo() |
366 |
{ |
367 |
this->move(1, this->largeIncrement); |
368 |
} |
369 |
|
370 |
void MainWindow::moveYMinusOne() |
371 |
{ |
372 |
this->move(1, -1 * this->smallIncrement); |
373 |
} |
374 |
|
375 |
void MainWindow::moveYMinusTwo() |
376 |
{ |
377 |
this->move(1, -1 * this->largeIncrement); |
378 |
} |
379 |
|
380 |
void MainWindow::moveZPlusOne() |
381 |
{ |
382 |
this->move(2, this->smallIncrement); |
383 |
} |
384 |
|
385 |
void MainWindow::moveZPlusTwo() |
386 |
{ |
387 |
this->move(2, this->largeIncrement); |
388 |
} |
389 |
|
390 |
void MainWindow::moveZMinusOne() |
391 |
{ |
392 |
this->move(2, -1 * this->smallIncrement); |
393 |
} |
394 |
|
395 |
void MainWindow::moveZMinusTwo() |
396 |
{ |
397 |
this->move(2, -1 * this->largeIncrement); |
398 |
} |
399 |
|
400 |
void MainWindow::updatePositionLabels() |
401 |
{ |
402 |
m_ui->xValue->setText(QString::number(ourview.vp[0])); |
403 |
m_ui->yValue->setText(QString::number(ourview.vp[1])); |
404 |
m_ui->zValue->setText(QString::number(ourview.vp[2])); |
405 |
} |
406 |
|
407 |
void MainWindow::showExposureDialog() |
408 |
{ |
409 |
m_exposureDialogUi->exposureValue->setText(QString::number(exposure)); |
410 |
m_exposureDialog->show(); |
411 |
} |
412 |
|
413 |
void MainWindow::hideExposureDialog() |
414 |
{ |
415 |
m_exposureDialog->hide(); |
416 |
} |
417 |
|
418 |
void MainWindow::showParameterDialog() |
419 |
{ |
420 |
//ambient tab |
421 |
m_parameterDialogUi->valueX->setText(QString::number(ambval[0])); |
422 |
m_parameterDialogUi->valueY->setText(QString::number(ambval[1])); |
423 |
m_parameterDialogUi->valueZ->setText(QString::number(ambval[2])); |
424 |
m_parameterDialogUi->weight->setText(QString::number(ambvwt)); |
425 |
m_parameterDialogUi->accuracy->setText(QString::number(ambacc)); |
426 |
m_parameterDialogUi->divisions->setText(QString::number(ambdiv)); |
427 |
m_parameterDialogUi->supersamples->setText(QString::number(ambssamp)); |
428 |
m_parameterDialogUi->bounces->setText(QString::number(ambounce)); |
429 |
m_parameterDialogUi->resolution->setText(QString::number(ambres)); |
430 |
|
431 |
//direct tab |
432 |
m_parameterDialogUi->certainty->setText(QString::number(shadcert)); |
433 |
m_parameterDialogUi->threshold->setText(QString::number(shadthresh)); |
434 |
m_parameterDialogUi->visibility->setText(QString::number(directvis)); |
435 |
m_parameterDialogUi->jitter->setText(QString::number(dstrsrc)); |
436 |
m_parameterDialogUi->sampling->setText(QString::number(srcsizerat)); |
437 |
//values on direct tab that I can't find: reflection |
438 |
|
439 |
//limit tab |
440 |
m_parameterDialogUi->limit_weight->setText(QString::number(minweight)); |
441 |
m_parameterDialogUi->reflection->setText(QString::number(maxdepth)); |
442 |
|
443 |
//medium tab |
444 |
m_parameterDialogUi->albedoX->setText(QString::number(salbedo[0])); |
445 |
m_parameterDialogUi->albedoY->setText(QString::number(salbedo[1])); |
446 |
m_parameterDialogUi->albedoZ->setText(QString::number(salbedo[2])); |
447 |
m_parameterDialogUi->extinctionX->setText(QString::number(cextinction[0])); |
448 |
m_parameterDialogUi->extinctionY->setText(QString::number(cextinction[1])); |
449 |
m_parameterDialogUi->extinctionZ->setText(QString::number(cextinction[2])); |
450 |
m_parameterDialogUi->eccentricity->setText(QString::number(seccg)); |
451 |
m_parameterDialogUi->mistDistance->setText(QString::number(ssampdist)); |
452 |
|
453 |
//pixel tab |
454 |
m_parameterDialogUi->sample->setText(QString::number(psample)); |
455 |
m_parameterDialogUi->px_threshold->setText(QString::number(maxdiff)); |
456 |
|
457 |
//specular tab |
458 |
m_parameterDialogUi->sp_jitter->setText(QString::number(specjitter)); |
459 |
m_parameterDialogUi->sp_threshold->setText(QString::number(specthresh)); |
460 |
|
461 |
m_parameterDialog->show(); |
462 |
} |
463 |
|
464 |
void MainWindow::hideParameterDialog() |
465 |
{ |
466 |
m_parameterDialog->hide(); |
467 |
} |
468 |
|
469 |
void MainWindow::adjustExposure() |
470 |
{ |
471 |
bool checkForPoint = false; |
472 |
|
473 |
QString command = "exposure "; |
474 |
|
475 |
if(m_exposureDialogUi->absolute->isChecked()) |
476 |
{ |
477 |
command += "="; |
478 |
} |
479 |
else if(m_exposureDialogUi->fstop->isChecked()) |
480 |
{ |
481 |
//TODO: check if the value is positive or not here |
482 |
command += "+"; |
483 |
} |
484 |
else if(m_exposureDialogUi->natural->isChecked()) |
485 |
{ |
486 |
command += "@"; |
487 |
checkForPoint = true; |
488 |
} |
489 |
else if(m_exposureDialogUi->relative->isChecked()) |
490 |
{ |
491 |
checkForPoint = true; |
492 |
} |
493 |
|
494 |
if(!(checkForPoint && m_exposureDialogUi->point->isChecked())) |
495 |
{ |
496 |
command += m_exposureDialogUi->exposureSetting->text(); |
497 |
} |
498 |
|
499 |
runCommand(command.toAscii()); |
500 |
} |
501 |
|
502 |
void MainWindow::updatePointRadio() |
503 |
{ |
504 |
if(m_exposureDialogUi->relative->isChecked() || |
505 |
m_exposureDialogUi->natural->isChecked()) |
506 |
{ |
507 |
m_exposureDialogUi->point->setEnabled(true); |
508 |
m_exposureDialogUi->average->setEnabled(true); |
509 |
} |
510 |
else |
511 |
{ |
512 |
m_exposureDialogUi->point->setEnabled(false); |
513 |
m_exposureDialogUi->average->setEnabled(false); |
514 |
} |
515 |
} |
516 |
|
517 |
void MainWindow::adjustParameters() |
518 |
{ |
519 |
if(m_parameterDialogUi->valueX->isModified() || |
520 |
m_parameterDialogUi->valueY->isModified() || |
521 |
m_parameterDialogUi->valueZ->isModified()) |
522 |
{ |
523 |
QString command = "set av "; |
524 |
command += m_parameterDialogUi->valueX->text(); |
525 |
command += " "; |
526 |
command += m_parameterDialogUi->valueY->text(); |
527 |
command += " "; |
528 |
command += m_parameterDialogUi->valueZ->text(); |
529 |
runCommand(command.toAscii()); |
530 |
} |
531 |
if(m_parameterDialogUi->weight->isModified()) |
532 |
{ |
533 |
QString command = "set aw "; |
534 |
command += m_parameterDialogUi->weight->text(); |
535 |
runCommand(command.toAscii()); |
536 |
} |
537 |
if(m_parameterDialogUi->accuracy->isModified()) |
538 |
{ |
539 |
QString command = "set aa "; |
540 |
command += m_parameterDialogUi->accuracy->text(); |
541 |
runCommand(command.toAscii()); |
542 |
} |
543 |
if(m_parameterDialogUi->divisions->isModified()) |
544 |
{ |
545 |
QString command = "set ad "; |
546 |
command += m_parameterDialogUi->divisions->text(); |
547 |
runCommand(command.toAscii()); |
548 |
} |
549 |
if(m_parameterDialogUi->supersamples->isModified()) |
550 |
{ |
551 |
QString command = "set as "; |
552 |
command += m_parameterDialogUi->supersamples->text(); |
553 |
runCommand(command.toAscii()); |
554 |
} |
555 |
if(m_parameterDialogUi->bounces->isModified()) |
556 |
{ |
557 |
QString command = "set ab "; |
558 |
command += m_parameterDialogUi->bounces->text(); |
559 |
runCommand(command.toAscii()); |
560 |
} |
561 |
if(m_parameterDialogUi->resolution->isModified()) |
562 |
{ |
563 |
QString command = "set ar "; |
564 |
command += m_parameterDialogUi->resolution->text(); |
565 |
runCommand(command.toAscii()); |
566 |
} |
567 |
if(m_parameterDialogUi->certainty->isModified()) |
568 |
{ |
569 |
QString command = "set dc "; |
570 |
command += m_parameterDialogUi->certainty->text(); |
571 |
runCommand(command.toAscii()); |
572 |
} |
573 |
if(m_parameterDialogUi->threshold->isModified()) |
574 |
{ |
575 |
QString command = "set dt "; |
576 |
command += m_parameterDialogUi->threshold->text(); |
577 |
runCommand(command.toAscii()); |
578 |
} |
579 |
if(m_parameterDialogUi->visibility->isModified()) |
580 |
{ |
581 |
QString command = "set dv "; |
582 |
command += m_parameterDialogUi->visibility->text(); |
583 |
runCommand(command.toAscii()); |
584 |
} |
585 |
if(m_parameterDialogUi->jitter->isModified()) |
586 |
{ |
587 |
QString command = "set dj "; |
588 |
command += m_parameterDialogUi->jitter->text(); |
589 |
runCommand(command.toAscii()); |
590 |
} |
591 |
if(m_parameterDialogUi->sampling->isModified()) |
592 |
{ |
593 |
QString command = "set ds "; |
594 |
command += m_parameterDialogUi->sampling->text(); |
595 |
runCommand(command.toAscii()); |
596 |
} |
597 |
if(m_parameterDialogUi->limit_weight->isModified()) |
598 |
{ |
599 |
QString command = "set lw "; |
600 |
command += m_parameterDialogUi->limit_weight->text(); |
601 |
runCommand(command.toAscii()); |
602 |
} |
603 |
if(m_parameterDialogUi->reflection->isModified()) |
604 |
{ |
605 |
QString command = "set lr "; |
606 |
command += m_parameterDialogUi->reflection->text(); |
607 |
runCommand(command.toAscii()); |
608 |
} |
609 |
if(m_parameterDialogUi->albedoX->isModified() || |
610 |
m_parameterDialogUi->albedoY->isModified() || |
611 |
m_parameterDialogUi->albedoZ->isModified()) |
612 |
{ |
613 |
QString command = "set ma "; |
614 |
command += m_parameterDialogUi->albedoX->text(); |
615 |
command += " "; |
616 |
command += m_parameterDialogUi->albedoY->text(); |
617 |
command += " "; |
618 |
command += m_parameterDialogUi->albedoZ->text(); |
619 |
runCommand(command.toAscii()); |
620 |
} |
621 |
if(m_parameterDialogUi->extinctionX->isModified() || |
622 |
m_parameterDialogUi->extinctionY->isModified() || |
623 |
m_parameterDialogUi->extinctionZ->isModified()) |
624 |
{ |
625 |
QString command = "set me "; |
626 |
command += m_parameterDialogUi->extinctionX->text(); |
627 |
command += " "; |
628 |
command += m_parameterDialogUi->extinctionY->text(); |
629 |
command += " "; |
630 |
command += m_parameterDialogUi->extinctionZ->text(); |
631 |
} |
632 |
if(m_parameterDialogUi->eccentricity->isModified()) |
633 |
{ |
634 |
QString command = "set mg "; |
635 |
command += m_parameterDialogUi->eccentricity->text(); |
636 |
runCommand(command.toAscii()); |
637 |
} |
638 |
if(m_parameterDialogUi->mistDistance->isModified()) |
639 |
{ |
640 |
QString command = "set ms "; |
641 |
command += m_parameterDialogUi->mistDistance->text(); |
642 |
runCommand(command.toAscii()); |
643 |
} |
644 |
if(m_parameterDialogUi->sample->isModified()) |
645 |
{ |
646 |
QString command = "set ps "; |
647 |
command += m_parameterDialogUi->sample->text(); |
648 |
runCommand(command.toAscii()); |
649 |
} |
650 |
if(m_parameterDialogUi->px_threshold->isModified()) |
651 |
{ |
652 |
QString command = "set pt "; |
653 |
command += m_parameterDialogUi->px_threshold->text(); |
654 |
runCommand(command.toAscii()); |
655 |
} |
656 |
if(m_parameterDialogUi->sp_jitter->isModified()) |
657 |
{ |
658 |
QString command = "set ss "; |
659 |
command += m_parameterDialogUi->sp_jitter->text(); |
660 |
runCommand(command.toAscii()); |
661 |
} |
662 |
if(m_parameterDialogUi->sp_threshold->isModified()) |
663 |
{ |
664 |
QString command = "set st "; |
665 |
command += m_parameterDialogUi->sp_threshold->text(); |
666 |
runCommand(command.toAscii()); |
667 |
} |
668 |
m_parameterDialog->hide(); |
669 |
} |
670 |
|
671 |
void MainWindow::showViewDialog() |
672 |
{ |
673 |
if(ourview.type==VT_PER) |
674 |
{ |
675 |
m_viewDialogUi->perspective->setChecked(true); |
676 |
} |
677 |
else if(ourview.type==VT_PAR) |
678 |
{ |
679 |
m_viewDialogUi->parallel->setChecked(true); |
680 |
} |
681 |
else if(ourview.type==VT_HEM) |
682 |
{ |
683 |
m_viewDialogUi->hemispherical->setChecked(true); |
684 |
} |
685 |
else if(ourview.type==VT_ANG) |
686 |
{ |
687 |
m_viewDialogUi->angular->setChecked(true); |
688 |
} |
689 |
else if(ourview.type==VT_CYL) |
690 |
{ |
691 |
m_viewDialogUi->cylindrical->setChecked(true); |
692 |
} |
693 |
|
694 |
m_viewDialogUi->viewX->setText(QString::number(ourview.vp[0])); |
695 |
m_viewDialogUi->viewY->setText(QString::number(ourview.vp[1])); |
696 |
m_viewDialogUi->viewZ->setText(QString::number(ourview.vp[2])); |
697 |
|
698 |
m_viewDialogUi->dirX->setText(QString::number(ourview.vdir[0], 'f', 4)); |
699 |
m_viewDialogUi->dirY->setText(QString::number(ourview.vdir[1], 'f', 4)); |
700 |
m_viewDialogUi->dirZ->setText(QString::number(ourview.vdir[2], 'f', 4)); |
701 |
|
702 |
m_viewDialogUi->upX->setText(QString::number(ourview.vup[0])); |
703 |
m_viewDialogUi->upY->setText(QString::number(ourview.vup[1])); |
704 |
m_viewDialogUi->upZ->setText(QString::number(ourview.vup[2])); |
705 |
|
706 |
m_viewDialogUi->sizeHoriz->setText(QString::number(ourview.horiz)); |
707 |
m_viewDialogUi->sizeVert->setText(QString::number(ourview.vert)); |
708 |
m_viewDialogUi->fore->setText(QString::number(ourview.vfore)); |
709 |
m_viewDialogUi->aft->setText(QString::number(ourview.vaft)); |
710 |
m_viewDialogUi->offsetHoriz->setText(QString::number(ourview.hoff)); |
711 |
m_viewDialogUi->offsetVert->setText(QString::number(ourview.voff)); |
712 |
|
713 |
m_viewDialog->show(); |
714 |
} |
715 |
|
716 |
void MainWindow::hideViewDialog() |
717 |
{ |
718 |
m_viewDialog->hide(); |
719 |
} |
720 |
|
721 |
void MainWindow::adjustView() |
722 |
{ |
723 |
bool changed = false; |
724 |
VIEW nv = ourview; |
725 |
|
726 |
//type |
727 |
if(m_viewDialogUi->perspective->isChecked() && nv.type != VT_PER) |
728 |
{ |
729 |
nv.type = VT_PER; |
730 |
changed = true; |
731 |
} |
732 |
if(m_viewDialogUi->parallel->isChecked() && nv.type != VT_PAR) |
733 |
{ |
734 |
nv.type = VT_PAR; |
735 |
changed = true; |
736 |
} |
737 |
if(m_viewDialogUi->hemispherical->isChecked() && nv.type != VT_HEM) |
738 |
{ |
739 |
nv.type = VT_HEM; |
740 |
changed = true; |
741 |
} |
742 |
if(m_viewDialogUi->angular->isChecked() && nv.type != VT_ANG) |
743 |
{ |
744 |
nv.type = VT_ANG; |
745 |
changed = true; |
746 |
} |
747 |
if(m_viewDialogUi->cylindrical->isChecked() && nv.type != VT_CYL) |
748 |
{ |
749 |
nv.type = VT_CYL; |
750 |
changed = true; |
751 |
} |
752 |
|
753 |
//viewpoint |
754 |
if(m_viewDialogUi->viewX->isModified()) |
755 |
{ |
756 |
bool okay = true; |
757 |
float f = m_viewDialogUi->viewX->text().toFloat(&okay); |
758 |
if(okay) |
759 |
{ |
760 |
nv.vp[0] = f; |
761 |
changed = true; |
762 |
} |
763 |
} |
764 |
if(m_viewDialogUi->viewY->isModified()) |
765 |
{ |
766 |
bool okay = true; |
767 |
float f = m_viewDialogUi->viewY->text().toFloat(&okay); |
768 |
if(okay) |
769 |
{ |
770 |
nv.vp[1] = f; |
771 |
changed = true; |
772 |
} |
773 |
} |
774 |
if(m_viewDialogUi->viewZ->isModified()) |
775 |
{ |
776 |
bool okay = true; |
777 |
float f = m_viewDialogUi->viewZ->text().toFloat(&okay); |
778 |
if(okay) |
779 |
{ |
780 |
nv.vp[2] = f; |
781 |
changed = true; |
782 |
} |
783 |
} |
784 |
|
785 |
//direction |
786 |
if(m_viewDialogUi->dirX->isModified()) |
787 |
{ |
788 |
bool okay = true; |
789 |
float f = m_viewDialogUi->dirX->text().toFloat(&okay); |
790 |
if(okay) |
791 |
{ |
792 |
nv.vdir[0] = f; |
793 |
changed = true; |
794 |
} |
795 |
} |
796 |
if(m_viewDialogUi->dirY->isModified()) |
797 |
{ |
798 |
bool okay = true; |
799 |
float f = m_viewDialogUi->dirY->text().toFloat(&okay); |
800 |
if(okay) |
801 |
{ |
802 |
nv.vdir[1] = f; |
803 |
changed = true; |
804 |
} |
805 |
} |
806 |
if(m_viewDialogUi->dirZ->isModified()) |
807 |
{ |
808 |
bool okay = true; |
809 |
float f = m_viewDialogUi->dirZ->text().toFloat(&okay); |
810 |
if(okay) |
811 |
{ |
812 |
nv.vdir[2] = f; |
813 |
changed = true; |
814 |
} |
815 |
} |
816 |
|
817 |
//up |
818 |
if(m_viewDialogUi->upX->isModified()) |
819 |
{ |
820 |
bool okay = true; |
821 |
float f = m_viewDialogUi->upX->text().toFloat(&okay); |
822 |
if(okay) |
823 |
{ |
824 |
nv.vup[0] = f; |
825 |
changed = true; |
826 |
} |
827 |
} |
828 |
if(m_viewDialogUi->upY->isModified()) |
829 |
{ |
830 |
bool okay = true; |
831 |
float f = m_viewDialogUi->upY->text().toFloat(&okay); |
832 |
if(okay) |
833 |
{ |
834 |
nv.vup[1] = f; |
835 |
changed = true; |
836 |
} |
837 |
} |
838 |
if(m_viewDialogUi->upZ->isModified()) |
839 |
{ |
840 |
bool okay = true; |
841 |
float f = m_viewDialogUi->upZ->text().toFloat(&okay); |
842 |
if(okay) |
843 |
{ |
844 |
nv.vup[2] = f; |
845 |
changed = true; |
846 |
} |
847 |
} |
848 |
|
849 |
//size |
850 |
if(m_viewDialogUi->sizeHoriz->isModified()) |
851 |
{ |
852 |
bool okay = true; |
853 |
double d = m_viewDialogUi->sizeHoriz->text().toDouble(&okay); |
854 |
if(okay) |
855 |
{ |
856 |
nv.horiz = d; |
857 |
changed = true; |
858 |
} |
859 |
} |
860 |
if(m_viewDialogUi->sizeVert->isModified()) |
861 |
{ |
862 |
bool okay = true; |
863 |
double d = m_viewDialogUi->sizeVert->text().toDouble(&okay); |
864 |
if(okay) |
865 |
{ |
866 |
nv.vert = d; |
867 |
changed = true; |
868 |
} |
869 |
} |
870 |
|
871 |
//clipping plane |
872 |
if(m_viewDialogUi->fore->isModified()) |
873 |
{ |
874 |
bool okay = true; |
875 |
double d = m_viewDialogUi->fore->text().toDouble(&okay); |
876 |
if(okay) |
877 |
{ |
878 |
nv.vfore = d; |
879 |
changed = true; |
880 |
} |
881 |
} |
882 |
if(m_viewDialogUi->aft->isModified()) |
883 |
{ |
884 |
bool okay = true; |
885 |
double d = m_viewDialogUi->aft->text().toDouble(&okay); |
886 |
if(okay) |
887 |
{ |
888 |
nv.vaft = d; |
889 |
changed = true; |
890 |
} |
891 |
} |
892 |
|
893 |
//clipping plane |
894 |
if(m_viewDialogUi->offsetHoriz->isModified()) |
895 |
{ |
896 |
bool okay = true; |
897 |
double d = m_viewDialogUi->offsetHoriz->text().toDouble(&okay); |
898 |
if(okay) |
899 |
{ |
900 |
nv.hoff = d; |
901 |
changed = true; |
902 |
} |
903 |
} |
904 |
if(m_viewDialogUi->offsetVert->isModified()) |
905 |
{ |
906 |
bool okay = true; |
907 |
double d = m_viewDialogUi->offsetVert->text().toDouble(&okay); |
908 |
if(okay) |
909 |
{ |
910 |
nv.voff = d; |
911 |
changed = true; |
912 |
} |
913 |
} |
914 |
|
915 |
if(changed) |
916 |
{ |
917 |
this->refreshView(&nv); |
918 |
} |
919 |
} |
920 |
|
921 |
void MainWindow::enableInterface(bool enable) |
922 |
{ |
923 |
m_ui->toolBar->setEnabled(enable); |
924 |
m_ui->progressBar->setEnabled(!enable); |
925 |
} |
926 |
|
927 |
void MainWindow::runCommand(const char *command) |
928 |
{ |
929 |
qt_set_abort(0); |
930 |
this->m_ui->pushButton->setText("Abort"); |
931 |
enableInterface(false); |
932 |
qt_process_command(command); |
933 |
qt_set_abort(1); |
934 |
this->m_ui->pushButton->setText("Submit"); |
935 |
enableInterface(true); |
936 |
} |
937 |
|
938 |
void MainWindow::pick(int* x, int* y) |
939 |
{ |
940 |
QCursor oldCursor = this->cursor(); |
941 |
this->setCursor(Qt::CrossCursor); |
942 |
this->getRvuWidget()->getPosition(x, y); |
943 |
// restore state |
944 |
this->setCursor(oldCursor); |
945 |
} |
946 |
|
947 |
void MainWindow::saveImage() |
948 |
{ |
949 |
this->currentImageName = QFileDialog::getSaveFileName(this, tr("Save File"), |
950 |
"", tr(".hdr images (*.hdr)")); |
951 |
QString command = "write " + this->currentImageName; |
952 |
this->runCommand(command.toAscii()); |
953 |
} |
954 |
|
955 |
void MainWindow::saveCurrentImage() |
956 |
{ |
957 |
if(this->currentImageName == "") |
958 |
{ |
959 |
this->saveImage(); |
960 |
return; |
961 |
} |
962 |
QString command = "write " + this->currentImageName; |
963 |
this->runCommand(command.toAscii()); |
964 |
} |
965 |
|
966 |
void MainWindow::loadView() |
967 |
{ |
968 |
QString viewFileName = QFileDialog::getOpenFileName(this, tr("Open View File"), |
969 |
"", tr("View Files (*.vp *.vf)")); |
970 |
QString command = "last " + viewFileName; |
971 |
this->runCommand(command.toAscii()); |
972 |
} |
973 |
|
974 |
void MainWindow::toggleGrayscale() |
975 |
{ |
976 |
QString command = "set b "; |
977 |
if(m_ui->grayscale->isChecked()) |
978 |
{ |
979 |
command += " 1"; |
980 |
} |
981 |
else |
982 |
{ |
983 |
command += " 0"; |
984 |
} |
985 |
this->runCommand(command.toAscii()); |
986 |
this->runCommand("new"); |
987 |
} |
988 |
|
989 |
void MainWindow::toggleBackfaceVisibility() |
990 |
{ |
991 |
QString command = "set bv"; |
992 |
if(m_ui->backfaceVisibility->isChecked()) |
993 |
{ |
994 |
command += " 1"; |
995 |
} |
996 |
else |
997 |
{ |
998 |
command += " 0"; |
999 |
} |
1000 |
this->runCommand(command.toAscii()); |
1001 |
this->runCommand("new"); |
1002 |
} |
1003 |
|
1004 |
void MainWindow::toggleIrradiance() |
1005 |
{ |
1006 |
QString command = "set i"; |
1007 |
if(m_ui->irradiance->isChecked()) |
1008 |
{ |
1009 |
command += " 1"; |
1010 |
} |
1011 |
else |
1012 |
{ |
1013 |
command += " 0"; |
1014 |
} |
1015 |
this->runCommand(command.toAscii()); |
1016 |
this->runCommand("new"); |
1017 |
} |
1018 |
|
1019 |
void MainWindow::loadRif() |
1020 |
{ |
1021 |
bool ok; |
1022 |
QString viewName = QInputDialog::getText(this, tr("Input view name"), |
1023 |
tr("Name of view:"), QLineEdit::Normal, |
1024 |
"", &ok); |
1025 |
if (ok && !viewName.isEmpty()) |
1026 |
{ |
1027 |
QString radFileName = QFileDialog::getOpenFileName(this, tr("Open rad File"), |
1028 |
"", tr("rad files (*.rif)")); |
1029 |
QString command = "L " + viewName + " " + radFileName; |
1030 |
this->runCommand(command.toAscii()); |
1031 |
} |
1032 |
} |
1033 |
|
1034 |
void MainWindow::appendToRif() |
1035 |
{ |
1036 |
bool ok; |
1037 |
QString viewName = QInputDialog::getText(this, tr("Input view name"), |
1038 |
tr("Name of view:"), QLineEdit::Normal, |
1039 |
"", &ok); |
1040 |
if (ok && !viewName.isEmpty()) |
1041 |
{ |
1042 |
QString radFileName = QFileDialog::getSaveFileName(this, tr("Save File"), |
1043 |
"", tr("rad files (*.rif)"), 0, QFileDialog::DontConfirmOverwrite); |
1044 |
QString command = "V " + viewName + " " + radFileName; |
1045 |
this->runCommand(command.toAscii()); |
1046 |
} |
1047 |
} |
1048 |
|
1049 |
void MainWindow::appendToView() |
1050 |
{ |
1051 |
QString viewFileName = QFileDialog::getSaveFileName(this, tr("Save File"), |
1052 |
"", tr("view files (*.vp *.vf)"), 0, QFileDialog::DontConfirmOverwrite); |
1053 |
if(viewFileName != "") |
1054 |
{ |
1055 |
QString command = "view " + viewFileName; |
1056 |
this->runCommand(command.toAscii()); |
1057 |
} |
1058 |
} |
1059 |
|
1060 |
void MainWindow::showIncrementsDialog() |
1061 |
{ |
1062 |
m_incrementsDialogUi->small->setText(QString::number(this->smallIncrement)); |
1063 |
m_incrementsDialogUi->large->setText(QString::number(this->largeIncrement)); |
1064 |
m_incrementsDialog->show(); |
1065 |
} |
1066 |
|
1067 |
void MainWindow::hideIncrementsDialog() |
1068 |
{ |
1069 |
m_incrementsDialog->hide(); |
1070 |
} |
1071 |
|
1072 |
void MainWindow::adjustIncrements() |
1073 |
{ |
1074 |
bool okay = true; |
1075 |
float f = m_incrementsDialogUi->small->text().toFloat(&okay); |
1076 |
if(okay) |
1077 |
{ |
1078 |
this->smallIncrement = f; |
1079 |
} |
1080 |
f = m_incrementsDialogUi->large->text().toFloat(&okay); |
1081 |
if(okay) |
1082 |
{ |
1083 |
this->largeIncrement = f; |
1084 |
} |
1085 |
} |
1086 |
|
1087 |
void MainWindow::showCommandsDialog() |
1088 |
{ |
1089 |
m_commandsDialog->show(); |
1090 |
} |
1091 |
|
1092 |
void MainWindow::showAbout() |
1093 |
{ |
1094 |
QString aboutText = |
1095 |
"rvu was written mainly by Greg Ward.\nThe Qt-based GUI was developed by Kitware, Inc. in 2011"; |
1096 |
QMessageBox::about(this, "About rvu", aboutText); |
1097 |
} |