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
14#include <ROOT/REveManager.hxx>
16
17#include "TClass.h"
18
19#include <nlohmann/json.hpp>
20
21using namespace ROOT::Experimental;
22
23////////////////////////////////////////////////////////////////////////////////
24/// Constructor.
25
26REveStraightLineSet::REveStraightLineSet(const std::string& n, const std::string& t):
27 REveElement (n, t),
28
29 fLinePlex (sizeof(Line_t), 4),
30 fMarkerPlex (sizeof(Marker_t), 8),
31 fOwnLinesIds (kFALSE),
32 fOwnMarkersIds (kFALSE),
33 fRnrMarkers (kTRUE),
34 fRnrLines (kTRUE),
35 fDepthTest (kTRUE),
36 fLastLine (nullptr)
37{
40
42 fLineColor = 4;
43 fMarkerColor = 2;
44 fMarkerStyle = 20;
45}
46
47////////////////////////////////////////////////////////////////////////////////
48/// Add a line.
49
53{
54 fLastLine = new (fLinePlex.NewAtom()) Line_t(x1, y1, z1, x2, y2, z2);
55 fLastLine->fId = fLinePlex.Size() - 1;
56 return fLastLine;
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Add a line.
61
64{
65 return AddLine(p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Set line vertices with given index.
70
71void
75{
76 Line_t* l = (Line_t*) fLinePlex.Atom(idx);
77
78 l->fV1[0] = x1; l->fV1[1] = y1; l->fV1[2] = z1;
79 l->fV2[0] = x2; l->fV2[1] = y2; l->fV2[2] = z2;
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Set line vertices with given index.
84
85void
87{
88 SetLine(idx, p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Add a marker with given position.
93
96{
97 Marker_t* marker = new (fMarkerPlex.NewAtom()) Marker_t(x, y, z, line_id);
98 return marker;
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Add a marker with given position.
103
106{
107 return AddMarker(p.fX, p.fY, p.fZ, line_id);
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// Add a marker for line with given index on relative position pos.
112
115{
116 Line_t& l = * (Line_t*) fLinePlex.Atom(line_id);
117 return AddMarker(l.fV1[0] + (l.fV2[0] - l.fV1[0])*pos,
118 l.fV1[1] + (l.fV2[1] - l.fV1[1])*pos,
119 l.fV1[2] + (l.fV2[2] - l.fV1[2])*pos,
120 line_id);
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Copy visualization parameters from element el.
125
127{
128 const REveStraightLineSet* m = dynamic_cast<const REveStraightLineSet*>(el);
129 if (m)
130 {
131 TAttLine::operator=(*m);
132 TAttMarker::operator=(*m);
133 fRnrMarkers = m->fRnrMarkers;
134 fRnrLines = m->fRnrLines;
135 fDepthTest = m->fDepthTest;
136 }
137
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Write visualization parameters.
143
144void REveStraightLineSet::WriteVizParams(std::ostream& out, const TString& var)
145{
147
148 TString t = " " + var + "->";
150 TAttLine ::SaveLineAttributes (out, var);
151 out << t << "SetRnrMarkers(" << ToString(fRnrMarkers) << ");\n";
152 out << t << "SetRnrLines(" << ToString(fRnrLines) << ");\n";
153 out << t << "SetDepthTest(" << ToString(fDepthTest) << ");\n";
154}
155
156
157////////////////////////////////////////////////////////////////////////////////
158/// Fill core part of JSON representation.
159
160Int_t REveStraightLineSet::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
161{
162 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
163
164 j["fLinePlexSize"] = fLinePlex.Size();
165 j["fMarkerPlexSize"] = fMarkerPlex.Size();
166 // j["fLineColor"] = fLineColor; // streamed as fMainColor
167 j["fLineWidth"] = fLineWidth;
168 j["fLineStyle"] = fLineStyle;
169 j["fMarkerColor"] = fMarkerColor;
170 j["fMarkerSize"] = fMarkerSize;
171 j["fMarkerStyle"] = fMarkerStyle;
172 j["fSecondarySelect"] = fAlwaysSecSelect;
173
174 if (fMarkerSize && gEve->IsRCore()) {
175 int x, y;
176 int ms = fMarkerPlex.Size();
178 j["fTexX"] = x;
179 j["fTexY"] = y;
180 }
181 return ret;
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// Crates 3D point array for rendering.
186
188{
189 int nVertices = fLinePlex.Size() * 2 + fMarkerPlex.Size();
190 fRenderData = std::make_unique<REveRenderData>("makeStraightLineSet", 3 * nVertices, 0, nVertices);
191
192 // printf("REveStraightLineSet::BuildRenderData id = %d \n", GetElementId());
194 while (li.next())
195 {
196 Line_t *l = (Line_t*) li();
197
198 fRenderData->PushV(l->fV1[0], l->fV1[1],l->fV1[2]);
199 fRenderData->PushV(l->fV2[0], l->fV2[1],l->fV2[2]);
200 fRenderData->PushI(l->fId);
201 }
202
203
205 while (mi.next())
206 {
207 Marker_t *m = (Marker_t*) mi();
208 fRenderData->PushV(m->fV[0], m->fV[1], m->fV[2]);
209 fRenderData->PushI(m->fLineId);
210 }
211
213
214 // printf("REveStraightLineSet::BuildRenderData size= %d\n", fRenderData->GetBinarySize());
215}
216
217////////////////////////////////////////////////////////////////////////////////
218/// Return class of projected object.
219/// Virtual from REveProjectable.
220
222{
223 return TClass::GetClass<REveStraightLineSetProjected>();
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Compute bounding-box.
228/// Virtual from TAttBBox.
229
231{
232 if (fLinePlex.Size() == 0 && fMarkerPlex.Size() == 0) {
233 BBoxZero();
234 return;
235 }
236
237 BBoxInit();
238
240 while (li.next()) {
241 BBoxCheckPoint(((Line_t*)li())->fV1);
242 BBoxCheckPoint(((Line_t*)li())->fV2);
243 }
244
246 while (mi.next())
247 {
248 BBoxCheckPoint(((Marker_t*)mi())->fV);
249 }
250}
251
252
253/** \class REveStraightLineSetProjected
254\ingroup REve
255Projected replica of a REveStraightLineSet.
256*/
257
259
260////////////////////////////////////////////////////////////////////////////////
261/// Constructor.
262
265{
266}
267
268////////////////////////////////////////////////////////////////////////////////
269/// Set projection manager and model object.
270
272 REveProjectable* model)
273{
275
276 CopyVizParams(dynamic_cast<REveElement*>(model));
277}
278
279////////////////////////////////////////////////////////////////////////////////
280/// Set depth (z-coordinate) of the projected points.
281
283{
284 SetDepthCommon(d, this, fBBox);
285
287 while (li.next())
288 {
290 l.fV1[2] = fDepth;
291 l.fV2[2] = fDepth;
292 }
293
295 while (mi.next())
296 {
297 Marker_t& m = * (Marker_t*) mi();
298 m.fV[2] = fDepth;
299 }
300}
301
302////////////////////////////////////////////////////////////////////////////////
303/// Callback that actually performs the projection.
304/// Called when projection parameters have been updated.
305
307{
309 REveStraightLineSet& orig = * dynamic_cast<REveStraightLineSet*>(fProjectable);
310
311 REveTrans *trans = orig.PtrMainTrans(kFALSE);
312
313 BBoxClear();
314
315 // Lines
316 Int_t num_lines = orig.GetLinePlex().Size();
317 if (proj.HasSeveralSubSpaces())
318 num_lines += TMath::Max(1, num_lines/10);
319 fLinePlex.Reset(sizeof(Line_t), num_lines);
320 REveVector p1, p2;
322 while (li.next())
323 {
324 Line_t *l = (Line_t*) li();
325
326 proj.ProjectPointfv(trans, l->fV1, p1, fDepth);
327 proj.ProjectPointfv(trans, l->fV2, p2, fDepth);
328
329 if (proj.AcceptSegment(p1, p2, 0.1f))
330 {
331 AddLine(p1, p2)->fId = l->fId;
332 }
333 else
334 {
335 REveVector bp1(l->fV1), bp2(l->fV2);
336 if (trans) {
337 trans->MultiplyIP(bp1);
338 trans->MultiplyIP(bp2);
339 }
340 proj.BisectBreakPoint(bp1, bp2, kTRUE, fDepth);
341
342 AddLine(p1, bp1)->fId = l->fId;
343 AddLine(bp2, p2)->fId = l->fId;
344 }
345 }
346 if (proj.HasSeveralSubSpaces())
348
349 // Markers
350 fMarkerPlex.Reset(sizeof(Marker_t), orig.GetMarkerPlex().Size());
352 REveVector pp;
353 while (mi.next())
354 {
355 Marker_t &m = * (Marker_t*) mi();
356
357 proj.ProjectPointfv(trans, m.fV, pp, fDepth);
358 AddMarker(pp, m.fLineId);
359 }
361}
#define d(i)
Definition RSha256.hxx:102
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
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.
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.
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.
virtual void CopyVizParams(const REveElement *el)
Copy visualization parameters from element el.
virtual void BuildRenderData()
Write transformation Matrix to render 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.
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.
static void CalcTextureSize(int nel, int align, int &sx, int &sy)
Calculate texture dimensions to hold nel elements with given alignment on x axis.
REveStraightLineSetProjected Projected copy of a REveStraightLineSet.
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
Crates 3D point array for rendering.
void ComputeBBox() override
Compute bounding-box.
REveStraightLineSet(const REveStraightLineSet &)=delete
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.
void BBoxClear()
Remove BBox information.
Definition TAttBBox.cxx:54
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
Definition TAttBBox.h:69
void BBoxZero(Float_t epsilon=0, Float_t x=0, Float_t y=0, Float_t z=0)
Create cube of volume (2*epsilon)^3 at (x,y,z).
Definition TAttBBox.cxx:42
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Definition TAttBBox.cxx:29
Float_t * fBBox
Definition TAttBBox.h:20
Width_t fLineWidth
Line width.
Definition TAttLine.h:23
Style_t fLineStyle
Line style.
Definition TAttLine.h:22
Color_t fLineColor
Line color.
Definition TAttLine.h:21
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:22
Size_t fMarkerSize
Marker size.
Definition TAttMarker.h:24
Style_t fMarkerStyle
Marker style.
Definition TAttMarker.h:23
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
Basic string class.
Definition TString.h:139
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
R__EXTERN REveManager * gEve
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4