source: Sophya/trunk/SophyaPI/PIext/pihisto2d.cc@ 2523

Last change on this file since 2523 was 2523, checked in by cmv, 22 years ago

OptionToString cmv 19/03/04

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