source: Sophya/trunk/SophyaPI/PIext/pintup3d.cc@ 2358

Last change on this file since 2358 was 2350, checked in by ansari, 23 years ago

Ajout nouvelles options pour trace d'axes ds le Help de baseexecut.cc
et ajout d'une nouvelle option (connectpoints) ds PINTupleDrawer (et 3D)

Reza 18 Mars 2003

File size: 9.1 KB
Line 
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-- */
45PINTuple3D::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
57PINTuple3D::~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-- */
80void PINTuple3D::SelectXYZ(const char* px, const char* py, const char* pz)
81{
82string name;
83if (mNT == NULL) xK = yK = zK = -1;
84if (px == NULL) xK = -1;
85else { name = px; xK = mNT->ColumnIndex(name); }
86if (py == NULL) yK = -1;
87else { name = py; yK = mNT->ColumnIndex(name); }
88if (pz == NULL) zK = -1;
89else { name = pz; zK = mNT->ColumnIndex(name); }
90}
91
92/* --Methode-- */
93void PINTuple3D::SelectWt(const char* pw, int nbins)
94{
95nWbins = (nbins > 0) ? nbins : 10;
96if (pw == NULL) wK = -1;
97else { string name = pw; wK = mNT->ColumnIndex(name); }
98
99if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
100else { wMin = 0.; wMax = 1.; }
101}
102
103/* --Methode-- */
104void PINTuple3D::SelectLabel(const char* plabel)
105{
106if (plabel == NULL) lK = -1;
107else { string name = plabel; lK = mNT->ColumnIndex(name); }
108}
109
110/* --Methode-- */
111void PINTuple3D::SelectErrBar(const char* erbx, const char* erby, const char* erbz)
112{
113string name;
114if (mNT == NULL) xebK = yebK = zebK = -1;
115if (erbx == NULL) xebK = -1;
116else { name = erbx; xebK = mNT->ColumnIndex(name); }
117if (erby == NULL) yebK = -1;
118else { name = erby; yebK = mNT->ColumnIndex(name); }
119if (erbz == NULL) zebK = -1;
120else { name = erbz; zebK = mNT->ColumnIndex(name); }
121}
122
123
124/* --Methode-- */
125void 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-- */
169void PINTuple3D::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
170{
171double xp,yp,zp,wp,xer,yer,zer;
172double xl,yl,zl;
173int nok;
174
175// On trace les axes - En attendant de faire mieux - Reza 8/12/98
176if (axesFlags != kAxesNone) DrawAxes(g);
177
178if (!mNT) return;
179if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
180
181#if defined(CC_HAS_RTTI_SUPPORT)
182PIGraphic3D* g3 = dynamic_cast<PIGraphic3D*>(g);
183#else
184PIGraphic3D* g3 = (PIGraphic3D*)(g);
185#endif
186
187if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt) g3->SelLine(PI_ThinLine);
188
189// Pour tracer des markers avec taille fonction de Wt (poids)
190double dw = (wMax-wMin)/nWbins;
191if (dw < 1.e-19) dw = 1.e19;
192int msz,sz;
193
194PIMarker mmrk = GetGraphicAtt().GetMarker();
195PIMarker mrk;
196if (wK >= 0) mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_CircleMarker;
197else mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_DotMarker;
198msz = GetGraphicAtt().GetMarkerSz();
199if (msz < 1) msz = 1;
200g->SelMarker(msz, mrk);
201
202nok = 0;
203xp = yp = zp = xl = yl = zl = 0;
204for (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) && connectPts ) // On relie les points ...
210 g3->DrawLine3D(xl, yl, zl, xp, yp, zp);
211 nok++;
212 if ( xebK >= 0 ) {
213 xer = mNT->GetCell(i, xebK);
214 g3->DrawLine3D(xp-xer, yp, zp, xp+xer, yp, zp);
215 }
216 if ( yebK >= 0 ) {
217 yer = mNT->GetCell(i, yebK);
218 g3->DrawLine3D(xp, yp-yer, zp, xp, yp+yer, zp);
219 }
220 if ( zebK >= 0 ) {
221 zer = mNT->GetCell(i, zebK);
222 g3->DrawLine3D(xp, yp, zp-zer, xp, yp, zp+zer);
223 }
224 if (wK >= 0) { // Taille de marker en fonction du poids
225 wp = mNT->GetCell(i, wK);
226 sz = (int)((wp-wMin)/dw);
227 if (sz < 0) sz = 0;
228 if (sz > nWbins) sz = nWbins;
229 sz += msz;
230 if (sz < 2) g->SelMarker(sz, PI_DotMarker);
231 else g->SelMarker(sz, mrk);
232 }
233 // Trace du marker
234 if ((wK >= 0)||(lK < 0)||(mmrk != PI_NotDefMarker)) g3->DrawMarker3D(xp, yp, zp);
235 // Trace eventuel du label
236 if (lK >= 0) g3->DrawString3D(xp, yp, zp, mNT->GetCelltoString(i, lK).c_str());
237}
238
239return;
240}
241
242/* La methode DecodeOptionString permet de decoder un ensemble d'options
243 et de parametre d'affichage specifie sous forme d'un vecteur de string.
244 Si rmdecopt == true, les options decodees sont supprimees du vecteur
245 de string fourni en entree - ce qui permet l'enchainement eventuel
246 de plusieurs decodages de string.
247 Les options peuvent etre sous forme de flag : "stat" "nostat"
248 ou plus complexes, par exemple "dynamic=-3,3"
249 Rc: La methode renvoie le nombre d'options decodees
250*/
251
252/* --Methode-- */
253int PINTuple3D::DecodeOptionString(vector<string> & opt, bool rmdecopt)
254{
255 int optsz1 = opt.size();
256 if(optsz1<1) return(0);
257 // On appelle d'abord le decodage de la classe PIDrawer de laquelle
258 // on herite. (Pas obligatoire) on decode donc ici les attributs de
259 // couleur, fontes ...
260 int ndec1 = PIDrawer::DecodeOptionString(opt, rmdecopt);
261 if(optsz1-ndec1<1) return(ndec1); // si tout a ete decode
262
263 vector<string> udopt; // On gardera ici les options non decodees
264 unsigned int k = 0;
265 int ndec = opt.size();
266 for( k=0; k<opt.size(); k++ ) {
267 string opts = opt[k];
268 // if(opts=="sta" || opts=="stat" || opts=="stats") SetStats(true);
269 // else if( opts=="nsta" || opts=="nstat"
270 // || opts=="nostat" || opts=="nostats") SetStats(false);
271 if (opts == "connectpoints") ConnectPoints(true);
272 else if (opts == "noconnectpoints") ConnectPoints(false);
273 else {
274 // Si option non decode
275 ndec--;
276 // S'il faut supprimer les options decodees
277 if (rmdecopt) udopt.push_back(opts);
278 }
279 }
280 // S'il faut supprimer les options decodees, on remplace l'argument opt
281 // par le vecteur des options non decodees.
282 if (rmdecopt) opt = udopt;
283 return(ndec+ndec1);
284}
285
286/* La methode GetOptionsHelpInfo(string& info) renvoie une chaine
287 avec la description des options comprises par ce drawer
288 Note: Il est preferable de ne pas initialiser la chaine
289 string info au depart, afin de permettre de mettre bout a
290 bout les aides de differents Drawer */
291
292/* --Methode-- */
293void PINTuple3D::GetOptionsHelpInfo(string& info)
294{
295// On recupere d'abord la chaine info de la classe de base
296PIDrawer::GetOptionsHelpInfo(info);
297info += " ---- PINTuple3D options help info : \n" ;
298info += " connectpoints: The points are connected by a line \n";
299info += " noconnectpoints (this is the default) \n";
300info += " and usual color/line/marker/... attribute decoding \n";
301return;
302}
303
Note: See TracBrowser for help on using the repository browser.