]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/PointSet.cxx
Getting rid of effC++ warnings about missing copy constructor and assignment operator.
[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(fRnrSelf == 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   RenderElement(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 RenderElement.
155
156   // printf("PointSetArray::~PointSetArray()\n");
157   delete [] fBins; fBins = 0;
158 }
159
160 void PointSetArray::Paint(Option_t* option)
161 {
162   if(fRnrSelf) {
163     for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
164       if((*i)->GetRnrSelf())
165         (*i)->GetObject()->Paint(option);
166     }
167   }
168 }
169
170 void PointSetArray::RemoveElementLocal(RenderElement* el)
171 {
172   for(Int_t i=0; i<fNBins; ++i) {
173     if(fBins[i] == el) {
174       fBins[i] = 0;
175       break;
176     }
177   }
178   RenderElement::RemoveElementLocal(el);
179 }
180
181 void PointSetArray::RemoveElements()
182 {
183   delete [] fBins; fBins = 0;
184   RenderElement::RemoveElements();
185 }
186
187 /**************************************************************************/
188
189 void PointSetArray::SetMarkerColor(Color_t tcolor)
190 {
191   for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
192     TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
193     if(m && m->GetMarkerColor() == fMarkerColor)
194       m->SetMarkerColor(tcolor);
195   }
196   TAttMarker::SetMarkerColor(tcolor);
197 }
198
199 void PointSetArray::SetMarkerStyle(Style_t mstyle)
200 {
201   for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
202     TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
203     if(m && m->GetMarkerStyle() == fMarkerStyle)
204       m->SetMarkerStyle(mstyle);
205   }
206   TAttMarker::SetMarkerStyle(mstyle);
207 }
208
209 void PointSetArray::SetMarkerSize(Size_t msize)
210 {
211   for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
212     TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
213     if(m && m->GetMarkerSize() == fMarkerSize)
214       m->SetMarkerSize(msize);
215   }
216   TAttMarker::SetMarkerSize(msize);
217 }
218
219 /**************************************************************************/
220
221 void PointSetArray::TakeAction(TSelectorDraw* sel)
222 {
223   static const Exc_t eH("PointSetArray::TakeAction ");
224
225   if(sel == 0)
226     throw(eH + "selector is <null>.");
227
228   Int_t n = sel->GetNfill();
229
230   // printf("PointSetArray::TakeAction n=%d\n", n);
231
232   Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
233   Double_t *qq = sel->GetV4();
234
235   if(qq == 0)
236     throw(eH + "requires 4-d varexp.");
237
238   switch(fSourceCS) {
239   case TVT_XYZ:
240     while(n-- > 0) {
241       Fill(*vx, *vy, *vz, *qq);
242       ++vx; ++vy; ++vz; ++qq;
243     }
244     break;
245   case TVT_RPhiZ:
246     while(n-- > 0) {
247       Fill(*vx * TMath::Cos(*vy), *vx * TMath::Sin(*vy), *vz, *qq);
248       ++vx; ++vy; ++vz; ++qq;
249     }
250     break;
251   default:
252     throw(eH + "unknown tree variable type.");
253   }
254 }
255
256 /**************************************************************************/
257
258 void PointSetArray::InitBins(const Text_t* quant_name,
259                              Int_t nbins, Double_t min, Double_t max,
260                              Bool_t addRe)
261 {
262   static const Exc_t eH("PointSetArray::InitBins ");
263
264   if(nbins < 1) throw(eH + "nbins < 1.");
265   if(min > max) throw(eH + "min > max.");
266
267   RemoveElements();
268
269   fQuantName = quant_name;
270   fNBins     = nbins;
271   fMin = fCurMin = min;
272   fMax = fCurMax = max;
273   fBinWidth  = (fMax - fMin)/fNBins;
274
275   fBins = new Reve::PointSet*[fNBins];
276   for(Int_t i=0; i<fNBins; ++i) {
277     fBins[i] = new Reve::PointSet
278       (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + i*fBinWidth, fMin + (i+1)*fBinWidth),
279        fDefPointSetCapacity);
280     fBins[i]->SetMarkerColor(fMarkerColor);
281     fBins[i]->SetMarkerStyle(fMarkerStyle);
282     fBins[i]->SetMarkerSize(fMarkerSize);
283     if(addRe)
284       gReve->AddRenderElement(this, fBins[i]);
285     else
286       AddElement(fBins[i]);
287   }
288 }
289
290 void PointSetArray::Fill(Double_t x, Double_t y, Double_t z, Double_t quant)
291 {
292   Int_t bin    = Int_t( (quant - fMin)/fBinWidth );
293   if(bin >= 0 && bin < fNBins && fBins[bin] != 0)
294     fBins[bin]->SetNextPoint(x, y, z);
295 }
296
297 void PointSetArray::CloseBins()
298 {
299   for(Int_t i=0; i<fNBins; ++i) {
300     if(fBins[i] != 0) {
301       // HACK! PolyMarker3D does half-management of array size.
302       // In fact, the error is mine, in pointset3d(gl) i use fN instead of Size().
303       // Fixed in my root, but not elsewhere.
304       fBins[i]->fN = fBins[i]->fLastPoint;
305
306       fBins[i]->ComputeBBox();
307     }
308   }
309 }
310
311 /**************************************************************************/
312
313 void PointSetArray::SetRange(Double_t min, Double_t max)
314 {
315   using namespace TMath;
316
317   fCurMin = min; fCurMax = max;
318   Int_t  low_b = (Int_t) Max(Double_t(0),       Floor((min-fMin)/fBinWidth));
319   Int_t high_b = (Int_t) Min(Double_t(fNBins-1), Ceil((max-fMin)/fBinWidth));
320   for(Int_t i=0; i<fNBins; ++i) {
321     if(fBins[i] != 0)
322       fBins[i]->SetRnrSelf(i>=low_b && i<=high_b);
323   }
324 }