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

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

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

File size: 6.6 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;
50 SelectXYZ(NULL, NULL, NULL);
[486]51 SelectWt(NULL, 1);
[165]52 SelectErrBar();
[486]53 SelectLabel(NULL);
[1856]54 SetName("NTup3DDrw");
[165]55}
56
57PINTuple3D::~PINTuple3D()
58{
59 if (mAdDO && mNT) delete mNT;
60}
61
[537]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
[165]79/* --Methode-- */
80void PINTuple3D::SelectXYZ(const char* px, const char* py, const char* pz)
81{
[326]82string name;
[165]83if (mNT == NULL) xK = yK = zK = -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]88if (pz == NULL) zK = -1;
[326]89else { name = pz; zK = mNT->ColumnIndex(name); }
[165]90}
91
92/* --Methode-- */
[486]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-- */
[165]111void PINTuple3D::SelectErrBar(const char* erbx, const char* erby, const char* erbz)
112{
[326]113string name;
[165]114if (mNT == NULL) xebK = yebK = zebK = -1;
115if (erbx == NULL) xebK = -1;
[326]116else { name = erbx; xebK = mNT->ColumnIndex(name); }
[165]117if (erby == NULL) yebK = -1;
[326]118else { name = erby; yebK = mNT->ColumnIndex(name); }
[165]119if (erbz == NULL) zebK = -1;
[326]120else { name = erbz; zebK = mNT->ColumnIndex(name); }
[165]121}
122
123
124/* --Methode-- */
125void PINTuple3D::UpdateLimits()
126{
[326]127 if (!mNT) return;
128 if (mNT->NbLines() <= 0) return;
[165]129 if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
130
131 // Commencer par trouver nos limites
[326]132 double xmin, xmax, ymin, ymax, zmin, zmax;
[165]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
[205]143 double D = xmax-xmin;
[165]144 if (D < (ymax-ymin)) D = ymax-ymin;
145 D *= 1.4;
146
147 Set3DView((xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)/2.,
[185]148 (xmin+xmax)/2.+D , (ymin+ymax)/2.-2.5*D , zmin+(zmax-zmin)*0.85, 0.25, 0.25);
[171]149
[2092]150 x3Min = xmin; // - PERC_GARDE*(xmax-xmin);
151 x3Max = xmax; // + PERC_GARDE*(xmax-xmin);
152 y3Min = ymin; // - PERC_GARDE*(ymax-ymin);
153 y3Max = ymax; // + PERC_GARDE*(ymax-ymin);
154 z3Min = zmin; // - PERC_GARDE*(zmax-zmin);
155 z3Max = zmax; // + PERC_GARDE*(zmax-zmin);
[171]156
[326]157// printf("PINTuple3D::UpdateLimits() : %g .. %g %g .. %g %g .. %g (%g) \n", xmin,xmax,ymin,ymax,zmin,zmax,D);
[165]158// printf("PINTuple3D::UpdateLimits() : %g %g %g << %g %g %g \n",
159// (xmin+xmax)/2., (ymin+ymax)/2, (zmin+zmax)*0.5,
160// (xmin+xmax)/2.+D , (ymin+ymax)/2.+2.*D , zmin+(zmax-zmin)*0.1);
161}
162
163
164/* --Methode-- */
[205]165void PINTuple3D::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
[165]166{
[486]167double xp,yp,zp,wp,xer,yer,zer;
[326]168double xl,yl,zl;
[165]169int nok;
170
[185]171// On trace les axes - En attendant de faire mieux - Reza 8/12/98
172if (axesFlags != kAxesNone) DrawAxes(g);
173
[165]174if (!mNT) return;
175if ( (xK < 0) || (yK < 0) || (zK < 0) ) return;
176
[440]177#if defined(CC_HAS_RTTI_SUPPORT)
[165]178PIGraphic3D* g3 = dynamic_cast<PIGraphic3D*>(g);
179#else
180PIGraphic3D* g3 = (PIGraphic3D*)(g);
181#endif
182
[1905]183if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt) g3->SelLine(PI_ThinLine);
[165]184
[486]185// Pour tracer des markers avec taille fonction de Wt (poids)
186double dw = (wMax-wMin)/nWbins;
187if (dw < 1.e-19) dw = 1.e19;
188int msz,sz;
189
[1905]190PIMarker mmrk = GetGraphicAtt().GetMarker();
[486]191PIMarker mrk;
[1905]192if (wK >= 0) mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_CircleMarker;
193else mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_DotMarker;
194msz = GetGraphicAtt().GetMarkerSz();
[486]195if (msz < 1) msz = 1;
196g->SelMarker(msz, mrk);
197
[165]198nok = 0;
[326]199xp = yp = zp = xl = yl = zl = 0;
200for (int i=0; i<mNT->NbLines(); i++) {
201 xl = xp; yl = yp; zl = zp;
202 xp = mNT->GetCell(i, xK);
203 yp = mNT->GetCell(i, yK);
204 zp = mNT->GetCell(i, zK);
[1905]205 if ( (i > 0) &&
206 (GetGraphicAtt().GetLineAtt() != PI_NotDefLineAtt) ) // On relie les points ...
[326]207 g3->DrawLine3D(xl, yl, zl, xp, yp, zp);
[165]208 nok++;
209 if ( xebK >= 0 ) {
[326]210 xer = mNT->GetCell(i, xebK);
[165]211 g3->DrawLine3D(xp-xer, yp, zp, xp+xer, yp, zp);
212 }
213 if ( yebK >= 0 ) {
[326]214 yer = mNT->GetCell(i, yebK);
[165]215 g3->DrawLine3D(xp, yp-yer, zp, xp, yp+yer, zp);
216 }
217 if ( zebK >= 0 ) {
[326]218 zer = mNT->GetCell(i, zebK);
[165]219 g3->DrawLine3D(xp, yp, zp-zer, xp, yp, zp+zer);
220 }
[486]221 if (wK >= 0) { // Taille de marker en fonction du poids
222 wp = mNT->GetCell(i, wK);
223 sz = (int)((wp-wMin)/dw);
224 if (sz < 0) sz = 0;
225 if (sz > nWbins) sz = nWbins;
226 sz += msz;
227 if (sz < 2) g->SelMarker(sz, PI_DotMarker);
228 else g->SelMarker(sz, mrk);
229 }
230 // Trace du marker
[1905]231 if ((wK >= 0)||(lK < 0)||(mmrk != PI_NotDefMarker)) g3->DrawMarker3D(xp, yp, zp);
[486]232 // Trace eventuel du label
233 if (lK >= 0) g3->DrawString3D(xp, yp, zp, mNT->GetCelltoString(i, lK).c_str());
[165]234}
235
236return;
237}
238
Note: See TracBrowser for help on using the repository browser.