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
214Int_t REvePointSet::WriteCoreJson(nlohmann::json& j, Int_t rnr_offset)
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["fMarkerStyle"] = GetMarkerStyle();
229 j["fSecondarySelect"] = fAlwaysSecSelect;
230
231 return ret;
232}
233
234////////////////////////////////////////////////////////////////////////////////
235/// Crates 3D point array for rendering.
236
238{
239 if (fSize > 0)
240 {
241 if (gEve->IsRCore()) {
242 fRenderData = std::make_unique<REveRenderData>("makeHit", 4*fTexX*fTexY);
243 for (int i = 0; i < fSize; ++i) {
244 fRenderData->PushV(&fPoints[i].fX, 3);
245 fRenderData->PushV(0);
246 }
247 fRenderData->ResizeV(4*fTexX*fTexY);
248 } else {
249 fRenderData = std::make_unique<REveRenderData>("makeHit", 3*fSize);
250 fRenderData->PushV(&fPoints[0].fX, 3*fSize);
251 }
252 }
253}
254
255////////////////////////////////////////////////////////////////////////////////
256/// Compute bounding box.
257
259{
260 if (fSize > 0) {
261 BBoxInit();
262 for (auto &p : fPoints)
263 {
264 BBoxCheckPoint(p.fX, p.fY, p.fZ);
265 }
266 } else {
267 BBoxZero();
268 }
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Virtual method of base class TPointSet3D. The function call is
273/// invoked with secondary selection in TPointSet3DGL.
274
276{
277 // Emit("PointSelected(Int_t)", id);
278}
279
280
281//==============================================================================
282// REvePointSetArray
283//==============================================================================
284
285/** \class REvePointSetArray
286\ingroup REve
287An array of point-sets with each point-set playing a role of a bin
288in a histogram. When a new point is added to a REvePointSetArray,
289an additional separating quantity needs to be specified: it
290determines into which REvePointSet (bin) the point will actually be
291stored. Underflow and overflow bins are automatically created but
292they are not drawn by default.
293
294By using the REvePointSelector the points and the separating
295quantities can be filled directly from a TTree holding the source
296data.
297Setting of per-point TRef's is not supported.
298
299After the filling, the range of separating variable can be
300controlled with a slider to choose a sub-set of PointSets that are
301actually shown.
302*/
303
304////////////////////////////////////////////////////////////////////////////////
305/// Constructor.
306
308 const std::string& title) :
309 REveElement(name, title),
310
311 fBins(nullptr), fDefPointSetCapacity(128), fNBins(0), fLastBin(-1),
312 fMin(0), fCurMin(0), fMax(0), fCurMax(0),
313 fBinWidth(0),
314 fQuantName()
315{
317}
318
319////////////////////////////////////////////////////////////////////////////////
320/// Destructor: deletes the fBins array. Actual removal of
321/// elements done by REveElement.
322
324{
325 // printf("REvePointSetArray::~REvePointSetArray()\n");
326 delete [] fBins; fBins = nullptr;
327}
328
329////////////////////////////////////////////////////////////////////////////////
330/// Virtual from REveElement, provide bin management.
331
333{
334 for (Int_t i=0; i<fNBins; ++i) {
335 if (fBins[i] == el) {
336 fBins[i] = nullptr;
337 break;
338 }
339 }
340}
341
342////////////////////////////////////////////////////////////////////////////////
343/// Virtual from REveElement, provide bin management.
344
346{
347 delete [] fBins; fBins = nullptr; fLastBin = -1;
348}
349
350////////////////////////////////////////////////////////////////////////////////
351/// Set marker color, propagate to children.
352
354{
355 for (auto & el : fChildren)
356 {
357 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
358 if (m && m->GetMarkerColor() == fMarkerColor)
359 m->SetMarkerColor(tcolor);
360 }
362}
363
364////////////////////////////////////////////////////////////////////////////////
365/// Set marker style, propagate to children.
366
368{
369 for (auto & el : fChildren)
370 {
371 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
372 if (m && m->GetMarkerStyle() == fMarkerStyle)
373 m->SetMarkerStyle(mstyle);
374 }
376}
377
378////////////////////////////////////////////////////////////////////////////////
379/// Set marker size, propagate to children.
380
382{
383 for (auto & el : fChildren)
384 {
385 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
386 if (m && m->GetMarkerSize() == fMarkerSize)
387 m->SetMarkerSize(msize);
388 }
390}
391
392////////////////////////////////////////////////////////////////////////////////
393/// Get the total number of filled points.
394/// 'under' and 'over' flags specify if under/overflow channels
395/// should be added to the sum.
396
398{
399 Int_t size = 0;
400 const Int_t min = under ? 0 : 1;
401 const Int_t max = over ? fNBins : fNBins - 1;
402 for (Int_t i = min; i < max; ++i)
403 {
404 if (fBins[i])
405 size += fBins[i]->GetSize();
406 }
407 return size;
408}
409
410////////////////////////////////////////////////////////////////////////////////
411/// Initialize internal point-sets with given binning parameters.
412/// The actual number of bins is nbins+2, bin 0 corresponding to
413/// underflow and bin nbin+1 to owerflow pointset.
414
415void REvePointSetArray::InitBins(const std::string& quant_name,
416 Int_t nbins, Double_t min, Double_t max)
417{
418 static const REveException eh("REvePointSetArray::InitBins ");
419
420 if (nbins < 1) throw eh + "nbins < 1.";
421 if (min > max) throw eh + "min > max.";
422
424
425 fQuantName = quant_name;
426 fNBins = nbins + 2; // under/overflow
427 fLastBin = -1;
428 fMin = fCurMin = min;
429 fMax = fCurMax = max;
430 fBinWidth = (fMax - fMin)/(fNBins - 2);
431
432 fBins = new REvePointSet* [fNBins];
433
434 for (Int_t i = 0; i < fNBins; ++i)
435 {
436 fBins[i] = new REvePointSet
437 (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + (i-1)*fBinWidth, fMin + i*fBinWidth),
438 "",
443 AddElement(fBins[i]);
444 }
445
446 fBins[0]->SetName("Underflow");
448
449 fBins[fNBins-1]->SetName("Overflow");
451}
452
453////////////////////////////////////////////////////////////////////////////////
454/// Add a new point. Appropriate point-set will be chosen based on
455/// the value of the separating quantity 'quant'.
456/// If the selected bin does not have an associated REvePointSet
457/// the point is discarded and false is returned.
458
460{
461 fLastBin = TMath::FloorNint((quant - fMin)/fBinWidth) + 1;
462
463 if (fLastBin < 0)
464 {
465 fLastBin = 0;
466 }
467 else if (fLastBin > fNBins - 1)
468 {
469 fLastBin = fNBins - 1;
470 }
471
472 if (fBins[fLastBin] != 0)
473 {
475 return kTRUE;
476 }
477 else
478 {
479 return kFALSE;
480 }
481}
482
483////////////////////////////////////////////////////////////////////////////////
484/// Call this after all the points have been filled.
485/// At this point we can calculate bounding-boxes of individual
486/// point-sets.
487
489{
490 for (Int_t i=0; i<fNBins; ++i)
491 {
492 if (fBins[i])
493 {
494 fBins[i]->SetTitle(Form("N=%d", fBins[i]->GetSize()));
495 fBins[i]->ComputeBBox();
496 }
497 }
498 fLastBin = -1;
499}
500
501////////////////////////////////////////////////////////////////////////////////
502/// Set active range of the separating quantity.
503/// Appropriate point-sets are tagged for rendering.
504/// Over/underflow point-sets are left as they were.
505
507{
508 using namespace TMath;
509
510 fCurMin = min; fCurMax = max;
511 Int_t low_b = Max(0, FloorNint((min-fMin)/fBinWidth)) + 1;
512 Int_t high_b = Min(fNBins-2, CeilNint ((max-fMin)/fBinWidth));
513
514 for (Int_t i = 1; i < fNBins - 1; ++i)
515 {
516 if (fBins[i])
517 fBins[i]->SetRnrSelf(i>=low_b && i<=high_b);
518 }
519}
520
521/** \class REvePointSetProjected
522\ingroup REve
523Projected copy of a REvePointSet.
524*/
525
526////////////////////////////////////////////////////////////////////////////////
527/// Default contructor.
528
530 REvePointSet (),
532{
533}
534
535////////////////////////////////////////////////////////////////////////////////
536/// Set projection manager and projection model.
537/// Virtual from REveProjected.
538
540 REveProjectable* model)
541{
542 REveProjected::SetProjection(proj, model);
543 CopyVizParams(dynamic_cast<REveElement*>(model));
544}
545
546////////////////////////////////////////////////////////////////////////////////
547/// Set depth (z-coordinate) of the projected points.
548
550{
551 SetDepthCommon(d, this, fBBox);
552
553 // XXXX rewrite
554
555 Int_t n = fSize;
556 Float_t *p = & fPoints[0].fZ;
557 for (Int_t i = 0; i < n; ++i, p+=3)
558 *p = fDepth;
559}
560
561////////////////////////////////////////////////////////////////////////////////
562/// Re-apply the projection.
563/// Virtual from REveProjected.
564
566{
568 REvePointSet &ps = * dynamic_cast<REvePointSet*>(fProjectable);
569 REveTrans *tr = ps.PtrMainTrans(kFALSE);
570
572
573 // XXXX rewrite
574
575 Int_t n = ps.GetSize();
576 Reset(n);
577 fSize = n;
578
579 if (n == 0)
580 return;
581
582 const Float_t *o = & ps.RefPoint(0).fX;
583 Float_t *p = & fPoints[0].fX;
584 for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
585 {
586 proj.ProjectPointfv(tr, o, p, fDepth);
587 }
588}
589
590////////////////////////////////////////////////////////////////////////////////
591/// Virtual method of base class TPointSet3D.
592/// Forward to projectable.
593
595{
596 REvePointSet *ps = dynamic_cast<REvePointSet*>(fProjectable);
597 ps->PointSelected(id);
598}
#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
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr 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:2467
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
TMarker m
Definition textangle.C:8