]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/PointSet.cxx
Add Getters and Setters in TrackRnrStyle and TrackList to define rendering of path...
[u/mrichter/AliRoot.git] / EVE / Reve / PointSet.cxx
1 // $Header$
2
3 #include "PointSet.h"
4
5 #include <Reve/RGTopFrame.h>
6
7 #include <TTree.h>
8 #include <TTreePlayer.h>
9 #include <TF3.h>
10
11 #include <TColor.h>
12 #include <TCanvas.h>
13
14 using namespace Reve;
15
16 //______________________________________________________________________
17 // PointSet
18 //
19
20 ClassImp(PointSet)
21
22 PointSet::PointSet(Int_t n_points, TreeVarType_e tv_type) :
23   RenderElement(fMarkerColor),
24   TPointSet3D(n_points),
25   TPointSelectorConsumer(tv_type),
26
27   fTitle()
28 {
29   fMarkerStyle = 20;
30 }
31
32 PointSet::PointSet(const Text_t* name, Int_t n_points, TreeVarType_e tv_type) :
33   RenderElement(fMarkerColor),
34   TPointSet3D(n_points),
35   TPointSelectorConsumer(tv_type),
36
37   fTitle()
38 {
39   fMarkerStyle = 20;
40   SetName(name);
41 }
42
43 PointSet::PointSet(const Text_t* name, TTree* tree, TreeVarType_e tv_type) :
44   RenderElement(fMarkerColor),
45   TPointSet3D(tree->GetSelectedRows()),
46   TPointSelectorConsumer(tv_type),
47
48   fTitle()
49 {
50   static const Exc_t eH("PointSet::PointSet ");
51
52   fMarkerStyle = 20;
53   SetName(name);
54
55   TTreePlayer* tp = dynamic_cast<TTreePlayer*>(tree->GetPlayer());
56   TakeAction(dynamic_cast<TSelectorDraw*>(tp->GetSelector()));
57 }
58
59 /**************************************************************************/
60
61 void PointSet::Reset(Int_t n_points)
62 {
63   delete [] fP; fP = 0;
64   fN = n_points;
65   if(fN) fP = new Float_t [3*fN];
66   memset(fP, 0, 3*fN*sizeof(Float_t));
67   fLastPoint = -1;
68   ClearIds();
69   ResetBBox();
70 }
71
72 Int_t PointSet::GrowFor(Int_t n_points)
73 {
74   // Resizes internal array to allow additional n_points to be stored.
75   // Returns the old size which is also the location where one can
76   // start storing new data.
77   // The caller is *obliged* to fill the new point slots.
78
79   Int_t old_size = Size();
80   Int_t new_size = old_size + n_points;
81   SetPoint(new_size - 1, 0, 0, 0);
82   return old_size;
83 }
84
85 /**************************************************************************/
86
87 void PointSet::Paint(Option_t* option)
88 {
89   if(fRnrElement == kFALSE) return;
90
91   TPointSet3D::Paint(option);
92 }
93
94 /**************************************************************************/
95
96 void PointSet::TakeAction(TSelectorDraw* sel)
97 {
98   static const Exc_t eH("PointSet::TakeAction ");
99
100   if(sel == 0)
101     throw(eH + "selector is <null>.");
102
103   Int_t    n = sel->GetNfill();
104   Int_t  beg = GrowFor(n);
105   Float_t *p = fP + 3*beg;
106
107   // printf("PointSet::TakeAction beg=%d n=%d size=%d\n", beg, n, Size());
108
109   Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
110
111   switch(fSourceCS) {
112   case TVT_XYZ:
113     while(n-- > 0) {
114       p[0] = *vx; p[1] = *vy; p[2] = *vz;
115       p += 3;
116       ++vx; ++vy; ++vz;
117     }
118     break;
119   case TVT_RPhiZ:
120     while(n-- > 0) {
121       p[0] = *vx * TMath::Cos(*vy); p[1] = *vx * TMath::Sin(*vy); p[2] = *vz;
122       p += 3;
123       ++vx; ++vy; ++vz;
124     }
125     break;
126   default:
127     throw(eH + "unknown tree variable type.");
128   }
129 }
130
131 /**************************************************************************/
132 /**************************************************************************/
133
134 //______________________________________________________________________
135 // PointSetArray
136 //
137
138 ClassImp(PointSetArray)
139
140 PointSetArray::PointSetArray(const Text_t* name,
141                              const Text_t* title) :
142   RenderElementListBase(fMarkerColor),
143   TNamed(name, title),
144
145   fBins(0), fDefPointSetCapacity(128), fNBins(0),
146   fMin(0), fCurMin(0), fMax(0), fCurMax(0),
147   fBinWidth(0),
148   fQuantName()
149 {}
150
151 PointSetArray::~PointSetArray()
152 {
153   // Destructor: deletes the fBins array. Actual removal of
154   // elements done by RenderElementListBase.
155
156   // printf("PointSetArray::~PointSetArray()\n");
157   delete [] fBins; fBins = 0;
158 }
159
160 void PointSetArray::RemoveElementLocal(RenderElement* el)
161 {
162   for(Int_t i=0; i<fNBins; ++i) {
163     if(fBins[i] == el) {
164       fBins[i] = 0;
165       break;
166     }
167   }
168   RenderElementListBase::RemoveElementLocal(el);
169 }
170
171 void PointSetArray::RemoveElements()
172 {
173   delete [] fBins; fBins = 0;
174   RenderElementListBase::RemoveElements();
175 }
176
177 /**************************************************************************/
178
179 void PointSetArray::SetMarkerColor(Color_t tcolor)
180 {
181   for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
182     TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
183     if(m && m->GetMarkerColor() == fMarkerColor)
184       m->SetMarkerColor(tcolor);
185   }
186   TAttMarker::SetMarkerColor(tcolor);
187 }
188
189 void PointSetArray::SetMarkerStyle(Style_t mstyle)
190 {
191   for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
192     TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
193     if(m && m->GetMarkerStyle() == fMarkerStyle)
194       m->SetMarkerStyle(mstyle);
195   }
196   TAttMarker::SetMarkerStyle(mstyle);
197 }
198
199 void PointSetArray::SetMarkerSize(Size_t msize)
200 {
201   for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
202     TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
203     if(m && m->GetMarkerSize() == fMarkerSize)
204       m->SetMarkerSize(msize);
205   }
206   TAttMarker::SetMarkerSize(msize);
207 }
208
209 /**************************************************************************/
210
211 void PointSetArray::TakeAction(TSelectorDraw* sel)
212 {
213   static const Exc_t eH("PointSetArray::TakeAction ");
214
215   if(sel == 0)
216     throw(eH + "selector is <null>.");
217
218   Int_t n = sel->GetNfill();
219
220   // printf("PointSetArray::TakeAction n=%d\n", n);
221
222   Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
223   Double_t *qq = sel->GetV4();
224
225   if(qq == 0)
226     throw(eH + "requires 4-d varexp.");
227
228   switch(fSourceCS) {
229   case TVT_XYZ:
230     while(n-- > 0) {
231       Fill(*vx, *vy, *vz, *qq);
232       ++vx; ++vy; ++vz; ++qq;
233     }
234     break;
235   case TVT_RPhiZ:
236     while(n-- > 0) {
237       Fill(*vx * TMath::Cos(*vy), *vx * TMath::Sin(*vy), *vz, *qq);
238       ++vx; ++vy; ++vz; ++qq;
239     }
240     break;
241   default:
242     throw(eH + "unknown tree variable type.");
243   }
244 }
245
246 /**************************************************************************/
247
248 void PointSetArray::InitBins(const Text_t* quant_name,
249                              Int_t nbins, Double_t min, Double_t max,
250                              Bool_t addRe)
251 {
252   static const Exc_t eH("PointSetArray::InitBins ");
253
254   if(nbins < 1) throw(eH + "nbins < 1.");
255   if(min > max) throw(eH + "min > max.");
256
257   RemoveElements();
258
259   fQuantName = quant_name;
260   fNBins     = nbins;
261   fMin = fCurMin = min;
262   fMax = fCurMax = max;
263   fBinWidth  = (fMax - fMin)/fNBins;
264
265   fBins = new Reve::PointSet*[fNBins];
266   for(Int_t i=0; i<fNBins; ++i) {
267     fBins[i] = new Reve::PointSet
268       (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + i*fBinWidth, fMin + (i+1)*fBinWidth),
269        fDefPointSetCapacity);
270     fBins[i]->SetMarkerColor(fMarkerColor);
271     fBins[i]->SetMarkerStyle(fMarkerStyle);
272     fBins[i]->SetMarkerSize(fMarkerSize);
273     if(addRe)
274       gReve->AddRenderElement(this, fBins[i]);
275     else
276       AddElement(fBins[i]);
277   }
278 }
279
280 void PointSetArray::Fill(Double_t x, Double_t y, Double_t z, Double_t quant)
281 {
282   Int_t bin    = Int_t( (quant - fMin)/fBinWidth );
283   if(bin >= 0 && bin < fNBins && fBins[bin] != 0)
284     fBins[bin]->SetNextPoint(x, y, z);
285 }
286
287 void PointSetArray::CloseBins()
288 {
289   for(Int_t i=0; i<fNBins; ++i) {
290     if(fBins[i] != 0) {
291       // HACK! PolyMarker3D does half-management of array size.
292       // In fact, the error is mine, in pointset3d(gl) i use fN instead of Size().
293       // Fixed in my root, but not elsewhere.
294       fBins[i]->fN = fBins[i]->fLastPoint;
295
296       fBins[i]->ComputeBBox();
297     }
298   }
299 }
300
301 /**************************************************************************/
302
303 void PointSetArray::SetRange(Double_t min, Double_t max)
304 {
305   using namespace TMath;
306
307   fCurMin = min; fCurMax = max;
308   Int_t  low_b = (Int_t) Max(Double_t(0),       Floor((min-fMin)/fBinWidth));
309   Int_t high_b = (Int_t) Min(Double_t(fNBins-1), Ceil((max-fMin)/fBinWidth));
310   for(Int_t i=0; i<fNBins; ++i) {
311     if(fBins[i] != 0)
312       fBins[i]->SetRnrElement(i>=low_b && i<=high_b);
313   }
314 }