ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/qtrvu/mainwindow.cxx
Revision: 1.1
Committed: Sat Oct 22 22:38:10 2011 UTC (12 years, 6 months ago) by greg
Branch: MAIN
CVS Tags: rad4R1
Log Message:
Added qt interface for rvu and cmake files from Bill Hoffman

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