Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveLine.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007, 2018
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/REveLine.hxx>
15
16#include "TClass.h"
17
18using namespace ROOT::Experimental;
19
20/** \class REveLine
21\ingroup REve
22An arbitrary polyline with fixed line and marker attributes.
23*/
24
25Bool_t REveLine::fgDefaultSmooth = kFALSE;
26
27
28////////////////////////////////////////////////////////////////////////////////
29/// Constructor.
30
31REveLine::REveLine(const std::string &name, const std::string &title, Int_t n_points) :
32 REvePointSet(name, title, n_points),
33 fRnrLine (kTRUE),
34 fRnrPoints (kFALSE),
35 fSmooth (fgDefaultSmooth)
36{
39}
40
41////////////////////////////////////////////////////////////////////////////////
42/// Copy constructor.
43
46 TAttLine (l),
47 fRnrLine (l.fRnrLine),
48 fRnrPoints (l.fRnrPoints),
49 fSmooth (l.fSmooth)
50{
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Set marker color. Propagate to projected lines.
55
57{
58 for (auto &pi: fProjectedList)
59 {
60 REveLine* l = dynamic_cast<REveLine*>(pi);
61 if (l && fMarkerColor == l->GetMarkerColor())
62 {
63 l->SetMarkerColor(col);
64 l->StampObjProps();
65 }
66 }
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Set line-style of the line.
72/// The style is propagated to projecteds.
73
75{
76 for (auto &pi: fProjectedList)
77 {
78 REveLine* pt = dynamic_cast<REveLine*>(pi);
79 if (pt)
80 {
81 pt->SetLineStyle(lstyle);
82 pt->StampObjProps();
83 }
84 }
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// Set line-style of the line.
90/// The style is propagated to projecteds.
91
93{
94 for (auto &pi: fProjectedList)
95 {
96 REveLine* pt = dynamic_cast<REveLine*>(pi);
97 if (pt)
98 {
99 pt->SetLineWidth(lwidth);
100 pt->StampObjProps();
101 }
102 }
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Set rendering of line. Propagate to projected lines.
109
111{
112 fRnrLine = r;
113 for (auto &pi: fProjectedList)
114 {
115 REveLine* l = dynamic_cast<REveLine*>(pi);
116 if (l)
117 {
118 l->SetRnrLine(r);
119 l->StampObjProps();
120 }
121 }
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Set rendering of points. Propagate to projected lines.
127
129{
130 fRnrPoints = r;
131 for (auto &pi: fProjectedList)
132 {
133 REveLine *l = dynamic_cast<REveLine*>(pi);
134 if (l)
135 {
136 l->SetRnrPoints(r);
137 l->StampObjProps();
138 }
139 }
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Set smooth rendering. Propagate to projected lines.
145
147{
148 fSmooth = r;
149 for (auto &pi: fProjectedList)
150 {
151 REveLine* l = dynamic_cast<REveLine*>(pi);
152 if (l)
153 {
154 l->SetSmooth(r);
155 l->StampObjProps();
156 }
157 }
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Make sure that no segment is longer than max.
163/// Per point references and integer ids are lost.
164
166{
167 // XXXX rewrite
168
169 const Float_t max2 = max*max;
170
171 Float_t *p = & fPoints[0].fX;
172 Int_t s = fSize;
173 REveVector a, b, d;
174
175 std::vector<REveVector> q;
176
177 b.Set(p);
178 q.push_back(b);
179 for (Int_t i = 1; i < s; ++i)
180 {
181 a = b; b.Set(&p[3*i]); d = b - a;
182 Float_t m2 = d.Mag2();
183 if (m2 > max2)
184 {
185 Float_t f = TMath::Sqrt(m2) / max;
187 d *= 1.0f / (n + 1);
188 for (Int_t j = 0; j < n; ++j)
189 {
190 a += d;
191 q.push_back(a);
192 }
193 }
194 q.push_back(b);
195 }
196
197 s = q.size();
198 Reset(s);
199 for (auto &i: q)
200 SetNextPoint(i.fX, i.fY, i.fZ);
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Sum-up lengths of individual segments.
205
207{
208 Float_t sum = 0;
209
210 for (Int_t i = 1; i < fSize; ++i)
211 {
212 sum += fPoints[i - 1].Distance(fPoints[i]);
213 }
214
215 return sum;
216}
217
218////////////////////////////////////////////////////////////////////////////////
219/// Return the first point of the line.
220/// If there are no points (0,0,0) is returned.
221
223{
225 if (fSize > 0) v = RefPoint(0);
226 return v;
227}
228
229////////////////////////////////////////////////////////////////////////////////
230/// Return the last point of the line.
231/// If there are no points (0,0,0) is returned.
232
234{
236 if (fSize > 0) v = RefPoint(fSize - 1);
237 return v;
238}
239
240////////////////////////////////////////////////////////////////////////////////
241/// Copy visualization parameters from element el.
242
244{
245 const REveLine* m = dynamic_cast<const REveLine*>(el);
246 if (m)
247 {
248 TAttLine::operator=(*m);
249 fRnrLine = m->fRnrLine;
250 fRnrPoints = m->fRnrPoints;
251 fSmooth = m->fSmooth;
252 }
253
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// Write visualization parameters.
259
260void REveLine::WriteVizParams(std::ostream& out, const TString& var)
261{
263
264 TString t = " " + var + "->";
266 out << t << "SetRnrLine(" << ToString(fRnrLine) << ");\n";
267 out << t << "SetRnrPoints(" << ToString(fRnrPoints) << ");\n";
268 out << t << "SetSmooth(" << ToString(fSmooth) << ");\n";
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Virtual from REveProjectable, returns REvePointSetProjected class.
273
275{
276 return TClass::GetClass<REveLineProjected>();
277}
278
279//------------------------------------------------------------------------------
280
281Int_t REveLine::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
282{
283 Int_t ret = REvePointSet::WriteCoreJson(j, rnr_offset);
284
285 j["fLineWidth"] = GetLineWidth();
286 j["fLineStyle"] = GetLineStyle();
287 j["fLineColor"] = GetLineColor();
288
289 return ret;
290}
291
292////////////////////////////////////////////////////////////////////////////////
293/// Virtual from REveElement. Prepares render data for binary streaming to client
294
296{
297 if (fSize > 0)
298 {
299 fRenderData = std::make_unique<REveRenderData>("makeTrack", 3*fSize);
300 fRenderData->PushV(&fPoints[0].fX, 3*fSize);
301 }
302}
303
304////////////////////////////////////////////////////////////////////////////////
305/// Get default value for smooth-line drawing flag.
306/// Static function.
307
309{
310 return fgDefaultSmooth;
311}
312
313////////////////////////////////////////////////////////////////////////////////
314/// Set default value for smooth-line drawing flag (default kFALSE).
315/// Static function.
316
318{
320}
321
322/** \class REveLineProjected
323\ingroup REve
324Projected copy of a REveLine.
325*/
326
327
328////////////////////////////////////////////////////////////////////////////////
329/// Default constructor.
330
332 REveLine (),
334{
335}
336
337////////////////////////////////////////////////////////////////////////////////
338/// Set projection manager and projection model.
339/// Virtual from REveProjected.
340
342 REveProjectable* model)
343{
345 CopyVizParams(dynamic_cast<REveElement*>(model));
346}
347
348////////////////////////////////////////////////////////////////////////////////
349/// Set depth (z-coordinate) of the projected points.
350
352{
353 SetDepthCommon(d, this, fBBox);
354
355 Int_t n = fSize;
356 Float_t *p = & fPoints[0].fZ;
357 for (Int_t i = 0; i < n; ++i, p+=3)
358 *p = fDepth;
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// Re-apply the projection.
363/// Virtual from REveProjected.
364
366{
368 REveLine & als = * dynamic_cast<REveLine*>(fProjectable);
369 REveTrans *tr = als.PtrMainTrans(kFALSE);
370
371 Int_t n = als.GetSize();
372 Reset(n);
373 fSize = n;
374 const Float_t *o = & als.RefPoint(0).fX;
375 Float_t *p = & fPoints[0].fX;
376 for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
377 {
378 proj.ProjectPointfv(tr, o, p, fDepth);
379 }
380}
ROOT::R::TRInterface & r
Definition Object.C:4
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
const Bool_t kFALSE
Definition RtypesCore.h:92
short Width_t
Definition RtypesCore.h:82
bool Bool_t
Definition RtypesCore.h:63
short Color_t
Definition RtypesCore.h:83
short Style_t
Definition RtypesCore.h:80
const Bool_t kTRUE
Definition RtypesCore.h:91
@ kGreen
Definition Rtypes.h:66
char name[80]
Definition TGX11.cxx:110
float * q
std::unique_ptr< REveRenderData > fRenderData
Externally assigned and controlled user data.
virtual REveTrans * PtrMainTrans(Bool_t create=kTRUE)
Return pointer to main transformation.
static const std::string & ToString(Bool_t b)
Convert Bool_t to string - kTRUE or kFALSE.
REveLineProjected()
Default constructor.
Definition REveLine.cxx:331
void SetDepthLocal(Float_t d) override
Set depth (z-coordinate) of the projected points.
Definition REveLine.cxx:351
void SetProjection(REveProjectionManager *mng, REveProjectable *model) override
Set projection manager and projection model.
Definition REveLine.cxx:341
void UpdateProjection() override
Re-apply the projection.
Definition REveLine.cxx:365
REveLine An arbitrary polyline with fixed line and marker attributes.
Definition REveLine.hxx:30
REveVector GetLineEnd() const
Return the last point of the line.
Definition REveLine.cxx:233
void ReduceSegmentLengths(Float_t max)
Make sure that no segment is longer than max.
Definition REveLine.cxx:165
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
Definition REveLine.cxx:243
void SetSmooth(Bool_t r)
Set smooth rendering. Propagate to projected lines.
Definition REveLine.cxx:146
void SetMarkerColor(Color_t col) override
Set marker color. Propagate to projected lines.
Definition REveLine.cxx:56
void WriteVizParams(std::ostream &out, const TString &var) override
Write visualization parameters.
Definition REveLine.cxx:260
REveVector GetLineStart() const
Return the first point of the line.
Definition REveLine.cxx:222
REveLine(const std::string &name="", const std::string &title="", Int_t n_points=0)
Constructor.
Definition REveLine.cxx:31
void SetLineWidth(Width_t lwidth) override
Set line-style of the line.
Definition REveLine.cxx:92
static Bool_t GetDefaultSmooth()
Get default value for smooth-line drawing flag.
Definition REveLine.cxx:308
static void SetDefaultSmooth(Bool_t r)
Set default value for smooth-line drawing flag (default kFALSE).
Definition REveLine.cxx:317
static Bool_t fgDefaultSmooth
Definition REveLine.hxx:39
void SetLineStyle(Style_t lstyle) override
Set line-style of the line.
Definition REveLine.cxx:74
Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override
Write core json.
Definition REveLine.cxx:281
void SetRnrLine(Bool_t r)
Set rendering of line. Propagate to projected lines.
Definition REveLine.cxx:110
Float_t CalculateLineLength() const
Sum-up lengths of individual segments.
Definition REveLine.cxx:206
void SetRnrPoints(Bool_t r)
Set rendering of points. Propagate to projected lines.
Definition REveLine.cxx:128
TClass * ProjectedClass(const REveProjection *p) const override
Virtual from REveProjectable, returns REvePointSetProjected class.
Definition REveLine.cxx:274
void BuildRenderData() override
Virtual from REveElement. Prepares render data for binary streaming to client.
Definition REveLine.cxx:295
void WriteVizParams(std::ostream &out, const TString &var) override
Write visualization parameters.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Write core json.
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
std::vector< REveVector > fPoints
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.
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.
void Set(const Float_t *v)
Float_t * fBBox
Definition TAttBBox.h:20
Line Attributes class.
Definition TAttLine.h:18
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:33
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:42
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:35
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:34
Color_t fLineColor
Line color.
Definition TAttLine.h:21
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition TAttLine.cxx:270
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
Color_t fMarkerColor
Marker color.
Definition TAttMarker.h:22
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
Basic string class.
Definition TString.h:136
TPaveText * pt
const Int_t n
Definition legend1.C:16
Int_t FloorNint(Double_t x)
Definition TMath.h:707
Double_t Sqrt(Double_t x)
Definition TMath.h:691
auto * m
Definition textangle.C:8
auto * l
Definition textangle.C:4
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345