Changeset 3145 in Sophya for trunk/SophyaPI/PIext/pihisto2d.cc
- Timestamp:
- Jan 18, 2007, 5:33:46 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/pihisto2d.cc
r3075 r3145 3 3 #include <pisysdep.h> 4 4 #include PIAPP_H 5 6 #include <iostream> 7 #include <math.h> 8 5 9 #include "sopnamsp.h" 6 10 #include "pihisto2d.h" … … 9 13 static int dbg = 0; 10 14 15 16 //------ Implementation classe P2DHistoWrapper 17 P2DHistoWrapper::P2DHistoWrapper(int_4 asx, int_4 asy) 18 : P2DArrayAdapter(asx, asy) , 19 mScale(1.) , mOff(0.) , mRetFg(0) 20 { 21 } 22 23 P2DHistoWrapper::~P2DHistoWrapper() 24 { 25 } 26 27 int P2DHistoWrapper::GetStatInfoAsText(vector<string> & /* text */ ) 28 { 29 return 0; 30 } 31 32 int P2DHistoWrapper::DecodeOptionString(vector<string> & opt, bool rmdecopt) 33 { 34 if(opt.size() < 1) return(0); 35 36 vector<string> udopt; // On gardera ici les options non decodees 37 unsigned int k = 0; 38 int ndec = opt.size(); 39 for( k=0; k<opt.size(); k++ ) { 40 string & opts = opt[k]; 41 if(opts.substr(0,7) == "hs1") { 42 mScale = 1.; mOff = 0.; 43 } 44 else if(opts.substr(0,7) == "hscale=") { 45 mScale = atof(opts.substr(7).c_str()); 46 } 47 else if(opts.substr(0,8) == "hoffset=") { 48 mOff = atof(opts.substr(8).c_str()); 49 } 50 else if(opts.substr(0,8) == "hbincont") { 51 mRetFg = 0; 52 } 53 else if(opts.substr(0,8) == "hbinerr") { 54 mRetFg = 1; 55 } 56 else if(opts.substr(0,8) == "hbinent") { 57 mRetFg = 2; 58 } 59 else { 60 ndec--; 61 // S'il faut supprimer les options decodees 62 if (rmdecopt) udopt.push_back(opts); 63 } 64 } 65 // S'il faut supprimer les options decodees, on remplace l'argument opt 66 // par le vecteur des options non decodees. 67 if (rmdecopt) opt = udopt; 68 return(ndec); 69 } 70 71 int 72 P2DHistoWrapper::OptionToString(vector<string> & opt) const 73 { 74 char buff[64]; 75 sprintf(buff, "hscale=%g", mScale); opt.push_back(buff); 76 sprintf(buff, "hoffset=%g", mOff); opt.push_back(buff); 77 if (mRetFg == 2) opt.push_back("hbinent"); 78 else if (mRetFg == 1) opt.push_back("hbinerr"); 79 else opt.push_back("hbincont"); 80 81 return 1; 82 } 83 11 84 //++ 12 85 // Class PIHisto2D … … 28 101 29 102 //++ 30 PIHisto2D::PIHisto2D( Histo2D* histo, bool ad)103 PIHisto2D::PIHisto2D(P2DHistoWrapper* histowp, bool ad) 31 104 // 32 105 // Createur d'une classe de dessin pour l'histogramme 2D histo. 33 106 //-- 34 : PIDrawer(), mHisto (histo), mAdDO(ad), mLogScale(10.), mFPoints(0.5)35 { 36 // mAdDO : Flag pour suppression automatique de mHisto 107 : PIDrawer(), mHistoWp(histowp), mAdDO(ad), mLogScale(10.), mFPoints(0.5) 108 { 109 // mAdDO : Flag pour suppression automatique de mHistoWp 37 110 // Attention: mFPoints n'est initialise que si on display par nuages de points 38 111 // mLogScale n'est initialise que si on utilise une echelle log … … 43 116 UseFrac(); 44 117 SetStats(); 45 118 SetStatPosOffset(); 46 119 SetName("Histo2DDrw"); 47 120 // PIHisto2D has specific control tools … … 62 135 // ---> parametre d'appel PIBaseWdgGen* wdg=NULL 63 136 DeactivateControlWindow(NULL); 64 if(mAdDO && mHisto !=NULL) delete mHisto;137 if(mAdDO && mHistoWp!=NULL) delete mHistoWp; 65 138 } 66 139 … … 139 212 140 213 //++ 141 void PIHisto2D::UseDyn(float hmin,float hmax)214 void PIHisto2D::UseDyn(float fmin,float fmax) 142 215 // 143 216 // Gestion de la dynamique a representer: … … 151 224 //-- 152 225 { 153 if(mHisto) 154 if(hmin>=hmax) {hmin = mHisto->VMin(); hmax = mHisto->VMax();} 155 if(hmin>=hmax) hmax = hmin+1.; 156 mHMin = hmin; mHMax = hmax; 226 if( (mHistoWp) && (mHistoWp->NBinX()>0) && (mHistoWp->NBinY()>0) && (fmin>=fmax) ) { 227 double v,hmin,hmax; 228 hmin = hmax = (*mHistoWp)(0,0); 229 for (int_4 i=0; i<mHistoWp->NBinX(); i++) 230 for (int_4 j=0; j<mHistoWp->NBinY(); j++) { 231 v = (*mHistoWp)(i, j); 232 if(v<hmin) hmin = v; 233 if(v>hmax) hmax = v; 234 } 235 fmin = hmin; fmax = hmax; // $CHECK$ CMV : attention, double vers float !! 236 } 237 238 // $CHECK$ CMV : Ne faut-il pas passer les attributs de la classe en double ?? 239 if(fmin>=fmax) fmax = fmin+1.; 240 mHMin = fmin; mHMax = fmax; 157 241 } 158 242 … … 189 273 ,(int)mFgCol,(int)mCmap,(int)mRevCmap,mTypScal,mTypDisp,mFPoints); 190 274 printf(" Dyn=%g,%g Frac=%g,%g LogSc=%g H=%p\n" 191 ,mHMin,mHMax,mFracMin,mFracMax,mLogScale,mHisto );192 if(lp>=1) mHisto->PrintStatus(); 275 ,mHMin,mHMax,mFracMin,mFracMax,mLogScale,mHistoWp); 276 // if(lp>=1) mHistoWp->PrintStatus(); $CHECK$ CMV : que faut-il faire ? 193 277 fflush(stdout); 194 278 } … … 201 285 //-- 202 286 { 203 if(!mHisto ) return;204 SetLimits(mHisto ->XMin(), mHisto->XMax(), mHisto->YMin() , mHisto->YMax());287 if(!mHistoWp) return; 288 SetLimits(mHistoWp->XMin(), mHistoWp->XMax(), mHistoWp->YMin() , mHistoWp->YMax()); 205 289 } 206 290 … … 259 343 if (axesFlags != kAxesNone) DrawAxes(g); 260 344 261 if(!mHisto ) return;262 if(mHisto ->NBinX()<=0 || mHisto->NBinY()<=0) return;345 if(!mHistoWp) return; 346 if(mHistoWp->NBinX()<=0 || mHistoWp->NBinY()<=0) return; 263 347 264 348 // Caracteristiques histogramme 265 double dx = mHisto ->WBinX(),dy = mHisto->WBinY();349 double dx = mHistoWp->WBinX(),dy = mHistoWp->WBinY(); 266 350 double p1dx,p1dy; 267 351 g->DGrC2UC(1.,1.,p1dx,p1dy); … … 309 393 310 394 // Plot de l'histogramme 311 for(int i=0; i<mHisto ->NBinX(); i++)312 for(int j=0; j<mHisto ->NBinY(); j++) {395 for(int i=0; i<mHistoWp->NBinX(); i++) 396 for(int j=0; j<mHistoWp->NBinY(); j++) { 313 397 314 398 r_8 left0,bottom0; 315 mHisto ->BinLowEdge(i,j,left0,bottom0);399 mHistoWp->BinLowEdge(i,j,left0,bottom0); 316 400 317 401 // Gestion de la dynamique a dessiner 318 float frac = ((*mHisto )(i,j)-HMin())/(HMax()-HMin());402 float frac = ((*mHistoWp)(i,j)-HMin())/(HMax()-HMin()); 319 403 if(frac<0.) continue; 320 404 if(mTypScal==1) { // echelle log10 … … 385 469 //-- 386 470 { 387 Histo2D* h = Histogram();471 P2DHistoWrapper* h = HistoWrapper(); 388 472 if(h == NULL) return; 389 473 390 int i,j; 391 h->FindBin(x,y,i,j); 474 int_4 i,j; 475 i = floor((x-h->XMin())/h->WBinX()); 476 j = floor((y-h->YMin())/h->WBinY()); 477 392 478 if(i>=0 && i<h->NBinX() && j>=0 && j<h->NBinY()) { 393 479 char str[64]; 394 480 if(fgdiff) { 395 481 int i0,j0; 396 h->FindBin(x0,y0,i0,j0); 482 i0 = floor((x0-h->XMin())/h->WBinX()); 483 j0 = floor((y0-h->YMin())/h->WBinY()); 397 484 if(i0>=0 && i0<h->NBinX() && j0>=0 && j0<h->NBinY()) { 398 485 sprintf(str," DV=%g",(*h)(i,j)-(*h)(i0,j0)); … … 417 504 //-- 418 505 { 419 if (!mHisto ) return;506 if (!mHistoWp) return; 420 507 if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt) g->SelLine(PI_ThinLine); 421 508 g->SelFontSz((YMax() - YMin())/30); … … 424 511 PIGrCoord a, d; 425 512 double cH = (double)g->GetFontHeight(a,d); 426 double cellHeight = 1.2 * cH; 427 428 // Les labels et leurs longueurs -> largeur de la cellule 429 char label[64]; 430 sprintf(label,"N= %-g", mHisto->NData()); 431 double cellWidth = 1.1 * (double)g->CalcStringWidth(label); 513 vector<string> lines; 514 int nlig = mHistoWp->GetStatInfoAsText(lines); 515 if (nlig < 1) return; 516 517 double cellHeight = nlig*1.2 * cH; 518 519 int idxll = 0; 520 521 int kl; 522 // on recherche la ligne la plus longue 523 for(kl=1; kl<nlig; kl++) 524 if ( lines[kl].length() > lines[idxll].length() ) idxll = kl; 525 526 double cellWidth = 1.1 * (double)g->CalcStringWidth(lines[idxll].c_str()); 527 432 528 433 529 double ofpx = spoX*(XMax()-XMin()); … … 446 542 cw = (g->isAxeXDirRtoL()) ? -0.05*cellWidth : -0.95*cellWidth; 447 543 xu = g->DeltaUCX(XMax(),cw); 448 cw = (g->isAxeYDirUpDown()) ? -0.1*cH : -1.1*cH; 544 545 cw = (g->isAxeYDirUpDown()) ? -0.15*cH : -1.15*cH; 449 546 yu = g->DeltaUCY(YMax(),cw); 450 547 xu += ofpx; yu += ofpy; 451 g->DrawString(xu,yu,label); 548 549 for(kl=0; kl<nlig; kl++) { 550 g->DrawString(xu, yu, lines[kl].c_str() ); 551 cw += -1.15*cH; 552 yu = g->DeltaUCY(YMax(),cw); yu += ofpy; 553 } 554 452 555 453 556 // printf("H[%d,%d] Dynamique: [%g,%g] Frac [%g,%g]\n" 454 // ,mHisto ->NBinX(),mHisto->NBinY(),HMin(),HMax(),FMin(),FMax());557 // ,mHistoWp->NBinX(),mHistoWp->NBinY(),HMin(),HMax(),FMin(),FMax()); 455 558 } 456 559 … … 489 592 //-- 490 593 { 491 double dx = mHisto ->WBinX(),dy = mHisto->WBinY();594 double dx = mHistoWp->WBinX(),dy = mHistoWp->WBinY(); 492 595 double dxg,dyg; 493 596 g->DUC2GrC(dx,dy,dxg,dyg); … … 573 676 if (rmdecopt) opt = udopt; 574 677 678 // Decodage des options par le histo-wrapper 679 int ndec2 = 0; 680 if ( ( optsz1-ndec1-ndec > 0) && (mHistoWp) ) { 681 ndec2 = mHistoWp->DecodeOptionString(opt, rmdecopt); 682 } 683 575 684 // Liste des options si demande 576 685 if(listopt) Print(); 577 686 578 return(ndec+ndec1 );687 return(ndec+ndec1+ndec2); 579 688 } 580 689 … … 607 716 if(mRevCmap) opt.push_back("revcmap"); 608 717 718 // Les options du Histo2DWrapper : 719 mHistoWp->OptionToString(opt); 609 720 return 1; 610 721 } … … 630 741 info += "- h2scale=lin/log[,logscale]: choose linear or logarithmic scale\n"; 631 742 info += "- h2dyn=[hmin][,hmax]: choose histogramme range for display\n"; 632 info += "- use g eneral keyto define color table (ex: grey32,midas_heat,...)\n";743 info += "- use graphic att. to define color table (ex: grey32,midas_heat,...)\n"; 633 744 info += " (see general graphicatt description)\n"; 634 info += "- use key\"revcmap\" to reverse color table\n";745 info += "- use \"revcmap\" to reverse color table\n"; 635 746 info += "- h2frac=[fmin][,fmax]: choose sub-range display [0,1]\n"; 747 info += " ---- HistoWrapper options : \n" ; 748 info += " hbincont: select bin content as Y value for display (default) \n"; 749 info += " hbinerr: select bin error as Y value for display \n"; 750 info += " hbinent: select bin entries as Y value for display \n"; 751 info += " hscale=value : multiplicative factor for Y value \n" ; 752 info += " hoffset=value : additive coefficient for Y value \n" ; 753 info += " hs1: set hscale=1 hoffset=0 (default) \n" ; 636 754 // On recupere ensuite la chaine info de la classe de base 637 755 PIDrawer::GetOptionsHelpInfo(info);
Note:
See TracChangeset
for help on using the changeset viewer.