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 | /*
|
---|
151 | x3Min = xmin; // - PERC_GARDE*(xmax-xmin);
|
---|
152 | x3Max = xmax; // + PERC_GARDE*(xmax-xmin);
|
---|
153 | y3Min = ymin; // - PERC_GARDE*(ymax-ymin);
|
---|
154 | y3Max = ymax; // + PERC_GARDE*(ymax-ymin);
|
---|
155 | z3Min = zmin; // - PERC_GARDE*(zmax-zmin);
|
---|
156 | z3Max = zmax; // + PERC_GARDE*(zmax-zmin);
|
---|
157 | */
|
---|
158 |
|
---|
159 | Set3DBox(xmin, xmax, ymin, ymax, zmin, zmax);
|
---|
160 |
|
---|
161 | // printf("PINTuple3D::UpdateLimits() : %g .. %g %g .. %g %g .. %g (%g) \n", xmin,xmax,ymin,ymax,zmin,zmax,D);
|
---|
162 | // printf("PINTuple3D::UpdateLimits() : %g %g %g << %g %g %g \n",
|
---|
163 | // (xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)*0.5,
|
---|
164 | // (xmin+xmax)/2.+D , (ymin+ymax)/2.+2.*D , zmin+(zmax-zmin)*0.1);
|
---|
165 | }
|
---|
166 |
|
---|
167 |
|
---|
168 | /* --Methode-- */
|
---|
169 | void PINTuple3D::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
170 | {
|
---|
171 | double xp,yp,zp,wp,xer,yer,zer;
|
---|
172 | double xl,yl,zl;
|
---|
173 | int nok;
|
---|
174 |
|
---|
175 | // On trace les axes - En attendant de faire mieux - Reza 8/12/98
|
---|
176 | if (axesFlags != kAxesNone) DrawAxes(g);
|
---|
177 |
|
---|
178 | if (!mNT) return;
|
---|
179 | if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
|
---|
180 |
|
---|
181 | #if defined(CC_HAS_RTTI_SUPPORT)
|
---|
182 | PIGraphic3D* g3 = dynamic_cast<PIGraphic3D*>(g);
|
---|
183 | #else
|
---|
184 | PIGraphic3D* g3 = (PIGraphic3D*)(g);
|
---|
185 | #endif
|
---|
186 |
|
---|
187 | if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt) g3->SelLine(PI_ThinLine);
|
---|
188 |
|
---|
189 | // Pour tracer des markers avec taille fonction de Wt (poids)
|
---|
190 | double dw = (wMax-wMin)/nWbins;
|
---|
191 | if (dw < 1.e-19) dw = 1.e19;
|
---|
192 | int msz,sz;
|
---|
193 |
|
---|
194 | PIMarker mmrk = GetGraphicAtt().GetMarker();
|
---|
195 | PIMarker mrk;
|
---|
196 | if (wK >= 0) mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_CircleMarker;
|
---|
197 | else mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_DotMarker;
|
---|
198 | msz = GetGraphicAtt().GetMarkerSz();
|
---|
199 | if (msz < 1) msz = 1;
|
---|
200 | g->SelMarker(msz, mrk);
|
---|
201 |
|
---|
202 | nok = 0;
|
---|
203 | xp = yp = zp = xl = yl = zl = 0;
|
---|
204 | for (int i=0; i<mNT->NbLines(); i++) {
|
---|
205 | xl = xp; yl = yp; zl = zp;
|
---|
206 | xp = mNT->GetCell(i, xK);
|
---|
207 | yp = mNT->GetCell(i, yK);
|
---|
208 | zp = mNT->GetCell(i, zK);
|
---|
209 | if ( (i > 0) &&
|
---|
210 | (GetGraphicAtt().GetLineAtt() != PI_NotDefLineAtt) ) // On relie les points ...
|
---|
211 | g3->DrawLine3D(xl, yl, zl, xp, yp, zp);
|
---|
212 | nok++;
|
---|
213 | if ( xebK >= 0 ) {
|
---|
214 | xer = mNT->GetCell(i, xebK);
|
---|
215 | g3->DrawLine3D(xp-xer, yp, zp, xp+xer, yp, zp);
|
---|
216 | }
|
---|
217 | if ( yebK >= 0 ) {
|
---|
218 | yer = mNT->GetCell(i, yebK);
|
---|
219 | g3->DrawLine3D(xp, yp-yer, zp, xp, yp+yer, zp);
|
---|
220 | }
|
---|
221 | if ( zebK >= 0 ) {
|
---|
222 | zer = mNT->GetCell(i, zebK);
|
---|
223 | g3->DrawLine3D(xp, yp, zp-zer, xp, yp, zp+zer);
|
---|
224 | }
|
---|
225 | if (wK >= 0) { // Taille de marker en fonction du poids
|
---|
226 | wp = mNT->GetCell(i, wK);
|
---|
227 | sz = (int)((wp-wMin)/dw);
|
---|
228 | if (sz < 0) sz = 0;
|
---|
229 | if (sz > nWbins) sz = nWbins;
|
---|
230 | sz += msz;
|
---|
231 | if (sz < 2) g->SelMarker(sz, PI_DotMarker);
|
---|
232 | else g->SelMarker(sz, mrk);
|
---|
233 | }
|
---|
234 | // Trace du marker
|
---|
235 | if ((wK >= 0)||(lK < 0)||(mmrk != PI_NotDefMarker)) g3->DrawMarker3D(xp, yp, zp);
|
---|
236 | // Trace eventuel du label
|
---|
237 | if (lK >= 0) g3->DrawString3D(xp, yp, zp, mNT->GetCelltoString(i, lK).c_str());
|
---|
238 | }
|
---|
239 |
|
---|
240 | return;
|
---|
241 | }
|
---|
242 |
|
---|