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