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

Last change on this file since 2750 was 2750, checked in by cmv, 20 years ago

iostream.h -> iostream cmv 20/05/05

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