source: Sophya/trunk/SophyaPI/PIext/pintuple.cc@ 2092

Last change on this file since 2092 was 2092, checked in by cmv, 23 years ago

intro PERC_GARDE pour localiser les pb cmv 14/7/2002

File size: 9.2 KB
RevLine 
[537]1// Peida Interactive - PI R. Ansari 97-99
2// Traceur (Drawer) pour NTupleInterface
3// LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
4
[165]5#include <stdio.h>
6#include "pintuple.h"
7
[2092]8#define PERC_GARDE 0.02
9
[537]10//++
11// Class PINTuple
12// Lib PIext
13// include pintuple.h
14//
15// Classe de traceur 2D (dans un plan) à partir des données
16// d'un objet implémentant l'interface *NTupleInterface*.
17// Les objets "PINTuple" 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// PIDrawer
26//--
27//++
28// Links Voir aussi
29// NTupleInterface
30// PINTuple3D
31//--
32
33//++
34// Titre Constructeur
35//--
36//++
37// PINTuple(NTupleInterface* nt, bool ad)
[544]38// Constructeur. Si "ad == true", l'objet "nt" est détruit par
[537]39// le destructeur de l'objet "PINTuple"
[544]40// Note : "nt" doit être créé par new
[537]41//--
[165]42
43/* --Methode-- */
[326]44PINTuple::PINTuple(NTupleInterface* nt, bool ad)
[165]45: PIDrawer()
46{
47 mNT = nt;
48 mAdDO = ad;
[544]49 SetStats(true);
[165]50 SelectXY(NULL, NULL);
[336]51 SelectWt(NULL, 1);
[165]52 SelectErrBar();
[486]53 SelectLabel(NULL);
[1856]54 SetName("NTupleDrw");
[165]55}
56
57PINTuple::~PINTuple()
58{
59 if (mAdDO && mNT) delete mNT;
60}
61
[537]62//++
63// Titre Méthodes
64//--
65//++
66// void SelectXY(const char* px, const char* py)
67// Choix des noms de colonnes X,Y définissant les coordonnées des points.
68// Ces deux colonnes doivent être spécifiées pour obtenir un tracé.
69// void SelectErrBar(const char* erbx=NULL, const char* erby=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=NULL)
76// Choix du nom de colonne correspondant à l'étiquette.
77//--
78
[165]79/* --Methode-- */
80void PINTuple::SelectXY(const char* px, const char* py)
81{
[326]82string name;
[165]83if (mNT == NULL) xK = yK = -1;
84if (px == NULL) xK = -1;
[326]85else { name = px; xK = mNT->ColumnIndex(name); }
[165]86if (py == NULL) yK = -1;
[326]87else { name = py; yK = mNT->ColumnIndex(name); }
[165]88}
89
90/* --Methode-- */
[333]91void PINTuple::SelectWt(const char* pw, int nbins)
92{
93nWbins = (nbins > 0) ? nbins : 10;
94if (pw == NULL) wK = -1;
95else { string name = pw; wK = mNT->ColumnIndex(name); }
96
97if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
98else { wMin = 0.; wMax = 1.; }
99}
100
101/* --Methode-- */
[486]102void PINTuple::SelectLabel(const char* plabel)
103{
104if (plabel == NULL) lK = -1;
105else { string name = plabel; lK = mNT->ColumnIndex(name); }
106}
107
108/* --Methode-- */
[165]109void PINTuple::SelectErrBar(const char* erbx, const char* erby)
110{
[326]111string name;
[165]112if (mNT == NULL) xebK = yebK = -1;
113if (erbx == NULL) xebK = -1;
[326]114else { name = erbx; xebK = mNT->ColumnIndex(name); }
[165]115if (erby == NULL) yebK = -1;
[326]116else { name = erby; yebK = mNT->ColumnIndex(name); }
[165]117}
118
119
120/* --Methode-- */
121void PINTuple::UpdateLimits()
122{
123 if (!mNT) return;
[326]124 if (mNT->NbLines() <= 0) return;
[165]125 if ( (xK < 0) || (yK < 0) ) return;
126
127 // Commencer par trouver nos limites
[326]128 double dx, dy;
129 double xmin, xmax, ymin, ymax;
[165]130 xmin = ymin = 9.e19;
131 xmax = ymax = -9.e19;
132 mNT->GetMinMax(xK, xmin, xmax);
133 mNT->GetMinMax(yK, ymin, ymax);
134
[2092]135 dx = PERC_GARDE*(xmax-xmin);
136 dy = PERC_GARDE*(ymax-ymin);
[165]137
138 SetLimits(xmin-dx, xmax+dx, ymin-dy, ymax+dy);
[548]139// SetAxesFlags(kBoxAxes | kExtTicks | kLabels); Ne pas faire - Reza 11/99
[165]140}
141
142
143/* --Methode-- */
[205]144void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
[165]145{
[333]146double xp,yp,xer,yer,wp;
[326]147double xl,yl;
[165]148int nok;
149
150if (!mNT) return;
[548]151if (axesFlags != kAxesNone) DrawAxes(g);
[165]152if ( (xK < 0) || (yK < 0) ) return;
[1905]153if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
[326]154
[333]155// Pour tracer des markers avec taille fonction de Wt (poids)
156double dw = (wMax-wMin)/nWbins;
157if (dw < 1.e-19) dw = 1.e19;
158int msz,sz;
159
[1905]160PIMarker mmrk = GetGraphicAtt().GetMarker();
[333]161PIMarker mrk;
[1905]162if (wK >= 0) mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_CircleMarker;
163else mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_DotMarker;
[1920]164 msz = GetGraphicAtt().GetMarkerSz();
[333]165if (msz < 1) msz = 1;
[344]166g->SelMarker(msz, mrk);
[333]167
[685]168PIGrCoord uxmin, uxmax, uymin, uymax;
169g->GetGrSpace(uxmin, uxmax, uymin, uymax);
170double xmin2 = uxmin;
171double ymin2 = uymin;
172double xmax2 = uxmax;
173double ymax2 = uymax;
174
[165]175nok = 0;
[326]176xp = yp = xl = yl = 0;
177for (int i=0; i<mNT->NbLines(); i++) {
178 xl = xp; yl = yp;
179 xp = mNT->GetCell(i, xK);
180 yp = mNT->GetCell(i, yK);
[686]181 if ( (xp < xmin2) || (xp > xmax2) || (yp < ymin2) || (yp > ymax2) ) continue;
182 nok++;
[165]183 if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
[1905]184 if ( (i > 0) && (GetGraphicAtt().GetLineAtt() != PI_NotDefLineAtt) )
185 g->DrawLine(xl, yl, xp, yp); // On relie les points ...
[165]186 if ( xebK >= 0 ) {
[326]187 xer = mNT->GetCell(i, xebK);
[165]188 if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp);
189 }
190 if ( yebK >= 0 ) {
[326]191 yer = mNT->GetCell(i, yebK);
[165]192 if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer);
193 }
[333]194 if (wK >= 0) { // Taille de marker en fonction du poids
195 wp = mNT->GetCell(i, wK);
196 sz = (int)((wp-wMin)/dw);
197 if (sz < 0) sz = 0;
198 if (sz > nWbins) sz = nWbins;
199 sz += msz;
200 if (sz < 2) g->SelMarker(sz, PI_DotMarker);
201 else g->SelMarker(sz, mrk);
202 }
[486]203 // Trace du marker
[1905]204 if ((wK >= 0)||(lK < 0)||(mmrk != PI_NotDefMarker)) g->DrawMarker(xp, yp);
[486]205 // Trace eventuel du label
206 if (lK >= 0) g->DrawString(xp, yp, mNT->GetCelltoString(i, lK).c_str());
207
[165]208}
209
[544]210if (stats) { // Trace de stats
[1905]211 g->SelFontSz((YMax() - YMin())/30);
[1645]212 // La hauteur de la cellule
[544]213 PIGrCoord a,d;
214 double cH = (double)g->GetFontHeight(a,d);
[1645]215 double cellHeight = 1.2 * cH;
216 // Les labels et leurs longueurs -> largeur de la cellule
217 char label[64];
218 sprintf(label, "Nd= %d / Ntot= %d", nok, mNT->NbLines());
[1644]219 double cellWidth = 1.1 * (double)g->CalcStringWidth(label);
[1645]220 double xu, yu, cw;
221 // Les limites du cadre
[548]222 xu = g->DeltaUCX(XMax(), - cellWidth);
223 yu = g->DeltaUCY(YMax(), - cellHeight);
224 g->DrawLine(xu, YMax(), xu, yu);
225 g->DrawLine(xu, yu, XMax(), yu);
[1645]226 // L'ecriture des labels (attention aux inversions possibles des axes!)
227 cw = (g->isAxeXDirRtoL()) ? -0.05*cellWidth : -0.95*cellWidth;
228 xu = g->DeltaUCX(XMax(),cw);
229 cw = (g->isAxeYDirUpDown()) ? -0.1*cH : -1.1*cH;
230 yu = g->DeltaUCY(YMax(),cw);
231 g->DrawString(xu,yu,label);
[544]232}
233
[165]234return;
235}
236
[344]237/* --Methode-- */
238void PINTuple::AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax)
239{
240if (!mNT) return;
241if ( (xK < 0) || (yK < 0) ) return;
242
243int ncnt = 0;
244double xp,yp;
245char buff[128];
246sprintf(buff,"PINTuple: NLines= %d NCol= %d \n", mNT->NbLines(), mNT->NbColumns());
247info += buff;
248info += mNT->LineHeaderToString();
249for (int i=0; i<mNT->NbLines(); i++) {
250 xp = mNT->GetCell(i, xK);
251 yp = mNT->GetCell(i, yK);
252 if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
253 ncnt++;
254 if (ncnt > 101) continue;
255 info += mNT->LineToString(i);
256 }
257if (ncnt >= 101) info += " .... \n";
258sprintf(buff," %d points inside selected region \n", ncnt);
259info += buff;
260// printf("PINTuple::AppendTextInfo()-DBG %g %g %g %g - %d\n", xmin, ymin, xmax, ymax, ncnt);
261return;
262}
[1971]263
264/* La methode DecodeOptionString permet de decoder un ensemble d'options
265 et de parametre d'affichage specifie sous forme d'un vecteur de string.
266 Si rmdecopt == true, les options decodees sont supprimees du vecteur
267 de string fourni en entree - ce qui permet l'enchainement eventuel
268 de plusieurs decodages de string.
269 Les options peuvent etre sous forme de flag : "stat" "nostat"
270 ou plus complexes, par exemple "dynamic=-3,3"
271 Rc: La methode renvoie le nombre d'options decodees
272*/
273
274/* --Methode-- */
275int PINTuple::DecodeOptionString(vector<string> & opt, bool rmdecopt)
276{
277 if (opt.size() < 1) return(0);
278 // On appelle d'abord le decodage de la classe PIDrawer de laquelle
279 // on herite. (Pas obligatoire) on decode donc ici les attributs de
280 // couleur, fontes ...
281 int ndec1 = PIDrawer::DecodeOptionString(opt, rmdecopt);
282 if ((opt.size() - ndec1) < 1) return(ndec1); // si tout a ete decode
283
284 vector<string> udopt; // On gardera ici les options non decodees
285 unsigned int k = 0;
286 int ndec = opt.size();
287 for( k=0; k<opt.size(); k++ ) {
288 string opts = opt[k];
289 if (opts == "stat") SetStats(true);
290 else if (opts == "nostat") SetStats(false);
291 else {
292 // Si option non decode
293 ndec--;
294 // S'il faut supprimer les options decodees
295 if (rmdecopt) udopt.push_back(opts);
296 }
297 }
298 // S'il faut supprimer les options decodees, on remplace l'argument opt
299 // par le vecteur des options non decodees.
300 if (rmdecopt) opt = udopt;
301 return(ndec+ndec1);
302}
[1975]303
304/* La methode GetOptionsHelpInfo(string& info) renvoie une chaine
305 avec la description des options comprises par ce drawer
306 Note: Il est preferable de ne pas initialiser la chaine
307 string info au depart, afin de permettre de mettre bout a
308 bout les aides de differents Drawer */
309
310/* --Methode-- */
311void PINTuple::GetOptionsHelpInfo(string& info)
312{
313 // On recupere d'abord la chaine info de la classe de base
314 PIDrawer::GetOptionsHelpInfo(info);
315 info += " ---- PINTuple options help info : \n" ;
316 info += " stat / nostat : activate/deactivate statistic information display \n";
317 return;
318}
Note: See TracBrowser for help on using the repository browser.