Changeset 82 in Sophya
- Timestamp:
- Feb 25, 1998, 5:02:27 PM (28 years ago)
- Location:
- trunk/SophyaPI/PI
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PI/pihisto2d.cc
r79 r82 1 1 #include <stdio.h> 2 2 #include "pihisto2d.h" 3 4 #include PIMENU_H 5 3 #include "nbrandom.h" 4 5 static int dbg = 0; 6 7 //++ 6 8 PIHisto2D::PIHisto2D(Histo2D* histo, bool ad) 7 9 : PIScDrawer(), mHisto(histo) 8 { 9 mAdDO = ad; // Flag pour suppression automatique de mHisto 10 UseColors(); 11 } 12 10 // 11 // Createur d'une classe de dessin pour l'histogramme 2D histo. 12 //-- 13 { 14 mAdDO = ad; // Flag pour suppression automatique de mHisto 15 16 mLogScale = 10.; 17 mFPoints = 0.5; 18 19 UseColors(); 20 UseDisplay(); 21 UseDyn(); 22 UseFrac(); 23 } 24 25 //++ 13 26 PIHisto2D::~PIHisto2D() 14 { 15 if (mAdDO) 16 delete mHisto; 17 } 18 19 void 20 PIHisto2D::UseColors(bool fg, CMapId cmap) 21 { 22 mFgCol = fg; mCmap = cmap; 23 } 24 25 void 26 PIHisto2D::UpdateSize() 27 // 28 // Destructeur. 29 //-- 30 { 31 if(mAdDO) delete mHisto; 32 } 33 34 //++ 35 void PIHisto2D::UseColors(bool fg, CMapId cmap) 36 // 37 // Choix de la couleur si fg=true 38 // (pour la couleur cmap cf picmap.h). 39 //-- 40 { 41 mFgCol = fg; mCmap = cmap; 42 } 43 44 //++ 45 void PIHisto2D::UseScale(unsigned short type,float logscale) 46 // 47 // Pour changer les echelles. 48 //| Type = 0 : echelle lineaire 49 //| = 1 : echelle log10 50 //| - Explication du codage en type=1 (log10) : 51 //| 1-/ map lineaire : 52 //| [0,1] -> [lmin,lmax] 53 //| f -> F = lmin+f*(lmax-lmin) 54 //| 2-/ transformation log10 : 55 //| [lmin,lmax] -> [log10(lmin),log10(lmax)] 56 //| F -> LF = lg10(F) 57 //| 3-/ rescaling entre 0 et 1 : 58 //| [log10(lmin),log10(lmax)] -> [0,1] 59 //| LF -> (LF-log10(lmin))/(log10(lmax)-log10(lmin)) 60 //| soit en definissant logscale = lmax/lmin 61 //| LF = log10(1.+f*(logscale-1))/log10(logscale) 62 //-- 63 { 64 if(type==0) mTypScal = 0; 65 if(type==1) { 66 mTypScal = 1; 67 if(logscale>1.) mLogScale = logscale; 68 } else mTypScal = 0; 69 } 70 71 //++ 72 void PIHisto2D::UseDisplay(unsigned short type, float fnpt) 73 // 74 // Type de Display 75 //| Type = 0 : carres de tailles variables 76 //| Type = 1 : nuages de points 77 //| Le nombre de points a utiliser est fnpt*N 78 //| ou N est le nombre de pixels ecran contenu 79 //| dans un bin de l'histogramme. 80 //| Type = 2 : code a la "hbook2" 81 //| Type = 3 : carres de tailles fixes en couleur 82 //-- 83 { 84 if(fnpt<0.) fnpt=0; else if(fnpt>1.) fnpt=1.; 85 if(type==0) mTypDisp = 0; 86 else if(type==1) { mTypDisp = 1; mFPoints = fnpt;} 87 else if(type==2) mTypDisp = 2; 88 else if(type==3) mTypDisp = 3; 89 else mTypDisp = 1; 90 } 91 92 //++ 93 void PIHisto2D::UseDyn(float hmin, float hmax) 94 // 95 // Gestion de la dynamique a representer: 96 // la dynamique va etre transformee de [hmin,hmax] vers [0,1]. 97 //-- 98 { 99 if(hmin>=hmax) {hmin = mHisto->VMin(); hmax = mHisto->VMax();} 100 if(hmin>=hmax) hmax = hmin+1.; 101 mHMin = hmin; mHMax = hmax; 102 } 103 104 //++ 105 void PIHisto2D::UseFrac(float frmin, float frmax) 106 // 107 // Pour definir la fraction de la dynamique a dessiner: 108 //| Pour certains type de display (f=[0,1] cf UseDyn), 109 //| - on ne dessine rien si f <= frmin 110 //| - on limite l'excursion a f*frmax cad [...,frmax] 111 //-- 112 { 113 if(frmax<=0. || frmax>1.) frmax = 1.; 114 if(frmin>=frmax) {frmin=0.1; frmax=0.9;} 115 mFracMin = frmin; mFracMax = frmax; 116 } 117 118 //++ 119 void PIHisto2D::Print(int lp) 120 // 121 // Print de l'etat des options du display. 122 //-- 123 { 124 printf("PIHisto2D::Print FgCol=%d Cmap=%d TypScal=%d TypDisp=%d (FPoints=%g)\n" 125 ,(int)mFgCol,(int)mCmap,mTypScal,mTypDisp,mFPoints); 126 printf(" Dyn=%g,%g Frac=%g,%g LogSc=%g H=%lx\n" 127 ,mHMin,mHMax,mFracMin,mFracMax,mLogScale,(long)mHisto); 128 if(lp<1) return; 129 mHisto->PrintStatus(); 130 } 131 132 void PIHisto2D::UpdateSize() 27 133 { 28 134 if (!mDrawer) return; 29 135 if (mDrawer->LimitsFixed()) return; 30 if (!mHisto)return;136 if(!mHisto) return; 31 137 // Commencer par trouver nos limites 32 138 … … 37 143 float ymin = mHisto->YMin(); 38 144 39 if (mDrawWdg) 145 if (mDrawWdg) 40 146 mDrawWdg->SetLimits(xmin, xmax, ymin, ymax); 41 else 147 else 42 148 mDrawer->SetLimits(xmin, xmax, ymin, ymax); 43 149 … … 45 151 } 46 152 47 48 void 49 PIHisto2D::Draw(PIGraphicUC* g, float /*xmin*/, float /*ymin*/, float /*xmax*/, float /*ymax*/) 50 { 51 if (!mHisto) return; 52 float hmin = mHisto->VMin(); 53 float hmax = mHisto->VMax(); 54 if(hmin>=hmax) hmax = hmin+1.; 55 float dx = mHisto->WBinX(); 56 float dy = mHisto->WBinY(); 57 float fracmin=0.1, fracmax=0.8; 58 59 PIColorMap* cmap=NULL; 60 PIColors coul; 61 int ncol = 0; 62 if (mFgCol) { 63 cmap = new PIColorMap(mCmap); 64 ncol = cmap->NCol(); 65 coul = g->GetForeground(); 66 // fracmin = 0.; 67 // fracmax = 1.; 153 //++ 154 void PIHisto2D::Draw(PIGraphicUC* g,float,float, float, float) 155 // 156 // Dessin de l'histogramme. 157 //-- 158 { 159 if(!mHisto) return; 160 // Caracteristiques histogramme 161 float dx = mHisto->WBinX(),dy = mHisto->WBinY(); 162 float p1dx,p1dy; 163 g->DGrC2UC(1.f,1.f,p1dx,p1dy); 164 165 // Gamme a representer entre [0,1] mais >=fracmin et scale fracmax 166 float fracmin=FMin(), fracmax=FMax(); 167 float llscale = (float) log10((double)LogScale()); 168 169 // gestion Couleurs. 170 PIColorMap* cmap=NULL; 171 PIColors coul = g->GetForeground(); 172 int ncol = 0; 173 if (mFgCol) { 174 cmap = new PIColorMap(mCmap); ncol = cmap->NCol(); 175 if(mTypDisp==3) fracmin=-1.; 176 } 177 178 // gestion Markers ou plot avec des points. 179 PIMarker Mk = g->GetMarker(); 180 int MkSz = g->GetMarkerSize(); 181 int npt = 1; 182 if(mTypDisp==1) { 183 g->SelMarker(1,PI_DotMarker); 184 npt = (int) ((float)NPixBin(g)*FPoints()); if(npt<=0) npt = 2; 185 } 186 187 // gestion Font. 188 PIFontAtt FontAtt = g->GetFontAtt(); 189 int FontSize = g->GetFontSize(); 190 if(mTypDisp==2) { 191 float dxg,dyg,dg; 192 g->DUC2GrC(dx,dy,dxg,dyg); 193 dg =(dxg<dyg) ? dxg : dyg; 194 int npix = (int) (dg*0.9); if(npix<8) npix = 8; 195 //printf("PIHisto2D::Draw_Font H dx=%g dy=%g, G dx=%g dy=%g, npix = %g,%d\n" 196 // ,dx,dy,dxg,dyg,dg,npix); 197 g->SelFontSzPt(npix,PI_RomanFont); 198 fracmin = 0; 199 } 200 201 // Print(); 202 203 // Plot de l'histogramme 204 for (int i=0; i<mHisto->NBinX(); i++) 205 for (int j=0; j<mHisto->NBinY(); j++) { 206 207 float left0,bottom0; 208 mHisto->BinLowEdge(i,j,left0,bottom0); 209 210 // Gestion de la dynamique a dessiner 211 float frac = ((*mHisto)(i,j)-HMin())/(HMax()-HMin()); 212 if(frac<0.) continue; 213 if(mTypScal==1) { // echelle log10 214 frac = log10(1.+frac*(LogScale()-1.))/llscale; 215 if(frac<0.) continue; 68 216 } 69 70 for (int i=0; i<mHisto->NBinX(); i++) { 71 for (int j=0; j<mHisto->NBinY(); j++) { 72 float left,bottom; 73 mHisto->BinLowEdge(i,j,left,bottom); 74 float frac = fracmax*((*mHisto)(i,j)-hmin)/(hmax-hmin); 75 if(frac<fracmin) continue; 76 float width = frac*dx; 77 float height = frac*dy; 78 left += 0.5*(1.-frac)*dx; 79 bottom += 0.5*(1.-frac)*dy; 80 if (cmap) { 81 int icol = ncol*(frac/fracmax); 82 if(icol>=ncol) icol = ncol-1; else if(icol<0) icol=0; 83 g->SelForeground(*cmap,icol); 84 g->DrawFBox(left,bottom,width,height); 85 } 86 else g->DrawBox(left,bottom,width,height); 217 if(frac<=fracmin) continue; 218 if(frac>1.) frac = 1.; 219 float fracred = frac * fracmax; 220 221 // Gestion de la couleur 222 int icol = 0; 223 if (cmap) { 224 icol = int( (float) ncol*frac ); 225 if(icol>=ncol) icol = ncol-1; else if(icol<0) icol=0; 226 g->SelForeground(*cmap,icol); 227 } 228 229 // Dessin proprement dit selon le choix graphique. 230 if(mTypDisp==0) { 231 //..... carres de tailles variables 232 float left = left0 + 0.5*(1.-fracred)*dx, width = fracred*dx; 233 float bottom = bottom0 + 0.5*(1.-fracred)*dy, height = fracred*dy; 234 if (cmap) g->DrawFBox(left,bottom,width,height); 235 else g->DrawBox(left,bottom,width,height); 236 } else if(mTypDisp==1) { 237 //..... nuage de points ..... 238 int ipt = int( (float) npt *frac ); 239 for(int k=0;k<ipt;k++) { 240 float x = left0 + frand01()*dx; 241 float y = bottom0 + frand01()*dy; 242 g->DrawMarker(x,y); 87 243 } 244 } else if(mTypDisp==2) { 245 //..... type hbook2/hprint .+23-Z* 246 char c[2]; 247 c[0] = HPrint2(frac); c[1]='\0'; 248 float x = left0 + dx/2.; 249 float y = bottom0 + dy/2.; 250 g->DrawString(x,y,c); 251 } else if(mTypDisp==3) { 252 //..... carres de tailles fixes (avec gestion de continuite) 253 if (cmap) g->DrawFBox(left0,bottom0,dx+p1dx,dy+p1dy); 254 else g->DrawBox(left0,bottom0,dx+p1dx,dy+p1dy); 88 255 } 89 if (cmap) { 90 g->SelForeground(coul); 91 delete cmap; 92 } 93 DrawStats(g); 94 } 95 96 void 97 PIHisto2D::DrawStats(PIGraphicUC* g) 256 257 } 258 259 // Remise dans les conditions ulterieures pour la suite du graphique. 260 g->SelMarker(MkSz,Mk); 261 g->SelForeground(coul); 262 g->SelFontSzPt(FontSize,FontAtt); 263 if (cmap) delete cmap; 264 265 // Fin du dessin, ecriture de la statistique. 266 DrawStats(g); 267 } 268 269 //++ 270 void PIHisto2D::DrawStats(PIGraphicUC* g) 271 // 272 // Dessin des informations statistiques de l'histogramme. 273 //-- 98 274 { 99 275 if (!mDrawWdg) return; … … 109 285 g->SelFontSz((mDrawWdg->YMax() - mDrawWdg->YMin())/30); 110 286 g->DrawString(mDrawWdg->XMax() - cellWidth*0.9, mDrawWdg->YMax() - cellHeight*0.8, label); 111 287 printf("H[%d,%d] Dynamique: [%g,%g] Frac [%g,%g]\n" 288 ,mHisto->NBinX(),mHisto->NBinY(),HMin(),HMax(),FMin(),FMax()); 289 } 290 291 //++ 292 char PIHisto2D::HPrint2(float f) 293 // 294 // Codage des valeurs en caracteres (fct privee). 295 //| f entre [0,1] mappee entre valeur=[0,37] 296 //| si <0 alors =0, si >1 alors 1 297 //| Display 4 ==> 4<=valeur<5 298 //| C ==> 12<=valeur<13 299 //| ==> valeur<=0 300 //| * ==> valeur>=1 301 //| . ==> 0<valeur<1 302 //|------------------------------------------ 303 //| 1111111111222222222233333333 304 //| 01234567890123456789012345678901234567 305 //| " .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*" 306 //|------------------------------------------ 307 //-- 308 { 309 char str[39] = " .+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*"; 310 int i; 311 if(f<=0.) i = 0; 312 else if(f>=1.) i = 37; 313 else { i = (int) (f*36.); i++;} 314 if(i<0) i=0; else if (i>=38) i = 37; 315 return str[i]; 316 } 317 318 //++ 319 int PIHisto2D::NPixBin(PIGraphicUC* g) 320 // 321 // Nombre de pixels ecran dans un bin d'histogramme 322 // (fct privee). 323 //-- 324 { 325 float dx = mHisto->WBinX(),dy = mHisto->WBinY(); 326 float dxg,dyg; 327 g->DUC2GrC(dx,dy,dxg,dyg); 328 int np = (int) dxg * (int) dyg; 329 //printf("PIHisto2D::NPixBin H dx=%g dy=%g, G dx=%g dy=%g, np = %d\n" 330 // ,dx,dy,dxg,dyg,np); 331 return np; 112 332 } 113 333 … … 118 338 119 339 120 // Le menu qui va servir a choisir l'option d'affichage suite au click 121 // de bouton-3 122 static PIPUMenu* optmenh2d=NULL; 123 static int nb_optmen = 0; 124 340 static H2WinArg* h2dWinArg=NULL; 341 static int nb_h2dWinArg = 0; 342 343 //++ 125 344 PIH2DWdg::PIH2DWdg(PIContainerGen *par, char *nom, int sx, int sy, int px, int py) 345 // 346 // Createur d'un Widget de dessin d'histogramme 2D. 347 // Le menu pour choisir l'option d'affichage apparait suite au clic 348 // du bouton-3 de la souris. 349 //-- 126 350 : PIScDrawWdg(par,nom,sx,sy,px,py) 127 351 { 128 if (!optmenh2d) { 129 optmenh2d = new PIPUMenu((PIMsgHandler *)this, "TypeH2D"); 130 optmenh2d->AppendItem("B&W", 6101); 131 optmenh2d->AppendItem("Gris", 6102); 132 optmenh2d->AppendItem("RJ32", 6103); 133 optmenh2d->AppendItem("BR32", 6104); 134 } 135 nb_optmen++; 352 if (!h2dWinArg) h2dWinArg = new H2WinArg(this); 353 nb_h2dWinArg++; 354 if(dbg) printf("PIH2DWdg::PIH2DWdg %lx h2dWinArg=%lx %d\n" 355 ,(long)this,(long)h2dWinArg,nb_h2dWinArg); 136 356 mPih = NULL; 137 ActivateButton(3); // Pour afficher le menu option de trace 138 } 139 357 // Pour afficher le menu option de trace 358 ActivateButton(3); 359 } 360 361 //++ 140 362 PIH2DWdg::~PIH2DWdg() 141 { 142 nb_optmen--; 143 if (nb_optmen == 0) { delete optmenh2d; optmenh2d=NULL; } 144 if (mPih) delete mPih; 145 } 146 147 void PIH2DWdg::SetHisto(Histo2D* histo, bool fg, CMapId cmap) 363 // 364 // Destructeur. 365 //-- 366 { 367 nb_h2dWinArg--; 368 if (nb_h2dWinArg == 0) { 369 h2dWinArg->Hide(); 370 delete h2dWinArg; 371 h2dWinArg=NULL; 372 } 373 if(dbg) printf("PIH2DWdg::~PIH2DWdg h2dWinArg=%lx %d\n" 374 ,(long)h2dWinArg,nb_h2dWinArg); 375 if (mPih) delete mPih; 376 } 377 378 //++ 379 void PIH2DWdg::SetHisto(Histo2D* histo) 380 // 381 // Pour connecter un histogramme 2D au Widget. 382 //-- 148 383 { 149 384 if (!histo) return; 150 385 if (mPih) delete mPih; 151 386 mPih = new PIHisto2D(histo, true); 152 mPih->UseColors(fg, cmap);153 387 AddScDrawer(mPih); 154 } 155 388 if(dbg) printf("PIH2DWdg::SetHisto mPih=%lx\n",(long)mPih); 389 } 390 391 //++ 156 392 string PIH2DWdg::GetClickText(float x, float y) 393 // 394 // Quand on click (and drag) le bouton-1, affichage 395 // des positions x,y et de la valeur du bin de l'histogramme 2D. 396 //-- 157 397 { 158 398 int i,j; … … 161 401 if ((!mPih) || (!mPih->Histogram())) { 162 402 sprintf(str,"X=%g Y=%g ???",x,y); 163 return((string)str); 403 return((string)str); 164 404 } 165 405 166 406 Histo2D* h = mPih->Histogram(); 167 168 407 169 408 h->FindBin(x,y,i,j); 170 409 if(i<0 || i>=h->NBinX() || j<0 || j>=h->NBinY()) 171 sprintf(str," X=%g Y=%g ???",x,y);172 else sprintf(str," X=%g Y=%g v=%g",x,y,(*h)(i,j));410 sprintf(str,"x= %g y= %g ???",x,y); 411 else sprintf(str,"x= %g y= %g v= %g",x,y,(*h)(i,j)); 173 412 174 413 return((string)str); 175 414 } 176 415 177 void PIH2DWdg::Process(PIMessage msg, PIMsgHandler* sender, void* data) 178 { 179 //printf("PIH2DWdg::Process(%d-%d , %lx ...) \n", UserMsg(msg), ModMsg(msg), (long)sender); 180 if (!mPih) return; 181 if (sender == optmenh2d) { // On n'attend de message que de la part du menu 182 int opt=6101; 183 bool fgc=false; 184 CMapId col=CMAP_GREYINV32; 185 186 opt = UserMsg(msg); 187 if (opt == 6102) { fgc = true; col = CMAP_GREYINV32; } 188 else if (opt == 6103) { fgc = true; col = CMAP_COLRJ32; } 189 else if (opt == 6104) { fgc = true; col = CMAP_COLBR32; } 190 mPih->UseColors(fgc, col); 191 mPih->Refresh(); // On rafraichit le dessin 192 } 193 194 } 195 416 //++ 196 417 void PIH2DWdg::But3Press(int x, int y) 197 { 198 //printf("PIH2DWdg::But3Press(%d %d ) \n", x, y); 199 optmenh2d->SetMsgParent((PIMsgHandler*)this); 200 optmenh2d->Show(this, x, y); 201 } 418 // 419 // Gestion de l'utilisation du bouton-3 de la souris. 420 // Un seul objet est cree pour tous les histogrammes 2D. 421 // Il est connecte a un histogramme donnee par l'action du 422 // du bouton-3 de la souris dans la fenetre contenant 423 // le dessin de l'histogramme. 424 //-- 425 { 426 h2dWinArg->SetPIH2DWdg(this); 427 h2dWinArg->SetMsgParent((PIMsgHandler*)this); 428 if(!h2dWinArg->Visible()) h2dWinArg->Show(); 429 if(dbg) printf("PIH2DWdg::But3Press(%d,%d) h2dWinArg=%lx\n" 430 ,x,y,(long)h2dWinArg); 431 } 432 433 434 ///////////////////////////////////////////////////////////////// 435 // Classe H2WinArg 436 ///////////////////////////////////////////////////////////////// 437 438 //++ 439 H2WinArg::H2WinArg(PIH2DWdg *par) 440 // 441 // Creation de la fenetre de gestion des parametres 442 // des dessins des histogrammes 2D. 443 //-- 444 : PIWindow((PIMsgHandler *)par, "Options", PIWK_dialog,250,260,150,150) 445 { 446 string sdum; 447 if(dbg) printf("H2WinArg::H2WinArg %lx par=%lx\n",(long)this,(long)par); 448 449 mH2Wdg = NULL; 450 451 mFgCol = false; 452 mCmap = CMAP_GREYINV32; 453 mTypScal = 0; 454 mTypDisp = 0; 455 mFPoints = 0.5; 456 mHMin = 1.; 457 mHMax = -1.; 458 mFracMin = 0.1; 459 mFracMax = 0.9; 460 mLogScale = 10.; 461 462 // menus bar 463 mPop[0] = new PIPUMenu((PIMsgHandler *)this,"Display"); 464 mPop[0]->AppendItem("Carres Var." , 6101); 465 mPop[0]->AppendItem("....." , 6102); 466 mPop[0]->AppendItem(".+12..Z*" , 6103); 467 mPop[0]->AppendItem("Carres Pleins", 6104); 468 mOPop[0] = new PIOptMenu(this,mPop[0],100,25,10,10); 469 sdum = "Carres Var."; mOPop[0]->SetValueStr(sdum); 470 471 mPop[1] = new PIPUMenu((PIMsgHandler *)this,"Scale"); 472 mPop[1]->AppendItem("Lineaire", 6201); 473 mPop[1]->AppendItem("Log10" , 6202); 474 mOPop[1] = new PIOptMenu(this,mPop[1],100,25,10,40); 475 sdum = "Lineaire"; mOPop[1]->SetValueStr(sdum); 476 477 mPop[2] = new PIPUMenu((PIMsgHandler *)this,"Color"); 478 mPop[2]->AppendItem("B&W" , 6301); 479 mPop[2]->AppendItem("Grey32" , 6302); 480 mPop[2]->AppendItem("GreyInv32", 6303); 481 mPop[2]->AppendItem("RJ32" , 6304); 482 mPop[2]->AppendItem("BR32" , 6305); 483 mPop[2]->AppendItem("RV32" , 6306); 484 mPop[2]->AppendItem("Arc16" , 6307); 485 mOPop[2] = new PIOptMenu(this,mPop[2],100,25,10,70); 486 sdum = "B&W"; mOPop[2]->SetValueStr(sdum); 487 488 // Labels et zone de saisie texte 489 mLab[0] = new PILabel(this, " Dyn: ",60,30,10,110); 490 mLab[1] = new PILabel(this, " Frac: ",60,30,10,145); 491 mLab[2] = new PILabel(this, " LogScal: ",60,30,10,180); 492 493 mText[0] = new PIText(this, "Dynamique",150,30,80,110); 494 mText[1] = new PIText(this, "Fraction" ,150,30,80,145); 495 mText[2] = new PIText(this, "LogScale" ,150,30,80,180); 496 SetText(); 497 498 // Labels et curseur mobile 499 mLab[3] = new PILabel(this, " PerPt: ",60,30,10,215); 500 mPScal = new PIScale(this,"FracPoints",6401,true,150,20,80,215); 501 mPScal->SetMinMax(0,100); 502 int imfp = mFPoints*100.f; 503 mPScal->SetValue(imfp); 504 505 // Boutons 506 mBut[0] = new PIButton(this, "Apply", 6001, 50, 20, 150,10); 507 mBut[1] = new PIButton(this, "Close", 6002, 50, 20, 150,35); 508 mBut[2] = new PIButton(this, "Get" , 6003, 50, 20, 150,60); 509 mBut[3] = new PIButton(this, "Print", 6004, 50, 20, 150,85); 510 FinishCreate(); 511 } 512 513 //++ 514 H2WinArg::~H2WinArg() 515 // 516 // Destructeur. 517 //-- 518 { 519 int i; 520 if(dbg) printf("H2WinArg::~H2WinArg %lx\n",(long)this); 521 for(i=0;i<3;i++) {delete mPop[i]; delete mOPop[i];} 522 for(i=0;i<4;i++) delete mBut[i]; 523 for(i=0;i<4;i++) delete mLab[i]; 524 for(i=0;i<3;i++) delete mText[i]; 525 delete mPScal; 526 } 527 528 //++ 529 void H2WinArg::SetText() 530 // 531 // Gestion des fenetres de saisie de texte. 532 //-- 533 { 534 string sdum; 535 char str[256]; 536 sprintf(str,"%g %g",mHMin,mHMax); 537 mText[0]->SetText(str); 538 sprintf(str,"%g %g",mFracMin,mFracMax); 539 mText[1]->SetText(str); 540 sprintf(str,"%g",mLogScale); 541 mText[2]->SetText(str); 542 543 if(mTypDisp==0) { sdum="Carres Var."; mOPop[0]->SetValueStr(sdum);} 544 else if(mTypDisp==1) { sdum="....."; mOPop[0]->SetValueStr(sdum);} 545 else if(mTypDisp==2) { sdum=".+12..Z*"; mOPop[0]->SetValueStr(sdum);} 546 else if(mTypDisp==3) { sdum="Carres Pleins"; mOPop[0]->SetValueStr(sdum);} 547 548 if(mTypScal==0) { sdum="Lineaire"; mOPop[1]->SetValueStr(sdum);} 549 else if(mTypScal==1) { sdum="Log10"; mOPop[1]->SetValueStr(sdum);} 550 551 if(!mFgCol) { sdum="B&W"; mOPop[2]->SetValueStr(sdum);} 552 else { 553 if(mCmap==CMAP_GREY32) { sdum="Grey32"; mOPop[2]->SetValueStr(sdum);} 554 else if(mCmap==CMAP_GREYINV32) { sdum="GreyInv32"; mOPop[2]->SetValueStr(sdum);} 555 else if(mCmap==CMAP_COLRJ32) { sdum="RJ32"; mOPop[2]->SetValueStr(sdum);} 556 else if(mCmap==CMAP_COLBR32) { sdum="BR32"; mOPop[2]->SetValueStr(sdum);} 557 else if(mCmap==CMAP_COLRV32) { sdum="RV32"; mOPop[2]->SetValueStr(sdum);} 558 else if(mCmap==CMAP_COL16) { sdum="Arc16"; mOPop[2]->SetValueStr(sdum);} 559 } 560 561 printf("H2WinArg::SetText\n"); 562 } 563 564 //++ 565 void H2WinArg::GetText() 566 // 567 // Gestion des fenetres de saisie de texte. 568 //-- 569 { 570 sscanf(mText[0]->GetText().c_str(),"%g %g",&mHMin,&mHMax); 571 sscanf(mText[1]->GetText().c_str(),"%g %g",&mFracMin,&mFracMax); 572 sscanf(mText[2]->GetText().c_str(),"%g",&mLogScale); 573 if(dbg) printf("H2WinArg::GetText\n"); 574 } 575 576 //++ 577 void H2WinArg::SetPIH2DWdg(PIH2DWdg* h2wdg) 578 // 579 // Connexion du widget de representation d'un histogramme 2D 580 // avec la fenetre de gestion des parametres. 581 //-- 582 { 583 mH2Wdg = h2wdg; 584 if(dbg) printf("H2WinArg::SetPIH2DWdg mH2Wdg = %lx\n",(long)mH2Wdg); 585 } 586 587 //++ 588 void H2WinArg::Process(PIMessage msg, PIMsgHandler* sender, void*) 589 // 590 // Gestions des messages. 591 //-- 592 { 593 if(dbg) printf("PIH2DWdg::Process(%d-%d , %lx ...) \n" 594 ,(int)UserMsg(msg),(int)ModMsg(msg), (long)sender); 595 596 if(!mH2Wdg) return; 597 PIHisto2D* mpih = mH2Wdg->GetPIHisto(); 598 if(!mpih) return; 599 600 int opt = UserMsg(msg); 601 if (opt == 6101) { mTypDisp = 0; } 602 else if (opt == 6102) { mTypDisp = 1; } 603 else if (opt == 6103) { mTypDisp = 2; } 604 else if (opt == 6104) { mTypDisp = 3; } 605 606 else if (opt == 6201) { mTypScal = 0; } 607 else if (opt == 6202) { mTypScal = 1; } 608 609 else if (opt == 6301) { mFgCol = false; } 610 else if (opt == 6302) { mFgCol = true; mCmap = CMAP_GREY32; } 611 else if (opt == 6303) { mFgCol = true; mCmap = CMAP_GREYINV32; } 612 else if (opt == 6304) { mFgCol = true; mCmap = CMAP_COLRJ32; } 613 else if (opt == 6305) { mFgCol = true; mCmap = CMAP_COLBR32; } 614 else if (opt == 6306) { mFgCol = true; mCmap = CMAP_COLRV32; } 615 else if (opt == 6307) { mFgCol = true; mCmap = CMAP_COL16; } 616 617 else if (opt == 6401) mFPoints = mPScal->GetValue()/100.; 618 619 else if (opt==6001) { 620 GetText(); 621 mpih->UseColors(mFgCol, mCmap); 622 mpih->UseScale(mTypScal,mLogScale); 623 mpih->UseDisplay(mTypDisp,mFPoints); 624 mpih->UseDyn(mHMin,mHMax); 625 mpih->UseFrac(mFracMin,mFracMax); 626 mpih->Refresh(); // On rafraichit le dessin 627 } 628 else if (opt==6002) { 629 this->Hide(); 630 } 631 else if (opt==6003) { 632 mFgCol = mpih->Color(); 633 mCmap = mpih->ColMap(); 634 mTypScal = mpih->TypScale(); 635 mTypDisp = mpih->TypDisplay(); 636 mFPoints = mpih->FPoints(); 637 mHMin = mpih->HMin(); 638 mHMax = mpih->HMax(); 639 mFracMin = mpih->FMin(); 640 mFracMax = mpih->FMax(); 641 mLogScale = mpih->LogScale(); 642 SetText(); 643 } 644 else if (opt==6004) { 645 mpih->Print(2); 646 } 647 648 if(dbg) { 649 printf("H2WinArg::Process opt=%d col=%d,%d scal=%d disp=%d npt=%g\n" 650 ,opt,(int) mFgCol,(int) mCmap,mTypScal,mTypDisp,mFPoints); 651 printf(" min,max= %g,%g frac= %g,%g logsc= %g\n" 652 ,mHMin,mHMax,mFracMin,mFracMax,mLogScale); 653 } 654 655 } -
trunk/SophyaPI/PI/pihisto2d.h
r76 r82 1 1 #ifndef PIHISTO2D_H 2 2 #define PIHISTO2D_H 3 4 #include "pisysdep.h" 5 #include PIMENU_H 6 #include PIMENUBAR_H 7 #include PIOPTMENU_H 3 8 4 9 #include "histos2.h" 5 10 #include "piscdrawwdg.h" 6 11 12 //////////////////////////////////////////////////////////////////// 7 13 class PIHisto2D : public PIScDrawer { 8 14 public: … … 10 16 virtual ~PIHisto2D(); 11 17 void UseColors(bool fg=false, CMapId cmap=CMAP_GREYINV32); 12 virtual void Draw(PIGraphicUC* g, float xmin, float ymin, float xmax, float ymax); 18 void UseScale(unsigned short type=0,float logscale=10.); 19 void UseDisplay(unsigned short type=0, float fnpt=0.5); 20 void UseDyn(float hmin=1., float hmax=-1.); 21 void UseFrac(float frmin=0.1, float frmax=0.9); 22 void Print(int lp=0); 23 virtual void Draw(PIGraphicUC* g,float xmin,float ymin,float xmax,float ymax); 13 24 virtual void UpdateSize(); 14 25 virtual void DrawStats(PIGraphicUC* g); 15 inline Histo2D* Histogram() { return(mHisto); } 26 27 inline Histo2D* Histogram() { return(mHisto); } 28 inline bool Color() { return(mFgCol); } 29 inline CMapId ColMap() { return(mCmap); } 30 inline unsigned short TypScale() { return(mTypScal); } 31 inline unsigned short TypDisplay() { return(mTypDisp); } 32 inline float FPoints() { return(mFPoints); } 33 inline float HMax() { return(mHMax);} 34 inline float HMin() { return(mHMin);} 35 inline float FMax() { return(mFracMax);} 36 inline float FMin() { return(mFracMin);} 37 inline float LogScale() { return(mLogScale);} 16 38 17 39 protected: 40 int NPixBin(PIGraphicUC* g); 41 char HPrint2(float f); 42 18 43 Histo2D* mHisto; 19 44 bool mFgCol; 20 45 CMapId mCmap; 46 unsigned short mTypScal; 47 unsigned short mTypDisp; 48 float mFPoints; 49 float mHMin,mHMax; 50 float mFracMin,mFracMax; 51 float mLogScale; 21 52 }; 22 53 54 //////////////////////////////////////////////////////////////////// 23 55 class PIH2DWdg : public PIScDrawWdg { 24 56 public: … … 27 59 ~PIH2DWdg(); 28 60 29 virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL); 30 void SetHisto(Histo2D* histo, bool fg=false, CMapId cmap=CMAP_GREYINV32); 31 61 void SetHisto(Histo2D* histo); 62 inline PIHisto2D* GetPIHisto() {return mPih;} 32 63 33 64 virtual string GetClickText(float x, float y); … … 39 70 }; 40 71 72 //////////////////////////////////////////////////////////////////// 73 class H2WinArg : public PIWindow { 74 public : 75 H2WinArg(PIH2DWdg *par); 76 ~H2WinArg(); 77 void SetPIH2DWdg(PIH2DWdg* h2wdg); 78 void SetText(); 79 void GetText(); 80 virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL); 81 82 protected: 83 PIH2DWdg * mH2Wdg; 84 85 PIPUMenu * mPop[3]; 86 PIOptMenu * mOPop[3]; 87 PIButton * mBut[4]; 88 PILabel * mLab[4]; 89 PIText * mText[3]; 90 PIScale * mPScal; 91 92 bool mFgCol; 93 CMapId mCmap; 94 unsigned short mTypScal; 95 unsigned short mTypDisp; 96 float mFPoints; 97 float mHMin,mHMax; 98 float mFracMin,mFracMax; 99 float mLogScale; 100 }; 101 41 102 #endif
Note:
See TracChangeset
for help on using the changeset viewer.