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