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
This commit is contained in:
l_maliakal_d
2013-08-29 15:15:24 +00:00
parent 88f0b089b4
commit e6c94a1d62
2 changed files with 95 additions and 67 deletions

View File

@ -566,7 +566,7 @@ QwtPlotHistogram *plotHistogram;
QVector<QwtIntervalSample> histogramSamples; QVector<QwtIntervalSample> histogramSamples;
bool firstPlot;
signals: signals:
void UpdatingPlotFinished(); void UpdatingPlotFinished();

View File

@ -201,15 +201,18 @@ void qDrawPlot::SetupWidgetWindow(){
histFrom = 0; histFrom = 0;
histTo = 0; histTo = 0;
histSize = 0; histSize = 0;
/*
grid = new QwtPlotGrid; grid = new QwtPlotGrid;
grid->enableXMin(true); grid->enableXMin(true);
grid->enableYMin(true); grid->enableYMin(true);
grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine)); grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
*/
plotHistogram = new QwtPlotHistogram(); plotHistogram = new QwtPlotHistogram();
plotHistogram->setStyle(QwtPlotHistogram::Columns); plotHistogram->setStyle(QwtPlotHistogram::Columns);
firstPlot = false;
//widget related initialization //widget related initialization
@ -480,20 +483,18 @@ bool qDrawPlot::StartOrStopThread(bool start){
//sets up the measurement parameters //sets up the measurement parameters
SetupMeasurement(); SetupMeasurement();
//refixing all the min and max for all scans //refixing all the zooming
if (scanArgument == qDefs::None);
else{
plot2D->GetPlot()->SetXMinMax(-0.5,nPixelsX+0.5); plot2D->GetPlot()->SetXMinMax(-0.5,nPixelsX+0.5);
plot2D->GetPlot()->SetYMinMax(startPixel,endPixel); plot2D->GetPlot()->SetYMinMax(startPixel,endPixel);
plot2D->GetPlot()->SetZoom(-0.5,startPixel,nPixelsX,endPixel-startPixel); plot2D->GetPlot()->SetZoom(-0.5,startPixel,nPixelsX,endPixel-startPixel);
plot2D->GetPlot()->UnZoom(); plot2D->GetPlot()->UnZoom();
}
cout << "Starting new acquisition thread ...." << endl; cout << "Starting new acquisition thread ...." << endl;
// Start acquiring data from server // Start acquiring data from server
if(!firstTime) pthread_join(gui_acquisition_thread,NULL);//wait until he's finished, ie. exits if(!firstTime) pthread_join(gui_acquisition_thread,NULL);//wait until he's finished, ie. exits
pthread_create(&gui_acquisition_thread, NULL,DataStartAcquireThread, (void*) this); 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 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 is manually done instead of keeping track of thread because
// this thread returns immediately after executing the acquire command // 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 plotHistogram->setBrush(QBrush(Qt::red,Qt::Dense4Pattern));//Qt::SolidPattern
histFrameIndexTitle->setText(GetHistTitle(0)); histFrameIndexTitle->setText(GetHistTitle(0));
plotHistogram->attach(plot1D); plotHistogram->attach(plot1D);
plot1D->SetZoomBase(plotHistogram->boundingRect().left(),0, //refixing all the zooming
plotHistogram->boundingRect().width(),plotHistogram->boundingRect().height()); plot1D->SetXMinMax(histFrom,histTo);
plot1D->SetYMinMax(0,plotHistogram->boundingRect().height());
plot1D->SetZoomBase(0,0,nPixelsX,plotHistogram->boundingRect().height());
} }
//not histogram //not histogram
else{ else{
@ -1262,8 +1265,15 @@ void qDrawPlot::UpdatePlot(){
histFrameIndexTitle->setText(GetHistTitle(0)); histFrameIndexTitle->setText(GetHistTitle(0));
//h->setTitle(GetHistTitle(hist_num)); //h->setTitle(GetHistTitle(hist_num));
h->Attach(plot1D); 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 // update range if required
if(XYRangeChanged){ if(XYRangeChanged){
@ -1273,6 +1283,9 @@ void qDrawPlot::UpdatePlot(){
if(!IsXYRange[qDefs::YMAXIMUM]) XYRangeValues[qDefs::YMAXIMUM]= plot1D->GetYMaximum(); if(!IsXYRange[qDefs::YMAXIMUM]) XYRangeValues[qDefs::YMAXIMUM]= plot1D->GetYMaximum();
plot1D->SetXMinMax(XYRangeValues[qDefs::XMINIMUM],XYRangeValues[qDefs::XMAXIMUM]); plot1D->SetXMinMax(XYRangeValues[qDefs::XMINIMUM],XYRangeValues[qDefs::XMAXIMUM]);
plot1D->SetYMinMax(XYRangeValues[qDefs::YMINIMUM],XYRangeValues[qDefs::YMAXIMUM]); plot1D->SetYMinMax(XYRangeValues[qDefs::YMINIMUM],XYRangeValues[qDefs::YMAXIMUM]);
//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; XYRangeChanged = false;
} }
//Display Statistics //Display Statistics
@ -1631,12 +1644,14 @@ void qDrawPlot::DisableZoom(bool disable){
int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){
int ret,i,actualPixelsX; int ret,i,actualPixelsX;
//double *temp=0,*trimXAxis=0,*trimYAxis=0; double min=0,max=0,sum=0;
#ifdef VERBOSE #ifdef VERBOSE
if(fromDetector) cout << "Geting Trimbits from Detector" << endl; if(fromDetector) cout << "Geting Trimbits from Detector" << endl;
else cout << "Getting Trimbits from Shared Memory" << endl; else cout << "Getting Trimbits from Shared Memory" << endl;
#endif #endif
LockLastImageArray();
slsDetectorDefs::detectorType detType = myDet->getDetectorsType(); slsDetectorDefs::detectorType detType = myDet->getDetectorsType();
if(detType == slsDetectorDefs::MYTHEN){ if(detType == slsDetectorDefs::MYTHEN){
@ -1646,6 +1661,7 @@ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){
ret = myDet->getChanRegs(histTrimbits,fromDetector); ret = myDet->getChanRegs(histTrimbits,fromDetector);
if(!ret){ if(!ret){
qDefs::Message(qDefs::WARNING,"No Trimbit data found in shared memory.","qDrawPlot::UpdateTrimbitPlot"); qDefs::Message(qDefs::WARNING,"No Trimbit data found in shared memory.","qDrawPlot::UpdateTrimbitPlot");
UnlockLastImageArray();
return qDefs::FAIL; return qDefs::FAIL;
} }
#ifdef VERBOSE #ifdef VERBOSE
@ -1654,23 +1670,30 @@ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){
qDefs::checkErrorMessage(myDet,"qDrawPlot::UpdateTrimbitPlot"); qDefs::checkErrorMessage(myDet,"qDrawPlot::UpdateTrimbitPlot");
//defining axes //clear/select plot and set titles
if(Histogram) nPixelsX = TRIM_HISTOGRAM_XMAX+1; Select1DPlot();
else nPixelsX = actualPixelsX; Clear1DPlot();
//Display Statistics
if(displayStatistics){
GetStatistics(min,max,sum,histTrimbits,actualPixelsX);
lblMinDisp->setText(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(histXAxis) delete [] histXAxis; histXAxis = new double [nPixelsX];
if(histYAxis[0]) delete [] histYAxis[0]; histYAxis[0]= new double [nPixelsX]; if(histYAxis[0]) delete [] histYAxis[0]; histYAxis[0]= new double [nPixelsX];
//initializing //initializing
for(unsigned int px=0;px<(int)nPixelsX;px++) histXAxis[px] = px; for(unsigned int px=0;px<(int)nPixelsX;px++) histXAxis[px] = px;
for(i=0;i<nPixelsX;i++) histYAxis[0][i] = 0; for(i=0;i<nPixelsX;i++) histYAxis[0][i] = 0;
//clear/select plot and set titles
Clear1DPlot();
Select1DPlot();
if(!Histogram){
cout << "Data Graph:" << nPixelsX << endl;
//data //data
memcpy(histYAxis[0],histTrimbits,nPixelsX*sizeof(double)); memcpy(histYAxis[0],histTrimbits,nPixelsX*sizeof(double));
//title //title
@ -1678,59 +1701,59 @@ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){
plot1D->SetXTitle("Channel Number"); plot1D->SetXTitle("Channel Number");
plot1D->SetYTitle("Trimbits"); plot1D->SetYTitle("Trimbits");
//set plot parameters //set plot parameters
plot1D->SetXMinMax(0,nPixelsX);
plot1D->SetZoomBase(0,0,nPixelsX,plotHistogram->boundingRect().height());
SlsQtH1D* h; SlsQtH1D* h;
plot1D_hists.append(h=new SlsQtH1D("",nPixelsX,histXAxis,histYAxis[0])); plot1D_hists.append(h=new SlsQtH1D("",nPixelsX,histXAxis,histYAxis[0]));
h->SetLineColor(1); h->SetLineColor(1);
h->setTitle(GetHistTitle(0)); histFrameIndexTitle->setText(GetHistTitle(0));
//attach plot //attach plot
h->Attach(plot1D); 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{ else{
cout << "Histogram: " << nPixelsX-1 << endl; cout << "Histogram: " << TRIM_HISTOGRAM_XMAX << endl;
//data
int value =0; //create intervals
histogramSamples.resize(TRIM_HISTOGRAM_XMAX+1);
for(i=0; i<TRIM_HISTOGRAM_XMAX+1; i++){
histogramSamples[i].interval.setInterval(i,i+1);
histogramSamples[i].value = 0;
}
//fill histogram values
int value = 0;
for(i=0;i<actualPixelsX;i++){ for(i=0;i<actualPixelsX;i++){
if((histTrimbits[i]<nPixelsX)&&(histTrimbits[i]>=0)){ if( (histTrimbits[i] <= TRIM_HISTOGRAM_XMAX) && (histTrimbits[i] >= 0)){//if(histogramSamples[j].interval.contains(data->values[i]))
value = (int) histTrimbits[i]; value = (int) histTrimbits[i];
histYAxis[0][value]++; histogramSamples[value].value += 1;
} }
else cout<<"OUT OF BOUNDS:"<<i<<"-"<<histTrimbits[i]<<endl; else cout<<"OUT OF BOUNDS:"<<i<<"-"<<histTrimbits[i]<<endl;
} }
/* for(i=0;i<TRIM_HISTOGRAM_XMAX;i++)
if((histYAxis[0][i]<=TRIM_HISTOGRAM_XMAX)&&(histYAxis[0][i]>0))
cout<<"HIsty["<<i<<"]:"<<histYAxis[0][i]<<endl;*/
//delete [] histTrimbits; //plot
//title
boxPlot->setTitle("Trimbits_Plot_Histogram"); boxPlot->setTitle("Trimbits_Plot_Histogram");
plot1D->SetXTitle("Trimbits"); plot1D->SetXTitle("Trimbits");
plot1D->SetYTitle("Frequency"); plot1D->SetYTitle("Frequency");
//set plot parameters plotHistogram->setData(new QwtIntervalSeriesData(histogramSamples));
SlsQtH1D* h; plotHistogram->setPen(QPen(Qt::red));
plot1D_hists.append(h=new SlsQtH1D("",nPixelsX,histXAxis,histYAxis[0])); plotHistogram->setBrush(QBrush(Qt::red,Qt::Dense4Pattern));//Qt::SolidPattern
h->SetLineColor(1); histFrameIndexTitle->setText(GetHistTitle(0));
h->setTitle(GetHistTitle(0)); plotHistogram->attach(plot1D);
//attach plot //refixing all the zooming
h->Attach(plot1D); 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 /**needs to be changed */
cout << "Trimbits Plot updated" << endl;
#endif
}
else if(detType == slsDetectorDefs::EIGER){ else if(detType == slsDetectorDefs::EIGER){
//defining axes //defining axes
@ -1745,6 +1768,7 @@ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){
ret = 1;/*myDet->getChanRegs(lastImageArray,fromDetector);*/ ret = 1;/*myDet->getChanRegs(lastImageArray,fromDetector);*/
if(!ret){ if(!ret){
qDefs::Message(qDefs::WARNING,"No Trimbit data found in shared memory.","qDrawPlot::UpdateTrimbitPlot"); qDefs::Message(qDefs::WARNING,"No Trimbit data found in shared memory.","qDrawPlot::UpdateTrimbitPlot");
UnlockLastImageArray();
return qDefs::FAIL; return qDefs::FAIL;
} }
//clear/select plot and set titles //clear/select plot and set titles
@ -1758,17 +1782,21 @@ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Trimbits Plot updated" << endl; cout << "Trimbits Plot updated" << endl;
#endif #endif
}
//Display Statistics //Display Statistics
if(displayStatistics){ if(displayStatistics){
double min=0,max=0,sum=0;
GetStatistics(min,max,sum,lastImageArray,nPixelsX*nPixelsY); GetStatistics(min,max,sum,lastImageArray,nPixelsX*nPixelsY);
lblMinDisp->setText(QString("%1").arg(min)); lblMinDisp->setText(QString("%1").arg(min));
lblMaxDisp->setText(QString("%1").arg(max)); lblMaxDisp->setText(QString("%1").arg(max));
lblSumDisp->setText(QString("%1").arg(sum)); lblSumDisp->setText(QString("%1").arg(sum));
} }
}
UnlockLastImageArray();
#ifdef VERBOSE
cout << "Trimbits Plot updated" << endl;
#endif
return qDefs::OK; return qDefs::OK;
} }