Changeset 3145 in Sophya for trunk/SophyaPI/PIext/pihisto2d.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/pihisto2d.cc

    r3075 r3145  
    33#include <pisysdep.h>
    44#include PIAPP_H
     5
     6#include <iostream>
     7#include <math.h>
     8
    59#include "sopnamsp.h"
    610#include "pihisto2d.h"
     
    913static int dbg = 0;
    1014
     15
     16//------ Implementation classe P2DHistoWrapper
     17P2DHistoWrapper::P2DHistoWrapper(int_4 asx, int_4 asy)
     18  :  P2DArrayAdapter(asx, asy) ,
     19     mScale(1.) , mOff(0.) , mRetFg(0)
     20{
     21}
     22
     23P2DHistoWrapper::~P2DHistoWrapper()
     24{
     25}
     26
     27int P2DHistoWrapper::GetStatInfoAsText(vector<string> & /* text */ )
     28{
     29  return 0;
     30}
     31
     32int 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
     71int
     72P2DHistoWrapper::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
    1184//++
    1285// Class        PIHisto2D
     
    28101
    29102//++
    30 PIHisto2D::PIHisto2D(Histo2D* histo, bool ad)
     103PIHisto2D::PIHisto2D(P2DHistoWrapper* histowp, bool ad)
    31104//
    32105//      Createur d'une classe de dessin pour l'histogramme 2D histo.
    33106//--
    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
    37110// Attention: mFPoints n'est initialise que si on display par nuages de points
    38111//            mLogScale n'est initialise que si on utilise une echelle log
     
    43116UseFrac();
    44117SetStats();
    45  SetStatPosOffset();
     118SetStatPosOffset();
    46119SetName("Histo2DDrw");
    47120// PIHisto2D has specific control tools
     
    62135// ---> parametre d'appel PIBaseWdgGen* wdg=NULL
    63136DeactivateControlWindow(NULL);
    64 if(mAdDO && mHisto!=NULL) delete mHisto;
     137if(mAdDO && mHistoWp!=NULL) delete mHistoWp;
    65138}
    66139
     
    139212
    140213//++
    141 void PIHisto2D::UseDyn(float hmin,float hmax)
     214void PIHisto2D::UseDyn(float fmin,float fmax)
    142215//
    143216//      Gestion de la dynamique a representer:
     
    151224//--
    152225{
    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 ??
     239if(fmin>=fmax) fmax = fmin+1.;
     240mHMin = fmin; mHMax = fmax;
    157241}
    158242
     
    189273      ,(int)mFgCol,(int)mCmap,(int)mRevCmap,mTypScal,mTypDisp,mFPoints);
    190274printf("                 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 ?
    193277fflush(stdout);
    194278}
     
    201285//--
    202286{
    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());
    205289}
    206290
     
    259343if (axesFlags != kAxesNone) DrawAxes(g);
    260344
    261 if(!mHisto) return;
    262 if(mHisto->NBinX()<=0 || mHisto->NBinY()<=0) return;
     345if(!mHistoWp) return;
     346if(mHistoWp->NBinX()<=0 || mHistoWp->NBinY()<=0) return;
    263347
    264348// Caracteristiques histogramme
    265 double dx = mHisto->WBinX(),dy = mHisto->WBinY();
     349double dx = mHistoWp->WBinX(),dy = mHistoWp->WBinY();
    266350double p1dx,p1dy;
    267351g->DGrC2UC(1.,1.,p1dx,p1dy);
     
    309393
    310394// Plot de l'histogramme
    311 for(int i=0; i<mHisto->NBinX(); i++)
    312   for(int j=0; j<mHisto->NBinY(); j++) {
     395for(int i=0; i<mHistoWp->NBinX(); i++)
     396  for(int j=0; j<mHistoWp->NBinY(); j++) {
    313397
    314398  r_8 left0,bottom0;
    315   mHisto->BinLowEdge(i,j,left0,bottom0);
     399  mHistoWp->BinLowEdge(i,j,left0,bottom0);
    316400
    317401  // Gestion de la dynamique a dessiner
    318   float frac = ((*mHisto)(i,j)-HMin())/(HMax()-HMin());
     402  float frac = ((*mHistoWp)(i,j)-HMin())/(HMax()-HMin());
    319403  if(frac<0.) continue;
    320404  if(mTypScal==1) {              // echelle log10
     
    385469//--
    386470{
    387 Histo2D* h = Histogram();
     471P2DHistoWrapper* h = HistoWrapper();
    388472if(h == NULL) return;
    389473
    390 int i,j;
    391 h->FindBin(x,y,i,j);
     474int_4 i,j;
     475i = floor((x-h->XMin())/h->WBinX());
     476j = floor((y-h->YMin())/h->WBinY());
     477
    392478if(i>=0 && i<h->NBinX() && j>=0 && j<h->NBinY()) {
    393479  char str[64];
    394480  if(fgdiff) {
    395481    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());
    397484    if(i0>=0 && i0<h->NBinX() && j0>=0 && j0<h->NBinY()) {
    398485      sprintf(str," DV=%g",(*h)(i,j)-(*h)(i0,j0));
     
    417504//--
    418505{
    419   if (!mHisto) return;
     506  if (!mHistoWp) return;
    420507  if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt)  g->SelLine(PI_ThinLine);
    421508  g->SelFontSz((YMax() - YMin())/30);
     
    424511  PIGrCoord a, d;
    425512  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
    432528
    433529  double ofpx = spoX*(XMax()-XMin());
     
    446542  cw = (g->isAxeXDirRtoL()) ? -0.05*cellWidth : -0.95*cellWidth;
    447543  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;
    449546  yu = g->DeltaUCY(YMax(),cw);
    450547  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
    452555
    453556  //  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());
    455558}
    456559
     
    489592//--
    490593{
    491 double dx = mHisto->WBinX(),dy = mHisto->WBinY();
     594double dx = mHistoWp->WBinX(),dy = mHistoWp->WBinY();
    492595double dxg,dyg;
    493596g->DUC2GrC(dx,dy,dxg,dyg);
     
    573676  if (rmdecopt)  opt = udopt;
    574677
     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
    575684  // Liste des options si demande
    576685  if(listopt) Print();
    577686
    578   return(ndec+ndec1);
     687  return(ndec+ndec1+ndec2);
    579688}
    580689
     
    607716 if(mRevCmap) opt.push_back("revcmap");
    608717
     718 // Les options du Histo2DWrapper :
     719 mHistoWp->OptionToString(opt);
    609720 return 1;
    610721}
     
    630741info += "- h2scale=lin/log[,logscale]: choose linear or logarithmic scale\n";
    631742info += "- h2dyn=[hmin][,hmax]: choose histogramme range for display\n";
    632 info += "- use general key to define color table (ex: grey32,midas_heat,...)\n";
     743info += "- use graphic att. to define color table (ex: grey32,midas_heat,...)\n";
    633744info += "            (see general graphicatt description)\n";
    634 info += "- use key \"revcmap\" to reverse color table\n";
     745info += "- use \"revcmap\" to reverse color table\n";
    635746info += "- h2frac=[fmin][,fmax]: choose sub-range display [0,1]\n";
     747info += " ---- HistoWrapper options : \n" ;
     748info += " hbincont: select bin content as Y value for display (default) \n";
     749info += " hbinerr: select bin error as Y value for display \n";
     750info += " hbinent: select bin entries as Y value for display \n";
     751info += " hscale=value : multiplicative factor for Y value \n" ;
     752info += " hoffset=value : additive coefficient for Y value \n" ;
     753info += " hs1: set hscale=1 hoffset=0  (default) \n" ;
    636754// On recupere ensuite la chaine info de la classe de base
    637755PIDrawer::GetOptionsHelpInfo(info);
Note: See TracChangeset for help on using the changeset viewer.