[537] | 1 | // Peida Interactive - PI R. Ansari 97-99
|
---|
| 2 | // Traceur3D (Drawer) pour NTupleInterface
|
---|
| 3 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
| 4 |
|
---|
[165] | 5 | #include <stdio.h>
|
---|
| 6 | #include "pintup3d.h"
|
---|
| 7 |
|
---|
[2092] | 8 | //#define PERC_GARDE 0.05
|
---|
| 9 |
|
---|
[537] | 10 | //++
|
---|
| 11 | // Class PINTuple3D
|
---|
| 12 | // Lib PIext
|
---|
| 13 | // include pintup3d.h
|
---|
| 14 | //
|
---|
| 15 | // Classe de traceur 3D à partir des données
|
---|
| 16 | // d'un objet implémentant l'interface *NTupleInterface*.
|
---|
| 17 | // Les objets "PINTuple3D" peuvent tracer des signes (markers)
|
---|
| 18 | // éventuellement avec des barres d'erreur et une étiquette
|
---|
| 19 | // pour chaque point. Si un attribut de ligne, autre que
|
---|
| 20 | // "PI_NotDefLineAtt" est spécifié, les points sont connectés
|
---|
| 21 | // par une ligne.
|
---|
| 22 | //--
|
---|
| 23 | //++
|
---|
| 24 | // Links Parents
|
---|
| 25 | // PIDrawer3D
|
---|
| 26 | //--
|
---|
| 27 | //++
|
---|
| 28 | // Links Voir aussi
|
---|
| 29 | // NTupleInterface
|
---|
| 30 | // PINTuple
|
---|
| 31 | //--
|
---|
| 32 |
|
---|
| 33 | //++
|
---|
| 34 | // Titre Constructeur
|
---|
| 35 | //--
|
---|
| 36 | //++
|
---|
| 37 | // PINTuple3D(NTupleInterface* nt, bool ad=false)
|
---|
| 38 | // Constructeur. Si "ad == true", l'objet "nt" est détruit par
|
---|
| 39 | // le destructeur de l'objet "PINTuple".
|
---|
| 40 | // Note : nt doit être créé par new
|
---|
| 41 | //--
|
---|
| 42 |
|
---|
[165] | 43 |
|
---|
| 44 | /* --Methode-- */
|
---|
[326] | 45 | PINTuple3D::PINTuple3D(NTupleInterface* nt, bool ad)
|
---|
[165] | 46 | : PIDrawer3D()
|
---|
| 47 | {
|
---|
| 48 | mNT = nt;
|
---|
| 49 | mAdDO = ad;
|
---|
[2373] | 50 | UseSizeScale(true, 5);
|
---|
| 51 | UseColorScale(true);
|
---|
[165] | 52 | SelectXYZ(NULL, NULL, NULL);
|
---|
[2373] | 53 | SelectWt(NULL);
|
---|
[165] | 54 | SelectErrBar();
|
---|
[486] | 55 | SelectLabel(NULL);
|
---|
[1856] | 56 | SetName("NTup3DDrw");
|
---|
[165] | 57 | }
|
---|
| 58 |
|
---|
| 59 | PINTuple3D::~PINTuple3D()
|
---|
| 60 | {
|
---|
| 61 | if (mAdDO && mNT) delete mNT;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[537] | 64 | //++
|
---|
| 65 | // Titre Méthodes
|
---|
| 66 | //--
|
---|
| 67 | //++
|
---|
| 68 | // void SelectXYZ(const char* px, const char* py, const char* pz)
|
---|
| 69 | // Choix des noms de colonnes X,Y,Z définissant les coordonnées des points.
|
---|
| 70 | // Ces trois colonnes doivent être spécifiées pour obtenir un tracé.
|
---|
| 71 | // void SelectErrBar(const char* erbx=NULL, const char* erby=NULL, const char* erbz=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)
|
---|
| 78 | // Choix du nom de colonne correspondant à l'étiquette.
|
---|
| 79 | //--
|
---|
| 80 |
|
---|
[165] | 81 | /* --Methode-- */
|
---|
| 82 | void PINTuple3D::SelectXYZ(const char* px, const char* py, const char* pz)
|
---|
| 83 | {
|
---|
[326] | 84 | string name;
|
---|
[165] | 85 | if (mNT == NULL) xK = yK = zK = -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 | if (pz == NULL) zK = -1;
|
---|
[326] | 91 | else { name = pz; zK = mNT->ColumnIndex(name); }
|
---|
[165] | 92 | }
|
---|
| 93 |
|
---|
| 94 | /* --Methode-- */
|
---|
[2373] | 95 | void PINTuple3D::SelectWt(const char* pw)
|
---|
[486] | 96 | {
|
---|
| 97 | if (pw == NULL) wK = -1;
|
---|
| 98 | else { string name = pw; wK = mNT->ColumnIndex(name); }
|
---|
| 99 |
|
---|
| 100 | if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
|
---|
| 101 | else { wMin = 0.; wMax = 1.; }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /* --Methode-- */
|
---|
| 105 | void PINTuple3D::SelectLabel(const char* plabel)
|
---|
| 106 | {
|
---|
| 107 | if (plabel == NULL) lK = -1;
|
---|
| 108 | else { string name = plabel; lK = mNT->ColumnIndex(name); }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | /* --Methode-- */
|
---|
[165] | 112 | void PINTuple3D::SelectErrBar(const char* erbx, const char* erby, const char* erbz)
|
---|
| 113 | {
|
---|
[326] | 114 | string name;
|
---|
[165] | 115 | if (mNT == NULL) xebK = yebK = zebK = -1;
|
---|
| 116 | if (erbx == NULL) xebK = -1;
|
---|
[326] | 117 | else { name = erbx; xebK = mNT->ColumnIndex(name); }
|
---|
[165] | 118 | if (erby == NULL) yebK = -1;
|
---|
[326] | 119 | else { name = erby; yebK = mNT->ColumnIndex(name); }
|
---|
[165] | 120 | if (erbz == NULL) zebK = -1;
|
---|
[326] | 121 | else { name = erbz; zebK = mNT->ColumnIndex(name); }
|
---|
[165] | 122 | }
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | /* --Methode-- */
|
---|
| 126 | void PINTuple3D::UpdateLimits()
|
---|
| 127 | {
|
---|
[326] | 128 | if (!mNT) return;
|
---|
| 129 | if (mNT->NbLines() <= 0) return;
|
---|
[165] | 130 | if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
|
---|
| 131 |
|
---|
| 132 | // Commencer par trouver nos limites
|
---|
[326] | 133 | double xmin, xmax, ymin, ymax, zmin, zmax;
|
---|
[165] | 134 | xmin = ymin = 9.e19;
|
---|
| 135 | xmax = ymax = -9.e19;
|
---|
| 136 | zmax = zmax = -9.e19;
|
---|
| 137 | mNT->GetMinMax(xK, xmin, xmax);
|
---|
| 138 | mNT->GetMinMax(yK, ymin, ymax);
|
---|
| 139 | mNT->GetMinMax(zK, zmin, zmax);
|
---|
| 140 |
|
---|
| 141 | // Centre du champ en C = (xmin+xmax)/2., (ymin+ymax)/2 (zmin+zmax)*0.5
|
---|
| 142 | // Distance D = Max(xmax-xmin,ymin-ymax)*2
|
---|
| 143 | // Observateur en O = X+D, Yc+2*D
|
---|
[205] | 144 | double D = xmax-xmin;
|
---|
[165] | 145 | if (D < (ymax-ymin)) D = ymax-ymin;
|
---|
| 146 | D *= 1.4;
|
---|
| 147 |
|
---|
| 148 | Set3DView((xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)/2.,
|
---|
[185] | 149 | (xmin+xmax)/2.+D , (ymin+ymax)/2.-2.5*D , zmin+(zmax-zmin)*0.85, 0.25, 0.25);
|
---|
[171] | 150 |
|
---|
[2165] | 151 | /*
|
---|
[2092] | 152 | x3Min = xmin; // - PERC_GARDE*(xmax-xmin);
|
---|
| 153 | x3Max = xmax; // + PERC_GARDE*(xmax-xmin);
|
---|
| 154 | y3Min = ymin; // - PERC_GARDE*(ymax-ymin);
|
---|
| 155 | y3Max = ymax; // + PERC_GARDE*(ymax-ymin);
|
---|
| 156 | z3Min = zmin; // - PERC_GARDE*(zmax-zmin);
|
---|
| 157 | z3Max = zmax; // + PERC_GARDE*(zmax-zmin);
|
---|
[2165] | 158 | */
|
---|
[171] | 159 |
|
---|
[2165] | 160 | Set3DBox(xmin, xmax, ymin, ymax, zmin, zmax);
|
---|
| 161 |
|
---|
[326] | 162 | // printf("PINTuple3D::UpdateLimits() : %g .. %g %g .. %g %g .. %g (%g) \n", xmin,xmax,ymin,ymax,zmin,zmax,D);
|
---|
[165] | 163 | // printf("PINTuple3D::UpdateLimits() : %g %g %g << %g %g %g \n",
|
---|
| 164 | // (xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)*0.5,
|
---|
| 165 | // (xmin+xmax)/2.+D , (ymin+ymax)/2.+2.*D , zmin+(zmax-zmin)*0.1);
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 | /* --Methode-- */
|
---|
[205] | 170 | void PINTuple3D::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
[165] | 171 | {
|
---|
[486] | 172 | double xp,yp,zp,wp,xer,yer,zer;
|
---|
[326] | 173 | double xl,yl,zl;
|
---|
[165] | 174 | int nok;
|
---|
| 175 |
|
---|
[185] | 176 | // On trace les axes - En attendant de faire mieux - Reza 8/12/98
|
---|
| 177 | if (axesFlags != kAxesNone) DrawAxes(g);
|
---|
| 178 |
|
---|
[165] | 179 | if (!mNT) return;
|
---|
| 180 | if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
|
---|
| 181 |
|
---|
[440] | 182 | #if defined(CC_HAS_RTTI_SUPPORT)
|
---|
[165] | 183 | PIGraphic3D* g3 = dynamic_cast<PIGraphic3D*>(g);
|
---|
| 184 | #else
|
---|
| 185 | PIGraphic3D* g3 = (PIGraphic3D*)(g);
|
---|
| 186 | #endif
|
---|
| 187 |
|
---|
[1905] | 188 | if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt) g3->SelLine(PI_ThinLine);
|
---|
[165] | 189 |
|
---|
[486] | 190 | // Pour tracer des markers avec taille fonction de Wt (poids)
|
---|
| 191 | double dw = (wMax-wMin)/nWbins;
|
---|
[2373] | 192 | if (dw < 1.e-19) dw = 1.e-19;
|
---|
| 193 | // Pour tracer des markers avec couleur en fonction de Wt (poids)
|
---|
| 194 | PIColorMap * cmap = NULL;
|
---|
| 195 | double dwc = 1.;
|
---|
| 196 | double nwc = 1.;
|
---|
| 197 | bool revcmap;
|
---|
| 198 | CMapId mcmapid = GetGraphicAtt().GetColMapId(revcmap);
|
---|
| 199 | if( colorScale && (wK >= 0) && (mcmapid != CMAP_OTHER) ) {
|
---|
| 200 | cmap = new PIColorMap(mcmapid);
|
---|
| 201 | cmap->ReverseColorIndex(revcmap);
|
---|
| 202 | nwc = cmap->NCol();
|
---|
| 203 | dwc = (wMax-wMin)/nwc;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
[486] | 206 | int msz,sz;
|
---|
| 207 |
|
---|
[1905] | 208 | PIMarker mmrk = GetGraphicAtt().GetMarker();
|
---|
[486] | 209 | PIMarker mrk;
|
---|
[1905] | 210 | if (wK >= 0) mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_CircleMarker;
|
---|
| 211 | else mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_DotMarker;
|
---|
| 212 | msz = GetGraphicAtt().GetMarkerSz();
|
---|
[486] | 213 | if (msz < 1) msz = 1;
|
---|
| 214 | g->SelMarker(msz, mrk);
|
---|
| 215 |
|
---|
[165] | 216 | nok = 0;
|
---|
[326] | 217 | xp = yp = zp = xl = yl = zl = 0;
|
---|
| 218 | for (int i=0; i<mNT->NbLines(); i++) {
|
---|
| 219 | xl = xp; yl = yp; zl = zp;
|
---|
| 220 | xp = mNT->GetCell(i, xK);
|
---|
| 221 | yp = mNT->GetCell(i, yK);
|
---|
| 222 | zp = mNT->GetCell(i, zK);
|
---|
[2373] | 223 |
|
---|
| 224 | // Taille - couleur de marker en fonction du poids
|
---|
| 225 | if (wK >= 0) wp = mNT->GetCell(i, wK);
|
---|
| 226 | if (mrkSzScale && (wK >= 0)) { // Changement de taille
|
---|
| 227 | sz = (int)((wp-wMin)/dw);
|
---|
| 228 | if (sz < 0) sz = 0;
|
---|
| 229 | if (sz > nWbins) sz = nWbins;
|
---|
| 230 | sz += msz;
|
---|
| 231 | if (sz < 2) g->SelMarker(sz, PI_DotMarker);
|
---|
| 232 | else g->SelMarker(sz, mrk);
|
---|
| 233 | }
|
---|
| 234 | // Couleur du marker en fonction du poids
|
---|
| 235 | if( colorScale && (wK >= 0) && cmap ) {
|
---|
| 236 | int cid = (int)((wp-wMin)/dwc);
|
---|
| 237 | if (cid < 0) cid = 0;
|
---|
| 238 | if (cid >= nwc) cid = nwc-1;
|
---|
| 239 | g->SelForeground(*cmap, cid);
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[2350] | 242 | if ( (i > 0) && connectPts ) // On relie les points ...
|
---|
[326] | 243 | g3->DrawLine3D(xl, yl, zl, xp, yp, zp);
|
---|
[165] | 244 | nok++;
|
---|
| 245 | if ( xebK >= 0 ) {
|
---|
[326] | 246 | xer = mNT->GetCell(i, xebK);
|
---|
[165] | 247 | g3->DrawLine3D(xp-xer, yp, zp, xp+xer, yp, zp);
|
---|
| 248 | }
|
---|
| 249 | if ( yebK >= 0 ) {
|
---|
[326] | 250 | yer = mNT->GetCell(i, yebK);
|
---|
[165] | 251 | g3->DrawLine3D(xp, yp-yer, zp, xp, yp+yer, zp);
|
---|
| 252 | }
|
---|
| 253 | if ( zebK >= 0 ) {
|
---|
[326] | 254 | zer = mNT->GetCell(i, zebK);
|
---|
[165] | 255 | g3->DrawLine3D(xp, yp, zp-zer, xp, yp, zp+zer);
|
---|
| 256 | }
|
---|
[486] | 257 | // Trace du marker
|
---|
[1905] | 258 | if ((wK >= 0)||(lK < 0)||(mmrk != PI_NotDefMarker)) g3->DrawMarker3D(xp, yp, zp);
|
---|
[486] | 259 | // Trace eventuel du label
|
---|
| 260 | if (lK >= 0) g3->DrawString3D(xp, yp, zp, mNT->GetCelltoString(i, lK).c_str());
|
---|
[165] | 261 | }
|
---|
| 262 |
|
---|
| 263 | return;
|
---|
| 264 | }
|
---|
| 265 |
|
---|
[2350] | 266 | /* La methode DecodeOptionString permet de decoder un ensemble d'options
|
---|
| 267 | et de parametre d'affichage specifie sous forme d'un vecteur de string.
|
---|
| 268 | Si rmdecopt == true, les options decodees sont supprimees du vecteur
|
---|
| 269 | de string fourni en entree - ce qui permet l'enchainement eventuel
|
---|
| 270 | de plusieurs decodages de string.
|
---|
| 271 | Les options peuvent etre sous forme de flag : "stat" "nostat"
|
---|
| 272 | ou plus complexes, par exemple "dynamic=-3,3"
|
---|
| 273 | Rc: La methode renvoie le nombre d'options decodees
|
---|
| 274 | */
|
---|
| 275 |
|
---|
| 276 | /* --Methode-- */
|
---|
| 277 | int PINTuple3D::DecodeOptionString(vector<string> & opt, bool rmdecopt)
|
---|
| 278 | {
|
---|
| 279 | int optsz1 = opt.size();
|
---|
| 280 | if(optsz1<1) return(0);
|
---|
| 281 | // On appelle d'abord le decodage de la classe PIDrawer de laquelle
|
---|
| 282 | // on herite. (Pas obligatoire) on decode donc ici les attributs de
|
---|
| 283 | // couleur, fontes ...
|
---|
| 284 | int ndec1 = PIDrawer::DecodeOptionString(opt, rmdecopt);
|
---|
| 285 | if(optsz1-ndec1<1) return(ndec1); // si tout a ete decode
|
---|
| 286 |
|
---|
| 287 | vector<string> udopt; // On gardera ici les options non decodees
|
---|
| 288 | unsigned int k = 0;
|
---|
| 289 | int ndec = opt.size();
|
---|
| 290 | for( k=0; k<opt.size(); k++ ) {
|
---|
| 291 | string opts = opt[k];
|
---|
| 292 | // if(opts=="sta" || opts=="stat" || opts=="stats") SetStats(true);
|
---|
| 293 | // else if( opts=="nsta" || opts=="nstat"
|
---|
| 294 | // || opts=="nostat" || opts=="nostats") SetStats(false);
|
---|
| 295 | if (opts == "connectpoints") ConnectPoints(true);
|
---|
| 296 | else if (opts == "noconnectpoints") ConnectPoints(false);
|
---|
[2373] | 297 | else if (opts == "colorscale") UseColorScale(true);
|
---|
| 298 | else if (opts == "nocolorscale") UseColorScale(false);
|
---|
| 299 | else if (opts == "sizescale") UseSizeScale(true);
|
---|
| 300 | else if (opts == "nosizescale") UseSizeScale(false);
|
---|
| 301 | else if (opts.substr(0,10) == "sizescale=") {
|
---|
| 302 | int nbn = atoi(opts.substr(10).c_str());
|
---|
| 303 | UseSizeScale(true, nbn);
|
---|
| 304 | }
|
---|
[2350] | 305 | else {
|
---|
| 306 | // Si option non decode
|
---|
| 307 | ndec--;
|
---|
| 308 | // S'il faut supprimer les options decodees
|
---|
| 309 | if (rmdecopt) udopt.push_back(opts);
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
| 312 | // S'il faut supprimer les options decodees, on remplace l'argument opt
|
---|
| 313 | // par le vecteur des options non decodees.
|
---|
| 314 | if (rmdecopt) opt = udopt;
|
---|
| 315 | return(ndec+ndec1);
|
---|
| 316 | }
|
---|
| 317 |
|
---|
| 318 | /* La methode GetOptionsHelpInfo(string& info) renvoie une chaine
|
---|
| 319 | avec la description des options comprises par ce drawer
|
---|
| 320 | Note: Il est preferable de ne pas initialiser la chaine
|
---|
| 321 | string info au depart, afin de permettre de mettre bout a
|
---|
| 322 | bout les aides de differents Drawer */
|
---|
| 323 |
|
---|
| 324 | /* --Methode-- */
|
---|
| 325 | void PINTuple3D::GetOptionsHelpInfo(string& info)
|
---|
| 326 | {
|
---|
| 327 | // On recupere d'abord la chaine info de la classe de base
|
---|
| 328 | PIDrawer::GetOptionsHelpInfo(info);
|
---|
| 329 | info += " ---- PINTuple3D options help info : \n" ;
|
---|
| 330 | info += " connectpoints: The points are connected by a line \n";
|
---|
| 331 | info += " noconnectpoints (this is the default) \n";
|
---|
[2373] | 332 | info += " colorscale/nocolorscale (Use color scale for weight) \n";
|
---|
| 333 | info += " sizescale/sizescale=nbins/nosizescale (Use marker size for weight) \n";
|
---|
[2350] | 334 | info += " and usual color/line/marker/... attribute decoding \n";
|
---|
| 335 | return;
|
---|
| 336 | }
|
---|
| 337 |
|
---|