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

Last change on this file since 2523 was 2400, checked in by ansari, 22 years ago

Modifs ds PINtup3D suite a la prise en charge du trace d'axes par ls BaseDrawer ds les traces 3D - Reza 6 Juin 2003

File size: 11.1 KB
RevLine 
[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
[2092]8//#define PERC_GARDE 0.05
9
[537]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
[165]43
44/* --Methode-- */
[326]45PINTuple3D::PINTuple3D(NTupleInterface* nt, bool ad)
[165]46: PIDrawer3D()
47{
48 mNT = nt;
49 mAdDO = ad;
[2400]50 mAutoScaleXY = mAutoScaleZ = true;
[2373]51 UseSizeScale(true, 5);
52 UseColorScale(true);
[2400]53 ConnectPoints(false);
[165]54 SelectXYZ(NULL, NULL, NULL);
[2373]55 SelectWt(NULL);
[165]56 SelectErrBar();
[486]57 SelectLabel(NULL);
[1856]58 SetName("NTup3DDrw");
[165]59}
60
61PINTuple3D::~PINTuple3D()
62{
63 if (mAdDO && mNT) delete mNT;
64}
65
[537]66//++
67// Titre Méthodes
68//--
69//++
70// void SelectXYZ(const char* px, const char* py, const char* pz)
71// Choix des noms de colonnes X,Y,Z définissant les coordonnées des points.
72// Ces trois colonnes doivent être spécifiées pour obtenir un tracé.
73// void SelectErrBar(const char* erbx=NULL, const char* erby=NULL, const char* erbz=NULL)
74// Choix des noms de colonnes pour le tracé des barres d'erreur.
75// void SelectWt(const char* pw=NULL, int nbins=10)
76// Choix du nom de colonne poids. Dans ce cas, la taille du signe
77// (marker) sera proportionnel à la valeur de cette colonne pour
78// chaque point.
79// void SelectLabel(const char* plabel)
80// Choix du nom de colonne correspondant à l'étiquette.
81//--
82
[165]83/* --Methode-- */
84void PINTuple3D::SelectXYZ(const char* px, const char* py, const char* pz)
85{
[326]86string name;
[165]87if (mNT == NULL) xK = yK = zK = -1;
88if (px == NULL) xK = -1;
[326]89else { name = px; xK = mNT->ColumnIndex(name); }
[165]90if (py == NULL) yK = -1;
[326]91else { name = py; yK = mNT->ColumnIndex(name); }
[165]92if (pz == NULL) zK = -1;
[326]93else { name = pz; zK = mNT->ColumnIndex(name); }
[165]94}
95
96/* --Methode-- */
[2373]97void PINTuple3D::SelectWt(const char* pw)
[486]98{
99if (pw == NULL) wK = -1;
100else { string name = pw; wK = mNT->ColumnIndex(name); }
101
102if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
103else { wMin = 0.; wMax = 1.; }
104}
105
106/* --Methode-- */
107void PINTuple3D::SelectLabel(const char* plabel)
108{
109if (plabel == NULL) lK = -1;
110else { string name = plabel; lK = mNT->ColumnIndex(name); }
111}
112
113/* --Methode-- */
[165]114void PINTuple3D::SelectErrBar(const char* erbx, const char* erby, const char* erbz)
115{
[326]116string name;
[165]117if (mNT == NULL) xebK = yebK = zebK = -1;
118if (erbx == NULL) xebK = -1;
[326]119else { name = erbx; xebK = mNT->ColumnIndex(name); }
[165]120if (erby == NULL) yebK = -1;
[326]121else { name = erby; yebK = mNT->ColumnIndex(name); }
[165]122if (erbz == NULL) zebK = -1;
[326]123else { name = erbz; zebK = mNT->ColumnIndex(name); }
[165]124}
125
126
127/* --Methode-- */
128void PINTuple3D::UpdateLimits()
129{
[326]130 if (!mNT) return;
131 if (mNT->NbLines() <= 0) return;
[165]132 if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
133
134 // Commencer par trouver nos limites
[326]135 double xmin, xmax, ymin, ymax, zmin, zmax;
[165]136 xmin = ymin = 9.e19;
137 xmax = ymax = -9.e19;
138 zmax = zmax = -9.e19;
139 mNT->GetMinMax(xK, xmin, xmax);
140 mNT->GetMinMax(yK, ymin, ymax);
141 mNT->GetMinMax(zK, zmin, zmax);
142
[2400]143 ComputeScaleFactor(xmin, xmax, ymin, ymax, zmin, zmax,
144 mAutoScaleXY, mAutoScaleZ, mScy, mScz);
145
146 // cout << " DEBUG - NTup3D X:" << XMin3() << "-" << XMax3() " s=" << mScx
147 // << " Y:" YMin3() << "-" << YMax3() << "
148 xmin *= mScx; xmax *= mScx;
149 ymin *= mScy; ymax *= mScy;
150 zmin *= mScz; zmax *= mScz;
[165]151// Centre du champ en C = (xmin+xmax)/2., (ymin+ymax)/2 (zmin+zmax)*0.5
152// Distance D = Max(xmax-xmin,ymin-ymax)*2
153// Observateur en O = X+D, Yc+2*D
[205]154 double D = xmax-xmin;
[165]155 if (D < (ymax-ymin)) D = ymax-ymin;
156 D *= 1.4;
157
158 Set3DView((xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)/2.,
[185]159 (xmin+xmax)/2.+D , (ymin+ymax)/2.-2.5*D , zmin+(zmax-zmin)*0.85, 0.25, 0.25);
[171]160
[2400]161 Set3DBox(xmin, xmax, ymin, ymax, zmin, zmax, mScx, mScy, mScz);
162
[2165]163 /*
[2092]164 x3Min = xmin; // - PERC_GARDE*(xmax-xmin);
165 x3Max = xmax; // + PERC_GARDE*(xmax-xmin);
166 y3Min = ymin; // - PERC_GARDE*(ymax-ymin);
167 y3Max = ymax; // + PERC_GARDE*(ymax-ymin);
168 z3Min = zmin; // - PERC_GARDE*(zmax-zmin);
169 z3Max = zmax; // + PERC_GARDE*(zmax-zmin);
[2165]170 */
[171]171
[2165]172
[326]173// printf("PINTuple3D::UpdateLimits() : %g .. %g %g .. %g %g .. %g (%g) \n", xmin,xmax,ymin,ymax,zmin,zmax,D);
[165]174// printf("PINTuple3D::UpdateLimits() : %g %g %g << %g %g %g \n",
175// (xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)*0.5,
176// (xmin+xmax)/2.+D , (ymin+ymax)/2.+2.*D , zmin+(zmax-zmin)*0.1);
177}
178
179
180/* --Methode-- */
[205]181void PINTuple3D::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
[165]182{
[486]183double xp,yp,zp,wp,xer,yer,zer;
[326]184double xl,yl,zl;
[165]185int nok;
186
[185]187// On trace les axes - En attendant de faire mieux - Reza 8/12/98
188if (axesFlags != kAxesNone) DrawAxes(g);
189
[165]190if (!mNT) return;
191if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
192
[440]193#if defined(CC_HAS_RTTI_SUPPORT)
[165]194PIGraphic3D* g3 = dynamic_cast<PIGraphic3D*>(g);
195#else
196PIGraphic3D* g3 = (PIGraphic3D*)(g);
197#endif
198
[1905]199if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt) g3->SelLine(PI_ThinLine);
[165]200
[486]201// Pour tracer des markers avec taille fonction de Wt (poids)
202double dw = (wMax-wMin)/nWbins;
[2373]203if (dw < 1.e-19) dw = 1.e-19;
204// Pour tracer des markers avec couleur en fonction de Wt (poids)
205PIColorMap * cmap = NULL;
206double dwc = 1.;
207double nwc = 1.;
208bool revcmap;
209CMapId mcmapid = GetGraphicAtt().GetColMapId(revcmap);
210if( colorScale && (wK >= 0) && (mcmapid != CMAP_OTHER) ) {
211 cmap = new PIColorMap(mcmapid);
212 cmap->ReverseColorIndex(revcmap);
213 nwc = cmap->NCol();
214 dwc = (wMax-wMin)/nwc;
215}
216
[486]217int msz,sz;
218
[1905]219PIMarker mmrk = GetGraphicAtt().GetMarker();
[486]220PIMarker mrk;
[1905]221if (wK >= 0) mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_CircleMarker;
222else mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_DotMarker;
223msz = GetGraphicAtt().GetMarkerSz();
[486]224if (msz < 1) msz = 1;
225g->SelMarker(msz, mrk);
226
[165]227nok = 0;
[326]228xp = yp = zp = xl = yl = zl = 0;
229for (int i=0; i<mNT->NbLines(); i++) {
230 xl = xp; yl = yp; zl = zp;
231 xp = mNT->GetCell(i, xK);
232 yp = mNT->GetCell(i, yK);
233 zp = mNT->GetCell(i, zK);
[2373]234
235// Taille - couleur de marker en fonction du poids
236 if (wK >= 0) wp = mNT->GetCell(i, wK);
237 if (mrkSzScale && (wK >= 0)) { // Changement de taille
238 sz = (int)((wp-wMin)/dw);
239 if (sz < 0) sz = 0;
240 if (sz > nWbins) sz = nWbins;
241 sz += msz;
242 if (sz < 2) g->SelMarker(sz, PI_DotMarker);
243 else g->SelMarker(sz, mrk);
244 }
245// Couleur du marker en fonction du poids
246 if( colorScale && (wK >= 0) && cmap ) {
247 int cid = (int)((wp-wMin)/dwc);
248 if (cid < 0) cid = 0;
249 if (cid >= nwc) cid = nwc-1;
250 g->SelForeground(*cmap, cid);
251 }
252
[2350]253 if ( (i > 0) && connectPts ) // On relie les points ...
[2400]254 g3->DrawLine3D(xl*mScx, yl*mScy, zl*mScz, xp*mScx, yp*mScy, zp*mScz);
[165]255 nok++;
256 if ( xebK >= 0 ) {
[326]257 xer = mNT->GetCell(i, xebK);
[2400]258 g3->DrawLine3D((xp-xer)*mScx, yp*mScy, zp*mScz, (xp+xer)*mScx, yp*mScy, zp*mScz);
[165]259 }
260 if ( yebK >= 0 ) {
[326]261 yer = mNT->GetCell(i, yebK);
[2400]262 g3->DrawLine3D(xp*mScx, (yp-yer)*mScy, zp*mScz, xp*mScx, (yp+yer)*mScy, zp*mScz);
[165]263 }
264 if ( zebK >= 0 ) {
[326]265 zer = mNT->GetCell(i, zebK);
[2400]266 g3->DrawLine3D(xp*mScx, yp*mScy, (zp-zer)*mScz, xp*mScx, yp*mScy, (zp+zer)*mScz);
[165]267 }
[486]268 // Trace du marker
[2400]269 if ((wK >= 0)||(lK < 0)||(mmrk != PI_NotDefMarker))
270 g3->DrawMarker3D(xp*mScx, yp*mScy, zp*mScz);
[486]271 // Trace eventuel du label
[2400]272 if (lK >= 0) g3->DrawString3D(xp*mScx, yp*mScy, zp*mScz,
273 mNT->GetCelltoString(i, lK).c_str());
[165]274}
275
276return;
277}
278
[2350]279/* La methode DecodeOptionString permet de decoder un ensemble d'options
280 et de parametre d'affichage specifie sous forme d'un vecteur de string.
281 Si rmdecopt == true, les options decodees sont supprimees du vecteur
282 de string fourni en entree - ce qui permet l'enchainement eventuel
283 de plusieurs decodages de string.
284 Les options peuvent etre sous forme de flag : "stat" "nostat"
285 ou plus complexes, par exemple "dynamic=-3,3"
286 Rc: La methode renvoie le nombre d'options decodees
287*/
288
289/* --Methode-- */
290int PINTuple3D::DecodeOptionString(vector<string> & opt, bool rmdecopt)
291{
292 int optsz1 = opt.size();
293 if(optsz1<1) return(0);
294 // On appelle d'abord le decodage de la classe PIDrawer de laquelle
295 // on herite. (Pas obligatoire) on decode donc ici les attributs de
296 // couleur, fontes ...
297 int ndec1 = PIDrawer::DecodeOptionString(opt, rmdecopt);
298 if(optsz1-ndec1<1) return(ndec1); // si tout a ete decode
299
300 vector<string> udopt; // On gardera ici les options non decodees
301 unsigned int k = 0;
302 int ndec = opt.size();
303 for( k=0; k<opt.size(); k++ ) {
304 string opts = opt[k];
305 // if(opts=="sta" || opts=="stat" || opts=="stats") SetStats(true);
306 // else if( opts=="nsta" || opts=="nstat"
307 // || opts=="nostat" || opts=="nostats") SetStats(false);
308 if (opts == "connectpoints") ConnectPoints(true);
309 else if (opts == "noconnectpoints") ConnectPoints(false);
[2373]310 else if (opts == "colorscale") UseColorScale(true);
311 else if (opts == "nocolorscale") UseColorScale(false);
312 else if (opts == "sizescale") UseSizeScale(true);
313 else if (opts == "nosizescale") UseSizeScale(false);
314 else if (opts.substr(0,10) == "sizescale=") {
315 int nbn = atoi(opts.substr(10).c_str());
316 UseSizeScale(true, nbn);
317 }
[2400]318 else if (opts == "rescalexy") mAutoScaleXY = true;
319 else if (opts == "norescalexy") mAutoScaleXY = false;
320 else if (opts == "rescalez") mAutoScaleZ = true;
321 else if (opts == "norescalez") mAutoScaleZ = false;
[2350]322 else {
323 // Si option non decode
324 ndec--;
325 // S'il faut supprimer les options decodees
326 if (rmdecopt) udopt.push_back(opts);
327 }
328 }
329 // S'il faut supprimer les options decodees, on remplace l'argument opt
330 // par le vecteur des options non decodees.
331 if (rmdecopt) opt = udopt;
332 return(ndec+ndec1);
333}
334
335/* La methode GetOptionsHelpInfo(string& info) renvoie une chaine
336 avec la description des options comprises par ce drawer
337 Note: Il est preferable de ne pas initialiser la chaine
338 string info au depart, afin de permettre de mettre bout a
339 bout les aides de differents Drawer */
340
341/* --Methode-- */
342void PINTuple3D::GetOptionsHelpInfo(string& info)
343{
344info += " ---- PINTuple3D options help info : \n" ;
345info += " connectpoints: The points are connected by a line \n";
346info += " noconnectpoints (this is the default) \n";
[2373]347info += " colorscale/nocolorscale (Use color scale for weight) \n";
348info += " sizescale/sizescale=nbins/nosizescale (Use marker size for weight) \n";
[2400]349info += " rescalexy / norescalexy rescalez / norescalez \n";
[2350]350info += " and usual color/line/marker/... attribute decoding \n";
[2400]351// On recupere ensuite la chaine info de la classe de base
352PIDrawer::GetOptionsHelpInfo(info);
[2350]353return;
354}
355
Note: See TracBrowser for help on using the repository browser.