1 | #include <stdio.h>
|
---|
2 | #include "piapplgen.h"
|
---|
3 | #include "pihisto2d.h"
|
---|
4 | #include "nbrandom.h"
|
---|
5 |
|
---|
6 | static int dbg = 0;
|
---|
7 |
|
---|
8 | //++
|
---|
9 | // Class PIHisto2D,PIH2DWdg,H2WinArg
|
---|
10 | // Lib PI
|
---|
11 | // include pihisto2d.h
|
---|
12 | //
|
---|
13 | // Classes de dessin des histogrammes a 2 dimensions.
|
---|
14 | //--
|
---|
15 |
|
---|
16 | //++
|
---|
17 | // Titre Dessin d'un histogramme 2D.
|
---|
18 | //--
|
---|
19 |
|
---|
20 | //++
|
---|
21 | PIHisto2D::PIHisto2D(Histo2D* histo, bool ad)
|
---|
22 | //
|
---|
23 | // Createur d'une classe de dessin pour l'histogramme 2D histo.
|
---|
24 | //--
|
---|
25 | : PIDrawer(), mHisto(histo)
|
---|
26 | {
|
---|
27 | mAdDO = ad; // Flag pour suppression automatique de mHisto
|
---|
28 |
|
---|
29 | mLogScale = 10.;
|
---|
30 | mFPoints = 0.5;
|
---|
31 |
|
---|
32 | UseColors();
|
---|
33 | UseDisplay();
|
---|
34 | UseDyn();
|
---|
35 | UseFrac();
|
---|
36 | }
|
---|
37 |
|
---|
38 | //++
|
---|
39 | PIHisto2D::~PIHisto2D()
|
---|
40 | //
|
---|
41 | // Destructeur.
|
---|
42 | //--
|
---|
43 | {
|
---|
44 | if(mAdDO) delete mHisto;
|
---|
45 | }
|
---|
46 |
|
---|
47 | //++
|
---|
48 | void PIHisto2D::UseColors(bool fg, CMapId cmap)
|
---|
49 | //
|
---|
50 | // Choix de la couleur si fg=true
|
---|
51 | // (pour la couleur cmap cf picmap.h).
|
---|
52 | //--
|
---|
53 | {
|
---|
54 | mFgCol = fg; mCmap = cmap;
|
---|
55 | }
|
---|
56 |
|
---|
57 | //++
|
---|
58 | void PIHisto2D::UseScale(unsigned short type,float logscale)
|
---|
59 | //
|
---|
60 | // Pour changer les echelles.
|
---|
61 | //| Type = 0 : echelle lineaire
|
---|
62 | //| = 1 : echelle log10
|
---|
63 | //| - Explication du codage en type=1 (log10) :
|
---|
64 | //| 1-/ map lineaire :
|
---|
65 | //| [0,1] -> [lmin,lmax]
|
---|
66 | //| f -> F = lmin+f*(lmax-lmin)
|
---|
67 | //| 2-/ transformation log10 :
|
---|
68 | //| [lmin,lmax] -> [log10(lmin),log10(lmax)]
|
---|
69 | //| F -> LF = lg10(F)
|
---|
70 | //| 3-/ rescaling entre 0 et 1 :
|
---|
71 | //| [log10(lmin),log10(lmax)] -> [0,1]
|
---|
72 | //| LF -> (LF-log10(lmin))/(log10(lmax)-log10(lmin))
|
---|
73 | //| soit en definissant logscale = lmax/lmin
|
---|
74 | //| LF = log10(1.+f*(logscale-1))/log10(logscale)
|
---|
75 | //--
|
---|
76 | {
|
---|
77 | if(type==0) mTypScal = 0;
|
---|
78 | if(type==1) {
|
---|
79 | mTypScal = 1;
|
---|
80 | if(logscale>1.) mLogScale = logscale;
|
---|
81 | } else mTypScal = 0;
|
---|
82 | }
|
---|
83 |
|
---|
84 | //++
|
---|
85 | void PIHisto2D::UseDisplay(unsigned short type, float fnpt)
|
---|
86 | //
|
---|
87 | // Type de Display
|
---|
88 | //| Type = 0 : carres de tailles variables
|
---|
89 | //| Type = 1 : nuages de points
|
---|
90 | //| Le nombre de points a utiliser est fnpt*N
|
---|
91 | //| ou N est le nombre de pixels ecran contenu
|
---|
92 | //| dans un bin de l'histogramme.
|
---|
93 | //| Type = 2 : code a la "hbook2" " .+123...9AB...YZ*"
|
---|
94 | //| (cf detail PIHisto2D::HPrint2)
|
---|
95 | //| Type = 3 : carres de tailles fixes (couleur).
|
---|
96 | //--
|
---|
97 | {
|
---|
98 | if(fnpt<0.) fnpt=0; else if(fnpt>1.) fnpt=1.;
|
---|
99 | if(type==0) mTypDisp = 0;
|
---|
100 | else if(type==1) { mTypDisp = 1; mFPoints = fnpt;}
|
---|
101 | else if(type==2) mTypDisp = 2;
|
---|
102 | else if(type==3) mTypDisp = 3;
|
---|
103 | else mTypDisp = 1;
|
---|
104 | }
|
---|
105 |
|
---|
106 | //++
|
---|
107 | void PIHisto2D::UseDyn(float hmin, float hmax)
|
---|
108 | //
|
---|
109 | // Gestion de la dynamique a representer:
|
---|
110 | // la dynamique va etre transformee de [hmin,hmax] vers [0,1].
|
---|
111 | //--
|
---|
112 | {
|
---|
113 | if(hmin>=hmax) {hmin = mHisto->VMin(); hmax = mHisto->VMax();}
|
---|
114 | if(hmin>=hmax) hmax = hmin+1.;
|
---|
115 | mHMin = hmin; mHMax = hmax;
|
---|
116 | }
|
---|
117 |
|
---|
118 | //++
|
---|
119 | void PIHisto2D::UseFrac(float frmin, float frmax)
|
---|
120 | //
|
---|
121 | // Pour definir la fraction de la dynamique a dessiner:
|
---|
122 | //| Certains type de display (f=[0,1] cf PIHisto2D::UseDyn),
|
---|
123 | //| - on ne dessine rien si f <= frmin
|
---|
124 | //| - on limite l'excursion a f*frmax cad [...,frmax]
|
---|
125 | //--
|
---|
126 | {
|
---|
127 | if(frmax<=0. || frmax>1.) frmax = 1.;
|
---|
128 | if(frmin>=frmax) {frmin=0.1; frmax=0.9;}
|
---|
129 | mFracMin = frmin; mFracMax = frmax;
|
---|
130 | }
|
---|
131 |
|
---|
132 | //++
|
---|
133 | void PIHisto2D::Print(int lp)
|
---|
134 | //
|
---|
135 | // Print de l'etat des options du display.
|
---|
136 | //--
|
---|
137 | {
|
---|
138 | printf("PIHisto2D::Print FgCol=%d Cmap=%d TypScal=%d TypDisp=%d (FPoints=%g)\n"
|
---|
139 | ,(int)mFgCol,(int)mCmap,mTypScal,mTypDisp,mFPoints);
|
---|
140 | printf(" Dyn=%g,%g Frac=%g,%g LogSc=%g H=%lx\n"
|
---|
141 | ,mHMin,mHMax,mFracMin,mFracMax,mLogScale,(long)mHisto);
|
---|
142 | if(lp<1) return;
|
---|
143 | mHisto->PrintStatus();
|
---|
144 | }
|
---|
145 |
|
---|
146 | //++
|
---|
147 | void PIHisto2D::UpdateLimits()
|
---|
148 | //
|
---|
149 | // Definition des tailles graphiques en fonction
|
---|
150 | // des caracteristiques de l'histogramme a dessiner.
|
---|
151 | //--
|
---|
152 | {
|
---|
153 | if(!mHisto) return;
|
---|
154 | SetLimits(mHisto->XMin(), mHisto->XMax(), mHisto->YMin() , mHisto->YMax());
|
---|
155 | SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
|
---|
156 | }
|
---|
157 |
|
---|
158 | //++
|
---|
159 | void PIHisto2D::Draw(PIGraphicUC* g,float,float, float, float)
|
---|
160 | //
|
---|
161 | // Dessin de l'histogramme.
|
---|
162 | //--
|
---|
163 | {
|
---|
164 | if(!mHisto) return;
|
---|
165 | // Caracteristiques histogramme
|
---|
166 | float dx = mHisto->WBinX(),dy = mHisto->WBinY();
|
---|
167 | float p1dx,p1dy;
|
---|
168 | g->DGrC2UC(1.f,1.f,p1dx,p1dy);
|
---|
169 |
|
---|
170 | // Gamme a representer entre [0,1] mais >=fracmin et scale fracmax
|
---|
171 | float fracmin=FMin(), fracmax=FMax();
|
---|
172 | float llscale = (float) log10((double)LogScale());
|
---|
173 |
|
---|
174 | // gestion Couleurs.
|
---|
175 | PIColorMap* cmap=NULL;
|
---|
176 | PIColors coul = g->GetForeground();
|
---|
177 | int ncol = 0;
|
---|
178 | if (mFgCol) {
|
---|
179 | cmap = new PIColorMap(mCmap); ncol = cmap->NCol();
|
---|
180 | if(mTypDisp==3) fracmin=-1.;
|
---|
181 | }
|
---|
182 |
|
---|
183 | // gestion epaisseur de ligne
|
---|
184 | if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
|
---|
185 |
|
---|
186 | // gestion Markers ou plot avec des points.
|
---|
187 | PIMarker Mk = g->GetMarker();
|
---|
188 | int MkSz = g->GetMarkerSize();
|
---|
189 | int npt = 1;
|
---|
190 | if(mTypDisp==1) {
|
---|
191 | g->SelMarker(1,PI_DotMarker);
|
---|
192 | npt = (int) ((float)NPixBin(g)*FPoints()); if(npt<=0) npt = 2;
|
---|
193 | }
|
---|
194 |
|
---|
195 | // gestion Font.
|
---|
196 | PIFontAtt FontAtt = g->GetFontAtt();
|
---|
197 | int FontSize = g->GetFontSize();
|
---|
198 | if(mTypDisp==2) {
|
---|
199 | float dxg,dyg,dg;
|
---|
200 | g->DUC2GrC(dx,dy,dxg,dyg);
|
---|
201 | dg =(dxg<dyg) ? dxg : dyg;
|
---|
202 | int npix = (int) (dg*0.9); if(npix<8) npix = 8;
|
---|
203 | //printf("PIHisto2D::Draw_Font H dx=%g dy=%g, G dx=%g dy=%g, npix = %g,%d\n"
|
---|
204 | // ,dx,dy,dxg,dyg,dg,npix);
|
---|
205 | g->SelFontSzPt(npix,PI_RomanFont);
|
---|
206 | fracmin = 0;
|
---|
207 | }
|
---|
208 |
|
---|
209 | // Print();
|
---|
210 |
|
---|
211 | // Plot de l'histogramme
|
---|
212 | for (int i=0; i<mHisto->NBinX(); i++)
|
---|
213 | for (int j=0; j<mHisto->NBinY(); j++) {
|
---|
214 |
|
---|
215 | float left0,bottom0;
|
---|
216 | mHisto->BinLowEdge(i,j,left0,bottom0);
|
---|
217 |
|
---|
218 | // Gestion de la dynamique a dessiner
|
---|
219 | float frac = ((*mHisto)(i,j)-HMin())/(HMax()-HMin());
|
---|
220 | if(frac<0.) continue;
|
---|
221 | if(mTypScal==1) { // echelle log10
|
---|
222 | frac = log10(1.+frac*(LogScale()-1.))/llscale;
|
---|
223 | if(frac<0.) continue;
|
---|
224 | }
|
---|
225 | if(frac<=fracmin) continue;
|
---|
226 | if(frac>1.) frac = 1.;
|
---|
227 | float fracred = frac * fracmax;
|
---|
228 |
|
---|
229 | // Gestion de la couleur
|
---|
230 | int icol = 0;
|
---|
231 | if (cmap) {
|
---|
232 | icol = int( (float) ncol*frac );
|
---|
233 | if(icol>=ncol) icol = ncol-1; else if(icol<0) icol=0;
|
---|
234 | g->SelForeground(*cmap,icol);
|
---|
235 | }
|
---|
236 |
|
---|
237 | // Dessin proprement dit selon le choix graphique.
|
---|
238 | if(mTypDisp==0) {
|
---|
239 | //..... carres de tailles variables
|
---|
240 | float left = left0 + 0.5*(1.-fracred)*dx, width = fracred*dx;
|
---|
241 | float bottom = bottom0 + 0.5*(1.-fracred)*dy, height = fracred*dy;
|
---|
242 | if (cmap) g->DrawFBox(left,bottom,width,height);
|
---|
243 | else g->DrawBox(left,bottom,width,height);
|
---|
244 | } else if(mTypDisp==1) {
|
---|
245 | //..... nuage de points .....
|
---|
246 | int ipt = int( (float) npt *frac );
|
---|
247 | for(int k=0;k<ipt;k++) {
|
---|
248 | float x = left0 + frand01()*dx;
|
---|
249 | float y = bottom0 + frand01()*dy;
|
---|
250 | g->DrawMarker(x,y);
|
---|
251 | }
|
---|
252 | } else if(mTypDisp==2) {
|
---|
253 | //..... type hbook2/hprint .+23-Z*
|
---|
254 | char c[2];
|
---|
255 | c[0] = HPrint2(frac); c[1]='\0';
|
---|
256 | float x = left0 + dx/2.;
|
---|
257 | float y = bottom0 + dy/2.;
|
---|
258 | g->DrawString(x,y,c);
|
---|
259 | } else if(mTypDisp==3) {
|
---|
260 | //..... carres de tailles fixes (avec gestion de continuite)
|
---|
261 | if (cmap) g->DrawFBox(left0,bottom0,dx+p1dx,dy+p1dy);
|
---|
262 | else g->DrawBox(left0,bottom0,dx+p1dx,dy+p1dy);
|
---|
263 | }
|
---|
264 |
|
---|
265 | }
|
---|
266 |
|
---|
267 | // Remise dans les conditions ulterieures pour la suite du graphique.
|
---|
268 | g->SelMarker(MkSz,Mk);
|
---|
269 | g->SelForeground(coul);
|
---|
270 | g->SelFontSzPt(FontSize,FontAtt);
|
---|
271 | if (cmap) delete cmap;
|
---|
272 |
|
---|
273 | // Fin du dessin, ecriture de la statistique.
|
---|
274 | DrawStats(g);
|
---|
275 | }
|
---|
276 |
|
---|
277 | //++
|
---|
278 | void PIHisto2D::DrawStats(PIGraphicUC* g)
|
---|
279 | //
|
---|
280 | // Dessin des informations statistiques de l'histogramme.
|
---|
281 | //--
|
---|
282 | {
|
---|
283 | // Une boite dans le coin superieur droit
|
---|
284 | if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
|
---|
285 | float cellHeight = (YMax() - YMin()) * 0.05;
|
---|
286 | float cellWidth = (XMax() - XMin()) * 0.23;
|
---|
287 | g->DrawLine(XMax() - cellWidth, YMax(),
|
---|
288 | XMax() - cellWidth, YMax() - cellHeight);
|
---|
289 | g->DrawLine(XMax() - cellWidth, YMax() - cellHeight,
|
---|
290 | XMax() , YMax() - cellHeight);
|
---|
291 | char label[50];
|
---|
292 | sprintf(label, "N = %.6g", mHisto->NData());
|
---|
293 | g->SelFontSz((YMax() - YMin())/30);
|
---|
294 | g->DrawString(XMax() - cellWidth*0.9, YMax() - cellHeight*0.8, label);
|
---|
295 | printf("H[%d,%d] Dynamique: [%g,%g] Frac [%g,%g]\n"
|
---|
296 | ,mHisto->NBinX(),mHisto->NBinY(),HMin(),HMax(),FMin(),FMax());
|
---|
297 | }
|
---|
298 |
|
---|
299 | //++
|
---|
300 | char PIHisto2D::HPrint2(float f)
|
---|
301 | //
|
---|
302 | // Codage des valeurs en caracteres (fct privee).
|
---|
303 | //| f entre [0,1] mappee entre valeur=[0,37]
|
---|
304 | //| si <0 alors =0, si >1 alors 1
|
---|
305 | //| Display 4 ==> 4<=valeur<5
|
---|
306 | //| C ==> 12<=valeur<13
|
---|
307 | //| ==> valeur<=0
|
---|
308 | //| * ==> valeur>=1
|
---|
309 | //| . ==> 0<valeur<1
|
---|
310 | //|------------------------------------------
|
---|
311 | //| C1111111111222222222233333333
|
---|
312 | //| C01234567890123456789012345678901234567
|
---|
313 | //| " .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*"
|
---|
314 | //|------------------------------------------
|
---|
315 | //--
|
---|
316 | {
|
---|
317 | char str[39] = " .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*";
|
---|
318 | int i;
|
---|
319 | if(f<=0.) i = 0;
|
---|
320 | else if(f>=1.) i = 37;
|
---|
321 | else { i = (int) (f*36.); i++;}
|
---|
322 | if(i<0) i=0; else if (i>=38) i = 37;
|
---|
323 | return str[i];
|
---|
324 | }
|
---|
325 |
|
---|
326 | //++
|
---|
327 | int PIHisto2D::NPixBin(PIGraphicUC* g)
|
---|
328 | //
|
---|
329 | // Nombre de pixels ecran dans un bin d'histogramme
|
---|
330 | // (fct privee).
|
---|
331 | //--
|
---|
332 | {
|
---|
333 | float dx = mHisto->WBinX(),dy = mHisto->WBinY();
|
---|
334 | float dxg,dyg;
|
---|
335 | g->DUC2GrC(dx,dy,dxg,dyg);
|
---|
336 | int np = (int) dxg * (int) dyg;
|
---|
337 | //printf("PIHisto2D::NPixBin H dx=%g dy=%g, G dx=%g dy=%g, np = %d\n"
|
---|
338 | // ,dx,dy,dxg,dyg,np);
|
---|
339 | return np;
|
---|
340 | }
|
---|
341 |
|
---|
342 |
|
---|
343 | /////////////////////////////////////////////////////////////////
|
---|
344 | // Classe PIH2DWdg
|
---|
345 | /////////////////////////////////////////////////////////////////
|
---|
346 | //++
|
---|
347 | // Titre Widget de dessin d'un histogramme 2D.
|
---|
348 | //--
|
---|
349 |
|
---|
350 | static H2WinArg* h2dWinArg=NULL;
|
---|
351 | static int nb_h2dWinArg = 0;
|
---|
352 |
|
---|
353 | //++
|
---|
354 | PIH2DWdg::PIH2DWdg(PIContainerGen *par, char *nom, int sx, int sy, int px, int py)
|
---|
355 | //
|
---|
356 | // Createur d'un Widget de dessin d'histogramme 2D.
|
---|
357 | // Le menu pour choisir les options d'affichage apparait
|
---|
358 | // suite au clic du bouton-3 de la souris (cf H2WinArg::H2WinArg).
|
---|
359 | //--
|
---|
360 | : PIScDrawWdg(par,nom,sx,sy,px,py)
|
---|
361 | {
|
---|
362 | if (!h2dWinArg) h2dWinArg = new H2WinArg(this);
|
---|
363 | nb_h2dWinArg++;
|
---|
364 | if(dbg) printf("PIH2DWdg::PIH2DWdg %lx h2dWinArg=%lx %d\n"
|
---|
365 | ,(long)this,(long)h2dWinArg,nb_h2dWinArg);
|
---|
366 | mPih = NULL;
|
---|
367 | // Pour afficher le menu option de trace
|
---|
368 | ActivateButton(3);
|
---|
369 | }
|
---|
370 |
|
---|
371 | //++
|
---|
372 | PIH2DWdg::~PIH2DWdg()
|
---|
373 | //
|
---|
374 | // Destructeur.
|
---|
375 | //--
|
---|
376 | {
|
---|
377 | nb_h2dWinArg--;
|
---|
378 | if (nb_h2dWinArg == 0) {
|
---|
379 | h2dWinArg->Hide();
|
---|
380 | delete h2dWinArg;
|
---|
381 | h2dWinArg=NULL;
|
---|
382 | }
|
---|
383 | if(dbg) printf("PIH2DWdg::~PIH2DWdg h2dWinArg=%lx %d\n"
|
---|
384 | ,(long)h2dWinArg,nb_h2dWinArg);
|
---|
385 | if (mPih) delete mPih;
|
---|
386 | }
|
---|
387 |
|
---|
388 | //++
|
---|
389 | void PIH2DWdg::SetHisto(Histo2D* histo)
|
---|
390 | //
|
---|
391 | // Pour connecter un histogramme 2D au Widget.
|
---|
392 | //--
|
---|
393 | {
|
---|
394 | if (!histo) return;
|
---|
395 | if (mPih) delete mPih;
|
---|
396 | mPih = new PIHisto2D(histo, true);
|
---|
397 | AddScDrawer(mPih);
|
---|
398 | if(dbg) printf("PIH2DWdg::SetHisto mPih=%lx\n",(long)mPih);
|
---|
399 | }
|
---|
400 |
|
---|
401 | //++
|
---|
402 | void PIH2DWdg::SetPIHisto(PIHisto2D* pih2)
|
---|
403 | //
|
---|
404 | // Pour connecter un traceur (Drawer) d'histo 2D au Widget.
|
---|
405 | //--
|
---|
406 | {
|
---|
407 | if (!pih2) return;
|
---|
408 | if (mPih) delete mPih;
|
---|
409 | mPih = pih2;
|
---|
410 | AddScDrawer(mPih);
|
---|
411 | if(dbg) printf("PIH2DWdg::SetPIHisto mPih=%lx\n",(long)mPih);
|
---|
412 | }
|
---|
413 |
|
---|
414 | //++
|
---|
415 | string PIH2DWdg::GetClickText(float x, float y)
|
---|
416 | //
|
---|
417 | // Quand on click (and drag) le bouton-1, affichage
|
---|
418 | // des positions x,y et de la valeur du bin de l'histogramme 2D.
|
---|
419 | //--
|
---|
420 | {
|
---|
421 | int i,j;
|
---|
422 | char str[128];
|
---|
423 |
|
---|
424 | if ((!mPih) || (!mPih->Histogram())) {
|
---|
425 | sprintf(str,"X=%g Y=%g ???",x,y);
|
---|
426 | return((string)str);
|
---|
427 | }
|
---|
428 |
|
---|
429 | Histo2D* h = mPih->Histogram();
|
---|
430 |
|
---|
431 | h->FindBin(x,y,i,j);
|
---|
432 | if(i<0 || i>=h->NBinX() || j<0 || j>=h->NBinY())
|
---|
433 | sprintf(str,"x= %g y= %g ???",x,y);
|
---|
434 | else sprintf(str,"x= %g y= %g v= %g",x,y,(*h)(i,j));
|
---|
435 |
|
---|
436 | return((string)str);
|
---|
437 | }
|
---|
438 |
|
---|
439 | //++
|
---|
440 | void PIH2DWdg::But3Press(int x, int y)
|
---|
441 | //
|
---|
442 | // Gestion de l'utilisation du bouton-3 de la souris.
|
---|
443 | // Un seul objet est cree pour tous les histogrammes 2D.
|
---|
444 | // Il est connecte a un histogramme donnee par l'action du
|
---|
445 | // du bouton-3 de la souris dans la fenetre contenant
|
---|
446 | // le dessin de l'histogramme (cf H2WinArg::H2WinArg).
|
---|
447 | //--
|
---|
448 | {
|
---|
449 | h2dWinArg->SetPIH2DWdg(this);
|
---|
450 | h2dWinArg->SetMsgParent((PIMsgHandler*)this);
|
---|
451 | if(!h2dWinArg->Visible()) h2dWinArg->Show();
|
---|
452 | if(dbg) printf("PIH2DWdg::But3Press(%d,%d) h2dWinArg=%lx\n"
|
---|
453 | ,x,y,(long)h2dWinArg);
|
---|
454 | }
|
---|
455 |
|
---|
456 |
|
---|
457 | /////////////////////////////////////////////////////////////////
|
---|
458 | // Classe H2WinArg
|
---|
459 | /////////////////////////////////////////////////////////////////
|
---|
460 | //++
|
---|
461 | // Titre Fenetre de dialogue pour le choix des options..
|
---|
462 | //--
|
---|
463 |
|
---|
464 | //++
|
---|
465 | H2WinArg::H2WinArg(PIH2DWdg *par)
|
---|
466 | //
|
---|
467 | // Creation de la fenetre de gestion des parametres
|
---|
468 | // des dessins des histogrammes 2D. Cette fenetre de
|
---|
469 | // dialogue est partagee par tous les widget de dessin
|
---|
470 | // des histogrammes 2D. Pour la faire apparaitre pour la
|
---|
471 | // faire apparaitre la premiere fois, cliquez avec le bouton
|
---|
472 | // numero 3 de la souris (bouton de droite) dans la fenetre
|
---|
473 | // de dessin de l'histogramme. Si elle est deja presente,
|
---|
474 | // pour la connecter a une autre fenetre de dessin cliquez avec
|
---|
475 | // le meme bouton dans cette fenetre.
|
---|
476 | //--
|
---|
477 | //++
|
---|
478 | //| - Menu 1: Choix du type de display
|
---|
479 | //| Carres variables, nuages de points, caracteres a la hbook2
|
---|
480 | //| et carres de tailles fixe (couleur ou niveauz de gris).
|
---|
481 | //| - Menu 2: Choix du type d'echelle
|
---|
482 | //| Lineaire ou logarithmique
|
---|
483 | //| - Menu 3: Choix de la couleur
|
---|
484 | //| noir et blanc, niveau de gris et couleurs diverses.
|
---|
485 | //| - Champ texte Dyn: Pour donner la dynamique, si min>=max
|
---|
486 | //| alors prend le min et le max de l'histogramme
|
---|
487 | //| - Champ texte Frac: fraction mini et maxi
|
---|
488 | //| (cf PIHisto2D::UseFrac)
|
---|
489 | //| - Champ texte LogScal: niveau de scaling pour le choix d'une
|
---|
490 | //| echelle logarithmique (cf PIHisto2D::UseScale)
|
---|
491 | //--
|
---|
492 | //++
|
---|
493 | //| - Curseur interactif PerPt: pourcentage de points a dessiner
|
---|
494 | //| dans chaque bin (cf PIHisto2D::UseDisplay)
|
---|
495 | //| - Bouton Apply: dessiner avec les options affichees
|
---|
496 | //| - Bouton Dismiss: fermeture de la fenetre de dialogue.
|
---|
497 | //| - Bouton Get: re-prendre les valeurs de display stoquees
|
---|
498 | //| pour un histogramme donne.
|
---|
499 | //| - Bouton Print: Imprimer les caracteristiques du display
|
---|
500 | //| et de l'histogramme.
|
---|
501 | //--
|
---|
502 | : PIWindow((PIMsgHandler *)par, "Options", PIWK_dialog,250,260,150,150)
|
---|
503 | {
|
---|
504 | string sdum;
|
---|
505 | if(dbg) printf("H2WinArg::H2WinArg %lx par=%lx\n",(long)this,(long)par);
|
---|
506 |
|
---|
507 | mH2Wdg = NULL;
|
---|
508 |
|
---|
509 | // Valeurs par defaut
|
---|
510 | mFgCol = false;
|
---|
511 | mCmap = CMAP_GREYINV32;
|
---|
512 | mTypScal = 0;
|
---|
513 | mTypDisp = 0;
|
---|
514 | mFPoints = 0.5;
|
---|
515 | mHMin = 1.;
|
---|
516 | mHMax = -1.;
|
---|
517 | mFracMin = 0.1;
|
---|
518 | mFracMax = 0.9;
|
---|
519 | mLogScale = 10.;
|
---|
520 |
|
---|
521 | // Taille automatique
|
---|
522 | int bsx, bsy;
|
---|
523 | PIApplicationPrefCompSize(bsx, bsy); // environ 6 lettres
|
---|
524 | int spx = (bsx>=10) ? bsx/10 : 1; // intervalle entre lettres X
|
---|
525 | int spy = (bsy>=5) ? bsy/5 : 1; // intervalle entre lettres Y
|
---|
526 | int wszx = 5*spx+bsx+int(2.5*bsx); // Taille fenetre en X
|
---|
527 | int wszy = 11*spy+8.5*bsy; // Taille fenetre en Y
|
---|
528 | SetSize(wszx, wszy);
|
---|
529 |
|
---|
530 | // menus bar
|
---|
531 | int cpx = 2*spx, cpy = 2*spy;
|
---|
532 | mOPop[0] = new PIOptMenu(this, "optmen-h2d-1" ,2*bsx,bsy,cpx,cpy);
|
---|
533 | mOPop[0]->AppendItem("Carres Var." , 6101);
|
---|
534 | mOPop[0]->AppendItem("....." , 6102);
|
---|
535 | mOPop[0]->AppendItem(".+12..Z*" , 6103);
|
---|
536 | mOPop[0]->AppendItem("Carres Pleins", 6104);
|
---|
537 | sdum = "Carres Var."; mOPop[0]->SetValueStr(sdum);
|
---|
538 | mOPop[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
539 |
|
---|
540 | cpy += bsy+spy;
|
---|
541 | mOPop[1] = new PIOptMenu(this, "optmen-h2d-2",2*bsx,bsy,cpx,cpy);
|
---|
542 | mOPop[1]->AppendItem("Lineaire", 6201);
|
---|
543 | mOPop[1]->AppendItem("Log10" , 6202);
|
---|
544 | sdum = "Lineaire"; mOPop[1]->SetValueStr(sdum);
|
---|
545 | mOPop[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
546 |
|
---|
547 | cpy += bsy+spy;
|
---|
548 | mOPop[2] = new PIOptMenu(this, "optmen-h2d-3",2*bsx,bsy,cpx,cpy);
|
---|
549 | mOPop[2]->AppendItem("Black&White", 6301);
|
---|
550 | mOPop[2]->AppendItem("Grey32" , 6302);
|
---|
551 | mOPop[2]->AppendItem("GreyInv32" , 6303);
|
---|
552 | mOPop[2]->AppendItem("ColRJ32" , 6304);
|
---|
553 | mOPop[2]->AppendItem("ColBR32" , 6305);
|
---|
554 | mOPop[2]->AppendItem("ColRV32" , 6306);
|
---|
555 | mOPop[2]->AppendItem("Grey128" , 6307);
|
---|
556 | mOPop[2]->AppendItem("GreyInv128", 6308);
|
---|
557 | mOPop[2]->AppendItem("ColRJ128" , 6309);
|
---|
558 | mOPop[2]->AppendItem("ColBR128" , 6310);
|
---|
559 | mOPop[2]->AppendItem("Col16" , 6311);
|
---|
560 | sdum = "Black&White"; mOPop[2]->SetValueStr(sdum);
|
---|
561 | mOPop[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
562 |
|
---|
563 | // Labels et zone de saisie texte
|
---|
564 | cpy += 2*(bsy+spy);
|
---|
565 | mLab[0] = new PILabel(this, " Dyn: ",bsx,bsy,cpx,cpy);
|
---|
566 | mLab[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
567 | mText[0] = new PIText(this, "Dynamique" ,int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
|
---|
568 | mText[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
569 | cpy += bsy+spy;
|
---|
570 | mLab[1] = new PILabel(this, " Frac: ",bsx,bsy,cpx,cpy);
|
---|
571 | mLab[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
572 | mText[1] = new PIText(this, "Fraction" ,int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
|
---|
573 | mText[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
574 | cpy += bsy+spy;
|
---|
575 | mLab[2] = new PILabel(this, " LogScal: ",bsx,bsy,cpx,cpy);
|
---|
576 | mLab[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
577 | mText[2] = new PIText(this, "LogScale" ,int(2.5*bsx),bsy,cpx+bsx+spx,cpy);
|
---|
578 | mText[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
579 | SetText();
|
---|
580 |
|
---|
581 | // Labels et curseur mobile
|
---|
582 | cpy += bsy+spy;
|
---|
583 | mLab[3] = new PILabel(this, " PerPt: ",bsx,bsy,cpx,cpy+0.25*bsy);
|
---|
584 | mLab[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
585 | mPScal = new PIScale(this,"FracPoints",6401,kSDirLtoR
|
---|
586 | ,int(2.5*bsx),1.25*bsy,cpx+bsx+spx,cpy);
|
---|
587 | mPScal->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
588 | mPScal->SetMinMax(0,100);
|
---|
589 | int imfp = mFPoints*100.f; mPScal->SetValue(imfp);
|
---|
590 |
|
---|
591 | // Boutons
|
---|
592 | cpx = 2*bsx+5*spx, cpy = 2*spy;
|
---|
593 | mBut[0] = new PIButton(this, "Apply", 6001,bsx,bsy,cpx,cpy);
|
---|
594 | mBut[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
595 | cpy += bsy+spy;
|
---|
596 | mBut[1] = new PIButton(this, "Dismiss",6002,bsx,bsy,cpx,cpy);
|
---|
597 | mBut[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
598 | cpy += bsy+spy;
|
---|
599 | mBut[2] = new PIButton(this, "Get" , 6003,bsx,bsy,cpx,cpy);
|
---|
600 | mBut[2]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
601 | cpy += bsy+spy;
|
---|
602 | mBut[3] = new PIButton(this, "Print", 6004,bsx,bsy,cpx,cpy);
|
---|
603 | mBut[3]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
604 | // FinishCreate();
|
---|
605 | }
|
---|
606 |
|
---|
607 | //++
|
---|
608 | H2WinArg::~H2WinArg()
|
---|
609 | //
|
---|
610 | // Destructeur.
|
---|
611 | //--
|
---|
612 | {
|
---|
613 | int i;
|
---|
614 | if(dbg) printf("H2WinArg::~H2WinArg %lx\n",(long)this);
|
---|
615 | for(i=0;i<3;i++) delete mOPop[i];
|
---|
616 | for(i=0;i<4;i++) delete mBut[i];
|
---|
617 | for(i=0;i<4;i++) delete mLab[i];
|
---|
618 | for(i=0;i<3;i++) delete mText[i];
|
---|
619 | delete mPScal;
|
---|
620 | }
|
---|
621 |
|
---|
622 | //++
|
---|
623 | void H2WinArg::SetText()
|
---|
624 | //
|
---|
625 | // Gestion des fenetres de saisie de texte.
|
---|
626 | //--
|
---|
627 | {
|
---|
628 | string sdum;
|
---|
629 | char str[256];
|
---|
630 | sprintf(str,"%g %g",mHMin,mHMax);
|
---|
631 | mText[0]->SetText(str);
|
---|
632 | sprintf(str,"%g %g",mFracMin,mFracMax);
|
---|
633 | mText[1]->SetText(str);
|
---|
634 | sprintf(str,"%g",mLogScale);
|
---|
635 | mText[2]->SetText(str);
|
---|
636 |
|
---|
637 | if(mTypDisp==0) { sdum="Carres Var."; mOPop[0]->SetValueStr(sdum);}
|
---|
638 | else if(mTypDisp==1) { sdum="....."; mOPop[0]->SetValueStr(sdum);}
|
---|
639 | else if(mTypDisp==2) { sdum=".+12..Z*"; mOPop[0]->SetValueStr(sdum);}
|
---|
640 | else if(mTypDisp==3) { sdum="Carres Pleins"; mOPop[0]->SetValueStr(sdum);}
|
---|
641 |
|
---|
642 | if(mTypScal==0) { sdum="Lineaire"; mOPop[1]->SetValueStr(sdum);}
|
---|
643 | else if(mTypScal==1) { sdum="Log10"; mOPop[1]->SetValueStr(sdum);}
|
---|
644 |
|
---|
645 | if(!mFgCol) { sdum="Black&White";mOPop[2]->SetValueStr(sdum);}
|
---|
646 | else {
|
---|
647 | if(mCmap==CMAP_GREY32) { sdum="Grey32"; mOPop[2]->SetValueStr(sdum);}
|
---|
648 | else if(mCmap==CMAP_GREYINV32) { sdum="GreyInv32"; mOPop[2]->SetValueStr(sdum);}
|
---|
649 | else if(mCmap==CMAP_COLRJ32) { sdum="ColRJ32"; mOPop[2]->SetValueStr(sdum);}
|
---|
650 | else if(mCmap==CMAP_COLBR32) { sdum="ColBR32"; mOPop[2]->SetValueStr(sdum);}
|
---|
651 | else if(mCmap==CMAP_COLRV32) { sdum="ColRV32"; mOPop[2]->SetValueStr(sdum);}
|
---|
652 | else if(mCmap==CMAP_GREY128) { sdum="Grey128"; mOPop[2]->SetValueStr(sdum);}
|
---|
653 | else if(mCmap==CMAP_GREYINV128) { sdum="GreyInv128"; mOPop[2]->SetValueStr(sdum);}
|
---|
654 | else if(mCmap==CMAP_COLRJ128) { sdum="ColRJ128"; mOPop[2]->SetValueStr(sdum);}
|
---|
655 | else if(mCmap==CMAP_COLBR128) { sdum="ColBR128"; mOPop[2]->SetValueStr(sdum);}
|
---|
656 | else if(mCmap==CMAP_COL16) { sdum="Col16"; mOPop[2]->SetValueStr(sdum);}
|
---|
657 | }
|
---|
658 |
|
---|
659 | if(dbg)printf("H2WinArg::SetText\n");
|
---|
660 | }
|
---|
661 |
|
---|
662 | //++
|
---|
663 | void H2WinArg::GetText()
|
---|
664 | //
|
---|
665 | // Gestion des fenetres de saisie de texte.
|
---|
666 | //--
|
---|
667 | {
|
---|
668 | sscanf(mText[0]->GetText().c_str(),"%g %g",&mHMin,&mHMax);
|
---|
669 | sscanf(mText[1]->GetText().c_str(),"%g %g",&mFracMin,&mFracMax);
|
---|
670 | sscanf(mText[2]->GetText().c_str(),"%g",&mLogScale);
|
---|
671 | if(dbg) printf("H2WinArg::GetText\n");
|
---|
672 | }
|
---|
673 |
|
---|
674 | //++
|
---|
675 | void H2WinArg::SetPIH2DWdg(PIH2DWdg* h2wdg)
|
---|
676 | //
|
---|
677 | // Connexion du widget de representation d'un histogramme 2D
|
---|
678 | // avec la fenetre de gestion des parametres.
|
---|
679 | //--
|
---|
680 | {
|
---|
681 | mH2Wdg = h2wdg;
|
---|
682 | if(dbg) printf("H2WinArg::SetPIH2DWdg mH2Wdg = %lx\n",(long)mH2Wdg);
|
---|
683 | }
|
---|
684 |
|
---|
685 | //++
|
---|
686 | void H2WinArg::Process(PIMessage msg, PIMsgHandler* sender, void*)
|
---|
687 | //
|
---|
688 | // Gestions des messages.
|
---|
689 | //--
|
---|
690 | {
|
---|
691 | if(dbg) printf("PIH2DWdg::Process(%d-%d , %lx ...) \n"
|
---|
692 | ,(int)UserMsg(msg),(int)ModMsg(msg), (long)sender);
|
---|
693 |
|
---|
694 | if(!mH2Wdg) return;
|
---|
695 | PIHisto2D* mpih = mH2Wdg->GetPIHisto();
|
---|
696 | if(!mpih) return;
|
---|
697 |
|
---|
698 | int opt = UserMsg(msg);
|
---|
699 | if (opt == 6101) { mTypDisp = 0; }
|
---|
700 | else if (opt == 6102) { mTypDisp = 1; }
|
---|
701 | else if (opt == 6103) { mTypDisp = 2; }
|
---|
702 | else if (opt == 6104) { mTypDisp = 3; }
|
---|
703 |
|
---|
704 | else if (opt == 6201) { mTypScal = 0; }
|
---|
705 | else if (opt == 6202) { mTypScal = 1; }
|
---|
706 |
|
---|
707 | else if (opt == 6301) { mFgCol = false; }
|
---|
708 | else if (opt == 6302) { mFgCol = true; mCmap = CMAP_GREY32; }
|
---|
709 | else if (opt == 6303) { mFgCol = true; mCmap = CMAP_GREYINV32; }
|
---|
710 | else if (opt == 6304) { mFgCol = true; mCmap = CMAP_COLRJ32; }
|
---|
711 | else if (opt == 6305) { mFgCol = true; mCmap = CMAP_COLBR32; }
|
---|
712 | else if (opt == 6306) { mFgCol = true; mCmap = CMAP_COLRV32; }
|
---|
713 | else if (opt == 6307) { mFgCol = true; mCmap = CMAP_GREY128; }
|
---|
714 | else if (opt == 6308) { mFgCol = true; mCmap = CMAP_GREYINV128; }
|
---|
715 | else if (opt == 6309) { mFgCol = true; mCmap = CMAP_COLRJ128; }
|
---|
716 | else if (opt == 6310) { mFgCol = true; mCmap = CMAP_COLBR128; }
|
---|
717 | else if (opt == 6311) { mFgCol = true; mCmap = CMAP_COL16; }
|
---|
718 |
|
---|
719 | else if (opt == 6401) mFPoints = mPScal->GetValue()/100.;
|
---|
720 |
|
---|
721 | else if (opt==6001) {
|
---|
722 | GetText();
|
---|
723 | mpih->UseColors(mFgCol, mCmap);
|
---|
724 | mpih->UseScale(mTypScal,mLogScale);
|
---|
725 | mpih->UseDisplay(mTypDisp,mFPoints);
|
---|
726 | mpih->UseDyn(mHMin,mHMax);
|
---|
727 | mpih->UseFrac(mFracMin,mFracMax);
|
---|
728 | mH2Wdg->Refresh(); // On rafraichit le dessin (tout le PIScDrawWdg)
|
---|
729 | }
|
---|
730 | else if (opt==6002) {
|
---|
731 | this->Hide();
|
---|
732 | }
|
---|
733 | else if (opt==6003) {
|
---|
734 | mFgCol = mpih->Color();
|
---|
735 | mCmap = mpih->ColMap();
|
---|
736 | mTypScal = mpih->TypScale();
|
---|
737 | mTypDisp = mpih->TypDisplay();
|
---|
738 | mFPoints = mpih->FPoints();
|
---|
739 | mHMin = mpih->HMin();
|
---|
740 | mHMax = mpih->HMax();
|
---|
741 | mFracMin = mpih->FMin();
|
---|
742 | mFracMax = mpih->FMax();
|
---|
743 | mLogScale = mpih->LogScale();
|
---|
744 | SetText();
|
---|
745 | }
|
---|
746 | else if (opt==6004) {
|
---|
747 | mpih->Print(2);
|
---|
748 | }
|
---|
749 |
|
---|
750 | if(dbg) {
|
---|
751 | printf("H2WinArg::Process opt=%d col=%d,%d scal=%d disp=%d npt=%g\n"
|
---|
752 | ,opt,(int) mFgCol,(int) mCmap,mTypScal,mTypDisp,mFPoints);
|
---|
753 | printf(" min,max= %g,%g frac= %g,%g logsc= %g\n"
|
---|
754 | ,mHMin,mHMax,mFracMin,mFracMax,mLogScale);
|
---|
755 | }
|
---|
756 |
|
---|
757 | }
|
---|