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
15#include <ROOT/REveTrans.hxx>
17
18#include "TArrayI.h"
19#include "TClass.h"
20
21#include <nlohmann/json.hpp>
22
23using namespace ROOT::Experimental;
24
25/** \class REvePointSet
26\ingroup REve
27REvePointSet is a render-element holding a collection of 3D points with
28optional per-point TRef and an arbitrary number of integer ids (to
29be used for signal, volume-id, track-id, etc).
30
313D point representation is implemented in base-class TPolyMarker3D.
32Per-point TRef is implemented in base-class TPointSet3D.
33
34By using the REvePointSelector the points and integer ids can be
35filled directly from a TTree holding the source data.
36Setting of per-point TRef's is not supported.
37
38REvePointSet is a REveProjectable: it can be projected by using the
39REveProjectionManager class.
40
41The render data has one entry, `pts`: f32 x 4 in an rgba32f texture, one
42texel (x, y, z, 0) per point, in point order, so the client's instance index
43is the point index. REvePointSetProjected writes its projected points the
44same way.
45*/
46
47////////////////////////////////////////////////////////////////////////////////
48/// Constructor.
49
50REvePointSet::REvePointSet(const std::string &name, const std::string &title, Int_t n_points)
52{
53 fMarkerStyle = 20;
54
56
57 Reset(n_points);
58
59 // Override from REveElement.
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Copy constructor.
65
72
73////////////////////////////////////////////////////////////////////////////////
74/// Destructor.
75
79
80////////////////////////////////////////////////////////////////////////////////
81/// Clone points and all point-related information from point-set 'e'.
82
84{
85 fPoints = e.fPoints;
86 fCapacity = e.fCapacity;
87 fSize = e.fSize;
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Drop all data and set-up the data structures to recive new data.
92/// n_points specifies the initial size of the array.
93
95{
96 fPoints.resize(n_points);
97 fCapacity = n_points;
98 fSize = 0;
99
100 ResetBBox();
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Resizes internal array to allow additional n_points to be stored.
105/// Returns the old size which is also the location where one can
106/// start storing new data.
107/// The caller is *obliged* to fill the new point slots.
108
110{
111 assert(n_points >= 0);
112
113 Int_t old_size = fCapacity;
114 Int_t new_size = old_size + n_points;
115
116 fPoints.resize(new_size);
117 fCapacity = new_size;
118
119 return old_size;
120}
121
122int REvePointSet::SetNextPoint(float x, float y, float z)
123{
124 return SetPoint(fSize, x, y, z);
125}
126
127int REvePointSet::SetPoint(int n, float x, float y, float z)
128{
129 if (n >= fCapacity)
130 {
131 fCapacity = std::max(n + 1, 2*fCapacity);
132 fPoints.resize(fCapacity);
133 }
134 fPoints[n].Set(x, y, z);
135 if (n >= fSize)
136 {
137 fSize = n + 1;
138 }
139 return fSize;
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// Set marker style, propagate to projecteds.
144
146{
147 for (auto &pi: fProjectedList)
148 {
149 REvePointSet* pt = dynamic_cast<REvePointSet *>(pi);
150 if (pt)
151 {
152 pt->SetMarkerStyle(mstyle);
153 pt->StampObjProps();
154 }
155 }
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// Set marker size, propagate to projecteds.
161
163{
164 for (auto &pi: fProjectedList)
165 {
166 REvePointSet* pt = dynamic_cast<REvePointSet *>(pi);
167 if (pt)
168 {
169 pt->SetMarkerSize(msize);
170 pt->StampObjProps();
171 }
172 }
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Copy visualization parameters from element el.
179
181{
182 const REvePointSet* m = dynamic_cast<const REvePointSet*>(el);
183 if (m)
184 {
185 TAttMarker::operator=(*m);
186 }
187
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// Write visualization parameters.
193
194void REvePointSet::WriteVizParams(std::ostream& out, const TString& var)
195{
197
199}
200
201////////////////////////////////////////////////////////////////////////////////
202/// Virtual from REveProjectable, returns REvePointSetProjected class.
203
205{
206 return TClass::GetClass<REvePointSetProjected>();
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// Fill core part of JSON representation. The number of points and the
211/// texture size are the `pts` entry's count and tex, see BuildRenderData().
212
213Int_t REvePointSet::WriteCoreJson(nlohmann::json& j, Int_t rnr_offset)
214{
215 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
216
217 j["fMarkerSize"] = GetMarkerSize();
218 j["fMarkerColor"] = GetMarkerColor();
219 j["fMarkerStyle"] = GetMarkerStyle();
220 j["fSecondarySelect"] = fAlwaysSecSelect;
221
222 return ret;
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Write the render data entry `pts`, see the class description. An empty set
227/// has no render data.
228
230{
231 if (fSize <= 0)
232 return;
233
234 using RD = REveRenderData;
235 fRenderData = std::make_unique<RD>("makeHit");
236
237 auto &pts = fRenderData->NewEntry("pts", RD::EType::kF32, 4).Reserve(fSize);
238 for (int i = 0; i < fSize; ++i)
239 pts.Push(fPoints[i].fX, fPoints[i].fY, fPoints[i].fZ, 0.f);
240 // The client's sprite shader reads one texel per instance.
241 pts.AsTexture(RD::ETexFormat::kRGBA32F, 1);
242}
243
244////////////////////////////////////////////////////////////////////////////////
245/// Compute bounding box.
246
248{
249 BBoxInit();
250 for (Int_t i = 0; i < fSize; ++i)
252}
253
254////////////////////////////////////////////////////////////////////////////////
255/// Virtual method of base class TPointSet3D. The function call is
256/// invoked with secondary selection in TPointSet3DGL.
257
259{
260 // Emit("PointSelected(Int_t)", id);
261}
262
263
264//==============================================================================
265// REvePointSetArray
266//==============================================================================
267
268/** \class REvePointSetArray
269\ingroup REve
270An array of point-sets with each point-set playing a role of a bin
271in a histogram. When a new point is added to a REvePointSetArray,
272an additional separating quantity needs to be specified: it
273determines into which REvePointSet (bin) the point will actually be
274stored. Underflow and overflow bins are automatically created but
275they are not drawn by default.
276
277By using the REvePointSelector the points and the separating
278quantities can be filled directly from a TTree holding the source
279data.
280Setting of per-point TRef's is not supported.
281
282After the filling, the range of separating variable can be
283controlled with a slider to choose a sub-set of PointSets that are
284actually shown.
285*/
286
287////////////////////////////////////////////////////////////////////////////////
288/// Constructor.
289
291 const std::string& title) :
292 REveElement(name, title),
293
294 fBins(nullptr), fDefPointSetCapacity(128), fNBins(0), fLastBin(-1),
295 fMin(0), fCurMin(0), fMax(0), fCurMax(0),
296 fBinWidth(0),
297 fQuantName()
298{
300}
301
302////////////////////////////////////////////////////////////////////////////////
303/// Destructor: deletes the fBins array. Actual removal of
304/// elements done by REveElement.
305
307{
308 // printf("REvePointSetArray::~REvePointSetArray()\n");
309 delete [] fBins; fBins = nullptr;
310}
311
312////////////////////////////////////////////////////////////////////////////////
313/// Virtual from REveElement, provide bin management.
314
316{
317 for (Int_t i=0; i<fNBins; ++i) {
318 if (fBins[i] == el) {
319 fBins[i] = nullptr;
320 break;
321 }
322 }
323}
324
325////////////////////////////////////////////////////////////////////////////////
326/// Virtual from REveElement, provide bin management.
327
329{
330 delete [] fBins; fBins = nullptr; fLastBin = -1;
331}
332
333////////////////////////////////////////////////////////////////////////////////
334/// Set marker color, propagate to children.
335
337{
338 for (auto & el : fChildren)
339 {
340 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
341 if (m && m->GetMarkerColor() == fMarkerColor)
342 m->SetMarkerColor(tcolor);
343 }
345}
346
347////////////////////////////////////////////////////////////////////////////////
348/// Set marker style, propagate to children.
349
351{
352 for (auto & el : fChildren)
353 {
354 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
355 if (m && m->GetMarkerStyle() == fMarkerStyle)
356 m->SetMarkerStyle(mstyle);
357 }
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// Set marker size, propagate to children.
363
365{
366 for (auto & el : fChildren)
367 {
368 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
369 if (m && m->GetMarkerSize() == fMarkerSize)
370 m->SetMarkerSize(msize);
371 }
373}
374
375////////////////////////////////////////////////////////////////////////////////
376/// Get the total number of filled points.
377/// 'under' and 'over' flags specify if under/overflow channels
378/// should be added to the sum.
379
381{
382 Int_t size = 0;
383 const Int_t min = under ? 0 : 1;
384 const Int_t max = over ? fNBins : fNBins - 1;
385 for (Int_t i = min; i < max; ++i)
386 {
387 if (fBins[i])
388 size += fBins[i]->GetSize();
389 }
390 return size;
391}
392
393////////////////////////////////////////////////////////////////////////////////
394/// Initialize internal point-sets with given binning parameters.
395/// The actual number of bins is nbins+2, bin 0 corresponding to
396/// underflow and bin nbin+1 to owerflow pointset.
397
398void REvePointSetArray::InitBins(const std::string& quant_name,
399 Int_t nbins, Double_t min, Double_t max)
400{
401 static const REveException eh("REvePointSetArray::InitBins ");
402
403 if (nbins < 1) throw eh + "nbins < 1.";
404 if (min > max) throw eh + "min > max.";
405
407
408 fQuantName = quant_name;
409 fNBins = nbins + 2; // under/overflow
410 fLastBin = -1;
411 fMin = fCurMin = min;
412 fMax = fCurMax = max;
413 fBinWidth = (fMax - fMin)/(fNBins - 2);
414
415 fBins = new REvePointSet* [fNBins];
416
417 for (Int_t i = 0; i < fNBins; ++i)
418 {
419 fBins[i] = new REvePointSet
420 (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + (i-1)*fBinWidth, fMin + i*fBinWidth),
421 "",
426 AddElement(fBins[i]);
427 }
428
429 fBins[0]->SetName("Underflow");
431
432 fBins[fNBins-1]->SetName("Overflow");
434}
435
436////////////////////////////////////////////////////////////////////////////////
437/// Add a new point. Appropriate point-set will be chosen based on
438/// the value of the separating quantity 'quant'.
439/// If the selected bin does not have an associated REvePointSet
440/// the point is discarded and false is returned.
441
443{
444 fLastBin = TMath::FloorNint((quant - fMin)/fBinWidth) + 1;
445
446 if (fLastBin < 0)
447 {
448 fLastBin = 0;
449 }
450 else if (fLastBin > fNBins - 1)
451 {
452 fLastBin = fNBins - 1;
453 }
454
455 if (fBins[fLastBin] != nullptr)
456 {
458 return kTRUE;
459 }
460 else
461 {
462 return kFALSE;
463 }
464}
465
466////////////////////////////////////////////////////////////////////////////////
467/// Call this after all the points have been filled.
468/// At this point we can calculate bounding-boxes of individual
469/// point-sets.
470
472{
473 for (Int_t i=0; i<fNBins; ++i)
474 {
475 if (fBins[i])
476 {
477 fBins[i]->SetTitle(Form("N=%d", fBins[i]->GetSize()));
478 fBins[i]->ComputeBBox();
479 }
480 }
481 fLastBin = -1;
482}
483
484////////////////////////////////////////////////////////////////////////////////
485/// Set active range of the separating quantity.
486/// Appropriate point-sets are tagged for rendering.
487/// Over/underflow point-sets are left as they were.
488
490{
491 using namespace TMath;
492
493 fCurMin = min; fCurMax = max;
494 Int_t low_b = Max(0, FloorNint((min-fMin)/fBinWidth)) + 1;
495 Int_t high_b = Min(fNBins-2, CeilNint ((max-fMin)/fBinWidth));
496
497 for (Int_t i = 1; i < fNBins - 1; ++i)
498 {
499 if (fBins[i])
500 fBins[i]->SetRnrSelf(i>=low_b && i<=high_b);
501 }
502}
503
504/** \class REvePointSetProjected
505\ingroup REve
506Projected copy of a REvePointSet.
507*/
508
509////////////////////////////////////////////////////////////////////////////////
510/// Default contructor.
511
517
518////////////////////////////////////////////////////////////////////////////////
519/// Set projection manager and projection model.
520/// Virtual from REveProjected.
521
523 REveProjectable* model)
524{
525 REveProjected::SetProjection(proj, model);
526 CopyVizParams(dynamic_cast<REveElement*>(model));
527}
528
529////////////////////////////////////////////////////////////////////////////////
530/// Set depth (z-coordinate) of the projected points.
531
533{
534 SetDepthCommon(d, this);
535
536 // XXXX rewrite
537
538 Int_t n = fSize;
539 if (n == 0)
540 return;
541
542 Float_t *p = & fPoints[0].fZ;
543 for (Int_t i = 0; i < n; ++i, p+=3)
544 *p = fDepth;
545}
546
547////////////////////////////////////////////////////////////////////////////////
548/// Re-apply the projection.
549/// Virtual from REveProjected.
550
552{
554 REvePointSet &ps = * dynamic_cast<REvePointSet*>(fProjectable);
555 REveTrans mt;
556 const REveTrans *tr = fManager->GetModelTrans(&ps, mt);
557
559
560 // XXXX rewrite
561
562 Int_t n = ps.GetSize();
563 Reset(n);
564 fSize = n;
565
566 if (n == 0)
567 return;
568
569 const Float_t *o = & ps.RefPoint(0).fX;
570 Float_t *p = & fPoints[0].fX;
571 for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
572 {
573 proj.ProjectPointfv(tr, o, p, fDepth);
574 }
575}
576
577////////////////////////////////////////////////////////////////////////////////
578/// Virtual method of base class TPointSet3D.
579/// Forward to projectable.
580
582{
583 REvePointSet *ps = dynamic_cast<REvePointSet*>(fProjectable);
584 ps->PointSelected(id);
585}
#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
Style number (short)
Definition RtypesCore.h:97
short Color_t
Color number (short)
Definition RtypesCore.h:100
float Size_t
Attribute size (float)
Definition RtypesCore.h:104
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
winID h TVirtualViewer3D TVirtualGLPainter p
char name[80]
Definition TGX11.cxx:142
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2571
void SetMainColorPtr(Color_t *colptr)
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
void BBoxCheckPoint(const REveVector &v)
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
! Render data entries for the client's maker, see REveRenderData.
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.
void BBoxInit()
Start filling the bounding box with BBoxCheckPoint(): min at +infinity, max at -infinity,...
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:42
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.
~REvePointSetArray() override
Destructor: deletes the fBins array.
Int_t fLastBin
! Index of the last filled REvePointSet.
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.
~REvePointSet() override
Destructor.
void SetMarkerColor(Color_t col) override
Set the marker color.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
void ComputeBBox() override
Compute bounding box.
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
Write the render data entry pts, see the class description.
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)
Set the depth and stamp el for a rebuild.
REveProjectionManager Manager class for steering of projections and managing projected objects.
const REveTrans * GetModelTrans(REveElement *model, REveTrans &t)
Return the matrix that takes the coordinates of model into the frame of this manager,...
REveProjection Base for specific classes that implement non-linear projections.
void ProjectPointfv(Float_t *v, Float_t d)
Project float array.
Render data of an element: a client maker name and a list of tagged entries, each a typed array with ...
Marker Attributes class.
Definition TAttMarker.h:22
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:35
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition TAttMarker.h:34
Color_t fMarkerColor
Marker color.
Definition TAttMarker.h:25
virtual Size_t GetMarkerSize() const
Return the marker size.
Definition TAttMarker.h:36
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Size_t fMarkerSize
Marker size.
Definition TAttMarker.h:27
Style_t fMarkerStyle
Marker style.
Definition TAttMarker.h:26
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
Basic string class.
Definition TString.h:137
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
Namespace for ROOT features in testing.
Definition TROOT.h:100
TMath.
Definition TMathBase.h:35
Int_t FloorNint(Double_t x)
Returns the nearest integer of TMath::Floor(x).
Definition TMath.h:699
TMarker m
Definition textangle.C:8