| 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 "pintuple.h"
|
|---|
| 7 |
|
|---|
| 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
|
|---|
| 17 | // pour chaque point. Si un attribut de ligne, autre que
|
|---|
| 18 | // "PI_NotDefLineAtt" est spécifié, les points sont connectés
|
|---|
| 19 | // par une ligne.
|
|---|
| 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)
|
|---|
| 36 | // Constructeur. Si "ad == true", l'objet "nt" est détruit par
|
|---|
| 37 | // le destructeur de l'objet "PINTuple"
|
|---|
| 38 | // Note : "nt" doit être créé par new
|
|---|
| 39 | //--
|
|---|
| 40 |
|
|---|
| 41 | /* --Methode-- */
|
|---|
| 42 | PINTuple::PINTuple(NTupleInterface* nt, bool ad)
|
|---|
| 43 | : PIDrawer()
|
|---|
| 44 | {
|
|---|
| 45 | mNT = nt;
|
|---|
| 46 | mAdDO = ad;
|
|---|
| 47 | SetStats(true);
|
|---|
| 48 | SelectXY(NULL, NULL);
|
|---|
| 49 | SelectWt(NULL, 1);
|
|---|
| 50 | SelectErrBar();
|
|---|
| 51 | SelectLabel(NULL);
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | PINTuple::~PINTuple()
|
|---|
| 55 | {
|
|---|
| 56 | if (mAdDO && mNT) delete mNT;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | //++
|
|---|
| 60 | // Titre Méthodes
|
|---|
| 61 | //--
|
|---|
| 62 | //++
|
|---|
| 63 | // void SelectXY(const char* px, const char* py)
|
|---|
| 64 | // Choix des noms de colonnes X,Y définissant les coordonnées des points.
|
|---|
| 65 | // Ces deux colonnes doivent être spécifiées pour obtenir un tracé.
|
|---|
| 66 | // void SelectErrBar(const char* erbx=NULL, const char* erby=NULL)
|
|---|
| 67 | // Choix des noms de colonnes pour le tracé des barres d'erreur.
|
|---|
| 68 | // void SelectWt(const char* pw=NULL, int nbins=10)
|
|---|
| 69 | // Choix du nom de colonne poids. Dans ce cas, la taille du signe
|
|---|
| 70 | // (marker) sera proportionnel à la valeur de cette colonne pour
|
|---|
| 71 | // chaque point.
|
|---|
| 72 | // void SelectLabel(const char* plabel=NULL)
|
|---|
| 73 | // Choix du nom de colonne correspondant à l'étiquette.
|
|---|
| 74 | //--
|
|---|
| 75 |
|
|---|
| 76 | /* --Methode-- */
|
|---|
| 77 | void PINTuple::SelectXY(const char* px, const char* py)
|
|---|
| 78 | {
|
|---|
| 79 | string name;
|
|---|
| 80 | if (mNT == NULL) xK = yK = -1;
|
|---|
| 81 | if (px == NULL) xK = -1;
|
|---|
| 82 | else { name = px; xK = mNT->ColumnIndex(name); }
|
|---|
| 83 | if (py == NULL) yK = -1;
|
|---|
| 84 | else { name = py; yK = mNT->ColumnIndex(name); }
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | /* --Methode-- */
|
|---|
| 88 | void PINTuple::SelectWt(const char* pw, int nbins)
|
|---|
| 89 | {
|
|---|
| 90 | nWbins = (nbins > 0) ? nbins : 10;
|
|---|
| 91 | if (pw == NULL) wK = -1;
|
|---|
| 92 | else { string name = pw; wK = mNT->ColumnIndex(name); }
|
|---|
| 93 |
|
|---|
| 94 | if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
|
|---|
| 95 | else { wMin = 0.; wMax = 1.; }
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | /* --Methode-- */
|
|---|
| 99 | void PINTuple::SelectLabel(const char* plabel)
|
|---|
| 100 | {
|
|---|
| 101 | if (plabel == NULL) lK = -1;
|
|---|
| 102 | else { string name = plabel; lK = mNT->ColumnIndex(name); }
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | /* --Methode-- */
|
|---|
| 106 | void PINTuple::SelectErrBar(const char* erbx, const char* erby)
|
|---|
| 107 | {
|
|---|
| 108 | string name;
|
|---|
| 109 | if (mNT == NULL) xebK = yebK = -1;
|
|---|
| 110 | if (erbx == NULL) xebK = -1;
|
|---|
| 111 | else { name = erbx; xebK = mNT->ColumnIndex(name); }
|
|---|
| 112 | if (erby == NULL) yebK = -1;
|
|---|
| 113 | else { name = erby; yebK = mNT->ColumnIndex(name); }
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 | /* --Methode-- */
|
|---|
| 118 | void PINTuple::UpdateLimits()
|
|---|
| 119 | {
|
|---|
| 120 | if (!mNT) return;
|
|---|
| 121 | if (mNT->NbLines() <= 0) return;
|
|---|
| 122 | if ( (xK < 0) || (yK < 0) ) return;
|
|---|
| 123 |
|
|---|
| 124 | // Commencer par trouver nos limites
|
|---|
| 125 | double dx, dy;
|
|---|
| 126 | double xmin, xmax, ymin, ymax;
|
|---|
| 127 | xmin = ymin = 9.e19;
|
|---|
| 128 | xmax = ymax = -9.e19;
|
|---|
| 129 | mNT->GetMinMax(xK, xmin, xmax);
|
|---|
| 130 | mNT->GetMinMax(yK, ymin, ymax);
|
|---|
| 131 |
|
|---|
| 132 | dx = 0.02*(xmax-xmin);
|
|---|
| 133 | dy = 0.02*(ymax-ymin);
|
|---|
| 134 |
|
|---|
| 135 | SetLimits(xmin-dx, xmax+dx, ymin-dy, ymax+dy);
|
|---|
| 136 | // SetAxesFlags(kBoxAxes | kExtTicks | kLabels); Ne pas faire - Reza 11/99
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 | /* --Methode-- */
|
|---|
| 141 | void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
|---|
| 142 | {
|
|---|
| 143 | double xp,yp,xer,yer,wp;
|
|---|
| 144 | double xl,yl;
|
|---|
| 145 | int nok;
|
|---|
| 146 |
|
|---|
| 147 | if (!mNT) return;
|
|---|
| 148 | if (axesFlags != kAxesNone) DrawAxes(g);
|
|---|
| 149 | if ( (xK < 0) || (yK < 0) ) return;
|
|---|
| 150 | if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
|
|---|
| 151 |
|
|---|
| 152 | // Pour tracer des markers avec taille fonction de Wt (poids)
|
|---|
| 153 | double dw = (wMax-wMin)/nWbins;
|
|---|
| 154 | if (dw < 1.e-19) dw = 1.e19;
|
|---|
| 155 | int msz,sz;
|
|---|
| 156 |
|
|---|
| 157 | PIMarker mrk;
|
|---|
| 158 | if (wK >= 0) mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_CircleMarker;
|
|---|
| 159 | else mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_DotMarker;
|
|---|
| 160 | msz = mMSz;
|
|---|
| 161 | if (msz < 1) msz = 1;
|
|---|
| 162 | g->SelMarker(msz, mrk);
|
|---|
| 163 |
|
|---|
| 164 | PIGrCoord uxmin, uxmax, uymin, uymax;
|
|---|
| 165 | g->GetGrSpace(uxmin, uxmax, uymin, uymax);
|
|---|
| 166 | double xmin2 = uxmin;
|
|---|
| 167 | double ymin2 = uymin;
|
|---|
| 168 | double xmax2 = uxmax;
|
|---|
| 169 | double ymax2 = uymax;
|
|---|
| 170 |
|
|---|
| 171 | nok = 0;
|
|---|
| 172 | xp = yp = xl = yl = 0;
|
|---|
| 173 | for (int i=0; i<mNT->NbLines(); i++) {
|
|---|
| 174 | xl = xp; yl = yp;
|
|---|
| 175 | xp = mNT->GetCell(i, xK);
|
|---|
| 176 | yp = mNT->GetCell(i, yK);
|
|---|
| 177 | if ( (xp < xmin2) || (xp > xmax2) || (yp < ymin2) || (yp > ymax2) ) continue;
|
|---|
| 178 | nok++;
|
|---|
| 179 | if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
|
|---|
| 180 | if ( (i > 0) && (mLAtt != PI_NotDefLineAtt) ) // On relie les points ...
|
|---|
| 181 | g->DrawLine(xl, yl, xp, yp);
|
|---|
| 182 | if ( xebK >= 0 ) {
|
|---|
| 183 | xer = mNT->GetCell(i, xebK);
|
|---|
| 184 | if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp);
|
|---|
| 185 | }
|
|---|
| 186 | if ( yebK >= 0 ) {
|
|---|
| 187 | yer = mNT->GetCell(i, yebK);
|
|---|
| 188 | if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer);
|
|---|
| 189 | }
|
|---|
| 190 | if (wK >= 0) { // Taille de marker en fonction du poids
|
|---|
| 191 | wp = mNT->GetCell(i, wK);
|
|---|
| 192 | sz = (int)((wp-wMin)/dw);
|
|---|
| 193 | if (sz < 0) sz = 0;
|
|---|
| 194 | if (sz > nWbins) sz = nWbins;
|
|---|
| 195 | sz += msz;
|
|---|
| 196 | if (sz < 2) g->SelMarker(sz, PI_DotMarker);
|
|---|
| 197 | else g->SelMarker(sz, mrk);
|
|---|
| 198 | }
|
|---|
| 199 | // Trace du marker
|
|---|
| 200 | if ((wK >= 0)||(lK < 0)||(mMrk != PI_NotDefMarker)) g->DrawMarker(xp, yp);
|
|---|
| 201 | // Trace eventuel du label
|
|---|
| 202 | if (lK >= 0) g->DrawString(xp, yp, mNT->GetCelltoString(i, lK).c_str());
|
|---|
| 203 |
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | if (stats) { // Trace de stats
|
|---|
| 207 | char label[64];
|
|---|
| 208 | sprintf(label, "Nd= %d/ Ntot= %d", nok, mNT->NbLines());
|
|---|
| 209 | g->SelFontSz((YMax() - YMin())/25, mFAtt);
|
|---|
| 210 | PIGrCoord a,d;
|
|---|
| 211 | double cH = (double)g->GetFontHeight(a,d);
|
|---|
| 212 | double cellHeight = cH * 1.3;
|
|---|
| 213 | double cellWidth = (double)g->CalcStringWidth(label) * 1.1;
|
|---|
| 214 | double xu, yu;
|
|---|
| 215 | xu = g->DeltaUCX(XMax(), - cellWidth);
|
|---|
| 216 | yu = g->DeltaUCY(YMax(), - cellHeight);
|
|---|
| 217 | g->DrawLine(xu, YMax(), xu, yu);
|
|---|
| 218 | g->DrawLine(xu, yu, XMax(), yu);
|
|---|
| 219 | xu = g->DeltaUCX(XMax(), - cellWidth*0.95);
|
|---|
| 220 | yu = g->DeltaUCY(YMax(), - cH*1.15);
|
|---|
| 221 | g->DrawString(xu, yu, label);
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | return;
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | /* --Methode-- */
|
|---|
| 228 | void PINTuple::AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax)
|
|---|
| 229 | {
|
|---|
| 230 | if (!mNT) return;
|
|---|
| 231 | if ( (xK < 0) || (yK < 0) ) return;
|
|---|
| 232 |
|
|---|
| 233 | int ncnt = 0;
|
|---|
| 234 | double xp,yp;
|
|---|
| 235 | char buff[128];
|
|---|
| 236 | sprintf(buff,"PINTuple: NLines= %d NCol= %d \n", mNT->NbLines(), mNT->NbColumns());
|
|---|
| 237 | info += buff;
|
|---|
| 238 | info += mNT->LineHeaderToString();
|
|---|
| 239 | for (int i=0; i<mNT->NbLines(); i++) {
|
|---|
| 240 | xp = mNT->GetCell(i, xK);
|
|---|
| 241 | yp = mNT->GetCell(i, yK);
|
|---|
| 242 | if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
|
|---|
| 243 | ncnt++;
|
|---|
| 244 | if (ncnt > 101) continue;
|
|---|
| 245 | info += mNT->LineToString(i);
|
|---|
| 246 | }
|
|---|
| 247 | if (ncnt >= 101) info += " .... \n";
|
|---|
| 248 | sprintf(buff," %d points inside selected region \n", ncnt);
|
|---|
| 249 | info += buff;
|
|---|
| 250 | // printf("PINTuple::AppendTextInfo()-DBG %g %g %g %g - %d\n", xmin, ymin, xmax, ymax, ncnt);
|
|---|
| 251 | return;
|
|---|
| 252 | }
|
|---|