ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/qtrvu/mainwindow.cxx
Revision: 1.3
Committed: Mon Aug 6 17:51:45 2012 UTC (10 years, 10 months ago) by greg
Branch: MAIN
CVS Tags: rad4R2P2, rad4R2P1, rad4R2
Changes since 1.2: +9 -0 lines
Log Message:
Zack's patch to add stereographic view type

File Contents

# Content
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_PLS)
690 {
691 m_viewDialogUi->planispheric->setChecked(true);
692 }
693 else if(ourview.type==VT_CYL)
694 {
695 m_viewDialogUi->cylindrical->setChecked(true);
696 }
697
698 m_viewDialogUi->viewX->setText(QString::number(ourview.vp[0]));
699 m_viewDialogUi->viewY->setText(QString::number(ourview.vp[1]));
700 m_viewDialogUi->viewZ->setText(QString::number(ourview.vp[2]));
701
702 m_viewDialogUi->dirX->setText(QString::number(ourview.vdir[0], 'f', 4));
703 m_viewDialogUi->dirY->setText(QString::number(ourview.vdir[1], 'f', 4));
704 m_viewDialogUi->dirZ->setText(QString::number(ourview.vdir[2], 'f', 4));
705
706 m_viewDialogUi->upX->setText(QString::number(ourview.vup[0]));
707 m_viewDialogUi->upY->setText(QString::number(ourview.vup[1]));
708 m_viewDialogUi->upZ->setText(QString::number(ourview.vup[2]));
709
710 m_viewDialogUi->sizeHoriz->setText(QString::number(ourview.horiz));
711 m_viewDialogUi->sizeVert->setText(QString::number(ourview.vert));
712 m_viewDialogUi->fore->setText(QString::number(ourview.vfore));
713 m_viewDialogUi->aft->setText(QString::number(ourview.vaft));
714 m_viewDialogUi->offsetHoriz->setText(QString::number(ourview.hoff));
715 m_viewDialogUi->offsetVert->setText(QString::number(ourview.voff));
716
717 m_viewDialog->show();
718 }
719
720 void MainWindow::hideViewDialog()
721 {
722 m_viewDialog->hide();
723 }
724
725 void MainWindow::adjustView()
726 {
727 bool changed = false;
728 VIEW nv = ourview;
729
730 //type
731 if(m_viewDialogUi->perspective->isChecked() && nv.type != VT_PER)
732 {
733 nv.type = VT_PER;
734 changed = true;
735 }
736 if(m_viewDialogUi->parallel->isChecked() && nv.type != VT_PAR)
737 {
738 nv.type = VT_PAR;
739 changed = true;
740 }
741 if(m_viewDialogUi->hemispherical->isChecked() && nv.type != VT_HEM)
742 {
743 nv.type = VT_HEM;
744 changed = true;
745 }
746 if(m_viewDialogUi->angular->isChecked() && nv.type != VT_ANG)
747 {
748 nv.type = VT_ANG;
749 changed = true;
750 }
751 if(m_viewDialogUi->planispheric->isChecked() && nv.type != VT_PLS)
752 {
753 nv.type = VT_PLS;
754 changed = true;
755 }
756 if(m_viewDialogUi->cylindrical->isChecked() && nv.type != VT_CYL)
757 {
758 nv.type = VT_CYL;
759 changed = true;
760 }
761
762 //viewpoint
763 if(m_viewDialogUi->viewX->isModified())
764 {
765 bool okay = true;
766 float f = m_viewDialogUi->viewX->text().toFloat(&okay);
767 if(okay)
768 {
769 nv.vp[0] = f;
770 changed = true;
771 }
772 }
773 if(m_viewDialogUi->viewY->isModified())
774 {
775 bool okay = true;
776 float f = m_viewDialogUi->viewY->text().toFloat(&okay);
777 if(okay)
778 {
779 nv.vp[1] = f;
780 changed = true;
781 }
782 }
783 if(m_viewDialogUi->viewZ->isModified())
784 {
785 bool okay = true;
786 float f = m_viewDialogUi->viewZ->text().toFloat(&okay);
787 if(okay)
788 {
789 nv.vp[2] = f;
790 changed = true;
791 }
792 }
793
794 //direction
795 if(m_viewDialogUi->dirX->isModified())
796 {
797 bool okay = true;
798 float f = m_viewDialogUi->dirX->text().toFloat(&okay);
799 if(okay)
800 {
801 nv.vdir[0] = f;
802 changed = true;
803 }
804 }
805 if(m_viewDialogUi->dirY->isModified())
806 {
807 bool okay = true;
808 float f = m_viewDialogUi->dirY->text().toFloat(&okay);
809 if(okay)
810 {
811 nv.vdir[1] = f;
812 changed = true;
813 }
814 }
815 if(m_viewDialogUi->dirZ->isModified())
816 {
817 bool okay = true;
818 float f = m_viewDialogUi->dirZ->text().toFloat(&okay);
819 if(okay)
820 {
821 nv.vdir[2] = f;
822 changed = true;
823 }
824 }
825
826 //up
827 if(m_viewDialogUi->upX->isModified())
828 {
829 bool okay = true;
830 float f = m_viewDialogUi->upX->text().toFloat(&okay);
831 if(okay)
832 {
833 nv.vup[0] = f;
834 changed = true;
835 }
836 }
837 if(m_viewDialogUi->upY->isModified())
838 {
839 bool okay = true;
840 float f = m_viewDialogUi->upY->text().toFloat(&okay);
841 if(okay)
842 {
843 nv.vup[1] = f;
844 changed = true;
845 }
846 }
847 if(m_viewDialogUi->upZ->isModified())
848 {
849 bool okay = true;
850 float f = m_viewDialogUi->upZ->text().toFloat(&okay);
851 if(okay)
852 {
853 nv.vup[2] = f;
854 changed = true;
855 }
856 }
857
858 //size
859 if(m_viewDialogUi->sizeHoriz->isModified())
860 {
861 bool okay = true;
862 double d = m_viewDialogUi->sizeHoriz->text().toDouble(&okay);
863 if(okay)
864 {
865 nv.horiz = d;
866 changed = true;
867 }
868 }
869 if(m_viewDialogUi->sizeVert->isModified())
870 {
871 bool okay = true;
872 double d = m_viewDialogUi->sizeVert->text().toDouble(&okay);
873 if(okay)
874 {
875 nv.vert = d;
876 changed = true;
877 }
878 }
879
880 //clipping plane
881 if(m_viewDialogUi->fore->isModified())
882 {
883 bool okay = true;
884 double d = m_viewDialogUi->fore->text().toDouble(&okay);
885 if(okay)
886 {
887 nv.vfore = d;
888 changed = true;
889 }
890 }
891 if(m_viewDialogUi->aft->isModified())
892 {
893 bool okay = true;
894 double d = m_viewDialogUi->aft->text().toDouble(&okay);
895 if(okay)
896 {
897 nv.vaft = d;
898 changed = true;
899 }
900 }
901
902 //clipping plane
903 if(m_viewDialogUi->offsetHoriz->isModified())
904 {
905 bool okay = true;
906 double d = m_viewDialogUi->offsetHoriz->text().toDouble(&okay);
907 if(okay)
908 {
909 nv.hoff = d;
910 changed = true;
911 }
912 }
913 if(m_viewDialogUi->offsetVert->isModified())
914 {
915 bool okay = true;
916 double d = m_viewDialogUi->offsetVert->text().toDouble(&okay);
917 if(okay)
918 {
919 nv.voff = d;
920 changed = true;
921 }
922 }
923
924 if(changed)
925 {
926 this->refreshView(&nv);
927 }
928 }
929
930 void MainWindow::enableInterface(bool enable)
931 {
932 m_ui->toolBar->setEnabled(enable);
933 m_ui->progressBar->setEnabled(!enable);
934 }
935
936 void MainWindow::runCommand(const char *command)
937 {
938 qt_set_abort(0);
939 this->m_ui->pushButton->setText("Abort");
940 enableInterface(false);
941 qt_process_command(command);
942 qt_set_abort(1);
943 this->m_ui->pushButton->setText("Submit");
944 enableInterface(true);
945 }
946
947 void MainWindow::pick(int* x, int* y)
948 {
949 QCursor oldCursor = this->cursor();
950 this->setCursor(Qt::CrossCursor);
951 this->getRvuWidget()->getPosition(x, y);
952 // restore state
953 this->setCursor(oldCursor);
954 }
955
956 void MainWindow::saveImage()
957 {
958 this->currentImageName = QFileDialog::getSaveFileName(this, tr("Save File"),
959 "", tr(".hdr images (*.hdr)"));
960 QString command = "write " + this->currentImageName;
961 this->runCommand(command.toAscii());
962 }
963
964 void MainWindow::saveCurrentImage()
965 {
966 if(this->currentImageName == "")
967 {
968 this->saveImage();
969 return;
970 }
971 QString command = "write " + this->currentImageName;
972 this->runCommand(command.toAscii());
973 }
974
975 void MainWindow::loadView()
976 {
977 QString viewFileName = QFileDialog::getOpenFileName(this, tr("Open View File"),
978 "", tr("View Files (*.vp *.vf)"));
979 QString command = "last " + viewFileName;
980 this->runCommand(command.toAscii());
981 }
982
983 void MainWindow::toggleGrayscale()
984 {
985 QString command = "set b ";
986 if(m_ui->grayscale->isChecked())
987 {
988 command += " 1";
989 }
990 else
991 {
992 command += " 0";
993 }
994 this->runCommand(command.toAscii());
995 this->runCommand("new");
996 }
997
998 void MainWindow::toggleBackfaceVisibility()
999 {
1000 QString command = "set bv";
1001 if(m_ui->backfaceVisibility->isChecked())
1002 {
1003 command += " 1";
1004 }
1005 else
1006 {
1007 command += " 0";
1008 }
1009 this->runCommand(command.toAscii());
1010 this->runCommand("new");
1011 }
1012
1013 void MainWindow::toggleIrradiance()
1014 {
1015 QString command = "set i";
1016 if(m_ui->irradiance->isChecked())
1017 {
1018 command += " 1";
1019 }
1020 else
1021 {
1022 command += " 0";
1023 }
1024 this->runCommand(command.toAscii());
1025 this->runCommand("new");
1026 }
1027
1028 void MainWindow::loadRif()
1029 {
1030 bool ok;
1031 QString viewName = QInputDialog::getText(this, tr("Input view name"),
1032 tr("Name of view:"), QLineEdit::Normal,
1033 "", &ok);
1034 if (ok && !viewName.isEmpty())
1035 {
1036 QString radFileName = QFileDialog::getOpenFileName(this, tr("Open rad File"),
1037 "", tr("rad files (*.rif)"));
1038 QString command = "L " + viewName + " " + radFileName;
1039 this->runCommand(command.toAscii());
1040 }
1041 }
1042
1043 void MainWindow::appendToRif()
1044 {
1045 bool ok;
1046 QString viewName = QInputDialog::getText(this, tr("Input view name"),
1047 tr("Name of view:"), QLineEdit::Normal,
1048 "", &ok);
1049 if (ok && !viewName.isEmpty())
1050 {
1051 QString radFileName = QFileDialog::getSaveFileName(this, tr("Save File"),
1052 "", tr("rad files (*.rif)"), 0, QFileDialog::DontConfirmOverwrite);
1053 QString command = "V " + viewName + " " + radFileName;
1054 this->runCommand(command.toAscii());
1055 }
1056 }
1057
1058 void MainWindow::appendToView()
1059 {
1060 QString viewFileName = QFileDialog::getSaveFileName(this, tr("Save File"),
1061 "", tr("view files (*.vp *.vf)"), 0, QFileDialog::DontConfirmOverwrite);
1062 if(viewFileName != "")
1063 {
1064 QString command = "view " + viewFileName;
1065 this->runCommand(command.toAscii());
1066 }
1067 }
1068
1069 void MainWindow::showIncrementsDialog()
1070 {
1071 m_incrementsDialogUi->small->setText(QString::number(this->smallIncrement));
1072 m_incrementsDialogUi->large->setText(QString::number(this->largeIncrement));
1073 m_incrementsDialog->show();
1074 }
1075
1076 void MainWindow::hideIncrementsDialog()
1077 {
1078 m_incrementsDialog->hide();
1079 }
1080
1081 void MainWindow::adjustIncrements()
1082 {
1083 bool okay = true;
1084 float f = m_incrementsDialogUi->small->text().toFloat(&okay);
1085 if(okay)
1086 {
1087 this->smallIncrement = f;
1088 }
1089 f = m_incrementsDialogUi->large->text().toFloat(&okay);
1090 if(okay)
1091 {
1092 this->largeIncrement = f;
1093 }
1094 }
1095
1096 void MainWindow::showCommandsDialog()
1097 {
1098 m_commandsDialog->show();
1099 }
1100
1101 void MainWindow::showAbout()
1102 {
1103 QString aboutText =
1104 "rvu was written mainly by Greg Ward.\nThe Qt-based GUI was developed by Kitware, Inc. in 2011";
1105 QMessageBox::about(this, "About rvu", aboutText);
1106 }