Changeset 3135 in Sophya for trunk/SophyaPI/PIext/pihisto.cc


Ignore:
Timestamp:
Jan 12, 2007, 7:36:32 PM (19 years ago)
Author:
cmv
Message:

suite du display des HistoErr avec Wrapper cmv 12/01/07

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/pihisto.cc

    r3132 r3135  
    4141      mScale = atof(opts.substr(7).c_str());
    4242    }
    43     else if(opt[k].substr(0,8) == "hoffset=") {
     43    else if(opts.substr(0,8) == "hoffset=") {
    4444      mOff = atof(opts.substr(8).c_str());
    4545    }
     
    7272//--
    7373//++
    74 // PIHisto(P1DHistoWrapper* histo, bool ad=false)
    75 //      Constructeur. Si "ad == true", l'objet "histo" est détruit par
     74// PIHisto(P1DHistoWrapper* histowp, bool ad=false)
     75//      Constructeur. Si "ad == true", l'objet "histowp" est détruit par
    7676//      le destructeur de l'objet "PIHisto"
    77 //      Note : "histo" doit être créé par new
     77//      Note : "histowp" doit être créé par new
    7878//
    79 // void  SetStats(bool fg=true)
    80 //      Active/ désactive l'indication des statistiques d'histogramme
    8179//--
    8280
    8381
    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();
     82PIHisto::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;
    9298  SetName("HistoDrw");
    9399}
     
    95101PIHisto::~PIHisto()
    96102{
    97   if(mAdDO) delete mHisto;
     103  if(mAdDO) delete mHistoWp;
    98104}
    99105
     
    101107PIHisto::UpdateLimits()
    102108{
    103   if (!mHisto)  return;
    104   double v1,v2,hmin,hmax;
     109  if (!mHistoWp)  return;
     110  double v,hmin,hmax;
    105111  hmin = 9.e39;
    106112  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;
    112117  }
    113118  // REZA$CHECK : Modifier pour tenir compte si axe (Y) en log
    114   v1 = 0.1*(hmax-hmin);
    115   hmin -= v1;   hmax += v1;
     119  v = 0.1*(hmax-hmin);
     120  hmin -= v;   hmax += v;
    116121
    117122  if(hmax<=hmin) hmax = hmin+1.;
    118   SetLimits(mHisto->XMin(), mHisto->XMax(), hmin, hmax);
     123  SetLimits(mHistoWp->XMin(), mHistoWp->XMax(), hmin, hmax);
    119124}
    120125
     
    124129  if (axesFlags != kAxesNone) DrawAxes(g);
    125130
    126   if (!mHisto)  return;
    127   if (mHisto->NBins()<=0) return;
     131  if (!mHistoWp)  return;
     132  if (mHistoWp->NBins()<=0) return;
    128133 
    129   mHisto->Update();
     134  mHistoWp->Update();
    130135
    131136  bool oktrace=false;
     
    136141  bool drawmarker=false;
    137142  if (GetGraphicAtt().GetMarker() != PI_NotDefMarker) drawmarker = true;
    138 //RZDEL   ||  (typeid(*mHisto) == typeid(HProf)) ) drawmarker = true;
    139143  // Tracer des erreurs ?
    140144  bool drawerr=false;
    141145  if(error==0) {  // Gestion automatique des erreurs
    142     //RZDEL  Tracer les erreurs si HProf
    143 //RZDEL    if( typeid(*mHisto)==typeid(HProf) ) drawerr=true;
    144146    // Trace les erreurs si marqueurs demandes
    145147    if(drawmarker) drawerr=true;
     
    156158  if(drawfill) {
    157159    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();
    161163      double bottom = 0;
    162       double height = (*mHisto)(i);
     164      double height = DrawVal(i);
    163165      g->DrawFBox(left,bottom,width,height);
    164166    }
     
    168170  if(drawmarker) {
    169171    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);
    173175      g->DrawMarker(x1,y1);
    174176    }
     
    179181    if(GetGraphicAtt().GetLineAtt()==PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
    180182    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.) {
    184186        // 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);
    188190        g->DrawLine(x1,y1, x1, y2);
    189191        // limites de barres d'erreurs (horizontales)
     
    197199  // Trace de la ligne continue si demandee
    198200  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();
    202204    int npt=0;
    203     x1[npt] = mHisto->BinLowEdge(0);
     205    x1[npt] = mHistoWp->BinLowEdge(0);
    204206    y1[npt] = 0;
    205207    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);
    209211      npt++;
    210212      x1[npt] = (double)x1[npt-1] + dx;
     
    238240  for( k=0; k<opt.size(); k++ ) {
    239241    string opts = opt[k];
    240     if(opts=="sta" || opts=="stat" || opts=="stats") SetStats(true);
     242    if(opts=="sta" || opts=="stat" || opts=="stats") stats=true;
    241243    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;
    248250    else if(opts.substr(0,11) == "statposoff=") {
    249251      float xo=0., yo=0.;
    250252      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;
    253259    else {
    254260      ndec--;
     
    264270  // Decodage des options par le histo-wrapper
    265271  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);
    268274  }
    269275  return(ndec+ndec1+ndec2);
     
    280286     else if(error==1) opt.push_back("err");
    281287 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");
    282291
    283292 char str[256]; sprintf(str,"statposoff=%g,%g",spoX,spoY);
     
    291300{
    292301info += " ---- PIHisto options help info : \n" ;
     302info += "  draw=v: draw bin content\n";
     303info += "      =e: draw bin error (if exist)\n";
     304info += "      =n: draw number of entries in the bin (if exist)\n";
     305info += "      default: draw scaled and offset value (default)";
    293306info += "  sta,stat,stats:            activate   statistic display\n";
    294307info += "  nsta,nstat,nostat,nostats: deactivate statistic display\n";
    295308info += "  err / noerr,nerr : draw, do not draw error bars\n";
    296 info += "  autoerr : draw error bars if Marker drawing requested OR Profile histo\n";
     309info += "  autoerr : draw error bars if Marker drawing requested\n";
    297310info += "  fill / nofill,nfill : fill, do not fill bars with selected color\n";
    298311info += "  statposoff=OffsetX,OffsetY : Position offset for Stats drawing \n";
     
    310323PIHisto::DrawStats(PIGraphicUC* g)
    311324{
    312   if (!mHisto) return;
     325  if (!mHistoWp) return;
    313326  //  if (mLAtt == PI_NotDefLineAtt)  g->SelLine(PI_ThinLine);
    314327  g->SelLine(PI_ThinLine);
     
    319332  double cH = (double)g->GetFontHeight(a,d);
    320333  vector<string> lines;
    321   int nlig = mHisto->GetStatInfoAsText(lines);
     334  int nlig = mHistoWp->GetStatInfoAsText(lines);
    322335  if (nlig < 1) return;
    323336
     
    361374}
    362375
    363 
    364 
    365376/* --Methode-- */
    366 double PIHisto::GetDistanceToPoint(double x, double y)
    367 {
    368  if (!mHisto) return 1.e+9;
     377double
     378PIHisto::GetDistanceToPoint(double x, double y)
     379{
     380 if (!mHistoWp) return 1.e+9;
    369381
    370382 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);
    374386   xp = (xp-x)/(XMax()-XMin())/0.5;
    375387   yp = (yp-y)/(YMax()-YMin())/0.5;
     
    379391 dist=sqrt(fabs(dist));
    380392 //cout<<dist<<"PIHisto: xlim="<<XMin()<<","<<XMax()<<" ylim="<<YMin()<<","<<YMax()
    381  //    <<" NBins="<<mHisto->NBins()<<endl;
     393 //    <<" NBins="<<mHistoWp->NBins()<<endl;
    382394 //cout<<"....d="<<dist<<" x="<<x<<" y="<<y<<endl;
    383395
Note: See TracChangeset for help on using the changeset viewer.