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

Last change on this file since 3075 was 3075, checked in by cmv, 19 years ago

remplacement nbrandom.h (obsolete) -> srandgen.h cmv 14/09/2006

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