| 1 | // Peida Interactive   -   PI        R. Ansari 97-99 | 
|---|
| 2 | // Traceur (Drawer) pour NTupleInterface | 
|---|
| 3 | // LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA | 
|---|
| 4 |  | 
|---|
| 5 | #include <stdio.h> | 
|---|
| 6 | #include <stdlib.h> | 
|---|
| 7 | #include <iostream> | 
|---|
| 8 | #include <math.h> | 
|---|
| 9 | #include "sopnamsp.h" | 
|---|
| 10 | #include "pintuple.h" | 
|---|
| 11 |  | 
|---|
| 12 | //++ | 
|---|
| 13 | // Class        PINTuple | 
|---|
| 14 | // Lib          PIext | 
|---|
| 15 | // include      pintuple.h | 
|---|
| 16 | // | 
|---|
| 17 | //      Classe de traceur 2D (dans un plan) à partir des données | 
|---|
| 18 | //      d'un objet implémentant l'interface *NTupleInterface*. | 
|---|
| 19 | //      Les objets "PINTuple" peuvent tracer des signes (markers) | 
|---|
| 20 | //      éventuellement avec des barres d'erreur et une étiquette | 
|---|
| 21 | //      pour chaque point. Si un nom de colonne poids est spécifié, | 
|---|
| 22 | //      la taille et/ou la couleur des signes (markers) sera fonction | 
|---|
| 23 | //      de la valeur de poids. | 
|---|
| 24 | //-- | 
|---|
| 25 | //++ | 
|---|
| 26 | // Links        Parents | 
|---|
| 27 | // PIDrawer | 
|---|
| 28 | //-- | 
|---|
| 29 | //++ | 
|---|
| 30 | // Links        Voir aussi | 
|---|
| 31 | // NTupleInterface | 
|---|
| 32 | // PINTuple3D | 
|---|
| 33 | //-- | 
|---|
| 34 |  | 
|---|
| 35 | //++ | 
|---|
| 36 | // Titre        Constructeur | 
|---|
| 37 | //-- | 
|---|
| 38 | //++ | 
|---|
| 39 | // PINTuple(NTupleInterface* nt, bool ad) | 
|---|
| 40 | //      Constructeur. Si "ad == true", l'objet "nt" est détruit par | 
|---|
| 41 | //      le destructeur de l'objet "PINTuple" | 
|---|
| 42 | //      Note : "nt" doit être créé par new dans ce cas. | 
|---|
| 43 | //-- | 
|---|
| 44 |  | 
|---|
| 45 | /* --Methode-- */ | 
|---|
| 46 | PINTuple::PINTuple(NTupleInterface* nt, bool ad) | 
|---|
| 47 | : PIDrawer() | 
|---|
| 48 | { | 
|---|
| 49 | mNT = nt; | 
|---|
| 50 | mAdDO = ad; | 
|---|
| 51 | SetStats(true); | 
|---|
| 52 | SetStatPosOffset(); | 
|---|
| 53 | ConnectPoints(false); | 
|---|
| 54 | UseSizeScale(true, 5); | 
|---|
| 55 | UseColorScale(true); | 
|---|
| 56 | SelectXY(NULL, NULL); | 
|---|
| 57 | SelectWt(NULL); | 
|---|
| 58 | SelectErrBar(); | 
|---|
| 59 | SelectLabel(NULL); | 
|---|
| 60 | SelectColorByName(NULL); | 
|---|
| 61 | SelectColorByIndex(NULL); | 
|---|
| 62 | SetName("NTupleDrw"); | 
|---|
| 63 | NptDraw = 0; | 
|---|
| 64 |  | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | PINTuple::~PINTuple() | 
|---|
| 68 | { | 
|---|
| 69 | if (mAdDO && mNT)  delete mNT; | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | //++ | 
|---|
| 73 | // Titre        Méthodes | 
|---|
| 74 | //-- | 
|---|
| 75 | //++ | 
|---|
| 76 | // void  SelectXY(const char* px, const char* py) | 
|---|
| 77 | //      Choix des noms de colonnes X,Y définissant les coordonnées des points. | 
|---|
| 78 | //      Ces deux colonnes doivent être spécifiées pour obtenir un tracé. | 
|---|
| 79 | // void  SelectErrBar(const char* erbx=NULL, const char* erby=NULL) | 
|---|
| 80 | //      Choix des noms de colonnes pour le tracé des barres d'erreur. | 
|---|
| 81 | // void  SelectWt(const char* pw=NULL, int nbins=10) | 
|---|
| 82 | //      Choix du nom de colonne poids. Dans ce cas, la taille du signe | 
|---|
| 83 | //      (marker) sera proportionnel à la valeur de cette colonne pour | 
|---|
| 84 | //      chaque point. | 
|---|
| 85 | // void  SelectLabel(const char* plabel=NULL) | 
|---|
| 86 | //      Choix du nom de colonne correspondant à l'étiquette. | 
|---|
| 87 | //-- | 
|---|
| 88 |  | 
|---|
| 89 | /* --Methode-- */ | 
|---|
| 90 | void  PINTuple::SelectXY(const char* px, const char* py) | 
|---|
| 91 | { | 
|---|
| 92 | string name; | 
|---|
| 93 | if (mNT == NULL)  xK = yK = -1; | 
|---|
| 94 | if (px == NULL) xK = -1; | 
|---|
| 95 | else { name = px; xK = mNT->ColumnIndex(name); } | 
|---|
| 96 | if (py == NULL) yK = -1; | 
|---|
| 97 | else { name = py; yK = mNT->ColumnIndex(name); } | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | /* --Methode-- */ | 
|---|
| 101 | void  PINTuple::SelectWt(const char* pw) | 
|---|
| 102 | { | 
|---|
| 103 | if (pw == NULL) wK = -1; | 
|---|
| 104 | else { string name = pw;   wK = mNT->ColumnIndex(name);  } | 
|---|
| 105 |  | 
|---|
| 106 | if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax); | 
|---|
| 107 | else  { wMin = 0.; wMax = 1.; } | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | /* --Methode-- */ | 
|---|
| 111 | void  PINTuple::SelectLabel(const char* plabel) | 
|---|
| 112 | { | 
|---|
| 113 | if (plabel == NULL) lK = -1; | 
|---|
| 114 | else {  string name = plabel;  lK = mNT->ColumnIndex(name);  } | 
|---|
| 115 | } | 
|---|
| 116 |  | 
|---|
| 117 | /* --Methode-- */ | 
|---|
| 118 | void  PINTuple::SelectColorByName(const char* pcolnm) | 
|---|
| 119 | { | 
|---|
| 120 | if (pcolnm == NULL) cnK = -1; | 
|---|
| 121 | else {  string name = pcolnm;  cnK = mNT->ColumnIndex(name);  } | 
|---|
| 122 | if (cnK >= 0)  ciK = -1; | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|
| 125 | /* --Methode-- */ | 
|---|
| 126 | void  PINTuple::SelectColorByIndex(const char* pcolidx) | 
|---|
| 127 | { | 
|---|
| 128 | if (pcolidx == NULL) ciK = -1; | 
|---|
| 129 | else {  string name = pcolidx;  ciK = mNT->ColumnIndex(name);  } | 
|---|
| 130 | if (ciK >= 0)  cnK = -1; | 
|---|
| 131 | } | 
|---|
| 132 |  | 
|---|
| 133 |  | 
|---|
| 134 | /* --Methode-- */ | 
|---|
| 135 | void  PINTuple::SelectErrBar(const char* erbx, const char* erby) | 
|---|
| 136 | { | 
|---|
| 137 | string name; | 
|---|
| 138 | if (mNT == NULL)  xebK = yebK = -1; | 
|---|
| 139 | if (erbx == NULL) xebK = -1; | 
|---|
| 140 | else { name = erbx;  xebK = mNT->ColumnIndex(name); } | 
|---|
| 141 | if (erby == NULL) yebK = -1; | 
|---|
| 142 | else { name = erby;  yebK = mNT->ColumnIndex(name); } | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 |  | 
|---|
| 146 | /* --Methode-- */ | 
|---|
| 147 | void PINTuple::UpdateLimits() | 
|---|
| 148 | { | 
|---|
| 149 | if (!mNT) return; | 
|---|
| 150 | if (mNT->NbLines() <= 0)  return; | 
|---|
| 151 | if ( (xK < 0) || (yK < 0) )   return; | 
|---|
| 152 |  | 
|---|
| 153 | // Commencer par trouver nos limites | 
|---|
| 154 | double xmin, xmax, ymin, ymax; | 
|---|
| 155 | xmin = ymin = 9.e19; | 
|---|
| 156 | xmax = ymax = -9.e19; | 
|---|
| 157 | mNT->GetMinMax(xK, xmin, xmax); | 
|---|
| 158 | mNT->GetMinMax(yK, ymin, ymax); | 
|---|
| 159 | PIAxes::ReSizeMinMax(isLogScaleX(),xmin,xmax); | 
|---|
| 160 | PIAxes::ReSizeMinMax(isLogScaleY(),ymin,ymax); | 
|---|
| 161 | SetLimits(xmin,xmax,ymin,ymax); | 
|---|
| 162 | //  SetAxesFlags(kBoxAxes | kExtTicks | kLabels);  Ne pas faire - Reza 11/99 | 
|---|
| 163 | } | 
|---|
| 164 |  | 
|---|
| 165 |  | 
|---|
| 166 | /* --Methode-- */ | 
|---|
| 167 | #define NMXMULTP_LOCAL  30   // Pour multipoint sans new | 
|---|
| 168 | void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax) | 
|---|
| 169 | { | 
|---|
| 170 | double xp,yp,xer,yer,wp; | 
|---|
| 171 | double xl,yl; | 
|---|
| 172 | long nok; | 
|---|
| 173 | int npolyg; | 
|---|
| 174 |  | 
|---|
| 175 | if (!mNT) return; | 
|---|
| 176 | if (axesFlags != kAxesNone) DrawAxes(g); | 
|---|
| 177 | if ( (xK < 0) || (yK < 0) )  return; | 
|---|
| 178 | if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt)  g->SelLine(PI_ThinLine); | 
|---|
| 179 |  | 
|---|
| 180 | //  Pour tracer des markers avec taille fonction de Wt (poids) | 
|---|
| 181 | double dw = (wMax-wMin)/nWbins; | 
|---|
| 182 | if (dw < 1.e-19) dw = 1.e-19; | 
|---|
| 183 |  | 
|---|
| 184 | // La couleur par defaut (pour le trace avec couleur specifie par nom de colonne (06/2007) | 
|---|
| 185 | PIColors defcol = GetGraphicAtt().GetColor(); | 
|---|
| 186 | if (defcol == PI_NotDefColor) defcol = PI_Black; | 
|---|
| 187 |  | 
|---|
| 188 | //  Pour tracer des markers avec couleur en fonction de Wt (poids) | 
|---|
| 189 | PIColorMap * cmap = NULL; | 
|---|
| 190 | double dwc = 1.; | 
|---|
| 191 | int nwc = 1; | 
|---|
| 192 | bool revcmap; | 
|---|
| 193 | CMapId mcmapid = GetGraphicAtt().GetColMapId(revcmap); | 
|---|
| 194 | if( colorScale && (wK >= 0) && (mcmapid != CMAP_OTHER) ) { | 
|---|
| 195 | cmap = new PIColorMap(mcmapid); | 
|---|
| 196 | cmap->ReverseColorIndex(revcmap); | 
|---|
| 197 | nwc = cmap->NCol(); | 
|---|
| 198 | dwc = (wMax-wMin)/(double)nwc; | 
|---|
| 199 | } | 
|---|
| 200 |  | 
|---|
| 201 | int msz,sz; | 
|---|
| 202 |  | 
|---|
| 203 | PIMarker mmrk = GetGraphicAtt().GetMarker(); | 
|---|
| 204 | PIMarker mrk; | 
|---|
| 205 | if (wK >= 0)  mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_CircleMarker; | 
|---|
| 206 | else   mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_DotMarker; | 
|---|
| 207 | msz = GetGraphicAtt().GetMarkerSz(); | 
|---|
| 208 | if (msz < 1) msz = 1; | 
|---|
| 209 | g->SelMarker(msz, mrk); | 
|---|
| 210 |  | 
|---|
| 211 | PIGrCoord uxmin, uxmax, uymin, uymax; | 
|---|
| 212 | g->GetGrSpace(uxmin, uxmax, uymin, uymax); | 
|---|
| 213 | double xmin2 = uxmin; | 
|---|
| 214 | double ymin2 = uymin; | 
|---|
| 215 | double xmax2 = uxmax; | 
|---|
| 216 | double ymax2 = uymax; | 
|---|
| 217 |  | 
|---|
| 218 | nok = 0; | 
|---|
| 219 | xp = yp = xl = yl = 0; | 
|---|
| 220 | PIGrCoord xpolyg[NMXMULTP_LOCAL], ypolyg[NMXMULTP_LOCAL]; | 
|---|
| 221 | npolyg = 0; | 
|---|
| 222 | NptDraw = 0; | 
|---|
| 223 |  | 
|---|
| 224 | // Mai 2005: Correction bug trace des lignes avec le pts en dehors de la zone (Reza) | 
|---|
| 225 | // flags pour la gestion des points/lignes a tracer | 
|---|
| 226 | bool fgokcurpt = true;  // Point courant dans la zone a tracer | 
|---|
| 227 | bool fgoklastpt = true;   // Le dernier point etait dans la zone a tracer | 
|---|
| 228 | for (long i=0; i<(long)mNT->NbLines(); i++) { | 
|---|
| 229 | xl = xp;  yl = yp; fgoklastpt = fgokcurpt; | 
|---|
| 230 |  | 
|---|
| 231 | xp = mNT->GetCell(i, xK); | 
|---|
| 232 | yp = mNT->GetCell(i, yK); | 
|---|
| 233 |  | 
|---|
| 234 | // Comptage du nombre de pts dans la zone graphique du widget | 
|---|
| 235 | if ( !((xp < xmin2) || (xp > xmax2) || (yp < ymin2) || (yp > ymax2)) )  nok++; | 
|---|
| 236 | // Gestion des limites a tracer | 
|---|
| 237 | fgokcurpt = true; | 
|---|
| 238 | if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) fgokcurpt = false; | 
|---|
| 239 | else NptDraw++; | 
|---|
| 240 |  | 
|---|
| 241 | // Taille - couleur de marker en fonction du poids | 
|---|
| 242 | if ( fgokcurpt &&(wK >= 0) ) wp = mNT->GetCell(i, wK); | 
|---|
| 243 | if ( fgokcurpt && mrkSzScale && (wK >= 0) ) {  // Changement de taille | 
|---|
| 244 | sz = (int)((wp-wMin)/dw); | 
|---|
| 245 | if (sz < 0) sz = 0; | 
|---|
| 246 | if (sz > nWbins)  sz = nWbins; | 
|---|
| 247 | sz += msz; | 
|---|
| 248 | if (sz < 2)  g->SelMarker(sz, PI_DotMarker); | 
|---|
| 249 | else g->SelMarker(sz, mrk); | 
|---|
| 250 | } | 
|---|
| 251 | // Couleur du marker en fonction du poids | 
|---|
| 252 | if( fgokcurpt && colorScale && (wK >= 0) && cmap ) { | 
|---|
| 253 | int cid = (int)((wp-wMin)/dwc); | 
|---|
| 254 | if (cid < 0) cid = 0; | 
|---|
| 255 | if (cid >= nwc)  cid = nwc-1; | 
|---|
| 256 | g->SelForeground(*cmap, cid); | 
|---|
| 257 | } | 
|---|
| 258 |  | 
|---|
| 259 | // Si on a specifie un nom de colonne pour la couleur (06/2007) | 
|---|
| 260 | if ( (cnK >= 0) || (ciK >= 0) ) { | 
|---|
| 261 | PIColors scol = defcol; | 
|---|
| 262 | if (cnK > 0) | 
|---|
| 263 | scol = PIGraphicAtt::ColNameToColor(mNT->GetCelltoString(i, cnK)); | 
|---|
| 264 | else | 
|---|
| 265 | scol = PIGraphicAtt::ColIndexToColor(mNT->GetCell(i, ciK)); | 
|---|
| 266 | if (scol == PI_NotDefColor) scol = defcol; | 
|---|
| 267 | g->SelForeground(scol); | 
|---|
| 268 | } | 
|---|
| 269 |  | 
|---|
| 270 | // Trace d'une ligne reliant les points | 
|---|
| 271 | if( connectPts ) { | 
|---|
| 272 | // On initialise le polygone avec le dernier point, si ce dernier ok | 
|---|
| 273 | if((npolyg==0) && (i>0) && fgokcurpt) {xpolyg[0]=xl; ypolyg[0]=yl; npolyg=1;} | 
|---|
| 274 | // On ajoute le point courant au polygone - sauf si celui-ci est vide | 
|---|
| 275 | if((npolyg<NMXMULTP_LOCAL) && (npolyg>0)) | 
|---|
| 276 | {xpolyg[npolyg]=xp; ypolyg[npolyg]=yp; npolyg++;} | 
|---|
| 277 | // On trace le polygone s'il est plein - ou le point courant en dehors | 
|---|
| 278 | // (point courant en dehors -> discontinuite de la ligne | 
|---|
| 279 | if( !fgokcurpt || (npolyg==NMXMULTP_LOCAL) ) | 
|---|
| 280 | {g->DrawPolygon(xpolyg,ypolyg,npolyg,false); npolyg=0;} | 
|---|
| 281 | } | 
|---|
| 282 |  | 
|---|
| 283 | // Plus rien a faire si point en dehors -- on s'en va | 
|---|
| 284 | if (!fgokcurpt)  continue; | 
|---|
| 285 |  | 
|---|
| 286 | // Trace des erreurs selon X et Y | 
|---|
| 287 | if (xebK >= 0) { | 
|---|
| 288 | xer = mNT->GetCell(i, xebK); | 
|---|
| 289 | if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp); | 
|---|
| 290 | } | 
|---|
| 291 | if (yebK >= 0) { | 
|---|
| 292 | yer = mNT->GetCell(i, yebK); | 
|---|
| 293 | if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer); | 
|---|
| 294 | } | 
|---|
| 295 |  | 
|---|
| 296 | // Trace du marker | 
|---|
| 297 | if ((wK >= 0)||(lK < 0)||(mmrk != PI_NotDefMarker))  g->DrawMarker(xp, yp); | 
|---|
| 298 |  | 
|---|
| 299 | // Trace eventuel du label | 
|---|
| 300 | if (lK >= 0) g->DrawString(xp, yp, mNT->GetCelltoString(i, lK).c_str()); | 
|---|
| 301 |  | 
|---|
| 302 | } | 
|---|
| 303 |  | 
|---|
| 304 | // Fin du trace d'une ligne reliant les points  si necessaire | 
|---|
| 305 | if( connectPts && npolyg>1 ) | 
|---|
| 306 | {g->DrawPolygon(xpolyg,ypolyg,npolyg,false); npolyg=0;} | 
|---|
| 307 |  | 
|---|
| 308 | if (stats) { // Trace de stats | 
|---|
| 309 | g->SelForeground(defcol); | 
|---|
| 310 | // Reza(12/2008): utilisation de flag et fraction pour selection automatique taille de fonte | 
|---|
| 311 | if (mAFSz) { | 
|---|
| 312 | double fsz = (YMax() - YMin())*mFontSzF; | 
|---|
| 313 | g->SelFontSz(fsz);  // au lieu de 1/30*(ymax-ymin) | 
|---|
| 314 | } | 
|---|
| 315 | // La hauteur de la cellule | 
|---|
| 316 | PIGrCoord a,d; | 
|---|
| 317 | double cH = (double)g->GetFontHeight(a,d); | 
|---|
| 318 | double cellHeight = 1.2 * cH; | 
|---|
| 319 | // Les labels et leurs longueurs -> largeur de la cellule | 
|---|
| 320 | char label[64]; | 
|---|
| 321 | sprintf(label, "N=%ld (/%ld)", (long)nok, (long)mNT->NbLines()); | 
|---|
| 322 | double cellWidth =   1.1 * (double)g->CalcStringWidth(label); | 
|---|
| 323 | double xu, yu, cw; | 
|---|
| 324 | double ofpx = spoX*(XMax()-XMin()); | 
|---|
| 325 | double ofpy = spoY*(YMax()-YMin()); | 
|---|
| 326 | // Les limites du cadre | 
|---|
| 327 | xu = g->DeltaUCX(XMax(), - cellWidth); | 
|---|
| 328 | yu = g->DeltaUCY(YMax(), - cellHeight); | 
|---|
| 329 | double recw = XMax()-xu; | 
|---|
| 330 | double rech = YMax()-yu; | 
|---|
| 331 | xu += ofpx;  yu += ofpy; | 
|---|
| 332 | g->DrawBox(xu, yu, recw, rech); | 
|---|
| 333 | // L'ecriture des labels (attention aux inversions possibles des axes!) | 
|---|
| 334 | cw = (g->isAxeXDirRtoL()) ? -0.05*cellWidth : -0.95*cellWidth; | 
|---|
| 335 | xu = g->DeltaUCX(XMax(),cw); | 
|---|
| 336 | cw = (g->isAxeYDirUpDown()) ? -0.1*cH : -1.1*cH; | 
|---|
| 337 | yu = g->DeltaUCY(YMax(),cw); | 
|---|
| 338 | xu += ofpx;  yu += ofpy; | 
|---|
| 339 | g->DrawString(xu,yu,label); | 
|---|
| 340 | } | 
|---|
| 341 |  | 
|---|
| 342 | if (cmap) delete cmap; | 
|---|
| 343 | return; | 
|---|
| 344 | } | 
|---|
| 345 | #undef NMXMULTP_LOCAL | 
|---|
| 346 |  | 
|---|
| 347 | /* --Methode-- */ | 
|---|
| 348 | void PINTuple::AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax) | 
|---|
| 349 | { | 
|---|
| 350 | if (!mNT) return; | 
|---|
| 351 | if ( (xK < 0) || (yK < 0) )  return; | 
|---|
| 352 |  | 
|---|
| 353 | long ncnt = 0; | 
|---|
| 354 | double xp,yp; | 
|---|
| 355 | char buff[128]; | 
|---|
| 356 | sprintf(buff,"PINTuple: NLines= %ld  NCol= %ld \n", (long)mNT->NbLines(), | 
|---|
| 357 | (long)mNT->NbColumns()); | 
|---|
| 358 | info += buff; | 
|---|
| 359 | info += mNT->LineHeaderToString(); | 
|---|
| 360 | for(long i=0; i<(long)mNT->NbLines(); i++) { | 
|---|
| 361 | xp = mNT->GetCell(i, xK); | 
|---|
| 362 | yp = mNT->GetCell(i, yK); | 
|---|
| 363 | if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) )  continue; | 
|---|
| 364 | ncnt++; | 
|---|
| 365 | if (ncnt > 101) continue; | 
|---|
| 366 | info += mNT->LineToString(i); | 
|---|
| 367 | } | 
|---|
| 368 | if (ncnt >= 101) info += " .... \n"; | 
|---|
| 369 | sprintf(buff," %ld points inside selected region \n", (long)ncnt); | 
|---|
| 370 | info += buff; | 
|---|
| 371 | // printf("PINTuple::AppendTextInfo()-DBG %g %g %g %g - %d\n", xmin, ymin, xmax, ymax, ncnt); | 
|---|
| 372 | return; | 
|---|
| 373 | } | 
|---|
| 374 |  | 
|---|
| 375 | /*  La methode DecodeOptionString permet de decoder un ensemble d'options | 
|---|
| 376 | et de parametre d'affichage specifie sous forme d'un vecteur de string. | 
|---|
| 377 | Si rmdecopt == true, les options decodees sont supprimees du vecteur | 
|---|
| 378 | de string fourni en entree - ce qui permet l'enchainement eventuel | 
|---|
| 379 | de plusieurs decodages de string. | 
|---|
| 380 | Les options peuvent etre sous forme de flag : "stat" "nostat" | 
|---|
| 381 | ou plus complexes, par exemple "dynamic=-3,3" | 
|---|
| 382 | Rc: La methode renvoie le nombre d'options decodees | 
|---|
| 383 | */ | 
|---|
| 384 |  | 
|---|
| 385 | /* --Methode-- */ | 
|---|
| 386 | int PINTuple::DecodeOptionString(vector<string> & opt, bool rmdecopt) | 
|---|
| 387 | { | 
|---|
| 388 | int optsz1 = opt.size(); | 
|---|
| 389 | if(optsz1<1)  return(0); | 
|---|
| 390 | // On appelle d'abord le decodage de la classe PIDrawer de laquelle | 
|---|
| 391 | // on herite. (Pas obligatoire) on decode donc ici les attributs de | 
|---|
| 392 | // couleur, fontes ... | 
|---|
| 393 | int ndec1 = PIDrawer::DecodeOptionString(opt, rmdecopt); | 
|---|
| 394 | if(optsz1-ndec1<1) return(ndec1);  // si tout a ete decode | 
|---|
| 395 |  | 
|---|
| 396 | vector<string> udopt;  // On gardera ici les options non decodees | 
|---|
| 397 | unsigned int k = 0; | 
|---|
| 398 | int ndec = opt.size(); | 
|---|
| 399 | for( k=0; k<opt.size(); k++ ) { | 
|---|
| 400 | string opts = opt[k]; | 
|---|
| 401 | if(opts=="sta" || opts=="stat" || opts=="stats") SetStats(true); | 
|---|
| 402 | else if(  opts=="nsta"   || opts=="nstat" | 
|---|
| 403 | || opts=="nostat" || opts=="nostats") SetStats(false); | 
|---|
| 404 | else if(opts.substr(0,11) == "statposoff=") { | 
|---|
| 405 | double xo=0., yo=0.; | 
|---|
| 406 | sscanf(opts.substr(11).c_str(),"%lf,%lf",&xo, &yo); | 
|---|
| 407 | SetStatPosOffset(xo, yo); | 
|---|
| 408 | } | 
|---|
| 409 | else if (opts == "connectpoints") ConnectPoints(true); | 
|---|
| 410 | else if (opts == "cpts") ConnectPoints(true); | 
|---|
| 411 | else if (opts == "noconnectpoints") ConnectPoints(false); | 
|---|
| 412 | else if (opts == "colorscale") UseColorScale(true); | 
|---|
| 413 | else if (opts == "nocolorscale") UseColorScale(false); | 
|---|
| 414 | else if (opts == "sizescale") UseSizeScale(true); | 
|---|
| 415 | else if (opts == "nosizescale") UseSizeScale(false); | 
|---|
| 416 | else if (opts.substr(0,10) == "sizescale=") { | 
|---|
| 417 | int nbn = atoi(opts.substr(10).c_str()); | 
|---|
| 418 | UseSizeScale(true, nbn); | 
|---|
| 419 | } | 
|---|
| 420 |  | 
|---|
| 421 | else { | 
|---|
| 422 | // Si option non decode | 
|---|
| 423 | ndec--; | 
|---|
| 424 | // S'il faut supprimer les options decodees | 
|---|
| 425 | if (rmdecopt)  udopt.push_back(opts); | 
|---|
| 426 | } | 
|---|
| 427 | } | 
|---|
| 428 | // S'il faut supprimer les options decodees, on remplace l'argument opt | 
|---|
| 429 | // par le vecteur des options non decodees. | 
|---|
| 430 | if (rmdecopt)  opt = udopt; | 
|---|
| 431 | return(ndec+ndec1); | 
|---|
| 432 | } | 
|---|
| 433 |  | 
|---|
| 434 | int PINTuple::OptionToString(vector<string> & opt) const | 
|---|
| 435 | { | 
|---|
| 436 | PIDrawer::OptionToString(opt); | 
|---|
| 437 |  | 
|---|
| 438 | char str[256]; | 
|---|
| 439 |  | 
|---|
| 440 | if(stats) opt.push_back("stat"); else opt.push_back("nstat"); | 
|---|
| 441 |  | 
|---|
| 442 | sprintf(str,"statposoff=%lf,%lf",spoX,spoY); opt.push_back(str); | 
|---|
| 443 |  | 
|---|
| 444 | if(connectPts) opt.push_back("connectpoints"); | 
|---|
| 445 | else opt.push_back("noconnectpoints"); | 
|---|
| 446 |  | 
|---|
| 447 | if(colorScale) opt.push_back("colorscale"); | 
|---|
| 448 | else opt.push_back("nocolorscale"); | 
|---|
| 449 |  | 
|---|
| 450 | if(mrkSzScale) { | 
|---|
| 451 | if(nWbins>0) {sprintf(str,"sizescale=%d",nWbins); opt.push_back(str);} | 
|---|
| 452 | else opt.push_back("sizescale"); | 
|---|
| 453 | } else opt.push_back("nosizescale"); | 
|---|
| 454 |  | 
|---|
| 455 | return 1; | 
|---|
| 456 | } | 
|---|
| 457 |  | 
|---|
| 458 | /* La methode GetOptionsHelpInfo(string& info) renvoie une chaine | 
|---|
| 459 | avec la description des options comprises par ce drawer | 
|---|
| 460 | Note: Il est preferable de ne pas initialiser la chaine | 
|---|
| 461 | string info au depart, afin de permettre de mettre bout a | 
|---|
| 462 | bout les aides de differents Drawer */ | 
|---|
| 463 |  | 
|---|
| 464 | /* --Methode-- */ | 
|---|
| 465 | void PINTuple::GetOptionsHelpInfo(string& info) | 
|---|
| 466 | { | 
|---|
| 467 | info += " ---- PINTuple options help info : \n" ; | 
|---|
| 468 | info += "  sta,stat,stats:            activate   statistic display\n"; | 
|---|
| 469 | info += "  nsta,nstat,nostat,nostats: deactivate statistic display\n"; | 
|---|
| 470 | info += "  statposoff=OffsetX,OffsetY : Position offset for Stats drawing \n"; | 
|---|
| 471 | info += "      as a fraction of total size \n"; | 
|---|
| 472 | info += "  connectpoints: The points are connected by a line \n"; | 
|---|
| 473 | info += "  noconnectpoints (this is the default) \n"; | 
|---|
| 474 | info += "  colorscale/nocolorscale (Use color scale for weight) \n"; | 
|---|
| 475 | info += "  sizescale/sizescale=nbins/nosizescale (Use marker size for weight) \n"; | 
|---|
| 476 | info += "   (and usual color/line/marker/... attribute decoding)  \n"; | 
|---|
| 477 | // On recupere ensuite la chaine info de la classe de base | 
|---|
| 478 | PIDrawer::GetOptionsHelpInfo(info); | 
|---|
| 479 | return; | 
|---|
| 480 | } | 
|---|
| 481 |  | 
|---|
| 482 |  | 
|---|
| 483 | /* --Methode-- */ | 
|---|
| 484 | double PINTuple::GetDistanceToPoint(double x, double y) | 
|---|
| 485 | { | 
|---|
| 486 | if(!mNT) return 1.e+9; | 
|---|
| 487 | if( xK<0 || yK<0 ) return 1.e+9; | 
|---|
| 488 |  | 
|---|
| 489 | const int nessai = 100; | 
|---|
| 490 | long inc = (NptDraw>nessai) ? (long)(NptDraw/nessai)+1 : 1; | 
|---|
| 491 |  | 
|---|
| 492 | double dist = -1.e+18; | 
|---|
| 493 | long n = 0; | 
|---|
| 494 | for(long i=0; i<(long)mNT->NbLines(); i++) { | 
|---|
| 495 | double xp=mNT->GetCell(i,xK); | 
|---|
| 496 | if(xp<XMin() || xp>XMax()) continue; | 
|---|
| 497 | double yp=mNT->GetCell(i,yK); | 
|---|
| 498 | if(yp<YMin() || yp>YMax()) continue; | 
|---|
| 499 | if(n%inc==0) { | 
|---|
| 500 | xp = (xp-x)/(XMax()-XMin())/0.5; | 
|---|
| 501 | yp = (yp-y)/(YMax()-YMin())/0.5; | 
|---|
| 502 | xp = xp*xp+yp*yp; | 
|---|
| 503 | if(dist<0. || xp<dist) dist = xp; | 
|---|
| 504 | } | 
|---|
| 505 | n++; | 
|---|
| 506 | } | 
|---|
| 507 | dist=sqrt(fabs(dist)); | 
|---|
| 508 | //cout<<"PINTuple: xlim="<<XMin()<<","<<XMax()<<" ylim="<<YMin()<<","<<YMax() | 
|---|
| 509 | //    <<" NbLines="<<mNT->NbLines()<<" inc="<<inc<<endl; | 
|---|
| 510 | //cout<<"....d="<<dist<<" x="<<x<<" y="<<y<<" NptDraw="<<NptDraw<<endl; | 
|---|
| 511 |  | 
|---|
| 512 | return dist; | 
|---|
| 513 | } | 
|---|