00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "PSQt/WdgRadHist.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 WdgRadHist::WdgRadHist(QWidget *parent)
00028 : QWidget(parent)
00029 , m_axes(0)
00030 , m_path_item(0)
00031 {
00032
00033 float xmin = 0;
00034 float xmax = 1000;
00035 float ymin = 0;
00036 float ymax = 1000;
00037 unsigned nxdiv=4;
00038 unsigned nydiv=4;
00039
00040
00041 m_axes = new PSQt::GUAxes(0);
00042 m_axes->setLimits(xmin, xmax, ymin, ymax, nxdiv, nydiv);
00043
00044 m_vbox = new QVBoxLayout();
00045 m_vbox -> addWidget(m_axes);
00046
00047 this -> setLayout(m_vbox);
00048 this->setContentsMargins(-9,-9,-9,-9);
00049 this->setWindowTitle("Radial Histogram");
00050 }
00051
00052
00053
00054 WdgRadHist::~WdgRadHist()
00055 {
00056
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 void
00066 WdgRadHist::onRHistIsFilled(ndarray<float, 1>& nda, const unsigned& zirmin, const unsigned& zirmax)
00067 {
00068 std::stringstream ss; ss << "Draw radial histogram: array size()=" << nda.size()
00069 << " zirmin=" << zirmin
00070 << " zirmax=" << zirmax;
00071 MsgInLog(_name_(), INFO, ss.str());
00072
00073 unsigned npts = zirmax-zirmin;
00074 float x1[npts];
00075 float y1[npts];
00076
00077 float xmin = zirmin;
00078 float xmax = zirmax;
00079 float ymin = nda[0];
00080 float ymax = nda[0];
00081 float dx = 1;
00082 float x = xmin;
00083 float y = 0;
00084
00085 for(unsigned i=0; i<npts; x+=dx, i++) {
00086 x1[i] = x;
00087 y = nda[i+zirmin];
00088 y1[i] = y;
00089 if(y>ymax) ymax=y;
00090 if(y<ymin) ymin=y;
00091 }
00092 m_axes->setLimits(xmin, xmax, ymin, ymax);
00093
00094
00095 if(m_path_item) {
00096 m_axes->pscene()->removeItem(m_path_item);
00097 delete m_path_item;
00098 }
00099 m_path_item = PSQt::hist(m_axes, x1, y1, npts, "-bT");
00100 }
00101
00102
00103 }
00104