[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>
|
---|
| 6 | #include "pintuple.h"
|
---|
| 7 |
|
---|
[537] | 8 | //++
|
---|
| 9 | // Class PINTuple
|
---|
| 10 | // Lib PIext
|
---|
| 11 | // include pintuple.h
|
---|
| 12 | //
|
---|
| 13 | // Classe de traceur 2D (dans un plan) à partir des données
|
---|
| 14 | // d'un objet implémentant l'interface *NTupleInterface*.
|
---|
| 15 | // Les objets "PINTuple" peuvent tracer des signes (markers)
|
---|
| 16 | // éventuellement avec des barres d'erreur et une étiquette
|
---|
[2373] | 17 | // pour chaque point. Si un nom de colonne poids est spécifié,
|
---|
| 18 | // la taille et/ou la couleur des signes (markers) sera fonction
|
---|
| 19 | // de la valeur de poids.
|
---|
[537] | 20 | //--
|
---|
| 21 | //++
|
---|
| 22 | // Links Parents
|
---|
| 23 | // PIDrawer
|
---|
| 24 | //--
|
---|
| 25 | //++
|
---|
| 26 | // Links Voir aussi
|
---|
| 27 | // NTupleInterface
|
---|
| 28 | // PINTuple3D
|
---|
| 29 | //--
|
---|
| 30 |
|
---|
| 31 | //++
|
---|
| 32 | // Titre Constructeur
|
---|
| 33 | //--
|
---|
| 34 | //++
|
---|
| 35 | // PINTuple(NTupleInterface* nt, bool ad)
|
---|
[544] | 36 | // Constructeur. Si "ad == true", l'objet "nt" est détruit par
|
---|
[537] | 37 | // le destructeur de l'objet "PINTuple"
|
---|
[2373] | 38 | // Note : "nt" doit être créé par new dans ce cas.
|
---|
[537] | 39 | //--
|
---|
[165] | 40 |
|
---|
| 41 | /* --Methode-- */
|
---|
[326] | 42 | PINTuple::PINTuple(NTupleInterface* nt, bool ad)
|
---|
[165] | 43 | : PIDrawer()
|
---|
| 44 | {
|
---|
| 45 | mNT = nt;
|
---|
| 46 | mAdDO = ad;
|
---|
[544] | 47 | SetStats(true);
|
---|
[2383] | 48 | SetStatPosOffset();
|
---|
[2350] | 49 | ConnectPoints(false);
|
---|
[2373] | 50 | UseSizeScale(true, 5);
|
---|
| 51 | UseColorScale(true);
|
---|
[165] | 52 | SelectXY(NULL, NULL);
|
---|
[2373] | 53 | SelectWt(NULL);
|
---|
[165] | 54 | SelectErrBar();
|
---|
[486] | 55 | SelectLabel(NULL);
|
---|
[1856] | 56 | SetName("NTupleDrw");
|
---|
[165] | 57 | }
|
---|
| 58 |
|
---|
| 59 | PINTuple::~PINTuple()
|
---|
| 60 | {
|
---|
| 61 | if (mAdDO && mNT) delete mNT;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[537] | 64 | //++
|
---|
| 65 | // Titre Méthodes
|
---|
| 66 | //--
|
---|
| 67 | //++
|
---|
| 68 | // void SelectXY(const char* px, const char* py)
|
---|
| 69 | // Choix des noms de colonnes X,Y définissant les coordonnées des points.
|
---|
| 70 | // Ces deux colonnes doivent être spécifiées pour obtenir un tracé.
|
---|
| 71 | // void SelectErrBar(const char* erbx=NULL, const char* erby=NULL)
|
---|
| 72 | // Choix des noms de colonnes pour le tracé des barres d'erreur.
|
---|
| 73 | // void SelectWt(const char* pw=NULL, int nbins=10)
|
---|
| 74 | // Choix du nom de colonne poids. Dans ce cas, la taille du signe
|
---|
| 75 | // (marker) sera proportionnel à la valeur de cette colonne pour
|
---|
| 76 | // chaque point.
|
---|
| 77 | // void SelectLabel(const char* plabel=NULL)
|
---|
| 78 | // Choix du nom de colonne correspondant à l'étiquette.
|
---|
| 79 | //--
|
---|
| 80 |
|
---|
[165] | 81 | /* --Methode-- */
|
---|
| 82 | void PINTuple::SelectXY(const char* px, const char* py)
|
---|
| 83 | {
|
---|
[326] | 84 | string name;
|
---|
[165] | 85 | if (mNT == NULL) xK = yK = -1;
|
---|
| 86 | if (px == NULL) xK = -1;
|
---|
[326] | 87 | else { name = px; xK = mNT->ColumnIndex(name); }
|
---|
[165] | 88 | if (py == NULL) yK = -1;
|
---|
[326] | 89 | else { name = py; yK = mNT->ColumnIndex(name); }
|
---|
[165] | 90 | }
|
---|
| 91 |
|
---|
| 92 | /* --Methode-- */
|
---|
[2373] | 93 | void PINTuple::SelectWt(const char* pw)
|
---|
[333] | 94 | {
|
---|
| 95 | if (pw == NULL) wK = -1;
|
---|
| 96 | else { string name = pw; wK = mNT->ColumnIndex(name); }
|
---|
| 97 |
|
---|
| 98 | if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
|
---|
| 99 | else { wMin = 0.; wMax = 1.; }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | /* --Methode-- */
|
---|
[486] | 103 | void PINTuple::SelectLabel(const char* plabel)
|
---|
| 104 | {
|
---|
| 105 | if (plabel == NULL) lK = -1;
|
---|
| 106 | else { string name = plabel; lK = mNT->ColumnIndex(name); }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | /* --Methode-- */
|
---|
[165] | 110 | void PINTuple::SelectErrBar(const char* erbx, const char* erby)
|
---|
| 111 | {
|
---|
[326] | 112 | string name;
|
---|
[165] | 113 | if (mNT == NULL) xebK = yebK = -1;
|
---|
| 114 | if (erbx == NULL) xebK = -1;
|
---|
[326] | 115 | else { name = erbx; xebK = mNT->ColumnIndex(name); }
|
---|
[165] | 116 | if (erby == NULL) yebK = -1;
|
---|
[326] | 117 | else { name = erby; yebK = mNT->ColumnIndex(name); }
|
---|
[165] | 118 | }
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 | /* --Methode-- */
|
---|
| 122 | void PINTuple::UpdateLimits()
|
---|
| 123 | {
|
---|
| 124 | if (!mNT) return;
|
---|
[326] | 125 | if (mNT->NbLines() <= 0) return;
|
---|
[165] | 126 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
| 127 |
|
---|
| 128 | // Commencer par trouver nos limites
|
---|
[326] | 129 | double xmin, xmax, ymin, ymax;
|
---|
[165] | 130 | xmin = ymin = 9.e19;
|
---|
| 131 | xmax = ymax = -9.e19;
|
---|
| 132 | mNT->GetMinMax(xK, xmin, xmax);
|
---|
| 133 | mNT->GetMinMax(yK, ymin, ymax);
|
---|
[2115] | 134 | PIAxes::ReSizeMinMax(isLogScaleX(),xmin,xmax);
|
---|
| 135 | PIAxes::ReSizeMinMax(isLogScaleY(),ymin,ymax);
|
---|
| 136 | SetLimits(xmin,xmax,ymin,ymax);
|
---|
[548] | 137 | // SetAxesFlags(kBoxAxes | kExtTicks | kLabels); Ne pas faire - Reza 11/99
|
---|
[165] | 138 | }
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 | /* --Methode-- */
|
---|
[205] | 142 | void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
[165] | 143 | {
|
---|
[333] | 144 | double xp,yp,xer,yer,wp;
|
---|
[326] | 145 | double xl,yl;
|
---|
[165] | 146 | int nok;
|
---|
| 147 |
|
---|
| 148 | if (!mNT) return;
|
---|
[548] | 149 | if (axesFlags != kAxesNone) DrawAxes(g);
|
---|
[165] | 150 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
[1905] | 151 | if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
|
---|
[326] | 152 |
|
---|
[333] | 153 | // Pour tracer des markers avec taille fonction de Wt (poids)
|
---|
| 154 | double dw = (wMax-wMin)/nWbins;
|
---|
[2373] | 155 | if (dw < 1.e-19) dw = 1.e-19;
|
---|
| 156 |
|
---|
| 157 | // Pour tracer des markers avec couleur en fonction de Wt (poids)
|
---|
| 158 | PIColorMap * cmap = NULL;
|
---|
| 159 | double dwc = 1.;
|
---|
| 160 | double nwc = 1.;
|
---|
| 161 | bool revcmap;
|
---|
| 162 | CMapId mcmapid = GetGraphicAtt().GetColMapId(revcmap);
|
---|
| 163 | if( colorScale && (wK >= 0) && (mcmapid != CMAP_OTHER) ) {
|
---|
| 164 | cmap = new PIColorMap(mcmapid);
|
---|
| 165 | cmap->ReverseColorIndex(revcmap);
|
---|
| 166 | nwc = cmap->NCol();
|
---|
| 167 | dwc = (wMax-wMin)/nwc;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[333] | 170 | int msz,sz;
|
---|
| 171 |
|
---|
[1905] | 172 | PIMarker mmrk = GetGraphicAtt().GetMarker();
|
---|
[333] | 173 | PIMarker mrk;
|
---|
[1905] | 174 | if (wK >= 0) mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_CircleMarker;
|
---|
| 175 | else mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_DotMarker;
|
---|
[2373] | 176 | msz = GetGraphicAtt().GetMarkerSz();
|
---|
[333] | 177 | if (msz < 1) msz = 1;
|
---|
[344] | 178 | g->SelMarker(msz, mrk);
|
---|
[333] | 179 |
|
---|
[685] | 180 | PIGrCoord uxmin, uxmax, uymin, uymax;
|
---|
| 181 | g->GetGrSpace(uxmin, uxmax, uymin, uymax);
|
---|
| 182 | double xmin2 = uxmin;
|
---|
| 183 | double ymin2 = uymin;
|
---|
| 184 | double xmax2 = uxmax;
|
---|
| 185 | double ymax2 = uymax;
|
---|
| 186 |
|
---|
[165] | 187 | nok = 0;
|
---|
[326] | 188 | xp = yp = xl = yl = 0;
|
---|
[2115] | 189 | for (long i=0; i<(long)mNT->NbLines(); i++) {
|
---|
[326] | 190 | xl = xp; yl = yp;
|
---|
| 191 | xp = mNT->GetCell(i, xK);
|
---|
| 192 | yp = mNT->GetCell(i, yK);
|
---|
[686] | 193 | if ( (xp < xmin2) || (xp > xmax2) || (yp < ymin2) || (yp > ymax2) ) continue;
|
---|
| 194 | nok++;
|
---|
[165] | 195 | if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
|
---|
[2373] | 196 |
|
---|
| 197 | // Taille - couleur de marker en fonction du poids
|
---|
| 198 | if (wK >= 0) wp = mNT->GetCell(i, wK);
|
---|
| 199 | if (mrkSzScale && (wK >= 0)) { // Changement de taille
|
---|
| 200 | sz = (int)((wp-wMin)/dw);
|
---|
| 201 | if (sz < 0) sz = 0;
|
---|
| 202 | if (sz > nWbins) sz = nWbins;
|
---|
| 203 | sz += msz;
|
---|
| 204 | if (sz < 2) g->SelMarker(sz, PI_DotMarker);
|
---|
| 205 | else g->SelMarker(sz, mrk);
|
---|
| 206 | }
|
---|
| 207 | // Couleur du marker en fonction du poids
|
---|
| 208 | if( colorScale && (wK >= 0) && cmap ) {
|
---|
| 209 | int cid = (int)((wp-wMin)/dwc);
|
---|
| 210 | if (cid < 0) cid = 0;
|
---|
| 211 | if (cid >= nwc) cid = nwc-1;
|
---|
| 212 | g->SelForeground(*cmap, cid);
|
---|
| 213 | }
|
---|
| 214 |
|
---|
[2350] | 215 | if ( (i > 0) && connectPts )
|
---|
[1905] | 216 | g->DrawLine(xl, yl, xp, yp); // On relie les points ...
|
---|
[165] | 217 | if ( xebK >= 0 ) {
|
---|
[326] | 218 | xer = mNT->GetCell(i, xebK);
|
---|
[165] | 219 | if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp);
|
---|
| 220 | }
|
---|
| 221 | if ( yebK >= 0 ) {
|
---|
[326] | 222 | yer = mNT->GetCell(i, yebK);
|
---|
[165] | 223 | if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer);
|
---|
| 224 | }
|
---|
[486] | 225 | // Trace du marker
|
---|
[1905] | 226 | if ((wK >= 0)||(lK < 0)||(mmrk != PI_NotDefMarker)) g->DrawMarker(xp, yp);
|
---|
[486] | 227 | // Trace eventuel du label
|
---|
| 228 | if (lK >= 0) g->DrawString(xp, yp, mNT->GetCelltoString(i, lK).c_str());
|
---|
| 229 |
|
---|
[165] | 230 | }
|
---|
| 231 |
|
---|
[544] | 232 | if (stats) { // Trace de stats
|
---|
[1905] | 233 | g->SelFontSz((YMax() - YMin())/30);
|
---|
[1645] | 234 | // La hauteur de la cellule
|
---|
[544] | 235 | PIGrCoord a,d;
|
---|
| 236 | double cH = (double)g->GetFontHeight(a,d);
|
---|
[1645] | 237 | double cellHeight = 1.2 * cH;
|
---|
| 238 | // Les labels et leurs longueurs -> largeur de la cellule
|
---|
| 239 | char label[64];
|
---|
[2383] | 240 | sprintf(label, "N=%d (/%d)", nok, mNT->NbLines());
|
---|
[1644] | 241 | double cellWidth = 1.1 * (double)g->CalcStringWidth(label);
|
---|
[1645] | 242 | double xu, yu, cw;
|
---|
[2383] | 243 | double ofpx = spoX*(XMax()-XMin());
|
---|
| 244 | double ofpy = spoY*(YMax()-YMin());
|
---|
[1645] | 245 | // Les limites du cadre
|
---|
[548] | 246 | xu = g->DeltaUCX(XMax(), - cellWidth);
|
---|
| 247 | yu = g->DeltaUCY(YMax(), - cellHeight);
|
---|
[2383] | 248 | double recw = XMax()-xu;
|
---|
| 249 | double rech = YMax()-yu;
|
---|
| 250 | xu += ofpx; yu += ofpy;
|
---|
| 251 | g->DrawBox(xu, yu, recw, rech);
|
---|
[1645] | 252 | // L'ecriture des labels (attention aux inversions possibles des axes!)
|
---|
| 253 | cw = (g->isAxeXDirRtoL()) ? -0.05*cellWidth : -0.95*cellWidth;
|
---|
| 254 | xu = g->DeltaUCX(XMax(),cw);
|
---|
| 255 | cw = (g->isAxeYDirUpDown()) ? -0.1*cH : -1.1*cH;
|
---|
| 256 | yu = g->DeltaUCY(YMax(),cw);
|
---|
[2383] | 257 | xu += ofpx; yu += ofpy;
|
---|
[1645] | 258 | g->DrawString(xu,yu,label);
|
---|
[544] | 259 | }
|
---|
| 260 |
|
---|
[2373] | 261 | if (cmap) delete cmap;
|
---|
[165] | 262 | return;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
[344] | 265 | /* --Methode-- */
|
---|
| 266 | void PINTuple::AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax)
|
---|
| 267 | {
|
---|
| 268 | if (!mNT) return;
|
---|
| 269 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
| 270 |
|
---|
| 271 | int ncnt = 0;
|
---|
| 272 | double xp,yp;
|
---|
| 273 | char buff[128];
|
---|
| 274 | sprintf(buff,"PINTuple: NLines= %d NCol= %d \n", mNT->NbLines(), mNT->NbColumns());
|
---|
| 275 | info += buff;
|
---|
| 276 | info += mNT->LineHeaderToString();
|
---|
[2115] | 277 | for(long i=0; i<(long)mNT->NbLines(); i++) {
|
---|
[344] | 278 | xp = mNT->GetCell(i, xK);
|
---|
| 279 | yp = mNT->GetCell(i, yK);
|
---|
| 280 | if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
|
---|
| 281 | ncnt++;
|
---|
| 282 | if (ncnt > 101) continue;
|
---|
| 283 | info += mNT->LineToString(i);
|
---|
| 284 | }
|
---|
| 285 | if (ncnt >= 101) info += " .... \n";
|
---|
| 286 | sprintf(buff," %d points inside selected region \n", ncnt);
|
---|
| 287 | info += buff;
|
---|
| 288 | // printf("PINTuple::AppendTextInfo()-DBG %g %g %g %g - %d\n", xmin, ymin, xmax, ymax, ncnt);
|
---|
| 289 | return;
|
---|
| 290 | }
|
---|
[1971] | 291 |
|
---|
| 292 | /* La methode DecodeOptionString permet de decoder un ensemble d'options
|
---|
| 293 | et de parametre d'affichage specifie sous forme d'un vecteur de string.
|
---|
| 294 | Si rmdecopt == true, les options decodees sont supprimees du vecteur
|
---|
| 295 | de string fourni en entree - ce qui permet l'enchainement eventuel
|
---|
| 296 | de plusieurs decodages de string.
|
---|
| 297 | Les options peuvent etre sous forme de flag : "stat" "nostat"
|
---|
| 298 | ou plus complexes, par exemple "dynamic=-3,3"
|
---|
| 299 | Rc: La methode renvoie le nombre d'options decodees
|
---|
| 300 | */
|
---|
| 301 |
|
---|
| 302 | /* --Methode-- */
|
---|
| 303 | int PINTuple::DecodeOptionString(vector<string> & opt, bool rmdecopt)
|
---|
| 304 | {
|
---|
[2229] | 305 | int optsz1 = opt.size();
|
---|
| 306 | if(optsz1<1) return(0);
|
---|
[1971] | 307 | // On appelle d'abord le decodage de la classe PIDrawer de laquelle
|
---|
| 308 | // on herite. (Pas obligatoire) on decode donc ici les attributs de
|
---|
| 309 | // couleur, fontes ...
|
---|
| 310 | int ndec1 = PIDrawer::DecodeOptionString(opt, rmdecopt);
|
---|
[2229] | 311 | if(optsz1-ndec1<1) return(ndec1); // si tout a ete decode
|
---|
[1971] | 312 |
|
---|
| 313 | vector<string> udopt; // On gardera ici les options non decodees
|
---|
| 314 | unsigned int k = 0;
|
---|
| 315 | int ndec = opt.size();
|
---|
| 316 | for( k=0; k<opt.size(); k++ ) {
|
---|
| 317 | string opts = opt[k];
|
---|
[2229] | 318 | if(opts=="sta" || opts=="stat" || opts=="stats") SetStats(true);
|
---|
| 319 | else if( opts=="nsta" || opts=="nstat"
|
---|
| 320 | || opts=="nostat" || opts=="nostats") SetStats(false);
|
---|
[2383] | 321 | else if(opts.substr(0,11) == "statposoff=") {
|
---|
| 322 | float xo=0., yo=0.;
|
---|
| 323 | sscanf(opts.substr(11).c_str(),"%g,%g",&xo, &yo);
|
---|
| 324 | SetStatPosOffset(xo, yo);
|
---|
| 325 | }
|
---|
[2350] | 326 | else if (opts == "connectpoints") ConnectPoints(true);
|
---|
| 327 | else if (opts == "noconnectpoints") ConnectPoints(false);
|
---|
[2373] | 328 | else if (opts == "colorscale") UseColorScale(true);
|
---|
| 329 | else if (opts == "nocolorscale") UseColorScale(false);
|
---|
| 330 | else if (opts == "sizescale") UseSizeScale(true);
|
---|
| 331 | else if (opts == "nosizescale") UseSizeScale(false);
|
---|
| 332 | else if (opts.substr(0,10) == "sizescale=") {
|
---|
| 333 | int nbn = atoi(opts.substr(10).c_str());
|
---|
| 334 | UseSizeScale(true, nbn);
|
---|
| 335 | }
|
---|
[2383] | 336 |
|
---|
[1971] | 337 | else {
|
---|
| 338 | // Si option non decode
|
---|
| 339 | ndec--;
|
---|
| 340 | // S'il faut supprimer les options decodees
|
---|
| 341 | if (rmdecopt) udopt.push_back(opts);
|
---|
| 342 | }
|
---|
| 343 | }
|
---|
| 344 | // S'il faut supprimer les options decodees, on remplace l'argument opt
|
---|
| 345 | // par le vecteur des options non decodees.
|
---|
| 346 | if (rmdecopt) opt = udopt;
|
---|
| 347 | return(ndec+ndec1);
|
---|
| 348 | }
|
---|
[1975] | 349 |
|
---|
| 350 | /* La methode GetOptionsHelpInfo(string& info) renvoie une chaine
|
---|
| 351 | avec la description des options comprises par ce drawer
|
---|
| 352 | Note: Il est preferable de ne pas initialiser la chaine
|
---|
| 353 | string info au depart, afin de permettre de mettre bout a
|
---|
| 354 | bout les aides de differents Drawer */
|
---|
| 355 |
|
---|
| 356 | /* --Methode-- */
|
---|
| 357 | void PINTuple::GetOptionsHelpInfo(string& info)
|
---|
| 358 | {
|
---|
[2229] | 359 | info += " ---- PINTuple options help info : \n" ;
|
---|
[2350] | 360 | info += " sta,stat,stats: activate statistic display\n";
|
---|
[2229] | 361 | info += " nsta,nstat,nostat,nostats: deactivate statistic display\n";
|
---|
[2383] | 362 | info += " statposoff=OffsetX,OffsetY : Position offset for Stats drawing \n";
|
---|
| 363 | info += " as a fraction of total size \n";
|
---|
[2350] | 364 | info += " connectpoints: The points are connected by a line \n";
|
---|
| 365 | info += " noconnectpoints (this is the default) \n";
|
---|
[2373] | 366 | info += " colorscale/nocolorscale (Use color scale for weight) \n";
|
---|
| 367 | info += " sizescale/sizescale=nbins/nosizescale (Use marker size for weight) \n";
|
---|
[2383] | 368 | info += " (and usual color/line/marker/... attribute decoding) \n";
|
---|
[2388] | 369 | // On recupere ensuite la chaine info de la classe de base
|
---|
| 370 | PIDrawer::GetOptionsHelpInfo(info);
|
---|
[2229] | 371 | return;
|
---|
[1975] | 372 | }
|
---|
[2373] | 373 |
|
---|
| 374 |
|
---|
| 375 |
|
---|