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