Changeset 82 in Sophya


Ignore:
Timestamp:
Feb 25, 1998, 5:02:27 PM (28 years ago)
Author:
cmv
Message:

dessin histo 2D 2sd generation avec fenetre de dialogue cmv 25/02/98

Location:
trunk/SophyaPI/PI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PI/pihisto2d.cc

    r79 r82  
    11#include <stdio.h>
    22#include "pihisto2d.h"
    3 
    4 #include PIMENU_H
    5 
     3#include "nbrandom.h"
     4
     5static int dbg = 0;
     6
     7//++
    68PIHisto2D::PIHisto2D(Histo2D* histo, bool ad)
    79: PIScDrawer(), mHisto(histo)
    8 {
    9   mAdDO = ad;     // Flag pour suppression automatique de mHisto 
    10   UseColors();
    11 }
    12 
     10//
     11//      Createur d'une classe de dessin pour l'histogramme 2D histo.
     12//--
     13{
     14mAdDO = ad;     // Flag pour suppression automatique de mHisto 
     15
     16mLogScale = 10.;
     17mFPoints = 0.5;
     18
     19UseColors();
     20UseDisplay();
     21UseDyn();
     22UseFrac();
     23}
     24
     25//++
    1326PIHisto2D::~PIHisto2D()
    14 {
    15   if (mAdDO)
    16     delete mHisto;
    17 }
    18 
    19 void
    20 PIHisto2D::UseColors(bool fg, CMapId cmap)
    21 {
    22   mFgCol = fg; mCmap = cmap;
    23 }
    24 
    25 void
    26 PIHisto2D::UpdateSize()
     27//
     28//      Destructeur.
     29//--
     30{
     31if(mAdDO) delete mHisto;
     32}
     33
     34//++
     35void PIHisto2D::UseColors(bool fg, CMapId cmap)
     36//
     37//      Choix de la couleur si fg=true
     38//      (pour la couleur cmap cf picmap.h).
     39//--
     40{
     41mFgCol = fg; mCmap = cmap;
     42}
     43
     44//++
     45void PIHisto2D::UseScale(unsigned short type,float logscale)
     46//
     47//      Pour changer les echelles.
     48//| Type = 0 : echelle lineaire
     49//|      = 1 : echelle log10
     50//| - Explication du codage en type=1 (log10) :
     51//|   1-/ map lineaire :
     52//|       [0,1] -> [lmin,lmax]
     53//|       f     -> F = lmin+f*(lmax-lmin)
     54//|   2-/ transformation log10 :
     55//|       [lmin,lmax] -> [log10(lmin),log10(lmax)]
     56//|       F           -> LF = lg10(F)
     57//|   3-/ rescaling entre 0 et 1 :
     58//|       [log10(lmin),log10(lmax)] -> [0,1]
     59//|       LF -> (LF-log10(lmin))/(log10(lmax)-log10(lmin))
     60//|       soit en definissant logscale = lmax/lmin
     61//|       LF = log10(1.+f*(logscale-1))/log10(logscale)
     62//--
     63{
     64if(type==0) mTypScal = 0;
     65if(type==1) {
     66  mTypScal = 1;
     67  if(logscale>1.) mLogScale = logscale;
     68} else mTypScal = 0;
     69}
     70
     71//++
     72void PIHisto2D::UseDisplay(unsigned short type, float fnpt)
     73//
     74//      Type de Display
     75//| Type = 0 : carres de tailles variables
     76//| Type = 1 : nuages de points
     77//|            Le nombre de points a utiliser est fnpt*N
     78//|            ou N est le nombre de pixels ecran contenu
     79//|            dans un bin de l'histogramme.
     80//| Type = 2 : code a la "hbook2"
     81//| Type = 3 : carres de tailles fixes en couleur
     82//--
     83{
     84if(fnpt<0.) fnpt=0; else if(fnpt>1.) fnpt=1.;
     85if(type==0)        mTypDisp = 0;
     86else if(type==1) { mTypDisp = 1; mFPoints = fnpt;}
     87else if(type==2)   mTypDisp = 2;
     88else if(type==3)   mTypDisp = 3;
     89else               mTypDisp = 1;
     90}
     91
     92//++
     93void PIHisto2D::UseDyn(float hmin, float hmax)
     94//
     95//      Gestion de la dynamique a representer:
     96//      la dynamique va etre transformee de [hmin,hmax] vers [0,1].
     97//--
     98{
     99if(hmin>=hmax) {hmin = mHisto->VMin(); hmax = mHisto->VMax();}
     100if(hmin>=hmax) hmax = hmin+1.;
     101mHMin = hmin; mHMax = hmax;
     102}
     103
     104//++
     105void PIHisto2D::UseFrac(float frmin, float frmax)
     106//
     107//      Pour definir la fraction de la dynamique a dessiner:
     108//| Pour certains type de display (f=[0,1] cf UseDyn),
     109//|    - on ne dessine rien si f <= frmin
     110//|    - on limite l'excursion a f*frmax cad [...,frmax]
     111//--
     112{
     113if(frmax<=0. || frmax>1.) frmax = 1.;
     114if(frmin>=frmax) {frmin=0.1; frmax=0.9;}
     115mFracMin = frmin; mFracMax = frmax;
     116}
     117
     118//++
     119void PIHisto2D::Print(int lp)
     120//
     121//      Print de l'etat des options du display.
     122//--
     123{
     124printf("PIHisto2D::Print FgCol=%d Cmap=%d TypScal=%d TypDisp=%d (FPoints=%g)\n"
     125      ,(int)mFgCol,(int)mCmap,mTypScal,mTypDisp,mFPoints);
     126printf("                 Dyn=%g,%g Frac=%g,%g LogSc=%g H=%lx\n"
     127      ,mHMin,mHMax,mFracMin,mFracMax,mLogScale,(long)mHisto);
     128if(lp<1) return;
     129mHisto->PrintStatus();
     130}
     131
     132void PIHisto2D::UpdateSize()
    27133{
    28134  if (!mDrawer) return;
    29135  if (mDrawer->LimitsFixed()) return;
    30   if (!mHisto) return;
     136  if(!mHisto) return;
    31137  // Commencer par trouver nos limites
    32138 
     
    37143  float ymin = mHisto->YMin();
    38144 
    39   if (mDrawWdg) 
     145  if (mDrawWdg)
    40146    mDrawWdg->SetLimits(xmin, xmax, ymin, ymax);
    41   else 
     147  else
    42148    mDrawer->SetLimits(xmin, xmax, ymin, ymax);
    43149
     
    45151}
    46152
    47 
    48 void
    49 PIHisto2D::Draw(PIGraphicUC* g, float /*xmin*/, float /*ymin*/, float /*xmax*/, float /*ymax*/)
    50 {
    51   if (!mHisto)  return;
    52   float hmin = mHisto->VMin();
    53   float hmax = mHisto->VMax();
    54   if(hmin>=hmax) hmax = hmin+1.;
    55   float dx = mHisto->WBinX();
    56   float dy = mHisto->WBinY();
    57   float fracmin=0.1, fracmax=0.8;
    58 
    59   PIColorMap* cmap=NULL;
    60   PIColors coul;
    61   int ncol = 0;
    62   if (mFgCol) {
    63     cmap = new PIColorMap(mCmap);
    64     ncol = cmap->NCol();
    65     coul = g->GetForeground();
    66 //    fracmin = 0.;
    67 //    fracmax = 1.;
     153//++
     154void PIHisto2D::Draw(PIGraphicUC* g,float,float, float, float)
     155//
     156//      Dessin de l'histogramme.
     157//--
     158{
     159if(!mHisto) return;
     160// Caracteristiques histogramme
     161float dx = mHisto->WBinX(),dy = mHisto->WBinY();
     162float p1dx,p1dy;
     163g->DGrC2UC(1.f,1.f,p1dx,p1dy);
     164
     165// Gamme a representer entre [0,1] mais >=fracmin et scale fracmax
     166float fracmin=FMin(), fracmax=FMax();
     167float llscale = (float) log10((double)LogScale());
     168
     169// gestion Couleurs.
     170PIColorMap* cmap=NULL;
     171PIColors coul = g->GetForeground();
     172int ncol = 0;
     173if (mFgCol) {
     174  cmap = new PIColorMap(mCmap); ncol = cmap->NCol();
     175  if(mTypDisp==3) fracmin=-1.;
     176}
     177
     178// gestion Markers ou plot avec des points.
     179PIMarker Mk = g->GetMarker();
     180int MkSz = g->GetMarkerSize();
     181int npt = 1;
     182if(mTypDisp==1) {
     183  g->SelMarker(1,PI_DotMarker);
     184  npt = (int) ((float)NPixBin(g)*FPoints()); if(npt<=0) npt = 2;
     185}
     186
     187// gestion Font.
     188PIFontAtt FontAtt = g->GetFontAtt();
     189int FontSize = g->GetFontSize();
     190if(mTypDisp==2) {
     191  float dxg,dyg,dg;
     192  g->DUC2GrC(dx,dy,dxg,dyg);
     193  dg =(dxg<dyg) ? dxg : dyg;
     194  int npix = (int) (dg*0.9); if(npix<8) npix = 8;
     195  //printf("PIHisto2D::Draw_Font H dx=%g dy=%g, G dx=%g dy=%g, npix = %g,%d\n"
     196  //      ,dx,dy,dxg,dyg,dg,npix);
     197  g->SelFontSzPt(npix,PI_RomanFont);
     198  fracmin = 0;
     199}
     200
     201// Print();
     202
     203// Plot de l'histogramme
     204for (int i=0; i<mHisto->NBinX(); i++)
     205for (int j=0; j<mHisto->NBinY(); j++) {
     206
     207  float left0,bottom0;
     208  mHisto->BinLowEdge(i,j,left0,bottom0);
     209
     210  // Gestion de la dynamique a dessiner
     211  float frac = ((*mHisto)(i,j)-HMin())/(HMax()-HMin());
     212  if(frac<0.) continue;
     213  if(mTypScal==1) {              // echelle log10
     214    frac = log10(1.+frac*(LogScale()-1.))/llscale;
     215    if(frac<0.) continue;
    68216  }
    69 
    70   for (int i=0; i<mHisto->NBinX(); i++) {
    71     for (int j=0; j<mHisto->NBinY(); j++) {
    72       float left,bottom;
    73       mHisto->BinLowEdge(i,j,left,bottom);
    74       float frac = fracmax*((*mHisto)(i,j)-hmin)/(hmax-hmin);
    75       if(frac<fracmin) continue;
    76       float width = frac*dx;
    77       float height = frac*dy;
    78       left += 0.5*(1.-frac)*dx;
    79       bottom += 0.5*(1.-frac)*dy;
    80       if (cmap) {
    81         int icol = ncol*(frac/fracmax);
    82         if(icol>=ncol) icol = ncol-1; else if(icol<0) icol=0;
    83         g->SelForeground(*cmap,icol);
    84         g->DrawFBox(left,bottom,width,height);
    85       }
    86       else g->DrawBox(left,bottom,width,height);
     217  if(frac<=fracmin) continue;
     218  if(frac>1.) frac = 1.;
     219  float fracred = frac * fracmax;
     220
     221  // Gestion de la couleur
     222  int icol = 0;
     223  if (cmap) {
     224    icol = int( (float) ncol*frac );
     225    if(icol>=ncol) icol = ncol-1; else if(icol<0) icol=0;
     226    g->SelForeground(*cmap,icol);
     227  }
     228
     229  // Dessin proprement dit selon le choix graphique.
     230  if(mTypDisp==0) {
     231    //..... carres de tailles variables
     232    float left   = left0   + 0.5*(1.-fracred)*dx, width  = fracred*dx;
     233    float bottom = bottom0 + 0.5*(1.-fracred)*dy, height = fracred*dy;
     234    if (cmap) g->DrawFBox(left,bottom,width,height);
     235    else      g->DrawBox(left,bottom,width,height);
     236  } else if(mTypDisp==1) {
     237    //..... nuage de points .....
     238    int ipt  = int( (float) npt *frac );
     239    for(int k=0;k<ipt;k++) {
     240      float x = left0 + frand01()*dx;
     241      float y = bottom0 + frand01()*dy;
     242      g->DrawMarker(x,y);
    87243    }
     244  } else if(mTypDisp==2) {
     245    //..... type hbook2/hprint .+23-Z*
     246    char c[2];
     247    c[0] = HPrint2(frac); c[1]='\0';
     248    float x = left0 + dx/2.;
     249    float y = bottom0 + dy/2.;
     250    g->DrawString(x,y,c);
     251  } else if(mTypDisp==3) {
     252    //..... carres de tailles fixes (avec gestion de continuite)
     253    if (cmap) g->DrawFBox(left0,bottom0,dx+p1dx,dy+p1dy);
     254    else      g->DrawBox(left0,bottom0,dx+p1dx,dy+p1dy);
    88255  }
    89   if (cmap) {
    90     g->SelForeground(coul);
    91     delete cmap;
    92   }
    93   DrawStats(g);
    94 }
    95 
    96 void
    97 PIHisto2D::DrawStats(PIGraphicUC* g)
     256
     257}
     258
     259// Remise dans les conditions ulterieures pour la suite du graphique.
     260g->SelMarker(MkSz,Mk);
     261g->SelForeground(coul);
     262g->SelFontSzPt(FontSize,FontAtt);
     263if (cmap) delete cmap;
     264
     265// Fin du dessin, ecriture de la statistique.
     266DrawStats(g);
     267}
     268
     269//++
     270void PIHisto2D::DrawStats(PIGraphicUC* g)
     271//
     272//      Dessin des informations statistiques de l'histogramme.
     273//--
    98274{
    99275  if (!mDrawWdg) return;
     
    109285  g->SelFontSz((mDrawWdg->YMax() - mDrawWdg->YMin())/30);
    110286  g->DrawString(mDrawWdg->XMax() - cellWidth*0.9, mDrawWdg->YMax() - cellHeight*0.8, label);
    111                        
     287  printf("H[%d,%d] Dynamique: [%g,%g] Frac [%g,%g]\n"
     288        ,mHisto->NBinX(),mHisto->NBinY(),HMin(),HMax(),FMin(),FMax());
     289}
     290
     291//++
     292char PIHisto2D::HPrint2(float f)
     293//
     294//      Codage des valeurs en caracteres (fct privee).
     295//| f entre [0,1] mappee entre valeur=[0,37]
     296//| si <0 alors =0, si >1 alors 1
     297//| Display 4   ==> 4<=valeur<5
     298//|         C   ==> 12<=valeur<13
     299//|             ==> valeur<=0
     300//|         *   ==> valeur>=1
     301//|         .   ==> 0<valeur<1
     302//|------------------------------------------
     303//|            1111111111222222222233333333
     304//|  01234567890123456789012345678901234567
     305//| " .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*"
     306//|------------------------------------------
     307//--
     308{
     309char str[39] = " .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*";
     310int i;
     311if(f<=0.) i = 0;
     312else if(f>=1.) i = 37;
     313else { i = (int) (f*36.); i++;}
     314if(i<0) i=0; else if (i>=38) i = 37;
     315return str[i];
     316}
     317
     318//++
     319int PIHisto2D::NPixBin(PIGraphicUC* g)
     320//
     321//      Nombre de pixels ecran dans un bin d'histogramme
     322//      (fct privee).
     323//--
     324{
     325float dx = mHisto->WBinX(),dy = mHisto->WBinY();
     326float dxg,dyg;
     327g->DUC2GrC(dx,dy,dxg,dyg);
     328int np = (int) dxg * (int) dyg;
     329//printf("PIHisto2D::NPixBin H dx=%g dy=%g, G dx=%g dy=%g, np = %d\n"
     330//      ,dx,dy,dxg,dyg,np);
     331return np;
    112332}
    113333
     
    118338
    119339
    120 //  Le menu qui va servir a choisir l'option d'affichage suite au click
    121 // de bouton-3
    122 static PIPUMenu* optmenh2d=NULL;
    123 static int nb_optmen = 0;
    124 
     340static H2WinArg* h2dWinArg=NULL;
     341static int nb_h2dWinArg = 0;
     342
     343//++
    125344PIH2DWdg::PIH2DWdg(PIContainerGen *par, char *nom, int sx, int sy, int px, int py)
     345//
     346//      Createur d'un Widget de dessin d'histogramme 2D.
     347//      Le menu pour choisir l'option d'affichage apparait suite au clic
     348//      du bouton-3 de la souris.
     349//--
    126350        : PIScDrawWdg(par,nom,sx,sy,px,py)
    127351{
    128 if (!optmenh2d) {
    129   optmenh2d = new PIPUMenu((PIMsgHandler *)this, "TypeH2D");
    130   optmenh2d->AppendItem("B&W", 6101);
    131   optmenh2d->AppendItem("Gris", 6102);
    132   optmenh2d->AppendItem("RJ32", 6103);
    133   optmenh2d->AppendItem("BR32", 6104);
    134   }
    135 nb_optmen++;
     352if (!h2dWinArg) h2dWinArg = new H2WinArg(this);
     353nb_h2dWinArg++;
     354if(dbg) printf("PIH2DWdg::PIH2DWdg %lx h2dWinArg=%lx %d\n"
     355              ,(long)this,(long)h2dWinArg,nb_h2dWinArg);
    136356mPih = NULL;
    137 ActivateButton(3); // Pour afficher le menu option de trace
    138 }
    139 
     357// Pour afficher le menu option de trace
     358ActivateButton(3);
     359}
     360
     361//++
    140362PIH2DWdg::~PIH2DWdg()
    141 {
    142 nb_optmen--;
    143 if (nb_optmen == 0) { delete optmenh2d;  optmenh2d=NULL; }
    144 if (mPih)  delete mPih;
    145 }
    146 
    147 void PIH2DWdg::SetHisto(Histo2D* histo, bool fg, CMapId cmap)
     363//
     364//      Destructeur.
     365//--
     366{
     367nb_h2dWinArg--;
     368if (nb_h2dWinArg == 0) {
     369  h2dWinArg->Hide();
     370  delete h2dWinArg;
     371  h2dWinArg=NULL;
     372}
     373if(dbg) printf("PIH2DWdg::~PIH2DWdg h2dWinArg=%lx %d\n"
     374              ,(long)h2dWinArg,nb_h2dWinArg);
     375if (mPih) delete mPih;
     376}
     377
     378//++
     379void PIH2DWdg::SetHisto(Histo2D* histo)
     380//
     381//      Pour connecter un histogramme 2D au Widget.
     382//--
    148383{
    149384if (!histo) return;
    150385if (mPih)  delete mPih;
    151386mPih = new PIHisto2D(histo, true);
    152 mPih->UseColors(fg, cmap);
    153387AddScDrawer(mPih);
    154 }
    155 
     388if(dbg) printf("PIH2DWdg::SetHisto mPih=%lx\n",(long)mPih);
     389}
     390
     391//++
    156392string  PIH2DWdg::GetClickText(float x, float y)
     393//
     394//      Quand on click (and drag) le bouton-1, affichage
     395//      des positions x,y et de la valeur du bin de l'histogramme 2D.
     396//--
    157397{
    158398int i,j;
     
    161401if ((!mPih) || (!mPih->Histogram())) {
    162402  sprintf(str,"X=%g Y=%g ???",x,y);
    163   return((string)str); 
     403  return((string)str);
    164404}
    165405
    166406Histo2D* h = mPih->Histogram();
    167 
    168407
    169408h->FindBin(x,y,i,j);
    170409if(i<0 || i>=h->NBinX() || j<0 || j>=h->NBinY())
    171   sprintf(str,"X=%g Y=%g ???",x,y);
    172 else sprintf(str,"X=%g Y=%g v=%g",x,y,(*h)(i,j));
     410  sprintf(str,"x= %g y= %g ???",x,y);
     411else sprintf(str,"x= %g y= %g v= %g",x,y,(*h)(i,j));
    173412
    174413return((string)str);
    175414}
    176415
    177 void PIH2DWdg::Process(PIMessage msg, PIMsgHandler* sender, void* data)
    178 {
    179 //printf("PIH2DWdg::Process(%d-%d , %lx ...) \n", UserMsg(msg), ModMsg(msg), (long)sender);
    180 if (!mPih) return;
    181 if (sender == optmenh2d) { // On n'attend de message que de la part du menu
    182   int opt=6101;
    183   bool fgc=false;
    184   CMapId col=CMAP_GREYINV32;
    185      
    186   opt = UserMsg(msg);
    187   if (opt == 6102) { fgc = true; col = CMAP_GREYINV32; }
    188   else if (opt == 6103) { fgc = true;  col = CMAP_COLRJ32; }
    189   else if (opt == 6104) { fgc = true; col = CMAP_COLBR32; }
    190   mPih->UseColors(fgc, col);
    191   mPih->Refresh();  // On rafraichit le dessin     
    192 }
    193 
    194 }
    195 
     416//++
    196417void PIH2DWdg::But3Press(int x, int y)
    197 {
    198 //printf("PIH2DWdg::But3Press(%d %d ) \n", x, y);
    199 optmenh2d->SetMsgParent((PIMsgHandler*)this);
    200 optmenh2d->Show(this, x, y);
    201 }
     418//
     419//      Gestion de l'utilisation du bouton-3 de la souris.
     420//      Un seul objet est cree pour tous les histogrammes 2D.
     421//      Il est connecte a un histogramme donnee par l'action du
     422//      du bouton-3 de la souris dans la fenetre contenant
     423//      le dessin de l'histogramme.
     424//--
     425{
     426h2dWinArg->SetPIH2DWdg(this);
     427h2dWinArg->SetMsgParent((PIMsgHandler*)this);
     428if(!h2dWinArg->Visible()) h2dWinArg->Show();
     429if(dbg) printf("PIH2DWdg::But3Press(%d,%d) h2dWinArg=%lx\n"
     430              ,x,y,(long)h2dWinArg);
     431}
     432
     433
     434/////////////////////////////////////////////////////////////////
     435//  Classe H2WinArg
     436/////////////////////////////////////////////////////////////////
     437
     438//++
     439H2WinArg::H2WinArg(PIH2DWdg *par)
     440//
     441//      Creation de la fenetre de gestion des parametres
     442//      des dessins des histogrammes 2D.
     443//--
     444: PIWindow((PIMsgHandler *)par, "Options", PIWK_dialog,250,260,150,150)
     445{
     446string sdum;
     447if(dbg) printf("H2WinArg::H2WinArg %lx par=%lx\n",(long)this,(long)par);
     448
     449mH2Wdg = NULL;
     450
     451mFgCol    = false;
     452mCmap     = CMAP_GREYINV32;
     453mTypScal  = 0;
     454mTypDisp  = 0;
     455mFPoints  = 0.5;
     456mHMin     = 1.;
     457mHMax     = -1.;
     458mFracMin  = 0.1;
     459mFracMax  = 0.9;
     460mLogScale = 10.;
     461
     462// menus bar
     463mPop[0] = new PIPUMenu((PIMsgHandler *)this,"Display");
     464mPop[0]->AppendItem("Carres Var."  , 6101);
     465mPop[0]->AppendItem("....."        , 6102);
     466mPop[0]->AppendItem(".+12..Z*"     , 6103);
     467mPop[0]->AppendItem("Carres Pleins", 6104);
     468mOPop[0] = new PIOptMenu(this,mPop[0],100,25,10,10);
     469sdum = "Carres Var."; mOPop[0]->SetValueStr(sdum);
     470
     471mPop[1] = new PIPUMenu((PIMsgHandler *)this,"Scale");
     472mPop[1]->AppendItem("Lineaire", 6201);
     473mPop[1]->AppendItem("Log10"   , 6202);
     474mOPop[1] = new PIOptMenu(this,mPop[1],100,25,10,40);
     475sdum = "Lineaire"; mOPop[1]->SetValueStr(sdum);
     476
     477mPop[2] = new PIPUMenu((PIMsgHandler *)this,"Color");
     478mPop[2]->AppendItem("B&W"      , 6301);
     479mPop[2]->AppendItem("Grey32"   , 6302);
     480mPop[2]->AppendItem("GreyInv32", 6303);
     481mPop[2]->AppendItem("RJ32"     , 6304);
     482mPop[2]->AppendItem("BR32"     , 6305);
     483mPop[2]->AppendItem("RV32"     , 6306);
     484mPop[2]->AppendItem("Arc16"    , 6307);
     485mOPop[2] = new PIOptMenu(this,mPop[2],100,25,10,70);
     486sdum = "B&W"; mOPop[2]->SetValueStr(sdum);
     487
     488// Labels et zone de saisie texte
     489mLab[0] = new PILabel(this, "     Dyn: ",60,30,10,110);
     490mLab[1] = new PILabel(this, "    Frac: ",60,30,10,145);
     491mLab[2] = new PILabel(this, " LogScal: ",60,30,10,180);
     492
     493mText[0] = new PIText(this, "Dynamique",150,30,80,110);
     494mText[1] = new PIText(this, "Fraction" ,150,30,80,145);
     495mText[2] = new PIText(this, "LogScale" ,150,30,80,180);
     496SetText();
     497
     498// Labels et curseur mobile
     499mLab[3] = new PILabel(this, "   PerPt: ",60,30,10,215);
     500mPScal = new PIScale(this,"FracPoints",6401,true,150,20,80,215);
     501mPScal->SetMinMax(0,100);
     502int imfp = mFPoints*100.f;
     503mPScal->SetValue(imfp);
     504
     505// Boutons
     506mBut[0] = new PIButton(this, "Apply", 6001, 50, 20, 150,10);
     507mBut[1] = new PIButton(this, "Close", 6002, 50, 20, 150,35);
     508mBut[2] = new PIButton(this, "Get"  , 6003, 50, 20, 150,60);
     509mBut[3] = new PIButton(this, "Print", 6004, 50, 20, 150,85);
     510FinishCreate();
     511}
     512
     513//++
     514H2WinArg::~H2WinArg()
     515//
     516//      Destructeur.
     517//--
     518{
     519int i;
     520if(dbg) printf("H2WinArg::~H2WinArg %lx\n",(long)this);
     521for(i=0;i<3;i++) {delete mPop[i]; delete mOPop[i];}
     522for(i=0;i<4;i++) delete mBut[i];
     523for(i=0;i<4;i++) delete mLab[i];
     524for(i=0;i<3;i++) delete mText[i];
     525delete mPScal;
     526}
     527
     528//++
     529void H2WinArg::SetText()
     530//
     531//      Gestion des fenetres de saisie de texte.
     532//--
     533{
     534string sdum;
     535char str[256];
     536sprintf(str,"%g %g",mHMin,mHMax);
     537mText[0]->SetText(str);
     538sprintf(str,"%g %g",mFracMin,mFracMax);
     539mText[1]->SetText(str);
     540sprintf(str,"%g",mLogScale);
     541mText[2]->SetText(str);
     542
     543if(mTypDisp==0)      { sdum="Carres Var.";   mOPop[0]->SetValueStr(sdum);}
     544else if(mTypDisp==1) { sdum=".....";         mOPop[0]->SetValueStr(sdum);}
     545else if(mTypDisp==2) { sdum=".+12..Z*";      mOPop[0]->SetValueStr(sdum);}
     546else if(mTypDisp==3) { sdum="Carres Pleins"; mOPop[0]->SetValueStr(sdum);}
     547
     548if(mTypScal==0)      { sdum="Lineaire"; mOPop[1]->SetValueStr(sdum);}
     549else if(mTypScal==1) { sdum="Log10";    mOPop[1]->SetValueStr(sdum);}
     550
     551if(!mFgCol)                      { sdum="B&W";       mOPop[2]->SetValueStr(sdum);}
     552else {
     553  if(mCmap==CMAP_GREY32)         { sdum="Grey32";    mOPop[2]->SetValueStr(sdum);}
     554  else if(mCmap==CMAP_GREYINV32) { sdum="GreyInv32"; mOPop[2]->SetValueStr(sdum);}
     555  else if(mCmap==CMAP_COLRJ32)   { sdum="RJ32";      mOPop[2]->SetValueStr(sdum);}
     556  else if(mCmap==CMAP_COLBR32)   { sdum="BR32";      mOPop[2]->SetValueStr(sdum);}
     557  else if(mCmap==CMAP_COLRV32)   { sdum="RV32";      mOPop[2]->SetValueStr(sdum);}
     558  else if(mCmap==CMAP_COL16)     { sdum="Arc16";     mOPop[2]->SetValueStr(sdum);}
     559}
     560
     561printf("H2WinArg::SetText\n");
     562}
     563
     564//++
     565void H2WinArg::GetText()
     566//
     567//      Gestion des fenetres de saisie de texte.
     568//--
     569{
     570sscanf(mText[0]->GetText().c_str(),"%g %g",&mHMin,&mHMax);
     571sscanf(mText[1]->GetText().c_str(),"%g %g",&mFracMin,&mFracMax);
     572sscanf(mText[2]->GetText().c_str(),"%g",&mLogScale);
     573if(dbg) printf("H2WinArg::GetText\n");
     574}
     575
     576//++
     577void H2WinArg::SetPIH2DWdg(PIH2DWdg* h2wdg)
     578//
     579//      Connexion du widget de representation d'un histogramme 2D
     580//      avec la fenetre de gestion des parametres.
     581//--
     582{
     583mH2Wdg = h2wdg;
     584if(dbg) printf("H2WinArg::SetPIH2DWdg mH2Wdg = %lx\n",(long)mH2Wdg);
     585}
     586
     587//++
     588void H2WinArg::Process(PIMessage msg, PIMsgHandler* sender, void*)
     589//
     590//      Gestions des messages.
     591//--
     592{
     593if(dbg) printf("PIH2DWdg::Process(%d-%d , %lx ...) \n"
     594              ,(int)UserMsg(msg),(int)ModMsg(msg), (long)sender);
     595
     596if(!mH2Wdg) return;
     597PIHisto2D* mpih = mH2Wdg->GetPIHisto();
     598if(!mpih) return;
     599
     600int opt = UserMsg(msg);
     601     if (opt == 6101) { mTypDisp = 0; }
     602else if (opt == 6102) { mTypDisp = 1; }
     603else if (opt == 6103) { mTypDisp = 2; }
     604else if (opt == 6104) { mTypDisp = 3; }
     605
     606else if (opt == 6201) { mTypScal = 0; }
     607else if (opt == 6202) { mTypScal = 1; }
     608
     609else if (opt == 6301) { mFgCol = false; }
     610else if (opt == 6302) { mFgCol = true;  mCmap = CMAP_GREY32; }
     611else if (opt == 6303) { mFgCol = true;  mCmap = CMAP_GREYINV32; }
     612else if (opt == 6304) { mFgCol = true;  mCmap = CMAP_COLRJ32; }
     613else if (opt == 6305) { mFgCol = true;  mCmap = CMAP_COLBR32; }
     614else if (opt == 6306) { mFgCol = true;  mCmap = CMAP_COLRV32; }
     615else if (opt == 6307) { mFgCol = true;  mCmap = CMAP_COL16; }
     616
     617else if (opt == 6401) mFPoints = mPScal->GetValue()/100.;
     618
     619else if (opt==6001) {
     620  GetText();
     621  mpih->UseColors(mFgCol, mCmap);
     622  mpih->UseScale(mTypScal,mLogScale);
     623  mpih->UseDisplay(mTypDisp,mFPoints);
     624  mpih->UseDyn(mHMin,mHMax);
     625  mpih->UseFrac(mFracMin,mFracMax);
     626  mpih->Refresh();  // On rafraichit le dessin
     627}
     628else if (opt==6002) {
     629  this->Hide();
     630}
     631else if (opt==6003) {
     632  mFgCol    = mpih->Color();
     633  mCmap     = mpih->ColMap();
     634  mTypScal  = mpih->TypScale();
     635  mTypDisp  = mpih->TypDisplay();
     636  mFPoints  = mpih->FPoints();
     637  mHMin     = mpih->HMin();
     638  mHMax     = mpih->HMax();
     639  mFracMin  = mpih->FMin();
     640  mFracMax  = mpih->FMax();
     641  mLogScale = mpih->LogScale();
     642  SetText();
     643}
     644else if (opt==6004) {
     645  mpih->Print(2);
     646}
     647
     648if(dbg) {
     649  printf("H2WinArg::Process opt=%d col=%d,%d scal=%d disp=%d npt=%g\n"
     650        ,opt,(int) mFgCol,(int) mCmap,mTypScal,mTypDisp,mFPoints);
     651  printf("                  min,max= %g,%g frac= %g,%g logsc= %g\n"
     652        ,mHMin,mHMax,mFracMin,mFracMax,mLogScale);
     653}
     654
     655}
  • trunk/SophyaPI/PI/pihisto2d.h

    r76 r82  
    11#ifndef PIHISTO2D_H
    22#define PIHISTO2D_H
     3
     4#include "pisysdep.h"
     5#include PIMENU_H
     6#include PIMENUBAR_H
     7#include PIOPTMENU_H
    38
    49#include "histos2.h"
    510#include "piscdrawwdg.h"
    611
     12////////////////////////////////////////////////////////////////////
    713class PIHisto2D : public PIScDrawer {
    814public:
     
    1016  virtual            ~PIHisto2D();
    1117          void       UseColors(bool fg=false, CMapId cmap=CMAP_GREYINV32);
    12   virtual void       Draw(PIGraphicUC* g, float xmin, float ymin, float xmax, float ymax);
     18          void       UseScale(unsigned short type=0,float logscale=10.);
     19          void       UseDisplay(unsigned short type=0, float fnpt=0.5);
     20          void       UseDyn(float hmin=1., float hmax=-1.);
     21          void       UseFrac(float frmin=0.1, float frmax=0.9);
     22          void       Print(int lp=0);
     23  virtual void       Draw(PIGraphicUC* g,float xmin,float ymin,float xmax,float ymax);
    1324  virtual void       UpdateSize();
    1425  virtual void       DrawStats(PIGraphicUC* g);
    15   inline  Histo2D*   Histogram() { return(mHisto); }
     26
     27  inline Histo2D*       Histogram() { return(mHisto); }
     28  inline bool           Color() { return(mFgCol); }
     29  inline CMapId         ColMap() { return(mCmap); }
     30  inline unsigned short TypScale() { return(mTypScal); }
     31  inline unsigned short TypDisplay() { return(mTypDisp); }
     32  inline float          FPoints() { return(mFPoints); }
     33  inline float          HMax() { return(mHMax);}
     34  inline float          HMin() { return(mHMin);}
     35  inline float          FMax() { return(mFracMax);}
     36  inline float          FMin() { return(mFracMin);}
     37  inline float          LogScale() { return(mLogScale);}
    1638
    1739protected:
     40  int NPixBin(PIGraphicUC* g);
     41  char HPrint2(float f);
     42
    1843  Histo2D* mHisto;
    1944  bool mFgCol;
    2045  CMapId mCmap;
     46  unsigned short mTypScal;
     47  unsigned short mTypDisp;
     48  float mFPoints;
     49  float mHMin,mHMax;
     50  float mFracMin,mFracMax;
     51  float mLogScale;
    2152};
    2253
     54////////////////////////////////////////////////////////////////////
    2355class PIH2DWdg : public PIScDrawWdg {
    2456public:
     
    2759                     ~PIH2DWdg();
    2860
    29   virtual void       Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
    30   void               SetHisto(Histo2D* histo, bool fg=false, CMapId cmap=CMAP_GREYINV32);
    31 
     61  void               SetHisto(Histo2D* histo);
     62  inline PIHisto2D*  GetPIHisto() {return mPih;}
    3263
    3364  virtual string     GetClickText(float x, float y);
     
    3970};
    4071
     72////////////////////////////////////////////////////////////////////
     73class H2WinArg : public PIWindow {
     74public :
     75               H2WinArg(PIH2DWdg *par);
     76               ~H2WinArg();
     77          void SetPIH2DWdg(PIH2DWdg* h2wdg);
     78          void SetText();
     79          void GetText();
     80  virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
     81
     82protected:
     83  PIH2DWdg  * mH2Wdg;
     84
     85  PIPUMenu  * mPop[3];
     86  PIOptMenu * mOPop[3];
     87  PIButton  * mBut[4];
     88  PILabel   * mLab[4];
     89  PIText    * mText[3];
     90  PIScale   * mPScal;
     91
     92  bool mFgCol;
     93  CMapId mCmap;
     94  unsigned short mTypScal;
     95  unsigned short mTypDisp;
     96  float mFPoints;
     97  float mHMin,mHMax;
     98  float mFracMin,mFracMax;
     99  float mLogScale;
     100};
     101
    41102#endif
Note: See TracChangeset for help on using the changeset viewer.