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

258
slsDetectorGui/slsDetectorPlotting/include/SlsQt1DPlot.h Executable file → Normal file
View File

@ -3,181 +3,179 @@
* @author Ian Johnson
* @version 1.0
* Modifications:
* 19.06.2012: {Some functions have been added by Dhanya to enable zooming in and out
* without using mouse control:
* DisableZoom,
* SetXMinMax,SetYMinMax,
* 19.06.2012: {Some functions have been added by Dhanya to enable zooming in
* and out without using mouse control: DisableZoom, SetXMinMax,SetYMinMax,
* GetXMinimum,GetXMaximum,GetYMinimum,GetYMaximum}
* */
#ifndef SLSQT1DPLOT_H
#define SLSQT1DPLOT_H
typedef double double32_t;
typedef float float32_t;
typedef int int32_t;
typedef double double32_t;
typedef float float32_t;
typedef int int32_t;
#include "ansi.h"
#include "SlsQt1DZoomer.h"
#include <iostream>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_marker.h>
#include <qwt_scale_div.h>
#include "SlsQt1DZoomer.h"
#include <iostream>
class QPen;
class SlsQt1DPlot;
class QwtSymbol;
class SlsQtH1D:public QwtPlotCurve{
class SlsQtH1D : public QwtPlotCurve {
public:
SlsQtH1D(QString title, int n, double xmin, double xmax, double* data=0);
SlsQtH1D(QString title, int n, double* data_x, double* data_y);
~SlsQtH1D();
public:
SlsQtH1D(QString title, int n, double xmin, double xmax, double *data = 0);
SlsQtH1D(QString title, int n, double *data_x, double *data_y);
~SlsQtH1D();
void Attach(SlsQt1DPlot* p);
void Detach(SlsQt1DPlot* p);
void Attach(SlsQt1DPlot *p);
void Detach(SlsQt1DPlot *p);
int SetLineColor(int c=-1);
int SetLineWidth(int w=1);
void SetLineStyle(int s=0);
void setStyleLinesorDots(bool isLines);
void setSymbolMarkers(bool isMarker);
int SetLineColor(int c = -1);
int SetLineWidth(int w = 1);
void SetLineStyle(int s = 0);
void setStyleLinesorDots(bool isLines);
void setSymbolMarkers(bool isMarker);
void SetData(int n, double xmin, double xmax, double* d=0);
void SetData(int n, double* dx, double* dy);
void SetData(int n, double xmin, double xmax, double *d = 0);
void SetData(int n, double *dx, double *dy);
double* GetX() {return x;}
double* GetY() {return y;}
int GetNBinsX() {return ndata;}
double *GetX() { return x; }
double *GetY() { return y; }
int GetNBinsX() { return ndata; }
double FillBin(int bx, double v=1);
double Fill(double x, double v=1);
double SetBinContent(int bx,double v);
double SetContent(double x,double v);
int FindBinIndex(double px);
double FillBin(int bx, double v = 1);
double Fill(double x, double v = 1);
double SetBinContent(int bx, double v);
double SetContent(double x, double v);
int FindBinIndex(double px);
double GetXMin() {return x[0];}
double GetFirstXgtZero() {return firstXgt0;}
double GetXMax() {return x[ndata-1];}
double GetYMin() {return ymin;}
double GetFirstYgtZero() {return firstYgt0;}
double GetYMax() {return ymax;}
double GetXMin() { return x[0]; }
double GetFirstXgtZero() { return firstXgt0; }
double GetXMax() { return x[ndata - 1]; }
double GetYMin() { return ymin; }
double GetFirstYgtZero() { return firstYgt0; }
double GetYMax() { return ymax; }
SlsQtH1D* Add(double v);
SlsQtH1D *Add(double v);
private:
int ndata;
int n_array;
double dx;
double *x{nullptr}, *y{nullptr};
double ymin, ymax;
double firstXgt0, firstYgt0;
void Initailize();
int SetUpArrays(int n);
int CheckIndex(int bx);
private:
int ndata;
int n_array;
double dx;
double *x{nullptr},*y{nullptr};
double ymin,ymax;
double firstXgt0,firstYgt0;
void Initailize();
int SetUpArrays(int n);
int CheckIndex(int bx);
QPen* pen_ptr{nullptr};
QPen *pen_ptr{nullptr};
};
class SlsQtH1DList {
public:
SlsQtH1DList(SlsQtH1D *hist = 0);
~SlsQtH1DList();
class SlsQtH1DList{
public:
SlsQtH1DList(SlsQtH1D* hist=0);
~SlsQtH1DList();
SlsQtH1D *Add(SlsQtH1D *h);
void Remove(SlsQtH1D *h);
void Print();
SlsQtH1D* Add(SlsQtH1D* h);
void Remove(SlsQtH1D* h);
void Print();
SlsQtH1D *Hist() { return the_hist; } // if no hist returns 0
SlsQtH1DList *Next() { return the_next; }
SlsQtH1D* Hist() {return the_hist;} //if no hist returns 0
SlsQtH1DList* Next() {return the_next;}
private:
SlsQtH1DList* the_next;
SlsQtH1D* the_hist;
private:
SlsQtH1DList *the_next;
SlsQtH1D *the_hist;
};
class SlsQt1DPlot:public QwtPlot{
Q_OBJECT
class SlsQt1DPlot : public QwtPlot {
Q_OBJECT
public:
SlsQt1DPlot(QWidget* = NULL);
~SlsQt1DPlot();
void SetTitle(QString title);
void SetXTitle(QString title);
void SetYTitle(QString title);
void SetTitleFont(const QFont& f);
void SetXFont(const QFont& f);
void SetYFont(const QFont& f);
void InsertHLine(double y);
void RemoveHLine();
void InsertVLine(double v);
void RemoveVLine();
public:
SlsQt1DPlot(QWidget * = NULL);
~SlsQt1DPlot();
void SetTitle(QString title);
void SetXTitle(QString title);
void SetYTitle(QString title);
void SetTitleFont(const QFont &f);
void SetXFont(const QFont &f);
void SetYFont(const QFont &f);
/** This group of functions have been added by Dhanya on 19.06.2012 to be able to
use zooming functionality without mouse control*/
void DisableZoom(bool disable);
void EnableXAutoScaling() {setAxisAutoScale(QwtPlot::xBottom, true);Update();};
void EnableYAutoScaling() {setAxisAutoScale(QwtPlot::yLeft, true);Update();};
void SetYStep (int step) {ystep = step;};
void SetXMinMax(double min,double max){setAxisScale(QwtPlot::xBottom,min,max);};
void SetYMinMax(double min,double max){setAxisScale(QwtPlot::yLeft,min,max);};
double GetXMinimum(){return hist_list->Hist()->GetXMin();};
double GetXMaximum(){return hist_list->Hist()->GetXMax();};
double GetYMinimum(){return hist_list->Hist()->GetYMin();};
double GetYMaximum(){return hist_list->Hist()->GetYMax();};
/**---*/
void InsertHLine(double y);
void RemoveHLine();
void InsertVLine(double v);
void RemoveVLine();
/** This group of functions have been added by Dhanya on 19.06.2012 to be
able to use zooming functionality without mouse control*/
void DisableZoom(bool disable);
void EnableXAutoScaling() {
setAxisAutoScale(QwtPlot::xBottom, true);
Update();
};
void EnableYAutoScaling() {
setAxisAutoScale(QwtPlot::yLeft, true);
Update();
};
void SetYStep(int step) { ystep = step; };
void SetXMinMax(double min, double max) {
setAxisScale(QwtPlot::xBottom, min, max);
};
void SetYMinMax(double min, double max) {
setAxisScale(QwtPlot::yLeft, min, max);
};
double GetXMinimum() { return hist_list->Hist()->GetXMin(); };
double GetXMaximum() { return hist_list->Hist()->GetXMax(); };
double GetYMinimum() { return hist_list->Hist()->GetYMin(); };
double GetYMaximum() { return hist_list->Hist()->GetYMax(); };
/**---*/
void SetZoom(double xmin,double ymin,double x_width,double y_width);
void SetZoomBase(double xmin,double ymin,double x_width, double y_width){ zoomer->SetZoomBase(xmin,ymin,x_width,y_width);}
void SetZoom(double xmin, double ymin, double x_width, double y_width);
void SetZoomBase(double xmin, double ymin, double x_width, double y_width) {
zoomer->SetZoomBase(xmin, ymin, x_width, y_width);
}
void alignScales();
void alignScales();
void SetLogX(bool yes=1);
void SetLogY(bool yes=1);
private:
SlsQtH1DList* hist_list{nullptr};
SlsQt1DZoomer* zoomer{nullptr};
QwtPlotPanner* panner{nullptr};
void SetLogX(bool yes = 1);
void SetLogY(bool yes = 1);
QwtPlotMarker *hline{nullptr};
QwtPlotMarker *vline{nullptr};
bool disableZoom{false};
int ystep{0};
void SetupZoom();
void UnknownStuff();
//void alignScales();
void CalculateNResetZoomBase();
void NewHistogramAttached(SlsQtH1D* h);
void HistogramDetached(SlsQtH1D* h);
private:
SlsQtH1DList *hist_list{nullptr};
SlsQt1DZoomer *zoomer{nullptr};
QwtPlotPanner *panner{nullptr};
void SetLog(int axisId, bool yes);
friend void SlsQtH1D::Attach(SlsQt1DPlot* p);
friend void SlsQtH1D::Detach(SlsQt1DPlot* p);
public slots:
void UnZoom();
void Update();
QwtPlotMarker *hline{nullptr};
QwtPlotMarker *vline{nullptr};
bool disableZoom{false};
int ystep{0};
void SetupZoom();
void UnknownStuff();
// void alignScales();
void CalculateNResetZoomBase();
void NewHistogramAttached(SlsQtH1D *h);
void HistogramDetached(SlsQtH1D *h);
void SetLog(int axisId, bool yes);
friend void SlsQtH1D::Attach(SlsQt1DPlot *p);
friend void SlsQtH1D::Detach(SlsQt1DPlot *p);
public slots:
void UnZoom();
void Update();
};
#endif

View File

@ -7,54 +7,51 @@
#ifndef SLSQT1DZOOMER_H
#define SLSQT1DZOOMER_H
#include <qwt_plot_zoomer.h>
#include <qwt_plot_panner.h>
#include <qwt_global.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_zoomer.h>
class SlsQtH1D;
class SlsQt1DZoomer:public QwtPlotZoomer{
private:
double x0,x1,y0,y1;
double firstXgt0,firstYgt0;
bool xIsLog,yIsLog;
class SlsQt1DZoomer : public QwtPlotZoomer {
private:
double x0, x1, y0, y1;
double firstXgt0, firstYgt0;
bool xIsLog, yIsLog;
public:
SlsQt1DZoomer(QWidget *canvas):QwtPlotZoomer(canvas){
setTrackerMode(AlwaysOn);
xIsLog=yIsLog=0;
}
public:
SlsQt1DZoomer(QWidget *canvas) : QwtPlotZoomer(canvas) {
setTrackerMode(AlwaysOn);
xIsLog = yIsLog = 0;
}
double x() {return x0;}
double x_firstGreaterThan0() {return firstXgt0;}
double w() {return x1-x0;}
double x() { return x0; }
double x_firstGreaterThan0() { return firstXgt0; }
double w() { return x1 - x0; }
double y() {return y0;}
double y_firstGreaterThan0() {return firstYgt0;}
double h() {return y1-y0;}
double y() { return y0; }
double y_firstGreaterThan0() { return firstYgt0; }
double h() { return y1 - y0; }
void SetZoomBase(double xmin,double ymin,double x_width, double y_width);
void SetZoomBase(SlsQtH1D* h);
void ExtendZoomBase(SlsQtH1D* h);
void ResetZoomBase();
void SetZoomBase(double xmin, double ymin, double x_width, double y_width);
void SetZoomBase(SlsQtH1D *h);
void ExtendZoomBase(SlsQtH1D *h);
void ResetZoomBase();
bool IsLogX(){ return xIsLog;}
bool IsLogY(){ return yIsLog;}
bool SetLogX(bool yes) { return xIsLog=yes;}
bool SetLogY(bool yes) { return yIsLog=yes;}
bool IsLogX() { return xIsLog; }
bool IsLogY() { return yIsLog; }
bool SetLogX(bool yes) { return xIsLog = yes; }
bool SetLogY(bool yes) { return yIsLog = yes; }
using QwtPlotPicker::trackerText;
virtual QwtText trackerText(const QPoint &pos) const{
QColor bg(Qt::white);
bg.setAlpha(200);
QwtText text = QwtPlotPicker::trackerText(pos);
text.setBackgroundBrush( QBrush( bg ));
return text;
}
using QwtPlotPicker::trackerText;
virtual QwtText trackerText(const QPoint &pos) const {
QColor bg(Qt::white);
bg.setAlpha(200);
QwtText text = QwtPlotPicker::trackerText(pos);
text.setBackgroundBrush(QBrush(bg));
return text;
}
};
#endif

191
slsDetectorGui/slsDetectorPlotting/include/SlsQt2DHist.h Executable file → Normal file
View File

@ -4,132 +4,131 @@
* @version 1.0
*/
#ifndef SLSQT2DHIST_H
#define SLSQT2DHIST_H
#if QT_VERSION >= 0x040000
#include <qprintdialog.h>
#endif
#include <qwt_color_map.h>
#include <qwt_plot_spectrogram.h>
#include <qwt_scale_widget.h>
#include <qwt_scale_draw.h>
#include <qwt_scale_widget.h>
class SlsQt2DHist : public QwtRasterData {
class SlsQt2DHist: public QwtRasterData{
private:
private:
double x_min, x_max, y_min, y_max;
double x_width, y_width;
double x_min,x_max,y_min,y_max;
double x_width,y_width;
int nx, ny, nb;
double *data{nullptr};
double z_min, z_mean, z_max;
bool z_mean_has_been_calculated;
int nx,ny,nb;
double *data{nullptr};
double z_min,z_mean,z_max;
bool z_mean_has_been_calculated;
int nx_array,ny_array;
int nx_array, ny_array;
bool interp;
bool interp;
static double value_between_points(double p1,double v1,double p2,double v2,double p){ //linear extrap
return (v2-v1)/(p2-p1)*(p-p1)+v1;
}
public:
SlsQt2DHist(int nbinsx=10, double xmin=0, double xmax=10, int nbinsy=10, double ymin=0, double ymax=10, double* d=0,double zmin=0,double zmax=-1);
virtual ~SlsQt2DHist();
static double value_between_points(double p1, double v1, double p2,
double v2, double p) { // linear extrap
return (v2 - v1) / (p2 - p1) * (p - p1) + v1;
}
double GetXMin() {return x_min;}
double GetXMax() {return x_max;}
double GetXBinWidth() {return x_width;}
double GetYMin() {return y_min;}
double GetYMax() {return y_max;}
double GetYBinWidth() {return y_width;}
double GetMinimum() {return z_min;}
double GetMaximum() {return z_max;}
double GetMean();
public:
SlsQt2DHist(int nbinsx = 10, double xmin = 0, double xmax = 10,
int nbinsy = 10, double ymin = 0, double ymax = 10,
double *d = 0, double zmin = 0, double zmax = -1);
virtual ~SlsQt2DHist();
int GetNBinsX(){return nx;}
int GetNBinsY(){return ny;}
double GetBinValue(int bx,int by);
int GetBinIndex(int bx,int by);
double* GetDataPtr(){return data;}
double GetXMin() { return x_min; }
double GetXMax() { return x_max; }
double GetXBinWidth() { return x_width; }
double GetYMin() { return y_min; }
double GetYMax() { return y_max; }
double GetYBinWidth() { return y_width; }
double GetMinimum() { return z_min; }
double GetMaximum() { return z_max; }
double GetMean();
void Interpolate(bool on=1) {interp=on;}
void SetBinValue(int bx,int by,double v);
void SetData(int nbinsx, double xmin, double xmax, int nbinsy,double ymin, double ymax,double *d,double zmin=0, double zmax=-1);
double SetMinimumToFirstGreaterThanZero();
void SetMinimum(double zmin) {z_min=zmin;}
void SetMaximum(double zmax) {z_max=zmax;}
void SetMinMax(double zmin=0,double zmax=-1);
int GetNBinsX() { return nx; }
int GetNBinsY() { return ny; }
double GetBinValue(int bx, int by);
int GetBinIndex(int bx, int by);
double *GetDataPtr() { return data; }
int FindBinIndex(double x, double y);
void Interpolate(bool on = 1) { interp = on; }
void SetBinValue(int bx, int by, double v);
void SetData(int nbinsx, double xmin, double xmax, int nbinsy, double ymin,
double ymax, double *d, double zmin = 0, double zmax = -1);
double SetMinimumToFirstGreaterThanZero();
void SetMinimum(double zmin) { z_min = zmin; }
void SetMaximum(double zmax) { z_max = zmax; }
void SetMinMax(double zmin = 0, double zmax = -1);
int FindBinIndex(double x, double y);
virtual QwtRasterData *copy() const{
//this function does not create a new SlsQt2DHistData instance,
//just passes a pointer so that data is common to both the copy and the original instance
return (QwtRasterData*) this;
}
virtual QwtRasterData *copy() const {
// this function does not create a new SlsQt2DHistData instance,
// just passes a pointer so that data is common to both the copy and the
// original instance
return (QwtRasterData *)this;
}
virtual QwtInterval range() const{ return QwtInterval(z_min,z_max);}
virtual QwtInterval interval(Qt::Axis axis) const {
switch (axis){
case Qt::ZAxis:
return QwtInterval(z_min,z_max);
case Qt::XAxis:
return QwtInterval(x_min,x_max);
case Qt::YAxis:
return QwtInterval(y_min,y_max);
default:
return QwtInterval(z_min,z_max);
virtual QwtInterval range() const { return QwtInterval(z_min, z_max); }
virtual QwtInterval interval(Qt::Axis axis) const {
switch (axis) {
case Qt::ZAxis:
return QwtInterval(z_min, z_max);
case Qt::XAxis:
return QwtInterval(x_min, x_max);
case Qt::YAxis:
return QwtInterval(y_min, y_max);
default:
return QwtInterval(z_min, z_max);
};
};
};
virtual double value(double x, double y) const {
// if(!interp){ //default is box like plot
int index =
int((x - x_min) / x_width) + int((y - y_min) / y_width) * nx;
if (index < 0 || index > nb)
index = nb;
if (!interp)
return data[index];
//}
int x_int = int((x - x_min) / x_width - 0.5);
if (x_int < 0)
x_int = 0;
else if (x_int > nx - 2)
x_int = nx - 2;
int y_int = int((y - y_min) / y_width - 0.5);
if (y_int < 0)
y_int = 0;
else if (y_int > ny - 2)
y_int = ny - 2;
int b00 = x_int * ny + y_int;
int b01 = x_int * ny + y_int + 1;
int b10 = (x_int + 1) * ny + y_int;
int b11 = (x_int + 1) * ny + y_int + 1;
virtual double value(double x, double y) const{
//if(!interp){ //default is box like plot
int index = int((x-x_min)/x_width) + int((y-y_min)/y_width)*nx;
if(index<0||index>nb) index = nb;
if(!interp) return data[index];
//}
// vertical extrap
double y0 = y_min + (y_int + 0.5) * y_width;
double y1 = y_min + (y_int + 1.5) * y_width;
double left_v = value_between_points(y0, data[b00], y1, data[b01], y);
double right_v = value_between_points(y0, data[b10], y1, data[b11], y);
// horazontal extrap
int x_int = int((x-x_min)/x_width-0.5);
if(x_int<0) x_int = 0; else if(x_int>nx-2) x_int = nx-2;
int y_int = int((y-y_min)/y_width-0.5);
if(y_int<0) y_int = 0; else if(y_int>ny-2) y_int = ny-2;
return 0.5;
int b00 = x_int*ny + y_int;
int b01 = x_int*ny + y_int+1;
int b10 = (x_int+1)*ny + y_int;
int b11 = (x_int+1)*ny + y_int+1;
//vertical extrap
double y0 = y_min+(y_int+0.5)*y_width;
double y1 = y_min+(y_int+1.5)*y_width;
double left_v = value_between_points(y0,data[b00],y1,data[b01],y);
double right_v = value_between_points(y0,data[b10],y1,data[b11],y);
//horazontal extrap
return 0.5;
return value_between_points(x_min+(x_int+0.5)*x_width,left_v,
x_min+(x_int+1.5)*x_width,right_v,x);
}
return value_between_points(x_min + (x_int + 0.5) * x_width, left_v,
x_min + (x_int + 1.5) * x_width, right_v,
x);
}
};
#endif

105
slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlot.h Executable file → Normal file
View File

@ -1,93 +1,92 @@
#pragma once
#include <qwt_plot.h>
#include <qlist.h>
#include <qwt_plot.h>
#include <qwt_plot_spectrogram.h>
#include "SlsQt2DZoomer.h"
#include "SlsQt2DHist.h"
#include "SlsQt2DHist.h"
#include "SlsQt2DZoomer.h"
class QwtPlotPanner;
class QwtScaleWidget;
class QwtLinearColorMap;
class QwtPlotPanner;
class QwtScaleWidget;
class QwtLinearColorMap;
class SlsQt2DPlot: public QwtPlot{
class SlsQt2DPlot : public QwtPlot {
Q_OBJECT
public:
public:
SlsQt2DPlot(QWidget * = NULL);
~SlsQt2DPlot();
void SetTitle(QString title);
void SetXTitle(QString title);
void SetYTitle(QString title);
void SetZTitle(QString title);
void SetTitleFont(const QFont& f);
void SetXFont(const QFont& f);
void SetYFont(const QFont& f);
void SetZFont(const QFont& f);
void SetTitleFont(const QFont &f);
void SetXFont(const QFont &f);
void SetYFont(const QFont &f);
void SetZFont(const QFont &f);
void UnZoom(bool replot=true);
void SetZoom(double xmin,double ymin,double x_width,double y_width);
void UnZoom(bool replot = true);
void SetZoom(double xmin, double ymin, double x_width, double y_width);
void DisableZoom(bool disable);
void EnableXAutoScaling() {setAxisAutoScale(QwtPlot::xBottom, true);};
void EnableYAutoScaling() {setAxisAutoScale(QwtPlot::yLeft, true);};
void SetXMinMax(double min,double max){setAxisScale(QwtPlot::xBottom,min,max);};
void SetYMinMax(double min,double max){setAxisScale(QwtPlot::yLeft,min,max);};
double GetXMinimum(){return hist->GetXMin();};
double GetXMaximum(){return hist->GetXMax();};
double GetYMinimum(){return hist->GetYMin();};
double GetYMaximum(){return hist->GetYMax();};
double GetZMinimum(){ return hist->GetMinimum();}
double GetZMaximum(){ return hist->GetMaximum();}
void SetZMinMax(double zmin=0,double zmax=-1);
void SetZMinimumToFirstGreaterThanZero(){hist->SetMinimumToFirstGreaterThanZero();}
double GetZMean() { return hist->GetMean();}
void EnableXAutoScaling() { setAxisAutoScale(QwtPlot::xBottom, true); };
void EnableYAutoScaling() { setAxisAutoScale(QwtPlot::yLeft, true); };
void SetXMinMax(double min, double max) {
setAxisScale(QwtPlot::xBottom, min, max);
};
void SetYMinMax(double min, double max) {
setAxisScale(QwtPlot::yLeft, min, max);
};
double GetXMinimum() { return hist->GetXMin(); };
double GetXMaximum() { return hist->GetXMax(); };
double GetYMinimum() { return hist->GetYMin(); };
double GetYMaximum() { return hist->GetYMax(); };
double GetZMinimum() { return hist->GetMinimum(); }
double GetZMaximum() { return hist->GetMaximum(); }
void SetZMinMax(double zmin = 0, double zmax = -1);
void SetZMinimumToFirstGreaterThanZero() {
hist->SetMinimumToFirstGreaterThanZero();
}
double GetZMean() { return hist->GetMean(); }
void SetData(int nbinsx, double xmin, double xmax, int nbinsy,double ymin, double ymax,double *d,double zmin=0, double zmax=-1){
hist->SetData(nbinsx,xmin,xmax,nbinsy,ymin,ymax,d,zmin,zmax);
void SetData(int nbinsx, double xmin, double xmax, int nbinsy, double ymin,
double ymax, double *d, double zmin = 0, double zmax = -1) {
hist->SetData(nbinsx, xmin, xmax, nbinsy, ymin, ymax, d, zmin, zmax);
}
double* GetDataPtr() {return hist->GetDataPtr();}
int GetBinIndex(int bx,int by) {return hist->GetBinIndex(bx,by);}
int FindBinIndex(double x,double y) {return hist->FindBinIndex(x,y);}
void SetBinValue(int bx,int by,double v) { hist->SetBinValue(bx,by,v);}
double GetBinValue(int bx,int by) {return hist->GetBinValue(bx,by);}
void FillTestPlot(int i=0);
double *GetDataPtr() { return hist->GetDataPtr(); }
int GetBinIndex(int bx, int by) { return hist->GetBinIndex(bx, by); }
int FindBinIndex(double x, double y) { return hist->FindBinIndex(x, y); }
void SetBinValue(int bx, int by, double v) { hist->SetBinValue(bx, by, v); }
double GetBinValue(int bx, int by) { return hist->GetBinValue(bx, by); }
void FillTestPlot(int i = 0);
void Update();
void SetInterpolate(bool enable);
void SetContour(bool enable);
void SetLogz(bool enable, bool isMin, bool isMax, double min, double max);
void SetZRange(bool isMin, bool isMax, double min, double max);
void LogZ(bool on=1);
void LogZ(bool on = 1);
public slots:
public slots:
void showSpectrogram(bool on);
private:
private:
void SetupZoom();
void SetupColorMap();
QwtLinearColorMap* myColourMap(QVector<double> colourStops);
QwtLinearColorMap* myColourMap(int log=0);
QwtLinearColorMap *myColourMap(QVector<double> colourStops);
QwtLinearColorMap *myColourMap(int log = 0);
QwtPlotSpectrogram *d_spectrogram{nullptr};
SlsQt2DHist* hist{nullptr};
SlsQt2DZoomer* zoomer{nullptr};
QwtPlotPanner* panner{nullptr};
SlsQt2DHist *hist{nullptr};
SlsQt2DZoomer *zoomer{nullptr};
QwtPlotPanner *panner{nullptr};
QwtScaleWidget *rightAxis{nullptr};
QwtLinearColorMap* colorMapLinearScale{nullptr};
QwtLinearColorMap* colorMapLogScale{nullptr};
QwtLinearColorMap *colorMapLinearScale{nullptr};
QwtLinearColorMap *colorMapLogScale{nullptr};
QList<double> contourLevelsLinear;
QList<double> contourLevelsLog;
bool disableZoom{false};
int isLog;
};

View File

@ -5,60 +5,50 @@
* Dhanya-05.12.2012- included an additional header
*/
#ifndef SLSQT2DZOOMER_H
#define SLSQT2DZOOMER_H
/**included by Dhanya on 05.12.2012 to avoid compile time errors with the latest gcc*/
/**included by Dhanya on 05.12.2012 to avoid compile time errors with the latest
* gcc*/
#include <cstdio>
/**end of Change by Dhanya*/
#include <qwt_plot_zoomer.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_zoomer.h>
#include "SlsQt2DHist.h"
class SlsQt2DZoomer:public QwtPlotZoomer{
private:
SlsQt2DHist* hist;
public:
SlsQt2DZoomer(QWidget *canvas):QwtPlotZoomer(canvas){
setTrackerMode(AlwaysOn);
}
void SetHist(SlsQt2DHist* h){
hist=h;
}
virtual QwtText trackerTextF(const QPointF &pos) const{
QColor bg(Qt::white);
bg.setAlpha(200);
//QwtText text = QwtPlotZoomer::trackerText(pos);
static QwtText text;
if(hist){
static char t[200];
sprintf(t,"%3.2f, %3.2f, %3.2f",pos.x(),pos.y(),hist->value(pos.x(),pos.y()));
text.setText(t);
}else {
QPoint p=pos.toPoint();
QwtText text = QwtPlotZoomer::trackerText(p);
class SlsQt2DZoomer : public QwtPlotZoomer {
private:
SlsQt2DHist *hist;
public:
SlsQt2DZoomer(QWidget *canvas) : QwtPlotZoomer(canvas) {
setTrackerMode(AlwaysOn);
}
void SetHist(SlsQt2DHist *h) { hist = h; }
virtual QwtText trackerTextF(const QPointF &pos) const {
QColor bg(Qt::white);
bg.setAlpha(200);
// QwtText text = QwtPlotZoomer::trackerText(pos);
static QwtText text;
if (hist) {
static char t[200];
sprintf(t, "%3.2f, %3.2f, %3.2f", pos.x(), pos.y(),
hist->value(pos.x(), pos.y()));
text.setText(t);
} else {
QPoint p = pos.toPoint();
QwtText text = QwtPlotZoomer::trackerText(p);
}
text.setBackgroundBrush(QBrush(bg));
return text;
}
text.setBackgroundBrush( QBrush( bg ));
return text;
}
};
#endif

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) {