Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REvePointSet.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include <ROOT/REvePointSet.hxx>
13
14#include <ROOT/REveManager.hxx>
16#include <ROOT/REveTrans.hxx>
18
19#include "TArrayI.h"
20#include "TClass.h"
21
22#include <nlohmann/json.hpp>
23
24using namespace ROOT::Experimental;
25
26/** \class REvePointSet
27\ingroup REve
28REvePointSet is a render-element holding a collection of 3D points with
29optional per-point TRef and an arbitrary number of integer ids (to
30be used for signal, volume-id, track-id, etc).
31
323D point representation is implemented in base-class TPolyMarker3D.
33Per-point TRef is implemented in base-class TPointSet3D.
34
35By using the REvePointSelector the points and integer ids can be
36filled directly from a TTree holding the source data.
37Setting of per-point TRef's is not supported.
38
39REvePointSet is a REveProjectable: it can be projected by using the
40REveProjectionManager class.
41*/
42
43////////////////////////////////////////////////////////////////////////////////
44/// Constructor.
45
46REvePointSet::REvePointSet(const std::string& name, const std::string& title, Int_t n_points) :
47 REveElement(name, title),
49 TAttMarker(),
50 TAttBBox(),
52{
53 fMarkerStyle = 20;
54
56
57 Reset(n_points);
58
59 // Override from REveElement.
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Copy constructor.
65
70 TAttBBox(e),
72{
73 fAlwaysSecSelect = e.GetAlwaysSecSelect();
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Destructor.
79
81{
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Clone points and all point-related information from point-set 'e'.
86
88{
89 fPoints = e.fPoints;
90 fCapacity = e.fCapacity;
91 fSize = e.fSize;
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Drop all data and set-up the data structures to recive new data.
96/// n_points specifies the initial size of the array.
97
99{
100 fPoints.resize(n_points);
101 fCapacity = n_points;
102 fSize = 0;
103
104 ResetBBox();
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Resizes internal array to allow additional n_points to be stored.
109/// Returns the old size which is also the location where one can
110/// start storing new data.
111/// The caller is *obliged* to fill the new point slots.
112
114{
115 assert(n_points >= 0);
116
117 Int_t old_size = fCapacity;
118 Int_t new_size = old_size + n_points;
119
120 fPoints.resize(new_size);
121 fCapacity = new_size;
122
123 return old_size;
124}
125
126int REvePointSet::SetNextPoint(float x, float y, float z)
127{
128 return SetPoint(fSize, x, y, z);
129}
130
131int REvePointSet::SetPoint(int n, float x, float y, float z)
132{
133 if (n >= fCapacity)
134 {
135 fCapacity = std::max(n + 1, 2*fCapacity);
136 fPoints.resize(fCapacity);
137 }
138 fPoints[n].Set(x, y, z);
139 if (n >= fSize)
140 {
141 fSize = n + 1;
142 }
143 return fSize;
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Set marker style, propagate to projecteds.
148
150{
151 for (auto &pi: fProjectedList)
152 {
153 REvePointSet* pt = dynamic_cast<REvePointSet *>(pi);
154 if (pt)
155 {
156 pt->SetMarkerStyle(mstyle);
157 pt->StampObjProps();
158 }
159 }
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// Set marker size, propagate to projecteds.
165
167{
168 for (auto &pi: fProjectedList)
169 {
170 REvePointSet* pt = dynamic_cast<REvePointSet *>(pi);
171 if (pt)
172 {
173 pt->SetMarkerSize(msize);
174 pt->StampObjProps();
175 }
176 }
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// Copy visualization parameters from element el.
183
185{
186 const REvePointSet* m = dynamic_cast<const REvePointSet*>(el);
187 if (m)
188 {
189 TAttMarker::operator=(*m);
190 }
191
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// Write visualization parameters.
197
198void REvePointSet::WriteVizParams(std::ostream& out, const TString& var)
199{
201
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Virtual from REveProjectable, returns REvePointSetProjected class.
207
209{
210 return TClass::GetClass<REvePointSetProjected>();
211}
212
213
215{
216 if (gEve->IsRCore())
218
219 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
220
221 if (gEve->IsRCore()) {
222 j["fSize"] = fSize;
223 j["fTexX"] = fTexX;
224 j["fTexY"] = fTexY;
225 }
226 j["fMarkerSize"] = GetMarkerSize();
227 j["fMarkerColor"] = GetMarkerColor();
228 j["fSecondarySelect"] = fAlwaysSecSelect;
229
230 return ret;
231}
232
233////////////////////////////////////////////////////////////////////////////////
234/// Crates 3D point array for rendering.
235
237{
238 if (fSize > 0)
239 {
240 if (gEve->IsRCore()) {
241 fRenderData = std::make_unique<REveRenderData>("makeHit", 4*fTexX*fTexY);
242 for (int i = 0; i < fSize; ++i) {
243 fRenderData->PushV(&fPoints[i].fX, 3);
244 fRenderData->PushV(0);
245 }
246 fRenderData->ResizeV(4*fTexX*fTexY);
247 } else {
248 fRenderData = std::make_unique<REveRenderData>("makeHit", 3*fSize);
249 fRenderData->PushV(&fPoints[0].fX, 3*fSize);
250 }
251 }
252}
253
254////////////////////////////////////////////////////////////////////////////////
255/// Compute bounding box.
256
258{
259 if (fSize > 0) {
260 BBoxInit();
261 for (auto &p : fPoints)
262 {
263 BBoxCheckPoint(p.fX, p.fY, p.fZ);
264 }
265 } else {
266 BBoxZero();
267 }
268}
269
270////////////////////////////////////////////////////////////////////////////////
271/// Virtual method of base class TPointSet3D. The function call is
272/// invoked with secondary selection in TPointSet3DGL.
273
275{
276 // Emit("PointSelected(Int_t)", id);
277}
278
279
280//==============================================================================
281// REvePointSetArray
282//==============================================================================
283
284/** \class REvePointSetArray
285\ingroup REve
286An array of point-sets with each point-set playing a role of a bin
287in a histogram. When a new point is added to a REvePointSetArray,
288an additional separating quantity needs to be specified: it
289determines into which REvePointSet (bin) the point will actually be
290stored. Underflow and overflow bins are automatically created but
291they are not drawn by default.
292
293By using the REvePointSelector the points and the separating
294quantities can be filled directly from a TTree holding the source
295data.
296Setting of per-point TRef's is not supported.
297
298After the filling, the range of separating variable can be
299controlled with a slider to choose a sub-set of PointSets that are
300actually shown.
301*/
302
303////////////////////////////////////////////////////////////////////////////////
304/// Constructor.
305
307 const std::string& title) :
308 REveElement(name, title),
309
310 fBins(nullptr), fDefPointSetCapacity(128), fNBins(0), fLastBin(-1),
311 fMin(0), fCurMin(0), fMax(0), fCurMax(0),
312 fBinWidth(0),
313 fQuantName()
314{
316}
317
318////////////////////////////////////////////////////////////////////////////////
319/// Destructor: deletes the fBins array. Actual removal of
320/// elements done by REveElement.
321
323{
324 // printf("REvePointSetArray::~REvePointSetArray()\n");
325 delete [] fBins; fBins = nullptr;
326}
327
328////////////////////////////////////////////////////////////////////////////////
329/// Virtual from REveElement, provide bin management.
330
332{
333 for (Int_t i=0; i<fNBins; ++i) {
334 if (fBins[i] == el) {
335 fBins[i] = nullptr;
336 break;
337 }
338 }
339}
340
341////////////////////////////////////////////////////////////////////////////////
342/// Virtual from REveElement, provide bin management.
343
345{
346 delete [] fBins; fBins = nullptr; fLastBin = -1;
347}
348
349////////////////////////////////////////////////////////////////////////////////
350/// Set marker color, propagate to children.
351
353{
354 for (auto & el : fChildren)
355 {
356 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
357 if (m && m->GetMarkerColor() == fMarkerColor)
358 m->SetMarkerColor(tcolor);
359 }
361}
362
363////////////////////////////////////////////////////////////////////////////////
364/// Set marker style, propagate to children.
365
367{
368 for (auto & el : fChildren)
369 {
370 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
371 if (m && m->GetMarkerStyle() == fMarkerStyle)
372 m->SetMarkerStyle(mstyle);
373 }
375}
376
377////////////////////////////////////////////////////////////////////////////////
378/// Set marker size, propagate to children.
379
381{
382 for (auto & el : fChildren)
383 {
384 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
385 if (m && m->GetMarkerSize() == fMarkerSize)
386 m->SetMarkerSize(msize);
387 }
389}
390
391////////////////////////////////////////////////////////////////////////////////
392/// Get the total number of filled points.
393/// 'under' and 'over' flags specify if under/overflow channels
394/// should be added to the sum.
395
397{
398 Int_t size = 0;
399 const Int_t min = under ? 0 : 1;
400 const Int_t max = over ? fNBins : fNBins - 1;
401 for (Int_t i = min; i < max; ++i)
402 {
403 if (fBins[i])
404 size += fBins[i]->GetSize();
405 }
406 return size;
407}
408
409////////////////////////////////////////////////////////////////////////////////
410/// Initialize internal point-sets with given binning parameters.
411/// The actual number of bins is nbins+2, bin 0 corresponding to
412/// underflow and bin nbin+1 to owerflow pointset.
413
414void REvePointSetArray::InitBins(const std::string& quant_name,
415 Int_t nbins, Double_t min, Double_t max)
416{
417 static const REveException eh("REvePointSetArray::InitBins ");
418
419 if (nbins < 1) throw eh + "nbins < 1.";
420 if (min > max) throw eh + "min > max.";
421
423
424 fQuantName = quant_name;
425 fNBins = nbins + 2; // under/overflow
426 fLastBin = -1;
427 fMin = fCurMin = min;
428 fMax = fCurMax = max;
429 fBinWidth = (fMax - fMin)/(fNBins - 2);
430
431 fBins = new REvePointSet* [fNBins];
432
433 for (Int_t i = 0; i < fNBins; ++i)
434 {
435 fBins[i] = new REvePointSet
436 (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + (i-1)*fBinWidth, fMin + i*fBinWidth),
437 "",
442 AddElement(fBins[i]);
443 }
444
445 fBins[0]->SetName("Underflow");
447
448 fBins[fNBins-1]->SetName("Overflow");
450}
451
452////////////////////////////////////////////////////////////////////////////////
453/// Add a new point. Appropriate point-set will be chosen based on
454/// the value of the separating quantity 'quant'.
455/// If the selected bin does not have an associated REvePointSet
456/// the point is discarded and false is returned.
457
459{
460 fLastBin = TMath::FloorNint((quant - fMin)/fBinWidth) + 1;
461
462 if (fLastBin < 0)
463 {
464 fLastBin = 0;
465 }
466 else if (fLastBin > fNBins - 1)
467 {
468 fLastBin = fNBins - 1;
469 }
470
471 if (fBins[fLastBin] != 0)
472 {
474 return kTRUE;
475 }
476 else
477 {
478 return kFALSE;
479 }
480}
481
482////////////////////////////////////////////////////////////////////////////////
483/// Call this after all the points have been filled.
484/// At this point we can calculate bounding-boxes of individual
485/// point-sets.
486
488{
489 for (Int_t i=0; i<fNBins; ++i)
490 {
491 if (fBins[i])
492 {
493 fBins[i]->SetTitle(Form("N=%d", fBins[i]->GetSize()));
494 fBins[i]->ComputeBBox();
495 }
496 }
497 fLastBin = -1;
498}
499
500////////////////////////////////////////////////////////////////////////////////
501/// Set active range of the separating quantity.
502/// Appropriate point-sets are tagged for rendering.
503/// Over/underflow point-sets are left as they were.
504
506{
507 using namespace TMath;
508
509 fCurMin = min; fCurMax = max;
510 Int_t low_b = Max(0, FloorNint((min-fMin)/fBinWidth)) + 1;
511 Int_t high_b = Min(fNBins-2, CeilNint ((max-fMin)/fBinWidth));
512
513 for (Int_t i = 1; i < fNBins - 1; ++i)
514 {
515 if (fBins[i])
516 fBins[i]->SetRnrSelf(i>=low_b && i<=high_b);
517 }
518}
519
520/** \class REvePointSetProjected
521\ingroup REve
522Projected copy of a REvePointSet.
523*/
524
525////////////////////////////////////////////////////////////////////////////////
526/// Default contructor.
527
529 REvePointSet (),
531{
532}
533
534////////////////////////////////////////////////////////////////////////////////
535/// Set projection manager and projection model.
536/// Virtual from REveProjected.
537
539 REveProjectable* model)
540{
541 REveProjected::SetProjection(proj, model);
542 CopyVizParams(dynamic_cast<REveElement*>(model));
543}
544
545////////////////////////////////////////////////////////////////////////////////
546/// Set depth (z-coordinate) of the projected points.
547
549{
550 SetDepthCommon(d, this, fBBox);
551
552 // XXXX rewrite
553
554 Int_t n = fSize;
555 Float_t *p = & fPoints[0].fZ;
556 for (Int_t i = 0; i < n; ++i, p+=3)
557 *p = fDepth;
558}
559
560////////////////////////////////////////////////////////////////////////////////
561/// Re-apply the projection.
562/// Virtual from REveProjected.
563
565{
567 REvePointSet &ps = * dynamic_cast<REvePointSet*>(fProjectable);
568 REveTrans *tr = ps.PtrMainTrans(kFALSE);
569
571
572 // XXXX rewrite
573
574 Int_t n = ps.GetSize();
575 Reset(n);
576 fSize = n;
577
578 if (n == 0)
579 return;
580
581 const Float_t *o = & ps.RefPoint(0).fX;
582 Float_t *p = & fPoints[0].fX;
583 for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
584 {
585 proj.ProjectPointfv(tr, o, p, fDepth);
586 }
587}
588
589////////////////////////////////////////////////////////////////////////////////
590/// Virtual method of base class TPointSet3D.
591/// Forward to projectable.
592
594{
595 REvePointSet *ps = dynamic_cast<REvePointSet*>(fProjectable);
596 ps->PointSelected(id);
597}
#define d(i)
Definition RSha256.hxx:102
#define e(i)
Definition RSha256.hxx:103
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
short Style_t
Definition RtypesCore.h:89
short Color_t
Definition RtypesCore.h:92
float Size_t
Definition RtypesCore.h:96
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
winID h TVirtualViewer3D TVirtualGLPainter p
char name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2468
void SetMainColorPtr(Color_t *colptr)
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
virtual void AddElement(REveElement *el)
Add el to the list of children.
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write-out visual parameters for this object.
void SetTitle(const std::string &title)
Set title of an element.
std::unique_ptr< REveRenderData > fRenderData
Externally assigned and controlled user data.
virtual REveTrans * PtrMainTrans(Bool_t create=kTRUE)
Return pointer to main transformation.
virtual Bool_t SetRnrSelf(Bool_t rnr)
Set render state of this element, i.e.
virtual void CopyVizParams(const REveElement *el)
Copy visualization parameters from element el.
virtual void RemoveElements()
Remove all elements.
void SetName(const std::string &name)
Set name of an element.
REveException Exception-type thrown by Eve classes.
Definition REveTypes.hxx:41
Double_t fMin
Index of the last filled REvePointSet.
void CloseBins()
Call this after all the points have been filled.
void SetMarkerSize(Size_t msize=1) override
Set marker size, propagate to children.
REvePointSetArray(const REvePointSetArray &)=delete
void SetMarkerColor(Color_t tcolor=1) override
Set marker color, propagate to children.
void RemoveElementsLocal() override
Virtual from REveElement, provide bin management.
void InitBins(const std::string &quant_name, Int_t nbins, Double_t min, Double_t max)
Initialize internal point-sets with given binning parameters.
Bool_t Fill(Double_t x, Double_t y, Double_t z, Double_t quant)
Add a new point.
virtual ~REvePointSetArray()
Destructor: deletes the fBins array.
void SetRange(Double_t min, Double_t max)
Set active range of the separating quantity.
void RemoveElementLocal(REveElement *el) override
Virtual from REveElement, provide bin management.
void SetMarkerStyle(Style_t mstyle=1) override
Set marker style, propagate to children.
Int_t Size(Bool_t under=kFALSE, Bool_t over=kFALSE) const
Get the total number of filled points.
void PointSelected(Int_t id)
Virtual method of base class TPointSet3D.
void SetProjection(REveProjectionManager *proj, REveProjectable *model) override
Set projection manager and projection model.
void UpdateProjection() override
Re-apply the projection.
void SetDepthLocal(Float_t d) override
Set depth (z-coordinate) of the projected points.
void PointSelected(Int_t id)
Virtual method of base class TPointSet3D.
virtual void ClonePoints(const REvePointSet &e)
Clone points and all point-related information from point-set 'e'.
void WriteVizParams(std::ostream &out, const TString &var) override
Write visualization parameters.
void SetMarkerColor(Color_t col) override
Set the marker color.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Write core json.
void ComputeBBox() override
Compute bounding box.
virtual ~REvePointSet()
Destructor.
void SetMarkerSize(Size_t msize=1) override
Set marker size, propagate to projecteds.
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
REvePointSet(const std::string &name="", const std::string &title="", Int_t n_points=0)
Constructor.
std::vector< REveVector > fPoints
int SetPoint(int n, float x, float y, float z)
int SetNextPoint(float x, float y, float z)
void Reset(Int_t n_points=0)
Drop all data and set-up the data structures to recive new data.
void SetMarkerStyle(Style_t mstyle=1) override
Set marker style, propagate to projecteds.
void BuildRenderData() override
Crates 3D point array for rendering.
TClass * ProjectedClass(const REveProjection *p) const override
Virtual from REveProjectable, returns REvePointSetProjected class.
Int_t GrowFor(Int_t n_points)
Resizes internal array to allow additional n_points to be stored.
virtual void SetProjection(REveProjectionManager *mng, REveProjectable *model)
Sets projection manager and reference in the projectable object.
void SetDepthCommon(Float_t d, REveElement *el, Float_t *bbox)
Utility function to update the z-values of the bounding-box.
REveProjectionManager Manager class for steering of projections and managing projected objects.
REveProjection Base for specific classes that implement non-linear projections.
void ProjectPointfv(Float_t *v, Float_t d)
Project float array.
static void CalcTextureSize(int nel, int align, int &sx, int &sy)
Calculate texture dimensions to hold nel elements with given alignment on x axis.
Helper for management of bounding-box information.
Definition TAttBBox.h:18
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
Definition TAttBBox.h:69
void ResetBBox()
Definition TAttBBox.h:57
void BBoxZero(Float_t epsilon=0, Float_t x=0, Float_t y=0, Float_t z=0)
Create cube of volume (2*epsilon)^3 at (x,y,z).
Definition TAttBBox.cxx:42
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition TAttBBox.cxx:29
Float_t * fBBox
Definition TAttBBox.h:20
Marker Attributes class.
Definition TAttMarker.h:19
virtual void SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
Save line attributes as C++ statement(s) on output stream out.
virtual Style_t GetMarkerStyle() const
Return the marker style.
Definition TAttMarker.h:32
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition TAttMarker.h:31
Color_t fMarkerColor
Marker color.
Definition TAttMarker.h:22
virtual Size_t GetMarkerSize() const
Return the marker size.
Definition TAttMarker.h:33
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:45
Size_t fMarkerSize
Marker size.
Definition TAttMarker.h:24
Style_t fMarkerStyle
Marker style.
Definition TAttMarker.h:23
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
Basic string class.
Definition TString.h:139
TPaveText * pt
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
R__EXTERN REveManager * gEve
TMath.
Definition TMathBase.h:35
Int_t FloorNint(Double_t x)
Returns the nearest integer of TMath::Floor(x).
Definition TMath.h:686
basic_json<> json
TMarker m
Definition textangle.C:8