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
58
59 // Override from REveElement.
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Copy constructor.
65
76
77////////////////////////////////////////////////////////////////////////////////
78/// Destructor.
79
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);
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
119
120 fPoints.resize(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
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, 6);
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
249 // save bbox in render data normals
250 ComputeBBox();
251 float* bb = GetBBox();
252 fRenderData->PushN(bb[0], bb[1], bb[2]);
253 fRenderData->PushN(bb[3], bb[4], bb[5]);
254 } else {
255 fRenderData = std::make_unique<REveRenderData>("makeHit", 3*fSize);
256 fRenderData->PushV(&fPoints[0].fX, 3*fSize);
257 }
258
260 }
261}
262
263////////////////////////////////////////////////////////////////////////////////
264/// Compute bounding box.
265
267{
268 if (fSize > 0) {
269 BBoxInit();
270 for (auto &p : fPoints)
271 {
272 BBoxCheckPoint(p.fX, p.fY, p.fZ);
273 }
274 } else {
275 BBoxZero();
276 }
277}
278
279////////////////////////////////////////////////////////////////////////////////
280/// Virtual method of base class TPointSet3D. The function call is
281/// invoked with secondary selection in TPointSet3DGL.
282
284{
285 // Emit("PointSelected(Int_t)", id);
286}
287
288
289//==============================================================================
290// REvePointSetArray
291//==============================================================================
292
293/** \class REvePointSetArray
294\ingroup REve
295An array of point-sets with each point-set playing a role of a bin
296in a histogram. When a new point is added to a REvePointSetArray,
297an additional separating quantity needs to be specified: it
298determines into which REvePointSet (bin) the point will actually be
299stored. Underflow and overflow bins are automatically created but
300they are not drawn by default.
301
302By using the REvePointSelector the points and the separating
303quantities can be filled directly from a TTree holding the source
304data.
305Setting of per-point TRef's is not supported.
306
307After the filling, the range of separating variable can be
308controlled with a slider to choose a sub-set of PointSets that are
309actually shown.
310*/
311
312////////////////////////////////////////////////////////////////////////////////
313/// Constructor.
314
316 const std::string& title) :
317 REveElement(name, title),
318
319 fBins(nullptr), fDefPointSetCapacity(128), fNBins(0), fLastBin(-1),
320 fMin(0), fCurMin(0), fMax(0), fCurMax(0),
321 fBinWidth(0),
322 fQuantName()
323{
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Destructor: deletes the fBins array. Actual removal of
329/// elements done by REveElement.
330
332{
333 // printf("REvePointSetArray::~REvePointSetArray()\n");
334 delete [] fBins; fBins = nullptr;
335}
336
337////////////////////////////////////////////////////////////////////////////////
338/// Virtual from REveElement, provide bin management.
339
341{
342 for (Int_t i=0; i<fNBins; ++i) {
343 if (fBins[i] == el) {
344 fBins[i] = nullptr;
345 break;
346 }
347 }
348}
349
350////////////////////////////////////////////////////////////////////////////////
351/// Virtual from REveElement, provide bin management.
352
354{
355 delete [] fBins; fBins = nullptr; fLastBin = -1;
356}
357
358////////////////////////////////////////////////////////////////////////////////
359/// Set marker color, propagate to children.
360
362{
363 for (auto & el : fChildren)
364 {
365 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
366 if (m && m->GetMarkerColor() == fMarkerColor)
368 }
370}
371
372////////////////////////////////////////////////////////////////////////////////
373/// Set marker style, propagate to children.
374
376{
377 for (auto & el : fChildren)
378 {
379 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
380 if (m && m->GetMarkerStyle() == fMarkerStyle)
382 }
384}
385
386////////////////////////////////////////////////////////////////////////////////
387/// Set marker size, propagate to children.
388
390{
391 for (auto & el : fChildren)
392 {
393 TAttMarker* m = dynamic_cast<TAttMarker*>(el);
394 if (m && m->GetMarkerSize() == fMarkerSize)
396 }
398}
399
400////////////////////////////////////////////////////////////////////////////////
401/// Get the total number of filled points.
402/// 'under' and 'over' flags specify if under/overflow channels
403/// should be added to the sum.
404
406{
407 Int_t size = 0;
408 const Int_t min = under ? 0 : 1;
409 const Int_t max = over ? fNBins : fNBins - 1;
410 for (Int_t i = min; i < max; ++i)
411 {
412 if (fBins[i])
413 size += fBins[i]->GetSize();
414 }
415 return size;
416}
417
418////////////////////////////////////////////////////////////////////////////////
419/// Initialize internal point-sets with given binning parameters.
420/// The actual number of bins is nbins+2, bin 0 corresponding to
421/// underflow and bin nbin+1 to owerflow pointset.
422
424 Int_t nbins, Double_t min, Double_t max)
425{
426 static const REveException eh("REvePointSetArray::InitBins ");
427
428 if (nbins < 1) throw eh + "nbins < 1.";
429 if (min > max) throw eh + "min > max.";
430
432
434 fNBins = nbins + 2; // under/overflow
435 fLastBin = -1;
436 fMin = fCurMin = min;
437 fMax = fCurMax = max;
438 fBinWidth = (fMax - fMin)/(fNBins - 2);
439
440 fBins = new REvePointSet* [fNBins];
441
442 for (Int_t i = 0; i < fNBins; ++i)
443 {
444 fBins[i] = new REvePointSet
445 (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + (i-1)*fBinWidth, fMin + i*fBinWidth),
446 "",
451 AddElement(fBins[i]);
452 }
453
454 fBins[0]->SetName("Underflow");
456
457 fBins[fNBins-1]->SetName("Overflow");
459}
460
461////////////////////////////////////////////////////////////////////////////////
462/// Add a new point. Appropriate point-set will be chosen based on
463/// the value of the separating quantity 'quant'.
464/// If the selected bin does not have an associated REvePointSet
465/// the point is discarded and false is returned.
466
468{
470
471 if (fLastBin < 0)
472 {
473 fLastBin = 0;
474 }
475 else if (fLastBin > fNBins - 1)
476 {
477 fLastBin = fNBins - 1;
478 }
479
480 if (fBins[fLastBin] != nullptr)
481 {
483 return kTRUE;
484 }
485 else
486 {
487 return kFALSE;
488 }
489}
490
491////////////////////////////////////////////////////////////////////////////////
492/// Call this after all the points have been filled.
493/// At this point we can calculate bounding-boxes of individual
494/// point-sets.
495
497{
498 for (Int_t i=0; i<fNBins; ++i)
499 {
500 if (fBins[i])
501 {
502 fBins[i]->SetTitle(Form("N=%d", fBins[i]->GetSize()));
503 fBins[i]->ComputeBBox();
504 }
505 }
506 fLastBin = -1;
507}
508
509////////////////////////////////////////////////////////////////////////////////
510/// Set active range of the separating quantity.
511/// Appropriate point-sets are tagged for rendering.
512/// Over/underflow point-sets are left as they were.
513
515{
516 using namespace TMath;
517
518 fCurMin = min; fCurMax = max;
519 Int_t low_b = Max(0, FloorNint((min-fMin)/fBinWidth)) + 1;
520 Int_t high_b = Min(fNBins-2, CeilNint ((max-fMin)/fBinWidth));
521
522 for (Int_t i = 1; i < fNBins - 1; ++i)
523 {
524 if (fBins[i])
525 fBins[i]->SetRnrSelf(i>=low_b && i<=high_b);
526 }
527}
528
529/** \class REvePointSetProjected
530\ingroup REve
531Projected copy of a REvePointSet.
532*/
533
534////////////////////////////////////////////////////////////////////////////////
535/// Default contructor.
536
542
543////////////////////////////////////////////////////////////////////////////////
544/// Set projection manager and projection model.
545/// Virtual from REveProjected.
546
553
554////////////////////////////////////////////////////////////////////////////////
555/// Set depth (z-coordinate) of the projected points.
556
558{
559 SetDepthCommon(d, this, fBBox);
560
561 // XXXX rewrite
562
563 Int_t n = fSize;
564 if (n == 0)
565 return;
566
567 Float_t *p = & fPoints[0].fZ;
568 for (Int_t i = 0; i < n; ++i, p+=3)
569 *p = fDepth;
570}
571
572////////////////////////////////////////////////////////////////////////////////
573/// Re-apply the projection.
574/// Virtual from REveProjected.
575
577{
579 REvePointSet &ps = * dynamic_cast<REvePointSet*>(fProjectable);
581
583
584 // XXXX rewrite
585
586 Int_t n = ps.GetSize();
587 Reset(n);
588 fSize = n;
589
590 if (n == 0)
591 return;
592
593 const Float_t *o = & ps.RefPoint(0).fX;
594 Float_t *p = & fPoints[0].fX;
595 for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
596 {
597 proj.ProjectPointfv(tr, o, p, fDepth);
598 }
599}
600
601////////////////////////////////////////////////////////////////////////////////
602/// Virtual method of base class TPointSet3D.
603/// Forward to projectable.
604
606{
607 REvePointSet *ps = dynamic_cast<REvePointSet*>(fProjectable);
608 ps->PointSelected(id);
609}
#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:96
short Color_t
Color number (short)
Definition RtypesCore.h:99
float Size_t
Attribute size (float)
Definition RtypesCore.h:103
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
char name[80]
Definition TGX11.cxx:145
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2495
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
! Vertex / normal / triangle index information for rendering.
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.
virtual void BuildRenderData()
Write transformation Matrix to render data.
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, 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.
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:41
Float_t * GetBBox()
Definition TAttBBox.h:55
void BBoxInit(Float_t infinity=1e6)
Allocate and prepare for incremental filling.
Definition TAttBBox.cxx:28
Float_t * fBBox
! Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition TAttBBox.h:20
Marker Attributes class.
Definition TAttMarker.h:21
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:34
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:41
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition TAttMarker.h:33
Color_t fMarkerColor
Marker color.
Definition TAttMarker.h:24
virtual Size_t GetMarkerSize() const
Return the marker size.
Definition TAttMarker.h:35
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:43
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:48
Size_t fMarkerSize
Marker size.
Definition TAttMarker.h:26
Style_t fMarkerStyle
Marker style.
Definition TAttMarker.h:25
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
Basic string class.
Definition TString.h:138
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:697
TMarker m
Definition textangle.C:8