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

Last change on this file since 3455 was 3153, checked in by ansari, 19 years ago

Adaptation+petites corrections, suite gestion P1D,P2DArrayAdapter::DecodeOptionString() ::OptionToString() par PIImage et PISurfDrawer, Reza 19/01/2007

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