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