1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 | // Classe d'interface avec le code de GNUplot
|
---|
3 | // pour calculer les contours & classe de trace de contours
|
---|
4 | // O. Perdereau
|
---|
5 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
6 |
|
---|
7 | #include "machdefs.h"
|
---|
8 | #include <stdio.h>
|
---|
9 | #include <stdlib.h>
|
---|
10 | #include <assert.h>
|
---|
11 | #include <iostream>
|
---|
12 | #include <math.h>
|
---|
13 |
|
---|
14 | #include "histos.h"
|
---|
15 | #include "ntuple.h"
|
---|
16 |
|
---|
17 | #include "nbtri.h"
|
---|
18 |
|
---|
19 | #include "picntools.h"
|
---|
20 | #include "pigncont.h"
|
---|
21 |
|
---|
22 | #include <sys/time.h>
|
---|
23 | #include <sys/resource.h>
|
---|
24 |
|
---|
25 | //++
|
---|
26 | // Class GNUPlotContour
|
---|
27 | // Lib PIGcont
|
---|
28 | // include pigncont.h
|
---|
29 | //
|
---|
30 | // Classe d'interface avec le code de GNUplot qui calcule les courbes de niveaux
|
---|
31 | // GNUplot part d'une grille (structure iso_curve) qui est remplie par les
|
---|
32 | // createurs
|
---|
33 | // Les parametres du calcul sont modifiable a partir de la fenetre d'options
|
---|
34 | // du traceur de contour (classe PIContourDrawer)
|
---|
35 | // Options (reconnues dans un enum t_contour_kind dans GNUplot)
|
---|
36 | //
|
---|
37 | // 1) nombre de courbes et et niveaux determines automatiquement par le programme (defaut)
|
---|
38 | // En general, 5 courbes sont tracees LEVELS_AUTO
|
---|
39 | //
|
---|
40 | // 2) nombre de niveaux fixe par l'utilisateur. Les niveaux sont equidistants entre
|
---|
41 | // le min et le max de la surface LEVELS_NUM
|
---|
42 | //
|
---|
43 | // 3) nombre et hauteurs des niveaux fixes par l'utilisateur. Les niveaux sont passes
|
---|
44 | // dans un tableau LEVELS_DISCRETE
|
---|
45 | //
|
---|
46 | // 4) nombre niveau min et ecart entre niveaux fixe par l'utilisateur LEVELS_INCREMENTAL
|
---|
47 | //
|
---|
48 | // Les contours sont traces en interpolant entre les points de la grille.
|
---|
49 | // On peut choisir 3 algorithmes d'interpolation a travers p.ex. les options
|
---|
50 | // de PIContourDrawer
|
---|
51 | // (enum t_contour_levels_kind ds GNUplot)
|
---|
52 | //
|
---|
53 | // a) interpolation simple CONTOUR_KIND_LINEAR
|
---|
54 | //
|
---|
55 | // b) spline cubique CONTOUR_KIND_CUBIC_SPL
|
---|
56 | //
|
---|
57 | // c) B-spline CONTOUR_KIND_BSPLINE
|
---|
58 | //
|
---|
59 | //--
|
---|
60 | //++
|
---|
61 | // Links Voir aussi
|
---|
62 | // PIContourDrawer
|
---|
63 | // PICnTools
|
---|
64 | //--
|
---|
65 | //++
|
---|
66 | // Titre Constructeurs et Méthodes
|
---|
67 | //--
|
---|
68 | //++
|
---|
69 | // GNUPlotContour(struct iso_curve * iso) :
|
---|
70 | // constructeur a partir d'une structure iso_curve
|
---|
71 | // (structure de GNUplot)
|
---|
72 | //--
|
---|
73 |
|
---|
74 |
|
---|
75 | GNUPlotContour::GNUPlotContour(struct iso_curve * iso){
|
---|
76 | int k=0;
|
---|
77 | iso1 = iso;
|
---|
78 | struct iso_curve *iso_cur = iso ;
|
---|
79 | struct iso_curve *iso_old;
|
---|
80 | _xmin = 1.e37;
|
---|
81 | _ymin = 1.e37;
|
---|
82 | _xmax = -1.e37;
|
---|
83 | _ymax = -1.e37;
|
---|
84 | _myiso = NULL;
|
---|
85 | _zmin = 1.e37;
|
---|
86 | _zmax = -1.e37;
|
---|
87 | while(iso_cur){
|
---|
88 | k++;
|
---|
89 | iso_cur = iso_cur->next;
|
---|
90 | _ny = iso_cur->p_count;
|
---|
91 | for(int k=0 ; k<_ny ; k++){
|
---|
92 | double xx=iso->points[k].x;
|
---|
93 | double yy=iso->points[k].y;
|
---|
94 | double zz=iso->points[k].z;
|
---|
95 | if(xx<_xmin) _xmin = xx;
|
---|
96 | if(xx>_xmax) _xmax = xx;
|
---|
97 | if(yy<_ymin) _ymin = yy;
|
---|
98 | if(yy>_ymax) _ymax = yy;
|
---|
99 | if(zz<_zmin) _zmin = zz;
|
---|
100 | if(zz>_zmax) _zmax = zz;
|
---|
101 |
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | _nx = k;
|
---|
106 | _contours = NULL;
|
---|
107 | My_Levels = NULL;
|
---|
108 |
|
---|
109 | _npolys=-1;
|
---|
110 | _Dxp =_Dyp =1.;
|
---|
111 | _Exy =_Invy =_Invy = FALSE ;
|
---|
112 |
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | //++
|
---|
117 | // GNUPlotContour(NTupleInterface *nt,int *nz=NULL,double *z=NULL,double *dz=NULL):
|
---|
118 | // constructeur a partir d'un NTupleInterface
|
---|
119 | // la structure iso_curve est remplie par le constructeur
|
---|
120 | //Inputs
|
---|
121 | //| NTupleInterface *nt
|
---|
122 | //| double *nz nombre de contours (optionnel)
|
---|
123 | //| double *z tabelau avec les niveaux des contours (optionnel)
|
---|
124 | //| double *dz increment entre contours (optionnel)
|
---|
125 | //--
|
---|
126 | GNUPlotContour::GNUPlotContour(NTupleInterface *nt,int *nz=NULL,double *z=NULL,double *dz=NULL){
|
---|
127 | _xmin = 1.e37;
|
---|
128 | _ymin = 1.e37;
|
---|
129 | _xmax = -1.e37;
|
---|
130 | _ymax = -1.e37;
|
---|
131 | _zmin = 1.e37;
|
---|
132 | _zmax = -1.e37;
|
---|
133 | char *nom[4]={"x","y","z","niso"};
|
---|
134 | _myiso = new NTuple(4,nom);
|
---|
135 | //_myiso->Show();
|
---|
136 | float xnt[4];
|
---|
137 | double mn,mx;
|
---|
138 |
|
---|
139 | nt->GetMinMax(0,_xmin,_xmax);
|
---|
140 | nt->GetMinMax(1,_ymin,_ymax);
|
---|
141 | nt->GetMinMax(2,_zmin,_zmax);
|
---|
142 |
|
---|
143 |
|
---|
144 | struct iso_curve *istmp = NULL ;
|
---|
145 | struct iso_curve *iso = NULL ;
|
---|
146 | struct iso_curve *iso_old = NULL ;
|
---|
147 | double x,y;
|
---|
148 | int nen = nt->NbLines();
|
---|
149 |
|
---|
150 | // histo des y
|
---|
151 | for(int k= 0 ; k<1000 ; k++){
|
---|
152 | istmp = iso_alloc(100);
|
---|
153 | iso_free(istmp);
|
---|
154 | }
|
---|
155 |
|
---|
156 | #define NUMPTMIN 25
|
---|
157 | #define MAXISO 100
|
---|
158 | #define MINISO 5
|
---|
159 |
|
---|
160 | Histo prep(_ymin,_ymax,nen);
|
---|
161 | for(int ix=0 ; ix<nen ; ix++) prep.Add(nt->GetCell(ix,1),1.);
|
---|
162 | Histo Intg = prep;
|
---|
163 | Intg.HInteg(0);
|
---|
164 | //prep.Print();
|
---|
165 | //Intg.Print();
|
---|
166 | float *bin;
|
---|
167 | int *cnt;
|
---|
168 |
|
---|
169 | int niso = sqrt( (double)nen);
|
---|
170 | bin = new float[niso+1];
|
---|
171 | cnt = new int[niso+1];
|
---|
172 |
|
---|
173 | int i;
|
---|
174 | for(i=0 ; i<niso ; i++){
|
---|
175 | bin[i] = prep.BinHighEdge(prep.BinPercent( ((double)i)/(double)niso));
|
---|
176 | cnt[i] = Intg(prep.BinPercent( ((double)i)/(double)niso));
|
---|
177 | }
|
---|
178 |
|
---|
179 | bin[niso]=_ymax;
|
---|
180 |
|
---|
181 | cnt[niso] = prep.NEntries();
|
---|
182 | int numx = 0;
|
---|
183 | int numi = 9999;
|
---|
184 | for(i=0;i<niso ; i++){
|
---|
185 | int numy = cnt[i+1]-cnt[i];
|
---|
186 |
|
---|
187 | if(numy>0){
|
---|
188 | numx = numx>numy ? numx : numy ;
|
---|
189 | numi = numy>numi ? numi : numy ;
|
---|
190 | }
|
---|
191 | }
|
---|
192 |
|
---|
193 |
|
---|
194 | if (numi<=0) {
|
---|
195 |
|
---|
196 | return;
|
---|
197 | }
|
---|
198 | _nx = 0;
|
---|
199 |
|
---|
200 | for(i=0;i<niso ; i++){
|
---|
201 | double ymi = bin[i];
|
---|
202 | double ymx = bin[i+1];
|
---|
203 | int numy = cnt[i+1]-cnt[i];
|
---|
204 |
|
---|
205 | if(numy<=0) continue;
|
---|
206 | double *xp;
|
---|
207 | xp = new double[numy];
|
---|
208 |
|
---|
209 | int *indx;
|
---|
210 | indx = new int[numy];
|
---|
211 |
|
---|
212 | istmp = iso_alloc(numy) ; // structure temporaire
|
---|
213 |
|
---|
214 | int ip=0;
|
---|
215 | int ix;
|
---|
216 | for(ix=0 ; ix<nen ; ix++){
|
---|
217 |
|
---|
218 | if(nt->GetCell(ix,1)>=ymi&&nt->GetCell(ix,1)<ymx){
|
---|
219 |
|
---|
220 |
|
---|
221 | istmp->points[ip].type = INRANGE;
|
---|
222 | istmp->points[ip].x = nt->GetCell(ix,0);
|
---|
223 | istmp->points[ip].y = nt->GetCell(ix,1);
|
---|
224 | istmp->points[ip].z = nt->GetCell(ix,2);
|
---|
225 | indx[ip] = ip;
|
---|
226 | xp[ip++] = nt->GetCell(ix,0);
|
---|
227 | }
|
---|
228 | }
|
---|
229 |
|
---|
230 | // tri des points de l'iso_curve
|
---|
231 | //
|
---|
232 | istmp->p_count = ip;
|
---|
233 |
|
---|
234 | tri_double(xp,indx,ip);
|
---|
235 |
|
---|
236 | // remplissage structure finale
|
---|
237 |
|
---|
238 | iso = iso_alloc(numx) ;
|
---|
239 | if( _nx == 0 ) iso1 = iso; //premiere structure remplie
|
---|
240 | if (iso_old) iso_old->next = iso;
|
---|
241 | for(ix=0 ; ix<numy ; ix++){
|
---|
242 | int jx = indx[ix];
|
---|
243 |
|
---|
244 |
|
---|
245 | iso->points[ix].type = INRANGE ;
|
---|
246 | iso->points[ix].x = istmp->points[jx].x ;
|
---|
247 | iso->points[ix].y = istmp->points[jx].y ;
|
---|
248 | iso->points[ix].z = istmp->points[jx].z ;
|
---|
249 | xnt[0] = iso->points[ix].x;
|
---|
250 | xnt[1] = iso->points[ix].y;
|
---|
251 | xnt[2] = iso->points[ix].z;
|
---|
252 | xnt[3] = _nx;
|
---|
253 | //cout << " fill avec "<<xnt[0]<<" "<<xnt[1] <<" "<<xnt[2] << " "<<xnt[3]<<endl;
|
---|
254 | // _myiso->Show();
|
---|
255 |
|
---|
256 | _myiso->Fill(xnt);
|
---|
257 | }
|
---|
258 | //cout << " completion "<<ip<<" =>> "<<numx<<endl;
|
---|
259 | // on complete
|
---|
260 | for(ix=ip; ix<numx ; ix++ ){
|
---|
261 | int jmx = indx[ip-1];
|
---|
262 | iso->points[ix].type = INRANGE ;
|
---|
263 | iso->points[ix].x = istmp->points[jmx].x ;
|
---|
264 | iso->points[ix].y = istmp->points[jmx].y ;
|
---|
265 | iso->points[ix].z = istmp->points[jmx].z ;
|
---|
266 | xnt[0] = iso->points[ix].x;
|
---|
267 | xnt[1] = iso->points[ix].y;
|
---|
268 | xnt[2] = iso->points[ix].z;
|
---|
269 | xnt[3] = _nx;
|
---|
270 | //cout << " fill avec "<<xnt[0]<<" "<<xnt[1] <<" "<<xnt[2] << " "<<xnt[3]<<endl;
|
---|
271 | _myiso->Fill(xnt);
|
---|
272 | //_myiso->Show();
|
---|
273 | }
|
---|
274 |
|
---|
275 | iso->p_count = numx;
|
---|
276 |
|
---|
277 | iso_old = iso;
|
---|
278 | _nx++;
|
---|
279 | //cout << " destruction structure tempo "<<_nx <<endl;
|
---|
280 | if(istmp){
|
---|
281 | iso_free( istmp );// destruction de la structure temporaire
|
---|
282 | istmp = NULL;
|
---|
283 | }
|
---|
284 | if(xp){delete[] xp ; xp=NULL;}
|
---|
285 | if(indx) {delete[] indx ; indx = NULL;}
|
---|
286 |
|
---|
287 | }
|
---|
288 | //if(_myiso!=NULL)_myiso->Write("myiso.ppf");
|
---|
289 | //cout << " fin du remplissage des iso_curves xmin,max "<< _xmin<<","<<_xmax<<" ymin,max "<<_ymin<<","<<_ymax<<endl;
|
---|
290 | _contours = NULL;
|
---|
291 | My_Levels = NULL;
|
---|
292 | _npolys=-1;
|
---|
293 | Contour_Levels_kind = LEVELS_AUTO ;
|
---|
294 | Contour_kind = CONTOUR_KIND_LINEAR ;
|
---|
295 | set_contour_kind(Contour_kind);
|
---|
296 | Contour_Levels = 5;
|
---|
297 | set_contour_levels(Contour_Levels);
|
---|
298 | set_contour_levels_kind(Contour_Levels_kind);
|
---|
299 |
|
---|
300 |
|
---|
301 | if(dz!=NULL){
|
---|
302 | My_Levels = new double[2];
|
---|
303 | Contour_Levels = *nz;
|
---|
304 | My_Levels[0] = *z ;
|
---|
305 | My_Levels[1] = *dz;
|
---|
306 | Contour_Levels_kind = LEVELS_INCREMENTAL ;
|
---|
307 | set_contour_levels(Contour_Levels);
|
---|
308 | set_contour_levels_kind(Contour_Levels_kind);
|
---|
309 | set_contour_levels_list(My_Levels);//,2);
|
---|
310 |
|
---|
311 | }else if(nz!=NULL){
|
---|
312 |
|
---|
313 | Contour_Levels = *nz;
|
---|
314 | Contour_Levels_kind = LEVELS_NUM ;
|
---|
315 | set_contour_levels(Contour_Levels);
|
---|
316 | set_contour_levels_kind(Contour_Levels_kind);
|
---|
317 | }
|
---|
318 |
|
---|
319 | }
|
---|
320 |
|
---|
321 | //++
|
---|
322 | // GNUPlotContour(P2DArrayAdapter*arr,int *nz=NULL,double *z=NULL,double *dz=NULL):
|
---|
323 | // constructeur a partir d'un P2DArrayAdapter
|
---|
324 | // la structure iso_curve est remplie par le constructeur
|
---|
325 | //Inputs
|
---|
326 | //| P2DArrayAdapter* arr
|
---|
327 | //| double *nz nombre de contours (optionnel)
|
---|
328 | //| double *z tabelau avec les niveaux des contours (optionnel)
|
---|
329 | //| double *dz increment entre contours (optionnel)
|
---|
330 | //--
|
---|
331 |
|
---|
332 | GNUPlotContour::GNUPlotContour(P2DArrayAdapter* arr,int *nz=NULL,double *z=NULL,double *dz=NULL){
|
---|
333 | _xmin = 1.e37;
|
---|
334 | _ymin = 1.e37;
|
---|
335 | _xmax = -1.e37;
|
---|
336 | _ymax = -1.e37;
|
---|
337 | _zmin = 1.e37;
|
---|
338 | _zmax = -1.e37;
|
---|
339 | // _nx = arr->XSize()-1;
|
---|
340 | // _ny = arr->YSize()-1;
|
---|
341 | _nx = arr->XSize() ;
|
---|
342 | _ny = arr->YSize() ;
|
---|
343 | //cout << " size x,y "<<_nx<<" , "<<_ny <<endl;
|
---|
344 | char *nom[4]={"x","y","z","niso"};
|
---|
345 |
|
---|
346 | _myiso = new NTuple(4,nom);
|
---|
347 | float xnt[4];
|
---|
348 | struct iso_curve *iso =NULL ;
|
---|
349 | struct iso_curve *iso_old =NULL ;
|
---|
350 | double x,y;
|
---|
351 | // Calcul de la taille en X et en Y d'un pixel
|
---|
352 | double dxp, dyp;
|
---|
353 | double x1,y1;
|
---|
354 | arr->XYfromxy(0,0,x,y);
|
---|
355 | arr->XYfromxy(1,1,x1,y1);
|
---|
356 | _Dxp = (x1-x);
|
---|
357 | _Dyp = (y1-y);
|
---|
358 | double zz;
|
---|
359 | for(int ix=0 ; ix<_nx ; ix++){
|
---|
360 | iso = iso_alloc(_ny) ;
|
---|
361 | if(ix==0) iso1 = iso;
|
---|
362 | if (iso_old) iso_old->next = iso;
|
---|
363 | for(int iy = 0 ; iy<_ny ; iy++){
|
---|
364 | /*i = ix*100+iy;*/
|
---|
365 | arr->XYfromxy(ix,iy,x,y);
|
---|
366 |
|
---|
367 | iso->points[iy].type = INRANGE;
|
---|
368 | iso->points[iy].x = x + _Dxp/2.;
|
---|
369 | iso->points[iy].y = y + _Dyp/2.;
|
---|
370 | zz=arr->Value(ix,iy);
|
---|
371 | iso->points[iy].z = zz;
|
---|
372 | //iso->points[iy].z = ((x-25)*(x-25) + (y-25)*(y-25))*.05 ;
|
---|
373 | if(x <_xmin) _xmin = x;
|
---|
374 | if(x >_xmax) _xmax = x;
|
---|
375 | if(y <_ymin) _ymin = y;
|
---|
376 | if(y >_ymax) _ymax = y;
|
---|
377 | if(zz <_zmin) _zmin = zz;
|
---|
378 | if(zz >_zmax) _zmax = zz;
|
---|
379 | //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);
|
---|
380 | xnt[0] = iso->points[iy].x;
|
---|
381 | xnt[1] = iso->points[iy].y;
|
---|
382 | xnt[2] = iso->points[iy].z;
|
---|
383 | xnt[3] = _nx;
|
---|
384 |
|
---|
385 | _myiso->Fill(xnt);
|
---|
386 | }
|
---|
387 | iso->p_count = _ny;
|
---|
388 | iso_old = iso;
|
---|
389 | /*printf(" remplissage %lx old %lx old next %lx \n",iso,iso_old,iso->next,iso_old->next);*/
|
---|
390 | /*iso->next = iso ;*/
|
---|
391 | }
|
---|
392 | //cout << " fin du remplissage des iso_curves xmin,max "<< _xmin<<","<<_xmax<<" ymin,max "<<_ymin<<","<<_ymax<<endl;
|
---|
393 | _contours = NULL;
|
---|
394 | My_Levels = NULL;
|
---|
395 | _npolys=-1;
|
---|
396 | Contour_kind = CONTOUR_KIND_LINEAR ;
|
---|
397 | set_contour_kind(Contour_kind);
|
---|
398 | Contour_Levels_kind = LEVELS_AUTO ;
|
---|
399 | Contour_Levels = 5;
|
---|
400 | set_contour_levels(Contour_Levels);
|
---|
401 | set_contour_levels_kind(Contour_Levels_kind);
|
---|
402 |
|
---|
403 |
|
---|
404 | if(dz!=NULL){
|
---|
405 | My_Levels = new double[2];
|
---|
406 | Contour_Levels = *nz;
|
---|
407 | My_Levels[0] = *z ;
|
---|
408 | My_Levels[1] = *dz;
|
---|
409 | Contour_Levels_kind = LEVELS_INCREMENTAL ;
|
---|
410 | set_contour_levels(Contour_Levels);
|
---|
411 | set_contour_levels_kind(Contour_Levels_kind);
|
---|
412 | set_contour_levels_list(My_Levels);//,2);
|
---|
413 |
|
---|
414 | }else if(nz!=NULL){
|
---|
415 | Contour_Levels = *nz;
|
---|
416 | Contour_Levels_kind = LEVELS_NUM ;
|
---|
417 | set_contour_levels(Contour_Levels);
|
---|
418 | set_contour_levels_kind(Contour_Levels_kind);
|
---|
419 | }
|
---|
420 |
|
---|
421 | }
|
---|
422 |
|
---|
423 |
|
---|
424 | //++
|
---|
425 | // ~GNUPlotContour()
|
---|
426 | //
|
---|
427 | // Destructeur
|
---|
428 | //
|
---|
429 | //--
|
---|
430 | GNUPlotContour::~GNUPlotContour(){
|
---|
431 | cout << " destructeur de GNUPlotContour "<<endl;
|
---|
432 |
|
---|
433 | struct iso_curve *iso_cur;
|
---|
434 | struct iso_curve *iso_nx;
|
---|
435 | iso_cur = iso1;
|
---|
436 |
|
---|
437 | while(iso_cur){
|
---|
438 | // cout << " ~GNUPlotContour() : destruction de iso1 "<< iso_cur << endl;
|
---|
439 | iso_nx = iso_cur->next;
|
---|
440 | iso_free(iso_cur);iso_cur = NULL;
|
---|
441 |
|
---|
442 | iso_cur = iso_nx;
|
---|
443 |
|
---|
444 | }
|
---|
445 |
|
---|
446 | iso1 = NULL;
|
---|
447 |
|
---|
448 | struct gnuplot_contours *cntcur = _contours;
|
---|
449 | /*****
|
---|
450 | struct gnuplot_contours *cntold;
|
---|
451 |
|
---|
452 | while(cntcur) {
|
---|
453 | //cout << " ~GNUPlotContour() : destruction de _contours" << _contours <<endl;
|
---|
454 | cntold = cntcur;
|
---|
455 | cntcur = cntold->next;
|
---|
456 | gp_free(cntold);
|
---|
457 | cntold=NULL;
|
---|
458 | }
|
---|
459 | *******/
|
---|
460 | contour_free(cntcur);
|
---|
461 | _contours = NULL;
|
---|
462 |
|
---|
463 | if(My_Levels) {
|
---|
464 | //cout << " ~GNUPlotContour() : destruction de MyLevels "<<My_Levels <<endl;
|
---|
465 | delete[] My_Levels; My_Levels=NULL;}
|
---|
466 |
|
---|
467 | if(_myiso!=NULL){ delete _myiso; _myiso=NULL;}
|
---|
468 |
|
---|
469 | }
|
---|
470 |
|
---|
471 |
|
---|
472 | //++
|
---|
473 | // void CalcContour()
|
---|
474 | // Methode de calcul des courbes de niveaux
|
---|
475 | // par appel a la routine de GNUplot
|
---|
476 | //
|
---|
477 | //--
|
---|
478 | void GNUPlotContour::CalcContour(){
|
---|
479 | //cout << " GNUPlotContour::CalcContour(): determination des contours "<<endl;
|
---|
480 |
|
---|
481 | struct rusage r_usage;
|
---|
482 | int rcus;
|
---|
483 |
|
---|
484 | set_contour_kind(Contour_kind);
|
---|
485 | if(Contour_Levels_kind == LEVELS_INCREMENTAL){
|
---|
486 |
|
---|
487 | set_contour_levels(Contour_Levels);
|
---|
488 | set_contour_levels_kind(Contour_Levels_kind);
|
---|
489 | //free_contour_levels_list();
|
---|
490 | set_contour_levels_list(My_Levels);//,2);
|
---|
491 |
|
---|
492 | }else if(Contour_Levels_kind == LEVELS_DISCRETE ){
|
---|
493 | set_contour_levels(Contour_Levels);
|
---|
494 | set_contour_levels_kind(Contour_Levels_kind);
|
---|
495 | //free_contour_levels_list();
|
---|
496 | set_contour_levels_list(My_Levels);//,Contour_Levels);
|
---|
497 |
|
---|
498 | }else if(Contour_Levels_kind == LEVELS_NUM ){
|
---|
499 |
|
---|
500 | set_contour_levels(Contour_Levels);
|
---|
501 | set_contour_levels_kind(Contour_Levels_kind);
|
---|
502 | }else if(Contour_Levels_kind == LEVELS_AUTO){
|
---|
503 | Contour_Levels = 5;
|
---|
504 | set_contour_levels(Contour_Levels);
|
---|
505 | set_contour_levels_kind(Contour_Levels_kind);
|
---|
506 | }
|
---|
507 |
|
---|
508 |
|
---|
509 | //rcus = getrusage( RUSAGE_SELF , &r_usage);
|
---|
510 |
|
---|
511 | //if(rcus==0)
|
---|
512 | // cout << " rusage -> "<< r_usage.ru_maxrss <<" , "<< r_usage.ru_ixrss <<" , "<< r_usage.ru_ixrss <<endl;
|
---|
513 | //else
|
---|
514 | // perror("1er appel");
|
---|
515 |
|
---|
516 | if(_contours) {
|
---|
517 | cout << " GNUPlotContour::CalcContour(): destruction des contours "<<_contours<<endl;
|
---|
518 | struct gnuplot_contours *cntcur = _contours;
|
---|
519 | /******
|
---|
520 | struct gnuplot_contours *cntold;
|
---|
521 | while(cntcur) {
|
---|
522 | cout << " GNUPlotContour::CalcContour(): destruction des contours "<< cntcur<<endl;
|
---|
523 | cntold = cntcur;
|
---|
524 | cntcur = cntold->next;
|
---|
525 | gp_free(cntold);
|
---|
526 | cntold = NULL;
|
---|
527 | }
|
---|
528 | ******/
|
---|
529 | contour_free(cntcur);
|
---|
530 | _contours = NULL;
|
---|
531 |
|
---|
532 | }
|
---|
533 |
|
---|
534 | //struct gnuplot_contours *cntcur;
|
---|
535 | //struct gnuplot_contours *cntold;
|
---|
536 |
|
---|
537 |
|
---|
538 | //rcus = getrusage( RUSAGE_SELF , &r_usage);
|
---|
539 | //if(rcus==0)
|
---|
540 | // cout << " rusage -> "<< r_usage.ru_maxrss <<" , "<< r_usage.ru_ixrss <<" , "<< r_usage.ru_ixrss <<endl;
|
---|
541 | //else
|
---|
542 | // perror("2d appel");
|
---|
543 |
|
---|
544 |
|
---|
545 | _contours = contour (_nx,iso1);
|
---|
546 |
|
---|
547 |
|
---|
548 | //rcus = getrusage( RUSAGE_SELF , &r_usage);
|
---|
549 | //if(rcus==0)
|
---|
550 | // cout << " rusage -> "<< r_usage.ru_maxrss <<" , "<< r_usage.ru_ixrss <<" , "<< r_usage.ru_ixrss <<endl;
|
---|
551 | //else
|
---|
552 | // perror("3ieme appel");
|
---|
553 |
|
---|
554 | //free_contour_levels_list();
|
---|
555 |
|
---|
556 |
|
---|
557 | }
|
---|
558 | //++
|
---|
559 | // void SetMyLevels(double *ptr,int k)
|
---|
560 | // Setting du tableau des niveaux des contours
|
---|
561 | //Inputs
|
---|
562 | //| int k : nombre de niveaux
|
---|
563 | //| double *ptr : adresse du tableau des niveaux
|
---|
564 | //--
|
---|
565 | void
|
---|
566 | GNUPlotContour::SetMyLevels(double *ptr,int k){
|
---|
567 |
|
---|
568 | if(My_Levels!=NULL) delete My_Levels;
|
---|
569 | My_Levels = new double[k];
|
---|
570 | for(int i=0 ; i<k ; i++)My_Levels[i] = ptr[i];
|
---|
571 | }
|
---|
572 | //++
|
---|
573 | // void SetMyLevels(vector<double>vec)
|
---|
574 | // Setting du tableau des niveaux des contours
|
---|
575 | //Inputs
|
---|
576 | //|
|
---|
577 | //| vector <double> vec : vecteur des niveaux
|
---|
578 | //--
|
---|
579 | void
|
---|
580 | GNUPlotContour::SetMyLevels(vector <double> vec){
|
---|
581 |
|
---|
582 | if(My_Levels!=NULL) delete My_Levels;
|
---|
583 | int sz = vec.size();
|
---|
584 | assert (sz>0);
|
---|
585 |
|
---|
586 | My_Levels = new double[sz];
|
---|
587 | for(int i=0 ; i<sz ; i++)
|
---|
588 | My_Levels[i] = vec[i];
|
---|
589 | }
|
---|
590 |
|
---|
591 | //++
|
---|
592 | // Class PIContourDrawer
|
---|
593 | // Lib PIGcont
|
---|
594 | // include pigncont.h
|
---|
595 | //
|
---|
596 | // Classe de traceur de contour qui herite de PIDrawer et de GNUPlotContour
|
---|
597 | // elle gere les options graphiques generales (couleurs, lignes, fontes,...)
|
---|
598 | // les contours peuvent etre traces avec des lignes ou des markers
|
---|
599 | // on peut afficher les valeurs des niveaux des contours
|
---|
600 | // on peut demander a utiliser une table de couleur
|
---|
601 | // tout ca a travers la fenetre de controle associee (PICnTools)
|
---|
602 | //
|
---|
603 | //--
|
---|
604 | //++
|
---|
605 | // Links Parents
|
---|
606 | // PIDrawer
|
---|
607 | // GNUPlotContour
|
---|
608 | //--
|
---|
609 | //++
|
---|
610 | // Links Voir aussi
|
---|
611 | // PICnTools
|
---|
612 | //--
|
---|
613 | //++
|
---|
614 | // Titre Constructeurs et Méthodes
|
---|
615 | //--
|
---|
616 | //++
|
---|
617 | // PIContourDrawer(P2DArrayAdapter* arr,bool autodel,int *nz,double *z0,double *dz )
|
---|
618 | // Constructeur a partir d'un P2DArrayAdapter* - voir le createur de GNUPlotContour
|
---|
619 | //
|
---|
620 | //--
|
---|
621 |
|
---|
622 | PIContourDrawer::PIContourDrawer(P2DArrayAdapter* arr,bool autodel,int *nz,double *z0,double *dz )
|
---|
623 | :GNUPlotContour(arr,nz,z0,dz)
|
---|
624 |
|
---|
625 | {
|
---|
626 | _arr = arr;
|
---|
627 | _nti = NULL;
|
---|
628 | _nz=5;
|
---|
629 | if(nz!=NULL)_nz = *nz;
|
---|
630 | _autodel = autodel;
|
---|
631 |
|
---|
632 | // This drawer has specific control tools
|
---|
633 | mFgSpecContWind = true;
|
---|
634 | InitAtts();
|
---|
635 | }
|
---|
636 |
|
---|
637 | //++
|
---|
638 | // PIContourDrawer(NTupleInterface* nti,bool autodel,int *nz,double *z0,double *dz )
|
---|
639 | // Constructeur a partir d'un NTupleInterface* - voir le createur de GNUPlotContour
|
---|
640 | //
|
---|
641 | //--
|
---|
642 | PIContourDrawer::PIContourDrawer(NTupleInterface* nti,bool autodel,int *nz,double *z0,double *dz )
|
---|
643 | :GNUPlotContour(nti,nz,z0,dz)
|
---|
644 |
|
---|
645 | {
|
---|
646 | _arr = NULL;
|
---|
647 | _nti = nti;
|
---|
648 | _nz=5;
|
---|
649 | if(nz!=NULL)_nz = *nz;
|
---|
650 | _autodel = autodel;
|
---|
651 | InitAtts();
|
---|
652 | }
|
---|
653 |
|
---|
654 |
|
---|
655 |
|
---|
656 | /* --Methode-- */
|
---|
657 | PIContourDrawer::~PIContourDrawer()
|
---|
658 | {
|
---|
659 | if(_autodel){
|
---|
660 | if(_arr!=NULL){delete _arr; _arr=NULL;}
|
---|
661 | if(_nti!=NULL){delete _nti ; _nti=NULL;}
|
---|
662 | }
|
---|
663 | DeactivateControlWindow(NULL);
|
---|
664 | //if (mColorMap!=NULL){delete mColorMap; mColorMap=NULL;}
|
---|
665 | }
|
---|
666 |
|
---|
667 | /* --Methode-- */
|
---|
668 | void PIContourDrawer::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
669 | {
|
---|
670 | // double xmin, double ymin, double xmax, double ymax LIMITES DE LA ZONE A REFRESHER
|
---|
671 | //PIGrCoord * xx = new PIGrCoord[10];
|
---|
672 | //PIGrCoord * yy = new PIGrCoord[10];
|
---|
673 | PIGrCoord * xx =NULL;
|
---|
674 | PIGrCoord * yy =NULL;
|
---|
675 | PIGrCoord xa;
|
---|
676 | PIGrCoord ya;
|
---|
677 | char buff[64];
|
---|
678 | // On met les bons attributs graphiques
|
---|
679 | //SelGraAtt(g);
|
---|
680 | g->SaveGraphicAtt();
|
---|
681 | struct gnuplot_contours *cntcur;
|
---|
682 | struct gnuplot_contours *cntold;
|
---|
683 | cntcur = _contours;
|
---|
684 |
|
---|
685 | double a,b;
|
---|
686 | int tot=0;
|
---|
687 | bool Invx, Invy, Exy;
|
---|
688 | PIColorMap * cmap = NULL;
|
---|
689 | CMapId mcmapid = GetGraphicAtt().GetColMapId();
|
---|
690 | if(mcmapid !=CMAP_OTHER ){
|
---|
691 | cmap = new PIColorMap(mcmapid);
|
---|
692 | }
|
---|
693 | int numdr = 0;
|
---|
694 | while(cntcur){
|
---|
695 | int npts = cntcur->num_pts ;
|
---|
696 | if(npts<0) continue;
|
---|
697 |
|
---|
698 | xx = new PIGrCoord[npts];
|
---|
699 | yy = new PIGrCoord[npts];
|
---|
700 | double lev = (cntcur->coords)[0].z ;
|
---|
701 | for(int l=0 ; l< npts ; l++){
|
---|
702 | a = (cntcur->coords)[l].x;
|
---|
703 | b = (cntcur->coords)[l].y;
|
---|
704 |
|
---|
705 | xx[l] = a ;
|
---|
706 | yy[l] = b ;
|
---|
707 |
|
---|
708 | }
|
---|
709 |
|
---|
710 | // choix de la couleur
|
---|
711 |
|
---|
712 | g->SelForeground(GetGraphicAtt().GetFgColor());
|
---|
713 | if(mcmapid !=CMAP_OTHER ){
|
---|
714 | if(_zmax-_zmin!=0){
|
---|
715 | int kc = ((lev - _zmin)/(_zmax-_zmin))*cmap->NCol();
|
---|
716 |
|
---|
717 | g->SelForeground(*cmap,kc);
|
---|
718 | }
|
---|
719 | }
|
---|
720 | // traitement des des markers
|
---|
721 | if(IsMarkOn()==true){
|
---|
722 |
|
---|
723 | g->SelMarker(GetGraphicAtt().GetMarkerSz(), GetGraphicAtt().GetMarker());
|
---|
724 | g->DrawMarkers(xx,yy,npts);
|
---|
725 | }
|
---|
726 | // traitement des lignes
|
---|
727 | if(mLineOn==true){
|
---|
728 |
|
---|
729 | g->SelLine(GetGraphicAtt().GetLineAtt());
|
---|
730 | g->DrawPolygon(xx,yy,npts,false);
|
---|
731 | }
|
---|
732 | // traitement des labels
|
---|
733 | // SIMPLISTE POUR L'INSTANT : UN AFFICHAGE
|
---|
734 | if(mLabelOn==true){
|
---|
735 | //
|
---|
736 |
|
---|
737 | char strg[10];
|
---|
738 | sprintf(strg,"%g",lev);
|
---|
739 | PIFont myfont(GetGraphicAtt().GetFont());
|
---|
740 |
|
---|
741 | g->SelFont(myfont);
|
---|
742 | double px,py;
|
---|
743 | px = (cntcur->coords)[0].x+2*(Xmax()-Xmin())/100.;
|
---|
744 | py = (cntcur->coords)[0].y;
|
---|
745 | g->DrawString(px,py,strg, PI_HorizontalCenter&&PI_VerticalCenter );
|
---|
746 |
|
---|
747 | }
|
---|
748 | numdr++;
|
---|
749 | delete[] xx;
|
---|
750 | xx=NULL;
|
---|
751 | delete[] yy;
|
---|
752 | yy=NULL;
|
---|
753 | cntcur = cntcur->next;
|
---|
754 | tot++;
|
---|
755 | }
|
---|
756 |
|
---|
757 | //cout << "PIContourDrawer::Draw fin de trace des "<<tot<< " polygones "<<endl;
|
---|
758 |
|
---|
759 | //
|
---|
760 | if(cmap !=NULL)delete cmap;
|
---|
761 |
|
---|
762 | g->RestoreGraphicAtt();
|
---|
763 | }
|
---|
764 |
|
---|
765 | /* --Methode-- */
|
---|
766 | void PIContourDrawer::UpdateLimits()
|
---|
767 | {
|
---|
768 | // Doit calculer les limites
|
---|
769 |
|
---|
770 | double xmn = _xmin;
|
---|
771 | double xmx = _xmax;
|
---|
772 | double ymn = _ymin;
|
---|
773 | double ymx = _ymax;
|
---|
774 |
|
---|
775 | SetLimits(xmn, xmx, ymn, ymx);
|
---|
776 | }
|
---|
777 |
|
---|
778 |
|
---|
779 | /* --Methode-- */
|
---|
780 | void PIContourDrawer::ShowControlWindow(PIBaseWdgGen* wdg)
|
---|
781 | {
|
---|
782 | PICnTools::SetCurrentBaseWdg(wdg);
|
---|
783 | PICnTools::SetCurrentCnDrw(this);
|
---|
784 | PICnTools::ShowPICnTools();
|
---|
785 | }
|
---|
786 |
|
---|
787 | //++
|
---|
788 | void PIContourDrawer::DeactivateControlWindow(PIBaseWdgGen* wdg)
|
---|
789 | //
|
---|
790 | // Desactivation de la fenetre de controle specialisee
|
---|
791 | //--
|
---|
792 | {
|
---|
793 | // si wdg != NULL, c'est un Detach (Drawer detache du PIBaseWdg
|
---|
794 | // si wdg == NULL, c'est un delete du PIHisto2D (du PIDrawer)
|
---|
795 |
|
---|
796 | PICnTools::SetCurrentBaseWdg(NULL);
|
---|
797 | PICnTools::SetCurrentCnDrw(NULL);
|
---|
798 | PICnTools::HidePICnTools();
|
---|
799 |
|
---|
800 | return;
|
---|
801 | }
|
---|
802 |
|
---|
803 |
|
---|
804 | /* --Methode-- */
|
---|
805 | bool PIContourDrawer::IsLabelOn(){
|
---|
806 | return (mLabelOn);
|
---|
807 | }
|
---|
808 |
|
---|
809 | bool PIContourDrawer::IsLineOn(){
|
---|
810 | return (mLineOn);
|
---|
811 | }
|
---|
812 |
|
---|
813 | bool PIContourDrawer::IsMarkOn(){
|
---|
814 | return (mMarkOn);
|
---|
815 | }
|
---|
816 |
|
---|
817 | void PIContourDrawer::SetLabelOn(bool state){
|
---|
818 | mLabelOn = state;
|
---|
819 | }
|
---|
820 |
|
---|
821 | void PIContourDrawer::SetMarkOn(bool state){
|
---|
822 | mMarkOn = state;
|
---|
823 | }
|
---|
824 |
|
---|
825 | void PIContourDrawer::SetLineOn(bool state){
|
---|
826 | mLineOn = state;
|
---|
827 | }
|
---|
828 |
|
---|
829 | void PIContourDrawer::InitAtts(){
|
---|
830 | mLineOn = true;
|
---|
831 | mMarkOn = false;
|
---|
832 | mLabelOn = false;
|
---|
833 | }
|
---|
834 |
|
---|
835 | int PIContourDrawer::DecodeOptionString(vector<string> & opt, bool rmdecopt)
|
---|
836 | {
|
---|
837 | // inspire de int PINTuple::DecodeOptionString
|
---|
838 | // OP 11/2002 LAL Orsay
|
---|
839 |
|
---|
840 | int ndec = opt.size();
|
---|
841 | if (ndec < 1) return(0);
|
---|
842 |
|
---|
843 |
|
---|
844 | cout << " PIDrawer::DecodeOptionString : ndec = "<< ndec <<endl;
|
---|
845 | // On appelle d'abord le decodage de la classe PIDrawer de laquelle
|
---|
846 | // on herite. (Pas obligatoire) on decode donc ici les attributs de
|
---|
847 | // couleur, fontes ...
|
---|
848 | int ndec1 = PIDrawer::DecodeOptionString(opt, rmdecopt);
|
---|
849 | cout << " PIDrawer::DecodeOptionString apres PIDrawer::DecodeOptionString : ndec = "
|
---|
850 | << ndec1 <<"<>" << ndec <<endl;
|
---|
851 | if( ndec - ndec1 < 1 ) return(ndec1); // si tout a ete decode
|
---|
852 |
|
---|
853 | vector<string> udopt; // On gardera ici les options non decodees
|
---|
854 | int iopt = 0;
|
---|
855 | ndec = opt.size();
|
---|
856 | int recalc = 0;
|
---|
857 | for (iopt = 0 ; iopt<ndec ; iopt++){
|
---|
858 |
|
---|
859 | string sopt = opt[iopt];
|
---|
860 | if( sopt.find_first_of("=") != string::npos ){
|
---|
861 | // options avec =
|
---|
862 | string deb = sopt.substr(0,sopt.find_first_of("="));
|
---|
863 | cout << " option avec = : "<<deb<<" "<<sopt<<endl;
|
---|
864 | if( (deb =="ncont") || (deb =="nc") ){ // # de contours
|
---|
865 | string fin = sopt.substr(sopt.find_first_of("=")+1 , string::npos);
|
---|
866 | cout <<" fin "<<fin<<endl;
|
---|
867 | int nlev = atoi(fin.c_str());
|
---|
868 | this->SetNLevel(nlev);
|
---|
869 | this->SetCntLevelKind(LEVELS_NUM);
|
---|
870 | recalc =1;
|
---|
871 | }else if(deb=="niv"||deb=="lev"){ // hauteur des niveaux
|
---|
872 | string fin = sopt.substr(sopt.find_first_of("=")+1 , string::npos);
|
---|
873 | char * buff = strdup(fin.c_str());
|
---|
874 | char *tmp;
|
---|
875 | tmp = strtok(buff,",");
|
---|
876 |
|
---|
877 | if(tmp==NULL){
|
---|
878 | cerr<< " PICOntourDrawer::DecodeOptionString ERREUR decodage des niveaux impossible " << buff <<endl;
|
---|
879 |
|
---|
880 | }else {
|
---|
881 |
|
---|
882 | vector <double> ztmp;
|
---|
883 | while(tmp!=NULL){
|
---|
884 | ztmp.push_back(atof(tmp));
|
---|
885 | tmp = strtok(NULL,",");
|
---|
886 | }
|
---|
887 | int nlev = ztmp.size();
|
---|
888 | cout << " PICOntourDrawer::DecodeOptionString "<<nlev<<" niveaux decodes "<<endl;
|
---|
889 | this->SetCntLevelKind(LEVELS_DISCRETE);
|
---|
890 | this->SetNLevel(nlev);
|
---|
891 | this->SetMyLevels(ztmp);
|
---|
892 | recalc =1;
|
---|
893 | }
|
---|
894 | }else if(deb=="lstep" ){ // niveaux incrementaux : args = nombre,depart,pas
|
---|
895 | string fin = sopt.substr(sopt.find_first_of("=")+1 , string::npos);
|
---|
896 | char * buff = strdup(fin.c_str());
|
---|
897 | char *tmp;
|
---|
898 | tmp = strtok(buff,",");
|
---|
899 |
|
---|
900 | if(tmp==NULL){
|
---|
901 | cerr<< " PICOntourDrawer::DecodeOptionString ERREUR decodage nvx/incr. impossible " << buff <<endl;
|
---|
902 | }else{
|
---|
903 |
|
---|
904 | vector <double> ztmp;
|
---|
905 | while(tmp!=NULL){
|
---|
906 | ztmp.push_back(atof(tmp));
|
---|
907 | tmp = strtok(NULL,",");
|
---|
908 | }
|
---|
909 | if(ztmp.size() !=2) {
|
---|
910 | cerr<< " PICOntourDrawer::DecodeOptionString ERREUR nb params incorrect(incr) " << buff <<endl;
|
---|
911 | }else{
|
---|
912 | vector <double> zlev;
|
---|
913 | zlev.push_back(ztmp[1]);
|
---|
914 | zlev.push_back(ztmp[2]);
|
---|
915 | this->SetCntLevelKind(LEVELS_INCREMENTAL);
|
---|
916 | this->SetNLevel( (int) ztmp[0]);
|
---|
917 | this->SetMyLevels(zlev);
|
---|
918 | recalc=1;
|
---|
919 | }
|
---|
920 | }
|
---|
921 |
|
---|
922 | }else{
|
---|
923 | cout<<"PICOntourDrawer::DecodeOptionString ERREUR option "<<sopt<<" non reconnue "<<endl;
|
---|
924 | ndec--;
|
---|
925 | if (rmdecopt) udopt.push_back( sopt );
|
---|
926 | }
|
---|
927 | }else{ //options sans "="
|
---|
928 | if( sopt == "labon" )
|
---|
929 | this->SetLabelOn();
|
---|
930 | else if (sopt == "bspline" ){
|
---|
931 | this->SetCntKind(CONTOUR_KIND_BSPLINE);
|
---|
932 | recalc = 1;
|
---|
933 | }else if (sopt == "3spl" ){
|
---|
934 | this->SetCntKind(CONTOUR_KIND_CUBIC_SPL);
|
---|
935 | recalc = 1;
|
---|
936 | }
|
---|
937 | else{
|
---|
938 | cout<<"PICOntourDrawer::DecodeOptionString ERREUR option "<<sopt<<" non reconnue "<<endl;
|
---|
939 | ndec--;
|
---|
940 | if (rmdecopt) udopt.push_back(sopt);
|
---|
941 | }
|
---|
942 | }
|
---|
943 |
|
---|
944 | }// FIN DE LA BOUCLE SUR LES OPTIONS
|
---|
945 |
|
---|
946 | if(recalc==1){
|
---|
947 | // il faut (re)calculer les contours
|
---|
948 | cout << " PICOntourDrawer::DecodeOptionString(re)calcul des contours "<<endl;
|
---|
949 | this->CalcContour();
|
---|
950 | }
|
---|
951 | this->Refresh();
|
---|
952 |
|
---|
953 |
|
---|
954 | //
|
---|
955 |
|
---|
956 | // S'il faut supprimer les options decodees, on remplace l'argument opt
|
---|
957 | // par le vecteur des options non decodees.
|
---|
958 | if (rmdecopt) opt = udopt;
|
---|
959 |
|
---|
960 | return(ndec+ndec1);
|
---|
961 |
|
---|
962 | }
|
---|
963 |
|
---|
964 |
|
---|
965 |
|
---|