00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011 #include <stdio.h>
00012 #include <QMessageBox>
00013 #include <QFileDialog>
00014 #include <QFileInfo>
00015 #include <QWhatsThis>
00016 #include <QSize>
00017 #include "mainwindow.h"
00018 #include "controldialog.h"
00019 #include "rangecontrol.h"
00020 #include "debug.h"
00021 #include "outlog.h"
00022
00023 using namespace std;
00024
00025
00026
00027 const double WhiteRiggingRadius = 0.99;
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 mainWindow::mainWindow(QWidget *parent) : QMainWindow(parent)
00046 {
00047
00048
00049
00050 map = NULL;
00051 texture = new SkyTexture;
00052 rigging = new Rigging;
00053 whiterig = new Rigging;
00054 polarsphere = new PolarArgLineSet;
00055
00056
00057
00058 setupUi(this);
00059
00060 viewer = new SkyViewer(centralwidget, this);
00061 viewer->setObjectName(QString::fromUtf8("viewer"));
00062 viewer->setGeometry(QRect(1, 0, 600, 591));
00063 viewer->setTexture(texture);
00064 viewer->setRigging(rigging);
00065 viewer->setWhiteRigging(whiterig);
00066 viewer->setPolarAngles(polarsphere);
00067 viewer->setFPSIsDisplayed(false);
00068
00069 setWindowTitle(tr("Skyviewer"));
00070
00071 filelabel = new QLabel("");
00072 filelabel->setMargin(2);
00073 filelabel->setMinimumWidth(150);
00074 filelabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
00075 viewerStatus->addWidget(filelabel);
00076
00077 projlabel = new QLabel("Projection: 3D Sphere");
00078 projlabel->setMargin(2);
00079 projlabel->setMinimumWidth(150);
00080 projlabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
00081 viewerStatus->addWidget(projlabel);
00082
00083 maplabel = new QLabel("Map: Temperature");
00084 maplabel->setMargin(2);
00085 maplabel->setMinimumWidth(150);
00086 maplabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
00087 viewerStatus->addWidget(maplabel);
00088
00089 if (! showpolar)
00090 {
00091 actionPolarAnglesM->setDisabled(true);
00092 actionPolarAnglesM->setVisible(false);
00093 actionPolarAnglesTB->setDisabled(true);
00094 actionPolarAnglesTB->setVisible(false);
00095 }
00096
00097
00098
00099
00100 ctl = new ControlDialog(this);
00101 rngctl = ctl->getRangeControl();
00102
00103
00104
00105 connect(actionOpen, SIGNAL(activated()), this, SLOT(fileLoad()));
00106 connect(actionReload, SIGNAL(activated()), this, SLOT(fileReload()));
00107 connect(actionNew, SIGNAL(activated()), this, SLOT(fileNew()));
00108 connect(actionSnapshot, SIGNAL(activated()), this, SLOT(fileSnapshot()));
00109 connect(actionClose, SIGNAL(activated()), this, SLOT(fileClose()));
00110 connect(actionExit, SIGNAL(activated()), this, SLOT(fileExit()));
00111
00112 connect(action3D_Sphere_tb, SIGNAL(activated()), this, SLOT(proj3Dsphere()));
00113 connect(action3D_Sphere_m, SIGNAL(activated()), this, SLOT(proj3Dsphere()));
00114 connect(actionMollweide_tb, SIGNAL(activated()), this, SLOT(projMollweide()));
00115 connect(actionMollweide_m, SIGNAL(activated()), this, SLOT(projMollweide()));
00116
00117 connect(actionTemperature, SIGNAL(activated()), this, SLOT(mapTemperature()));
00118 connect(actionQ_Polarization, SIGNAL(activated()), this, SLOT(mapQPolarization()));
00119 connect(actionU_Polarization, SIGNAL(activated()), this, SLOT(mapUPolarization()));
00120 connect(actionP_Polarization, SIGNAL(activated()), this, SLOT(mapPPolarization()));
00121 connect(actionNum_Obs, SIGNAL(activated()), this, SLOT(mapNumObs()));
00122
00123 connect(actionPolarAnglesTB, SIGNAL(activated()), this, SLOT(mapPolVectTB()));
00124 connect(actionPolarAnglesM, SIGNAL(activated()), this, SLOT(mapPolVectM()));
00125
00126
00127 connect(actionHelp, SIGNAL(activated()), viewer, SLOT(help()));
00128
00129
00130 connect(rngctl, SIGNAL(reTextureNeeded()), this, SLOT(reTexture()));
00131 connect(rngctl, SIGNAL(changeProjRigging()), this, SLOT(newRigging()));
00132 connect(rngctl, SIGNAL(changeFieldInfo()), this, SLOT(newField()));
00133 connect(rngctl, SIGNAL(changePolVect()), this, SLOT(newPolVect()));
00134
00135 connect(ctl, SIGNAL(resetPixels(std::vector<int>)), this, SLOT(unselectPixels(std::vector<int>)));
00136 connect(ctl, SIGNAL(recenterOnPixel(int)), this, SLOT(recenterOnPixel(int)));
00137
00138
00139
00140 QSize sz;
00141 sz = viewer->size();
00142 delta = size() - sz;
00143 viewmoll = false;
00144 action3D_Sphere_tb->setChecked(! viewmoll);
00145 action3D_Sphere_m->setChecked(! viewmoll);
00146 actionMollweide_tb->setChecked(viewmoll);
00147 actionMollweide_m->setChecked(viewmoll);
00148
00149 rigging->generate (rngctl->getRigging(), viewmoll);
00150 whiterig->generate(rngctl->getRigging(), viewmoll, WhiteRiggingRadius);
00151 ctl->clearStatus();
00152 ctl->show();
00153
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163 mainWindow::~mainWindow(void)
00164 {
00165 if (map != NULL) delete map;
00166 map = NULL;
00167 if (texture != NULL) delete texture;
00168 texture = NULL;
00169 if (rigging != NULL) delete rigging;
00170 rigging = NULL;
00171 if (whiterig != NULL) delete whiterig;
00172 whiterig = NULL;
00173 if (polarsphere != NULL) delete polarsphere;
00174 polarsphere = NULL;
00175 }
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 void mainWindow::resizeEvent(QResizeEvent *event)
00189 {
00190
00191
00192
00193 viewer->resize(event->size() - delta);
00194
00195
00196
00197 QMainWindow::resizeEvent(event);
00198 }
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 void mainWindow::readFile (const char *file)
00213 {
00214 if (file == NULL) return;
00215 QString tmp = file;
00216 readFile(tmp);
00217 }
00218 void mainWindow::readFile (const QString file)
00219 {
00220 QString tmp;
00221 QFileInfo fi;
00222 if (file.length() <= 0) return;
00223 filename = file;
00224 fi.setFile(filename);
00225 tmp = fi.completeSuffix();
00226 tmp = (tmp.length() > 0) ? (fi.baseName() + tr(".") + tmp) : fi.baseName();
00227 filelabel->setText(tmp);
00228 ctl->startFile(tmp);
00229 readFile();
00230
00231 }
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 void mainWindow::readFile ()
00245 {
00246 if (filename.length() <= 0) return;
00247
00248
00249
00250 if (map == NULL) map = new HealpixMap();
00251 if (map == NULL)
00252 {
00253 QMessageBox::critical(this, tr("Skyviewer"),
00254 tr("Unable to allocate memory for the map!"),
00255 QMessageBox::Ok);
00256 return;
00257 }
00258
00259
00260
00261 try {
00262 map->readFITS(filename, ctl);
00263 }
00264 catch (MapException &exc)
00265 {
00266 QString msg(tr("Unable to read map: "));
00267 QMessageBox::critical(this, tr("Skyviewer Load Error"),
00268 (msg + filename + "\nError: " + exc.Message()),
00269 QMessageBox::Ok);
00270 return;
00271 }
00272 ctl->init(map);
00273 setFieldEnables();
00274
00275
00276
00277
00278 if (showtex)
00279 {
00280 try {
00281 texture->set(map, rngctl);
00282 viewer->update();
00283 }
00284 catch (MapException &exc)
00285 {
00286 QString msg(tr("Unable to read map: "));
00287 QMessageBox::critical(this, tr("Skyviewer"),
00288 (exc.Comment() == NULL) ? (msg + filename) : tr(exc.Comment()),
00289 QMessageBox::Ok);
00290 return;
00291 }
00292 }
00293 if (showpolar && map->has_Polarization())
00294 {
00295 if (polarsphere != NULL) polarsphere->set(map);
00296 }
00297
00298
00299
00300
00301 }
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 void mainWindow::undefined()
00315 {
00316 QMessageBox::warning(this, tr("Skyviewer"),
00317 tr("This feature has not yet been defined!"),
00318 QMessageBox::Ok);
00319 }
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 void mainWindow::fileNew()
00334 {
00335 undefined();
00336 }
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 void mainWindow::fileLoad()
00350 {
00351 QString dir(".");
00352 if (filename.length() > 0)
00353 {
00354 QFileInfo fi(filename);
00355 dir = fi.absolutePath();
00356 }
00357 QString fil = QFileDialog::getOpenFileName(this, tr("Open FITS File"),
00358 dir, tr("FITS (*.fits);;Any(*)"));
00359 if (fil.length() <= 0) return;
00360 readFile(fil);
00361 }
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374 void mainWindow::fileReload()
00375 {
00376 readFile();
00377 }
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390 void mainWindow::fileSnapshot()
00391 {
00392
00393 viewer->saveSnapshot(false);
00394 }
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 void mainWindow::fileClose()
00409 {
00410 close();
00411 }
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424 void mainWindow::fileExit()
00425 {
00426 QApplication::exit(0);
00427 }
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 void mainWindow::proj3Dsphere()
00444 {
00445 if( rngctl->getProjection() == Spherical ) {
00446 action3D_Sphere_tb->setChecked(true);
00447 action3D_Sphere_m->setChecked(true);
00448 return;
00449 }
00450 rngctl->setProjection(Spherical);
00451 }
00452 void mainWindow::projMollweide()
00453 {
00454 if( rngctl->getProjection() == Mollweide ) {
00455 actionMollweide_tb->setChecked(true);
00456 actionMollweide_m->setChecked(true);
00457 return;
00458 }
00459 rngctl->setProjection(Mollweide);
00460 }
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473 void mainWindow::newRigging(void)
00474 {
00475 try {
00476 viewmoll = rngctl->getProjection() == Mollweide;
00477 viewer->constrainMollweide(viewmoll);
00478 rigging->generate (rngctl->getRigging(), viewmoll);
00479 whiterig->generate(rngctl->getRigging(), viewmoll, WhiteRiggingRadius);
00480 polarsphere->setMollweide(viewmoll);
00481 viewer->update();
00482 }
00483 catch (MapException &exc)
00484 {
00485 const char *comm = exc.Comment();
00486 QMessageBox::critical(this, tr("Skyviewer"),
00487 tr((comm != NULL) ? comm : "newRigging error!"),
00488 QMessageBox::Ok);
00489 }
00490
00491 action3D_Sphere_tb->setChecked(! viewmoll);
00492 action3D_Sphere_m->setChecked(! viewmoll);
00493 actionMollweide_tb->setChecked(viewmoll);
00494 actionMollweide_m->setChecked(viewmoll);
00495 projlabel->setText(viewmoll ? "Projection: Mollweide" : "Projection: 3D Sphere");
00496
00497 }
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512 void mainWindow::setFieldEnables()
00513 {
00514 actionTemperature->setEnabled(map->has_Temperature());
00515 actionQ_Polarization->setEnabled(map->has_Polarization());
00516 actionU_Polarization->setEnabled(map->has_Polarization());
00517 actionP_Polarization->setEnabled(map->has_Polarization());
00518 actionNum_Obs->setEnabled(map->has_Nobs());
00519
00520 actionPolarAnglesTB->setEnabled(map->has_Polarization());
00521 actionPolarAnglesM->setEnabled(map->has_Polarization());
00522
00523 return;
00524 }
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538 void mainWindow::mapTemperature() { rngctl->setField(I); }
00539 void mainWindow::mapQPolarization() { rngctl->setField(Q); }
00540 void mainWindow::mapUPolarization() { rngctl->setField(U); }
00541 void mainWindow::mapPPolarization() { rngctl->setField(P); }
00542 void mainWindow::mapNumObs() { rngctl->setField(Nobs); }
00543
00544
00545
00546
00547
00548
00549
00550 void mainWindow::newField()
00551 {
00552 actionTemperature->setChecked(false);
00553 actionQ_Polarization->setChecked(false);
00554 actionU_Polarization->setChecked(false);
00555 actionP_Polarization->setChecked(false);
00556 actionNum_Obs->setChecked(false);
00557 switch( rngctl->getField() ) {
00558 case I:
00559 actionTemperature->setChecked(true);
00560 maplabel->setText(tr("Map: Temperature"));
00561 break;
00562 case Q:
00563 actionQ_Polarization->setChecked(true);
00564 maplabel->setText(tr("Map: Q Polarization"));
00565 break;
00566 case U:
00567 actionU_Polarization->setChecked(true);
00568 maplabel->setText(tr("Map: U Polarization"));
00569 break;
00570 case P:
00571 actionP_Polarization->setChecked(true);
00572 maplabel->setText(tr("Map: P Polarization"));
00573 break;
00574 case Nobs:
00575 actionNum_Obs->setChecked(true);
00576 maplabel->setText(tr("Map: Num Obs"));
00577 break;
00578 }
00579 return;
00580 }
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594 void mainWindow::mapPolVectM()
00595 {
00596 rngctl->setPolarVect(actionPolarAnglesM->isChecked() ? On : Off );
00597 }
00598 void mainWindow::mapPolVectTB()
00599 {
00600 rngctl->setPolarVect(actionPolarAnglesTB->isChecked() ? On : Off );
00601 }
00602
00603
00604
00605
00606
00607
00608 void mainWindow::newPolVect()
00609 {
00610 bool b = rngctl->getPolVect() == On;
00611 actionPolarAnglesTB->setChecked(b);
00612 actionPolarAnglesM->setChecked(b);
00613 if (polarsphere != NULL) polarsphere->setOn(b);
00614 }
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629 void mainWindow::reTexture(void)
00630 {
00631 if (! showtex) return;
00632 try {
00633 texture->set(map, rngctl);
00634 viewer->update();
00635 }
00636 catch (MapException &exc)
00637 {
00638 const char *comm = exc.Comment();
00639 QMessageBox::critical(this, tr("Skyviewer"),
00640 tr((comm != NULL) ? comm : "reTextureOld error!"),
00641 QMessageBox::Ok);
00642 }
00643 }
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657 int mainWindow::selectPixel (int pix)
00658 {
00659 if( ! ctl->selectPixel(pix,&((*map)[pix])) ) {
00660 texture->highlite(pix, 1.0);
00661 }
00662 if ( ctl->numselected() <= 0) {
00663 if (viewer->animationIsStarted()) viewer->stopAnimation();
00664 }
00665 else {
00666 if (! viewer->animationIsStarted()) viewer->startAnimation();
00667 }
00668 viewer->update();
00669 return pix;
00670 }
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685 int mainWindow::selectPixel (double theta, double phi)
00686 {
00687 int pix;
00688 long p;
00689
00690
00691 map->angles2pixel(theta, phi, p);
00692 pix = int(p);
00693
00694
00695 return selectPixel(pix);
00696 }
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708 void mainWindow::highlightPixels (double hlite)
00709 {
00710 for(int i = 0; i < ctl->numselected(); i ++ )
00711 texture->highlite(ctl->pixnum(i), float(hlite));
00712 }
00713 void mainWindow::unselectPixels(std::vector<int> pixs)
00714 {
00715 for(uint i = 0; i < pixs.size(); i ++ )
00716 texture->highlite(pixs[i], 1.0);
00717 return;
00718 }
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733 void mainWindow::recenterOnPixel(int pixnum)
00734 {
00735 double theta,phi;
00736 map->pixel2angles(pixnum, theta, phi);
00737
00738 viewer->recenterAt(theta,phi);
00739 return;
00740 }