| 1 | #include <stdio.h>
 | 
|---|
| 2 | #include <stdlib.h>
 | 
|---|
| 3 | #include <pisysdep.h>
 | 
|---|
| 4 | #include PIAPP_H
 | 
|---|
| 5 | #include "sopnamsp.h"
 | 
|---|
| 6 | #include "pihisto2d.h"
 | 
|---|
| 7 | #include "nbrandom.h"
 | 
|---|
| 8 | 
 | 
|---|
| 9 | static int dbg = 0;
 | 
|---|
| 10 | 
 | 
|---|
| 11 | //++
 | 
|---|
| 12 | // Class        PIHisto2D
 | 
|---|
| 13 | // Lib          PIext
 | 
|---|
| 14 | // include      pihisto2d.h
 | 
|---|
| 15 | //
 | 
|---|
| 16 | //      Classes de dessin des histogrammes a 2 dimensions pour 
 | 
|---|
| 17 | //      objets *Histo2D* 
 | 
|---|
| 18 | //--
 | 
|---|
| 19 | 
 | 
|---|
| 20 | //++
 | 
|---|
| 21 | // Links        Parents
 | 
|---|
| 22 | // PIDrawer
 | 
|---|
| 23 | //--
 | 
|---|
| 24 | 
 | 
|---|
| 25 | //++
 | 
|---|
| 26 | // Titre        Constructeur, méthodes
 | 
|---|
| 27 | //--
 | 
|---|
| 28 | 
 | 
|---|
| 29 | //++
 | 
|---|
| 30 | PIHisto2D::PIHisto2D(Histo2D* histo, bool ad)
 | 
|---|
| 31 | //
 | 
|---|
| 32 | //      Createur d'une classe de dessin pour l'histogramme 2D histo.
 | 
|---|
| 33 | //--
 | 
|---|
| 34 | : PIDrawer(), mHisto(histo), mAdDO(ad), mLogScale(10.), mFPoints(0.5)
 | 
|---|
| 35 | {
 | 
|---|
| 36 | // mAdDO : Flag pour suppression automatique de mHisto
 | 
|---|
| 37 | // Attention: mFPoints n'est initialise que si on display par nuages de points
 | 
|---|
| 38 | //            mLogScale n'est initialise que si on utilise une echelle log
 | 
|---|
| 39 | UseScale();
 | 
|---|
| 40 | UseColors();
 | 
|---|
| 41 | UseDisplay();
 | 
|---|
| 42 | UseDyn();
 | 
|---|
| 43 | UseFrac();
 | 
|---|
| 44 | SetStats();
 | 
|---|
| 45 |  SetStatPosOffset();
 | 
|---|
| 46 | SetName("Histo2DDrw"); 
 | 
|---|
| 47 | // PIHisto2D has specific control tools
 | 
|---|
| 48 | mFgSpecContWind = true;
 | 
|---|
| 49 | }
 | 
|---|
| 50 | 
 | 
|---|
| 51 | //++
 | 
|---|
| 52 | PIHisto2D::~PIHisto2D()
 | 
|---|
| 53 | //
 | 
|---|
| 54 | //      Destructeur.
 | 
|---|
| 55 | //--
 | 
|---|
| 56 | {
 | 
|---|
| 57 | // La fonction virtuelle DeactivateControlWindow() doit etre appele
 | 
|---|
| 58 | // a ce niveau - En effet au niveau du destructeur de base, il 
 | 
|---|
| 59 | // semble pointer sur la fonction de la classe de base
 | 
|---|
| 60 | //                    Reza - Octobre 2002 
 | 
|---|
| 61 | // Desactivation totale de la fenetre de controle specialise 
 | 
|---|
| 62 | // ---> parametre d'appel PIBaseWdgGen* wdg=NULL
 | 
|---|
| 63 | DeactivateControlWindow(NULL);
 | 
|---|
| 64 | if(mAdDO && mHisto!=NULL) delete mHisto;
 | 
|---|
| 65 | }
 | 
|---|
| 66 | 
 | 
|---|
| 67 | //++
 | 
|---|
| 68 | void PIHisto2D::UseColors(bool fg,CMapId cmap,bool revcmap)
 | 
|---|
| 69 | //
 | 
|---|
| 70 | //      Choix de la couleur si fg=true avec la color map cmap.
 | 
|---|
| 71 | //      (pour la couleur cmap cf picmap.h).
 | 
|---|
| 72 | //      Independamment du choix du display, la dynamique est
 | 
|---|
| 73 | //      codee sur la color map donnant ainsi une double
 | 
|---|
| 74 | //      information. Par exemple, carres de tailles variables
 | 
|---|
| 75 | //      en couleur. Cette option est incontournable dans le cas
 | 
|---|
| 76 | //      d'un display par des carres de taille fixe.
 | 
|---|
| 77 | //      revcmap doit etre mis a "true" si on veut avoir une color map
 | 
|---|
| 78 | //      inversee.
 | 
|---|
| 79 | //| -**- gestion dans H2WinArg par menu deroulant Black&White etc...
 | 
|---|
| 80 | //--
 | 
|---|
| 81 | {
 | 
|---|
| 82 | mFgCol = fg; mCmap = cmap; mRevCmap = revcmap;
 | 
|---|
| 83 | }
 | 
|---|
| 84 | 
 | 
|---|
| 85 | //++
 | 
|---|
| 86 | void PIHisto2D::UseScale(unsigned short type,float logscale)
 | 
|---|
| 87 | //
 | 
|---|
| 88 | //      Pour changer les echelles (lineaire ou logarithmique)
 | 
|---|
| 89 | //| Type = 0 : echelle lineaire
 | 
|---|
| 90 | //|      = 1 : echelle log10
 | 
|---|
| 91 | //| -**- Explication du codage en type=0 (lineaire) :
 | 
|---|
| 92 | //|   1. [hmin,hmax] -> [0,1]
 | 
|---|
| 93 | //|           h      ->   f = (h-hmin)/(hmax-hmin)
 | 
|---|
| 94 | //|   2. codage de f=[0,1] sur la dynamique du display choisi
 | 
|---|
| 95 | //| -**- Explication du codage en type=1 (logarithmique base 10) :
 | 
|---|
| 96 | //|   1. map lineaire entre 0 et 1:
 | 
|---|
| 97 | //|      [hmin,hmax] -> [0,1]
 | 
|---|
| 98 | //|           h      ->   f = (h-hmin)/(hmax-hmin)
 | 
|---|
| 99 | //|   2. transformation logarithmique de base 10 :
 | 
|---|
| 100 | //|      [0,1] -> [0,1]
 | 
|---|
| 101 | //|        f   -> lf = log10(1.+f*(logscale-1))/log10(logscale)
 | 
|---|
| 102 | //|   3. codage de lf=[0,1] sur la dynamique du display choisi
 | 
|---|
| 103 | //| -**- gestion dans H2WinArg par menu deroulant Lineaire/Log10
 | 
|---|
| 104 | //|         et "logscale" par saisie de valeur dans champ LogScal
 | 
|---|
| 105 | //--
 | 
|---|
| 106 | {
 | 
|---|
| 107 | if(type==0)       mTypScal=0;
 | 
|---|
| 108 | else if(type==1) {mTypScal=1; if(logscale>1.) mLogScale=logscale;}
 | 
|---|
| 109 | else              mTypScal=0;
 | 
|---|
| 110 | }
 | 
|---|
| 111 | 
 | 
|---|
| 112 | //++
 | 
|---|
| 113 | void PIHisto2D::UseDisplay(unsigned short type,float fnpt)
 | 
|---|
| 114 | //
 | 
|---|
| 115 | //      Type de Display
 | 
|---|
| 116 | //| Type = 0 : carres de tailles variables
 | 
|---|
| 117 | //| Type = 1 : nuages de points
 | 
|---|
| 118 | //|            Le nombre de points a utiliser est fnpt*N
 | 
|---|
| 119 | //|            ou N est le nombre de pixels ecran contenu
 | 
|---|
| 120 | //|            dans un bin de l'histogramme.
 | 
|---|
| 121 | //| Type = 2 : code a la "hbook2" " .+123...9AB...YZ*"
 | 
|---|
| 122 | //|            (cf detail PIHisto2D::HPrint2)
 | 
|---|
| 123 | //| Type = 3 : carres de taille fixe (couleur).
 | 
|---|
| 124 | //| -**- gestion dans H2WinArg par menu deroulant Carres_Var etc...
 | 
|---|
| 125 | //|         et "fnpt" par saisie de valeur dans champ PerPt
 | 
|---|
| 126 | //--
 | 
|---|
| 127 | {
 | 
|---|
| 128 | if(type==0) mTypDisp = 0;
 | 
|---|
| 129 | else if(type==1) {
 | 
|---|
| 130 |   mTypDisp = 1;
 | 
|---|
| 131 |   if(fnpt<0.) mFPoints = 0.;
 | 
|---|
| 132 |     else if(fnpt>1.) mFPoints = 1.;
 | 
|---|
| 133 |       else mFPoints = fnpt;
 | 
|---|
| 134 | }
 | 
|---|
| 135 | else if(type==2) mTypDisp = 2;
 | 
|---|
| 136 | else if(type==3) mTypDisp = 3;
 | 
|---|
| 137 | else             mTypDisp = 1;
 | 
|---|
| 138 | }
 | 
|---|
| 139 | 
 | 
|---|
| 140 | //++
 | 
|---|
| 141 | void PIHisto2D::UseDyn(float hmin,float hmax)
 | 
|---|
| 142 | //
 | 
|---|
| 143 | //      Gestion de la dynamique a representer:
 | 
|---|
| 144 | //|  La dynamique va etre transformee de [hmin,hmax] vers [0,1] selon
 | 
|---|
| 145 | //|  [hmin,hmax] -> [0,1]
 | 
|---|
| 146 | //|       h      ->   f = (h-hmin)/(hmax-hmin)
 | 
|---|
| 147 | //|  Par la suite, selon ce qui est demande, f va coder le display 
 | 
|---|
| 148 | //|  ou etre transforme en une autre echelle [0,1] (ex: echelle log10).
 | 
|---|
| 149 | //|  Si hmax<=hmin, ils sont forces a la dynamique totale de l'histo2D.
 | 
|---|
| 150 | //| -**- gestion dans H2WinArg par saisie de valeurs dans champ Dyn
 | 
|---|
| 151 | //--
 | 
|---|
| 152 | {
 | 
|---|
| 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;
 | 
|---|
| 157 | }
 | 
|---|
| 158 | 
 | 
|---|
| 159 | //++
 | 
|---|
| 160 | void PIHisto2D::UseFrac(float frmin,float frmax)
 | 
|---|
| 161 | //
 | 
|---|
| 162 | //      Pour definir la fraction de la dynamique a dessiner:
 | 
|---|
| 163 | //| Selon le type de display (f=[0,1] cf PIHisto2D::UseDyn),
 | 
|---|
| 164 | //|  - on ne dessine rien si f <= frmin dans les cas de display avec
 | 
|---|
| 165 | //|    des nuages de points ou des carres de tailles variables.
 | 
|---|
| 166 | //|    Pour un display "a la hbook2" on force frmin = 0.
 | 
|---|
| 167 | //|  - frmax n'est utilise que pour la representation avec
 | 
|---|
| 168 | //|    des carres de tailles variables: c'est la taille
 | 
|---|
| 169 | //|    maximum que peut avoir le carre exprimee en unite
 | 
|---|
| 170 | //|    de la taille du bin (ex: si frmax=0.8 le carre
 | 
|---|
| 171 | //|    le + grand qui pourra etre dessine dans un bin
 | 
|---|
| 172 | //|    aura une taille egale a 0.8*(taille du bin)).
 | 
|---|
| 173 | //| -**- gestion dans H2WinArg par saisie de valeurs dans champ Frac
 | 
|---|
| 174 | //--
 | 
|---|
| 175 | {
 | 
|---|
| 176 | if(frmin<0.  || frmin>=1.) frmin = 0.;
 | 
|---|
| 177 | if(frmax<=0. || frmax>1. ) frmax = 1.;
 | 
|---|
| 178 | if(frmin>=frmax) {frmin=0.1; frmax=0.9;}
 | 
|---|
| 179 | mFracMin = frmin; mFracMax = frmax;
 | 
|---|
| 180 | }
 | 
|---|
| 181 | 
 | 
|---|
| 182 | //++
 | 
|---|
| 183 | void PIHisto2D::Print(int lp)
 | 
|---|
| 184 | //
 | 
|---|
| 185 | //      Print de l'etat des options du display.
 | 
|---|
| 186 | //--
 | 
|---|
| 187 | {
 | 
|---|
| 188 | printf("PIHisto2D::Print FgCol=%d Cmap=%d (Rev=%d) TypScal=%d TypDisp=%d (FPoints=%g)\n"
 | 
|---|
| 189 |       ,(int)mFgCol,(int)mCmap,(int)mRevCmap,mTypScal,mTypDisp,mFPoints);
 | 
|---|
| 190 | 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();
 | 
|---|
| 193 | fflush(stdout);
 | 
|---|
| 194 | }
 | 
|---|
| 195 | 
 | 
|---|
| 196 | //++
 | 
|---|
| 197 | void PIHisto2D::UpdateLimits()
 | 
|---|
| 198 | //
 | 
|---|
| 199 | //      Definition des tailles graphiques en fonction
 | 
|---|
| 200 | //      des caracteristiques de l'histogramme a dessiner.
 | 
|---|
| 201 | //--
 | 
|---|
| 202 | {
 | 
|---|
| 203 |  if(!mHisto) return;
 | 
|---|
| 204 |  SetLimits(mHisto->XMin(), mHisto->XMax(), mHisto->YMin() , mHisto->YMax());
 | 
|---|
| 205 | }
 | 
|---|
| 206 | 
 | 
|---|
| 207 | //++
 | 
|---|
| 208 | void PIHisto2D::ShowControlWindow(PIBaseWdgGen* wdg)
 | 
|---|
| 209 | //
 | 
|---|
| 210 | //      Affichage de la fenetre de controle H2WinArg
 | 
|---|
| 211 | //--
 | 
|---|
| 212 | {
 | 
|---|
| 213 |   H2WinArg::SetCurrentPIHisto2D(this);
 | 
|---|
| 214 |   H2WinArg::ShowPIHisto2DTools(wdg);
 | 
|---|
| 215 | }
 | 
|---|
| 216 | 
 | 
|---|
| 217 | //++
 | 
|---|
| 218 | void PIHisto2D::DeactivateControlWindow(PIBaseWdgGen* wdg)
 | 
|---|
| 219 | //
 | 
|---|
| 220 | //      Desactivation de la fenetre de controle specialisee
 | 
|---|
| 221 | //--
 | 
|---|
| 222 | {
 | 
|---|
| 223 |   if (H2WinArg::GetCurrentPIHisto2D() == this) { 
 | 
|---|
| 224 |     // si wdg != NULL, c'est un Detach (Drawer detache du PIBaseWdg
 | 
|---|
| 225 |     // si wdg == NULL, c'est un delete du PIHisto2D (du PIDrawer)
 | 
|---|
| 226 |     if ((wdg == NULL) || (H2WinArg::GetCurrentBaseWdg() == wdg)) {
 | 
|---|
| 227 |       H2WinArg::SetCurrentBaseWdg(NULL);
 | 
|---|
| 228 |       H2WinArg::SetCurrentPIHisto2D(NULL);
 | 
|---|
| 229 |       H2WinArg::HidePIHisto2DTools();
 | 
|---|
| 230 |     }
 | 
|---|
| 231 |   }
 | 
|---|
| 232 |   PIDrawer::DeactivateControlWindow(wdg);
 | 
|---|
| 233 |   return;
 | 
|---|
| 234 | }
 | 
|---|
| 235 | 
 | 
|---|
| 236 | //++
 | 
|---|
| 237 | void PIHisto2D::Draw(PIGraphicUC* g,double xmin,double ymin,double xmax,double ymax)
 | 
|---|
| 238 | //
 | 
|---|
| 239 | //      Dessin de l'histogramme.
 | 
|---|
| 240 | //| -**- Code de dessin selon choix des options:
 | 
|---|
| 241 | //|  (detail voir UseColors UseScale UseDisplay UseDyn UseFrac)
 | 
|---|
| 242 | //|  - [hmin,hmax] -> f=[0,1]
 | 
|---|
| 243 | //|    (Choix hmin,hmax champ Dyn de H2WinArg)
 | 
|---|
| 244 | //|  - Eventuellement ech Log -> re-codage log10 entre f=[0,1]
 | 
|---|
| 245 | //|    (Choix menu deroulant et champ LogScal de H2WinArg)
 | 
|---|
| 246 | //|  - Restriction de f=[0,1] -> f=[Frac(min),Frac(max)]
 | 
|---|
| 247 | //|    (Choix champ Frac de H2WinArg)
 | 
|---|
| 248 | //| -**- Puis selon display:
 | 
|---|
| 249 | //|  0 carres variables, menu "Carres Var." de H2WinArg:
 | 
|---|
| 250 | //|      if(f>Frac(min)) taille carre = f * Frac(max) * taille_du_bin
 | 
|---|
| 251 | //|  1 nuage de points, menu "....." et champ PerPt de H2WinArg:
 | 
|---|
| 252 | //|      if(f>Frac(min)) npoints = f * PerPt * npoints_ecran_dans_bin
 | 
|---|
| 253 | //|  2 code hbook2, menu ".12..Z*" de H2WinArg:
 | 
|---|
| 254 | //|      if(f>0) map de f=]0,1] dans ".+...Z*"
 | 
|---|
| 255 | //|  3 carres pleins, menu "Carres Pleins" et couleurs de H2WinArg):
 | 
|---|
| 256 | //|      couleur = lut[ f * nombre_d_entree_dans_la_lut ]
 | 
|---|
| 257 | //--
 | 
|---|
| 258 | {
 | 
|---|
| 259 | if (axesFlags != kAxesNone) DrawAxes(g);
 | 
|---|
| 260 | 
 | 
|---|
| 261 | if(!mHisto) return;
 | 
|---|
| 262 | // Caracteristiques histogramme
 | 
|---|
| 263 | double dx = mHisto->WBinX(),dy = mHisto->WBinY();
 | 
|---|
| 264 | double p1dx,p1dy;
 | 
|---|
| 265 | g->DGrC2UC(1.,1.,p1dx,p1dy);
 | 
|---|
| 266 | 
 | 
|---|
| 267 | // Gamme a representer entre [0,1] mais >=fracmin et scale fracmax
 | 
|---|
| 268 | float fracmin=FMin(), fracmax=FMax();
 | 
|---|
| 269 | float llscale = (float) log10((double)LogScale());
 | 
|---|
| 270 | 
 | 
|---|
| 271 | // gestion Couleurs.
 | 
|---|
| 272 | PIColors fgcoul = GetGraphicAtt().GetFgColor();
 | 
|---|
| 273 | PIColors bgcoul = GetGraphicAtt().GetBgColor();
 | 
|---|
| 274 | PIColorMap* cmap=NULL;
 | 
|---|
| 275 | int ncol = 0;
 | 
|---|
| 276 | if (mFgCol) {
 | 
|---|
| 277 |   cmap = new PIColorMap(mCmap);
 | 
|---|
| 278 |   cmap->ReverseColorIndex(mRevCmap);
 | 
|---|
| 279 |   ncol = cmap->NCol();
 | 
|---|
| 280 |   if(mTypDisp==3) fracmin=-1.;
 | 
|---|
| 281 | }
 | 
|---|
| 282 | 
 | 
|---|
| 283 | // gestion epaisseur de ligne
 | 
|---|
| 284 | PILineAtt LineAtt = GetGraphicAtt().GetLineAtt();
 | 
|---|
| 285 | if(LineAtt == PI_NotDefLineAtt) GetGraphicAtt().SetLineAtt(PI_ThinLine);
 | 
|---|
| 286 | 
 | 
|---|
| 287 | // gestion Markers ou plot avec des points.
 | 
|---|
| 288 | PIMarker Mk = GetGraphicAtt().GetMarker();
 | 
|---|
| 289 | int MkSz = GetGraphicAtt().GetMarkerSize();
 | 
|---|
| 290 | int npt = 1;
 | 
|---|
| 291 | if(mTypDisp==1) {
 | 
|---|
| 292 |   g->SelMarker(1,PI_DotMarker);
 | 
|---|
| 293 |   npt = (int) ((float)NPixBin(g)*FPoints()); if(npt<=0) npt = 2;
 | 
|---|
| 294 | }
 | 
|---|
| 295 | 
 | 
|---|
| 296 | // gestion Font.
 | 
|---|
| 297 | PIFontAtt FontAtt = GetGraphicAtt().GetFontAtt();
 | 
|---|
| 298 | int FontSize = GetGraphicAtt().GetFontSzPt();
 | 
|---|
| 299 | if(mTypDisp==2) {
 | 
|---|
| 300 |   double dxg,dyg,dg;
 | 
|---|
| 301 |   g->DUC2GrC(dx,dy,dxg,dyg);
 | 
|---|
| 302 |   dg =(dxg<dyg) ? dxg : dyg;
 | 
|---|
| 303 |   int npix = (int) (dg*0.9); if(npix<8) npix = 8;
 | 
|---|
| 304 |   g->SelFontSzPt(npix,FontAtt);
 | 
|---|
| 305 |   fracmin = 0;
 | 
|---|
| 306 | }
 | 
|---|
| 307 | 
 | 
|---|
| 308 | // Plot de l'histogramme
 | 
|---|
| 309 | for(int i=0; i<mHisto->NBinX(); i++)
 | 
|---|
| 310 |   for(int j=0; j<mHisto->NBinY(); j++) {
 | 
|---|
| 311 | 
 | 
|---|
| 312 |   r_8 left0,bottom0;
 | 
|---|
| 313 |   mHisto->BinLowEdge(i,j,left0,bottom0);
 | 
|---|
| 314 | 
 | 
|---|
| 315 |   // Gestion de la dynamique a dessiner
 | 
|---|
| 316 |   float frac = ((*mHisto)(i,j)-HMin())/(HMax()-HMin());
 | 
|---|
| 317 |   if(frac<0.) continue;
 | 
|---|
| 318 |   if(mTypScal==1) {              // echelle log10
 | 
|---|
| 319 |     frac = log10(1.+frac*(LogScale()-1.))/llscale;
 | 
|---|
| 320 |     if(frac<0.) continue;
 | 
|---|
| 321 |   }
 | 
|---|
| 322 |   if(frac<=fracmin) continue;
 | 
|---|
| 323 |   if(frac>1.) frac = 1.;
 | 
|---|
| 324 |   float fracred = frac * fracmax;
 | 
|---|
| 325 | 
 | 
|---|
| 326 |   // Gestion de la couleur
 | 
|---|
| 327 |   int icol = 0;
 | 
|---|
| 328 |   if (cmap) {
 | 
|---|
| 329 |     icol = int( (float) ncol*frac );
 | 
|---|
| 330 |     if(icol>=ncol) icol = ncol-1; else if(icol<0) icol=0;
 | 
|---|
| 331 |     g->SelForeground(*cmap,icol);
 | 
|---|
| 332 |   }
 | 
|---|
| 333 | 
 | 
|---|
| 334 | // Pour ne pas dessiner en dehors des axes 
 | 
|---|
| 335 |   if ( (left0+dx/2. < xmin) || (left0+dx/2. > xmax) || 
 | 
|---|
| 336 |          (bottom0+dy/2. < ymin) || (bottom0+dy/2. > ymax) ) continue;
 | 
|---|
| 337 | 
 | 
|---|
| 338 |   // Dessin proprement dit selon le choix graphique.
 | 
|---|
| 339 |   if(mTypDisp==0) {
 | 
|---|
| 340 |     //..... carres de tailles variables
 | 
|---|
| 341 |     double left   = left0   + 0.5*(1.-fracred)*dx, width  = fracred*dx;
 | 
|---|
| 342 |     double bottom = bottom0 + 0.5*(1.-fracred)*dy, height = fracred*dy;
 | 
|---|
| 343 |     if (cmap) g->DrawFBox(left,bottom,width,height);
 | 
|---|
| 344 |     else      g->DrawBox(left,bottom,width,height);
 | 
|---|
| 345 |   } else if(mTypDisp==1) {
 | 
|---|
| 346 |     //..... nuage de points .....
 | 
|---|
| 347 |     int ipt  = int( (float) npt *frac );
 | 
|---|
| 348 |     for(int k=0;k<ipt;k++) {
 | 
|---|
| 349 |       double x = left0 + frand01()*dx;
 | 
|---|
| 350 |       double y = bottom0 + frand01()*dy;
 | 
|---|
| 351 |       g->DrawMarker(x,y);
 | 
|---|
| 352 |     }
 | 
|---|
| 353 |   } else if(mTypDisp==2) {
 | 
|---|
| 354 |     //..... type hbook2/hprint .+23-Z*
 | 
|---|
| 355 |     char c[2];
 | 
|---|
| 356 |     c[0] = HPrint2(frac); c[1]='\0';
 | 
|---|
| 357 |     double x = left0 + dx/2.;
 | 
|---|
| 358 |     double y = bottom0 + dy/2.;
 | 
|---|
| 359 |     g->DrawString(x,y,c,PI_HorizontalCenter|PI_VerticalCenter);
 | 
|---|
| 360 |   } else if(mTypDisp==3) {
 | 
|---|
| 361 |     //..... carres de tailles fixes (avec gestion de continuite)
 | 
|---|
| 362 |     if (cmap) g->DrawFBox(left0,bottom0,dx+p1dx,dy+p1dy);
 | 
|---|
| 363 |     else      g->DrawBox(left0,bottom0,dx+p1dx,dy+p1dy);
 | 
|---|
| 364 |   }
 | 
|---|
| 365 | 
 | 
|---|
| 366 | }
 | 
|---|
| 367 | 
 | 
|---|
| 368 | // Remise dans les conditions ulterieures pour la suite du graphique.
 | 
|---|
| 369 | GetGraphicAtt().SetMarkerAtt(MkSz,Mk);
 | 
|---|
| 370 | GetGraphicAtt().SetColAtt(fgcoul,bgcoul);
 | 
|---|
| 371 | g->SelFontSzPt(FontSize,FontAtt);
 | 
|---|
| 372 | GetGraphicAtt().SetLineAtt(LineAtt);
 | 
|---|
| 373 | if (cmap) delete cmap;
 | 
|---|
| 374 | 
 | 
|---|
| 375 | // Fin du dessin, ecriture de la statistique.
 | 
|---|
| 376 | if(stats) DrawStats(g);
 | 
|---|
| 377 | }
 | 
|---|
| 378 | 
 | 
|---|
| 379 | //++
 | 
|---|
| 380 | void PIHisto2D::GetClickInfo(string& info,double x,double y,double x0,double y0,bool fgdiff)
 | 
|---|
| 381 | //
 | 
|---|
| 382 | //      Info specifique du drawer pour la position x,y
 | 
|---|
| 383 | //--
 | 
|---|
| 384 | {
 | 
|---|
| 385 | Histo2D* h = Histogram();
 | 
|---|
| 386 | if(h == NULL) return;
 | 
|---|
| 387 | 
 | 
|---|
| 388 | int i,j;
 | 
|---|
| 389 | h->FindBin(x,y,i,j);
 | 
|---|
| 390 | if(i>=0 && i<h->NBinX() && j>=0 && j<h->NBinY()) {
 | 
|---|
| 391 |   char str[64];
 | 
|---|
| 392 |   if(fgdiff) {
 | 
|---|
| 393 |     int i0,j0;
 | 
|---|
| 394 |     h->FindBin(x0,y0,i0,j0);
 | 
|---|
| 395 |     if(i0>=0 && i0<h->NBinX() && j0>=0 && j0<h->NBinY()) {
 | 
|---|
| 396 |       sprintf(str," DV=%g",(*h)(i,j)-(*h)(i0,j0));
 | 
|---|
| 397 |       info += str;
 | 
|---|
| 398 |     } else {
 | 
|---|
| 399 |       info += " DV=?";
 | 
|---|
| 400 |     }
 | 
|---|
| 401 |   }
 | 
|---|
| 402 |   sprintf(str," V=%g",(*h)(i,j));
 | 
|---|
| 403 |   info += str;
 | 
|---|
| 404 | } else {
 | 
|---|
| 405 |   info += " V=?";
 | 
|---|
| 406 | }
 | 
|---|
| 407 | 
 | 
|---|
| 408 | return;
 | 
|---|
| 409 | }
 | 
|---|
| 410 | 
 | 
|---|
| 411 | //++
 | 
|---|
| 412 | void PIHisto2D::DrawStats(PIGraphicUC* g)
 | 
|---|
| 413 | //
 | 
|---|
| 414 | //      Dessin des informations statistiques de l'histogramme.
 | 
|---|
| 415 | //--
 | 
|---|
| 416 | {
 | 
|---|
| 417 |   if (!mHisto) return;
 | 
|---|
| 418 |   if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt)  g->SelLine(PI_ThinLine);
 | 
|---|
| 419 |   g->SelFontSz((YMax() - YMin())/30);
 | 
|---|
| 420 | 
 | 
|---|
| 421 |   // La hauteur de la cellule
 | 
|---|
| 422 |   PIGrCoord a, d;
 | 
|---|
| 423 |   double cH = (double)g->GetFontHeight(a,d);
 | 
|---|
| 424 |   double cellHeight = 1.2 * cH;
 | 
|---|
| 425 | 
 | 
|---|
| 426 |   // Les labels et leurs longueurs -> largeur de la cellule
 | 
|---|
| 427 |   char label[64];
 | 
|---|
| 428 |   sprintf(label,"N= %-g", mHisto->NData());
 | 
|---|
| 429 |   double cellWidth =  1.1 * (double)g->CalcStringWidth(label);
 | 
|---|
| 430 | 
 | 
|---|
| 431 |   double ofpx = spoX*(XMax()-XMin());
 | 
|---|
| 432 |   double ofpy = spoY*(YMax()-YMin());
 | 
|---|
| 433 | 
 | 
|---|
| 434 |   double xu, yu, cw;
 | 
|---|
| 435 |   // Les limites du cadre
 | 
|---|
| 436 |   xu = g->DeltaUCX(XMax(), -cellWidth);
 | 
|---|
| 437 |   yu = g->DeltaUCY(YMax(), -cellHeight);
 | 
|---|
| 438 |   double recw = XMax()-xu;
 | 
|---|
| 439 |   double rech = YMax()-yu;
 | 
|---|
| 440 |   xu += ofpx;  yu += ofpy;
 | 
|---|
| 441 |   g->DrawBox(xu, yu, recw, rech);
 | 
|---|
| 442 | 
 | 
|---|
| 443 |   // L'ecriture des labels
 | 
|---|
| 444 |   cw = (g->isAxeXDirRtoL()) ? -0.05*cellWidth : -0.95*cellWidth;
 | 
|---|
| 445 |   xu = g->DeltaUCX(XMax(),cw);
 | 
|---|
| 446 |   cw = (g->isAxeYDirUpDown()) ? -0.1*cH : -1.1*cH;
 | 
|---|
| 447 |   yu = g->DeltaUCY(YMax(),cw);
 | 
|---|
| 448 |   xu += ofpx;  yu += ofpy;
 | 
|---|
| 449 |   g->DrawString(xu,yu,label);
 | 
|---|
| 450 | 
 | 
|---|
| 451 |   //  printf("H[%d,%d] Dynamique: [%g,%g] Frac [%g,%g]\n"
 | 
|---|
| 452 |   //        ,mHisto->NBinX(),mHisto->NBinY(),HMin(),HMax(),FMin(),FMax());
 | 
|---|
| 453 | }
 | 
|---|
| 454 | 
 | 
|---|
| 455 | //++
 | 
|---|
| 456 | char PIHisto2D::HPrint2(float f)
 | 
|---|
| 457 | //
 | 
|---|
| 458 | //      Codage des valeurs en caracteres (fct privee).
 | 
|---|
| 459 | //| f entre [0,1] mappee entre valeur=[0,37]
 | 
|---|
| 460 | //| si <0 alors =0, si >1 alors 1
 | 
|---|
| 461 | //| Display 4   ==> 4<=valeur<5
 | 
|---|
| 462 | //|         C   ==> 12<=valeur<13
 | 
|---|
| 463 | //|             ==> valeur<=0
 | 
|---|
| 464 | //|         *   ==> valeur>=1
 | 
|---|
| 465 | //|         .   ==> 0<valeur<1
 | 
|---|
| 466 | //|------------------------------------------
 | 
|---|
| 467 | //|             1         2         3
 | 
|---|
| 468 | //|   01234567890123456789012345678901234567
 | 
|---|
| 469 | //|   .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ* 
 | 
|---|
| 470 | //|------------------------------------------
 | 
|---|
| 471 | //--
 | 
|---|
| 472 | {
 | 
|---|
| 473 | char str[39] = " .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*";
 | 
|---|
| 474 | int i;
 | 
|---|
| 475 | if(f<=0.) i = 0;
 | 
|---|
| 476 | else if(f>=1.) i = 37;
 | 
|---|
| 477 | else { i = (int) (f*36.); i++;}
 | 
|---|
| 478 | if(i<0) i=0; else if (i>=38) i = 37;
 | 
|---|
| 479 | return str[i];
 | 
|---|
| 480 | }
 | 
|---|
| 481 | 
 | 
|---|
| 482 | //++
 | 
|---|
| 483 | int PIHisto2D::NPixBin(PIGraphicUC* g)
 | 
|---|
| 484 | //
 | 
|---|
| 485 | //      Nombre de pixels ecran dans un bin d'histogramme
 | 
|---|
| 486 | //      (fct privee).
 | 
|---|
| 487 | //--
 | 
|---|
| 488 | {
 | 
|---|
| 489 | double dx = mHisto->WBinX(),dy = mHisto->WBinY();
 | 
|---|
| 490 | double dxg,dyg;
 | 
|---|
| 491 | g->DUC2GrC(dx,dy,dxg,dyg);
 | 
|---|
| 492 | int np = (int) dxg * (int) dyg;
 | 
|---|
| 493 | //printf("PIHisto2D::NPixBin H dx=%g dy=%g, G dx=%g dy=%g, np = %d\n"
 | 
|---|
| 494 | //      ,dx,dy,dxg,dyg,np);
 | 
|---|
| 495 | return np;
 | 
|---|
| 496 | }
 | 
|---|
| 497 | 
 | 
|---|
| 498 | //++
 | 
|---|
| 499 | int PIHisto2D::DecodeOptionString(vector<string> & opt, bool rmdecopt)
 | 
|---|
| 500 | //
 | 
|---|
| 501 | //      Decodage des options
 | 
|---|
| 502 | //--
 | 
|---|
| 503 | {
 | 
|---|
| 504 |   // Decodage des options generales pidrawer
 | 
|---|
| 505 |   int optsz1 = opt.size();
 | 
|---|
| 506 |   if(optsz1<1) return(0); 
 | 
|---|
| 507 |   int ndec1 = PIDrawer::DecodeOptionString(opt, rmdecopt);
 | 
|---|
| 508 |   if(optsz1-ndec1<1) return(ndec1);  // si tout a ete decode
 | 
|---|
| 509 | 
 | 
|---|
| 510 |   // Options generales pidrawer interessant le display Histo2D
 | 
|---|
| 511 |   bool rev; 
 | 
|---|
| 512 |   if(GetGraphicAtt().GetColMapId(rev) != CMAP_OTHER) {
 | 
|---|
| 513 |     UseColors(true,GetGraphicAtt().GetColMapId(),rev);
 | 
|---|
| 514 |   } else UseColors(false);
 | 
|---|
| 515 | 
 | 
|---|
| 516 |   // Decodage des options propres au display Histo2D
 | 
|---|
| 517 |   vector<string> udopt;  // On gardera ici les options non decodees
 | 
|---|
| 518 |   unsigned int k = 0;
 | 
|---|
| 519 |   int ndec = opt.size();
 | 
|---|
| 520 |   bool listopt=false;
 | 
|---|
| 521 |   for( k=0; k<opt.size(); k++ ) {
 | 
|---|
| 522 |     string opts = opt[k];
 | 
|---|
| 523 |     if(opts=="h2help") {
 | 
|---|
| 524 |       string info; GetOptionsHelpInfo(info);
 | 
|---|
| 525 |       size_t q = info.find("PIHisto2D");
 | 
|---|
| 526 |       if(q<info.length()-1) cout<<info.substr(q)<<endl;
 | 
|---|
| 527 |     } else if(opts=="h2list") {
 | 
|---|
| 528 |       listopt=true;
 | 
|---|
| 529 |     } else if(opts=="sta" || opts=="stat" || opts=="stats") {
 | 
|---|
| 530 |       SetStats(true);
 | 
|---|
| 531 |     } else if(  opts=="nsta"   || opts=="nstat"
 | 
|---|
| 532 |              || opts=="nostat" || opts=="nostats") {
 | 
|---|
| 533 |       SetStats(false);
 | 
|---|
| 534 |     } else  if(opts.substr(0,11) == "statposoff=") {
 | 
|---|
| 535 |       float xo=0., yo=0.;
 | 
|---|
| 536 |       sscanf(opts.substr(11).c_str(),"%g,%g",&xo, &yo);
 | 
|---|
| 537 |       SetStatPosOffset(xo, yo);
 | 
|---|
| 538 |     } else if(opts.substr(0,8)=="h2scale=") {
 | 
|---|
| 539 |       unsigned short t=TypScale(); float ls=LogScale();
 | 
|---|
| 540 |       if(opts.substr(8,3)=="lin") t=0;
 | 
|---|
| 541 |       else if(opts.substr(8,3)=="log")
 | 
|---|
| 542 |         {t=1; sscanf(opts.c_str(),"h2scale=log,%g",&ls);}
 | 
|---|
| 543 |       UseScale(t,ls);
 | 
|---|
| 544 |     } else if(opts.substr(0,7)=="h2disp=") {
 | 
|---|
| 545 |       unsigned short t=TypDisplay(); float fpts=FPoints();
 | 
|---|
| 546 |       if(opts.substr(7,3)=="var") t=0;
 | 
|---|
| 547 |       else if(opts.substr(7,3)=="hbk") t=2;
 | 
|---|
| 548 |       else if(opts.substr(7,3)=="img") t=3;
 | 
|---|
| 549 |       else if(opts.substr(7,3)=="pts")
 | 
|---|
| 550 |         {t=1; sscanf(opts.c_str(),"h2disp=pts,%g",&fpts);}
 | 
|---|
| 551 |       UseDisplay(t,fpts);
 | 
|---|
| 552 |     } else if(opts.substr(0,6)=="h2dyn=") {
 | 
|---|
| 553 |       float hmin=HMin(),hmax=HMax(); size_t q = opts.find(',');
 | 
|---|
| 554 |       sscanf(opts.c_str(),"h2dyn=%g",&hmin);
 | 
|---|
| 555 |       if(q<opts.length()-1) sscanf(opts.substr(q+1).c_str(),"%g",&hmax);
 | 
|---|
| 556 |       UseDyn(hmin,hmax);
 | 
|---|
| 557 |     } else if(opts.substr(0,7)=="h2frac=") {
 | 
|---|
| 558 |       float fmin=FMin(),fmax=FMax(); size_t q = opts.find(',');
 | 
|---|
| 559 |       sscanf(opts.c_str(),"h2frac=%g",&fmin);
 | 
|---|
| 560 |       if(q<opts.length()-1) sscanf(opts.substr(q+1).c_str(),"%g",&fmax);
 | 
|---|
| 561 |       UseFrac(fmin,fmax);
 | 
|---|
| 562 |    } else {
 | 
|---|
| 563 |       ndec--;
 | 
|---|
| 564 |       // S'il faut supprimer les options decodees
 | 
|---|
| 565 |       if (rmdecopt)  udopt.push_back(opts);
 | 
|---|
| 566 |     }
 | 
|---|
| 567 |   }
 | 
|---|
| 568 | 
 | 
|---|
| 569 |   // S'il faut supprimer les options decodees, on remplace l'argument opt
 | 
|---|
| 570 |   // par le vecteur des options non decodees.
 | 
|---|
| 571 |   if (rmdecopt)  opt = udopt;
 | 
|---|
| 572 | 
 | 
|---|
| 573 |   // Liste des options si demande
 | 
|---|
| 574 |   if(listopt) Print();
 | 
|---|
| 575 | 
 | 
|---|
| 576 |   return(ndec+ndec1);
 | 
|---|
| 577 | }
 | 
|---|
| 578 | 
 | 
|---|
| 579 | int PIHisto2D::OptionToString(vector<string> & opt) const
 | 
|---|
| 580 | {
 | 
|---|
| 581 |  PIDrawer::OptionToString(opt);
 | 
|---|
| 582 |  char str[256];
 | 
|---|
| 583 | 
 | 
|---|
| 584 |  if(stats) opt.push_back("stat"); else opt.push_back("nstat");
 | 
|---|
| 585 | 
 | 
|---|
| 586 |  sprintf(str,"statposoff=%f,%f",spoX,spoY);
 | 
|---|
| 587 |  opt.push_back(str);
 | 
|---|
| 588 | 
 | 
|---|
| 589 |  if(mTypDisp==0) sprintf(str,"h2disp=var");
 | 
|---|
| 590 |   else if(mTypDisp==1) sprintf(str,"h2disp=pts,%g",mFPoints);
 | 
|---|
| 591 |     else if(mTypDisp==2) sprintf(str,"h2disp=hbk");
 | 
|---|
| 592 |       else if(mTypDisp==3) sprintf(str,"h2disp=img");
 | 
|---|
| 593 |  opt.push_back(str);
 | 
|---|
| 594 | 
 | 
|---|
| 595 |  if(mTypScal==0) sprintf(str,"h2scale=lin");
 | 
|---|
| 596 |    else if(mTypScal==1) sprintf(str,"h2disp=log,%g",mLogScale);
 | 
|---|
| 597 |  opt.push_back(str);
 | 
|---|
| 598 | 
 | 
|---|
| 599 |  sprintf(str,"h2dyn=%g,%g",mHMin,mHMax);
 | 
|---|
| 600 |  opt.push_back(str);
 | 
|---|
| 601 | 
 | 
|---|
| 602 |  sprintf(str,"h2frac=%g,%g",mFracMin,mFracMax);
 | 
|---|
| 603 |  opt.push_back(str);
 | 
|---|
| 604 | 
 | 
|---|
| 605 |  if(mRevCmap) opt.push_back("revcmap");
 | 
|---|
| 606 | 
 | 
|---|
| 607 |  return 1;
 | 
|---|
| 608 | }
 | 
|---|
| 609 | 
 | 
|---|
| 610 | 
 | 
|---|
| 611 | //++
 | 
|---|
| 612 | void PIHisto2D::GetOptionsHelpInfo(string& info)
 | 
|---|
| 613 | //
 | 
|---|
| 614 | //      Help relatif au options
 | 
|---|
| 615 | //--
 | 
|---|
| 616 | {
 | 
|---|
| 617 | info += " ---- PIHisto2D options help info (see also ALT-O): \n" ;
 | 
|---|
| 618 | info += "- h2help: get this help text\n";
 | 
|---|
| 619 | info += "- h2list: list choosen options\n";
 | 
|---|
| 620 | info += "- sta,stat,stats:            activate   statistic display\n";
 | 
|---|
| 621 | info += "  nsta,nstat,nostat,nostats: deactivate statistic display\n";
 | 
|---|
| 622 | info += "- h2disp=typ[,fracpts]: choose display type\n";
 | 
|---|
| 623 | info += "    typ=var: variable size boxes\n";
 | 
|---|
| 624 | info += "    typ=hbk: \"a la hbook2\"\n";
 | 
|---|
| 625 | info += "    typ=img: image like (use \"h2col\" for color map)\n";
 | 
|---|
| 626 | info += "    typ=pts: point clouds (fracpts=max possible fraction\n";
 | 
|---|
| 627 | info += "             of used pixels per bin [0,1])\n";
 | 
|---|
| 628 | info += "- h2scale=lin/log[,logscale]: choose linear or logarithmic scale\n";
 | 
|---|
| 629 | info += "- h2dyn=[hmin][,hmax]: choose histogramme range for display\n";
 | 
|---|
| 630 | info += "- use general key to define color table (ex: grey32,midas_heat,...)\n";
 | 
|---|
| 631 | info += "            (see general graphicatt description)\n";
 | 
|---|
| 632 | info += "- use key \"revcmap\" to reverse color table\n";
 | 
|---|
| 633 | info += "- h2frac=[fmin][,fmax]: choose sub-range display [0,1]\n";
 | 
|---|
| 634 | // On recupere ensuite la chaine info de la classe de base
 | 
|---|
| 635 | PIDrawer::GetOptionsHelpInfo(info);
 | 
|---|
| 636 | return;
 | 
|---|
| 637 | }
 | 
|---|
| 638 | 
 | 
|---|
| 639 | /////////////////////////////////////////////////////////////////
 | 
|---|
| 640 | //  Classe H2WinArg
 | 
|---|
| 641 | /////////////////////////////////////////////////////////////////
 | 
|---|
| 642 | //++
 | 
|---|
| 643 | // Class        H2WinArg
 | 
|---|
| 644 | // Lib          PIext
 | 
|---|
| 645 | // include      pihisto2d.h
 | 
|---|
| 646 | //
 | 
|---|
| 647 | //      Fenêtre de dialogue pour le choix des options de tracé pour "PIHisto2D"
 | 
|---|
| 648 | //      Classe de fenêtre de dialogue permettant de modifier interactivement
 | 
|---|
| 649 | //      Les différents attributs de visualisation pour les *PIImage* .
 | 
|---|
| 650 | //--
 | 
|---|
| 651 | //++
 | 
|---|
| 652 | // Links        Parents
 | 
|---|
| 653 | // PIWindow
 | 
|---|
| 654 | //--
 | 
|---|
| 655 | //++
 | 
|---|
| 656 | // Links        Voir aussi
 | 
|---|
| 657 | // PIHisto2D
 | 
|---|
| 658 | // PIH2DWdg
 | 
|---|
| 659 | //--
 | 
|---|
| 660 | 
 | 
|---|
| 661 | //++
 | 
|---|
| 662 | // Titre        Constructeur, méthodes
 | 
|---|
| 663 | //--
 | 
|---|
| 664 | 
 | 
|---|
| 665 | PIBaseWdgGen* H2WinArg::mBWdg = NULL;
 | 
|---|
| 666 | PIHisto2D* H2WinArg::mH2DDrw = NULL;
 | 
|---|
| 667 | static H2WinArg* cur_h2winarg = NULL;
 | 
|---|
| 668 | 
 | 
|---|
| 669 | void H2WinArg::ShowPIHisto2DTools()
 | 
|---|
| 670 | {
 | 
|---|
| 671 |   if (cur_h2winarg == NULL)  cur_h2winarg = new H2WinArg(PIApplicationGetApp());
 | 
|---|
| 672 |   cur_h2winarg->Show();
 | 
|---|
| 673 | }
 | 
|---|
| 674 | 
 | 
|---|
| 675 | void H2WinArg::ShowPIHisto2DTools(PIBaseWdgGen* cbw)
 | 
|---|
| 676 | {
 | 
|---|
| 677 |   if (cur_h2winarg == NULL)  cur_h2winarg = new H2WinArg(PIApplicationGetApp());
 | 
|---|
| 678 |   mBWdg = cbw;
 | 
|---|
| 679 |   cur_h2winarg->Show();
 | 
|---|
| 680 | }
 | 
|---|
| 681 | 
 | 
|---|
| 682 | void H2WinArg::HidePIHisto2DTools()
 | 
|---|
| 683 | {
 | 
|---|
| 684 |   if (cur_h2winarg != NULL)  cur_h2winarg->Hide();
 | 
|---|
| 685 | }
 | 
|---|
| 686 | 
 | 
|---|
| 687 | void H2WinArg::SetCurrentBaseWdg(PIBaseWdgGen* cbw)
 | 
|---|
| 688 | {
 | 
|---|
| 689 |   mBWdg = cbw;
 | 
|---|
| 690 | }
 | 
|---|
| 691 | 
 | 
|---|
| 692 | void H2WinArg::SetCurrentPIHisto2D(PIHisto2D* h2ddrw)
 | 
|---|
| 693 | {
 | 
|---|
| 694 |   mH2DDrw = h2ddrw;
 | 
|---|
| 695 | }
 | 
|---|
| 696 | 
 | 
|---|
| 697 | PIBaseWdgGen* H2WinArg::GetCurrentBaseWdg()
 | 
|---|
| 698 | {
 | 
|---|
| 699 |   return(mBWdg);
 | 
|---|
| 700 | }
 | 
|---|
| 701 | 
 | 
|---|
| 702 | PIHisto2D* H2WinArg::GetCurrentPIHisto2D()
 | 
|---|
| 703 | {
 | 
|---|
| 704 |   return(mH2DDrw);
 | 
|---|
| 705 | }
 | 
|---|
| 706 | 
 | 
|---|
| 707 | //++
 | 
|---|
| 708 | H2WinArg::H2WinArg(PIMsgHandler* par)
 | 
|---|
| 709 | //
 | 
|---|
| 710 | //      Creation de la fenetre de gestion des parametres
 | 
|---|
| 711 | //      des dessins des histogrammes 2D. Cette fenetre de
 | 
|---|
| 712 | //      dialogue est partagee par tous les widget de dessin
 | 
|---|
| 713 | //      des histogrammes 2D. Pour faire apparaitre la fenetre
 | 
|---|
| 714 | //      tapez ALT-O.
 | 
|---|
| 715 | //--
 | 
|---|
| 716 | //++
 | 
|---|
| 717 | //| - Menu 1: Choix du type de display
 | 
|---|
| 718 | //|     Carres variables, nuages de points, caracteres a la hbook2
 | 
|---|
| 719 | //|     et carres de tailles fixe (couleur ou niveauz de gris).
 | 
|---|
| 720 | //| - Menu 2: Choix du type d'echelle
 | 
|---|
| 721 | //|     Lineaire ou logarithmique
 | 
|---|
| 722 | //| - Menu 3: Choix de la couleur
 | 
|---|
| 723 | //|     noir et blanc, niveau de gris et couleurs diverses.
 | 
|---|
| 724 | //| - Champ texte Dyn: Pour donner la dynamique, si min>=max
 | 
|---|
| 725 | //|     alors prend le min et le max de l'histogramme
 | 
|---|
| 726 | //|     (cf PIHisto2D::UseDyn)
 | 
|---|
| 727 | //| - Champ texte Frac: fraction mini et maxi
 | 
|---|
| 728 | //|     (cf PIHisto2D::UseFrac)
 | 
|---|
| 729 | //| - Champ texte LogScal: niveau de scaling pour le choix d'une
 | 
|---|
| 730 | //|     echelle logarithmique (cf PIHisto2D::UseScale)
 | 
|---|
| 731 | //--
 | 
|---|
| 732 | //++
 | 
|---|
| 733 | //| - Curseur interactif PerPt: pourcentage de points a dessiner
 | 
|---|
| 734 | //|     dans chaque bin (cf PIHisto2D::UseDisplay)
 | 
|---|
| 735 | //| - Bouton Apply: dessiner avec les options affichees
 | 
|---|
| 736 | //| - Bouton Dismiss: fermeture de la fenetre de dialogue.
 | 
|---|
| 737 | //| - Bouton Get: re-prendre les valeurs de display stoquees
 | 
|---|
| 738 | //|     pour un histogramme donne.
 | 
|---|
| 739 | //| - Bouton Print: Imprimer les caracteristiques du display
 | 
|---|
| 740 | //|     et de l'histogramme.
 | 
|---|
| 741 | //--
 | 
|---|
| 742 | : PIWindow((PIMsgHandler *)par,"H2D-Options",PIWK_dialog,250,260,150,150)
 | 
|---|
| 743 | , mFgCol(false), mCmap(CMAP_GREYINV32), mRevCmap(false)
 | 
|---|
| 744 | , mTypScal(0)  , mLogScale(10.)
 | 
|---|
| 745 | , mTypDisp(0)  , mFPoints(0.5)
 | 
|---|
| 746 | , mHMin(1.)    , mHMax(-1.)
 | 
|---|
| 747 | , mFracMin(0.1), mFracMax(0.9)
 | 
|---|
| 748 | {
 | 
|---|
| 749 | if(dbg) printf("H2WinArg::H2WinArg %p par=%p\n",this,par);
 | 
|---|
| 750 | 
 | 
|---|
| 751 | // Taille automatique
 | 
|---|
| 752 | int bsx, bsy;
 | 
|---|
| 753 | PIApplicationPrefCompSize(bsx, bsy);  // environ 6 lettres
 | 
|---|
| 754 | int spx = (bsx>=10) ? bsx/10 : 1;  // intervalle entre lettres X
 | 
|---|
| 755 | int spy = (bsy>=5) ? bsy/5 : 1;    // intervalle entre lettres Y
 | 
|---|
| 756 | int wszx = 5*spx+bsx+int(2.5*bsx); // Taille fenetre en X
 | 
|---|
| 757 | int wszy = 11*spy+int(8.5*bsy);    // Taille fenetre en Y
 | 
|---|
| 758 | SetSize(wszx, wszy);
 | 
|---|
| 759 | 
 | 
|---|
| 760 | // menu du style de display des bins
 | 
|---|
| 761 |   int cpx = 2*spx, cpy = 2*spy;
 | 
|---|
| 762 | mOPop[0] = new PIOptMenu(this,"optmen-h2d-1",2*bsx,bsy,cpx,cpy);
 | 
|---|
| 763 | mOPop[0]->AppendItem("Carres Var."  ,6101);
 | 
|---|
| 764 | mOPop[0]->AppendItem("....."        ,6102);
 | 
|---|
| 765 | mOPop[0]->AppendItem(".+12..Z*"     ,6103);
 | 
|---|
| 766 | mOPop[0]->AppendItem("Carres Pleins",6104);
 | 
|---|
| 767 | mOPop[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 768 | 
 | 
|---|
| 769 | // Menu du choix de la dynamique
 | 
|---|
| 770 |   cpy += bsy+spy;
 | 
|---|
| 771 | mOPop[1] = new PIOptMenu(this,"optmen-h2d-2",2*bsx,bsy,cpx,cpy);
 | 
|---|
| 772 | mOPop[1]->AppendItem("Lineaire",6201);
 | 
|---|
| 773 | mOPop[1]->AppendItem("Log10"   ,6202);
 | 
|---|
| 774 | mOPop[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 775 | 
 | 
|---|
| 776 | // Menu du choix de la table des couleurs
 | 
|---|
| 777 |   cpy += bsy+spy;
 | 
|---|
| 778 | mOPop[2] = new PIOptMenu(this,"optmen-h2d-3",2*bsx,bsy,cpx,cpy);
 | 
|---|
| 779 | mOPop[2]->AppendItem("Black&White",7000);
 | 
|---|
| 780 | mCasc[0] = new PIMenu(mOPop[2]->Menu(),"PIStd-128Col");
 | 
|---|
| 781 | mCasc[1] = new PIMenu(mOPop[2]->Menu(), "PIUniCol32");
 | 
|---|
| 782 | mCasc[2] = new PIMenu(mOPop[2]->Menu(),"MIDAS-CMap");
 | 
|---|
| 783 | int kcc,nsct1=5,nsct2=9,nsct3=17,nsct4=PIColorMap::NumberStandardColorMaps()-2;
 | 
|---|
| 784 | for(kcc=0; kcc<nsct1; kcc++) 
 | 
|---|
| 785 |   mOPop[2]->AppendItem(PIColorMap::GetStandardColorMapName(kcc).c_str(),7001+kcc);
 | 
|---|
| 786 | for(kcc=nsct1; kcc<nsct2; kcc++) 
 | 
|---|
| 787 |   mCasc[0]->AppendItem(PIColorMap::GetStandardColorMapName(kcc).c_str(),7001+kcc);
 | 
|---|
| 788 | mOPop[2]->AppendPDMenu(mCasc[0]);
 | 
|---|
| 789 | for(kcc=nsct2; kcc<nsct3; kcc++) 
 | 
|---|
| 790 |   mCasc[1]->AppendItem(PIColorMap::GetStandardColorMapName(kcc).c_str(),7001+kcc);
 | 
|---|
| 791 | mOPop[2]->AppendPDMenu(mCasc[1]);
 | 
|---|
| 792 | for(kcc=nsct3; kcc<nsct4; kcc++) 
 | 
|---|
| 793 |   mCasc[2]->AppendItem(PIColorMap::GetStandardColorMapName(kcc).c_str(),7001+kcc);
 | 
|---|
| 794 | mOPop[2]->AppendPDMenu(mCasc[2]);
 | 
|---|
| 795 | for(kcc=nsct4; kcc<PIColorMap::NumberStandardColorMaps(); kcc++) 
 | 
|---|
| 796 |   mOPop[2]->AppendItem(PIColorMap::GetStandardColorMapName(kcc).c_str(),7001+kcc);
 | 
|---|
| 797 | //mOPop[2]->SetValue(7000);
 | 
|---|
| 798 | mOPop[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 799 | 
 | 
|---|
| 800 | // Reverse color map
 | 
|---|
| 801 |   cpy += bsy+spy;
 | 
|---|
| 802 | mCkb = new PICheckBox(this,"Reverse CMap",8001,2*bsx,bsy,cpx,cpy);
 | 
|---|
| 803 | mCkb->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 804 | 
 | 
|---|
| 805 | // Labels et zones de saisie texte
 | 
|---|
| 806 |   cpy += bsy+spy;
 | 
|---|
| 807 | mLab[0] = new PILabel(this,"     Dyn: ",bsx,bsy,cpx,cpy); 
 | 
|---|
| 808 | mLab[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 809 | mText[0] = new PIText(this,"Dynamique",int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
 | 
|---|
| 810 | mText[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 811 |   cpy += bsy+spy;
 | 
|---|
| 812 | mLab[1] = new PILabel(this,"    Frac: ",bsx,bsy,cpx,cpy);
 | 
|---|
| 813 | mLab[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 814 | mText[1] = new PIText(this,"Fraction",int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
 | 
|---|
| 815 | mText[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 816 |   cpy += bsy+spy;
 | 
|---|
| 817 | mLab[2] = new PILabel(this," LogScal: ",bsx,bsy,cpx,cpy);
 | 
|---|
| 818 | mLab[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 819 | mText[2] = new PIText(this,"LogScale",int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
 | 
|---|
| 820 | mText[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 821 | 
 | 
|---|
| 822 | // Labels et curseur mobile
 | 
|---|
| 823 | cpy += bsy+spy;
 | 
|---|
| 824 | mLab[3] = new PILabel(this,"   PerPt: ",bsx,bsy,cpx,cpy+int(0.25*bsy));
 | 
|---|
| 825 | mLab[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 826 | mPScal = new PIScale(this,"FracPoints",6401,kSDirLtoR
 | 
|---|
| 827 |                         ,int(2.5*bsx),int(1.25*bsy),cpx+bsx+spx,cpy);
 | 
|---|
| 828 | mPScal->SetMinMax(0,100);
 | 
|---|
| 829 | mPScal->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 830 | 
 | 
|---|
| 831 | //
 | 
|---|
| 832 | SetText();
 | 
|---|
| 833 | //
 | 
|---|
| 834 | 
 | 
|---|
| 835 | // Boutons
 | 
|---|
| 836 |   cpx = 2*bsx+5*spx, cpy = 2*spy;
 | 
|---|
| 837 | mBut[0] = new PIButton(this,"Apply",6001,bsx,bsy,cpx,cpy);
 | 
|---|
| 838 | mBut[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 839 |   cpy += bsy+spy;
 | 
|---|
| 840 | mBut[1] = new PIButton(this,"Dismiss",6002,bsx,bsy,cpx,cpy);
 | 
|---|
| 841 | mBut[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 842 |   cpy += bsy+spy;
 | 
|---|
| 843 | mBut[2] = new PIButton(this,"Get",6003,bsx,bsy,cpx,cpy);
 | 
|---|
| 844 | mBut[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 845 |   cpy += bsy+spy;
 | 
|---|
| 846 | mBut[3] = new PIButton(this,"Print",6004,bsx,bsy,cpx,cpy);
 | 
|---|
| 847 | mBut[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
 | 
|---|
| 848 | // FinishCreate();
 | 
|---|
| 849 | }
 | 
|---|
| 850 | 
 | 
|---|
| 851 | //++
 | 
|---|
| 852 | H2WinArg::~H2WinArg()
 | 
|---|
| 853 | //
 | 
|---|
| 854 | //      Destructeur.
 | 
|---|
| 855 | //--
 | 
|---|
| 856 | {
 | 
|---|
| 857 | int i;
 | 
|---|
| 858 | if(dbg) printf("H2WinArg::~H2WinArg %p\n",this);
 | 
|---|
| 859 | for(i=0;i<3;i++) delete mCasc[i];
 | 
|---|
| 860 | for(i=0;i<3;i++) delete mOPop[i];
 | 
|---|
| 861 | for(i=0;i<4;i++) delete mBut[i];
 | 
|---|
| 862 | for(i=0;i<4;i++) delete mLab[i];
 | 
|---|
| 863 | for(i=0;i<3;i++) delete mText[i];
 | 
|---|
| 864 | delete mCkb;
 | 
|---|
| 865 | delete mPScal;
 | 
|---|
| 866 | }
 | 
|---|
| 867 | 
 | 
|---|
| 868 | //++
 | 
|---|
| 869 | void H2WinArg::Show()
 | 
|---|
| 870 | //
 | 
|---|
| 871 | //      Initialisation sur ouverture ALT-O
 | 
|---|
| 872 | //--
 | 
|---|
| 873 | {
 | 
|---|
| 874 |  if(dbg) printf("H2WinArg::Show() mH2DDrw=%p\n",mH2DDrw);
 | 
|---|
| 875 |  // Pour recuperer les valeurs du Drawer sur lequel on fait ALT-O
 | 
|---|
| 876 |  PIWindow::Show();
 | 
|---|
| 877 |  return;
 | 
|---|
| 878 | }
 | 
|---|
| 879 | 
 | 
|---|
| 880 | //++
 | 
|---|
| 881 | void H2WinArg::SetText()
 | 
|---|
| 882 | //
 | 
|---|
| 883 | //      Gestion des fenetres de saisie de texte et des pop-menus.
 | 
|---|
| 884 | //--
 | 
|---|
| 885 | {
 | 
|---|
| 886 | if(dbg) printf("H2WinArg::SetText()\n");
 | 
|---|
| 887 | string sdum;
 | 
|---|
| 888 | char str[256];
 | 
|---|
| 889 | 
 | 
|---|
| 890 | sprintf(str,"%g %g",mHMin,mHMax);
 | 
|---|
| 891 | mText[0]->SetText(str);
 | 
|---|
| 892 | 
 | 
|---|
| 893 | sprintf(str,"%g %g",mFracMin,mFracMax);
 | 
|---|
| 894 | mText[1]->SetText(str);
 | 
|---|
| 895 | 
 | 
|---|
| 896 | sprintf(str,"%g",mLogScale);
 | 
|---|
| 897 | mText[2]->SetText(str);
 | 
|---|
| 898 | if(mTypScal==1) mText[2]->SetSensitive();
 | 
|---|
| 899 |   else          mText[2]->SetUnSensitive();
 | 
|---|
| 900 | 
 | 
|---|
| 901 | if(mTypDisp==0)      {sdum="Carres Var.";   mOPop[0]->SetValueStr(sdum);}
 | 
|---|
| 902 | else if(mTypDisp==1) {sdum=".....";         mOPop[0]->SetValueStr(sdum);}
 | 
|---|
| 903 | else if(mTypDisp==2) {sdum=".+12..Z*";      mOPop[0]->SetValueStr(sdum);}
 | 
|---|
| 904 | else if(mTypDisp==3) {sdum="Carres Pleins"; mOPop[0]->SetValueStr(sdum);}
 | 
|---|
| 905 | 
 | 
|---|
| 906 | if(mTypScal==0)      {sdum="Lineaire"; mOPop[1]->SetValueStr(sdum);}
 | 
|---|
| 907 | else if(mTypScal==1) {sdum="Log10";    mOPop[1]->SetValueStr(sdum);}
 | 
|---|
| 908 | 
 | 
|---|
| 909 | if(!mFgCol) {mOPop[2]->SetValue(7000);}
 | 
|---|
| 910 | else {
 | 
|---|
| 911 |   for(int kk=0;kk<PIColorMap::NumberStandardColorMaps();kk++)
 | 
|---|
| 912 |     if(mCmap == PIColorMap::GetStandardColorMapId(kk))
 | 
|---|
| 913 |       {mOPop[2]->SetValue(7001+kk); break;}
 | 
|---|
| 914 | }
 | 
|---|
| 915 | mCkb->SetState(mRevCmap);
 | 
|---|
| 916 | 
 | 
|---|
| 917 | mPScal->SetValue(int(mFPoints*100.));
 | 
|---|
| 918 | if(mTypDisp==1) mPScal->SetSensitive();
 | 
|---|
| 919 |   else          mPScal->SetUnSensitive();
 | 
|---|
| 920 | }
 | 
|---|
| 921 | 
 | 
|---|
| 922 | //++
 | 
|---|
| 923 | void H2WinArg::Process(PIMessage msg, PIMsgHandler* sender, void*)
 | 
|---|
| 924 | //
 | 
|---|
| 925 | //      Gestions des messages.
 | 
|---|
| 926 | //--
 | 
|---|
| 927 | {
 | 
|---|
| 928 | if(dbg) printf("H2WinArg::Process(%d-%d , %p ...) \n"
 | 
|---|
| 929 |               ,(int)UserMsg(msg),(int)ModMsg(msg),sender);
 | 
|---|
| 930 | 
 | 
|---|
| 931 | // if(!mH2Wdg) return;
 | 
|---|
| 932 | if(!mBWdg) return;
 | 
|---|
| 933 | // PIHisto2D* mpih = mH2Wdg->GetPIHisto();
 | 
|---|
| 934 | PIHisto2D* mpih = mH2DDrw;
 | 
|---|
| 935 | if(!mpih) return;
 | 
|---|
| 936 | 
 | 
|---|
| 937 | int opt = UserMsg(msg);
 | 
|---|
| 938 | 
 | 
|---|
| 939 |      if(opt == 6101) {mTypDisp = 0;}
 | 
|---|
| 940 | else if(opt == 6102) {mTypDisp = 1;}
 | 
|---|
| 941 | else if(opt == 6103) {mTypDisp = 2;}
 | 
|---|
| 942 | else if(opt == 6104) {mTypDisp = 3;}
 | 
|---|
| 943 | 
 | 
|---|
| 944 | else if(opt == 6201) {mTypScal = 0;}
 | 
|---|
| 945 | else if(opt == 6202) {mTypScal = 1;}
 | 
|---|
| 946 | 
 | 
|---|
| 947 | else if(opt == 7000) {mFgCol = false;}
 | 
|---|
| 948 | else if(opt >= 7001 && opt <8000) {
 | 
|---|
| 949 |   int k  = opt-7001;
 | 
|---|
| 950 |   mFgCol = true;
 | 
|---|
| 951 |   mCmap  = PIColorMap::GetStandardColorMapId(k);
 | 
|---|
| 952 | }
 | 
|---|
| 953 | 
 | 
|---|
| 954 | else if(opt == 8001) mRevCmap = mCkb->GetState();
 | 
|---|
| 955 | 
 | 
|---|
| 956 | else if(opt == 6401) mFPoints = mPScal->GetValue()/100.;
 | 
|---|
| 957 | 
 | 
|---|
| 958 | else if(opt==6001) {
 | 
|---|
| 959 |   sscanf(mText[0]->GetText().c_str(),"%g %g",&mHMin,&mHMax);
 | 
|---|
| 960 |   sscanf(mText[1]->GetText().c_str(),"%g %g",&mFracMin,&mFracMax);
 | 
|---|
| 961 |   sscanf(mText[2]->GetText().c_str(),"%g",&mLogScale);
 | 
|---|
| 962 |   mpih->UseColors(mFgCol,mCmap,mRevCmap);
 | 
|---|
| 963 |   mpih->UseScale(mTypScal,mLogScale);
 | 
|---|
| 964 |   mpih->UseDisplay(mTypDisp,mFPoints);
 | 
|---|
| 965 |   mpih->UseDyn(mHMin,mHMax);
 | 
|---|
| 966 |   mpih->UseFrac(mFracMin,mFracMax);
 | 
|---|
| 967 |   mBWdg->Refresh();  // On rafraichit le dessin (tout le PIScDrawWdg)
 | 
|---|
| 968 | }
 | 
|---|
| 969 | else if(opt==6002) this->Hide();
 | 
|---|
| 970 | else if (opt==6003) {
 | 
|---|
| 971 |   mFgCol = mpih->Color(); mCmap = mpih->ColMap();
 | 
|---|
| 972 |                           mRevCmap = mpih->IsColMapRev();
 | 
|---|
| 973 |   mTypScal = mpih->TypScale(); mLogScale = mpih->LogScale();
 | 
|---|
| 974 |   mTypDisp = mpih->TypDisplay(); mFPoints = mpih->FPoints();
 | 
|---|
| 975 |   mHMin = mpih->HMin(); mHMax = mpih->HMax();
 | 
|---|
| 976 |   mFracMin = mpih->FMin(); mFracMax = mpih->FMax();
 | 
|---|
| 977 | }
 | 
|---|
| 978 | else if(opt==6004) mpih->Print(2);
 | 
|---|
| 979 | 
 | 
|---|
| 980 | SetText();
 | 
|---|
| 981 | 
 | 
|---|
| 982 | if(dbg) {
 | 
|---|
| 983 |   printf("H2WinArg::Process opt=%d col=%d,%d,%d scal=%d disp=%d npt=%g\n"
 | 
|---|
| 984 |         ,opt,(int)mFgCol,(int)mCmap,(int)mRevCmap,mTypScal,mTypDisp,mFPoints);
 | 
|---|
| 985 |   printf("                  min,max= %g,%g frac= %g,%g logsc= %g\n"
 | 
|---|
| 986 |         ,mHMin,mHMax,mFracMin,mFracMax,mLogScale);
 | 
|---|
| 987 | }
 | 
|---|
| 988 | 
 | 
|---|
| 989 | }
 | 
|---|