00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "PSQt/WdgSpecHist.h"
00010 #include "PSQt/Logger.h"
00011 #include "ndarray/ndarray.h"
00012
00013 #include "PSQt/QGUtils.h"
00014
00015 #include <sstream>
00016 #include <iostream>
00017
00018
00019
00020
00021
00022
00023 namespace PSQt {
00024
00025
00026
00027 WdgSpecHist::WdgSpecHist(QWidget *parent)
00028 : QWidget(parent)
00029
00030 , m_axes(0)
00031 , m_path_item(0)
00032 {
00033
00034 float xmin = 0;
00035 float xmax = 100;
00036 float ymin = 0;
00037 float ymax = 100;
00038 unsigned nxdiv=4;
00039 unsigned nydiv=4;
00040
00041
00042 m_axes = new PSQt::GUAxes(0);
00043 m_axes->setLimits(xmin, xmax, ymin, ymax, nxdiv, nydiv);
00044
00045
00046 m_cbar = new PSQt::WdgColorBar(this);
00047 m_cbar->setMinimumSize(100, 20);
00048
00049 m_hbox = new QHBoxLayout();
00050 m_hbox -> addSpacing(75);
00051 m_hbox -> addWidget(m_cbar);
00052 m_hbox -> addSpacing(75);
00053
00054
00055 m_vbox = new QVBoxLayout();
00056 m_vbox -> addWidget(m_axes);
00057 m_vbox -> addLayout(m_hbox);
00058
00059 this -> setLayout(m_vbox);
00060 this->setContentsMargins(-9,-9,-9,-9);
00061 this->setWindowTitle("Spectral Histogram");
00062 }
00063
00064
00065
00066 WdgSpecHist::~WdgSpecHist()
00067 {
00068
00069 }
00070
00071
00072
00073
00074
00075
00076
00077 void
00078 WdgSpecHist::onSHistIsFilled(float* arr, const float& amin, const float& amax, const unsigned& nbins)
00079 {
00080 std::stringstream ss; ss << "Show spectral histogram with nbins=" << nbins
00081 << " amin=" << amin
00082 << " amax=" << amax;
00083 MsgInLog(_name_(), INFO, ss.str());
00084
00085 float x1[nbins+1];
00086 float y1[nbins];
00087
00088 float xmin = amin;
00089 float xmax = amax;
00090 float ymin = arr[0];
00091 float ymax = arr[0];
00092 float dx = (amax-amin)/nbins;
00093 float x = xmin;
00094 float y = 0;
00095
00096 for(unsigned i=0; i<nbins; x+=dx, i++) {
00097 x1[i] = x;
00098 y = arr[i];
00099 y1[i] = y;
00100 if(y>ymax) ymax=y;
00101 if(y<ymin) ymin=y;
00102 }
00103 x1[nbins] = x1[nbins-1] + dx;
00104
00105 m_axes->setLimits(xmin, xmax, ymin, ymax);
00106
00107
00108 if(m_path_item) {
00109 m_axes->pscene()->removeItem(m_path_item);
00110 delete m_path_item;
00111 }
00112 m_path_item = PSQt::hist(m_axes, x1, y1, nbins, "-bT");
00113 }
00114
00115
00116 }
00117