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////////////////////////////////////////////////////////////////////////////////
23/// Constructor.
24
25REveStraightLineSet::REveStraightLineSet(const std::string& n, const std::string& t):
26 REveElement (n, t),
27
28 fLinePlex (sizeof(Line_t), 4),
29 fMarkerPlex (sizeof(Marker_t), 8),
30 fOwnLinesIds (kFALSE),
31 fOwnMarkersIds (kFALSE),
32 fRnrMarkers (kTRUE),
33 fRnrLines (kTRUE),
34 fDepthTest (kTRUE),
35 fLastLine (0)
36{
39
41 fLineColor = 4;
42 fMarkerColor = 2;
43 fMarkerStyle = 20;
44}
45
46////////////////////////////////////////////////////////////////////////////////
47/// Add a line.
48
51 Float_t x2, Float_t y2, Float_t z2)
52{
53 fLastLine = new (fLinePlex.NewAtom()) Line_t(x1, y1, z1, x2, y2, z2);
54 fLastLine->fId = fLinePlex.Size() - 1;
55 return fLastLine;
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Add a line.
60
63{
64 return AddLine(p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
65}
66
67////////////////////////////////////////////////////////////////////////////////
68/// Set line vertices with given index.
69
70void
72 Float_t x1, Float_t y1, Float_t z1,
73 Float_t x2, Float_t y2, Float_t z2)
74{
75 Line_t* l = (Line_t*) fLinePlex.Atom(idx);
76
77 l->fV1[0] = x1; l->fV1[1] = y1; l->fV1[2] = z1;
78 l->fV2[0] = x2; l->fV2[1] = y2; l->fV2[2] = z2;
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Set line vertices with given index.
83
84void
86{
87 SetLine(idx, p1.fX, p1.fY, p1.fZ, p2.fX, p2.fY, p2.fZ);
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Add a marker with given position.
92
95{
96 Marker_t* marker = new (fMarkerPlex.NewAtom()) Marker_t(x, y, z, line_id);
97 return marker;
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Add a marker with given position.
102
105{
106 return AddMarker(p.fX, p.fY, p.fZ, line_id);
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// Add a marker for line with given index on relative position pos.
111
114{
115 Line_t& l = * (Line_t*) fLinePlex.Atom(line_id);
116 return AddMarker(l.fV1[0] + (l.fV2[0] - l.fV1[0])*pos,
117 l.fV1[1] + (l.fV2[1] - l.fV1[1])*pos,
118 l.fV1[2] + (l.fV2[2] - l.fV1[2])*pos,
119 line_id);
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Copy visualization parameters from element el.
124
126{
127 const REveStraightLineSet* m = dynamic_cast<const REveStraightLineSet*>(el);
128 if (m)
129 {
130 TAttLine::operator=(*m);
131 TAttMarker::operator=(*m);
132 fRnrMarkers = m->fRnrMarkers;
133 fRnrLines = m->fRnrLines;
134 fDepthTest = m->fDepthTest;
135 }
136
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// Write visualization parameters.
142
143void REveStraightLineSet::WriteVizParams(std::ostream& out, const TString& var)
144{
146
147 TString t = " " + var + "->";
149 TAttLine ::SaveLineAttributes (out, var);
150 out << t << "SetRnrMarkers(" << ToString(fRnrMarkers) << ");\n";
151 out << t << "SetRnrLines(" << ToString(fRnrLines) << ");\n";
152 out << t << "SetDepthTest(" << ToString(fDepthTest) << ");\n";
153}
154
155
156////////////////////////////////////////////////////////////////////////////////
157/// Fill core part of JSON representation.
158
160{
161 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
162
163 j["fLinePlexSize"] = fLinePlex.Size();
164 j["fMarkerPlexSize"] = fMarkerPlex.Size();
165 j["fLineWidth"] = fLineWidth;
166 j["fLineStyle"] = fLineStyle;
167 j["fMarkerSize"] = fMarkerSize;
168 j["fMarkerStyle"] = fMarkerStyle;
169 j["fSecondarySelect"] = fAlwaysSecSelect;
170
171 return ret;
172}
173
174////////////////////////////////////////////////////////////////////////////////
175/// Crates 3D point array for rendering.
176
178{
179 int nVertices = fLinePlex.Size() * 2 + fMarkerPlex.Size();
180 fRenderData = std::make_unique<REveRenderData>("makeStraightLineSet", 3 * nVertices, 0, nVertices);
181
182 // printf("REveStraightLineSet::BuildRenderData id = %d \n", GetElementId());
184 while (li.next())
185 {
186 Line_t *l = (Line_t*) li();
187
188 fRenderData->PushV(l->fV1[0], l->fV1[1],l->fV1[2]);
189 fRenderData->PushV(l->fV2[0], l->fV2[1],l->fV2[2]);
190 fRenderData->PushI(l->fId);
191 }
192
193
195 while (mi.next())
196 {
197 Marker_t *m = (Marker_t*) mi();
198 fRenderData->PushV(m->fV[0], m->fV[1], m->fV[2]);
199 fRenderData->PushI(m->fLineId);
200 }
201
203
204 // printf("REveStraightLineSet::BuildRenderData size= %d\n", fRenderData->GetBinarySize());
205}
206
207////////////////////////////////////////////////////////////////////////////////
208/// Return class of projected object.
209/// Virtual from REveProjectable.
210
212{
213 return TClass::GetClass<REveStraightLineSetProjected>();
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// Compute bounding-box.
218/// Virtual from TAttBBox.
219
221{
222 if (fLinePlex.Size() == 0 && fMarkerPlex.Size() == 0) {
223 BBoxZero();
224 return;
225 }
226
227 BBoxInit();
228
230 while (li.next()) {
231 BBoxCheckPoint(((Line_t*)li())->fV1);
232 BBoxCheckPoint(((Line_t*)li())->fV2);
233 }
234
236 while (mi.next())
237 {
238 BBoxCheckPoint(((Marker_t*)mi())->fV);
239 }
240}
241
242
243/** \class REveStraightLineSetProjected
244\ingroup REve
245Projected replica of a REveStraightLineSet.
246*/
247
249
250////////////////////////////////////////////////////////////////////////////////
251/// Constructor.
252
255{
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Set projection manager and model object.
260
262 REveProjectable* model)
263{
265
266 CopyVizParams(dynamic_cast<REveElement*>(model));
267}
268
269////////////////////////////////////////////////////////////////////////////////
270/// Set depth (z-coordinate) of the projected points.
271
273{
274 SetDepthCommon(d, this, fBBox);
275
277 while (li.next())
278 {
280 l.fV1[2] = fDepth;
281 l.fV2[2] = fDepth;
282 }
283
285 while (mi.next())
286 {
287 Marker_t& m = * (Marker_t*) mi();
288 m.fV[2] = fDepth;
289 }
290}
291
292////////////////////////////////////////////////////////////////////////////////
293/// Callback that actually performs the projection.
294/// Called when projection parameters have been updated.
295
297{
299 REveStraightLineSet& orig = * dynamic_cast<REveStraightLineSet*>(fProjectable);
300
301 REveTrans *trans = orig.PtrMainTrans(kFALSE);
302
303 BBoxClear();
304
305 // Lines
306 Int_t num_lines = orig.GetLinePlex().Size();
307 if (proj.HasSeveralSubSpaces())
308 num_lines += TMath::Max(1, num_lines/10);
309 fLinePlex.Reset(sizeof(Line_t), num_lines);
310 REveVector p1, p2;
312 while (li.next())
313 {
314 Line_t *l = (Line_t*) li();
315
316 proj.ProjectPointfv(trans, l->fV1, p1, fDepth);
317 proj.ProjectPointfv(trans, l->fV2, p2, fDepth);
318
319 if (proj.AcceptSegment(p1, p2, 0.1f))
320 {
321 AddLine(p1, p2)->fId = l->fId;
322 }
323 else
324 {
325 REveVector bp1(l->fV1), bp2(l->fV2);
326 if (trans) {
327 trans->MultiplyIP(bp1);
328 trans->MultiplyIP(bp2);
329 }
330 proj.BisectBreakPoint(bp1, bp2, kTRUE, fDepth);
331
332 AddLine(p1, bp1)->fId = l->fId;
333 AddLine(bp2, p2)->fId = l->fId;
334 }
335 }
336 if (proj.HasSeveralSubSpaces())
338
339 // Markers
340 fMarkerPlex.Reset(sizeof(Marker_t), orig.GetMarkerPlex().Size());
342 REveVector pp;
343 while (mi.next())
344 {
345 Marker_t &m = * (Marker_t*) mi();
346
347 proj.ProjectPointfv(trans, m.fV, pp, fDepth);
348 AddMarker(pp, m.fLineId);
349 }
351}
#define d(i)
Definition RSha256.hxx:102
static const double x2[5]
static const double x1[5]
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
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.
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:58
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:80
Basic string class.
Definition TString.h:136
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Short_t Max(Short_t a, Short_t b)
Definition TMathBase.h:208
basic_json< std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, adl_serializer, std::vector< std::uint8_t > > json
auto * m
Definition textangle.C:8
auto * l
Definition textangle.C:4