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


Ignore:
Timestamp:
Jan 18, 2007, 5:33:46 PM (19 years ago)
Author:
ansari
Message:

1/ Petites modifs ds PIHisto et le P1DHistoWrapper - en particulier decodage des options et choix renvoi BinContent/Error/NEntries
2/ Codage Wrapper pour Histo-2D et modifs PIHisto2D
3/ Suppression des adaptateurs de tableaux PI des Histos2D ds pipodrw.h .cc, les
Wrappers d'histos heritant de P1D,P2DArrayAdapter
4/ Mise a jour Makefile et smakefile

Reza , 18/01/2007

File:
1 edited

Legend:

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

    r3139 r3145  
    1212
    1313//------ Implementation classe P1DHistoWrapper
    14 P1DHistoWrapper::P1DHistoWrapper()
    15 : mScale(1.) , mOff(0.)
     14P1DHistoWrapper::P1DHistoWrapper(int_4 asx)
     15  :  P1DArrayAdapter(asx) ,
     16     mScale(1.) , mOff(0.) , mRetFg(0)
    1617{
    1718}
     
    4445      mOff = atof(opts.substr(8).c_str());
    4546    }
     47    else if(opts.substr(0,8) == "hbincont") {
     48      mRetFg = 0;
     49    }   
     50    else if(opts.substr(0,8) == "hbinerr") {
     51      mRetFg = 1;
     52    }   
     53    else if(opts.substr(0,8) == "hbinent") {
     54      mRetFg = 2;
     55    }   
    4656    else {
    4757      ndec--;
     
    5464  if (rmdecopt)  opt = udopt;
    5565  return(ndec);
     66}
     67
     68int
     69P1DHistoWrapper::OptionToString(vector<string> & opt) const
     70{
     71  char buff[64];
     72  sprintf(buff, "hscale=%g", mScale);  opt.push_back(buff);
     73  sprintf(buff, "hoffset=%g", mOff);  opt.push_back(buff);
     74  if (mRetFg == 2) opt.push_back("hbinent");
     75  else if (mRetFg == 1) opt.push_back("hbinerr");
     76  else opt.push_back("hbincont");
     77
     78  return 1;
    5679}
    5780
     
    7598//      Constructeur. Si "ad == true", l'objet "histowp" est détruit par
    7699//      le destructeur de l'objet "PIHisto"
    77 //      Note : "histowp" doit être créé par new
     100//      Note : "histowp" doit être créé par new si ad==true
    78101//
    79102//--
     
    85108  mAdDO = ad;     // Flag pour suppression automatique de mHistoWp
    86109  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;
     110  pline=true;
     111  error=false;
    96112  filled=false;
    97113  spoX=-0.01; spoY=-0.01;
     
    108124{
    109125  if (!mHistoWp)  return;
     126  if ( mHistoWp->NBins() < 1 ) {
     127    SetLimits(mHistoWp->XMin(), mHistoWp->XMax(), 0., 1.);
     128  }
    110129  double v,hmin,hmax;
    111   hmin = 9.e39;
    112   hmax = -9.e39;
    113   for (int i=1; i<mHistoWp->NBins(); i++) {
    114     v = DrawVal(i);
     130  hmin = hmax = (*mHistoWp)(0);
     131  for (int_4 i=1; i<mHistoWp->NBins(); i++) {
     132    v = (*mHistoWp)(i);
    115133    if(v<hmin) hmin = v;
    116134    if(v>hmax) hmax = v;
    117135  }
    118   // REZA$CHECK : Modifier pour tenir compte si axe (Y) en log
    119   v = 0.1*(hmax-hmin);
    120   hmin -= v;   hmax += v;
    121 
     136  if ( isLogScaleY() ) {
     137    if ( hmin >= 0.) {
     138      if ( hmax <= hmin ) {
     139        hmax = hmin*10.;
     140        if (hmax <= 0.) hmax = 1.;
     141        if (hmin <= 0.) hmin = hmax / 100.;
     142      }
     143      else if ( (hmin == 0.) && (hmax > hmin) ) hmin = hmax/1.e6;
     144      else hmin /= 1.1;
     145    }
     146    else if (hmax > 0.) hmax *= 1.1;
     147  }
     148  else {
     149      v = 0.05*(hmax-hmin);
     150      hmin -= v;   hmax += v;
     151  }
    122152  if(hmax<=hmin) hmax = hmin+1.;
     153   
    123154  SetLimits(mHistoWp->XMin(), mHistoWp->XMax(), hmin, hmax);
    124155}
     
    134165  mHistoWp->Update();
    135166
    136   bool oktrace=false;
    137167  // Tracer d'une polyline si demandee
    138168  bool drawpline=false;
    139   if(GetGraphicAtt().GetLineAtt() != PI_NotDefLineAtt) drawpline=true;
     169  if (pline) drawpline=true;
    140170  // Tracer des marqueurs si demande ou si HProf
    141171  bool drawmarker=false;
     
    143173  // Tracer des erreurs ?
    144174  bool drawerr=false;
    145   if(error==0) {  // Gestion automatique des erreurs
    146     // Trace les erreurs si marqueurs demandes
    147     if(drawmarker) drawerr=true;
    148   }
    149   else if(error>0) drawerr=true;
    150   else if(error<0) drawerr=false;
     175  if (error) drawerr = true;
    151176  // Fill de l'histo ?
    152177  bool drawfill=false;
    153178  if(filled) drawfill=true; else drawfill=false;
    154   // Et aussi si on ne demande ni ligne ni marqueur ?
    155   if( !drawmarker && !drawpline && !drawerr ) drawfill=true;
     179  // Et aussi si on ne demande ni ligne ni marqueur ni erreur ni fill ?
     180  if( !drawmarker && !drawfill && !drawerr ) drawpline=true;
    156181
    157182  // Remplissage des bins avec la couleur courante (trace en premier)
    158183  if(drawfill) {
    159     oktrace = true;
    160184    for(int i=0; i<mHistoWp->NBins(); i++) {
    161185      double left   = mHistoWp->BinLowEdge(i);
    162186      double width  = mHistoWp->BinWidth();
    163187      double bottom = 0;
    164       double height = DrawVal(i);
     188      double height = (*mHistoWp)(i);
    165189      g->DrawFBox(left,bottom,width,height);
    166190    }
     
    169193  // Trace des marqeurs
    170194  if(drawmarker) {
    171     double x1,y1; oktrace = true;
     195    double x1,y1;
    172196    for(int i=0; i<mHistoWp->NBins(); i++) {
    173197      x1 = mHistoWp->BinCenter(i);
    174       y1 = DrawVal(i);
     198      y1 = (*mHistoWp)(i);
    175199      g->DrawMarker(x1,y1);
    176200    }
     
    180204  if(drawerr) {
    181205    if(GetGraphicAtt().GetLineAtt()==PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
    182     double x1,x2,y1,y2;  oktrace = true;
     206    double x1,x2,y1,y2; 
    183207    double bw = mHistoWp->BinWidth();
    184208    for(int i=0; i<mHistoWp->NBins(); i++) {
     
    186210        // barres d'erreur verticales
    187211        x1 = x2 = mHistoWp->BinCenter(i);
    188         y1 = DrawVal(i) - mHistoWp->Error(i);
    189         y2 = DrawVal(i) + mHistoWp->Error(i);
     212        y1 = (*mHistoWp)(i) - mHistoWp->Error(i);
     213        y2 = (*mHistoWp)(i) + mHistoWp->Error(i);
    190214        g->DrawLine(x1,y1, x1, y2);
    191215        // limites de barres d'erreurs (horizontales)
     
    199223  // Trace de la ligne continue si demandee
    200224  if(drawpline) {
     225    if(GetGraphicAtt().GetLineAtt()==PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
    201226    PIGrCoord* x1 = new PIGrCoord[2*mHistoWp->NBins()+2];
    202227    PIGrCoord* y1 = new PIGrCoord[2*mHistoWp->NBins()+2];
     
    208233    for(int i=0; i<mHistoWp->NBins(); i++) {
    209234      x1[npt] = mHistoWp->BinLowEdge(i);
    210       y1[npt] = DrawVal(i);
     235      y1[npt] = (*mHistoWp)(i);
    211236      npt++;
    212237      x1[npt] = (double)x1[npt-1] + dx;
     
    219244    g->DrawPolygon(x1,y1,npt,false);
    220245    delete [] x1; delete [] y1;
    221     oktrace = true;
    222246  }
    223247
     
    243267    else if(  opts=="nsta"   || opts=="nstat"
    244268           || 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;
     269    else if(opts=="err") error=true;
     270    else if(opts=="noerr" || opts=="nerr") error=false;
     271    // $CHECK$CMV  : on desactive pline si fill ?
     272    else if(opts=="fill") { filled=true; pline=false; } 
    249273    else if(opts=="nofill" || opts=="nfill") filled=false;
     274    // $CHECK$CMV  : on desactive fill si pline ?
     275    else if(opts=="pline") { pline=true; filled=false; }
     276    else if(opts=="nopline") pline=false;
    250277    else if(opts.substr(0,11) == "statposoff=") {
    251278      float xo=0., yo=0.;
     
    253280      spoX=xo; spoY=yo;
    254281    }
    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;
    259282    else {
    260283      ndec--;
     
    281304 PIDrawer::OptionToString(opt);
    282305
    283  if(stats) opt.push_back("stat"); else opt.push_back("nstat");
    284  if(error==-1) opt.push_back("noerr");
    285    else if(error==0) opt.push_back("autoerr");
    286      else if(error==1) opt.push_back("err");
     306 if(stats) opt.push_back("stat"); else opt.push_back("nostat");
     307 if(error) opt.push_back("err");  else opt.push_back("noerr");
    287308 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");
     309 if(pline) opt.push_back("pline"); else opt.push_back("nopline");
    291310
    292311 char str[256]; sprintf(str,"statposoff=%g,%g",spoX,spoY);
    293312 opt.push_back(str);
    294313
     314 mHistoWp->OptionToString(opt);
    295315 return 1;
    296316}
     
    300320{
    301321info += " ---- 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)\n";
    306 info += "  sta,stat,stats:            activate   statistic display\n";
    307 info += "  nsta,nstat,nostat,nostats: deactivate statistic display\n";
    308 info += "  err / noerr,nerr : draw, do not draw error bars\n";
    309 info += "  autoerr : draw error bars if Marker drawing requested\n";
    310 info += "  fill / nofill,nfill : fill, do not fill bars with selected color\n";
    311 info += "  statposoff=OffsetX,OffsetY : Position offset for Stats drawing \n";
    312 info += "       as a fraction of total size \n";
     322info += " sta,stat,stats:            activate   statistic display\n";
     323info += " nsta,nstat,nostat,nostats: deactivate statistic display\n";
     324info += " pline/nopline: display/do not display as polyline (def= pline) \n";
     325info += " err/noerr,nerr: draw/do not draw error bars (def= noerr) \n";
     326info += " fill/nofill,nfill: fill/do not fill histo (def= nofill) \n";
     327info += " - Use marker attribute (marker=...) to draw markers \n";
     328info += " statposoff=OffsetX,OffsetY : Position offset for Stats drawing \n";
     329info += "      as a fraction of total size \n";
    313330info += " ---- HistoWrapper options : \n" ;
    314 info += "  hscale=value  : multiplicative factor (in Y) \n" ;
    315 info += "  hoffset=value : additive coefficient  (in Y) \n" ;
    316 info += "  hs1 : set hscale=1 hoffset=0  (default) \n" ;
     331info += " hbincont: select bin content as Y value for display (default) \n";
     332info += " hbinerr: select bin error as Y value for display \n";
     333info += " hbinent: select bin entries as Y value for display \n";
     334info += " hscale=value : multiplicative factor for Y value \n" ;
     335info += " hoffset=value : additive coefficient for Y value \n" ;
     336info += " hs1: set hscale=1 hoffset=0  (default) \n" ;
    317337// On recupere ensuite la chaine info de la classe de base
    318338PIDrawer::GetOptionsHelpInfo(info);
     
    335355  if (nlig < 1) return;
    336356
    337   double cellHeight = (nlig+0.6) * cH;
     357  double cellHeight = nlig*1.2 * cH;
    338358
    339359  int idxll = 0;
     
    383403 for(int i=0; i<mHistoWp->NBins(); i++) {
    384404   double xp=mHistoWp->BinCenter(i);
    385    double yp=DrawVal(i);
     405   double yp=(*mHistoWp)(i);
    386406   xp = (xp-x)/(XMax()-XMin())/0.5;
    387407   yp = (yp-y)/(YMax()-YMin())/0.5;
Note: See TracChangeset for help on using the changeset viewer.