Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveStraightLineSet.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
15
16#include "TClass.h"
17
18#include <nlohmann/json.hpp>
19
20using namespace ROOT::Experimental;
21
22/** \class REveStraightLineSet
23\ingroup REve
24Set of straight lines with optional markers along the lines.
25
26The render data holds every line and every marker, in plex order:
27 - `pos`, f32 x 3, the two vertices of each line, drawn as lines; the
28 client's line index is the line's plex index.
29 - `mrk`, f32 x 4 in an rgba32f texture, one texel (x, y, z, 0) per marker;
30 the client's marker index is the marker's plex index.
31 - `mline`, i32, the fLineId of each marker: a picked marker selects its
32 line, and a selected line outlines its markers.
33An entry is left out when it would be empty. The lines' fId is not sent: the
34client takes a line's plex index as its id.
35*/
36
37////////////////////////////////////////////////////////////////////////////////
38/// Constructor.
39
40REveStraightLineSet::REveStraightLineSet(const std::string& n, const std::string& t):
41 REveElement (n, t),
42
43 fLinePlex (sizeof(Line_t), 4),
44 fMarkerPlex (sizeof(Marker_t), 8),
45 fOwnLinesIds (kFALSE),
46 fOwnMarkersIds (kFALSE),
47 fRnrMarkers (kTRUE),
48 fRnrLines (kTRUE),
49 fDepthTest (kTRUE),
50 fLastLine (nullptr)
51{
54
56 fLineColor = 4;
57 fMarkerColor = 2;
58 fMarkerStyle = 20;
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Add a line.
63
72
73////////////////////////////////////////////////////////////////////////////////
74/// Add a line.
75
78{
79 return AddLine(p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Set line vertices with given index.
84
85void
89{
90 Line_t* l = (Line_t*) fLinePlex.Atom(idx);
91
92 l->fV1[0] = x1; l->fV1[1] = y1; l->fV1[2] = z1;
93 l->fV2[0] = x2; l->fV2[1] = y2; l->fV2[2] = z2;
94}
95
96////////////////////////////////////////////////////////////////////////////////
97/// Set line vertices with given index.
98
99void
101{
102 SetLine(idx, p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// Add a marker with given position.
107
110{
111 Marker_t* marker = new (fMarkerPlex.NewAtom()) Marker_t(x, y, z, line_id);
112 return marker;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Add a marker with given position.
117
120{
121 return AddMarker(p.fX, p.fY, p.fZ, line_id);
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Add a marker for line with given index on relative position pos.
126
129{
130 Line_t& l = * (Line_t*) fLinePlex.Atom(line_id);
131 return AddMarker(l.fV1[0] + (l.fV2[0] - l.fV1[0])*pos,
132 l.fV1[1] + (l.fV2[1] - l.fV1[1])*pos,
133 l.fV1[2] + (l.fV2[2] - l.fV1[2])*pos,
134 line_id);
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// Copy visualization parameters from element el.
139
141{
142 const REveStraightLineSet* m = dynamic_cast<const REveStraightLineSet*>(el);
143 if (m)
144 {
145 TAttLine::operator=(*m);
146 TAttMarker::operator=(*m);
147 fRnrMarkers = m->fRnrMarkers;
148 fRnrLines = m->fRnrLines;
149 fDepthTest = m->fDepthTest;
150 }
151
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Write visualization parameters.
157
158void REveStraightLineSet::WriteVizParams(std::ostream& out, const TString& var)
159{
161
162 TString t = " " + var + "->";
164 TAttLine ::SaveLineAttributes (out, var);
165 out << t << "SetRnrMarkers(" << ToString(fRnrMarkers) << ");\n";
166 out << t << "SetRnrLines(" << ToString(fRnrLines) << ");\n";
167 out << t << "SetDepthTest(" << ToString(fDepthTest) << ");\n";
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Fill core part of JSON representation. The numbers of lines and markers
172/// and the marker texture's size are the entries' count and tex, see
173/// BuildRenderData().
174
175Int_t REveStraightLineSet::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
176{
177 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
178
179 // j["fLineColor"] = fLineColor; // streamed as fMainColor
180 j["fLineWidth"] = fLineWidth;
181 j["fLineStyle"] = fLineStyle;
182 j["fMarkerColor"] = fMarkerColor;
183 j["fMarkerSize"] = fMarkerSize;
184 j["fMarkerStyle"] = fMarkerStyle;
185 j["fSecondarySelect"] = fAlwaysSecSelect;
186
187 return ret;
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// Write the render data entries `pos`, `mrk` and `mline`, see the class
192/// description. A set without lines and markers has no render data.
193
195{
196 const int n_lines = fLinePlex.Size();
197 const int n_markers = fMarkerPlex.Size();
198 if (n_lines + n_markers == 0)
199 return;
200
201 using RD = REveRenderData;
202 fRenderData = std::make_unique<RD>("makeStraightLineSet");
203
204 if (n_lines > 0) {
205 auto &pos = fRenderData->NewEntry("pos", RD::EType::kF32, 3)
206 .Role(RD::ERole::kVertex)
207 .Prim(RD::EPrim::kLines)
208 .Reserve(2 * n_lines);
210 while (li.next()) {
211 Line_t *l = (Line_t *)li();
212 pos.Push((const Float_t *)l->fV1, 3);
213 pos.Push((const Float_t *)l->fV2, 3);
214 }
215 }
216
217 if (n_markers > 0) {
218 auto &mrk = fRenderData->NewEntry("mrk", RD::EType::kF32, 4).Reserve(n_markers);
219 auto &mline = fRenderData->NewEntry("mline", RD::EType::kI32, 1).Role(RD::ERole::kData).Reserve(n_markers);
221 while (mi.next()) {
222 Marker_t *m = (Marker_t *)mi();
223 mrk.Push(m->fV[0], m->fV[1], m->fV[2], 0.f);
224 mline.Push(m->fLineId);
225 }
226 // The client's sprite shader reads one texel per instance.
227 mrk.AsTexture(RD::ETexFormat::kRGBA32F, 1);
228 }
229}
230
231////////////////////////////////////////////////////////////////////////////////
232/// Return class of projected object.
233/// Virtual from REveProjectable.
234
236{
237 return TClass::GetClass<REveStraightLineSetProjected>();
238}
239
240////////////////////////////////////////////////////////////////////////////////
241/// Fill the bounding box (virtual from REveElement).
242
244{
245 BBoxInit();
246
248 while (li.next()) {
249 BBoxCheckPoint(((Line_t*)li())->fV1);
250 BBoxCheckPoint(((Line_t*)li())->fV2);
251 }
252
254 while (mi.next())
255 {
256 BBoxCheckPoint(((Marker_t*)mi())->fV);
257 }
258}
259
260
261/** \class REveStraightLineSetProjected
262\ingroup REve
263Projected replica of a REveStraightLineSet.
264*/
265
266
267////////////////////////////////////////////////////////////////////////////////
268/// Constructor.
269
274
275////////////////////////////////////////////////////////////////////////////////
276/// Set projection manager and model object.
277
285
286////////////////////////////////////////////////////////////////////////////////
287/// Set depth (z-coordinate) of the projected points.
288
290{
291 SetDepthCommon(d, this);
292
294 while (li.next())
295 {
297 l.fV1[2] = fDepth;
298 l.fV2[2] = fDepth;
299 }
300
302 while (mi.next())
303 {
304 Marker_t& m = * (Marker_t*) mi();
305 m.fV[2] = fDepth;
306 }
307}
308
309////////////////////////////////////////////////////////////////////////////////
310/// Callback that actually performs the projection.
311/// Called when projection parameters have been updated.
312
314{
316 REveStraightLineSet& orig = * dynamic_cast<REveStraightLineSet*>(fProjectable);
317
318 REveTrans mt;
319 const REveTrans *trans = fManager->GetModelTrans(&orig, mt);
320
321 BBoxClear();
322
323 // Lines
324 Int_t num_lines = orig.GetLinePlex().Size();
325 if (proj.HasSeveralSubSpaces())
326 num_lines += TMath::Max(1, num_lines/10);
327 fLinePlex.Reset(sizeof(Line_t), num_lines);
328 REveVector p1, p2;
330 while (li.next())
331 {
332 Line_t *l = (Line_t*) li();
333
334 proj.ProjectPointfv(trans, l->fV1, p1, fDepth);
335 proj.ProjectPointfv(trans, l->fV2, p2, fDepth);
336
337 if (proj.AcceptSegment(p1, p2, 0.1f))
338 {
339 AddLine(p1, p2)->fId = l->fId;
340 }
341 else
342 {
343 REveVector bp1(l->fV1), bp2(l->fV2);
344 if (trans) {
345 trans->MultiplyIP(bp1);
346 trans->MultiplyIP(bp2);
347 }
348 proj.BisectBreakPoint(bp1, bp2, kTRUE, fDepth);
349
350 AddLine(p1, bp1)->fId = l->fId;
351 AddLine(bp2, p2)->fId = l->fId;
352 }
353 }
354 if (proj.HasSeveralSubSpaces())
356
357 // Markers
358 fMarkerPlex.Reset(sizeof(Marker_t), orig.GetMarkerPlex().Size());
360 REveVector pp;
361 while (mi.next())
362 {
363 Marker_t &m = * (Marker_t*) mi();
364
365 proj.ProjectPointfv(trans, m.fV, pp, fDepth);
366 AddMarker(pp, m.fLineId);
367 }
369}
#define d(i)
Definition RSha256.hxx:102
short Marker_t
Marker number (short)
Definition RtypesCore.h:98
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
void Reset(Int_t atom_size, Int_t chunk_size)
Empty the container and reset it with given atom and chunk sizes.
void Refit()
Refit the container so that all current data fits into a single chunk.
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
void BBoxCheckPoint(const REveVector &v)
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write-out visual parameters for this object.
virtual void InitMainTrans(Bool_t can_edit=kTRUE)
Initialize the main transformation to identity matrix, without motion.
std::unique_ptr< REveRenderData > fRenderData
! Render data entries for the client's maker, see REveRenderData.
static const std::string & ToString(Bool_t b)
Convert Bool_t to string - kTRUE or kFALSE.
virtual void CopyVizParams(const REveElement *el)
Copy visualization parameters from element el.
void BBoxInit()
Start filling the bounding box with BBoxCheckPoint(): min at +infinity, max at -infinity,...
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.
virtual Bool_t HasSeveralSubSpaces() const
virtual Bool_t AcceptSegment(REveVector &, REveVector &, Float_t) const
virtual void BisectBreakPoint(REveVector &vL, REveVector &vR, Float_t eps_sqr)
Find break-point on both sides of the discontinuity.
Render data of an element: a client maker name and a list of tagged entries, each a typed array with ...
void UpdateProjection() override
Callback that actually performs the projection.
void SetDepthLocal(Float_t d) override
Set depth (z-coordinate) of the projected points.
void SetProjection(REveProjectionManager *mng, REveProjectable *model) override
Set projection manager and model object.
REveStraightLineSet Set of straight lines with optional markers along the lines.
Line_t * AddLine(Float_t x1, Float_t y1, Float_t z1, Float_t x2, Float_t y2, Float_t z2)
Add a line.
Marker_t * AddMarker(Float_t x, Float_t y, Float_t z, Int_t line_id=-1)
Add a marker with given position.
TClass * ProjectedClass(const REveProjection *p) const override
Return class of projected object.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
void BuildRenderData() override
Write the render data entries pos, mrk and mline, see the class description.
void ComputeBBox() override
Fill the bounding box (virtual from REveElement).
void SetLine(int idx, Float_t x1, Float_t y1, Float_t z1, Float_t x2, Float_t y2, Float_t z2)
Set line vertices with given index.
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
void WriteVizParams(std::ostream &out, const TString &var) override
Write visualization parameters.
void MultiplyIP(TVector3 &v, Double_t w=1) const
Multiply vector in-place.
Width_t fLineWidth
Line width.
Definition TAttLine.h:26
Style_t fLineStyle
Line style.
Definition TAttLine.h:25
Color_t fLineColor
Line color.
Definition TAttLine.h:24
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.
Color_t fMarkerColor
Marker color.
Definition TAttMarker.h:25
Size_t fMarkerSize
Marker size.
Definition TAttMarker.h:27
Style_t fMarkerStyle
Marker style.
Definition TAttMarker.h:26
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
Basic string class.
Definition TString.h:137
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
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:249
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4