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
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 if (nVertices == 0)
191 return;
192
193 fRenderData = std::make_unique<REveRenderData>("makeStraightLineSet", 3 * nVertices, 0, nVertices);
194
195 // printf("REveStraightLineSet::BuildRenderData id = %d \n", GetElementId());
197 while (li.next())
198 {
199 Line_t *l = (Line_t*) li();
200
201 fRenderData->PushV(l->fV1[0], l->fV1[1],l->fV1[2]);
202 fRenderData->PushV(l->fV2[0], l->fV2[1],l->fV2[2]);
203 fRenderData->PushI(l->fId);
204 }
205
206
208 while (mi.next())
209 {
210 Marker_t *m = (Marker_t*) mi();
211 fRenderData->PushV(m->fV[0], m->fV[1], m->fV[2]);
212 fRenderData->PushI(m->fLineId);
213 }
214
216
217 // printf("REveStraightLineSet::BuildRenderData size= %d\n", fRenderData->GetBinarySize());
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// Return class of projected object.
222/// Virtual from REveProjectable.
223
225{
226 return TClass::GetClass<REveStraightLineSetProjected>();
227}
228
229////////////////////////////////////////////////////////////////////////////////
230/// Fill the bounding box (virtual from REveElement).
231
233{
234 BBoxInit();
235
237 while (li.next()) {
238 BBoxCheckPoint(((Line_t*)li())->fV1);
239 BBoxCheckPoint(((Line_t*)li())->fV2);
240 }
241
243 while (mi.next())
244 {
245 BBoxCheckPoint(((Marker_t*)mi())->fV);
246 }
247}
248
249
250/** \class REveStraightLineSetProjected
251\ingroup REve
252Projected replica of a REveStraightLineSet.
253*/
254
255
256////////////////////////////////////////////////////////////////////////////////
257/// Constructor.
258
263
264////////////////////////////////////////////////////////////////////////////////
265/// Set projection manager and model object.
266
274
275////////////////////////////////////////////////////////////////////////////////
276/// Set depth (z-coordinate) of the projected points.
277
279{
280 SetDepthCommon(d, this);
281
283 while (li.next())
284 {
286 l.fV1[2] = fDepth;
287 l.fV2[2] = fDepth;
288 }
289
291 while (mi.next())
292 {
293 Marker_t& m = * (Marker_t*) mi();
294 m.fV[2] = fDepth;
295 }
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Callback that actually performs the projection.
300/// Called when projection parameters have been updated.
301
303{
305 REveStraightLineSet& orig = * dynamic_cast<REveStraightLineSet*>(fProjectable);
306
307 REveTrans mt;
308 const REveTrans *trans = fManager->GetModelTrans(&orig, mt);
309
310 BBoxClear();
311
312 // Lines
313 Int_t num_lines = orig.GetLinePlex().Size();
314 if (proj.HasSeveralSubSpaces())
315 num_lines += TMath::Max(1, num_lines/10);
316 fLinePlex.Reset(sizeof(Line_t), num_lines);
317 REveVector p1, p2;
319 while (li.next())
320 {
321 Line_t *l = (Line_t*) li();
322
323 proj.ProjectPointfv(trans, l->fV1, p1, fDepth);
324 proj.ProjectPointfv(trans, l->fV2, p2, fDepth);
325
326 if (proj.AcceptSegment(p1, p2, 0.1f))
327 {
328 AddLine(p1, p2)->fId = l->fId;
329 }
330 else
331 {
332 REveVector bp1(l->fV1), bp2(l->fV2);
333 if (trans) {
334 trans->MultiplyIP(bp1);
335 trans->MultiplyIP(bp2);
336 }
337 proj.BisectBreakPoint(bp1, bp2, kTRUE, fDepth);
338
339 AddLine(p1, bp1)->fId = l->fId;
340 AddLine(bp2, p2)->fId = l->fId;
341 }
342 }
343 if (proj.HasSeveralSubSpaces())
345
346 // Markers
347 fMarkerPlex.Reset(sizeof(Marker_t), orig.GetMarkerPlex().Size());
349 REveVector pp;
350 while (mi.next())
351 {
352 Marker_t &m = * (Marker_t*) mi();
353
354 proj.ProjectPointfv(trans, m.fV, pp, fDepth);
355 AddMarker(pp, m.fLineId);
356 }
358}
#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
! Vertex / normal / triangle index information for rendering.
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 BuildRenderData()
Build fRenderData, what the client draws.
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.
static void CalcTextureSize(int nel, int align, int &sx, int &sy)
Calculate texture dimensions to hold nel elements with given alignment on x axis.
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
Fill the bounding box (virtual from REveElement).
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.
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
R__EXTERN REveManager * gEve
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