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