PSQt/src/WdgRadHist.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------
00002 // File and Version Information:
00003 //   $Id: WdgRadHist.cpp 9856 2015-04-02 23:21:13Z dubrovin@SLAC.STANFORD.EDU $
00004 //
00005 // Author: Mikhail S. Dubrovin
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>  // for stringstream
00016 #include <iostream>    // for std::cout
00017 //#include <fstream>     // for std::ifstream(fname)
00018 //#include <math.h>  // atan2
00019 //#include <cstring> // for memcpy
00020 
00021 //using namespace std; // for cout without std::
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   //  setWdgParams();
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   //m_axes = new PSQt::GUAxes(0, xmin, xmax, ymin, ymax, nxdiv, nydiv);
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   //  if (m_frame)      delete m_frame;  
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   //PSQt::graph(m_axes, x1, y1, npts, "-rT4");
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 } // namespace PSQt
00104 //--------------------------

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7