clang format on gui

This commit is contained in:
Erik Frojdh
2020-03-10 10:18:52 +01:00
parent bd6529a64c
commit 9ede0629ef
34 changed files with 3813 additions and 3060 deletions

160
slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cxx Executable file → Normal file
View File

@ -5,6 +5,7 @@
*/
#include "SlsQt1DPlot.h"
#include "qwt_symbol.h"
#include <iostream>
#include <qwt_legend.h>
#include <qwt_math.h>
@ -14,19 +15,18 @@
#include <qwt_scale_draw.h>
#include <qwt_scale_engine.h>
#include <qwt_scale_widget.h>
#include "qwt_symbol.h"
#include <stdlib.h>
#define QwtLog10ScaleEngine QwtLogScaleEngine // hmm
#define QwtLog10ScaleEngine QwtLogScaleEngine //hmm
SlsQtH1D::SlsQtH1D(QString title, int n, double min, double max, double *data) : QwtPlotCurve(title), x(nullptr), y(nullptr), pen_ptr(nullptr) {
SlsQtH1D::SlsQtH1D(QString title, int n, double min, double max, double *data)
: QwtPlotCurve(title), x(nullptr), y(nullptr), pen_ptr(nullptr) {
Initailize();
SetData(n, min, max, data);
}
SlsQtH1D::SlsQtH1D(QString title, int n, double *data_x, double *data_y) : QwtPlotCurve(title) {
SlsQtH1D::SlsQtH1D(QString title, int n, double *data_x, double *data_y)
: QwtPlotCurve(title) {
Initailize();
SetData(n, data_x, data_y);
}
@ -39,12 +39,12 @@ void SlsQtH1D::Initailize() {
}
SlsQtH1D::~SlsQtH1D() {
delete [] x;
delete [] y;
delete pen_ptr;
delete[] x;
delete[] y;
delete pen_ptr;
}
void SlsQtH1D::Attach(SlsQt1DPlot *p) {
@ -128,18 +128,17 @@ void SlsQtH1D::SetLineStyle(int s) {
setPen(*pen_ptr);
}
void SlsQtH1D::setStyleLinesorDots(bool isLines) {
void SlsQtH1D::setStyleLinesorDots(bool isLines) {
setStyle(isLines ? QwtPlotCurve::Lines : QwtPlotCurve::Dots);
}
void SlsQtH1D::setSymbolMarkers(bool isMarker) {
QwtSymbol* marker = new QwtSymbol();
void SlsQtH1D::setSymbolMarkers(bool isMarker) {
QwtSymbol *marker = new QwtSymbol();
if (isMarker) {
marker->setStyle(QwtSymbol::Cross);
marker->setSize(5, 5);
}
setSymbol(marker);
}
void SlsQtH1D::SetData(int n, double xmin, double xmax, double *data) {
@ -170,9 +169,7 @@ void SlsQtH1D::SetData(int n, double xmin, double xmax, double *data) {
firstYgt0 = y[i];
}
setRawSamples(x, y, ndata);
}
void SlsQtH1D::SetData(int n, double *data_x, double *data_y) {
@ -181,7 +178,7 @@ void SlsQtH1D::SetData(int n, double *data_x, double *data_y) {
n = SetUpArrays(n);
ndata = n;
dx = -1; //signifies not regular intervals
dx = -1; // signifies not regular intervals
ymin = ymax = data_y ? data_y[0] : 0;
@ -202,18 +199,17 @@ void SlsQtH1D::SetData(int n, double *data_x, double *data_y) {
firstYgt0 = y[b];
}
setRawSamples(x, y, ndata);
}
int SlsQtH1D::SetUpArrays(int n) {
n = n < 1 ? 1 : n; //overflow bin
n = n < 1 ? 1 : n; // overflow bin
if (n + 1 > n_array) {
n_array = n + 1;
delete x;
delete y;
delete x;
delete y;
x = new double[n_array];
y = new double[n_array];
}
@ -225,7 +221,9 @@ double SlsQtH1D::FillBin(int bx, double v) {
bx = CheckIndex(bx);
return SetBinContent(bx, y[bx] + v);
}
double SlsQtH1D::Fill(double x, double v) { return FillBin(FindBinIndex(x), v); }
double SlsQtH1D::Fill(double x, double v) {
return FillBin(FindBinIndex(x), v);
}
double SlsQtH1D::SetBinContent(int bx, double v) {
bx = CheckIndex(bx);
@ -241,13 +239,15 @@ double SlsQtH1D::SetBinContent(int bx, double v) {
return y[bx];
}
double SlsQtH1D::SetContent(double x, double v) { return SetBinContent(FindBinIndex(x), v); }
double SlsQtH1D::SetContent(double x, double v) {
return SetBinContent(FindBinIndex(x), v);
}
int SlsQtH1D::FindBinIndex(double px) {
if (dx > 0)
CheckIndex(int((px - x[0]) / dx));
//find closest bin
// find closest bin
int b = 0;
for (; b < ndata; b++)
if (x[b] > px)
@ -261,7 +261,9 @@ int SlsQtH1D::FindBinIndex(double px) {
return b;
}
int SlsQtH1D::CheckIndex(int bx) { return (bx < 0 || bx > ndata) ? ndata : bx; } //ndata is the overflow bin
int SlsQtH1D::CheckIndex(int bx) {
return (bx < 0 || bx > ndata) ? ndata : bx;
} // ndata is the overflow bin
SlsQtH1D *SlsQtH1D::Add(double v) {
for (int bx = 0; bx < ndata; bx++)
@ -269,23 +271,20 @@ SlsQtH1D *SlsQtH1D::Add(double v) {
return this;
}
//1d hist list stuff
// 1d hist list stuff
SlsQtH1DList::SlsQtH1DList(SlsQtH1D *hist) {
the_hist = hist;
the_next = 0;
}
SlsQtH1DList::~SlsQtH1DList() {
delete the_next;
}
SlsQtH1DList::~SlsQtH1DList() { delete the_next; }
SlsQtH1D *SlsQtH1DList::Add(SlsQtH1D *hist) {
SlsQtH1DList *hl = this;
while (hl) {
if (hist == hl->the_hist)
return hist; //already added
return hist; // already added
if (!hl->the_next)
break;
hl = hl->the_next;
@ -304,7 +303,8 @@ void SlsQtH1DList::Print() {
SlsQtH1DList *hl = this;
int i = 0;
while (hl) {
std::cout << " " << i++ << ") " << hl << " " << hl->the_hist << " " << hl->the_next << '\n';
std::cout << " " << i++ << ") " << hl << " " << hl->the_hist << " "
<< hl->the_next << '\n';
hl = hl->the_next;
if (i > 10)
break;
@ -313,10 +313,10 @@ void SlsQtH1DList::Print() {
void SlsQtH1DList::Remove(SlsQtH1D *hist) {
SlsQtH1DList *hl = this;
while (hl) { //every match will be removed
while (hl) { // every match will be removed
if (hl->the_hist != hist)
hl = hl->the_next;
else { //match
else { // match
if (!hl->the_next)
hl->the_hist = 0; // first the_hist is zero when there's no next
else {
@ -330,7 +330,7 @@ void SlsQtH1DList::Remove(SlsQtH1D *hist) {
}
}
//1d plot stuff
// 1d plot stuff
SlsQt1DPlot::SlsQt1DPlot(QWidget *parent) : QwtPlot(parent) {
// n_histograms_attached=0;
hline = vline = 0;
@ -352,16 +352,16 @@ SlsQt1DPlot::SlsQt1DPlot(QWidget *parent) : QwtPlot(parent) {
}
SlsQt1DPlot::~SlsQt1DPlot() {
delete hist_list;
delete hline;
delete vline;
delete zoomer;
delete panner;
delete hist_list;
delete hline;
delete vline;
delete zoomer;
delete panner;
}
void SlsQt1DPlot::CalculateNResetZoomBase() {
@ -378,8 +378,8 @@ void SlsQt1DPlot::CalculateNResetZoomBase() {
void SlsQt1DPlot::NewHistogramAttached(SlsQtH1D *h) {
hist_list->Add(h);
CalculateNResetZoomBase();
//commented out by dhanya to take off zooming every hist in 1d plots
//if(!hist_list->Next()) UnZoom();
// commented out by dhanya to take off zooming every hist in 1d plots
// if(!hist_list->Next()) UnZoom();
Update();
}
@ -389,13 +389,9 @@ void SlsQt1DPlot::HistogramDetached(SlsQtH1D *h) {
Update();
}
void SlsQt1DPlot::Update() {
replot();
}
void SlsQt1DPlot::Update() { replot(); }
void SlsQt1DPlot::SetTitle(QString title) {
setTitle(title);
}
void SlsQt1DPlot::SetTitle(QString title) { setTitle(title); }
void SlsQt1DPlot::SetXTitle(QString title) {
setAxisTitle(QwtPlot::xBottom, title);
@ -405,20 +401,20 @@ void SlsQt1DPlot::SetYTitle(QString title) {
setAxisTitle(QwtPlot::yLeft, title);
}
void SlsQt1DPlot::SetTitleFont(const QFont& f) {
void SlsQt1DPlot::SetTitleFont(const QFont &f) {
QwtText t("");
t.setFont(f);
t.setRenderFlags( Qt::AlignLeft | Qt::AlignVCenter);
t.setRenderFlags(Qt::AlignLeft | Qt::AlignVCenter);
setTitle(t);
}
void SlsQt1DPlot::SetXFont(const QFont& f) {
void SlsQt1DPlot::SetXFont(const QFont &f) {
QwtText t("");
t.setFont(f);
setAxisTitle(QwtPlot::xBottom, t);
}
void SlsQt1DPlot::SetYFont(const QFont& f) {
void SlsQt1DPlot::SetYFont(const QFont &f) {
QwtText t("");
t.setFont(f);
setAxisTitle(QwtPlot::yLeft, t);
@ -432,9 +428,10 @@ void SlsQt1DPlot::SetLog(int axisId, bool yes) {
if (axisId == QwtPlot::yLeft)
zoomer->SetLogY(yes);
zoomer->ResetZoomBase(); //needs to be done before setting Engine
zoomer->ResetZoomBase(); // needs to be done before setting Engine
//the old ones are deleted by in the setAxisScaleFunction() function see: 128 of file qwt_plot_axis.cpp
// the old ones are deleted by in the setAxisScaleFunction() function see:
// 128 of file qwt_plot_axis.cpp
if (yes)
setAxisScaleEngine(axisId, new QwtLog10ScaleEngine());
else
@ -450,11 +447,13 @@ void SlsQt1DPlot::UnZoom() {
setAxisScale(QwtPlot::xBottom, zoomer->x(), zoomer->x() + zoomer->w());
setAxisScale(QwtPlot::yLeft, zoomer->y(), zoomer->y() + zoomer->h());
zoomer->setZoomBase(); //Call replot for the attached plot before initializing the zoomer with its scales.
zoomer->setZoomBase(); // Call replot for the attached plot before
// initializing the zoomer with its scales.
Update();
}
void SlsQt1DPlot::SetZoom(double xmin, double ymin, double x_width, double y_width) {
void SlsQt1DPlot::SetZoom(double xmin, double ymin, double x_width,
double y_width) {
setAxisScale(QwtPlot::xBottom, xmin, xmin + x_width);
setAxisScale(QwtPlot::yLeft, ymin, ymin + y_width);
Update();
@ -503,9 +502,11 @@ void SlsQt1DPlot::SetupZoom() {
zoomer = new SlsQt1DZoomer(canvas());
#if QT_VERSION < 0x040000
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton,
Qt::ControlButton);
#else
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton,
Qt::ControlModifier);
#endif
zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);
@ -546,32 +547,39 @@ void SlsQt1DPlot::alignScales() {
void SlsQt1DPlot::UnknownStuff() {
// We don't need the cache here
((QwtPlotCanvas *)canvas())->setPaintAttribute(QwtPlotCanvas::BackingStore, false);
((QwtPlotCanvas *)canvas())
->setPaintAttribute(QwtPlotCanvas::BackingStore, false);
#ifdef Q_WS_X11
// Qt::WA_PaintOnScreen is only supported for X11, but leads
// to substantial bugs with Qt 4.2.x/Windows
canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
#endif
}
//Added by Dhanya on 19.06.2012 to disable zooming when any of the axes range has been set
// Added by Dhanya on 19.06.2012 to disable zooming when any of the axes range
// has been set
void SlsQt1DPlot::DisableZoom(bool disable) {
if (disableZoom != disable) {
disableZoom = disable;
if (disable) {
if (zoomer) {
zoomer->setMousePattern(QwtEventPattern::MouseSelect1, Qt::NoButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::NoButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::NoButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect1,
Qt::NoButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::NoButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
Qt::NoButton);
}
if (panner)
panner->setMouseButton(Qt::NoButton);
} else {
if (zoomer) {
zoomer->setMousePattern(QwtEventPattern::MouseSelect1, Qt::LeftButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect1,
Qt::LeftButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
Qt::RightButton);
}
if (panner)
panner->setMouseButton(Qt::MidButton);

136
slsDetectorGui/slsDetectorPlotting/src/SlsQt1DZoomer.cxx Executable file → Normal file
View File

@ -4,7 +4,6 @@
* @version 1.0
*/
#include <iostream>
#include <qwt_plot.h>
@ -13,78 +12,89 @@
#include "SlsQt1DPlot.h"
#include "SlsQt1DZoomer.h"
void SlsQt1DZoomer::ResetZoomBase(){
SetZoomBase(x0,y0,x1-x0,y1-y0); //for going between log and nonlog plots
void SlsQt1DZoomer::ResetZoomBase() {
SetZoomBase(x0, y0, x1 - x0,
y1 - y0); // for going between log and nonlog plots
}
void SlsQt1DZoomer::SetZoomBase(double xmin,double ymin,double x_width, double y_width){
if(xIsLog&&xmin<=0){
double xmax = xmin+x_width;
xmin = firstXgt0*0.98;
if(xmax<=xmin) x_width=firstXgt0;
else x_width=xmax-xmin;
}
if(yIsLog&&ymin<=0){
double ymax = ymin+y_width;
ymin = firstYgt0*0.98;
if(ymax<=ymin) y_width=firstYgt0;
else y_width=ymax-ymin;
}
if(plot()){
if(xIsLog){
double xmin_curr = plot()->axisScaleDiv(QwtPlot::xBottom).lowerBound();
double xmax_curr = plot()->axisScaleDiv(QwtPlot::xBottom).upperBound();
if(xmin_curr<xmin)
xmin_curr=xmin;
if(xmax_curr>xmin+x_width)
xmax_curr=xmin+x_width;
plot()->setAxisScale(QwtPlot::xBottom,xmin_curr,xmax_curr);
void SlsQt1DZoomer::SetZoomBase(double xmin, double ymin, double x_width,
double y_width) {
if (xIsLog && xmin <= 0) {
double xmax = xmin + x_width;
xmin = firstXgt0 * 0.98;
if (xmax <= xmin)
x_width = firstXgt0;
else
x_width = xmax - xmin;
}
if(yIsLog){
double ymin_curr = plot()->axisScaleDiv(QwtPlot::yLeft).lowerBound();
double ymax_curr = plot()->axisScaleDiv(QwtPlot::yLeft).upperBound();
if(ymin_curr<ymin)
ymin_curr=ymin;
if(ymax_curr>ymin+y_width)
ymax_curr=ymin+y_width;
plot()->setAxisScale(QwtPlot::yLeft,ymin_curr,ymax_curr);
if (yIsLog && ymin <= 0) {
double ymax = ymin + y_width;
ymin = firstYgt0 * 0.98;
if (ymax <= ymin)
y_width = firstYgt0;
else
y_width = ymax - ymin;
}
plot()->replot();
}
setZoomBase(QRectF(xmin,ymin,x_width,y_width));
if (plot()) {
if (xIsLog) {
double xmin_curr =
plot()->axisScaleDiv(QwtPlot::xBottom).lowerBound();
double xmax_curr =
plot()->axisScaleDiv(QwtPlot::xBottom).upperBound();
if (xmin_curr < xmin)
xmin_curr = xmin;
if (xmax_curr > xmin + x_width)
xmax_curr = xmin + x_width;
plot()->setAxisScale(QwtPlot::xBottom, xmin_curr, xmax_curr);
}
if (yIsLog) {
double ymin_curr =
plot()->axisScaleDiv(QwtPlot::yLeft).lowerBound();
double ymax_curr =
plot()->axisScaleDiv(QwtPlot::yLeft).upperBound();
if (ymin_curr < ymin)
ymin_curr = ymin;
if (ymax_curr > ymin + y_width)
ymax_curr = ymin + y_width;
plot()->setAxisScale(QwtPlot::yLeft, ymin_curr, ymax_curr);
}
plot()->replot();
}
setZoomBase(QRectF(xmin, ymin, x_width, y_width));
}
void SlsQt1DZoomer::SetZoomBase(SlsQtH1D* h){
x0 = h->GetXMin()<0 ? h->GetXMin()*1.02 : h->GetXMin()/1.02;
x1 = h->GetXMax()<0 ? h->GetXMax()/1.02 : h->GetXMax()*1.02;
y0 = h->GetYMin()<0 ? h->GetYMin()*1.02 : h->GetYMin()/1.02;
y1 = h->GetYMax()<0 ? h->GetYMax()/1.02 : h->GetYMax()*1.02;
void SlsQt1DZoomer::SetZoomBase(SlsQtH1D *h) {
x0 = h->GetXMin() < 0 ? h->GetXMin() * 1.02 : h->GetXMin() / 1.02;
x1 = h->GetXMax() < 0 ? h->GetXMax() / 1.02 : h->GetXMax() * 1.02;
y0 = h->GetYMin() < 0 ? h->GetYMin() * 1.02 : h->GetYMin() / 1.02;
y1 = h->GetYMax() < 0 ? h->GetYMax() / 1.02 : h->GetYMax() * 1.02;
firstXgt0 = h->GetFirstXgtZero(); //for log plots
firstYgt0 = h->GetFirstYgtZero(); //for log plots
firstXgt0 = h->GetFirstXgtZero(); // for log plots
firstYgt0 = h->GetFirstYgtZero(); // for log plots
ResetZoomBase();
ResetZoomBase();
}
void SlsQt1DZoomer::ExtendZoomBase(SlsQtH1D* h){
double h_x0 = h->GetXMin()<0 ? h->GetXMin()*1.02 : h->GetXMin()/1.02;
double h_x1 = h->GetXMax()<0 ? h->GetXMax()/1.02 : h->GetXMax()*1.02;
double h_y0 = h->GetYMin()<0 ? h->GetYMin()*1.02 : h->GetYMin()/1.02;
double h_y1 = h->GetYMax()<0 ? h->GetYMax()/1.02 : h->GetYMax()*1.02;
if(h_x0<x0) x0 = h_x0;
if(h_x1>x1) x1 = h_x1;
if(h_y0<y0) y0 = h_y0;
if(h_y1>y1) y1 = h_y1;
void SlsQt1DZoomer::ExtendZoomBase(SlsQtH1D *h) {
double h_x0 = h->GetXMin() < 0 ? h->GetXMin() * 1.02 : h->GetXMin() / 1.02;
double h_x1 = h->GetXMax() < 0 ? h->GetXMax() / 1.02 : h->GetXMax() * 1.02;
double h_y0 = h->GetYMin() < 0 ? h->GetYMin() * 1.02 : h->GetYMin() / 1.02;
double h_y1 = h->GetYMax() < 0 ? h->GetYMax() / 1.02 : h->GetYMax() * 1.02;
if(h->GetFirstXgtZero()<firstXgt0) firstXgt0 = h->GetFirstXgtZero();
if(h->GetFirstYgtZero()<firstYgt0) firstYgt0 = h->GetFirstYgtZero();
ResetZoomBase();
if (h_x0 < x0)
x0 = h_x0;
if (h_x1 > x1)
x1 = h_x1;
if (h_y0 < y0)
y0 = h_y0;
if (h_y1 > y1)
y1 = h_y1;
if (h->GetFirstXgtZero() < firstXgt0)
firstXgt0 = h->GetFirstXgtZero();
if (h->GetFirstYgtZero() < firstYgt0)
firstYgt0 = h->GetFirstYgtZero();
ResetZoomBase();
}

232
slsDetectorGui/slsDetectorPlotting/src/SlsQt2DHist.cxx Executable file → Normal file
View File

@ -4,125 +4,145 @@
* @version 1.0
*/
#include "ansi.h"
#include <iostream>
#include <cmath>
#include "SlsQt2DHist.h"
#include "ansi.h"
#include <cmath>
#include <iostream>
using std::cout;
using std::endl;
SlsQt2DHist::SlsQt2DHist(int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, double* d,double zmin,double zmax):QwtRasterData(){
x_min=0;x_max=0;y_min=0;y_max=0;
interp=0;
nx_array=ny_array=0;data=0;
SetData(nbinsx,xmin,xmax,nbinsy,ymin,ymax,d,zmin,zmax);
SlsQt2DHist::SlsQt2DHist(int nbinsx, double xmin, double xmax, int nbinsy,
double ymin, double ymax, double *d, double zmin,
double zmax)
: QwtRasterData() {
x_min = 0;
x_max = 0;
y_min = 0;
y_max = 0;
interp = 0;
nx_array = ny_array = 0;
data = 0;
SetData(nbinsx, xmin, xmax, nbinsy, ymin, ymax, d, zmin, zmax);
}
SlsQt2DHist::~SlsQt2DHist() { delete[] data; }
SlsQt2DHist::~SlsQt2DHist(){ delete [] data;}
int SlsQt2DHist::GetBinIndex(int bx, int by){
int b = bx*ny+by;
if(b<0 || b>=nb){
cout<<"GetBinIndex:: Incorrect indicies bx and by returning overflow bin;"<<endl;
return nb;
}
return b;
}
int SlsQt2DHist::FindBinIndex(double x, double y){
return GetBinIndex(int((x-x_min)/x_width),int((y-y_min)/y_width));
}
double SlsQt2DHist::GetBinValue(int bx,int by){
return data[GetBinIndex(bx,by)];
}
void SlsQt2DHist::SetBinValue(int bx,int by,double v){
z_mean_has_been_calculated = 0;
data[GetBinIndex(bx,by)] = v;
}
void SlsQt2DHist::SetData(int nbinsx, double xmin, double xmax, int nbinsy,double ymin, double ymax, double *d,double zmin,double zmax){
z_mean_has_been_calculated = 0;
if(xmax<xmin||ymax<ymin) cout<<"Warning input range invalid."<<endl;
x_width = (xmax - xmin)/nbinsx;
y_width = (ymax - ymin)/nbinsy;
if(x_min!=xmin||x_max!=xmax||y_min!=ymin||y_max!=ymax){
x_min=xmin;x_max=xmax;
y_min=ymin;y_max=ymax;
setInterval( Qt::XAxis,QwtInterval(xmin,xmax));
setInterval( Qt::YAxis,QwtInterval(ymin,ymax));
}
if(nbinsx*nbinsy<1){
cout<<"Exitting: SlsQt2DHist::SetData() number of bins must be greater than zero."<<endl;
exit(1);
}
if(nbinsx*nbinsy>nx_array*ny_array){
delete [] data;
data = new double [nbinsx*nbinsy+1]; //one for under/overflow bin
nx_array = nbinsx;
ny_array = nbinsy;
}
nx=nbinsx;
ny=nbinsy;
nb=nx*ny;
data[nb]=0;//set over flow to zero
if(d){
memcpy(data,d,nb*sizeof(double));
SetMinMax(zmin,zmax);
}
}
void SlsQt2DHist::SetMinMax(double zmin,double zmax){
/* if(zmin<zmax){ edited out to test*/
if(zmax != -1){
z_min=zmin;
z_max=zmax;
}else{
z_mean_has_been_calculated = 1;
z_min=data[0];
z_mean=0;
z_max=data[0];
for(int i=0;i<nb;i++){
if(data[i]<z_min) z_min=data[i];
if(data[i]>z_max) z_max=data[i];
z_mean+=data[i];
int SlsQt2DHist::GetBinIndex(int bx, int by) {
int b = bx * ny + by;
if (b < 0 || b >= nb) {
cout << "GetBinIndex:: Incorrect indicies bx and by returning overflow "
"bin;"
<< endl;
return nb;
}
z_mean/=nb;
if(z_min>0) z_min/=1.02; else z_min*=1.02;
if(z_max>0) z_max*=1.02; else z_max/=1.02;
}
setInterval( Qt::ZAxis,QwtInterval(z_min,z_max));
return b;
}
double SlsQt2DHist::GetMean(){
if(!z_mean_has_been_calculated){
z_mean_has_been_calculated = 1;
z_mean=0;
for(int i=0;i<nb;i++) z_mean+=data[i];
z_mean/=nb;
}
return z_mean;
int SlsQt2DHist::FindBinIndex(double x, double y) {
return GetBinIndex(int((x - x_min) / x_width), int((y - y_min) / y_width));
}
double SlsQt2DHist::SetMinimumToFirstGreaterThanZero(){
z_min=fabs(z_max)+1;
for(int i=0;i<nb;i++){
if(data[i]>0 && data[i]<z_min) z_min=data[i];
}
setInterval( Qt::ZAxis,QwtInterval(z_min,z_max));
return z_min;
double SlsQt2DHist::GetBinValue(int bx, int by) {
return data[GetBinIndex(bx, by)];
}
void SlsQt2DHist::SetBinValue(int bx, int by, double v) {
z_mean_has_been_calculated = 0;
data[GetBinIndex(bx, by)] = v;
}
void SlsQt2DHist::SetData(int nbinsx, double xmin, double xmax, int nbinsy,
double ymin, double ymax, double *d, double zmin,
double zmax) {
z_mean_has_been_calculated = 0;
if (xmax < xmin || ymax < ymin)
cout << "Warning input range invalid." << endl;
x_width = (xmax - xmin) / nbinsx;
y_width = (ymax - ymin) / nbinsy;
if (x_min != xmin || x_max != xmax || y_min != ymin || y_max != ymax) {
x_min = xmin;
x_max = xmax;
y_min = ymin;
y_max = ymax;
setInterval(Qt::XAxis, QwtInterval(xmin, xmax));
setInterval(Qt::YAxis, QwtInterval(ymin, ymax));
}
if (nbinsx * nbinsy < 1) {
cout << "Exitting: SlsQt2DHist::SetData() number of bins must be "
"greater than zero."
<< endl;
exit(1);
}
if (nbinsx * nbinsy > nx_array * ny_array) {
delete[] data;
data = new double[nbinsx * nbinsy + 1]; // one for under/overflow bin
nx_array = nbinsx;
ny_array = nbinsy;
}
nx = nbinsx;
ny = nbinsy;
nb = nx * ny;
data[nb] = 0; // set over flow to zero
if (d) {
memcpy(data, d, nb * sizeof(double));
SetMinMax(zmin, zmax);
}
}
void SlsQt2DHist::SetMinMax(double zmin, double zmax) {
/* if(zmin<zmax){ edited out to test*/
if (zmax != -1) {
z_min = zmin;
z_max = zmax;
} else {
z_mean_has_been_calculated = 1;
z_min = data[0];
z_mean = 0;
z_max = data[0];
for (int i = 0; i < nb; i++) {
if (data[i] < z_min)
z_min = data[i];
if (data[i] > z_max)
z_max = data[i];
z_mean += data[i];
}
z_mean /= nb;
if (z_min > 0)
z_min /= 1.02;
else
z_min *= 1.02;
if (z_max > 0)
z_max *= 1.02;
else
z_max /= 1.02;
}
setInterval(Qt::ZAxis, QwtInterval(z_min, z_max));
}
double SlsQt2DHist::GetMean() {
if (!z_mean_has_been_calculated) {
z_mean_has_been_calculated = 1;
z_mean = 0;
for (int i = 0; i < nb; i++)
z_mean += data[i];
z_mean /= nb;
}
return z_mean;
}
double SlsQt2DHist::SetMinimumToFirstGreaterThanZero() {
z_min = fabs(z_max) + 1;
for (int i = 0; i < nb; i++) {
if (data[i] > 0 && data[i] < z_min)
z_min = data[i];
}
setInterval(Qt::ZAxis, QwtInterval(z_min, z_max));
return z_min;
}

123
slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlot.cxx Executable file → Normal file
View File

@ -19,11 +19,7 @@
#include <qwt_scale_engine.h>
#include <qwt_scale_widget.h>
#define QwtLog10ScaleEngine QwtLogScaleEngine //hmm remove?
#define QwtLog10ScaleEngine QwtLogScaleEngine // hmm remove?
SlsQt2DPlot::SlsQt2DPlot(QWidget *parent) : QwtPlot(parent) {
isLog = 0;
@ -40,55 +36,52 @@ SlsQt2DPlot::SlsQt2DPlot(QWidget *parent) : QwtPlot(parent) {
Update();
}
SlsQt2DPlot::~SlsQt2DPlot() {
if (d_spectrogram) {
d_spectrogram->detach();
//delete d_spectrogram;
// delete d_spectrogram;
}
delete hist;
delete colorMapLinearScale;
delete colorMapLogScale;
delete zoomer;
delete panner;
delete hist;
delete colorMapLinearScale;
delete colorMapLogScale;
delete zoomer;
delete panner;
}
void SlsQt2DPlot::SetTitle(QString title) {
setTitle(title);
}
void SlsQt2DPlot::SetTitle(QString title) { setTitle(title); }
void SlsQt2DPlot::SetXTitle(QString title) {
setAxisTitle(QwtPlot::xBottom, title);
setAxisTitle(QwtPlot::xBottom, title);
}
void SlsQt2DPlot::SetYTitle(QString title) {
setAxisTitle(QwtPlot::yLeft, title);
setAxisTitle(QwtPlot::yLeft, title);
}
void SlsQt2DPlot::SetZTitle(QString title) {
setAxisTitle(QwtPlot::yRight, title);
setAxisTitle(QwtPlot::yRight, title);
}
void SlsQt2DPlot::SetTitleFont(const QFont& f) {
void SlsQt2DPlot::SetTitleFont(const QFont &f) {
QwtText t("");
t.setFont(f);
t.setRenderFlags( Qt::AlignLeft | Qt::AlignVCenter);
t.setRenderFlags(Qt::AlignLeft | Qt::AlignVCenter);
setTitle(t);
}
void SlsQt2DPlot::SetXFont(const QFont& f) {
void SlsQt2DPlot::SetXFont(const QFont &f) {
QwtText t("");
t.setFont(f);
setAxisTitle(QwtPlot::xBottom, t);
}
void SlsQt2DPlot::SetYFont(const QFont& f) {
void SlsQt2DPlot::SetYFont(const QFont &f) {
QwtText t("");
t.setFont(f);
setAxisTitle(QwtPlot::yLeft, t);
}
void SlsQt2DPlot::SetZFont(const QFont& f) {
void SlsQt2DPlot::SetZFont(const QFont &f) {
QwtText t("");
t.setFont(f);
setAxisTitle(QwtPlot::yRight, t);
@ -105,7 +98,6 @@ void SlsQt2DPlot::SetupColorMap() {
for (double level = 0.5; level < 10.0; level += 1.0)
(contourLevelsLog) += (pow(10, 2 * level / 10.0) - 1) / 99.0 * 10;
// A color bar on the right axis
rightAxis = axisWidget(QwtPlot::yRight);
@ -124,7 +116,8 @@ void SlsQt2DPlot::FillTestPlot(int mode) {
double dmax = sqrt(pow(nx / 2.0 - 0.5, 2) + pow(ny / 2.0 - 0.5, 2));
for (int i = 0; i < nx; i++) {
for (int j = 0; j < ny; j++) {
double d = sqrt(pow(nx / 2.0 - (i + 0.5), 2) + pow(ny / 2.0 - (j + 0.5), 2));
double d = sqrt(pow(nx / 2.0 - (i + 0.5), 2) +
pow(ny / 2.0 - (j + 0.5), 2));
if (mode % 3)
the_data[i + j * nx] = 10 * d / dmax;
@ -146,9 +139,11 @@ void SlsQt2DPlot::SetupZoom() {
zoomer->SetHist(hist);
#if QT_VERSION < 0x040000
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton,
Qt::ControlButton);
#else
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton,
Qt::ControlModifier);
#endif
zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);
@ -169,27 +164,31 @@ void SlsQt2DPlot::SetupZoom() {
}
/*void SlsQt2DPlot::CompletelyUnZoom(){
setAxisScale(QwtPlot::xBottom,hist->GetXMin(),hist->GetXMin()+(hist->GetXMax()-hist->GetXMin()));
setAxisScale(QwtPlot::yLeft,hist->GetYMin(),hist->GetYMin()+(hist->GetYMax()-hist->GetYMin()));
zoomer->setZoomBase();
//replot();
setAxisScale(QwtPlot::xBottom,hist->GetXMin(),hist->GetXMin()+(hist->GetXMax()-hist->GetXMin()));
setAxisScale(QwtPlot::yLeft,hist->GetYMin(),hist->GetYMin()+(hist->GetYMax()-hist->GetYMin()));
zoomer->setZoomBase();
//replot();
}*/
void SlsQt2DPlot::UnZoom(bool replot) {
zoomer->setZoomBase(QRectF(hist->GetXMin(), hist->GetYMin(), hist->GetXMax() - hist->GetXMin(), hist->GetYMax() - hist->GetYMin()));
zoomer->setZoomBase(replot); //Call replot for the attached plot before initializing the zoomer with its scales.
zoomer->setZoomBase(QRectF(hist->GetXMin(), hist->GetYMin(),
hist->GetXMax() - hist->GetXMin(),
hist->GetYMax() - hist->GetYMin()));
zoomer->setZoomBase(replot); // Call replot for the attached plot before
// initializing the zoomer with its scales.
// zoomer->zoom(0);
}
void SlsQt2DPlot::SetZoom(double xmin, double ymin, double x_width, double y_width) {
void SlsQt2DPlot::SetZoom(double xmin, double ymin, double x_width,
double y_width) {
zoomer->setZoomBase(QRectF(xmin, ymin, x_width, y_width));
}
void SlsQt2DPlot::DisableZoom(bool disable) {
if (disableZoom != disable) {
disableZoom = disable;
#ifdef VERBOSE
if (disable)
std::cout << "Disabling zoom\n";
@ -198,25 +197,33 @@ void SlsQt2DPlot::DisableZoom(bool disable) {
#endif
if (disable) {
if (zoomer) {
zoomer->setMousePattern(QwtEventPattern::MouseSelect1, Qt::NoButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect1,
Qt::NoButton);
#if QT_VERSION < 0x040000
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::NoButton, Qt::ControlButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::NoButton, Qt::ControlButton);
#else
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::NoButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::NoButton, Qt::ControlModifier);
#endif
zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::NoButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
Qt::NoButton);
}
if (panner)
panner->setMouseButton(Qt::NoButton);
} else {
if (zoomer) {
zoomer->setMousePattern(QwtEventPattern::MouseSelect1, Qt::LeftButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect1,
Qt::LeftButton);
#if QT_VERSION < 0x040000
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlButton);
#else
zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlModifier);
#endif
zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);
zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
Qt::RightButton);
}
if (panner)
panner->setMouseButton(Qt::MidButton);
@ -224,7 +231,6 @@ void SlsQt2DPlot::DisableZoom(bool disable) {
}
}
void SlsQt2DPlot::SetZMinMax(double zmin, double zmax) {
hist->SetMinMax(zmin, zmax);
}
@ -294,24 +300,25 @@ void SlsQt2DPlot::SetContour(bool enable) {
Update();
}
void SlsQt2DPlot::SetLogz(bool enable, bool isMin, bool isMax, double min, double max) {
LogZ(enable);
SetZRange(isMin, isMax, min, max);
void SlsQt2DPlot::SetLogz(bool enable, bool isMin, bool isMax, double min,
double max) {
LogZ(enable);
SetZRange(isMin, isMax, min, max);
}
void SlsQt2DPlot::SetZRange(bool isMin, bool isMax, double min, double max){
if(isLog) {
SetZMinimumToFirstGreaterThanZero();
}
void SlsQt2DPlot::SetZRange(bool isMin, bool isMax, double min, double max) {
if (isLog) {
SetZMinimumToFirstGreaterThanZero();
}
// set zmin and zmax
if (isMin || isMax) {
double zmin = (isMin ? min : GetZMinimum());
double zmax = (isMax ? max : GetZMaximum());
SetZMinMax(zmin, zmax);
}
// set zmin and zmax
if (isMin || isMax) {
double zmin = (isMin ? min : GetZMinimum());
double zmax = (isMax ? max : GetZMaximum());
SetZMinMax(zmin, zmax);
}
Update();
Update();
}
void SlsQt2DPlot::LogZ(bool on) {