1 | #include <stdio.h>
|
---|
2 | #include "pintup3d.h"
|
---|
3 |
|
---|
4 |
|
---|
5 | /* --Methode-- */
|
---|
6 | PINTuple3D::PINTuple3D(NTupleInterface* nt, bool ad)
|
---|
7 | : PIDrawer3D()
|
---|
8 | {
|
---|
9 | mNT = nt;
|
---|
10 | mAdDO = ad;
|
---|
11 | SelectXYZ(NULL, NULL, NULL);
|
---|
12 | SelectWt(NULL, 1);
|
---|
13 | SelectErrBar();
|
---|
14 | SelectLabel(NULL);
|
---|
15 | }
|
---|
16 |
|
---|
17 | PINTuple3D::~PINTuple3D()
|
---|
18 | {
|
---|
19 | if (mAdDO && mNT) delete mNT;
|
---|
20 | }
|
---|
21 |
|
---|
22 | /* --Methode-- */
|
---|
23 | void PINTuple3D::SelectXYZ(const char* px, const char* py, const char* pz)
|
---|
24 | {
|
---|
25 | string name;
|
---|
26 | if (mNT == NULL) xK = yK = zK = -1;
|
---|
27 | if (px == NULL) xK = -1;
|
---|
28 | else { name = px; xK = mNT->ColumnIndex(name); }
|
---|
29 | if (py == NULL) yK = -1;
|
---|
30 | else { name = py; yK = mNT->ColumnIndex(name); }
|
---|
31 | if (pz == NULL) zK = -1;
|
---|
32 | else { name = pz; zK = mNT->ColumnIndex(name); }
|
---|
33 | }
|
---|
34 |
|
---|
35 | /* --Methode-- */
|
---|
36 | void PINTuple3D::SelectWt(const char* pw, int nbins)
|
---|
37 | {
|
---|
38 | nWbins = (nbins > 0) ? nbins : 10;
|
---|
39 | if (pw == NULL) wK = -1;
|
---|
40 | else { string name = pw; wK = mNT->ColumnIndex(name); }
|
---|
41 |
|
---|
42 | if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
|
---|
43 | else { wMin = 0.; wMax = 1.; }
|
---|
44 | }
|
---|
45 |
|
---|
46 | /* --Methode-- */
|
---|
47 | void PINTuple3D::SelectLabel(const char* plabel)
|
---|
48 | {
|
---|
49 | if (plabel == NULL) lK = -1;
|
---|
50 | else { string name = plabel; lK = mNT->ColumnIndex(name); }
|
---|
51 | }
|
---|
52 |
|
---|
53 | /* --Methode-- */
|
---|
54 | void PINTuple3D::SelectErrBar(const char* erbx, const char* erby, const char* erbz)
|
---|
55 | {
|
---|
56 | string name;
|
---|
57 | if (mNT == NULL) xebK = yebK = zebK = -1;
|
---|
58 | if (erbx == NULL) xebK = -1;
|
---|
59 | else { name = erbx; xebK = mNT->ColumnIndex(name); }
|
---|
60 | if (erby == NULL) yebK = -1;
|
---|
61 | else { name = erby; yebK = mNT->ColumnIndex(name); }
|
---|
62 | if (erbz == NULL) zebK = -1;
|
---|
63 | else { name = erbz; zebK = mNT->ColumnIndex(name); }
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | /* --Methode-- */
|
---|
68 | void PINTuple3D::UpdateLimits()
|
---|
69 | {
|
---|
70 | if (!mNT) return;
|
---|
71 | if (mNT->NbLines() <= 0) return;
|
---|
72 | if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
|
---|
73 |
|
---|
74 | // Commencer par trouver nos limites
|
---|
75 | double xmin, xmax, ymin, ymax, zmin, zmax;
|
---|
76 | xmin = ymin = 9.e19;
|
---|
77 | xmax = ymax = -9.e19;
|
---|
78 | zmax = zmax = -9.e19;
|
---|
79 | mNT->GetMinMax(xK, xmin, xmax);
|
---|
80 | mNT->GetMinMax(yK, ymin, ymax);
|
---|
81 | mNT->GetMinMax(zK, zmin, zmax);
|
---|
82 |
|
---|
83 | // Centre du champ en C = (xmin+xmax)/2., (ymin+ymax)/2 (zmin+zmax)*0.5
|
---|
84 | // Distance D = Max(xmax-xmin,ymin-ymax)*2
|
---|
85 | // Observateur en O = X+D, Yc+2*D
|
---|
86 | double D = xmax-xmin;
|
---|
87 | if (D < (ymax-ymin)) D = ymax-ymin;
|
---|
88 | D *= 1.4;
|
---|
89 |
|
---|
90 | Set3DView((xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)/2.,
|
---|
91 | (xmin+xmax)/2.+D , (ymin+ymax)/2.-2.5*D , zmin+(zmax-zmin)*0.85, 0.25, 0.25);
|
---|
92 |
|
---|
93 | x3Min = xmin; // - 0.05*(xmax-xmin);
|
---|
94 | x3Max = xmax; // + 0.05*(xmax-xmin);
|
---|
95 | y3Min = ymin; // - 0.05*(ymax-ymin);
|
---|
96 | y3Max = ymax; // + 0.05*(ymax-ymin);
|
---|
97 | z3Min = zmin; // - 0.05*(zmax-zmin);
|
---|
98 | z3Max = zmax; // + 0.05*(zmax-zmin);
|
---|
99 |
|
---|
100 | // printf("PINTuple3D::UpdateLimits() : %g .. %g %g .. %g %g .. %g (%g) \n", xmin,xmax,ymin,ymax,zmin,zmax,D);
|
---|
101 | // printf("PINTuple3D::UpdateLimits() : %g %g %g << %g %g %g \n",
|
---|
102 | // (xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)*0.5,
|
---|
103 | // (xmin+xmax)/2.+D , (ymin+ymax)/2.+2.*D , zmin+(zmax-zmin)*0.1);
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | /* --Methode-- */
|
---|
108 | void PINTuple3D::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
109 | {
|
---|
110 | double xp,yp,zp,wp,xer,yer,zer;
|
---|
111 | double xl,yl,zl;
|
---|
112 | int nok;
|
---|
113 |
|
---|
114 | // On trace les axes - En attendant de faire mieux - Reza 8/12/98
|
---|
115 | if (axesFlags != kAxesNone) DrawAxes(g);
|
---|
116 |
|
---|
117 | if (!mNT) return;
|
---|
118 | if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
|
---|
119 |
|
---|
120 | #if defined(CC_HAS_RTTI_SUPPORT)
|
---|
121 | PIGraphic3D* g3 = dynamic_cast<PIGraphic3D*>(g);
|
---|
122 | #else
|
---|
123 | PIGraphic3D* g3 = (PIGraphic3D*)(g);
|
---|
124 | #endif
|
---|
125 |
|
---|
126 | if (mLAtt == PI_NotDefLineAtt) g3->SelLine(PI_ThinLine);
|
---|
127 |
|
---|
128 | // Pour tracer des markers avec taille fonction de Wt (poids)
|
---|
129 | double dw = (wMax-wMin)/nWbins;
|
---|
130 | if (dw < 1.e-19) dw = 1.e19;
|
---|
131 | int msz,sz;
|
---|
132 |
|
---|
133 | PIMarker mrk;
|
---|
134 | if (wK >= 0) mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_CircleMarker;
|
---|
135 | else mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_DotMarker;
|
---|
136 | msz = mMSz;
|
---|
137 | if (msz < 1) msz = 1;
|
---|
138 | g->SelMarker(msz, mrk);
|
---|
139 |
|
---|
140 | nok = 0;
|
---|
141 | xp = yp = zp = xl = yl = zl = 0;
|
---|
142 | for (int i=0; i<mNT->NbLines(); i++) {
|
---|
143 | xl = xp; yl = yp; zl = zp;
|
---|
144 | xp = mNT->GetCell(i, xK);
|
---|
145 | yp = mNT->GetCell(i, yK);
|
---|
146 | zp = mNT->GetCell(i, zK);
|
---|
147 | if ( (i > 0) && (mLAtt != PI_NotDefLineAtt) ) // On relie les points ...
|
---|
148 | g3->DrawLine3D(xl, yl, zl, xp, yp, zp);
|
---|
149 | nok++;
|
---|
150 | if ( xebK >= 0 ) {
|
---|
151 | xer = mNT->GetCell(i, xebK);
|
---|
152 | g3->DrawLine3D(xp-xer, yp, zp, xp+xer, yp, zp);
|
---|
153 | }
|
---|
154 | if ( yebK >= 0 ) {
|
---|
155 | yer = mNT->GetCell(i, yebK);
|
---|
156 | g3->DrawLine3D(xp, yp-yer, zp, xp, yp+yer, zp);
|
---|
157 | }
|
---|
158 | if ( zebK >= 0 ) {
|
---|
159 | zer = mNT->GetCell(i, zebK);
|
---|
160 | g3->DrawLine3D(xp, yp, zp-zer, xp, yp, zp+zer);
|
---|
161 | }
|
---|
162 | if (wK >= 0) { // Taille de marker en fonction du poids
|
---|
163 | wp = mNT->GetCell(i, wK);
|
---|
164 | sz = (int)((wp-wMin)/dw);
|
---|
165 | if (sz < 0) sz = 0;
|
---|
166 | if (sz > nWbins) sz = nWbins;
|
---|
167 | sz += msz;
|
---|
168 | if (sz < 2) g->SelMarker(sz, PI_DotMarker);
|
---|
169 | else g->SelMarker(sz, mrk);
|
---|
170 | }
|
---|
171 | // Trace du marker
|
---|
172 | if ((wK >= 0)||(lK < 0)||(mMrk != PI_NotDefMarker)) g3->DrawMarker3D(xp, yp, zp);
|
---|
173 | // Trace eventuel du label
|
---|
174 | if (lK >= 0) g3->DrawString3D(xp, yp, zp, mNT->GetCelltoString(i, lK).c_str());
|
---|
175 | }
|
---|
176 |
|
---|
177 | return;
|
---|
178 | }
|
---|
179 |
|
---|