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