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
71
72////////////////////////////////////////////////////////////////////////////////
73/// Draw archade around base vectors.
74
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
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 mt;
151 const REveTrans *trans = fManager->GetModelTrans(&orig, mt);
153
154 // project center of ellipse
155 REveTrans trans0;
156 TVector3 v0 = trans->GetPos();
157 REveVector p0(v0.x(), v0.y(), v0.z());
158 proj.ProjectPointfv(&trans0, p0, p0, fDepth);
159
160 // first axis point
161 REveVector p1 = v1;
162 proj.ProjectPointfv(trans,v1, p1, fDepth);
163
164 // second axis point
165 REveVector p2 = v2;
166 proj.ProjectPointfv(trans, v2, p2, fDepth);
167
168 return (p1-p0).Mag2()+ (p2-p0).Mag2();
169}
170
171////////////////////////////////////////////////////////////////////////////////
172/// Find longest projection of axes and draw an arch.
173
175{
176 REveEllipsoid& orig = * dynamic_cast<REveEllipsoid*>(fProjectable);
177 // find ellipse with biggest surface
178 float max = 0;
179 {
180 REveVector v1 = orig.fV0;
181 REveVector v2 = orig.fV1;
182 float d = GetEllipseSurface(v1, v2);
183 if (d > max) {
184 fMV0 = v1;
185 fMV1 = v2;
186 max = d;
187 }
188 }
189 {
190 REveVector v1 = orig.fV1;
191 REveVector v2 = orig.fV2;
192 float d = GetEllipseSurface(v1, v2);
193 if (d > max) {
194 fMV0 = v1;
195 fMV1 = v2;
196 max = d;
197 }
198 }
199 {
200 REveVector v1 = orig.fV0;
201 REveVector v2 = orig.fV2;
202 float d = GetEllipseSurface(v1, v2);
203 if (d > max) {
204 fMV0 = v1;
205 fMV1 = v2;
206 max = d;
207 }
208 }
209 if (gDebug) {
210 printf("REveEllipsoidProjected::OutlineProjected, printing axes %s\n", GetCName());
211 fMV0.Dump();
212 fMV1.Dump();
213 }
214
215 REveVector p0;
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Crates 3D point array for rendering.
221
226
227
228
229////////////////////////////////////////////////////////////////////////////////
230/// This is virtual method from base-class REveProjected.
231
237
238////////////////////////////////////////////////////////////////////////////////
239/// Callback that actually performs the projection.
240/// Called when projection parameters have been updated.
241
243{
246 REveEllipsoid& orig = * dynamic_cast<REveEllipsoid*>(fProjectable);
247
248 REveTrans mt;
249 const REveTrans *trans = fManager->GetModelTrans(&orig, mt);
250
251 // Lines
252 Int_t num_lines = (int)fArchPnts.size();
253 if (proj.HasSeveralSubSpaces())
254 num_lines += TMath::Max(1, num_lines/10);
255 fLinePlex.Reset(sizeof(Line_t), num_lines);
256 REveVector p1, p2;
257 for (size_t i = 0; i <fArchPnts.size(); i+=2 )
258 {
259 proj.ProjectPointfv(trans, fArchPnts[i], p1, fDepth);
260 proj.ProjectPointfv(trans, fArchPnts[i+1], p2, fDepth);
261
262 if (proj.AcceptSegment(p1, p2, 0.1f))
263 {
264 AddLine(p1, p2);
265 }
266 else
267 {
268 REveVector bp1(fArchPnts[i]), bp2(fArchPnts[i+1]);
269 if (trans) {
270 trans->MultiplyIP(bp1);
271 trans->MultiplyIP(bp2);
272 }
273 proj.BisectBreakPoint(bp1, bp2, kTRUE, fDepth);
274
275 AddLine(p1, bp1);
276 AddLine(bp2, p2);
277 }
278 }
279 if (proj.HasSeveralSubSpaces())
281
282 // Markers
283 fMarkerPlex.Reset(sizeof(Marker_t), orig.GetMarkerPlex().Size());
285 REveVector pp;
286 while (mi.next())
287 {
288 Marker_t &m = * (Marker_t*) mi();
289
290 proj.ProjectPointfv(trans, m.fV, pp, fDepth);
291 AddMarker(pp, m.fLineId);
292 }
293}
294
295////////////////////////////////////////////////////////////////////////////////
296/// Fill core part of JSON representation.
297
299{
300 Int_t ret = REveStraightLineSet::WriteCoreJson(j, rnr_offset);
301
302 j["fSecondarySelect"] = false;
303 // printf("REveStraightLineSet::WriteCoreJson %d \n", ret);
304 return ret;
305}
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:792
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 void BuildRenderData()
Build fRenderData, what the client draws.
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.
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.
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:84
const Int_t n
Definition legend1.C:16
Namespace for ROOT features in testing.
Definition TROOT.h:100
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:249
constexpr Double_t TwoPi()
Definition TMath.h:47
TMarker m
Definition textangle.C:8