1 /** @file SnarkDisplay.cpp
2 @package snark14Display
3 @author Bruno M. Carvalho and Deniz Sarioz
4 licensed under (open-source) QPL v1.0
5 which accompanies this distribution in the file QPL
7 modification: Joanna Klukowska 1/13/2009
8 added choice of grayScale display for plot
9 in addition to color display
14 #include "SnarkDisplay.hpp"
15 #include "displaylines.hpp"
16 #include "displayprojection.hpp"
17 #include "eval_helper.hpp"
19 #include "line_real_t.hpp"
21 #include "linesimages.hpp"
23 #include "displaywindow.hpp"
24 #include "selectEvalExecutions.hpp"
25 #include "variables.hpp"
27 #include "openimages.hpp"
38 #include <qapplication.h>
40 #include <qfiledialog.h>
42 #include <qpushbutton.h>
48 #include <qwhatsthis.h>
49 #include <qmessagebox.h>
52 const char *myTag = "sd140707";
55 * Constructs a SnarkDisplay which is a child of 'parent', with the
56 * name 'name' and widget flags set to 'fl'
58 SnarkDisplay::SnarkDisplay(QWidget* parent, const char* name, WFlags fl)
59 : QWidget(parent, name, fl) {
60 std::cout << "Executing snark14Display - " << myTag << std::endl;
62 desk = QApplication::desktop();
63 maxSizex = desk->size().width();
64 maxSizey = desk->size().height();
66 setName("snark14Display");
68 setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, sizePolicy().hasHeightForWidth()));
69 setMinimumSize(QSize(250, 400));
70 setMaximumSize(QSize(250, 400));
71 setCaption(tr("snark14Display"));
73 recfilbutton = new QPushButton(this, "recfilbutton");
74 recfilbutton->setGeometry(QRect(40, 25, 170, 40));
75 recfilbutton->setText(tr("Open Recfil File"));
76 QObject::connect(recfilbutton, SIGNAL(clicked()), this, SLOT(openRecfilFile()));
78 imagesbutton = new QPushButton(this, "imagesbutton");
79 imagesbutton->setGeometry(QRect(40, 75, 170, 40));
80 imagesbutton->setText(tr("Open Images"));
81 QObject::connect(imagesbutton, SIGNAL(clicked()), this, SLOT(callOpenImages()));
83 rangebutton = new QPushButton(this, "rangebutton");
84 rangebutton->setGeometry(QRect(40, 125, 170, 40));
85 rangebutton->setText(tr("Set Global Features"));
86 QObject::connect(rangebutton, SIGNAL(clicked()), this, SLOT(callRange()));
88 linesbutton = new QPushButton(this, "linesbutton");
89 linesbutton->setGeometry(QRect(40, 175, 170, 40));
90 linesbutton->setText(tr("Display Lines"));
91 QObject::connect(linesbutton, SIGNAL(clicked()), this, SLOT(callLines()));
93 projfilbutton = new QPushButton(this, "projfilbutton");
94 projfilbutton->setGeometry(QRect(40, 225, 170, 40));
95 projfilbutton->setText(tr("Open Prjfil File"));
96 QObject::connect(projfilbutton, SIGNAL(clicked()), this, SLOT(openPrjfilFile()));
98 evalbutton = new QPushButton(this, "evalbutton");
99 evalbutton->setGeometry(QRect(40, 275, 170, 40));
100 evalbutton->setText(tr("Open Eval File"));
101 QObject::connect(evalbutton, SIGNAL(clicked()), this, SLOT(openEvalFile()));
103 Line1 = new QFrame(this, "Line1");
104 Line1->setGeometry(QRect(0, 325, 260, 16));
105 Line1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
107 quitbutton = new QPushButton(this, "quitbutton");
108 quitbutton->setGeometry(QRect(10, 350, 100, 40));
109 quitbutton->setText(tr("Quit"));
110 QObject::connect(quitbutton, SIGNAL(clicked()), qApp, SLOT(quit()));
112 helpbutton = new QPushButton(this, "helpbutton");
113 helpbutton->setGeometry(QRect(140, 350, 100, 40));
114 helpbutton->setText(tr("About"));
115 QObject::connect(helpbutton, SIGNAL(clicked()), this, SLOT(about()));
117 allocSnarkimages(numimages);
118 // allocDisplaywindows(numimages);
119 displaywindowset = 0;
120 displaywindowactive = 0;
122 myOpenImagesWinP = 0;
123 } // --SnarkDisplay ctor
125 /** Destroys the object and frees any allocated resources
127 SnarkDisplay::~SnarkDisplay() {
128 // no need to delete child widgets, Qt does it all for us
131 /** Calls file dialog and opens recfil file
133 @author Bruno M. Carvalho
135 void SnarkDisplay::openRecfilFile() {
136 unsigned int asn, an;
137 int i, j, ni, widthproj, widthexec;
138 char name[256], oldname[256], nameexecution[13], namephantom[41];
139 char namealg[5], nameprojection[13];
141 const DIGDimensions* Dimensions;
142 QString itname, recfilfilename, s;
143 QFileDialog fd(QString::null, "Recfil files (*recfil*)\n All files (*)", this, "Open Recfil File", true);
144 fd.setCaption("Open Recfil File");
145 fd.setSelection(QDir::currentDirPath());
146 if (fd.exec() == QDialog::Accepted)
147 recfilfilename = fd.selectedFile();
153 for (i = 0; i < numimages; i++) {
154 if (imageindexes[i]) {
155 free(imageindexes[i]);
161 myRangeWinP->closeWindow();
164 if (myOpenImagesWinP) {
165 delete myOpenImagesWinP;
166 myOpenImagesWinP = 0;
169 freeSnarkimages(numimages);
170 freeDisplaywindows(numimages);
172 if (!recfilfilename.isEmpty()) {
173 snprintf(name, sizeof(name)-1, "%s", recfilfilename.latin1());
174 if (digrecfil.Open(name) != 0) {
175 s.sprintf("Error!\nUnable to open file:\n%s\n", recfilfilename.latin1());
176 QMessageBox::information(this, "SnarkDisplay", s);
180 snprintf(oldname, sizeof(oldname)-1, "%s", name);
181 phantomexists = false;
182 if (digrecfil.GetDimensions(&Dimensions) != 0) {
183 s.sprintf("%s is not a snark14 recfil\n", recfilfilename.latin1());
184 QMessageBox::information(this, "SnarkDisplay", s);
187 if ((Dimensions->x != 1) && (Dimensions->y != 1) && (Dimensions->z != 1)) {
188 s.sprintf("%s is not a snark14 recfil\n", recfilfilename.latin1());
189 QMessageBox::information(this, "SnarkDisplay", s);
192 if (Dimensions->z == 1) {
193 Sizex = Dimensions->x;
194 Sizey = Dimensions->y;
196 if (Dimensions->y == 1) {
197 Sizex = Dimensions->x;
198 Sizey = Dimensions->z;
200 Sizex = Dimensions->y;
201 Sizey = Dimensions->z;
204 digrecfil.GetDataFormat(&dataformat);
205 nameproj = (const char *) malloc(sizeof (const char) *81);
206 digrecfil.GetTitle(&nameproj);
207 strncpy(nameprojection, nameproj, 12);
208 nameprojection[12] = 0;
210 for (j = 11; j >= 0; j--) {
211 if (nameprojection[j] == ' ' || nameprojection[j] == 0 || nameprojection[j] == 10) {
212 nameprojection[j] = 0;
217 digrecfil.GetNoOfArraySets(&asn);
218 settitles = (const char **) malloc(sizeof (const char *) * asn);
220 for (i = 0; i < (static_cast<int> (asn)); i++) {
221 digrecfil.SelectArraySet(i);
222 digrecfil.GetArraySetTitle(&settitles[i]);
223 digrecfil.GetNoOfArrays(&an);
226 imagetitles = (char **) malloc(sizeof (char *) * numimages);
227 for (i = 0; i < numimages; i++) {
228 imagetitles[i] = (char *) malloc(sizeof (char) *41);
230 imageindexes = (unsigned int **) malloc(sizeof (unsigned int *) * numimages);
231 for (i = 0; i < numimages; i++) {
232 imageindexes[i] = (unsigned int *) malloc(sizeof (unsigned int *) *2);
235 for (i = 0; i < (static_cast<int> (asn)); i++) {
237 digrecfil.SelectArraySet(i);
238 digrecfil.GetNoOfArrays(&an);
239 digrecfil.GetArraySetType(&na);
240 strncpy(namealg, na, 4);
242 for (j = 0; j < 4; j++)
243 namealg[j] = toupper(namealg[j]);
244 if (!strcmp(namealg, "PHAN")) {
245 phantomexists = true;
246 strncpy(namephantom, settitles[i], 40);
248 if (!strcmp(namephantom, ""))
251 itname.sprintf("%-40s", namephantom);
252 snprintf(imagetitles[ni], sizeof(imagetitles[ni])-1, "%s", itname.latin1());
253 imageindexes[ni][0] = i;
254 imageindexes[ni][1] = 0;
257 strncpy(nameexecution, settitles[i], 12);
258 nameexecution[12] = 0;
260 for (j = 11; j >= 0; j--) {
261 if (nameexecution[j] == ' ' || nameexecution[j] == 0) {
262 nameexecution[j] = 0;
267 for (j = 0; j < (static_cast<int> (an)); j++) {
268 if (strcmp(nameprojection, ""))
269 itname.sprintf("%-*s_%-*s_%s_%04d_r_a", widthproj, nameprojection, widthexec, nameexecution, namealg, j + 1);
271 itname.sprintf("__%-*s_%4s_%04d_r_a", widthexec, nameexecution, namealg, j + 1);
272 snprintf(imagetitles[ni], sizeof(imagetitles[ni])-1, "%s", itname.latin1());
273 imageindexes[ni][0] = i;
274 imageindexes[ni][1] = j;
279 allocSnarkimages(numimages);
280 allocDisplaywindows(numimages);
282 if (myOpenImagesWinP) {
283 myOpenImagesWinP->setImagesNames();
289 } //--SnarkDisplay::openRecfilFile()
291 /** Starts a window for selecting images to be shown
293 @author Bruno M. Carvalho
295 void SnarkDisplay::callOpenImages() {
297 topleft = this->pos();
299 QMessageBox::information(this, "SnarkDisplay", "Error!\n"
300 "No recfil file is open.");
302 // noiw=new openimageswindow(desk,"Open Images",false,0,topleft.x()+30,topleft.y()+30);
303 if (!myOpenImagesWinP) {
304 myOpenImagesWinP = new openimageswindow(displaywindowset, desk, "Open Images", false, 0, topleft.x() + 30, topleft.y() + 30);
305 // myOpenImagesWinP = new openimageswindow(displaywindowset,this,"Open Images",false,0,topleft.x()+30,topleft.y()+30);
307 myOpenImagesWinP->hide(); // hack to give focus, setFocus() didn't work
308 myOpenImagesWinP->show();
310 } // --SnarkDisplay::callOpenImages()
312 /** Starts a lines window
314 @author Bruno M. Carvalho, deniz
316 @comments majorly shortened due to new (Deniz'04) classes
318 void SnarkDisplay::callLines() {
319 if (std::verbose >= 2) {
320 std::cout << "++SnarkDisplay::callLines()" << std::endl;
323 int linetype, c, i, j, k, minx, maxx;
325 int topleftx, toplefty;
328 QString title, xaxis, yaxis, temp;
332 QMessageBox::information(this, "SnarkDisplay", "Error!\n"
333 "No recfil file is open.");
335 if (!imageset[0]->isLoaded())
336 imageset[0]->readImage(0, dataformat);
337 linesimageswindow* nw = new linesimageswindow(this, "Multiple Images' Lines", true);
339 if (c == QDialog::Accepted) {
340 linetype = nw->getLinetype(); // row or column. 0 for row, 1 for column.
341 l[0] = nw->getLine1();
342 l[1] = nw->getLine2();
343 l[2] = nw->getLine3();
344 l[3] = nw->getLine4();
345 title = ((nw->getTitle()).simplifyWhiteSpace());
346 xaxis = nw->getXAxis();
347 yaxis = nw->getYAxis();
348 minx = nw->getMinX();
349 maxx = nw->getMaxX();
350 miny = nw->getMinY();
351 maxy = nw->getMaxY();
352 topleft = this->pos();
353 topleftx = topleft.x();
354 toplefty = topleft.y();
355 siarray = nw->getSelectedImages();
356 // (linetype==0) ==> show for suchandsuch row(s) all column values based on xrange
357 // (linetype==1) ==> show for suchandsuch col(s) all row values based on xrange
358 QString rowOrColumn = ((linetype) ? ("Column ") : ("Row "));
359 QString vs = ((linetype) ? ("Rows") : ("Columns"));
360 for (k = 1; k <= siarray[0]; k++) {
361 if (!imageset[siarray[k]]->isLoaded())
362 imageset[siarray[k]]->readImage(k, DIGDataFormat_ASCII);
364 // j is index for user-selected (keyed in) rows or columns
365 for (j = 0; j < 4; j++) {
366 // l[j] is the user-selected (keyed in) row or column "at position j"
367 if (l[j] >= 0 && l[j] < Sizex) { // plot only if within range.
368 line_real_set_t myLRS(minx, maxx, miny, maxy); // create a brand new LRS for brand new plot
369 myLRS.clear(); // and be sure of it!
370 QString whichRowOrCol;
371 whichRowOrCol.setNum(l[j]);
372 QString plotName = title.simplifyWhiteSpace();
373 // plotName += " ::multiple images':: ";
375 plotName += (rowOrColumn + whichRowOrCol);
379 QPixmap* pmp = new QPixmap(sd_line_t::WIDTH, sd_line_t::HEIGHT);
380 pmp->fill(Qt::white);
382 picasso.setBackgroundColor(Qt::white);
383 for (k = 1; k <= siarray[0]; k++) { // k is array index for the image within recfil
384 QString LRName = imagetitles[siarray[k]]; // something like "brainscan_ART_iter_5"
385 line_real_t myLR(LRName);
386 if (!(imageset[siarray[k]]->isLoaded())) {
387 imageset[siarray[k]]->readImage(k, DIGDataFormat_ASCII);
389 img = imageset[siarray[k]]->getImage();
390 int& row = ((linetype) ? (i) : (l[j])); // not assignment, but rather, unification.
391 int& col = ((linetype) ? (l[j]) : (i)); // (linetype==1) means l[j] is col, else l[j] is row
392 for (i = 0; i < Sizey; i++) { // recfils are Sizey by Sizey
393 myLR.add(i, img[row][col]); // x is independent i, y is dependent img[row][col]
395 myLRS.add(myLR); // add my LineReal due to selected row/col in this (k) image to my LRS
396 } // --for each image k (plot all of them on the same thing.)
397 plot_t myPlot(myLRS); // plot myLRS due to single selection of row/col (up to 4)
398 myPlot.setName(plotName);
399 myPlot.setXAxisName(xaxis);
400 myPlot.setYAxisName(yaxis);
401 // jk 1/13/2009 adding grayScale option for graphs
402 if (nw->isGrayScaleChecked()) { // picasso paints on QPixmap pointed to by pmp
403 myPlot.plotGray(picasso);
405 myPlot.plot(picasso);
408 if (toplefty > (maxSizey - 100))
410 // spawn a display for each row/col plot, each plot potentially due to many images
411 displaylineswindow* nieuwDLWp = new displaylineswindow(desk, plotName, pmp, false, 0, topleftx, toplefty);
413 } // --if of chosen row or column being within the appropriate range (i think)
414 } // --for each chosen row or column (max. 4 of them)
415 } // --"if" of Accepted QDialog
416 } // --"else" of "no recfil is open"
417 } // --SnarkDisplay::callLines()
419 /** Starts a range window
421 @author Bruno M. Carvalho
423 void SnarkDisplay::callRange() {
424 bool imageopened = false;
427 QMessageBox::information(desk, "SnarkDisplay", "Error!\n"
428 "No recfil file is open.");
430 for (i = 0; i < numimages; i++) {
431 if (displaywindowactive[i]) {
436 // rangewindow* nw=new rangewindow(this,"Set Range",false,Qt::WType_TopLevel);
438 myRangeWinP->closeWindow();
441 myRangeWinP = new rangewindow(this, "Set Range", false, Qt::WType_TopLevel);
444 QMessageBox::information(desk, "SnarkDisplay", "Error!\n"
445 "No image is open.");
447 } // --SnarkDisplay::callRange()
449 /** Calls file dialog and opens PROJECTION file
451 @author Bruno M. Carvalho
453 void SnarkDisplay::openPrjfilFile() {
454 QString projfilfilename, s;
456 // const DIGDimensions* Dimensions;
459 QFileDialog fd(QString::null, "Projfil files (*prjfil*)\n All files (*)", this, "Open Prjfil File", TRUE);
460 fd.setCaption("Open Projfil File");
461 fd.setSelection(QDir::currentDirPath());
462 if (fd.exec() == QDialog::Accepted) {
463 projfilfilename = fd.selectedFile();
464 snprintf(name, sizeof(name)-1, "%s", projfilfilename.latin1());
465 if (openprojfil) //*(JD 1/28/04)
466 digprojfil.Close(); //(JD 1/28/04)
467 if (digprojfil.Open(name) != 0) {
468 s.sprintf("Error!\nUnable to open file:\n%s\nMaybe it is not a snark14 prjfil file!", projfilfilename.latin1());
469 QMessageBox::information(this, "SnarkDisplay", s);
471 // digprojfil.GetDataFormat(&projformat);
472 projname = (const char *) malloc(sizeof (const char) *81);
473 digprojfil.GetTitle(&projname);
474 // digprojfil.GetNoOfArraySets(&prjnum);
475 digprojfil.GetNoOfProjs(&prjnum);
476 // digprojfil.GetDimensions(&Dimensions);
477 // usrays = Dimensions->x;
478 digprojfil.GetDimensions(&usrays);
479 projfil = new Snarkproj();
480 // open prjfil in displaywindow
481 topleft = this->pos();
482 projwin = new displayprojection(desk, projname, false, 0, topleft.x(), topleft.y());
484 projwin->resetscroll();
486 digprojfil.Open(name);
487 openprojfil = true; //*(JD 1/28/04)
491 /** Calls file dialog and opens eval file, throwing all information into global myEES
493 @author Bruno M. Carvalho for version 1.0, Deniz Sarioz after
495 void SnarkDisplay::openEvalFile() {
496 // myEES stands for "my eval_execution_set" defined in variables.h
497 // eval_execution_set is defined in eval_helper.hpp and fleshed out in eval_helper.cpp
498 myEES.clear(); // just in case
499 // opening new eval file: get rid of ALL previous eval-related information
500 QString evalfilename, s;
502 const unsigned maxlinelength = 512;
503 const unsigned maxnamelength = 512;
504 char line[maxlinelength]; // buffer for reading in lines
505 char name[maxnamelength]; // buffer for reading in name
506 memset(&(line[0]), 0, maxlinelength); // init line with null terminator
507 memset(&(name[0]), 0, maxnamelength); // init name with null terminator
508 int tmpint; // complete dummy
509 QFileDialog fd(QString::null, "Eval files (*eval*)\n All files (*)", this, "Open Eval File", TRUE);
510 fd.setCaption("Open Eval File");
511 fd.setSelection(QDir::currentDirPath());
512 if (fd.exec() == QDialog::Accepted) {
513 evalfilename = fd.selectedFile();
514 snprintf(name, sizeof(name)-1, "%s", evalfilename.latin1());
515 if (std::verbose >= 2) printf("\nname of eval file is:\n%s\n", name);
516 if ((fp = fopen(name, "r")) == NULL) {
517 s.sprintf("Error!\nUnable to open file:\n%s\n", evalfilename.latin1());
518 QMessageBox::information(this, "SnarkDisplay", s);
522 JUSTBEGAN, NEWEVALUATE, GLOBAL, POINT
524 status_t status = JUSTBEGAN;
526 /* if end in JUSTBEGAN or NEWEVALUATE, raise red flag
527 * graph of possible status transitions
532 * JUSTBEGAN ---------> NEWEVALUATE ---> POINT
536 * GLOBAL-------------/
538 enum global_status_t {
539 GLOBEGAN, TOREADPHAN, TOREADGLOB
541 // this is assigned based on the string parsed
542 global_status_t globalstatus = GLOBEGAN;
543 bool ADD_POINTMEAS = false;
544 typedef char* inputline_t;
546 measline_t mymeasline;
547 execname_t myexecname;
548 bool ignoredonce = false;
549 myline = (&(line[0])); // myline permanently points to line[0]
550 mymeasline = (&(line[0]));
551 myexecname = (&(line[0]));
552 while (fgets(line, maxlinelength, fp)) {
553 //// if(isspace(mymeasline)) continue;
556 while ((' ' == *p) || ('\t' == *p)) p++;
557 if (('\n' == *p) || ('\r' == *p) || ('\0' == *p)) continue;
560 // first line does not have to start with evaluation name: allow comments
561 if (strstr(myline, "evaluation name:")) {
562 status = NEWEVALUATE;
564 myEES.new_exec(myexecname); // READ IN evaluation name!
565 } catch (std::exception &e) {
566 std::cerr << "This badness happened:" << std::endl << e.what() << std::endl;
570 std::cout << "stuff in eval file before first 'evaluation name:' ignored!!!" << std::endl;
574 break; // the switch, not the while
576 if (strstr(myline, "global resolution measures")) {
579 if (strstr(myline, "point by point resolution measures")) {
583 break; // out of switch
585 if (strstr(myline, "evaluation name:")) { // can happen at any time
586 globalstatus = GLOBEGAN;
587 status = NEWEVALUATE;
589 myEES.new_exec(myexecname); // READ IN evaluation name!
590 } catch (std::exception &e) {
591 std::cerr << "This badness happened:" << std::endl << e.what() << std::endl;
594 switch (globalstatus) {
596 if (strstr(myline, "hantom name")) {
597 // read the name of phantom! (necessary?)
598 } else if (strstr(myline, "etrics for test phantom")) {
599 globalstatus = TOREADPHAN;
601 break; // out of inner switch
602 case TOREADPHAN: // read exactly one line of phantom data
603 if (sscanf(myline, "%d", &tmpint) == 1) { // if line starts with an integer
605 myEES.set_phantomeas(mymeasline);
606 } catch (std::exception &e) {
607 std::cerr << "This badness happened:" << std::endl << e.what() << std::endl;
609 globalstatus = TOREADGLOB; // next, should try to read an execution
611 break; // out of inner switch
613 if (sscanf(myline, "%d", &tmpint) == 1) {
615 myEES.add_to_globmeaset(mymeasline);
616 } catch (std::exception &e) {
617 std::cerr << "This badness happened:" << std::endl << e.what() << std::endl;
619 } else if (strstr(myline, "execution name")) {
620 // parse in execution name (necessary?)
622 myEES.new_globmeaset(myexecname);
623 } catch (std::exception &e) {
624 std::cerr << "This badness happened:" << std::endl << e.what() << std::endl;
626 } else if (strstr(myline, "etrics for algorithm")) {
627 // parse in ALGO name! (maybe?)
628 } else if (strstr(myline, "point by point resolution measures")) {
629 globalstatus = GLOBEGAN;
632 break; // out of inner switch (optional here, defensive)
635 break; // out of switch
637 if (strstr(myline, "evaluation name")) {
638 // parse evaluation name!
639 ADD_POINTMEAS = false;
640 status = NEWEVALUATE;
642 myEES.new_exec(myexecname); // READ IN evaluation name!
643 } catch (std::exception &e) {
644 std::cerr << "This badness happened:" << std::endl << e.what() << std::endl;
646 } else if (strstr(myline, "execution name")) {
647 ADD_POINTMEAS = false;
649 myEES.new_PBPmeaset(myexecname); // name gets assigned as we go along, but still parse in name
650 } catch (std::exception &e) {
651 std::cerr << "This badness happened:" << std::endl << e.what() << std::endl;
653 } else if (strstr(myline, "algn")) { // need a line with this
654 ADD_POINTMEAS = true;
655 } else if (ADD_POINTMEAS) {
656 // NOW we can go ahead with this, since whitespace-lines are skipped
658 myEES.add_to_PBPmeaset(mymeasline);
659 } catch (std::exception &e) {
660 std::cerr << "This badness happened:" << std::endl << e.what() << std::endl;
663 break; // out of switch (optional here, defensive)
665 memset(myline, 0, maxlinelength); // reinit line to null terminator
666 } // while can keep reading lines
667 if ((status == JUSTBEGAN) || (status == NEWEVALUATE)) {
668 //maybe throw std::runtime_error("malformed eval file: no measurements");
669 std::cerr << "malformed eval file: no measurements... please open a valid eval file." << std::endl;
675 } catch (std::exception &e) {
676 std::cerr << "This badness happened:" << std::endl << e.what() << std::endl;
681 // new version: first, user should select executions!
683 topleft = this->pos();
684 selectEvalExecutionsWindow* selectEvalExecsWin;
685 selectEvalExecsWin = new selectEvalExecutionsWindow(desk, "Open Evaluate Executions", false, 0, topleft.x() + 30, topleft.y() + 30);
686 selectEvalExecsWin->show();
687 } // --if was able to open the file ("else" of failure, failure already handled)
688 } // --if QDialog accepted
690 } // --SnarkDisplay::openEvalFile()
692 /** Updates low and high thresholds for image windows having the button Global Thresholds checked
694 @author Bruno M. Carvalho
696 void SnarkDisplay::updateGlobalThreshs() {
697 // the new way: do it for all of them!
698 for (int i = 0; i < numimages; i++)
699 if (imageset[i]->isLoaded() && displaywindowset[i]) {
700 displaywindowset[i]->setGlobalthreshs();
704 /** tells all windows to be activated by the global thresholds
706 @author Bruno M. Carvalho
708 void SnarkDisplay::signalAllGlobals(bool on) {
711 myRangeWinP->signalAllGlobals(allglobal);
713 for (int i = 0; i < numimages; i++) {
714 if (alldifference && (i == 0)) continue;
715 if (imageset[i]->isLoaded() && displaywindowset[i]) {
716 displaywindowset[i]->setGlobal(on);
719 updateGlobalThreshs(); // refresh immediately
722 void SnarkDisplay::signalAllDifference(bool on) {
725 myRangeWinP->signalAllDifference(alldifference);
728 if (imageset[0]->isLoaded() && displaywindowset[0]) {
730 displaywindowset[0]->setGlobal(false);
732 displaywindowset[0]->setGlobal(true);
736 for (int i = 1; i < numimages; i++) {
737 if (imageset[i]->isLoaded() && displaywindowset[i]) {
738 displaywindowset[i]->setDifference(on);
743 void SnarkDisplay::signalAllIntensity(bool on) {
744 for (int i = 0; i < numimages; i++) {
745 if (displaywindowset[i]) {
746 displaywindowset[i]->setIntensity(on);
751 /** Calls about window
753 @author Bruno M. Carvalho & Deniz Sarioz
755 void SnarkDisplay::about() {
756 QMessageBox::information(this, "snark14Display",
757 "snark14Display was developed by\n"
758 "Bruno M. Carvalho and Deniz Sarioz\n"
760 "copyright (QPL) by CUNY-GC-CS-DIG\n"
761 "http://www.dig.cs.gc.cuny.edu");
764 /** Allocates space for a vector of Snarkimages
765 @param ni number of images
766 @author Bruno M. Carvalho
768 void SnarkDisplay::allocSnarkimages(int ni) {
770 imageset = (Snarkimage **) malloc((unsigned) (ni) * sizeof (Snarkimage*));
772 QMessageBox::information(this, "SnarkDisplay", "Error!\n"
773 "Allocation failure in allocSnarkimages()\n");
775 for (i = 0; i < ni; i++) {
776 imageset[i] = new Snarkimage();
778 QMessageBox::information(this, "SnarkDisplay", "Error!\n"
779 "Allocation failure in allocSnarkimages()\n");
785 /** Allocates space for a vector of displaywindow POINTERS
786 @param ni number of images
787 @author Bruno M. Carvalho
789 void SnarkDisplay::allocDisplaywindows(int ni) {
791 alldifference = false;
792 globalmax = globaldiffmax = -100000;
793 globalmin = globaldiffmin = 100000;
794 // forget everything we did before!
796 // displaywindowset = (displaywindow **) malloc((unsigned) (ni)*sizeof(displaywindow*));
797 displaywindowset = new displaywindow* [ni];
798 if (!displaywindowset) {
799 QMessageBox::information(this, "SnarkDisplay", "Error!\n"
800 "Allocation failure in allocDisplaywindows()\n");
802 displaywindowactive = (bool *) malloc((unsigned) (ni) * sizeof (bool));
803 for (int i = 0; i < ni; i++) {
804 displaywindowactive[i] = false;
805 displaywindowset[i] = 0; // NULL
809 /** Frees space of a vector of Snarkimages
810 @param ni number of images
811 @author Bruno M. Carvalho
813 void SnarkDisplay::freeSnarkimages(int ni) {
817 for (i = 0; i < ni; i++) {
819 imageset[i]->~Snarkimage();
825 } // --SnarkDisplay::freeSnarkimages()
827 /** Frees space of a vector of Displaywindows
829 @author Bruno M. Carvalho
831 void SnarkDisplay::freeDisplaywindows(int ni) {
833 if (displaywindowset) {
834 for (i = 0; i < ni; i++) {
835 if (displaywindowset[i]) {
836 delete displaywindowset[i];
839 delete [] displaywindowset;
841 } // --SnarkDisplay::freeDisplaywindows()
843 /** Starts the application
845 @author Bruno M. Carvalho, parametrized by deniz
847 int main(int argc, char* argv[]) {
848 QApplication snarkapp(argc, argv);
851 int wid = atoi(argv[1]);
852 int hei = atoi(argv[2]);
853 int minwid = 3 * sd_line_t::XWINPAD;
854 int minhei = 3 * sd_line_t::YWINPAD;
855 if ((wid >= minwid) && (hei >= minhei)) {
856 std::cout << "For plots, accepted window WIDTH=" << wid << ", HEIGHT=" << hei << std::endl;
857 sd_line_t::WIDTH = wid;
858 sd_line_t::HEIGHT = hei;
860 std::cout << "Minimum width: " << minwid << ", minimum height: " << minhei << std::endl;
861 std::cout << "Aborting " << argv[0] << std::endl;
865 // SnarkDisplay* mw=new SnarkDisplay();
867 // snarkapp.setMainWidget(mw);
868 snarkapp.setMainWidget(&mw);
872 return snarkapp.exec();