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

Last change on this file since 2606 was 2547, checked in by ansari, 21 years ago

Suite (et presque fin) adaptation/codage options auto/rescaling ds PINTup3D - Reza 2 Juin 2004

File size: 11.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 aScxy = aScz = true;
51 UseSizeScale(true, 5);
52 UseColorScale(true);
53 ConnectPoints(false);
54 SelectXYZ(NULL, NULL, NULL);
55 SelectWt(NULL);
56 SelectErrBar();
57 SelectLabel(NULL);
58 SetName("NTup3DDrw");
59}
60
61PINTuple3D::~PINTuple3D()
62{
63 if (mAdDO && mNT) delete mNT;
64}
65
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
83/* --Methode-- */
84void PINTuple3D::SelectXYZ(const char* px, const char* py, const char* pz)
85{
86string name;
87if (mNT == NULL) xK = yK = zK = -1;
88if (px == NULL) xK = -1;
89else { name = px; xK = mNT->ColumnIndex(name); }
90if (py == NULL) yK = -1;
91else { name = py; yK = mNT->ColumnIndex(name); }
92if (pz == NULL) zK = -1;
93else { name = pz; zK = mNT->ColumnIndex(name); }
94}
95
96/* --Methode-- */
97void PINTuple3D::SelectWt(const char* pw)
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-- */
114void PINTuple3D::SelectErrBar(const char* erbx, const char* erby, const char* erbz)
115{
116string name;
117if (mNT == NULL) xebK = yebK = zebK = -1;
118if (erbx == NULL) xebK = -1;
119else { name = erbx; xebK = mNT->ColumnIndex(name); }
120if (erby == NULL) yebK = -1;
121else { name = erby; yebK = mNT->ColumnIndex(name); }
122if (erbz == NULL) zebK = -1;
123else { name = erbz; zebK = mNT->ColumnIndex(name); }
124}
125
126
127/* --Methode-- */
128void PINTuple3D::UpdateLimits()
129{
130 if (!mNT) return;
131 if (mNT->NbLines() <= 0) return;
132 if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
133
134 // Commencer par trouver nos limites
135 double xmin, xmax, ymin, ymax, zmin, zmax;
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
143 ComputeScaleFactor(xmin, xmax, ymin, ymax, zmin, zmax,
144 aScxy, aScz, 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;
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
154 double D = xmax-xmin;
155 if (D < (ymax-ymin)) D = ymax-ymin;
156 D *= 1.4;
157
158 Set3DView((xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)/2.,
159 (xmin+xmax)/2.+D , (ymin+ymax)/2.-2.5*D , zmin+(zmax-zmin)*0.85, 0.25, 0.25);
160
161 Set3DBox(xmin, xmax, ymin, ymax, zmin, zmax, mScx, mScy, mScz);
162
163 /*
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);
170 */
171
172
173// printf("PINTuple3D::UpdateLimits() : %g .. %g %g .. %g %g .. %g (%g) \n", xmin,xmax,ymin,ymax,zmin,zmax,D);
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-- */
181void PINTuple3D::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
182{
183double xp,yp,zp,wp,xer,yer,zer;
184double xl,yl,zl;
185int nok;
186
187// On trace les axes - En attendant de faire mieux - Reza 8/12/98
188if (axesFlags != kAxesNone) DrawAxes(g);
189
190if (!mNT) return;
191if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
192
193#if defined(CC_HAS_RTTI_SUPPORT)
194PIGraphic3D* g3 = dynamic_cast<PIGraphic3D*>(g);
195#else
196PIGraphic3D* g3 = (PIGraphic3D*)(g);
197#endif
198
199if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt) g3->SelLine(PI_ThinLine);
200
201// Pour tracer des markers avec taille fonction de Wt (poids)
202double dw = (wMax-wMin)/nWbins;
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
217int msz,sz;
218
219PIMarker mmrk = GetGraphicAtt().GetMarker();
220PIMarker mrk;
221if (wK >= 0) mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_CircleMarker;
222else mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_DotMarker;
223msz = GetGraphicAtt().GetMarkerSz();
224if (msz < 1) msz = 1;
225g->SelMarker(msz, mrk);
226
227nok = 0;
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);
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
253 if ( (i > 0) && connectPts ) // On relie les points ...
254 g3->DrawLine3D(ScaleX(xl), ScaleY(yl), ScaleZ(zl), ScaleX(xp), ScaleY(yp), ScaleZ(zp));
255 nok++;
256 if ( xebK >= 0 ) {
257 xer = mNT->GetCell(i, xebK);
258 g3->DrawLine3D(ScaleX(xp-xer), ScaleY(yp), ScaleZ(zp), ScaleX(xp+xer), ScaleY(yp), ScaleZ(zp) );
259 }
260 if ( yebK >= 0 ) {
261 yer = mNT->GetCell(i, yebK);
262 g3->DrawLine3D(ScaleX(xp), ScaleY(yp-yer), ScaleZ(zp), ScaleX(xp), ScaleY(yp+yer), ScaleZ(zp) );
263 }
264 if ( zebK >= 0 ) {
265 zer = mNT->GetCell(i, zebK);
266 g3->DrawLine3D(ScaleX(xp), ScaleY(yp), ScaleZ(zp-zer), ScaleX(xp), ScaleY(yp), ScaleZ(zp+zer));
267 }
268 // Trace du marker
269 if ((wK >= 0)||(lK < 0)||(mmrk != PI_NotDefMarker))
270 g3->DrawMarker3D(ScaleX(xp), ScaleY(yp), ScaleZ(zp));
271 // Trace eventuel du label
272 if (lK >= 0) g3->DrawString3D(ScaleX(xp), ScaleY(yp), ScaleZ(zp),
273 mNT->GetCelltoString(i, lK).c_str());
274}
275
276return;
277}
278
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 : "connectpoints" "noconnectpoints"
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 = PIDrawer3D::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 == "connectpoints") ConnectPoints(true);
306 else if (opts == "noconnectpoints") ConnectPoints(false);
307 else if (opts == "colorscale") UseColorScale(true);
308 else if (opts == "nocolorscale") UseColorScale(false);
309 else if (opts == "sizescale") UseSizeScale(true);
310 else if (opts == "nosizescale") UseSizeScale(false);
311 else if (opts.substr(0,10) == "sizescale=") {
312 int nbn = atoi(opts.substr(10).c_str());
313 UseSizeScale(true, nbn);
314 }
315 else {
316 // Si option non decode
317 ndec--;
318 // S'il faut supprimer les options decodees
319 if (rmdecopt) udopt.push_back(opts);
320 }
321 }
322 // S'il faut supprimer les options decodees, on remplace l'argument opt
323 // par le vecteur des options non decodees.
324 if (rmdecopt) opt = udopt;
325 return(ndec+ndec1);
326}
327
328int PINTuple3D::OptionToString(vector<string> & opt) const
329{
330 PIDrawer3D::OptionToString(opt);
331
332 if(connectPts) opt.push_back("connectpoints");
333 else opt.push_back("noconnectpoints");
334
335 if(colorScale) opt.push_back("colorscale");
336 else opt.push_back("nocolorscale");
337
338 if(mrkSzScale) {
339 char str[256];
340 if(nWbins>0) {sprintf(str,"sizescale=%d",nWbins); opt.push_back(str);}
341 else opt.push_back("sizescale");
342 } else opt.push_back("nosizescale");
343
344 return 1;
345}
346
347/* La methode GetOptionsHelpInfo(string& info) renvoie une chaine
348 avec la description des options comprises par ce drawer
349 Note: Il est preferable de ne pas initialiser la chaine
350 string info au depart, afin de permettre de mettre bout a
351 bout les aides de differents Drawer */
352
353/* --Methode-- */
354void PINTuple3D::GetOptionsHelpInfo(string& info)
355{
356info += " ---- PINTuple3D options help info : \n" ;
357info += " connectpoints: The points are connected by a line \n";
358info += " noconnectpoints (this is the default) \n";
359info += " colorscale/nocolorscale (Use color scale for weight) \n";
360info += " sizescale/sizescale=nbins/nosizescale (Use marker size for weight) \n";
361// On recupere ensuite la chaine info de la classe de base
362PIDrawer3D::GetOptionsHelpInfo(info);
363return;
364}
365
Note: See TracBrowser for help on using the repository browser.