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)
48{
49 fMarkerStyle = 20;
50
52
53 Reset(n_points);
54
55 // Override from REveElement.
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Copy constructor.
61
68
69////////////////////////////////////////////////////////////////////////////////
70/// Destructor.
71
75
76////////////////////////////////////////////////////////////////////////////////
77/// Clone points and all point-related information from point-set 'e'.
78
80{
81 fPoints = e.fPoints;
82 fCapacity = e.fCapacity;
83 fSize = e.fSize;
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Drop all data and set-up the data structures to recive new data.
88/// n_points specifies the initial size of the array.
89
91{
92 fPoints.resize(n_points);
93 fCapacity = n_points;
94 fSize = 0;
95
96 ResetBBox();
97}
98
99////////////////////////////////////////////////////////////////////////////////
100/// Resizes internal array to allow additional n_points to be stored.
101/// Returns the old size which is also the location where one can
102/// start storing new data.
103/// The caller is *obliged* to fill the new point slots.
104
106{
107 assert(n_points >= 0);
108
109 Int_t old_size = fCapacity;
110 Int_t new_size = old_size + n_points;
111
112 fPoints.resize(new_size);
113 fCapacity = new_size;
114
115 return old_size;
116}
117
118int REvePointSet::SetNextPoint(float x, float y, float z)
119{
120 return SetPoint(fSize, x, y, z);
121}
122
123int REvePointSet::SetPoint(int n, float x, float y, float z)
124{
125 if (n >= fCapacity)
126 {
127 fCapacity = std::max(n + 1, 2*fCapacity);
128 fPoints.resize(fCapacity);
129 }
130 fPoints[n].Set(x, y, z);
131 if (n >= fSize)
132 {
133 fSize = n + 1;
134 }
135 return fSize;
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Set marker style, propagate to projecteds.
140
142{
143 for (auto &pi: fProjectedList)
144 {
145 REvePointSet* pt = dynamic_cast<REvePointSet *>(pi);
146 if (pt)
147 {
148 pt->SetMarkerStyle(mstyle);
149 pt->StampObjProps();
150 }
151 }
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Set marker size, propagate to projecteds.
157
159{
160 for (auto &pi: fProjectedList)
161 {
162 REvePointSet* pt = dynamic_cast<REvePointSet *>(pi);
163 if (pt)
164 {
165 pt->SetMarkerSize(msize);
166 pt->StampObjProps();
167 }
168 }
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Copy visualization parameters from element el.
175
177{
178 const REvePointSet* m = dynamic_cast<const REvePointSet*>(el);
179 if (m)
180 {
181 TAttMarker::operator=(*m);
182 }
183
185}
186
187////////////////////////////////////////////////////////////////////////////////
188/// Write visualization parameters.
189
190void REvePointSet::WriteVizParams(std::ostream& out, const TString& var)
191{
193
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Virtual from REveProjectable, returns REvePointSetProjected class.
199
201{
202 return TClass::GetClass<REvePointSetProjected>();
203}
204
205
206Int_t REvePointSet::WriteCoreJson(nlohmann::json& j, Int_t rnr_offset)
207{
208 if (gEve->IsRCore())
210
211 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
212
213 if (gEve->IsRCore()) {
214 j["fSize"] = fSize;
215 j["fTexX"] = fTexX;
216 j["fTexY"] = fTexY;
217 }
218 j["fMarkerSize"] = GetMarkerSize();
219 j["fMarkerColor"] = GetMarkerColor();
220 j["fMarkerStyle"] = GetMarkerStyle();
221 j["fSecondarySelect"] = fAlwaysSecSelect;
222
223 return ret;
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Crates 3D point array for rendering.
228
230{
231 if (fSize > 0)
232 {
233 if (gEve->IsRCore()) {
234 fRenderData = std::make_unique<REveRenderData>("makeHit", 4*fTexX*fTexY, 6);
235 for (int i = 0; i < fSize; ++i) {
236 fRenderData->PushV(&fPoints[i].fX, 3);
237 fRenderData->PushV(0);
238 }
239 fRenderData->ResizeV(4 * fTexX * fTexY);
240 } else {
241 fRenderData = std::make_unique<REveRenderData>("makeHit", 3*fSize);
242 fRenderData->PushV(&fPoints[0].fX, 3*fSize);
243 }
244
246 }
247}
248
249////////////////////////////////////////////////////////////////////////////////
250/// Compute bounding box.
251
253{
254 BBoxInit();
255 for (Int_t i = 0; i < fSize; ++i)
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Virtual method of base class TPointSet3D. The function call is
261/// invoked with secondary selection in TPointSet3DGL.
262
264{
265 // Emit("PointSelected(Int_t)", id);
266}
267
268
269//==============================================================================
270// REvePointSetArray
271//==============================================================================
272
273/** \class REvePointSetArray
274\ingroup REve
275An array of point-sets with each point-set playing a role of a bin
276in a histogram. When a new point is added to a REvePointSetArray,
277an additional separating quantity needs to be specified: it
278determines into which REvePointSet (bin) the point will actually be
279stored. Underflow and overflow bins are automatically created but
280they are not drawn by default.
281
282By using the REvePointSelector the points and the separating
283quantities can be filled directly from a TTree holding the source
284data.
285Setting of per-point TRef's is not supported.
286
287After the filling, the range of separating variable can be
288controlled with a slider to choose a sub-set of PointSets that are
289actually shown.
290*/
291
292////////////////////////////////////////////////////////////////////////////////
293/// Constructor.
294
296 const std::string& title) :
297 REveElement(name, title),
298
299 fBins(nullptr), fDefPointSetCapacity(128), fNBins(0), fLastBin(-1),
300 fMin(0), fCurMin(0), fMax(0), fCurMax(0),
301 fBinWidth(0),
302 fQuantName()
303{
305}
306
307////////////////////////////////////////////////////////////////////////////////
308/// Destructor: deletes the fBins array. Actual removal of
309/// elements done by REveElement.
310
312{
313 // printf("REvePointSetArray::~REvePointSetArray()\n");
314 delete [] fBins; fBins = nullptr;
315}
316
317////////////////////////////////////////////////////////////////////////////////
318/// Virtual from REveElement, provide bin management.
319
321{
322 for (Int_t i=0; i<fNBins; ++i) {
323 if (fBins[i] == el) {
324 fBins[i] = nullptr;
325 break;
326 }
327 }
328}
329
330////////////////////////////////////////////////////////////////////////////////
331/// Virtual from REveElement, provide bin management.
332
334{
335 delete [] fBins; fBins = nullptr; fLastBin = -1;
336}
337
338////////////////////////////////////////////////////////////////////////////////
339/// Set marker color, propagate to children.
340
342{
343 for (auto & el : fChildren)
344 {
345 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
346 if (m && m->GetMarkerColor() == fMarkerColor)
347 m->SetMarkerColor(tcolor);
348 }
350}
351
352////////////////////////////////////////////////////////////////////////////////
353/// Set marker style, propagate to children.
354
356{
357 for (auto & el : fChildren)
358 {
359 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
360 if (m && m->GetMarkerStyle() == fMarkerStyle)
361 m->SetMarkerStyle(mstyle);
362 }
364}
365
366////////////////////////////////////////////////////////////////////////////////
367/// Set marker size, propagate to children.
368
370{
371 for (auto & el : fChildren)
372 {
373 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
374 if (m && m->GetMarkerSize() == fMarkerSize)
375 m->SetMarkerSize(msize);
376 }
378}
379
380////////////////////////////////////////////////////////////////////////////////
381/// Get the total number of filled points.
382/// 'under' and 'over' flags specify if under/overflow channels
383/// should be added to the sum.
384
386{
387 Int_t size = 0;
388 const Int_t min = under ? 0 : 1;
389 const Int_t max = over ? fNBins : fNBins - 1;
390 for (Int_t i = min; i < max; ++i)
391 {
392 if (fBins[i])
393 size += fBins[i]->GetSize();
394 }
395 return size;
396}
397
398////////////////////////////////////////////////////////////////////////////////
399/// Initialize internal point-sets with given binning parameters.
400/// The actual number of bins is nbins+2, bin 0 corresponding to
401/// underflow and bin nbin+1 to owerflow pointset.
402
403void REvePointSetArray::InitBins(const std::string& quant_name,
404 Int_t nbins, Double_t min, Double_t max)
405{
406 static const REveException eh("REvePointSetArray::InitBins ");
407
408 if (nbins < 1) throw eh + "nbins < 1.";
409 if (min > max) throw eh + "min > max.";
410
412
413 fQuantName = quant_name;
414 fNBins = nbins + 2; // under/overflow
415 fLastBin = -1;
416 fMin = fCurMin = min;
417 fMax = fCurMax = max;
418 fBinWidth = (fMax - fMin)/(fNBins - 2);
419
420 fBins = new REvePointSet* [fNBins];
421
422 for (Int_t i = 0; i < fNBins; ++i)
423 {
424 fBins[i] = new REvePointSet
425 (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + (i-1)*fBinWidth, fMin + i*fBinWidth),
426 "",
431 AddElement(fBins[i]);
432 }
433
434 fBins[0]->SetName("Underflow");
436
437 fBins[fNBins-1]->SetName("Overflow");
439}
440
441////////////////////////////////////////////////////////////////////////////////
442/// Add a new point. Appropriate point-set will be chosen based on
443/// the value of the separating quantity 'quant'.
444/// If the selected bin does not have an associated REvePointSet
445/// the point is discarded and false is returned.
446
448{
449 fLastBin = TMath::FloorNint((quant - fMin)/fBinWidth) + 1;
450
451 if (fLastBin < 0)
452 {
453 fLastBin = 0;
454 }
455 else if (fLastBin > fNBins - 1)
456 {
457 fLastBin = fNBins - 1;
458 }
459
460 if (fBins[fLastBin] != nullptr)
461 {
463 return kTRUE;
464 }
465 else
466 {
467 return kFALSE;
468 }
469}
470
471////////////////////////////////////////////////////////////////////////////////
472/// Call this after all the points have been filled.
473/// At this point we can calculate bounding-boxes of individual
474/// point-sets.
475
477{
478 for (Int_t i=0; i<fNBins; ++i)
479 {
480 if (fBins[i])
481 {
482 fBins[i]->SetTitle(Form("N=%d", fBins[i]->GetSize()));
483 fBins[i]->ComputeBBox();
484 }
485 }
486 fLastBin = -1;
487}
488
489////////////////////////////////////////////////////////////////////////////////
490/// Set active range of the separating quantity.
491/// Appropriate point-sets are tagged for rendering.
492/// Over/underflow point-sets are left as they were.
493
495{
496 using namespace TMath;
497
498 fCurMin = min; fCurMax = max;
499 Int_t low_b = Max(0, FloorNint((min-fMin)/fBinWidth)) + 1;
500 Int_t high_b = Min(fNBins-2, CeilNint ((max-fMin)/fBinWidth));
501
502 for (Int_t i = 1; i < fNBins - 1; ++i)
503 {
504 if (fBins[i])
505 fBins[i]->SetRnrSelf(i>=low_b && i<=high_b);
506 }
507}
508
509/** \class REvePointSetProjected
510\ingroup REve
511Projected copy of a REvePointSet.
512*/
513
514////////////////////////////////////////////////////////////////////////////////
515/// Default contructor.
516
522
523////////////////////////////////////////////////////////////////////////////////
524/// Set projection manager and projection model.
525/// Virtual from REveProjected.
526
528 REveProjectable* model)
529{
530 REveProjected::SetProjection(proj, model);
531 CopyVizParams(dynamic_cast<REveElement*>(model));
532}
533
534////////////////////////////////////////////////////////////////////////////////
535/// Set depth (z-coordinate) of the projected points.
536
538{
539 SetDepthCommon(d, this);
540
541 // XXXX rewrite
542
543 Int_t n = fSize;
544 if (n == 0)
545 return;
546
547 Float_t *p = & fPoints[0].fZ;
548 for (Int_t i = 0; i < n; ++i, p+=3)
549 *p = fDepth;
550}
551
552////////////////////////////////////////////////////////////////////////////////
553/// Re-apply the projection.
554/// Virtual from REveProjected.
555
557{
559 REvePointSet &ps = * dynamic_cast<REvePointSet*>(fProjectable);
560 REveTrans mt;
561 const REveTrans *tr = fManager->GetModelTrans(&ps, mt);
562
564
565 // XXXX rewrite
566
567 Int_t n = ps.GetSize();
568 Reset(n);
569 fSize = n;
570
571 if (n == 0)
572 return;
573
574 const Float_t *o = & ps.RefPoint(0).fX;
575 Float_t *p = & fPoints[0].fX;
576 for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
577 {
578 proj.ProjectPointfv(tr, o, p, fDepth);
579 }
580}
581
582////////////////////////////////////////////////////////////////////////////////
583/// Virtual method of base class TPointSet3D.
584/// Forward to projectable.
585
587{
588 REvePointSet *ps = dynamic_cast<REvePointSet*>(fProjectable);
589 ps->PointSelected(id);
590}
#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
! Vertex / normal / triangle index information for rendering.
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.
virtual void BuildRenderData()
Build fRenderData, what the client draws.
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
Write core json.
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
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)
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.
static void CalcTextureSize(int nel, int align, int &sx, int &sy)
Calculate texture dimensions to hold nel elements with given alignment on x axis.
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
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:699
TMarker m
Definition textangle.C:8