00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "PSQt/GUIImageViewer.h"
00011 #include "PSQt/Logger.h"
00012 #include "AppUtils/AppDataPath.h"
00013 #include "PSQt/DragCenter.h"
00014
00015
00016
00017
00018 #include <sstream>
00019
00020
00021
00022 #include <cstdlib>
00023 #include <iostream>
00024 #include <fstream>
00025
00026
00027 namespace PSQt {
00028
00029
00030
00031 GUIImageViewer::GUIImageViewer(QWidget *parent, const int& xcent, const int& ycent)
00032 : Frame(parent)
00033 , m_colortab(0)
00034 {
00035 MsgInLog(_name_(), INFO, "Open image viewer");
00036
00037 AppUtils::AppDataPath adp_fname_def("PSQt/images/2011-08-10-Tiled-XPP.jpg");
00038
00039 m_file = new PSQt::WdgFile(this, "Image:", adp_fname_def.path());
00040 m_pointpos = new PSQt::WdgPointPos(this, "Center x:", " y:", 0, 0, false, 60, 2);
00041 m_curspos = new PSQt::WdgPointPos3D(this, "col:", "row:", "A:", 0, 0, 0, false, 50, 0, 0, 2);
00042 m_colortab = new WdgColorTable();
00043 m_but_add = new QPushButton("Add circle", this);
00044 m_but_reset = new QPushButton("Reset", this);
00045 m_but_cols = new QPushButton("Colors", this);
00046 m_but_spec = new QPushButton("Spectrum", this);
00047 m_but_rhis = new QPushButton("r-Histo", this);
00048 m_cbx_more = new QCheckBox("&More");
00049
00050 m_image = new PSQt::WdgImageFigs(this, m_file->fileName());
00051 m_imageproc = new ImageProc();
00052 m_radhist = new PSQt::WdgRadHist();
00053 m_spechist = new PSQt::WdgSpecHist();
00054 const DragBase* p_drag_center = m_image->getDragStore()->getDragCenter();
00055
00056 m_hbox = new QHBoxLayout();
00057 m_hbox -> addWidget(m_pointpos);
00058 m_hbox -> addWidget(m_but_add);
00059 m_hbox -> addWidget(m_but_reset);
00060 m_hbox -> addStretch(1);
00061 m_hbox -> addWidget(m_cbx_more);
00062
00063 m_hbex = new QHBoxLayout();
00064 m_hbex -> addWidget(m_curspos);
00065 m_hbex -> addStretch(1);
00066 m_hbex -> addWidget(m_but_cols);
00067 m_hbex -> addWidget(m_but_spec);
00068 m_hbex -> addWidget(m_but_rhis);
00069
00070 m_vbox = new QVBoxLayout();
00071 m_vbox -> addWidget(m_file);
00072 m_vbox -> addWidget(m_image);
00073 m_vbox -> addLayout(m_hbex);
00074 m_vbox -> addLayout(m_hbox);
00075
00076 this -> setLayout(m_vbox);
00077 this -> setWindowTitle("Image Viewer");
00078 this -> move(100,50);
00079
00080 setStyle();
00081 setTips();
00082
00083 connect(m_but_add, SIGNAL(clicked()), this, SLOT(onButAdd()));
00084 connect(m_but_reset,SIGNAL(clicked()), this, SLOT(onButReset()));
00085 connect(m_but_cols, SIGNAL(clicked()), this, SLOT(onButColorTab()));
00086 connect(m_but_spec, SIGNAL(clicked()), this, SLOT(onButSpec()));
00087 connect(m_but_rhis, SIGNAL(clicked()), this, SLOT(onButRHis()));
00088 connect(m_file, SIGNAL(fileNameIsChanged(const std::string&)), m_image, SLOT(onFileNameChanged(const std::string&)));
00089
00090 connect(p_drag_center, SIGNAL(centerIsMoved(const QPointF&)), m_pointpos, SLOT(setPointPos(const QPointF&)));
00091 connect(m_pointpos, SIGNAL(posIsChanged(const QPointF&)), p_drag_center, SLOT(moveToRaw(const QPointF&)));
00092 connect(m_pointpos, SIGNAL(posIsChanged(const QPointF&)), m_image, SLOT(forceUpdate()));
00093 connect(p_drag_center, SIGNAL(centerIsChanged(const QPointF&)), m_imageproc, SLOT(onCenterIsChanged(const QPointF&)));
00094
00095 connect(m_but_reset,SIGNAL(clicked()), m_image, SLOT(onZoomResetButton()));
00096
00097 connect(m_cbx_more, SIGNAL(stateChanged(int)), this, SLOT(onCheckBox(int)));
00098
00099 connect(m_image, SIGNAL(zoomIsChanged(int&, int&, int&, int&, float&, float&)),
00100 m_imageproc, SLOT(onZoomIsChanged(int&, int&, int&, int&, float&, float&)));
00101
00102 connect(m_image, SIGNAL(mouseInPoint(const float&, const float&, const float&)),
00103 m_curspos, SLOT(setPointPos(const float&, const float&, const float&)));
00104
00105 connect(m_colortab, SIGNAL(hueAnglesUpdated(const float&, const float&)),
00106 m_image, SLOT(onHueAnglesUpdated(const float&, const float&)));
00107
00108 connect(m_imageproc, SIGNAL(rhistIsFilled(ndarray<float, 1>&, const unsigned&, const unsigned&)),
00109 m_radhist, SLOT(onRHistIsFilled(ndarray<float, 1>&, const unsigned&, const unsigned&)));
00110
00111 connect(m_imageproc, SIGNAL(shistIsFilled(float*, const float&, const float&, const unsigned&)),
00112 m_spechist, SLOT(onSHistIsFilled(float*, const float&, const float&, const unsigned&)));
00113
00114 connect(m_colortab, SIGNAL(hueAnglesUpdated(const float&, const float&)),
00115 m_spechist->colorBar(), SLOT(onHueAnglesUpdated(const float&, const float&)));
00116
00117 connect(m_spechist->axes(), SIGNAL(pressOnAxes(QMouseEvent*, QPointF)),
00118 m_image, SLOT(onPressOnAxes(QMouseEvent*, QPointF)));
00119
00120
00121
00122
00123
00124 ((DragCenter*)p_drag_center) -> moveToRaw(QPoint(xcent,ycent));
00125
00126
00127 m_pointpos->setPointPos(m_image->getDragStore()->getCenter());
00128
00129
00130
00131 ((DragCenter*)p_drag_center) -> forceToEmitSignal();
00132
00133
00134
00135
00136
00137 onCheckBox(0);
00138 }
00139
00140
00141
00142 void
00143 GUIImageViewer::setTips()
00144 {
00145 m_but_add -> setToolTip("Add circle for current center and random radius.\n"\
00146 "Then move circle clicking on it by left mouse button and drag,\n"\
00147 "or remove circle clicking on it by middle mouse button.");
00148 m_but_reset-> setToolTip("Reset zoom and intensity range.");
00149 m_but_cols -> setToolTip("Open/close color setting tool");
00150 m_but_spec -> setToolTip("Open/close spectral window");
00151 m_but_rhis -> setToolTip("Open/close radial projection (angul-integrated)");
00152 m_cbx_more -> setToolTip("Show more or less control buttons");
00153 }
00154
00155
00156 void
00157 GUIImageViewer::setStyle()
00158 {
00159 m_but_add -> setCursor(Qt::PointingHandCursor);
00160 m_but_reset-> setCursor(Qt::PointingHandCursor);
00161 m_but_cols -> setCursor(Qt::PointingHandCursor);
00162 m_but_spec -> setCursor(Qt::PointingHandCursor);
00163 m_but_rhis -> setCursor(Qt::PointingHandCursor);
00164 m_cbx_more -> setCursor(Qt::PointingHandCursor);
00165 }
00166
00167
00168
00169 void
00170 GUIImageViewer::resizeEvent(QResizeEvent *event)
00171 {
00172 stringstream ss; ss << "Image Viewer, w=" << event->size().width() << " h=" << event->size().height();
00173 setWindowTitle(ss.str().c_str());
00174 }
00175
00176
00177
00178 void
00179 GUIImageViewer::closeEvent(QCloseEvent *event)
00180 {
00181 if (m_colortab) m_colortab->close();
00182 if (m_radhist ) m_radhist ->close();
00183 if (m_spechist) m_spechist->close();
00184
00185 QWidget::closeEvent(event);
00186 stringstream ss; ss << "Close image viewer: event type = " << event -> type();
00187 MsgInLog(_name_(), INFO, ss.str());
00188 }
00189
00190
00191
00192 void
00193 GUIImageViewer::moveEvent(QMoveEvent *e)
00194 {
00195 stringstream ss; ss << _name_() << "Image Viewer, x=" << e->pos().x() << " y=" << e->pos().y();
00196 setWindowTitle(ss.str().c_str());
00197 }
00198
00199
00200
00201 void
00202 GUIImageViewer::mousePressEvent(QMouseEvent *e)
00203 {
00204 stringstream ss; ss << _name_() << "Image Viewer, x=" << e->pos().x() << " y=" << e->pos().y();
00205 setWindowTitle(ss.str().c_str());
00206 }
00207
00208
00209
00210 void
00211 GUIImageViewer::showChildWindows()
00212 {
00213 onButSpec();
00214 onButRHis();
00215 }
00216
00217
00218
00219
00220
00221
00222 void
00223 GUIImageViewer::onButExit()
00224 {
00225 MsgInLog(_name_(), DEBUG, "onButExit");
00226 this->close();
00227 }
00228
00229
00230
00231 void
00232 GUIImageViewer::message(QWidget* wdg, const char* cmt)
00233 {
00234 stringstream ss; ss << cmt << " window " << ((wdg->isVisible()) ? "is open" : "closed");
00235 MsgInLog(_name_(), INFO, ss.str());
00236 }
00237
00238
00239
00240 void
00241 GUIImageViewer::onButRHis()
00242 {
00243 static unsigned counter=0;
00244 if(!counter++)
00245 m_radhist->move(this->pos().x() + this->size().width() + 8, this->pos().y());
00246 m_radhist->setVisible(! (m_radhist->isVisible()));
00247 this->message(m_radhist, "Radial histogram");
00248 }
00249
00250
00251
00252 void
00253 GUIImageViewer::onButSpec()
00254 {
00255 static unsigned counter=0;
00256 if(!counter++)
00257 m_spechist -> move(this->pos().x() + this->size().width() + 8,
00258 this->pos().y() + 363);
00259 m_spechist->setVisible(! (m_spechist->isVisible()));
00260 this->message(m_spechist, "Spectral histogram");
00261 }
00262
00263
00264
00265 void
00266 GUIImageViewer::onButAdd()
00267 {
00268 MsgInLog(_name_(), DEBUG, "onButAdd");
00269 float rad_raw = 110+rand()%180;
00270 this -> m_image -> addCircle(rad_raw);
00271 }
00272
00273
00274
00275 void
00276 GUIImageViewer::onButReset()
00277 {
00278 MsgInLog(_name_(), DEBUG, "onButReset, SIGNAL(clicked()) is emitted by the button");
00279 }
00280
00281
00282
00283 void
00284 GUIImageViewer::onButColorTab()
00285 {
00286 static unsigned counter=0;
00287 if(!counter++)
00288 m_colortab -> move(this->pos().x() + 8, this->pos().y());
00289
00290 m_colortab->setVisible(! (m_colortab->isVisible()));
00291
00292 this->message(m_colortab, "Color table");
00293 }
00294
00295
00296
00297 void
00298 GUIImageViewer::onImageIsUpdated(ndarray<GeoImage::raw_image_t,2>& nda)
00299 {
00300 MsgInLog(_name_(), DEBUG, "onImageIsUpdated()");
00301
00302 this -> wdgImage() -> onImageIsUpdated(nda);
00303 m_imageproc -> onImageIsUpdated(nda);
00304 }
00305
00306
00307 void
00308 GUIImageViewer::onCheckBox(int state)
00309 {
00310 MsgInLog(_name_(), DEBUG, "onCheckBox()");
00311
00312 bool is_visible = m_cbx_more -> isChecked();
00313 m_cbx_more -> setText((is_visible)? "&Less" : "&More");
00314 m_curspos ->setVisible(is_visible);
00315 m_but_cols->setVisible(is_visible);
00316 m_but_spec->setVisible(is_visible);
00317 m_but_rhis->setVisible(is_visible);
00318 }
00319
00320
00321
00322 }
00323
00324