source: Sophya/trunk/SophyaPI/PIGcont/pigncont.cc@ 1842

Last change on this file since 1842 was 1842, checked in by ansari, 24 years ago

correction pour compil avec SGI-CC , Reza 21/12/2001

File size: 14.8 KB
Line 
1#include "machdefs.h"
2#include <stdio.h>
3#include <stdlib.h>
4#include <iostream.h>
5#include <math.h>
6
7#include "histos.h"
8#include "ntuple.h"
9
10#include "nbtri.h"
11
12#include "picntools.h"
13#include "pigncont.h"
14
15/* A virer ?? Reza 21/12/2001
16static TBOOLEAN multiplot;
17static double zero =0;
18static TBOOLEAN fg_polar;
19static int xleft, xright, ybot, ytop;
20static float xsize;
21static float ysize;
22static float xoffset, yoffset;
23*/
24
25GNUPlotContour::GNUPlotContour(struct iso_curve * iso){
26 int k=0;
27 iso1 = iso;
28 struct iso_curve *iso_cur = iso ;
29 struct iso_curve *iso_old;
30 _xmin = 1.e37;
31 _ymin = 1.e37;
32 _xmax = -1.e37;
33 _ymax = -1.e37;
34 _myiso = NULL;
35 _zmin = 1.e37;
36 _zmax = -1.e37;
37 while(iso_cur){
38 k++;
39 iso_cur = iso_cur->next;
40 _ny = iso_cur->p_count;
41 for(int k=0 ; k<_ny ; k++){
42 double xx=iso->points[k].x;
43 double yy=iso->points[k].y;
44 double zz=iso->points[k].z;
45 if(xx<_xmin) _xmin = xx;
46 if(xx>_xmax) _xmax = xx;
47 if(yy<_ymin) _ymin = yy;
48 if(yy>_ymax) _ymax = yy;
49 if(zz<_zmin) _zmin = zz;
50 if(zz>_zmax) _zmax = zz;
51
52 }
53 }
54
55 _nx = k;
56 _contours = NULL;
57 My_Levels = NULL;
58
59 _npolys=-1;
60 _Dxp =_Dyp =1.;
61 _Exy =_Invy =_Invy = FALSE ;
62
63}
64
65
66GNUPlotContour::GNUPlotContour(NTupleInterface *nt,int *nz=NULL,double *z=NULL,double *dz=NULL){
67 _xmin = 1.e37;
68 _ymin = 1.e37;
69 _xmax = -1.e37;
70 _ymax = -1.e37;
71 _zmin = 1.e37;
72 _zmax = -1.e37;
73 char *nom[4]={"x","y","z","niso"};
74 _myiso = new NTuple(4,nom);
75 //_myiso->Show();
76 float xnt[4];
77 double mn,mx;
78
79 nt->GetMinMax(0,_xmin,_xmax);
80 nt->GetMinMax(1,_ymin,_ymax);
81 nt->GetMinMax(2,_zmin,_zmax);
82
83
84 struct iso_curve *istmp = NULL ;
85 struct iso_curve *iso = NULL ;
86 struct iso_curve *iso_old = NULL ;
87 double x,y;
88 int nen = nt->NbLines();
89
90 // histo des y
91 for(int k= 0 ; k<1000 ; k++){
92 istmp = iso_alloc(100);
93 iso_free(istmp);
94 }
95
96#define NUMPTMIN 25
97#define MAXISO 100
98#define MINISO 5
99
100 Histo prep(_ymin,_ymax,nen);
101 for(int ix=0 ; ix<nen ; ix++) prep.Add(nt->GetCell(ix,1),1.);
102 Histo Intg = prep;
103 Intg.HInteg(0);
104 //prep.Print();
105 //Intg.Print();
106 float *bin;
107 int *cnt;
108
109 int niso = sqrt( (double)nen);
110 bin = new float[niso+1];
111 cnt = new int[niso+1];
112
113 int i;
114 for(i=0 ; i<niso ; i++){
115 bin[i] = prep.BinHighEdge(prep.BinPercent( ((double)i)/(double)niso));
116 cnt[i] = Intg(prep.BinPercent( ((double)i)/(double)niso));
117 }
118
119 bin[niso]=_ymax;
120
121 cnt[niso] = prep.NEntries();
122 int numx = 0;
123 int numi = 9999;
124 for(i=0;i<niso ; i++){
125 int numy = cnt[i+1]-cnt[i];
126
127 if(numy>0){
128 numx = numx>numy ? numx : numy ;
129 numi = numy>numi ? numi : numy ;
130 }
131 }
132
133
134 if (numi<=0) {
135
136 return;
137 }
138 _nx = 0;
139
140 for(i=0;i<niso ; i++){
141 double ymi = bin[i];
142 double ymx = bin[i+1];
143 int numy = cnt[i+1]-cnt[i];
144
145 if(numy<=0) continue;
146 double *xp;
147 xp = new double[numy];
148
149 int *indx;
150 indx = new int[numy];
151
152 istmp = iso_alloc(numy) ; // structure temporaire
153
154 int ip=0;
155 int ix;
156 for(ix=0 ; ix<nen ; ix++){
157
158 if(nt->GetCell(ix,1)>=ymi&&nt->GetCell(ix,1)<ymx){
159
160
161 istmp->points[ip].type = INRANGE;
162 istmp->points[ip].x = nt->GetCell(ix,0);
163 istmp->points[ip].y = nt->GetCell(ix,1);
164 istmp->points[ip].z = nt->GetCell(ix,2);
165 indx[ip] = ip;
166 xp[ip++] = nt->GetCell(ix,0);
167 }
168 }
169
170 // tri des points de l'iso_curve
171 //
172 istmp->p_count = ip;
173
174 tri_double(xp,indx,ip);
175
176 // remplissage structure finale
177
178 iso = iso_alloc(numx) ;
179 if( _nx == 0 ) iso1 = iso; //premiere structure remplie
180 if (iso_old) iso_old->next = iso;
181 for(ix=0 ; ix<numy ; ix++){
182 int jx = indx[ix];
183
184
185 iso->points[ix].type = INRANGE ;
186 iso->points[ix].x = istmp->points[jx].x ;
187 iso->points[ix].y = istmp->points[jx].y ;
188 iso->points[ix].z = istmp->points[jx].z ;
189 xnt[0] = iso->points[ix].x;
190 xnt[1] = iso->points[ix].y;
191 xnt[2] = iso->points[ix].z;
192 xnt[3] = _nx;
193 //cout << " fill avec "<<xnt[0]<<" "<<xnt[1] <<" "<<xnt[2] << " "<<xnt[3]<<endl;
194 // _myiso->Show();
195
196 _myiso->Fill(xnt);
197 }
198 //cout << " completion "<<ip<<" =>> "<<numx<<endl;
199 // on complete
200 for(ix=ip; ix<numx ; ix++ ){
201 int jmx = indx[ip-1];
202 iso->points[ix].type = INRANGE ;
203 iso->points[ix].x = istmp->points[jmx].x ;
204 iso->points[ix].y = istmp->points[jmx].y ;
205 iso->points[ix].z = istmp->points[jmx].z ;
206 xnt[0] = iso->points[ix].x;
207 xnt[1] = iso->points[ix].y;
208 xnt[2] = iso->points[ix].z;
209 xnt[3] = _nx;
210 //cout << " fill avec "<<xnt[0]<<" "<<xnt[1] <<" "<<xnt[2] << " "<<xnt[3]<<endl;
211 _myiso->Fill(xnt);
212 //_myiso->Show();
213 }
214
215 iso->p_count = numx;
216
217 iso_old = iso;
218 _nx++;
219 //cout << " destruction structure tempo "<<_nx <<endl;
220 if(istmp){
221 iso_free( istmp );// destruction de la structure temporaire
222 istmp = NULL;
223 }
224 if(xp){delete[] xp ; xp=NULL;}
225 if(indx) {delete[] indx ; indx = NULL;}
226
227 }
228 //if(_myiso!=NULL)_myiso->Write("myiso.ppf");
229 //cout << " fin du remplissage des iso_curves xmin,max "<< _xmin<<","<<_xmax<<" ymin,max "<<_ymin<<","<<_ymax<<endl;
230 _contours = NULL;
231 My_Levels = NULL;
232 _npolys=-1;
233 Contour_Levels_kind = LEVELS_AUTO ;
234 Contour_kind = CONTOUR_KIND_LINEAR ;
235 set_contour_kind(Contour_kind);
236 Contour_Levels = 5;
237 set_contour_levels(Contour_Levels);
238 set_contour_levels_kind(Contour_Levels_kind);
239
240
241 if(dz!=NULL){
242 My_Levels = new double[2];
243 Contour_Levels = *nz;
244 My_Levels[0] = *z ;
245 My_Levels[1] = *dz;
246 Contour_Levels_kind = LEVELS_INCREMENTAL ;
247 set_contour_levels(Contour_Levels);
248 set_contour_levels_kind(Contour_Levels_kind);
249 set_contour_levels_list(My_Levels);//,2);
250
251 }else if(nz!=NULL){
252
253 Contour_Levels = *nz;
254 Contour_Levels_kind = LEVELS_NUM ;
255 set_contour_levels(Contour_Levels);
256 set_contour_levels_kind(Contour_Levels_kind);
257 }
258
259}
260
261GNUPlotContour::GNUPlotContour(P2DArrayAdapter*arr,int *nz=NULL,double *z=NULL,double *dz=NULL){
262 _xmin = 1.e37;
263 _ymin = 1.e37;
264 _xmax = -1.e37;
265 _ymax = -1.e37;
266 _zmin = 1.e37;
267 _zmax = -1.e37;
268 // _nx = arr->XSize()-1;
269 // _ny = arr->YSize()-1;
270 _nx = arr->XSize() ;
271 _ny = arr->YSize() ;
272 //cout << " size x,y "<<_nx<<" , "<<_ny <<endl;
273 char *nom[4]={"x","y","z","niso"};
274
275 _myiso = new NTuple(4,nom);
276 float xnt[4];
277 struct iso_curve *iso =NULL ;
278 struct iso_curve *iso_old =NULL ;
279 double x,y;
280 // Calcul de la taille en X et en Y d'un pixel
281 double dxp, dyp;
282 double x1,y1;
283 arr->XYfromxy(0,0,x,y);
284 arr->XYfromxy(1,1,x1,y1);
285 _Dxp = (x1-x);
286 _Dyp = (y1-y);
287 double zz;
288 for(int ix=0 ; ix<_nx ; ix++){
289 iso = iso_alloc(_ny) ;
290 if(ix==0) iso1 = iso;
291 if (iso_old) iso_old->next = iso;
292 for(int iy = 0 ; iy<_ny ; iy++){
293 /*i = ix*100+iy;*/
294 arr->XYfromxy(ix,iy,x,y);
295
296 iso->points[iy].type = INRANGE;
297 iso->points[iy].x = x + _Dxp/2.;
298 iso->points[iy].y = y + _Dyp/2.;
299 zz=arr->Value(ix,iy);
300 iso->points[iy].z = zz;
301 //iso->points[iy].z = ((x-25)*(x-25) + (y-25)*(y-25))*.05 ;
302 if(x <_xmin) _xmin = x;
303 if(x >_xmax) _xmax = x;
304 if(y <_ymin) _ymin = y;
305 if(y >_ymax) _ymax = y;
306 if(zz <_zmin) _zmin = zz;
307 if(zz >_zmax) _zmax = zz;
308 //printf("ix=%d iy=%d x=%f y=%f z=%f \n",ix,iy,iso->points[iy].x,iso->points[iy].y,iso->points[iy].z);
309 xnt[0] = iso->points[iy].x;
310 xnt[1] = iso->points[iy].y;
311 xnt[2] = iso->points[iy].z;
312 xnt[3] = _nx;
313
314 _myiso->Fill(xnt);
315 }
316 iso->p_count = _ny;
317 iso_old = iso;
318 /*printf(" remplissage %lx old %lx old next %lx \n",iso,iso_old,iso->next,iso_old->next);*/
319 /*iso->next = iso ;*/
320 }
321 //cout << " fin du remplissage des iso_curves xmin,max "<< _xmin<<","<<_xmax<<" ymin,max "<<_ymin<<","<<_ymax<<endl;
322 _contours = NULL;
323 My_Levels = NULL;
324 _npolys=-1;
325 Contour_kind = CONTOUR_KIND_LINEAR ;
326 set_contour_kind(Contour_kind);
327 Contour_Levels_kind = LEVELS_AUTO ;
328 Contour_Levels = 5;
329 set_contour_levels(Contour_Levels);
330 set_contour_levels_kind(Contour_Levels_kind);
331
332
333 if(dz!=NULL){
334 My_Levels = new double[2];
335 Contour_Levels = *nz;
336 My_Levels[0] = *z ;
337 My_Levels[1] = *dz;
338 Contour_Levels_kind = LEVELS_INCREMENTAL ;
339 set_contour_levels(Contour_Levels);
340 set_contour_levels_kind(Contour_Levels_kind);
341 set_contour_levels_list(My_Levels);//,2);
342
343 }else if(nz!=NULL){
344 Contour_Levels = *nz;
345 Contour_Levels_kind = LEVELS_NUM ;
346 set_contour_levels(Contour_Levels);
347 set_contour_levels_kind(Contour_Levels_kind);
348 }
349
350}
351
352GNUPlotContour::~GNUPlotContour(){
353 cout << " destructeur de GNUPlotContour "<<endl;
354
355 struct iso_curve *iso_cur;
356 struct iso_curve *iso_nx;
357 iso_cur = iso1;
358
359 while(iso_cur){
360 // cout << " ~GNUPlotContour() : destruction de iso1 "<< iso_cur << endl;
361 iso_nx = iso_cur->next;
362 iso_free(iso_cur);iso_cur = NULL;
363
364 iso_cur = iso_nx;
365
366 }
367
368 iso1 = NULL;
369
370 struct gnuplot_contours *cntcur = _contours;
371 struct gnuplot_contours *cntold;
372
373 while(cntcur) {
374 //cout << " ~GNUPlotContour() : destruction de _contours" << _contours <<endl;
375 cntold = cntcur;
376 cntcur = cntold->next;
377 gp_free(cntold);
378 cntold=NULL;
379 }
380
381 _contours = NULL;
382
383 if(My_Levels) {
384 //cout << " ~GNUPlotContour() : destruction de MyLevels "<<My_Levels <<endl;
385 delete[] My_Levels; My_Levels=NULL;}
386
387 if(_myiso!=NULL){ delete _myiso; _myiso=NULL;}
388
389}
390
391void GNUPlotContour::CalcContour(){
392 cout << " GNUPlotContour::CalcContour(): determination des contours "<<endl;
393
394 set_contour_kind(Contour_kind);
395 if(Contour_Levels_kind == LEVELS_INCREMENTAL){
396
397 set_contour_levels(Contour_Levels);
398 set_contour_levels_kind(Contour_Levels_kind);
399 //free_contour_levels_list();
400 set_contour_levels_list(My_Levels);//,2);
401
402 }else if(Contour_Levels_kind == LEVELS_DISCRETE ){
403 set_contour_levels(Contour_Levels);
404 set_contour_levels_kind(Contour_Levels_kind);
405 //free_contour_levels_list();
406 set_contour_levels_list(My_Levels);//,Contour_Levels);
407
408 }else if(Contour_Levels_kind == LEVELS_NUM ){
409
410 set_contour_levels(Contour_Levels);
411 set_contour_levels_kind(Contour_Levels_kind);
412 }else if(Contour_Levels_kind == LEVELS_AUTO){
413 Contour_Levels = 5;
414 set_contour_levels(Contour_Levels);
415 set_contour_levels_kind(Contour_Levels_kind);
416 }
417
418 if(_contours) {
419 //cout << " GNUPlotContour::CalcContour(): destruction des contours "<<endl;
420 struct gnuplot_contours *cntcur = _contours;
421 struct gnuplot_contours *cntold;
422 while(cntcur) {
423 cntold = cntcur;
424 cntcur = cntold->next;
425 gp_free(cntold);
426 }
427 _contours = NULL;
428
429 }
430
431
432
433 //struct gnuplot_contours *cntcur;
434 //struct gnuplot_contours *cntold;
435
436 _contours = contour (_nx,iso1);
437 //free_contour_levels_list();
438
439
440}
441//_+_ Methode
442void
443GNUPlotContour::SetMyLevels(double *ptr,int k){
444
445 if(My_Levels!=NULL) delete My_Levels;
446 My_Levels = new double[k];
447 for(int i=0 ; i<k ; i++)My_Levels[i] = ptr[i];
448}
449
450// Class PIContourDrawer
451/* --Methode-- */
452PIContourDrawer::PIContourDrawer(P2DArrayAdapter* arr,bool autodel,int *nz,double *z0,double *dz )
453 :GNUPlotContour(arr,nz,z0,dz)
454
455{
456 _arr = arr;
457 _nti = NULL;
458 _nz=5;
459 if(nz!=NULL)_nz = *nz;
460 _autodel = autodel;
461 InitAtts();
462}
463
464PIContourDrawer::PIContourDrawer(NTupleInterface* nti,bool autodel,int *nz,double *z0,double *dz )
465 :GNUPlotContour(nti,nz,z0,dz)
466
467{
468 _arr = NULL;
469 _nti = nti;
470 _nz=5;
471 if(nz!=NULL)_nz = *nz;
472 _autodel = autodel;
473 InitAtts();
474}
475
476
477
478/* --Methode-- */
479PIContourDrawer::~PIContourDrawer()
480{
481 if(_autodel){
482 if(_arr!=NULL){delete _arr; _arr=NULL;}
483 if(_nti!=NULL){delete _nti ; _nti=NULL;}
484 }
485 //if (mColorMap!=NULL){delete mColorMap; mColorMap=NULL;}
486}
487
488/* --Methode-- */
489void PIContourDrawer::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
490{
491 // double xmin, double ymin, double xmax, double ymax LIMITES DE LA ZONE A REFRESHER
492 //PIGrCoord * xx = new PIGrCoord[10];
493 //PIGrCoord * yy = new PIGrCoord[10];
494 PIGrCoord * xx =NULL;
495 PIGrCoord * yy =NULL;
496 PIGrCoord xa;
497 PIGrCoord ya;
498 char buff[64];
499 // On met les bons attributs graphiques
500 //SelGraAtt(g);
501 g->SaveGraphicAtt();
502 struct gnuplot_contours *cntcur;
503 struct gnuplot_contours *cntold;
504 cntcur = _contours;
505
506 double a,b;
507 int tot=0;
508 bool Invx, Invy, Exy;
509 PIColorMap * cmap = NULL;
510 if(mCmapid !=CMAP_OTHER ){
511 cmap = new PIColorMap(mCmapid);
512 }
513 int numdr = 0;
514 while(cntcur){
515 int npts = cntcur->num_pts ;
516 if(npts<0) continue;
517
518 xx = new PIGrCoord[npts];
519 yy = new PIGrCoord[npts];
520 double lev = (cntcur->coords)[0].z ;
521 for(int l=0 ; l< npts ; l++){
522 a = (cntcur->coords)[l].x;
523 b = (cntcur->coords)[l].y;
524
525 xx[l] = a ;
526 yy[l] = b ;
527
528 }
529
530 // choix de la couleur
531
532 g->SelForeground(mFCol);
533 if(mCmapid !=CMAP_OTHER ){
534 if(_zmax-_zmin!=0){
535 int kc = ((lev - _zmin)/(_zmax-_zmin))*cmap->NCol();
536
537 g->SelForeground(*cmap,kc);
538 }
539 }
540 // traitement des des markers
541 if(IsMarkOn()==true){
542
543 g->SelMarker(mMSz,mMrk);
544 g->DrawMarkers(xx,yy,npts);
545 }
546 // traitement des lignes
547 if(mLineOn==true){
548
549 g->SelLine(mLAtt);
550 g->DrawPolygon(xx,yy,npts,false);
551 }
552 // traitement des labels
553 // SIMPLISTE POUR L'INSTANT : UN AFFICHAGE
554 if(mLabelOn==true){
555 //
556
557 char strg[10];
558 sprintf(strg,"%g",lev);
559 PIFont myfont(mFName);
560 myfont.SetFontAtt(mFAtt);
561 myfont.SetFontSz(mFSz);
562
563 g->SelFont(myfont);
564 double px,py;
565 px = (cntcur->coords)[0].x+2*(Xmax()-Xmin())/100.;
566 py = (cntcur->coords)[0].y;
567 g->DrawString(px,py,strg, PI_HorizontalCenter&&PI_VerticalCenter );
568
569 }
570 numdr++;
571 delete[] xx;
572 xx=NULL;
573 delete[] yy;
574 yy=NULL;
575 cntcur = cntcur->next;
576 tot++;
577 }
578
579 //cout << "PIContourDrawer::Draw fin de trace des "<<tot<< " polygones "<<endl;
580
581 //
582 if(cmap !=NULL)delete cmap;
583
584 g->RestoreGraphicAtt();
585}
586
587/* --Methode-- */
588void PIContourDrawer::UpdateLimits()
589{
590 // Doit calculer les limites
591
592 double xmn = _xmin;
593 double xmx = _xmax;
594 double ymn = _ymin;
595 double ymx = _ymax;
596
597 SetLimits(xmn, xmx, ymn, ymx);
598}
599
600
601/* --Methode-- */
602void PIContourDrawer::ShowControlWindow(PIBaseWdgGen* wdg)
603{
604 PICnTools::SetCurrentBaseWdg(wdg);
605 PICnTools::SetCurrentCnDrw(this);
606 PICnTools::ShowPICnTools();
607}
608
609
610/* --Methode-- */
611bool PIContourDrawer::IsLabelOn(){
612 return (mLabelOn);
613}
614
615bool PIContourDrawer::IsLineOn(){
616 return (mLineOn);
617}
618
619bool PIContourDrawer::IsMarkOn(){
620 return (mMarkOn);
621}
622
623void PIContourDrawer::SetLabelOn(bool state){
624 mLabelOn = state;
625}
626
627void PIContourDrawer::SetMarkOn(bool state){
628 mMarkOn = state;
629}
630
631void PIContourDrawer::SetLineOn(bool state){
632 mLineOn = state;
633}
634
635void PIContourDrawer::InitAtts(){
636 mLineOn = false;
637 mMarkOn = true;
638 mLabelOn = false;
639}
640
641
642
Note: See TracBrowser for help on using the repository browser.