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