| [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 | 
 | 
|---|
| [537] | 8 | //++
 | 
|---|
 | 9 | // Class        PINTuple3D
 | 
|---|
 | 10 | // Lib          PIext
 | 
|---|
 | 11 | // include      pintup3d.h
 | 
|---|
 | 12 | //
 | 
|---|
 | 13 | //      Classe de traceur 3D à partir des données
 | 
|---|
 | 14 | //      d'un objet implémentant l'interface *NTupleInterface*.
 | 
|---|
 | 15 | //      Les objets "PINTuple3D" 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 | // PIDrawer3D
 | 
|---|
 | 24 | //--
 | 
|---|
 | 25 | //++
 | 
|---|
 | 26 | // Links        Voir aussi
 | 
|---|
 | 27 | // NTupleInterface
 | 
|---|
 | 28 | // PINTuple
 | 
|---|
 | 29 | //--
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | //++
 | 
|---|
 | 32 | // Titre        Constructeur
 | 
|---|
 | 33 | //--
 | 
|---|
 | 34 | //++
 | 
|---|
 | 35 | // PINTuple3D(NTupleInterface* nt, bool ad=false)
 | 
|---|
 | 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 | 
 | 
|---|
| [165] | 41 |  
 | 
|---|
 | 42 | /* --Methode-- */
 | 
|---|
| [326] | 43 | PINTuple3D::PINTuple3D(NTupleInterface* nt, bool ad)
 | 
|---|
| [165] | 44 | : PIDrawer3D()
 | 
|---|
 | 45 | {
 | 
|---|
 | 46 |   mNT = nt;
 | 
|---|
 | 47 |   mAdDO = ad; 
 | 
|---|
 | 48 |   SelectXYZ(NULL, NULL, NULL);
 | 
|---|
| [486] | 49 |   SelectWt(NULL, 1);
 | 
|---|
| [165] | 50 |   SelectErrBar();
 | 
|---|
| [486] | 51 |   SelectLabel(NULL);
 | 
|---|
| [1856] | 52 |   SetName("NTup3DDrw");
 | 
|---|
| [165] | 53 | }
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 | PINTuple3D::~PINTuple3D()
 | 
|---|
 | 56 | {
 | 
|---|
 | 57 |   if (mAdDO && mNT)  delete mNT;
 | 
|---|
 | 58 | }
 | 
|---|
 | 59 | 
 | 
|---|
| [537] | 60 | //++
 | 
|---|
 | 61 | // Titre        Méthodes
 | 
|---|
 | 62 | //--
 | 
|---|
 | 63 | //++
 | 
|---|
 | 64 | // void  SelectXYZ(const char* px, const char* py, const char* pz)
 | 
|---|
 | 65 | //      Choix des noms de colonnes X,Y,Z définissant les coordonnées des points. 
 | 
|---|
 | 66 | //      Ces trois colonnes doivent être spécifiées pour obtenir un tracé.
 | 
|---|
 | 67 | // void  SelectErrBar(const char* erbx=NULL, const char* erby=NULL, const char* erbz=NULL)
 | 
|---|
 | 68 | //      Choix des noms de colonnes pour le tracé des barres d'erreur.
 | 
|---|
 | 69 | // void  SelectWt(const char* pw=NULL, int nbins=10)
 | 
|---|
 | 70 | //      Choix du nom de colonne poids. Dans ce cas, la taille du signe
 | 
|---|
 | 71 | //      (marker) sera proportionnel à la valeur de cette colonne pour 
 | 
|---|
 | 72 | //      chaque point.
 | 
|---|
 | 73 | // void  SelectLabel(const char* plabel)
 | 
|---|
 | 74 | //      Choix du nom de colonne correspondant à l'étiquette.
 | 
|---|
 | 75 | //--
 | 
|---|
 | 76 | 
 | 
|---|
| [165] | 77 | /* --Methode-- */
 | 
|---|
 | 78 | void  PINTuple3D::SelectXYZ(const char* px, const char* py, const char* pz)
 | 
|---|
 | 79 | {
 | 
|---|
| [326] | 80 | string name;
 | 
|---|
| [165] | 81 | if (mNT == NULL)  xK = yK = zK = -1;
 | 
|---|
 | 82 | if (px == NULL) xK = -1;
 | 
|---|
| [326] | 83 | else { name = px; xK = mNT->ColumnIndex(name); }
 | 
|---|
| [165] | 84 | if (py == NULL) yK = -1;
 | 
|---|
| [326] | 85 | else { name = py; yK = mNT->ColumnIndex(name); }
 | 
|---|
| [165] | 86 | if (pz == NULL) zK = -1;
 | 
|---|
| [326] | 87 | else { name = pz; zK = mNT->ColumnIndex(name); }
 | 
|---|
| [165] | 88 | }
 | 
|---|
 | 89 | 
 | 
|---|
 | 90 | /* --Methode-- */
 | 
|---|
| [486] | 91 | void  PINTuple3D::SelectWt(const char* pw, int nbins)
 | 
|---|
 | 92 | {
 | 
|---|
 | 93 | nWbins = (nbins > 0) ? nbins : 10;
 | 
|---|
 | 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-- */
 | 
|---|
 | 102 | void  PINTuple3D::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  PINTuple3D::SelectErrBar(const char* erbx, const char* erby, const char* erbz)
 | 
|---|
 | 110 | {
 | 
|---|
| [326] | 111 | string name;
 | 
|---|
| [165] | 112 | if (mNT == NULL)  xebK = yebK = zebK = -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 | if (erbz == NULL) zebK = -1;
 | 
|---|
| [326] | 118 | else { name = erbz;  zebK = mNT->ColumnIndex(name); }
 | 
|---|
| [165] | 119 | }
 | 
|---|
 | 120 | 
 | 
|---|
 | 121 | 
 | 
|---|
 | 122 | /* --Methode-- */
 | 
|---|
 | 123 | void PINTuple3D::UpdateLimits()
 | 
|---|
 | 124 | {
 | 
|---|
| [326] | 125 |   if (!mNT) return; 
 | 
|---|
 | 126 |   if (mNT->NbLines() <= 0)  return;
 | 
|---|
| [165] | 127 |   if ( (xK < 0) || (yK < 0)  || (zK < 0) )   return;
 | 
|---|
 | 128 | 
 | 
|---|
 | 129 |   // Commencer par trouver nos limites
 | 
|---|
| [326] | 130 |   double xmin, xmax, ymin, ymax, zmin, zmax;
 | 
|---|
| [165] | 131 |   xmin = ymin = 9.e19;
 | 
|---|
 | 132 |   xmax = ymax = -9.e19;
 | 
|---|
 | 133 |   zmax = zmax = -9.e19;
 | 
|---|
 | 134 |   mNT->GetMinMax(xK, xmin, xmax);
 | 
|---|
 | 135 |   mNT->GetMinMax(yK, ymin, ymax);
 | 
|---|
 | 136 |   mNT->GetMinMax(zK, zmin, zmax);
 | 
|---|
 | 137 | 
 | 
|---|
 | 138 | // Centre du champ en C = (xmin+xmax)/2., (ymin+ymax)/2  (zmin+zmax)*0.5
 | 
|---|
 | 139 | // Distance D = Max(xmax-xmin,ymin-ymax)*2
 | 
|---|
 | 140 | // Observateur en O = X+D, Yc+2*D 
 | 
|---|
| [205] | 141 |   double D = xmax-xmin;
 | 
|---|
| [165] | 142 |   if (D < (ymax-ymin))  D = ymax-ymin;
 | 
|---|
 | 143 |   D *= 1.4;
 | 
|---|
 | 144 |   
 | 
|---|
 | 145 |   Set3DView((xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)/2., 
 | 
|---|
| [185] | 146 |             (xmin+xmax)/2.+D , (ymin+ymax)/2.-2.5*D , zmin+(zmax-zmin)*0.85, 0.25, 0.25);  
 | 
|---|
| [171] | 147 | 
 | 
|---|
| [185] | 148 |   x3Min = xmin;  // - 0.05*(xmax-xmin);
 | 
|---|
 | 149 |   x3Max = xmax;  // + 0.05*(xmax-xmin);
 | 
|---|
 | 150 |   y3Min = ymin;  // - 0.05*(ymax-ymin);
 | 
|---|
 | 151 |   y3Max = ymax;  // + 0.05*(ymax-ymin);
 | 
|---|
 | 152 |   z3Min = zmin;  // - 0.05*(zmax-zmin);
 | 
|---|
 | 153 |   z3Max = zmax;  // + 0.05*(zmax-zmin);
 | 
|---|
| [171] | 154 | 
 | 
|---|
| [326] | 155 | //  printf("PINTuple3D::UpdateLimits() : %g .. %g  %g .. %g  %g .. %g (%g) \n", xmin,xmax,ymin,ymax,zmin,zmax,D);
 | 
|---|
| [165] | 156 | //  printf("PINTuple3D::UpdateLimits() :  %g %g %g << %g %g %g \n", 
 | 
|---|
 | 157 | //         (xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)*0.5, 
 | 
|---|
 | 158 | //         (xmin+xmax)/2.+D , (ymin+ymax)/2.+2.*D , zmin+(zmax-zmin)*0.1);
 | 
|---|
 | 159 | }
 | 
|---|
 | 160 | 
 | 
|---|
 | 161 | 
 | 
|---|
 | 162 | /* --Methode-- */
 | 
|---|
| [205] | 163 | void PINTuple3D::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
 | 
|---|
| [165] | 164 | {
 | 
|---|
| [486] | 165 | double xp,yp,zp,wp,xer,yer,zer;
 | 
|---|
| [326] | 166 | double xl,yl,zl;
 | 
|---|
| [165] | 167 | int nok;
 | 
|---|
 | 168 | 
 | 
|---|
| [185] | 169 | // On trace les axes - En attendant de faire mieux - Reza 8/12/98
 | 
|---|
 | 170 | if (axesFlags != kAxesNone)  DrawAxes(g);
 | 
|---|
 | 171 | 
 | 
|---|
| [165] | 172 | if (!mNT) return;
 | 
|---|
 | 173 | if ( (xK < 0) || (yK < 0) || (zK < 0) )  return;
 | 
|---|
 | 174 | 
 | 
|---|
| [440] | 175 | #if defined(CC_HAS_RTTI_SUPPORT)
 | 
|---|
| [165] | 176 | PIGraphic3D* g3 = dynamic_cast<PIGraphic3D*>(g);
 | 
|---|
 | 177 | #else
 | 
|---|
 | 178 | PIGraphic3D* g3 = (PIGraphic3D*)(g);
 | 
|---|
 | 179 | #endif
 | 
|---|
 | 180 | 
 | 
|---|
| [1905] | 181 | if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt)  g3->SelLine(PI_ThinLine);
 | 
|---|
| [165] | 182 | 
 | 
|---|
| [486] | 183 | //  Pour tracer des markers avec taille fonction de Wt (poids)
 | 
|---|
 | 184 | double dw = (wMax-wMin)/nWbins;
 | 
|---|
 | 185 | if (dw < 1.e-19) dw = 1.e19;
 | 
|---|
 | 186 | int msz,sz;
 | 
|---|
 | 187 | 
 | 
|---|
| [1905] | 188 | PIMarker mmrk = GetGraphicAtt().GetMarker();
 | 
|---|
| [486] | 189 | PIMarker mrk;
 | 
|---|
| [1905] | 190 | if (wK >= 0)  mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_CircleMarker;
 | 
|---|
 | 191 | else   mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_DotMarker;
 | 
|---|
 | 192 | msz = GetGraphicAtt().GetMarkerSz();
 | 
|---|
| [486] | 193 | if (msz < 1) msz = 1;
 | 
|---|
 | 194 | g->SelMarker(msz, mrk);
 | 
|---|
 | 195 | 
 | 
|---|
| [165] | 196 | nok = 0;  
 | 
|---|
| [326] | 197 | xp = yp = zp = xl = yl = zl = 0;
 | 
|---|
 | 198 | for (int i=0; i<mNT->NbLines(); i++) {
 | 
|---|
 | 199 |   xl = xp;  yl = yp;  zl = zp;
 | 
|---|
 | 200 |   xp = mNT->GetCell(i, xK);
 | 
|---|
 | 201 |   yp = mNT->GetCell(i, yK);
 | 
|---|
 | 202 |   zp = mNT->GetCell(i, zK);
 | 
|---|
| [1905] | 203 |   if ( (i > 0) && 
 | 
|---|
 | 204 |        (GetGraphicAtt().GetLineAtt() != PI_NotDefLineAtt) )   // On relie les points ...
 | 
|---|
| [326] | 205 |     g3->DrawLine3D(xl, yl, zl, xp, yp, zp);
 | 
|---|
| [165] | 206 |   nok++;
 | 
|---|
 | 207 |   if ( xebK >= 0 ) {
 | 
|---|
| [326] | 208 |     xer = mNT->GetCell(i, xebK);
 | 
|---|
| [165] | 209 |     g3->DrawLine3D(xp-xer, yp, zp, xp+xer, yp, zp);
 | 
|---|
 | 210 |   }
 | 
|---|
 | 211 |   if ( yebK >= 0 ) {
 | 
|---|
| [326] | 212 |     yer = mNT->GetCell(i, yebK);
 | 
|---|
| [165] | 213 |     g3->DrawLine3D(xp, yp-yer, zp, xp, yp+yer, zp);
 | 
|---|
 | 214 |   }
 | 
|---|
 | 215 |   if ( zebK >= 0 ) {
 | 
|---|
| [326] | 216 |     zer = mNT->GetCell(i, zebK);
 | 
|---|
| [165] | 217 |     g3->DrawLine3D(xp, yp, zp-zer, xp, yp, zp+zer);
 | 
|---|
 | 218 |   }
 | 
|---|
| [486] | 219 |   if (wK >= 0) { // Taille de marker en fonction du poids
 | 
|---|
 | 220 |     wp = mNT->GetCell(i, wK);
 | 
|---|
 | 221 |     sz = (int)((wp-wMin)/dw);
 | 
|---|
 | 222 |     if (sz < 0) sz = 0;
 | 
|---|
 | 223 |     if (sz > nWbins)  sz = nWbins;
 | 
|---|
 | 224 |     sz += msz;
 | 
|---|
 | 225 |     if (sz < 2)  g->SelMarker(sz, PI_DotMarker);
 | 
|---|
 | 226 |     else g->SelMarker(sz, mrk);
 | 
|---|
 | 227 |   }
 | 
|---|
 | 228 |   // Trace du marker
 | 
|---|
| [1905] | 229 |   if ((wK >= 0)||(lK < 0)||(mmrk != PI_NotDefMarker))  g3->DrawMarker3D(xp, yp, zp); 
 | 
|---|
| [486] | 230 |   // Trace eventuel du label
 | 
|---|
 | 231 |   if (lK >= 0) g3->DrawString3D(xp, yp, zp, mNT->GetCelltoString(i, lK).c_str());
 | 
|---|
| [165] | 232 | }
 | 
|---|
 | 233 | 
 | 
|---|
 | 234 | return;
 | 
|---|
 | 235 | }
 | 
|---|
 | 236 | 
 | 
|---|