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