| [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); | 
|---|
| [165] | 52 | } | 
|---|
|  | 53 |  | 
|---|
|  | 54 | PINTuple3D::~PINTuple3D() | 
|---|
|  | 55 | { | 
|---|
|  | 56 | if (mAdDO && mNT)  delete mNT; | 
|---|
|  | 57 | } | 
|---|
|  | 58 |  | 
|---|
| [537] | 59 | //++ | 
|---|
|  | 60 | // Titre        Méthodes | 
|---|
|  | 61 | //-- | 
|---|
|  | 62 | //++ | 
|---|
|  | 63 | // void  SelectXYZ(const char* px, const char* py, const char* pz) | 
|---|
|  | 64 | //      Choix des noms de colonnes X,Y,Z définissant les coordonnées des points. | 
|---|
|  | 65 | //      Ces trois colonnes doivent être spécifiées pour obtenir un tracé. | 
|---|
|  | 66 | // void  SelectErrBar(const char* erbx=NULL, const char* erby=NULL, const char* erbz=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) | 
|---|
|  | 73 | //      Choix du nom de colonne correspondant à l'étiquette. | 
|---|
|  | 74 | //-- | 
|---|
|  | 75 |  | 
|---|
| [165] | 76 | /* --Methode-- */ | 
|---|
|  | 77 | void  PINTuple3D::SelectXYZ(const char* px, const char* py, const char* pz) | 
|---|
|  | 78 | { | 
|---|
| [326] | 79 | string name; | 
|---|
| [165] | 80 | if (mNT == NULL)  xK = yK = zK = -1; | 
|---|
|  | 81 | if (px == NULL) xK = -1; | 
|---|
| [326] | 82 | else { name = px; xK = mNT->ColumnIndex(name); } | 
|---|
| [165] | 83 | if (py == NULL) yK = -1; | 
|---|
| [326] | 84 | else { name = py; yK = mNT->ColumnIndex(name); } | 
|---|
| [165] | 85 | if (pz == NULL) zK = -1; | 
|---|
| [326] | 86 | else { name = pz; zK = mNT->ColumnIndex(name); } | 
|---|
| [165] | 87 | } | 
|---|
|  | 88 |  | 
|---|
|  | 89 | /* --Methode-- */ | 
|---|
| [486] | 90 | void  PINTuple3D::SelectWt(const char* pw, int nbins) | 
|---|
|  | 91 | { | 
|---|
|  | 92 | nWbins = (nbins > 0) ? nbins : 10; | 
|---|
|  | 93 | if (pw == NULL) wK = -1; | 
|---|
|  | 94 | else { string name = pw;   wK = mNT->ColumnIndex(name);  } | 
|---|
|  | 95 |  | 
|---|
|  | 96 | if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax); | 
|---|
|  | 97 | else  { wMin = 0.; wMax = 1.; } | 
|---|
|  | 98 | } | 
|---|
|  | 99 |  | 
|---|
|  | 100 | /* --Methode-- */ | 
|---|
|  | 101 | void  PINTuple3D::SelectLabel(const char* plabel) | 
|---|
|  | 102 | { | 
|---|
|  | 103 | if (plabel == NULL) lK = -1; | 
|---|
|  | 104 | else {  string name = plabel;  lK = mNT->ColumnIndex(name);  } | 
|---|
|  | 105 | } | 
|---|
|  | 106 |  | 
|---|
|  | 107 | /* --Methode-- */ | 
|---|
| [165] | 108 | void  PINTuple3D::SelectErrBar(const char* erbx, const char* erby, const char* erbz) | 
|---|
|  | 109 | { | 
|---|
| [326] | 110 | string name; | 
|---|
| [165] | 111 | if (mNT == NULL)  xebK = yebK = zebK = -1; | 
|---|
|  | 112 | if (erbx == NULL) xebK = -1; | 
|---|
| [326] | 113 | else { name = erbx;  xebK = mNT->ColumnIndex(name); } | 
|---|
| [165] | 114 | if (erby == NULL) yebK = -1; | 
|---|
| [326] | 115 | else { name = erby;  yebK = mNT->ColumnIndex(name); } | 
|---|
| [165] | 116 | if (erbz == NULL) zebK = -1; | 
|---|
| [326] | 117 | else { name = erbz;  zebK = mNT->ColumnIndex(name); } | 
|---|
| [165] | 118 | } | 
|---|
|  | 119 |  | 
|---|
|  | 120 |  | 
|---|
|  | 121 | /* --Methode-- */ | 
|---|
|  | 122 | void PINTuple3D::UpdateLimits() | 
|---|
|  | 123 | { | 
|---|
| [326] | 124 | if (!mNT) return; | 
|---|
|  | 125 | if (mNT->NbLines() <= 0)  return; | 
|---|
| [165] | 126 | if ( (xK < 0) || (yK < 0)  || (zK < 0) )   return; | 
|---|
|  | 127 |  | 
|---|
|  | 128 | // Commencer par trouver nos limites | 
|---|
| [326] | 129 | double xmin, xmax, ymin, ymax, zmin, zmax; | 
|---|
| [165] | 130 | xmin = ymin = 9.e19; | 
|---|
|  | 131 | xmax = ymax = -9.e19; | 
|---|
|  | 132 | zmax = zmax = -9.e19; | 
|---|
|  | 133 | mNT->GetMinMax(xK, xmin, xmax); | 
|---|
|  | 134 | mNT->GetMinMax(yK, ymin, ymax); | 
|---|
|  | 135 | mNT->GetMinMax(zK, zmin, zmax); | 
|---|
|  | 136 |  | 
|---|
|  | 137 | // Centre du champ en C = (xmin+xmax)/2., (ymin+ymax)/2  (zmin+zmax)*0.5 | 
|---|
|  | 138 | // Distance D = Max(xmax-xmin,ymin-ymax)*2 | 
|---|
|  | 139 | // Observateur en O = X+D, Yc+2*D | 
|---|
| [205] | 140 | double D = xmax-xmin; | 
|---|
| [165] | 141 | if (D < (ymax-ymin))  D = ymax-ymin; | 
|---|
|  | 142 | D *= 1.4; | 
|---|
|  | 143 |  | 
|---|
|  | 144 | Set3DView((xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)/2., | 
|---|
| [185] | 145 | (xmin+xmax)/2.+D , (ymin+ymax)/2.-2.5*D , zmin+(zmax-zmin)*0.85, 0.25, 0.25); | 
|---|
| [171] | 146 |  | 
|---|
| [185] | 147 | x3Min = xmin;  // - 0.05*(xmax-xmin); | 
|---|
|  | 148 | x3Max = xmax;  // + 0.05*(xmax-xmin); | 
|---|
|  | 149 | y3Min = ymin;  // - 0.05*(ymax-ymin); | 
|---|
|  | 150 | y3Max = ymax;  // + 0.05*(ymax-ymin); | 
|---|
|  | 151 | z3Min = zmin;  // - 0.05*(zmax-zmin); | 
|---|
|  | 152 | z3Max = zmax;  // + 0.05*(zmax-zmin); | 
|---|
| [171] | 153 |  | 
|---|
| [326] | 154 | //  printf("PINTuple3D::UpdateLimits() : %g .. %g  %g .. %g  %g .. %g (%g) \n", xmin,xmax,ymin,ymax,zmin,zmax,D); | 
|---|
| [165] | 155 | //  printf("PINTuple3D::UpdateLimits() :  %g %g %g << %g %g %g \n", | 
|---|
|  | 156 | //         (xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)*0.5, | 
|---|
|  | 157 | //         (xmin+xmax)/2.+D , (ymin+ymax)/2.+2.*D , zmin+(zmax-zmin)*0.1); | 
|---|
|  | 158 | } | 
|---|
|  | 159 |  | 
|---|
|  | 160 |  | 
|---|
|  | 161 | /* --Methode-- */ | 
|---|
| [205] | 162 | void PINTuple3D::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax) | 
|---|
| [165] | 163 | { | 
|---|
| [486] | 164 | double xp,yp,zp,wp,xer,yer,zer; | 
|---|
| [326] | 165 | double xl,yl,zl; | 
|---|
| [165] | 166 | int nok; | 
|---|
|  | 167 |  | 
|---|
| [185] | 168 | // On trace les axes - En attendant de faire mieux - Reza 8/12/98 | 
|---|
|  | 169 | if (axesFlags != kAxesNone)  DrawAxes(g); | 
|---|
|  | 170 |  | 
|---|
| [165] | 171 | if (!mNT) return; | 
|---|
|  | 172 | if ( (xK < 0) || (yK < 0) || (zK < 0) )  return; | 
|---|
|  | 173 |  | 
|---|
| [440] | 174 | #if defined(CC_HAS_RTTI_SUPPORT) | 
|---|
| [165] | 175 | PIGraphic3D* g3 = dynamic_cast<PIGraphic3D*>(g); | 
|---|
|  | 176 | #else | 
|---|
|  | 177 | PIGraphic3D* g3 = (PIGraphic3D*)(g); | 
|---|
|  | 178 | #endif | 
|---|
|  | 179 |  | 
|---|
|  | 180 | if (mLAtt == PI_NotDefLineAtt)  g3->SelLine(PI_ThinLine); | 
|---|
|  | 181 |  | 
|---|
| [486] | 182 | //  Pour tracer des markers avec taille fonction de Wt (poids) | 
|---|
|  | 183 | double dw = (wMax-wMin)/nWbins; | 
|---|
|  | 184 | if (dw < 1.e-19) dw = 1.e19; | 
|---|
|  | 185 | int msz,sz; | 
|---|
|  | 186 |  | 
|---|
|  | 187 | PIMarker mrk; | 
|---|
|  | 188 | if (wK >= 0)  mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_CircleMarker; | 
|---|
|  | 189 | else   mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_DotMarker; | 
|---|
|  | 190 | msz = mMSz; | 
|---|
|  | 191 | if (msz < 1) msz = 1; | 
|---|
|  | 192 | g->SelMarker(msz, mrk); | 
|---|
|  | 193 |  | 
|---|
| [165] | 194 | nok = 0; | 
|---|
| [326] | 195 | xp = yp = zp = xl = yl = zl = 0; | 
|---|
|  | 196 | for (int i=0; i<mNT->NbLines(); i++) { | 
|---|
|  | 197 | xl = xp;  yl = yp;  zl = zp; | 
|---|
|  | 198 | xp = mNT->GetCell(i, xK); | 
|---|
|  | 199 | yp = mNT->GetCell(i, yK); | 
|---|
|  | 200 | zp = mNT->GetCell(i, zK); | 
|---|
|  | 201 | if ( (i > 0) && (mLAtt != PI_NotDefLineAtt) )   // On relie les points ... | 
|---|
|  | 202 | g3->DrawLine3D(xl, yl, zl, xp, yp, zp); | 
|---|
| [165] | 203 | nok++; | 
|---|
|  | 204 | if ( xebK >= 0 ) { | 
|---|
| [326] | 205 | xer = mNT->GetCell(i, xebK); | 
|---|
| [165] | 206 | g3->DrawLine3D(xp-xer, yp, zp, xp+xer, yp, zp); | 
|---|
|  | 207 | } | 
|---|
|  | 208 | if ( yebK >= 0 ) { | 
|---|
| [326] | 209 | yer = mNT->GetCell(i, yebK); | 
|---|
| [165] | 210 | g3->DrawLine3D(xp, yp-yer, zp, xp, yp+yer, zp); | 
|---|
|  | 211 | } | 
|---|
|  | 212 | if ( zebK >= 0 ) { | 
|---|
| [326] | 213 | zer = mNT->GetCell(i, zebK); | 
|---|
| [165] | 214 | g3->DrawLine3D(xp, yp, zp-zer, xp, yp, zp+zer); | 
|---|
|  | 215 | } | 
|---|
| [486] | 216 | if (wK >= 0) { // Taille de marker en fonction du poids | 
|---|
|  | 217 | wp = mNT->GetCell(i, wK); | 
|---|
|  | 218 | sz = (int)((wp-wMin)/dw); | 
|---|
|  | 219 | if (sz < 0) sz = 0; | 
|---|
|  | 220 | if (sz > nWbins)  sz = nWbins; | 
|---|
|  | 221 | sz += msz; | 
|---|
|  | 222 | if (sz < 2)  g->SelMarker(sz, PI_DotMarker); | 
|---|
|  | 223 | else g->SelMarker(sz, mrk); | 
|---|
|  | 224 | } | 
|---|
|  | 225 | // Trace du marker | 
|---|
|  | 226 | if ((wK >= 0)||(lK < 0)||(mMrk != PI_NotDefMarker))  g3->DrawMarker3D(xp, yp, zp); | 
|---|
|  | 227 | // Trace eventuel du label | 
|---|
|  | 228 | if (lK >= 0) g3->DrawString3D(xp, yp, zp, mNT->GetCelltoString(i, lK).c_str()); | 
|---|
| [165] | 229 | } | 
|---|
|  | 230 |  | 
|---|
|  | 231 | return; | 
|---|
|  | 232 | } | 
|---|
|  | 233 |  | 
|---|