00001 #include "MultiScaleDetectorPlotWidget.h" 00002 00003 #include "MultiScaleDetectorPlotWidget.moc" 00004 00005 #include <iostream> 00006 00007 MultiScaleDetectorPlotWidget::MultiScaleDetectorPlotWidget(QWidget* parent, unsigned int _scales): 00008 QWidget(parent), 00009 m_scales(_scales) 00010 { 00011 m_plotLayout = new QGridLayout(this); 00012 m_smooth = new QwtPlot(QwtText("Smoothed signal"), this); 00013 m_derivative = new QwtPlot(QwtText("Differential operator"), this); 00014 m_smoothZoomer = new QwtPlotZoomer(m_smooth->canvas()); 00015 m_diffZoomer = new QwtPlotZoomer(m_derivative->canvas()); 00016 00017 buildGui(); 00018 initCurves(); 00019 00020 } 00021 00022 MultiScaleDetectorPlotWidget::~MultiScaleDetectorPlotWidget() { 00023 delete m_plotLayout; 00024 delete m_smooth; 00025 delete m_derivative; 00026 delete m_smoothZoomer; 00027 delete m_diffZoomer; 00028 for(unsigned int i = 0; i < m_scales; i ++){ 00029 delete m_smoothCurve[i]; 00030 delete m_smoothMarker[i]; 00031 delete m_diffCurve[i]; 00032 delete m_diffMarker[i]; 00033 } 00034 } 00035 00036 void MultiScaleDetectorPlotWidget::buildGui(){ 00037 m_plotLayout->setSpacing(3); 00038 m_plotLayout->setMargin(3); 00039 m_plotLayout->addWidget(m_smooth,0,0); 00040 m_plotLayout->addWidget(m_derivative,0,1); 00041 setMaximumHeight(256); 00042 setMinimumHeight(256); 00043 00044 m_smoothZoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier); 00045 m_smoothZoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton); 00046 m_diffZoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier); 00047 m_diffZoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton); 00048 00049 m_smooth->plotLayout()->setAlignCanvasToScales(true); 00050 m_derivative->plotLayout()->setAlignCanvasToScales(true); 00051 00052 } 00053 00054 void MultiScaleDetectorPlotWidget::initCurves(){ 00055 for(int i = 0; i < m_smoothCurve.size(); i ++){ 00056 delete m_smoothCurve[i]; 00057 delete m_smoothMarker[i]; 00058 delete m_diffCurve[i]; 00059 delete m_diffMarker[i]; 00060 } 00061 m_smoothCurve.resize(m_scales); 00062 m_smoothMarker.resize(m_scales); 00063 m_diffCurve.resize(m_scales); 00064 m_diffMarker.resize(m_scales); 00065 m_colors.resize(m_scales); 00066 QColor colors[12] = {Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::yellow, Qt::magenta, 00067 Qt::darkRed, Qt::darkGreen, Qt::darkBlue, Qt::darkCyan, Qt::darkYellow, Qt::darkMagenta}; 00068 for(unsigned int i = 0; i < m_scales; i ++){ 00069 m_colors[i] = colors[i%12]; 00070 QwtSymbol symbol(QwtSymbol::Ellipse, QBrush(), QPen(m_colors[i]),QSize(10,10)); 00071 m_smoothCurve[i] = new QwtPlotCurve(); 00072 m_smoothCurve[i]->setStyle(QwtPlotCurve::Lines); 00073 m_smoothCurve[i]->setPen(QPen(m_colors[i])); 00074 m_smoothCurve[i]->attach(m_smooth); 00075 m_smoothMarker[i] = new QwtPlotCurve(); 00076 m_smoothMarker[i]->setStyle(QwtPlotCurve::NoCurve); 00077 m_smoothMarker[i]->setSymbol(symbol); 00078 m_smoothMarker[i]->attach(m_smooth); 00079 m_diffCurve[i] = new QwtPlotCurve(); 00080 m_diffCurve[i]->setStyle(QwtPlotCurve::Lines); 00081 m_diffCurve[i]->setPen(QPen(m_colors[i])); 00082 m_diffCurve[i]->attach(m_derivative); 00083 m_diffMarker[i] = new QwtPlotCurve(); 00084 m_diffMarker[i]->setStyle(QwtPlotCurve::NoCurve); 00085 m_diffMarker[i]->setSymbol(symbol); 00086 m_diffMarker[i]->attach(m_derivative); 00087 } 00088 } 00089 00090 void MultiScaleDetectorPlotWidget::setSmoothData(QVector<double>& _dataX, QVector<double>& _dataY, unsigned int _scale){ 00091 setData(m_smoothCurve, _dataX, _dataY, _scale); 00092 } 00093 00094 void MultiScaleDetectorPlotWidget::setSmoothData(QVector< QVector<double> >& _dataX, QVector< QVector<double> >& _dataY){ 00095 setData(m_smoothCurve, _dataX, _dataY); 00096 } 00097 00098 void MultiScaleDetectorPlotWidget::setDifferentialData(QVector<double>& _dataX, QVector<double>& _dataY, unsigned int _scale){ 00099 setData(m_diffCurve, _dataX, _dataY, _scale); 00100 } 00101 00102 void MultiScaleDetectorPlotWidget::setDifferentialData(QVector< QVector<double> >& _dataX, QVector< QVector<double> >& _dataY){ 00103 setData(m_diffCurve, _dataX, _dataY); 00104 } 00105 00106 void MultiScaleDetectorPlotWidget::setSmoothMarker(QVector<double>& _dataX, QVector<double>& _dataY, unsigned int _scale){ 00107 setData(m_smoothMarker, _dataX, _dataY, _scale); 00108 } 00109 00110 void MultiScaleDetectorPlotWidget::setSmoothMarker(QVector< QVector<double> >& _dataX, QVector< QVector<double> >& _dataY){ 00111 setData(m_smoothMarker, _dataX, _dataY); 00112 } 00113 00114 void MultiScaleDetectorPlotWidget::setDifferentialMarker(QVector<double>& _dataX, QVector<double>& _dataY, unsigned int _scale){ 00115 setData(m_diffMarker, _dataX, _dataY, _scale); 00116 } 00117 00118 void MultiScaleDetectorPlotWidget::setDifferentialMarker(QVector< QVector<double> >& _dataX, QVector< QVector<double> >& _dataY){ 00119 setData(m_diffMarker, _dataX, _dataY); 00120 } 00121 00122 void MultiScaleDetectorPlotWidget::setData(QVector<QwtPlotCurve *>& _curve, QVector<double>& _dataX, QVector<double>& _dataY, unsigned int _scale){ 00123 if(_scale < m_scales){ 00124 _curve[_scale]->setData(_dataX, _dataY); 00125 } 00126 } 00127 00128 void MultiScaleDetectorPlotWidget::setData(QVector<QwtPlotCurve *>& _curve, QVector< QVector<double> >& _dataX, QVector< QVector<double> >& _dataY){ 00129 if(_dataX.size() != _dataY.size()) return; 00130 if(_dataX.size() != (int) m_scales) setScales(_dataX.size()); 00131 for(unsigned int i = 0; i < m_scales; i++){ 00132 setData(_curve, _dataX[i], _dataY[i], i); 00133 } 00134 } 00135 00136 void MultiScaleDetectorPlotWidget::replot(){ 00137 m_smooth->setAxisAutoScale(0); 00138 m_derivative->setAxisAutoScale(0); 00139 m_smooth->setAxisAutoScale(2); 00140 m_derivative->setAxisAutoScale(2); 00141 m_smooth->replot(); 00142 m_derivative->replot(); 00143 m_smoothZoomer->setZoomBase(); 00144 m_diffZoomer->setZoomBase(); 00145 } 00146