source: Sophya/trunk/SophyaPI/PI/Tests/midasitt.cc@ 1128

Last change on this file since 1128 was 1128, checked in by ercodmgr, 25 years ago

une image + facile pour voir les lut cmv 8/8/2000

File size: 15.8 KB
RevLine 
[1123]1#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include <math.h>
5
6#include <iostream.h>
7
8#include "pisysdep.h"
9
10#include PIAPP_H
11#include PIMENU_H
12#include PISTDWDG_H
13#include PIWIN_H
14#include PIPERIODIC_H
15
16#include "pidrawwin.h"
17#include "piscdrawwdg.h"
18#include "piimage.h"
19#include "parradapter.h"
20
21#include "psfile.h"
22
23#include "piimgtools.h"
24#include "pidrwtools.h"
25
26#include "pisurfdr.h"
27
28// ---------- classe PITApp -----------------------
29class PITApp : public PIApplication {
30public:
31 PITApp(int narg=0, char* arg[]=NULL);
32 ~PITApp();
33 virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
34
35 PIMenu* m[3];
36 PIText* txt;
37 PIPixmap* zoom;
38 PICMapView* cmapv;
39 PIWindow *mCurW;
40 PIColorMap midas_cmap;
41};
42
43/* Tableau pour lire les composantes RGB de MIDAS_ITT */
44static double rgb_r[512];
45static double rgb_g[512];
46static double rgb_b[512];
47static int rgb_ncol = 0;
48
49/* --Methode-- */
50PITApp::PITApp(int narg, char* arg[])
51 : PIApplication(360, 130, narg, arg) , midas_cmap("MIDAS_ColMap", rgb_ncol)
52{
53
54m[0] = new PIMenu(Menubar(),"Fichier");
55m[0]->AppendItem("Info", 10101);
56m[0]->AppendItem("Close", 10110);
57m[0]->AppendItem("Exit", 10150);
58// On accroche le menu au Menubar
59AppendMenu(m[0]);
60
61// 2eme Menu
62
63m[1] = new PIMenu(Menubar(),"Graphics");
64m[1]->AppendItem("Sin(x)/x", 10201);
65m[1]->AppendItem("YfXDrawer", 10202);
66m[1]->AppendItem("2-Drawers", 10203);
67m[1]->AppendItem("Surf-3D", 10204);
68m[1]->AppendItem("Surf-3D-Color", 10205);
69m[1]->AppendItem("Image", 10206);
[1128]70m[1]->AppendItem("Image Gauss", 10207);
[1123]71
72AppendMenu(m[1]);
73
74
75m[2] = new PIMenu(Menubar(),"Tools");
76m[2]->AppendItem("ShowImageTools", 10301);
77m[2]->AppendItem("ShowDrawerTools", 10302);
78m[2]->AppendItem("PostScript (EPS)", 10305);
79AppendMenu(m[2]);
80
81MainWin()->SetSize(360,130);
82zoom = new PIPixmap(MainWin(), "Zoom", 90, 90, 5, 5);
83zoom->SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
84// zoom->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_elastic,PIBK_fixed);
85cmapv = new PICMapView(MainWin(), "CMapView", 350, 25, 5, 100);
86cmapv->SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
87// cmapv->SetBinding(PIBK_fixed,PIBK_free,PIBK_fixed,PIBK_free);
88// Creation d' zone texte multiligne
89txt = new PIText(MainWin(), "mltext", 250, 90, 105, 5);
90txt->SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
91// txt->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed,PIBK_free);
92txt->SetMutiLineMode(true);
93txt->SetTextEditable(false);
94txt->SetText("");
95
96// On alloue les couleurs de la MIDAS_ITT
97 cout << " Allocating MIDAS ITT colors in midas_cmap NCol=" << rgb_ncol << endl;
98PIColor col; // Les couleurs PI sont des entiers de 0 a 65535 (16 bits)
99for(int kc=0; kc<rgb_ncol; kc++) {
100 col.red = rgb_r[kc]*65535;
101 col.green = rgb_g[kc]*65535;
102 col.blue = rgb_b[kc]*65535;
103 midas_cmap.AllocColor(col, kc);
104 }
105SetReady();
106}
107
108/* --Methode-- */
109PITApp::~PITApp()
110{
111for(int i=0; i<3; i++) delete m[i];
112delete txt;
113delete cmapv;
114delete zoom;
115}
116
117
118static int nbwin = 0;
119static int numpsf = 0;
120static int fgswcol = 0;
121
122static double fsinc(double x) {if ( (x>-1.e-8) && (x<1.e-8) ) return(0.); else return (sin(x)/x);}
123
124/* --Methode-- */
125void PITApp::Process(PIMessage msg, PIMsgHandler* sender, void* data)
126{
127char strg[64];
128int i,j;
129
130if ( ( ModMsg(msg) == PIMsg_Active) || (ModMsg(msg) == PIMsg_Close) ) {
131 PIWdg *sndw;
132 sndw = (PIWdg *)sender;
133 if (sndw->kind() == PIWindow::ClassId) {
134 if (ModMsg(msg) == PIMsg_Close) {
135 printf("PITApp::Process()/Debug : Closing Window %lx \n", (long)sender);
136 delete (PIWindow *)sender;
137 mCurW = NULL; }
138 else mCurW = (PIWindow *)sender;
139 }
140}
141else
142 {
143 switch(UserMsg(msg))
144 {
145
146// --------- 1er menu ----------
147 case 10101:
148 txt->SetText("pitgr: PI Graphics Tests \n * 2-D graphics \n * 3-D Graphics \n Image display ");
149 break;
150
151 case 10110 :
152 if (mCurW) { mCurW->Hide(); delete mCurW;}
153 mCurW = NULL;
154 break;
155
156 case 10150: // Sortie d'application
157 Stop();
158 break;
159
160
161// ---------- 3eme menu --------
162 case 10301 :
163 PIImgTools::ShowPIImgTools();
164 break;
165 case 10302 :
166 PIDrwTools::ShowPIDrwTools();
167 break;
168 case 10305 :
169 if(mCurW) {
170 char buff[64];
171 sprintf(buff, "pigr_%d.eps", numpsf); numpsf++;
172 printf("Creating EPS File %s (Encapsulated PostScript) \n", buff);
173 PSFile *mps;
174 mps = new PSFile(buff);
175 mCurW->PSPrint(mps,0,0);
176 delete mps;
177 }
178 break;
179
180// ---------- 2eme menu --------
181
182 case 10201 : // Trace de la fonction sin(x)/x
183 {
184 SetBusy(); // souris -> montre
185 txt->SetText("PIScDrawWdg Creation\n Sin(x)/x \n Button 1 -> Coord \n Button 2 Zoom \n <Alt>O <Alt>V \n Try DrawerTools");
186
187 PIFuncDrawer* mfd = new PIFuncDrawer(fsinc);
188 mfd->SetColAtt(PI_Gold);
189 mfd->SetLineAtt(PI_NormalLine);
190 nbwin++; sprintf(strg,"2D Graphics (PI W %d)", nbwin);
191 PIWindow* wp = new PIWindow(this, strg, PIWK_normal, 300, 300, 150, 150);
192 wp->SetAutoDelChilds(true);
193 PIScDrawWdg* scd = new PIScDrawWdg(wp, "scwdg-sinc", 300, 300, 0, 0);
194 scd->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
195 scd->SetLimits(0.1, 30., -1., 1.);
196 scd->AddScDrawer(mfd,true);
197 scd->BaseDrawer()->ElAddText(2, 0.8, "Y = Sin(x)/x", PI_Red);
198 scd->SetTitles(" --- PIFuncDrawer (Sin(x)/x) --- ");
199 wp->Show(); // On affiche la fenetre
200 SetReady(); // souris->pointeur , on n'est plus occupe
201 }
202 break;
203
204
205 case 10202 : // Trace Test de PIYfXDrawer
206 {
207 SetBusy(); // souris -> montre
208 txt->SetText("PIScDrawWdg Creation\n PIYfXDrawer \n Button 1 -> Coord \n Button 2 Zoom \n <Alt>O <Alt>V \n Try DrawerTools");
209
210 float* vpx = new float[30];
211 float* vpy = new float[30];
212 int i; double x;
213 for(i=0; i<30; i++) { x = 8.*i/30; vpx[i] = x; vpy[i] = 3*cos(x)+2*sin(x); }
214 PIYfXDrawer* mxyd = new PIYfXDrawer( new P1DAdapter<float>(vpx, 30, true),
215 new P1DAdapter<float>(vpy, 30, true), true);
216 mxyd->SetColAtt(PI_Red);
217 mxyd->SetMarkerAtt(7, PI_FTriangleMarker);
218
219 nbwin++; sprintf(strg,"2D Graphics (PI W %d)", nbwin);
220 PIWindow* awp = new PIWindow(this, strg, PIWK_normal, 300, 300, 300, 300);
221 PIScDrawWdg* scd = new PIScDrawWdg(awp, "scwdg-YfX", 300, 300, 0, 0);
222 scd->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
223 scd->AddScDrawer(mxyd,true);
224 scd->SetTitles(" --- PIYfXDrawer (3*cons(x)+2*sin(x)) --- ");
225 awp->SetAutoDelChilds(true);
226 awp->Show();
227 SetReady();
228 }
229 break;
230
231 case 10203 : // FunDrawer + PIYfXDrawer
232 {
233 SetBusy(); // souris -> montre
234 txt->SetText("PIScDrawWdg Creation\n PIYfXDrawer + FuncDrawer(Sin(x)/x) \n Button 1 -> Coord \n Button 2 Zoom \n <Alt>O <Alt>V \n Try DrawerTools");
235
236 float* vpx = new float[30];
237 float* vpy = new float[30];
238 int i; double x;
239 for(i=0; i<30; i++) { x = 8.*i/30; vpx[i] = x; vpy[i] = 3*cos(x)+2*sin(x); }
240 PIYfXDrawer* mxyd = new PIYfXDrawer( new P1DAdapter<float>(vpx, 30, true),
241 new P1DAdapter<float>(vpy, 30, true), true);
242
243 mxyd->SetColAtt(PI_Magenta);
244 mxyd->SetMarkerAtt(7, PI_FBoxMarker);
245
246 PIFuncDrawer* mfd = new PIFuncDrawer(fsinc);
247 mfd->SetColAtt(PI_Blue);
248 mfd->SetLineAtt(PI_NormalLine);
249
250 nbwin++; sprintf(strg,"2D Graphics (PI W %d)", nbwin);
251 PIWindow* awp = new PIWindow(this, strg, PIWK_normal, 400, 400, 300, 300);
252 PIScDrawWdg* scd = new PIScDrawWdg(awp, "scwdg-YfX", 400, 400, 0, 0);
253 scd->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed);
254 scd->AddScDrawer(mxyd,true);
255 scd->AddScDrawer(mfd,true);
256 scd->SetTitles(" --- PIYfXDrawer + PIFuncDrawer --- ");
257 awp->SetAutoDelChilds(true);
258 awp->Show();
259
260 SetReady();
261 }
262 break;
263
[1128]264 case 10207 :
265 {
266 SetBusy(); // souris -> montre
267 txt->SetText("PIImage Creation\n Image Display \n Button 1 -> Coord/value \n Button 2 Select Rectangle \n Butt on 3 Move \n <Alt>O <Alt>V <Alt>C \n Try ImageTools");
268
269 int sx=400, sy=600;
270 printf(" Creating Image (%dx%d) ... ", sx, sy);
271 float* img = new float[sx*sy];
272 int i, j;
273 for(i=0;i<sx;i++) {
274 double x = (i-sx/2.)/(sx/5.);
275 for(j=0;j<sy;j++) {
276 double y = (j-sy/2.)/(sy/5.);
277 y = -0.5*(x*x+y*y);
278 if(y<-80.) y=0.;
279 img[j*sx+i] = 1000.*exp(-0.5*(x*x+y*y));
280 }
281 }
282 printf(" >> OK \n");
283 nbwin++; sprintf(strg,"Image (PI W %d)", nbwin);
284 PIWindow* awp = new PIWindow(this, strg, PIWK_normal, sx, sy, 300, 300);
285 PIImage * pii = new PIImage(awp, "fitsimage", sx, sy, 0, 0);
286 pii->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_fixed);
287 pii->SetZoomWin(zoom, false);
288 pii->SetCMapWin(cmapv, false);
289 pii->ShowCursor(true);
290 pii->SetColMap(&midas_cmap, false);
291 awp->SetAutoDelChilds(true);
292 awp->Show();
293 pii->SetImage(new P2DAdapter<float>(img, sx, sy, true), true);
294 SetReady();
295 }
296 break;
297
[1123]298 case 10206 :
299 {
300 SetBusy(); // souris -> montre
301 txt->SetText("PIImage Creation\n Image Display \n Button 1 -> Coord/value \n Button 2 Select Rectangle \n Butt on 3 Move \n <Alt>O <Alt>V <Alt>C \n Try ImageTools");
302
303 int sx, sy;
304 sx = 400;
305 sy = 600;
306 printf(" Creating Image (%dx%d) ... ", sx, sy);
307 float* img = new float[sx*sy];
308 int i, j, k, kk, i0, j0;
309 double lamp, amp,x,y;
310 for(k=0; k<sx*sy; k++) img[k] = 1000.+(random()%200-100);
311// On genere 500 etoiles
312 for(k=0; k<500; k++) {
313 i0 = 20+random()%(sx-20);
314 j0 = 20+random()%(sy-20);
315 lamp = 2.0+0.012*(random()%100);
316 amp = pow(10., lamp);
317// if (k%5 == 0) printf(" DBG %d %d - %g \n", i0, j0, flux);
318 for(i=i0-15; i<i0+15; i++) {
319 if(i<0 || i>=sx) continue;
320 for(j=j0-15; j<j0+15; j++) {
321 if(j<0 || j>=sy) continue;
322 x = i-i0; y = j-j0;
323 kk = j*sx+i;
324 img[kk] += amp*exp(-(x*x)/7.-(y*y)/8.);
325 }
326 }
327 }
328 printf(" >> OK \n");
329
330 nbwin++; sprintf(strg,"Image (PI W %d)", nbwin);
331 PIWindow* awp = new PIWindow(this, strg, PIWK_normal, sx, sy, 300, 300);
332 PIImage * pii = new PIImage(awp, "fitsimage", sx, sy, 0, 0);
333 pii->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_fixed);
334 pii->SetZoomWin(zoom, false);
335 pii->SetCMapWin(cmapv, false);
336 pii->ShowCursor(true);
337 pii->SetColMap(&midas_cmap, false);
338 awp->SetAutoDelChilds(true);
339 awp->Show();
340 pii->SetImage(new P2DAdapter<float>(img, sx, sy, true), true);
341 SetReady();
342 }
343 break;
344
345
346// Dessins 3D
347 case 10204:
348 {
349 SetBusy(); // souris -> montre
350 txt->SetText("PIDraw3DWdg Creation\n 3-D Surf Display \n Button 1 \n (Shift) Button 2 Rotate \n Button Zoom \n <Alt>O <Alt>V \n Try DrawerTools");
351
352 printf(" Creating Matrix 80x60 ... ");
353 float* tf = new float[60*80];
354 int i,j,k;
355 double xp,yp,rp;
356 for(i=0; i<80; i++)
357 for(j=0; j<60; j++) {
358 xp = i-30; yp = j-20;
359 rp = (xp*xp)/16.+(yp*yp)/9.;
360 tf[j*80+i] = 10.*exp(-rp);
361 xp = i-50; yp = j-28;
362 rp = (xp*xp)/9.+(yp*yp)/9.;
363 tf[j*80+i] += 4.*exp(-rp);
364 }
365 printf(" >> OK \n");
366
367 nbwin++; sprintf(strg,"3D Surf (PI W %d)", nbwin);
368 PIWindow* awp = new PIWindow(this, strg, PIWK_normal, 500, 500, 200, 200);
369 PISurfaceDrawer* sd = new PISurfaceDrawer(new P2DAdapter<float>(tf, 80, 60, true), true, true, true);
370 PIDraw3DWdg* drw3 = new PIDraw3DWdg(awp, "ex3ddrw", 500, 500, 0, 0);
371 drw3->SetBinding(PIBK_fixed , PIBK_fixed , PIBK_fixed, PIBK_fixed);
372 drw3->AddDrawer3D(sd, false);
373 drw3->SetTitles(" --- PISurfaceDrawer (80x60) --- ");
374 awp->SetAutoDelChilds(true);
375 awp->Show();
376 SetReady();
377 }
378 break;
379
380 case 10205:
381 {
382 SetBusy(); // souris -> montre
383 txt->SetText("PIDraw3DWdg Creation\n 3-D Surf Display \n Button 1 \n (Shift) Button 2 Rotate \n Button Zoom \n <Alt>O <Alt>V \n Try DrawerTools");
384
385 printf(" Creating Matrix 50x50 ... ");
386 float * tf = new float[2500];
387 int i,j;
388 double xp,yp,rp;
389 for(i=0; i<50; i++)
390 for(j=0; j<50; j++) {
391 xp = i-15; yp = j-25;
392 rp = (xp*xp)/16.+(yp*yp)/16.;
393 tf[j*50+i] = 11.*exp(-rp);
394 xp = i-35; yp = j-15;
395 rp = (xp*xp)/9.+(yp*yp)/9.;
396 tf[j*50+i] += 3.*exp(-rp);
397 xp = i-45; yp = j-40;
398 rp = (xp*xp)/10.+(yp*yp)/20.;
399 tf[j*50+i] += 6.*exp(-rp);
400 }
401 printf(" >> OK \n");
402
403 nbwin++; sprintf(strg,"PI W# %d 3D Surf", nbwin);
404 PIWindow* awp = new PIWindow(this, strg, PIWK_normal, 500, 500, 200, 200);
405 PISurfaceDrawer* sd = new PISurfaceDrawer(new P2DAdapter<float>(tf, 50, 50, true), true, true, true);
406 if (fgswcol%3 == 0) sd->SetColMapId(CMAP_COLRJ32);
407 else if (fgswcol%3 == 1) sd->SetColMapId(CMAP_COLBR32);
408 else sd->SetColMapId(CMAP_COLRV32);
409 fgswcol++;
410 PIDraw3DWdg* drw3 = new PIDraw3DWdg(awp, "ex3ddrw", 600, 600, 0, 0);
411 drw3->SetBinding(PIBK_fixed , PIBK_fixed , PIBK_fixed, PIBK_fixed);
412 drw3->AddDrawer3D(sd, false);
413 drw3->SetTitles(" --- PISurfaceDrawer (50x50) --- ");
414 awp->SetAutoDelChilds(true);
415 awp->Show();
416 SetReady();
417 }
418 break;
419
420 default :
421// printf("PITApp::Process() Msg= %d (%d - %d)??? \n",
422// (int)msg, (int)UserMsg(msg),(int)ModMsg(msg));
423 break;
424 }
425 }
426return;
427}
428
429
430// ................................................................
431// programme principal
432// ................................................................
433
434
435
436int main(int narg, char *arg[])
437{
438
439if ( (narg < 2) || (strcmp(arg[1],"-h") == 0) ) {
440 printf("midasitt : MIDAS ITT color table test \n");
441 printf(" Usage : midasitt [Xt options] \n");
442 return(0);
443 }
444
445
446string midas_itt_file = arg[1];
447
448cout << " Reading RGB values from MIDAS_ITT file " << (string)arg[1];
449FILE * fip = fopen(arg[1], "r");
450if (fip == NULL) {
451 cout << "midasitt ERROR opening file " << (string)arg[1] << endl;
452 return(2);
453 }
454
455char lineb[512];
456int nlread = 0;
457int numl = 0;
458while ( (fgets(lineb,512,fip) != NULL) && (nlread < 512) ) {
459 lineb[9] = '\0';
460 numl = atoi(lineb);
461 if (numl != (nlread+1) ) continue;
462 lineb[25] = '\0';
463 rgb_r[nlread] = atof(lineb+14);
464 lineb[41] = '\0';
465 rgb_g[nlread] = atof(lineb+30);
466 lineb[60] = '\0';
467 rgb_b[nlread] = atof(lineb+46);
468 nlread++;
469}
470
471fclose(fip);
472if (nlread != 256) {
473 cout << "midasitt ERROR number of lines != 256 " << nlread << endl;
474 return(3);
475}
476 rgb_ncol = nlread;
477
478int kl;
479cout << "MIDAS_ITT: RGB - Red ( File" << (string)arg[1] << ")" << endl;
480for(kl=0; kl<rgb_ncol; kl++) {
481 cout << rgb_r[kl] << ", " ;
482 if ((kl%8) == 0) cout << endl;
483}
484cout << endl;
485cout << "MIDAS_ITT: RGB - Green ( File" << (string)arg[1] << ")" << endl;
486for(kl=0; kl<rgb_ncol; kl++) {
487 cout << rgb_g[kl] << ", " ;
488 if ((kl%8) == 0) cout << endl;
489}
490cout << endl;
491cout << "MIDAS_ITT: RGB - Blue ( File" << (string)arg[1] << ")" << endl;
492for(kl=0; kl<rgb_ncol; kl++) {
493 cout << rgb_b[kl] << ", " ;
494 if ((kl%8) == 0) cout << endl;
495}
496
497cout << "\n \n" << endl;
498
499
500PITApp* app = new PITApp(narg, arg);
501int sx,sy;
502PIApplicationPrefCompSize(sx, sy);
503printf("##### pit-main() PrefCompSize= %d %d ##### \n", sx, sy);
504PIApplicationScreenSize(sx, sy);
505printf("##### pit-main() ScreenSize= %d %d ##### \n", sx, sy);
506PIColorMap* cmap = new PIColorMap(CMAP_GREY32);
507printf("##### pit-main() NbTotColors=%d Already Allocated= %d ##### \n",
508 cmap->TotNbColors(), cmap->NbAllocColors());
509
510
511app->Run();
512
513delete cmap;
514delete app;
515exit(0);
516}
517
518
Note: See TracBrowser for help on using the repository browser.