Changeset 3135 in Sophya for trunk/SophyaPI/PIext/pihisto.cc
- Timestamp:
- Jan 12, 2007, 7:36:32 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/pihisto.cc
r3132 r3135 41 41 mScale = atof(opts.substr(7).c_str()); 42 42 } 43 else if(opt [k].substr(0,8) == "hoffset=") {43 else if(opts.substr(0,8) == "hoffset=") { 44 44 mOff = atof(opts.substr(8).c_str()); 45 45 } … … 72 72 //-- 73 73 //++ 74 // PIHisto(P1DHistoWrapper* histo , bool ad=false)75 // Constructeur. Si "ad == true", l'objet "histo " est détruit par74 // PIHisto(P1DHistoWrapper* histowp, bool ad=false) 75 // Constructeur. Si "ad == true", l'objet "histowp" est détruit par 76 76 // le destructeur de l'objet "PIHisto" 77 // Note : "histo " doit être créé par new77 // Note : "histowp" doit être créé par new 78 78 // 79 // void SetStats(bool fg=true)80 // Active/ désactive l'indication des statistiques d'histogramme81 79 //-- 82 80 83 81 84 PIHisto::PIHisto(P1DHistoWrapper* histo, bool ad) 85 : PIDrawer(), mHisto(histo) 86 { 87 mAdDO = ad; // Flag pour suppression automatique de mHisto 88 SetStats(); 89 SetError(); 90 SetFilled(); 91 SetStatPosOffset(); 82 PIHisto::PIHisto(P1DHistoWrapper* histowp, bool ad) 83 : PIDrawer(), mHistoWp(histowp) 84 { 85 mAdDO = ad; // Flag pour suppression automatique de mHistoWp 86 stats=true; 87 // todraw = 0 draw scaled and offset value (default) 88 // = 1 draw bin content 89 // = 2 draw bin error (if exist) 90 // = 3 draw number of entries in the bin (if exist) 91 todraw=0; 92 // error = -1 pas de barre d'erreur 93 // 1 barres d'erreurs, 94 // 0 barres d'erreurs automatiques (si markeur demande) 95 error=0; 96 filled=false; 97 spoX=-0.01; spoY=-0.01; 92 98 SetName("HistoDrw"); 93 99 } … … 95 101 PIHisto::~PIHisto() 96 102 { 97 if(mAdDO) delete mHisto ;103 if(mAdDO) delete mHistoWp; 98 104 } 99 105 … … 101 107 PIHisto::UpdateLimits() 102 108 { 103 if (!mHisto ) return;104 double v 1,v2,hmin,hmax;109 if (!mHistoWp) return; 110 double v,hmin,hmax; 105 111 hmin = 9.e39; 106 112 hmax = -9.e39; 107 for (int i=1; i<mHisto->NBins(); i++) { 108 v1 = (*mHisto)(i); //DEL - mHisto->Error(i); 109 v2 = (*mHisto)(i); //DEL + mHisto->Error(i); 110 if(v1<hmin) hmin = v1; 111 if(v2>hmax) hmax = v2; 113 for (int i=1; i<mHistoWp->NBins(); i++) { 114 v = DrawVal(i); 115 if(v<hmin) hmin = v; 116 if(v>hmax) hmax = v; 112 117 } 113 118 // REZA$CHECK : Modifier pour tenir compte si axe (Y) en log 114 v 1= 0.1*(hmax-hmin);115 hmin -= v 1; hmax += v1;119 v = 0.1*(hmax-hmin); 120 hmin -= v; hmax += v; 116 121 117 122 if(hmax<=hmin) hmax = hmin+1.; 118 SetLimits(mHisto ->XMin(), mHisto->XMax(), hmin, hmax);123 SetLimits(mHistoWp->XMin(), mHistoWp->XMax(), hmin, hmax); 119 124 } 120 125 … … 124 129 if (axesFlags != kAxesNone) DrawAxes(g); 125 130 126 if (!mHisto ) return;127 if (mHisto ->NBins()<=0) return;131 if (!mHistoWp) return; 132 if (mHistoWp->NBins()<=0) return; 128 133 129 mHisto ->Update();134 mHistoWp->Update(); 130 135 131 136 bool oktrace=false; … … 136 141 bool drawmarker=false; 137 142 if (GetGraphicAtt().GetMarker() != PI_NotDefMarker) drawmarker = true; 138 //RZDEL || (typeid(*mHisto) == typeid(HProf)) ) drawmarker = true;139 143 // Tracer des erreurs ? 140 144 bool drawerr=false; 141 145 if(error==0) { // Gestion automatique des erreurs 142 //RZDEL Tracer les erreurs si HProf143 //RZDEL if( typeid(*mHisto)==typeid(HProf) ) drawerr=true;144 146 // Trace les erreurs si marqueurs demandes 145 147 if(drawmarker) drawerr=true; … … 156 158 if(drawfill) { 157 159 oktrace = true; 158 for(int i=0; i<mHisto ->NBins(); i++) {159 double left = mHisto ->BinLowEdge(i);160 double width = mHisto ->BinWidth();160 for(int i=0; i<mHistoWp->NBins(); i++) { 161 double left = mHistoWp->BinLowEdge(i); 162 double width = mHistoWp->BinWidth(); 161 163 double bottom = 0; 162 double height = (*mHisto)(i);164 double height = DrawVal(i); 163 165 g->DrawFBox(left,bottom,width,height); 164 166 } … … 168 170 if(drawmarker) { 169 171 double x1,y1; oktrace = true; 170 for(int i=0; i<mHisto ->NBins(); i++) {171 x1 = mHisto ->BinCenter(i);172 y1 = (*mHisto)(i);172 for(int i=0; i<mHistoWp->NBins(); i++) { 173 x1 = mHistoWp->BinCenter(i); 174 y1 = DrawVal(i); 173 175 g->DrawMarker(x1,y1); 174 176 } … … 179 181 if(GetGraphicAtt().GetLineAtt()==PI_NotDefLineAtt) g->SelLine(PI_ThinLine); 180 182 double x1,x2,y1,y2; oktrace = true; 181 double bw = mHisto ->BinWidth();182 for(int i=0; i<mHisto ->NBins(); i++) {183 if(mHisto ->Error(i)>0.) {183 double bw = mHistoWp->BinWidth(); 184 for(int i=0; i<mHistoWp->NBins(); i++) { 185 if(mHistoWp->Error(i)>0.) { 184 186 // barres d'erreur verticales 185 x1 = x2 = mHisto ->BinCenter(i);186 y1 = (*mHisto)(i) - mHisto->Error(i);187 y2 = (*mHisto)(i) + mHisto->Error(i);187 x1 = x2 = mHistoWp->BinCenter(i); 188 y1 = DrawVal(i) - mHistoWp->Error(i); 189 y2 = DrawVal(i) + mHistoWp->Error(i); 188 190 g->DrawLine(x1,y1, x1, y2); 189 191 // limites de barres d'erreurs (horizontales) … … 197 199 // Trace de la ligne continue si demandee 198 200 if(drawpline) { 199 PIGrCoord* x1 = new PIGrCoord[2*mHisto ->NBins()+2];200 PIGrCoord* y1 = new PIGrCoord[2*mHisto ->NBins()+2];201 double dx = mHisto ->BinWidth();201 PIGrCoord* x1 = new PIGrCoord[2*mHistoWp->NBins()+2]; 202 PIGrCoord* y1 = new PIGrCoord[2*mHistoWp->NBins()+2]; 203 double dx = mHistoWp->BinWidth(); 202 204 int npt=0; 203 x1[npt] = mHisto ->BinLowEdge(0);205 x1[npt] = mHistoWp->BinLowEdge(0); 204 206 y1[npt] = 0; 205 207 npt++; 206 for(int i=0; i<mHisto ->NBins(); i++) {207 x1[npt] = mHisto ->BinLowEdge(i);208 y1[npt] = (*mHisto)(i);208 for(int i=0; i<mHistoWp->NBins(); i++) { 209 x1[npt] = mHistoWp->BinLowEdge(i); 210 y1[npt] = DrawVal(i); 209 211 npt++; 210 212 x1[npt] = (double)x1[npt-1] + dx; … … 238 240 for( k=0; k<opt.size(); k++ ) { 239 241 string opts = opt[k]; 240 if(opts=="sta" || opts=="stat" || opts=="stats") SetStats(true);242 if(opts=="sta" || opts=="stat" || opts=="stats") stats=true; 241 243 else if( opts=="nsta" || opts=="nstat" 242 || opts=="nostat" || opts=="nostats") SetStats(false);243 else if(opts=="err") SetError(1);244 else if(opts=="noerr" || opts=="nerr") SetError(-1);245 else if(opts=="autoerr") SetError(0);246 else if(opts=="fill") SetFilled(true);247 else if(opts=="nofill" || opts=="nfill") SetFilled(false);244 || opts=="nostat" || opts=="nostats") stats=false; 245 else if(opts=="err") error=1; 246 else if(opts=="noerr" || opts=="nerr") error=-1; 247 else if(opts=="autoerr") error=0; 248 else if(opts=="fill") filled=true; 249 else if(opts=="nofill" || opts=="nfill") filled=false; 248 250 else if(opts.substr(0,11) == "statposoff=") { 249 251 float xo=0., yo=0.; 250 252 sscanf(opts.substr(11).c_str(),"%g,%g",&xo, &yo); 251 SetStatPosOffset(xo, yo); 252 } 253 spoX=xo; spoY=yo; 254 } 255 else if(opts.substr(0,6) == "draw=v") todraw = 1; 256 else if(opts.substr(0,6) == "draw=e") todraw = 2; 257 else if(opts.substr(0,6) == "draw=n") todraw = 3; 258 else if(opts.substr(0,5) == "draw=" ) todraw = 0; 253 259 else { 254 260 ndec--; … … 264 270 // Decodage des options par le histo-wrapper 265 271 int ndec2 = 0; 266 if ( ( optsz1-ndec1-ndec > 0) && (mHisto ) ) {267 ndec2 = mHisto ->DecodeOptionString(opt, rmdecopt);272 if ( ( optsz1-ndec1-ndec > 0) && (mHistoWp) ) { 273 ndec2 = mHistoWp->DecodeOptionString(opt, rmdecopt); 268 274 } 269 275 return(ndec+ndec1+ndec2); … … 280 286 else if(error==1) opt.push_back("err"); 281 287 if(filled) opt.push_back("fill"); else opt.push_back("nofill"); 288 if(todraw==1) opt.push_back("draw=v"); 289 else if(todraw==2) opt.push_back("draw=e"); 290 else if(todraw==3) opt.push_back("draw=n"); 282 291 283 292 char str[256]; sprintf(str,"statposoff=%g,%g",spoX,spoY); … … 291 300 { 292 301 info += " ---- PIHisto options help info : \n" ; 302 info += " draw=v: draw bin content\n"; 303 info += " =e: draw bin error (if exist)\n"; 304 info += " =n: draw number of entries in the bin (if exist)\n"; 305 info += " default: draw scaled and offset value (default)"; 293 306 info += " sta,stat,stats: activate statistic display\n"; 294 307 info += " nsta,nstat,nostat,nostats: deactivate statistic display\n"; 295 308 info += " err / noerr,nerr : draw, do not draw error bars\n"; 296 info += " autoerr : draw error bars if Marker drawing requested OR Profile histo\n";309 info += " autoerr : draw error bars if Marker drawing requested\n"; 297 310 info += " fill / nofill,nfill : fill, do not fill bars with selected color\n"; 298 311 info += " statposoff=OffsetX,OffsetY : Position offset for Stats drawing \n"; … … 310 323 PIHisto::DrawStats(PIGraphicUC* g) 311 324 { 312 if (!mHisto ) return;325 if (!mHistoWp) return; 313 326 // if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine); 314 327 g->SelLine(PI_ThinLine); … … 319 332 double cH = (double)g->GetFontHeight(a,d); 320 333 vector<string> lines; 321 int nlig = mHisto ->GetStatInfoAsText(lines);334 int nlig = mHistoWp->GetStatInfoAsText(lines); 322 335 if (nlig < 1) return; 323 336 … … 361 374 } 362 375 363 364 365 376 /* --Methode-- */ 366 double PIHisto::GetDistanceToPoint(double x, double y) 367 { 368 if (!mHisto) return 1.e+9; 377 double 378 PIHisto::GetDistanceToPoint(double x, double y) 379 { 380 if (!mHistoWp) return 1.e+9; 369 381 370 382 double dist = -1.e+18; 371 for(int i=0; i<mHisto ->NBins(); i++) {372 double xp=mHisto ->BinCenter(i);373 double yp= (*mHisto)(i);383 for(int i=0; i<mHistoWp->NBins(); i++) { 384 double xp=mHistoWp->BinCenter(i); 385 double yp=DrawVal(i); 374 386 xp = (xp-x)/(XMax()-XMin())/0.5; 375 387 yp = (yp-y)/(YMax()-YMin())/0.5; … … 379 391 dist=sqrt(fabs(dist)); 380 392 //cout<<dist<<"PIHisto: xlim="<<XMin()<<","<<XMax()<<" ylim="<<YMin()<<","<<YMax() 381 // <<" NBins="<<mHisto ->NBins()<<endl;393 // <<" NBins="<<mHistoWp->NBins()<<endl; 382 394 //cout<<"....d="<<dist<<" x="<<x<<" y="<<y<<endl; 383 395
Note:
See TracChangeset
for help on using the changeset viewer.