Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveEllipsoid.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2020
3
4/*************************************************************************
5 * Copyright (C) 1995-2020, 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
13#include <ROOT/REveTrans.hxx>
16
17#include "TMath.h"
18#include "TClass.h"
19
20#include <cassert>
21
22#include <nlohmann/json.hpp>
23
24using namespace ROOT::Experimental;
25
26////////////////////////////////////////////////////////////////////////////////
27/// Constructor.
28
29REveEllipsoid::REveEllipsoid(const std::string &n , const std::string &t):
31{
32 fPhiStep = 0.01f;
33}
34
35
36////////////////////////////////////////////////////////////////////////////////
37/// Draw archade as straight line set.
38
39void REveEllipsoid::DrawArch(float phiStart, float phiEnd, float phiStep, REveVector& v0, REveVector& v1, REveVector& v2)
40{
41 float phi = phiStart;
42
43 REveVector f = v1;
44 while (phi < phiEnd ) {
45 REveVector v = v0 + v1*((float)cos(phi)) + v2*((float)sin(phi));
46 AddLine(f, v);
47 f=v;
48 phi += phiStep;
49 }
50 REveVector v = v0 + v1*((float)cos(phiEnd)) + v2*((float)sin(phiEnd));
51 AddLine(f, v);
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// Set size of phi step in archade drawing.
56
58{
59 fPhiStep = ps;
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// Three defining base vectors of ellipse.
64
66{
67 fV0 = v0;
68 fV1 = v1;
69 fV2 = v2;
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Draw archade around base vectors.
74
76{
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Virtual from REveProjectable, returns REveEllipsoidProjected class.
85
87{
88 return TClass::GetClass<REveEllipsoidProjected>();
89}
90
91
92////////////////////////////////////////////////////////////////////////////////
93/// Fill core part of JSON representation.
94
95Int_t REveEllipsoid::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
96{
97 Int_t ret = REveStraightLineSet::WriteCoreJson(j, rnr_offset);
98
99 j["fSecondarySelect"] = false;
100 // printf("REveStraightLineSet::WriteCoreJson %d \n", ret);
101 return ret;
102}
103
104//==============================================================================
105//==============================================================================
106//==============================================================================
107
108////////////////////////////////////////////////////////////////////////////////
109/// Constructor.
110
111REveEllipsoidProjected::REveEllipsoidProjected(const std::string& /*n*/, const std::string& /*t*/) :
113{
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Destructor.
118
120{
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Draw archade around base vectors.
125
126void REveEllipsoidProjected::DrawArchProjected(float phiStart, float phiEnd, float phiStep, REveVector& v0, REveVector& v1, REveVector& v2)
127{
128 float phi = phiStart;
129
130 REveVector f = v1;
131 while (phi < phiEnd ) {
132 REveVector v = v0 + v1*((float)cos(phi)) + v2*((float)sin(phi));
133 fArchPnts.push_back(f);
134 fArchPnts.push_back(v);
135 f=v;
136 phi += phiStep;
137 }
138
139 REveVector v = v0 + v1*((float)cos(phiEnd)) + v2*((float)sin(phiEnd));
140 fArchPnts.push_back(f);
141 fArchPnts.push_back(v);
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Get surface size of projected ellipse
146
148{
149 REveEllipsoid& orig = * dynamic_cast<REveEllipsoid*>(fProjectable);
150 REveTrans * trans = orig.PtrMainTrans(kFALSE);
152
153 // project center of ellipse
154 REveTrans trans0;
155 TVector3 v0 = trans->GetPos();
156 REveVector p0(v0.x(), v0.y(), v0.z());
157 proj.ProjectPointfv(&trans0, p0, p0, fDepth);
158
159 // first axis point
160 REveVector p1 = v1;
161 proj.ProjectPointfv(trans,v1, p1, fDepth);
162
163 // second axis point
164 REveVector p2 = v2;
165 proj.ProjectPointfv(trans, v2, p2, fDepth);
166
167 return (p1-p0).Mag2()+ (p2-p0).Mag2();
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Find longest projection of axes and draw an arch.
172
174{
175 REveEllipsoid& orig = * dynamic_cast<REveEllipsoid*>(fProjectable);
176 // find ellipse with biggest surface
177 float max = 0;
178 {
179 REveVector v1 = orig.fV0;
180 REveVector v2 = orig.fV1;
181 float d = GetEllipseSurface(v1, v2);
182 if (d > max) {
183 fMV0 = v1;
184 fMV1 = v2;
185 max = d;
186 }
187 }
188 {
189 REveVector v1 = orig.fV1;
190 REveVector v2 = orig.fV2;
191 float d = GetEllipseSurface(v1, v2);
192 if (d > max) {
193 fMV0 = v1;
194 fMV1 = v2;
195 max = d;
196 }
197 }
198 {
199 REveVector v1 = orig.fV0;
200 REveVector v2 = orig.fV2;
201 float d = GetEllipseSurface(v1, v2);
202 if (d > max) {
203 fMV0 = v1;
204 fMV1 = v2;
205 max = d;
206 }
207 }
208 if (gDebug) {
209 printf("REveEllipsoidProjected::OutlineProjected, printing axes %s\n", GetCName());
210 fMV0.Dump();
211 fMV1.Dump();
212 }
213
214 REveVector p0;
216}
217
218////////////////////////////////////////////////////////////////////////////////
219/// Crates 3D point array for rendering.
220
222{
224}
225
226
227
228////////////////////////////////////////////////////////////////////////////////
229/// This is virtual method from base-class REveProjected.
230
232{
234 CopyVizParams(dynamic_cast<REveElement*>(model));
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Callback that actually performs the projection.
239/// Called when projection parameters have been updated.
240
242{
245 REveEllipsoid& orig = * dynamic_cast<REveEllipsoid*>(fProjectable);
246
247 REveTrans *trans = orig.PtrMainTrans(kFALSE);
248
249 // Lines
250 Int_t num_lines = (int)fArchPnts.size();
251 if (proj.HasSeveralSubSpaces())
252 num_lines += TMath::Max(1, num_lines/10);
253 fLinePlex.Reset(sizeof(Line_t), num_lines);
254 REveVector p1, p2;
255 for (size_t i = 0; i <fArchPnts.size(); i+=2 )
256 {
257 proj.ProjectPointfv(trans, fArchPnts[i], p1, fDepth);
258 proj.ProjectPointfv(trans, fArchPnts[i+1], p2, fDepth);
259
260 if (proj.AcceptSegment(p1, p2, 0.1f))
261 {
262 AddLine(p1, p2);
263 }
264 else
265 {
266 REveVector bp1(fArchPnts[i]), bp2(fArchPnts[i+1]);
267 if (trans) {
268 trans->MultiplyIP(bp1);
269 trans->MultiplyIP(bp2);
270 }
271 proj.BisectBreakPoint(bp1, bp2, kTRUE, fDepth);
272
273 AddLine(p1, bp1);
274 AddLine(bp2, p2);
275 }
276 }
277 if (proj.HasSeveralSubSpaces())
279
280 // Markers
281 fMarkerPlex.Reset(sizeof(Marker_t), orig.GetMarkerPlex().Size());
283 REveVector pp;
284 while (mi.next())
285 {
286 Marker_t &m = * (Marker_t*) mi();
287
288 proj.ProjectPointfv(trans, m.fV, pp, fDepth);
289 AddMarker(pp, m.fLineId);
290 }
291}
292
293////////////////////////////////////////////////////////////////////////////////
294/// Fill core part of JSON representation.
295
297{
298 Int_t ret = REveStraightLineSet::WriteCoreJson(j, rnr_offset);
299
300 j["fSecondarySelect"] = false;
301 // printf("REveStraightLineSet::WriteCoreJson %d \n", ret);
302 return ret;
303}
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
Int_t gDebug
Definition TROOT.cxx:597
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.
const char * GetCName() const
virtual REveTrans * PtrMainTrans(Bool_t create=kTRUE)
Return pointer to main transformation.
virtual void BuildRenderData()
Write transformation Matrix to render data.
virtual void OutlineProjected()
Find longest projection of axes and draw an arch.
void SetProjection(REveProjectionManager *mng, REveProjectable *model) override
This is virtual method from base-class REveProjected.
float GetEllipseSurface(const REveVector &v1, const REveVector &v2)
Get surface size of projected ellipse.
REveEllipsoidProjected(const REveEllipsoidProjected &)=delete
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
void DrawArchProjected(float phiStart, float phiEnd, float phiStep, REveVector &v0, REveVector &v1, REveVector &v2)
Draw archade around base vectors.
void BuildRenderData() override
Crates 3D point array for rendering.
void UpdateProjection() override
Callback that actually performs the projection.
void SetBaseVectors(REveVector &v0, REveVector &v1, REveVector &v3)
Three defining base vectors of ellipse.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
void DrawArch(float phiStart, float phiEnd, float phiStep, REveVector &v0, REveVector &v1, REveVector &v2)
Draw archade as straight line set.
TClass * ProjectedClass(const REveProjection *p) const override
Virtual from REveProjectable, returns REveEllipsoidProjected class.
virtual void Outline()
Draw archade around base vectors.
void SetPhiStep(float ps)
Set size of phi step in archade drawing.
REveEllipsoid(const REveEllipsoid &)=delete
virtual void SetProjection(REveProjectionManager *mng, REveProjectable *model)
Sets projection manager and reference in the projectable object.
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.
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.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
void GetPos(Double_t &x, Double_t &y, Double_t &z) const
Get position (base-vec 4).
void MultiplyIP(TVector3 &v, Double_t w=1) const
Multiply vector in-place.
void Dump() const
Dump to stdout as "(x, y, z)\n".
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
const Int_t n
Definition legend1.C:16
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
constexpr Double_t TwoPi()
Definition TMath.h:44
TMarker m
Definition textangle.C:8