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