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

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

ResizeMinMax: cmv 17/07/2002

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