[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;
|
---|
[2545] | 50 | aScxy = aScz = true;
|
---|
[2373] | 51 | UseSizeScale(true, 5);
|
---|
| 52 | UseColorScale(true);
|
---|
[2400] | 53 | ConnectPoints(false);
|
---|
[165] | 54 | SelectXYZ(NULL, NULL, NULL);
|
---|
[2373] | 55 | SelectWt(NULL);
|
---|
[165] | 56 | SelectErrBar();
|
---|
[486] | 57 | SelectLabel(NULL);
|
---|
[1856] | 58 | SetName("NTup3DDrw");
|
---|
[165] | 59 | }
|
---|
| 60 |
|
---|
| 61 | PINTuple3D::~PINTuple3D()
|
---|
| 62 | {
|
---|
| 63 | if (mAdDO && mNT) delete mNT;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[537] | 66 | //++
|
---|
| 67 | // Titre Méthodes
|
---|
| 68 | //--
|
---|
| 69 | //++
|
---|
| 70 | // void SelectXYZ(const char* px, const char* py, const char* pz)
|
---|
| 71 | // Choix des noms de colonnes X,Y,Z définissant les coordonnées des points.
|
---|
| 72 | // Ces trois colonnes doivent être spécifiées pour obtenir un tracé.
|
---|
| 73 | // void SelectErrBar(const char* erbx=NULL, const char* erby=NULL, const char* erbz=NULL)
|
---|
| 74 | // Choix des noms de colonnes pour le tracé des barres d'erreur.
|
---|
| 75 | // void SelectWt(const char* pw=NULL, int nbins=10)
|
---|
| 76 | // Choix du nom de colonne poids. Dans ce cas, la taille du signe
|
---|
| 77 | // (marker) sera proportionnel à la valeur de cette colonne pour
|
---|
| 78 | // chaque point.
|
---|
| 79 | // void SelectLabel(const char* plabel)
|
---|
| 80 | // Choix du nom de colonne correspondant à l'étiquette.
|
---|
| 81 | //--
|
---|
| 82 |
|
---|
[165] | 83 | /* --Methode-- */
|
---|
| 84 | void PINTuple3D::SelectXYZ(const char* px, const char* py, const char* pz)
|
---|
| 85 | {
|
---|
[326] | 86 | string name;
|
---|
[165] | 87 | if (mNT == NULL) xK = yK = zK = -1;
|
---|
| 88 | if (px == NULL) xK = -1;
|
---|
[326] | 89 | else { name = px; xK = mNT->ColumnIndex(name); }
|
---|
[165] | 90 | if (py == NULL) yK = -1;
|
---|
[326] | 91 | else { name = py; yK = mNT->ColumnIndex(name); }
|
---|
[165] | 92 | if (pz == NULL) zK = -1;
|
---|
[326] | 93 | else { name = pz; zK = mNT->ColumnIndex(name); }
|
---|
[165] | 94 | }
|
---|
| 95 |
|
---|
| 96 | /* --Methode-- */
|
---|
[2373] | 97 | void PINTuple3D::SelectWt(const char* pw)
|
---|
[486] | 98 | {
|
---|
| 99 | if (pw == NULL) wK = -1;
|
---|
| 100 | else { string name = pw; wK = mNT->ColumnIndex(name); }
|
---|
| 101 |
|
---|
| 102 | if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
|
---|
| 103 | else { wMin = 0.; wMax = 1.; }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | /* --Methode-- */
|
---|
| 107 | void PINTuple3D::SelectLabel(const char* plabel)
|
---|
| 108 | {
|
---|
| 109 | if (plabel == NULL) lK = -1;
|
---|
| 110 | else { string name = plabel; lK = mNT->ColumnIndex(name); }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | /* --Methode-- */
|
---|
[165] | 114 | void PINTuple3D::SelectErrBar(const char* erbx, const char* erby, const char* erbz)
|
---|
| 115 | {
|
---|
[326] | 116 | string name;
|
---|
[165] | 117 | if (mNT == NULL) xebK = yebK = zebK = -1;
|
---|
| 118 | if (erbx == NULL) xebK = -1;
|
---|
[326] | 119 | else { name = erbx; xebK = mNT->ColumnIndex(name); }
|
---|
[165] | 120 | if (erby == NULL) yebK = -1;
|
---|
[326] | 121 | else { name = erby; yebK = mNT->ColumnIndex(name); }
|
---|
[165] | 122 | if (erbz == NULL) zebK = -1;
|
---|
[326] | 123 | else { name = erbz; zebK = mNT->ColumnIndex(name); }
|
---|
[165] | 124 | }
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | /* --Methode-- */
|
---|
| 128 | void PINTuple3D::UpdateLimits()
|
---|
| 129 | {
|
---|
[326] | 130 | if (!mNT) return;
|
---|
| 131 | if (mNT->NbLines() <= 0) return;
|
---|
[165] | 132 | if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
|
---|
| 133 |
|
---|
| 134 | // Commencer par trouver nos limites
|
---|
[326] | 135 | double xmin, xmax, ymin, ymax, zmin, zmax;
|
---|
[165] | 136 | xmin = ymin = 9.e19;
|
---|
| 137 | xmax = ymax = -9.e19;
|
---|
| 138 | zmax = zmax = -9.e19;
|
---|
| 139 | mNT->GetMinMax(xK, xmin, xmax);
|
---|
| 140 | mNT->GetMinMax(yK, ymin, ymax);
|
---|
| 141 | mNT->GetMinMax(zK, zmin, zmax);
|
---|
| 142 |
|
---|
[2400] | 143 | ComputeScaleFactor(xmin, xmax, ymin, ymax, zmin, zmax,
|
---|
[2545] | 144 | aScxy, aScz, mScy, mScz);
|
---|
[2400] | 145 |
|
---|
| 146 | // cout << " DEBUG - NTup3D X:" << XMin3() << "-" << XMax3() " s=" << mScx
|
---|
| 147 | // << " Y:" YMin3() << "-" << YMax3() << "
|
---|
| 148 | xmin *= mScx; xmax *= mScx;
|
---|
| 149 | ymin *= mScy; ymax *= mScy;
|
---|
| 150 | zmin *= mScz; zmax *= mScz;
|
---|
[165] | 151 | // Centre du champ en C = (xmin+xmax)/2., (ymin+ymax)/2 (zmin+zmax)*0.5
|
---|
| 152 | // Distance D = Max(xmax-xmin,ymin-ymax)*2
|
---|
| 153 | // Observateur en O = X+D, Yc+2*D
|
---|
[205] | 154 | double D = xmax-xmin;
|
---|
[165] | 155 | if (D < (ymax-ymin)) D = ymax-ymin;
|
---|
| 156 | D *= 1.4;
|
---|
| 157 |
|
---|
| 158 | Set3DView((xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)/2.,
|
---|
[185] | 159 | (xmin+xmax)/2.+D , (ymin+ymax)/2.-2.5*D , zmin+(zmax-zmin)*0.85, 0.25, 0.25);
|
---|
[171] | 160 |
|
---|
[2400] | 161 | Set3DBox(xmin, xmax, ymin, ymax, zmin, zmax, mScx, mScy, mScz);
|
---|
| 162 |
|
---|
[2165] | 163 | /*
|
---|
[2092] | 164 | x3Min = xmin; // - PERC_GARDE*(xmax-xmin);
|
---|
| 165 | x3Max = xmax; // + PERC_GARDE*(xmax-xmin);
|
---|
| 166 | y3Min = ymin; // - PERC_GARDE*(ymax-ymin);
|
---|
| 167 | y3Max = ymax; // + PERC_GARDE*(ymax-ymin);
|
---|
| 168 | z3Min = zmin; // - PERC_GARDE*(zmax-zmin);
|
---|
| 169 | z3Max = zmax; // + PERC_GARDE*(zmax-zmin);
|
---|
[2165] | 170 | */
|
---|
[171] | 171 |
|
---|
[2165] | 172 |
|
---|
[326] | 173 | // printf("PINTuple3D::UpdateLimits() : %g .. %g %g .. %g %g .. %g (%g) \n", xmin,xmax,ymin,ymax,zmin,zmax,D);
|
---|
[165] | 174 | // printf("PINTuple3D::UpdateLimits() : %g %g %g << %g %g %g \n",
|
---|
| 175 | // (xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)*0.5,
|
---|
| 176 | // (xmin+xmax)/2.+D , (ymin+ymax)/2.+2.*D , zmin+(zmax-zmin)*0.1);
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | /* --Methode-- */
|
---|
[205] | 181 | void PINTuple3D::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
[165] | 182 | {
|
---|
[486] | 183 | double xp,yp,zp,wp,xer,yer,zer;
|
---|
[326] | 184 | double xl,yl,zl;
|
---|
[165] | 185 | int nok;
|
---|
| 186 |
|
---|
[185] | 187 | // On trace les axes - En attendant de faire mieux - Reza 8/12/98
|
---|
| 188 | if (axesFlags != kAxesNone) DrawAxes(g);
|
---|
| 189 |
|
---|
[165] | 190 | if (!mNT) return;
|
---|
| 191 | if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
|
---|
| 192 |
|
---|
[440] | 193 | #if defined(CC_HAS_RTTI_SUPPORT)
|
---|
[165] | 194 | PIGraphic3D* g3 = dynamic_cast<PIGraphic3D*>(g);
|
---|
| 195 | #else
|
---|
| 196 | PIGraphic3D* g3 = (PIGraphic3D*)(g);
|
---|
| 197 | #endif
|
---|
| 198 |
|
---|
[1905] | 199 | if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt) g3->SelLine(PI_ThinLine);
|
---|
[165] | 200 |
|
---|
[486] | 201 | // Pour tracer des markers avec taille fonction de Wt (poids)
|
---|
| 202 | double dw = (wMax-wMin)/nWbins;
|
---|
[2373] | 203 | if (dw < 1.e-19) dw = 1.e-19;
|
---|
| 204 | // Pour tracer des markers avec couleur en fonction de Wt (poids)
|
---|
| 205 | PIColorMap * cmap = NULL;
|
---|
| 206 | double dwc = 1.;
|
---|
| 207 | double nwc = 1.;
|
---|
| 208 | bool revcmap;
|
---|
| 209 | CMapId mcmapid = GetGraphicAtt().GetColMapId(revcmap);
|
---|
| 210 | if( colorScale && (wK >= 0) && (mcmapid != CMAP_OTHER) ) {
|
---|
| 211 | cmap = new PIColorMap(mcmapid);
|
---|
| 212 | cmap->ReverseColorIndex(revcmap);
|
---|
| 213 | nwc = cmap->NCol();
|
---|
| 214 | dwc = (wMax-wMin)/nwc;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
[486] | 217 | int msz,sz;
|
---|
| 218 |
|
---|
[1905] | 219 | PIMarker mmrk = GetGraphicAtt().GetMarker();
|
---|
[486] | 220 | PIMarker mrk;
|
---|
[1905] | 221 | if (wK >= 0) mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_CircleMarker;
|
---|
| 222 | else mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_DotMarker;
|
---|
| 223 | msz = GetGraphicAtt().GetMarkerSz();
|
---|
[486] | 224 | if (msz < 1) msz = 1;
|
---|
| 225 | g->SelMarker(msz, mrk);
|
---|
| 226 |
|
---|
[165] | 227 | nok = 0;
|
---|
[326] | 228 | xp = yp = zp = xl = yl = zl = 0;
|
---|
| 229 | for (int i=0; i<mNT->NbLines(); i++) {
|
---|
| 230 | xl = xp; yl = yp; zl = zp;
|
---|
| 231 | xp = mNT->GetCell(i, xK);
|
---|
| 232 | yp = mNT->GetCell(i, yK);
|
---|
| 233 | zp = mNT->GetCell(i, zK);
|
---|
[2373] | 234 |
|
---|
| 235 | // Taille - couleur de marker en fonction du poids
|
---|
| 236 | if (wK >= 0) wp = mNT->GetCell(i, wK);
|
---|
| 237 | if (mrkSzScale && (wK >= 0)) { // Changement de taille
|
---|
| 238 | sz = (int)((wp-wMin)/dw);
|
---|
| 239 | if (sz < 0) sz = 0;
|
---|
| 240 | if (sz > nWbins) sz = nWbins;
|
---|
| 241 | sz += msz;
|
---|
| 242 | if (sz < 2) g->SelMarker(sz, PI_DotMarker);
|
---|
| 243 | else g->SelMarker(sz, mrk);
|
---|
| 244 | }
|
---|
| 245 | // Couleur du marker en fonction du poids
|
---|
| 246 | if( colorScale && (wK >= 0) && cmap ) {
|
---|
| 247 | int cid = (int)((wp-wMin)/dwc);
|
---|
| 248 | if (cid < 0) cid = 0;
|
---|
| 249 | if (cid >= nwc) cid = nwc-1;
|
---|
| 250 | g->SelForeground(*cmap, cid);
|
---|
| 251 | }
|
---|
| 252 |
|
---|
[2350] | 253 | if ( (i > 0) && connectPts ) // On relie les points ...
|
---|
[2547] | 254 | g3->DrawLine3D(ScaleX(xl), ScaleY(yl), ScaleZ(zl), ScaleX(xp), ScaleY(yp), ScaleZ(zp));
|
---|
[165] | 255 | nok++;
|
---|
| 256 | if ( xebK >= 0 ) {
|
---|
[326] | 257 | xer = mNT->GetCell(i, xebK);
|
---|
[2547] | 258 | g3->DrawLine3D(ScaleX(xp-xer), ScaleY(yp), ScaleZ(zp), ScaleX(xp+xer), ScaleY(yp), ScaleZ(zp) );
|
---|
[165] | 259 | }
|
---|
| 260 | if ( yebK >= 0 ) {
|
---|
[326] | 261 | yer = mNT->GetCell(i, yebK);
|
---|
[2547] | 262 | g3->DrawLine3D(ScaleX(xp), ScaleY(yp-yer), ScaleZ(zp), ScaleX(xp), ScaleY(yp+yer), ScaleZ(zp) );
|
---|
[165] | 263 | }
|
---|
| 264 | if ( zebK >= 0 ) {
|
---|
[326] | 265 | zer = mNT->GetCell(i, zebK);
|
---|
[2547] | 266 | g3->DrawLine3D(ScaleX(xp), ScaleY(yp), ScaleZ(zp-zer), ScaleX(xp), ScaleY(yp), ScaleZ(zp+zer));
|
---|
[165] | 267 | }
|
---|
[486] | 268 | // Trace du marker
|
---|
[2400] | 269 | if ((wK >= 0)||(lK < 0)||(mmrk != PI_NotDefMarker))
|
---|
[2547] | 270 | g3->DrawMarker3D(ScaleX(xp), ScaleY(yp), ScaleZ(zp));
|
---|
[486] | 271 | // Trace eventuel du label
|
---|
[2547] | 272 | if (lK >= 0) g3->DrawString3D(ScaleX(xp), ScaleY(yp), ScaleZ(zp),
|
---|
[2400] | 273 | mNT->GetCelltoString(i, lK).c_str());
|
---|
[165] | 274 | }
|
---|
| 275 |
|
---|
| 276 | return;
|
---|
| 277 | }
|
---|
| 278 |
|
---|
[2350] | 279 | /* La methode DecodeOptionString permet de decoder un ensemble d'options
|
---|
| 280 | et de parametre d'affichage specifie sous forme d'un vecteur de string.
|
---|
| 281 | Si rmdecopt == true, les options decodees sont supprimees du vecteur
|
---|
| 282 | de string fourni en entree - ce qui permet l'enchainement eventuel
|
---|
| 283 | de plusieurs decodages de string.
|
---|
[2524] | 284 | Les options peuvent etre sous forme de flag : "connectpoints" "noconnectpoints"
|
---|
[2350] | 285 | ou plus complexes, par exemple "dynamic=-3,3"
|
---|
| 286 | Rc: La methode renvoie le nombre d'options decodees
|
---|
| 287 | */
|
---|
| 288 |
|
---|
| 289 | /* --Methode-- */
|
---|
| 290 | int PINTuple3D::DecodeOptionString(vector<string> & opt, bool rmdecopt)
|
---|
| 291 | {
|
---|
| 292 | int optsz1 = opt.size();
|
---|
[2524] | 293 | if(optsz1<1) return(0);
|
---|
[2350] | 294 | // On appelle d'abord le decodage de la classe PIDrawer de laquelle
|
---|
| 295 | // on herite. (Pas obligatoire) on decode donc ici les attributs de
|
---|
| 296 | // couleur, fontes ...
|
---|
[2547] | 297 | int ndec1 = PIDrawer3D::DecodeOptionString(opt, rmdecopt);
|
---|
[2350] | 298 | if(optsz1-ndec1<1) return(ndec1); // si tout a ete decode
|
---|
| 299 |
|
---|
| 300 | vector<string> udopt; // On gardera ici les options non decodees
|
---|
| 301 | unsigned int k = 0;
|
---|
| 302 | int ndec = opt.size();
|
---|
| 303 | for( k=0; k<opt.size(); k++ ) {
|
---|
| 304 | string opts = opt[k];
|
---|
| 305 | if (opts == "connectpoints") ConnectPoints(true);
|
---|
| 306 | else if (opts == "noconnectpoints") ConnectPoints(false);
|
---|
[2373] | 307 | else if (opts == "colorscale") UseColorScale(true);
|
---|
| 308 | else if (opts == "nocolorscale") UseColorScale(false);
|
---|
| 309 | else if (opts == "sizescale") UseSizeScale(true);
|
---|
| 310 | else if (opts == "nosizescale") UseSizeScale(false);
|
---|
| 311 | else if (opts.substr(0,10) == "sizescale=") {
|
---|
| 312 | int nbn = atoi(opts.substr(10).c_str());
|
---|
| 313 | UseSizeScale(true, nbn);
|
---|
| 314 | }
|
---|
[2350] | 315 | else {
|
---|
| 316 | // Si option non decode
|
---|
| 317 | ndec--;
|
---|
| 318 | // S'il faut supprimer les options decodees
|
---|
| 319 | if (rmdecopt) udopt.push_back(opts);
|
---|
| 320 | }
|
---|
| 321 | }
|
---|
| 322 | // S'il faut supprimer les options decodees, on remplace l'argument opt
|
---|
| 323 | // par le vecteur des options non decodees.
|
---|
| 324 | if (rmdecopt) opt = udopt;
|
---|
| 325 | return(ndec+ndec1);
|
---|
| 326 | }
|
---|
| 327 |
|
---|
[2524] | 328 | int PINTuple3D::OptionToString(vector<string> & opt) const
|
---|
| 329 | {
|
---|
[2547] | 330 | PIDrawer3D::OptionToString(opt);
|
---|
[2524] | 331 |
|
---|
| 332 | if(connectPts) opt.push_back("connectpoints");
|
---|
| 333 | else opt.push_back("noconnectpoints");
|
---|
| 334 |
|
---|
| 335 | if(colorScale) opt.push_back("colorscale");
|
---|
| 336 | else opt.push_back("nocolorscale");
|
---|
| 337 |
|
---|
| 338 | if(mrkSzScale) {
|
---|
| 339 | char str[256];
|
---|
| 340 | if(nWbins>0) {sprintf(str,"sizescale=%d",nWbins); opt.push_back(str);}
|
---|
| 341 | else opt.push_back("sizescale");
|
---|
| 342 | } else opt.push_back("nosizescale");
|
---|
| 343 |
|
---|
| 344 | return 1;
|
---|
| 345 | }
|
---|
| 346 |
|
---|
[2350] | 347 | /* La methode GetOptionsHelpInfo(string& info) renvoie une chaine
|
---|
| 348 | avec la description des options comprises par ce drawer
|
---|
| 349 | Note: Il est preferable de ne pas initialiser la chaine
|
---|
| 350 | string info au depart, afin de permettre de mettre bout a
|
---|
| 351 | bout les aides de differents Drawer */
|
---|
| 352 |
|
---|
| 353 | /* --Methode-- */
|
---|
| 354 | void PINTuple3D::GetOptionsHelpInfo(string& info)
|
---|
| 355 | {
|
---|
| 356 | info += " ---- PINTuple3D options help info : \n" ;
|
---|
| 357 | info += " connectpoints: The points are connected by a line \n";
|
---|
| 358 | info += " noconnectpoints (this is the default) \n";
|
---|
[2373] | 359 | info += " colorscale/nocolorscale (Use color scale for weight) \n";
|
---|
| 360 | info += " sizescale/sizescale=nbins/nosizescale (Use marker size for weight) \n";
|
---|
[2400] | 361 | // On recupere ensuite la chaine info de la classe de base
|
---|
[2547] | 362 | PIDrawer3D::GetOptionsHelpInfo(info);
|
---|
[2350] | 363 | return;
|
---|
| 364 | }
|
---|
| 365 |
|
---|