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