From e6c94a1d622a8c5720e0322fc42b70e7d8722a98 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Thu, 29 Aug 2013 15:15:24 +0000 Subject: [PATCH] fixed the zooming problems for 2d git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@233 af1100a4-978c-4157-bff7-07162d2ba061 --- slsDetectorGui/include/qDrawPlot.h | 2 +- slsDetectorGui/src/qDrawPlot.cpp | 160 +++++++++++++++++------------ 2 files changed, 95 insertions(+), 67 deletions(-) diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index 4f2459f64..a5e35316e 100644 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -566,7 +566,7 @@ QwtPlotHistogram *plotHistogram; QVector histogramSamples; - +bool firstPlot; signals: void UpdatingPlotFinished(); diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index c8482dd44..d4b0bb466 100644 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -201,15 +201,18 @@ void qDrawPlot::SetupWidgetWindow(){ histFrom = 0; histTo = 0; histSize = 0; + /* grid = new QwtPlotGrid; grid->enableXMin(true); grid->enableYMin(true); grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine)); grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); + */ plotHistogram = new QwtPlotHistogram(); plotHistogram->setStyle(QwtPlotHistogram::Columns); + firstPlot = false; //widget related initialization @@ -480,20 +483,18 @@ bool qDrawPlot::StartOrStopThread(bool start){ //sets up the measurement parameters SetupMeasurement(); - //refixing all the min and max for all scans - if (scanArgument == qDefs::None); - else{ - plot2D->GetPlot()->SetXMinMax(-0.5,nPixelsX+0.5); - plot2D->GetPlot()->SetYMinMax(startPixel,endPixel); - plot2D->GetPlot()->SetZoom(-0.5,startPixel,nPixelsX,endPixel-startPixel); - plot2D->GetPlot()->UnZoom(); - } + //refixing all the zooming + plot2D->GetPlot()->SetXMinMax(-0.5,nPixelsX+0.5); + plot2D->GetPlot()->SetYMinMax(startPixel,endPixel); + plot2D->GetPlot()->SetZoom(-0.5,startPixel,nPixelsX,endPixel-startPixel); + plot2D->GetPlot()->UnZoom(); + cout << "Starting new acquisition thread ...." << endl; // Start acquiring data from server if(!firstTime) pthread_join(gui_acquisition_thread,NULL);//wait until he's finished, ie. exits pthread_create(&gui_acquisition_thread, NULL,DataStartAcquireThread, (void*) this); - firstTime = false; + firstPlot = true; // This is set here and later reset to zero when all the plotting is done // This is manually done instead of keeping track of thread because // this thread returns immediately after executing the acquire command @@ -1238,8 +1239,10 @@ void qDrawPlot::UpdatePlot(){ plotHistogram->setBrush(QBrush(Qt::red,Qt::Dense4Pattern));//Qt::SolidPattern histFrameIndexTitle->setText(GetHistTitle(0)); plotHistogram->attach(plot1D); - plot1D->SetZoomBase(plotHistogram->boundingRect().left(),0, - plotHistogram->boundingRect().width(),plotHistogram->boundingRect().height()); + //refixing all the zooming + plot1D->SetXMinMax(histFrom,histTo); + plot1D->SetYMinMax(0,plotHistogram->boundingRect().height()); + plot1D->SetZoomBase(0,0,nPixelsX,plotHistogram->boundingRect().height()); } //not histogram else{ @@ -1262,8 +1265,15 @@ void qDrawPlot::UpdatePlot(){ histFrameIndexTitle->setText(GetHistTitle(0)); //h->setTitle(GetHistTitle(hist_num)); h->Attach(plot1D); + //refixing all the zooming + if(firstPlot){ + plot1D->SetXMinMax(h->minXValue(),h->maxXValue()); + plot1D->SetYMinMax(h->minYValue(),h->maxYValue()); + plot1D->SetZoomBase(h->minXValue(),h->minYValue(), + h->maxXValue()-h->minXValue(),h->maxYValue()-h->minYValue()); + firstPlot = false; + } } - plot1D->Update(); } // update range if required if(XYRangeChanged){ @@ -1273,7 +1283,10 @@ void qDrawPlot::UpdatePlot(){ if(!IsXYRange[qDefs::YMAXIMUM]) XYRangeValues[qDefs::YMAXIMUM]= plot1D->GetYMaximum(); plot1D->SetXMinMax(XYRangeValues[qDefs::XMINIMUM],XYRangeValues[qDefs::XMAXIMUM]); plot1D->SetYMinMax(XYRangeValues[qDefs::YMINIMUM],XYRangeValues[qDefs::YMAXIMUM]); - XYRangeChanged = false; + //Should not be reset for histogram, + //that is the only way to zoom in (new plots are zoomed out as its different each time) + if(!histogram) + XYRangeChanged = false; } //Display Statistics if(displayStatistics){ @@ -1631,12 +1644,14 @@ void qDrawPlot::DisableZoom(bool disable){ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){ int ret,i,actualPixelsX; - //double *temp=0,*trimXAxis=0,*trimYAxis=0; + double min=0,max=0,sum=0; #ifdef VERBOSE if(fromDetector) cout << "Geting Trimbits from Detector" << endl; else cout << "Getting Trimbits from Shared Memory" << endl; #endif + LockLastImageArray(); + slsDetectorDefs::detectorType detType = myDet->getDetectorsType(); if(detType == slsDetectorDefs::MYTHEN){ @@ -1646,6 +1661,7 @@ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){ ret = myDet->getChanRegs(histTrimbits,fromDetector); if(!ret){ qDefs::Message(qDefs::WARNING,"No Trimbit data found in shared memory.","qDrawPlot::UpdateTrimbitPlot"); + UnlockLastImageArray(); return qDefs::FAIL; } #ifdef VERBOSE @@ -1654,23 +1670,30 @@ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){ qDefs::checkErrorMessage(myDet,"qDrawPlot::UpdateTrimbitPlot"); - //defining axes - if(Histogram) nPixelsX = TRIM_HISTOGRAM_XMAX+1; - else nPixelsX = actualPixelsX; - - if(histXAxis) delete [] histXAxis; histXAxis = new double [nPixelsX]; - if(histYAxis[0]) delete [] histYAxis[0]; histYAxis[0]= new double [nPixelsX]; - //initializing - for(unsigned int px=0;px<(int)nPixelsX;px++) histXAxis[px] = px; - for(i=0;isetText(QString("%1").arg(min)); + lblMaxDisp->setText(QString("%1").arg(max)); + lblSumDisp->setText(QString("%1").arg(sum)); + } if(!Histogram){ cout << "Data Graph:" << nPixelsX << endl; + + //initialize + nPixelsX = actualPixelsX; + if(histXAxis) delete [] histXAxis; histXAxis = new double [nPixelsX]; + if(histYAxis[0]) delete [] histYAxis[0]; histYAxis[0]= new double [nPixelsX]; + //initializing + for(unsigned int px=0;px<(int)nPixelsX;px++) histXAxis[px] = px; + for(i=0;iSetXTitle("Channel Number"); plot1D->SetYTitle("Trimbits"); //set plot parameters + plot1D->SetXMinMax(0,nPixelsX); + plot1D->SetZoomBase(0,0,nPixelsX,plotHistogram->boundingRect().height()); SlsQtH1D* h; plot1D_hists.append(h=new SlsQtH1D("",nPixelsX,histXAxis,histYAxis[0])); h->SetLineColor(1); - h->setTitle(GetHistTitle(0)); + histFrameIndexTitle->setText(GetHistTitle(0)); //attach plot h->Attach(plot1D); + //refixing all the zooming + plot1D->SetXMinMax(h->minXValue(),h->maxXValue()); + plot1D->SetYMinMax(h->minYValue(),h->maxYValue()); + plot1D->SetZoomBase(h->minXValue(),h->minYValue(), + h->maxXValue()-h->minXValue(),h->maxYValue()-h->minYValue()); } else{ - cout << "Histogram: " << nPixelsX-1 << endl; - //data - int value =0; + cout << "Histogram: " << TRIM_HISTOGRAM_XMAX << endl; + + //create intervals + histogramSamples.resize(TRIM_HISTOGRAM_XMAX+1); + for(i=0; i=0)){ + if( (histTrimbits[i] <= TRIM_HISTOGRAM_XMAX) && (histTrimbits[i] >= 0)){//if(histogramSamples[j].interval.contains(data->values[i])) value = (int) histTrimbits[i]; - histYAxis[0][value]++; + histogramSamples[value].value += 1; } else cout<<"OUT OF BOUNDS:"<0)) - cout<<"HIsty["<setTitle("Trimbits_Plot_Histogram"); plot1D->SetXTitle("Trimbits"); plot1D->SetYTitle("Frequency"); - //set plot parameters - SlsQtH1D* h; - plot1D_hists.append(h=new SlsQtH1D("",nPixelsX,histXAxis,histYAxis[0])); - h->SetLineColor(1); - h->setTitle(GetHistTitle(0)); - //attach plot - h->Attach(plot1D); + plotHistogram->setData(new QwtIntervalSeriesData(histogramSamples)); + plotHistogram->setPen(QPen(Qt::red)); + plotHistogram->setBrush(QBrush(Qt::red,Qt::Dense4Pattern));//Qt::SolidPattern + histFrameIndexTitle->setText(GetHistTitle(0)); + plotHistogram->attach(plot1D); + //refixing all the zooming + plot1D->SetXMinMax(0,TRIM_HISTOGRAM_XMAX+1); + plot1D->SetYMinMax(0,plotHistogram->boundingRect().height()); + plot1D->SetZoomBase(0,0,actualPixelsX,plotHistogram->boundingRect().height()); } - //Display Statistics - if(displayStatistics){ - double min=0,max=0,sum=0; - GetStatistics(min,max,sum,histYAxis[0],nPixelsX); - lblMinDisp->setText(QString("%1").arg(min)); - lblMaxDisp->setText(QString("%1").arg(max)); - lblSumDisp->setText(QString("%1").arg(sum)); - } - - -#ifdef VERBOSE - cout << "Trimbits Plot updated" << endl; -#endif } - + /**needs to be changed */ else if(detType == slsDetectorDefs::EIGER){ //defining axes @@ -1745,6 +1768,7 @@ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){ ret = 1;/*myDet->getChanRegs(lastImageArray,fromDetector);*/ if(!ret){ qDefs::Message(qDefs::WARNING,"No Trimbit data found in shared memory.","qDrawPlot::UpdateTrimbitPlot"); + UnlockLastImageArray(); return qDefs::FAIL; } //clear/select plot and set titles @@ -1758,17 +1782,21 @@ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){ #ifdef VERBOSE cout << "Trimbits Plot updated" << endl; #endif - } - //Display Statistics - if(displayStatistics){ - double min=0,max=0,sum=0; - GetStatistics(min,max,sum,lastImageArray,nPixelsX*nPixelsY); - lblMinDisp->setText(QString("%1").arg(min)); - lblMaxDisp->setText(QString("%1").arg(max)); - lblSumDisp->setText(QString("%1").arg(sum)); + + //Display Statistics + if(displayStatistics){ + GetStatistics(min,max,sum,lastImageArray,nPixelsX*nPixelsY); + lblMinDisp->setText(QString("%1").arg(min)); + lblMaxDisp->setText(QString("%1").arg(max)); + lblSumDisp->setText(QString("%1").arg(sum)); + } + } - + UnlockLastImageArray(); +#ifdef VERBOSE + cout << "Trimbits Plot updated" << endl; +#endif return qDefs::OK; }