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#include <ROOT/REveTrans.hxx>
16
17#include "TClass.h"
18
19#include <nlohmann/json.hpp>
20
21using namespace ROOT::Experimental;
22
23/** \class REveLine
24\ingroup REve
25An arbitrary polyline with fixed line and marker attributes.
26*/
27
28Bool_t REveLine::fgDefaultSmooth = kFALSE;
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 {
251 TAttLine::operator=(*m);
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
284Int_t REveLine::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
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
315
316////////////////////////////////////////////////////////////////////////////////
317/// Set default value for smooth-line drawing flag (default kFALSE).
318/// Static function.
319
324
325/** \class REveLineProjected
326\ingroup REve
327Projected copy of a REveLine.
328*/
329
330
331////////////////////////////////////////////////////////////////////////////////
332/// Default constructor.
333
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);
357
358 for (Int_t i = 0; i < fSize; ++i)
359 fPoints[i].fZ = fDepth;
360}
361
362////////////////////////////////////////////////////////////////////////////////
363/// Re-apply the projection.
364/// Virtual from REveProjected.
365
367{
369 REveLine & als = * dynamic_cast<REveLine*>(fProjectable);
370 REveTrans mt;
371 const REveTrans *tr = fManager->GetModelTrans(&als, mt);
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
Style number (short)
Definition RtypesCore.h:97
short Color_t
Color number (short)
Definition RtypesCore.h:100
short Width_t
Line width (short)
Definition RtypesCore.h:99
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
@ 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:142
float * q
std::unique_ptr< REveRenderData > fRenderData
! Vertex / normal / triangle index information for rendering.
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:366
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)
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.
Line Attributes class.
Definition TAttLine.h:21
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:36
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:46
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:38
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:37
Color_t fLineColor
Line color.
Definition TAttLine.h:24
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:289
Color_t fMarkerColor
Marker color.
Definition TAttMarker.h:25
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
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
const Int_t n
Definition legend1.C:16
Namespace for ROOT features in testing.
Definition TROOT.h:100
Int_t FloorNint(Double_t x)
Returns the nearest integer of TMath::Floor(x).
Definition TMath.h:699
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:675
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2335