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
22using namespace ROOT::Experimental;
23
24
25////////////////////////////////////////////////////////////////////////////////
26/// Constructor.
27
28REveEllipsoid::REveEllipsoid(const std::string &n , const std::string &t):
30{
31 fPhiStep = 0.01f;
32}
33
34
35////////////////////////////////////////////////////////////////////////////////
36/// Draw archade as straight line set.
37
38void REveEllipsoid::DrawArch(float phiStart, float phiEnd, float phiStep, REveVector& v0, REveVector& v1, REveVector& v2)
39{
40 float phi = phiStart;
41
42 REveVector f = v1;
43 while (phi < phiEnd ) {
44 REveVector v = v0 + v1*((float)cos(phi)) + v2*((float)sin(phi));
45 AddLine(f, v);
46 f=v;
47 phi += phiStep;
48 }
49 REveVector v = v0 + v1*((float)cos(phiEnd)) + v2*((float)sin(phiEnd));
50 AddLine(f, v);
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Set size of phi step in archade drawing.
55
57{
58 fPhiStep = ps;
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Three defining base vectors of ellipse.
63
65{
66 fV0 = v0;
67 fV1 = v1;
68 fV2 = v2;
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Draw archade around base vectors.
73
75{
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Virtual from REveProjectable, returns REveEllipsoidProjected class.
84
86{
87 return TClass::GetClass<REveEllipsoidProjected>();
88}
89
90
91////////////////////////////////////////////////////////////////////////////////
92/// Fill core part of JSON representation.
93
94Int_t REveEllipsoid::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
95{
96 Int_t ret = REveStraightLineSet::WriteCoreJson(j, rnr_offset);
97
98 j["fSecondarySelect"] = false;
99 // printf("REveStraightLineSet::WriteCoreJson %d \n", ret);
100 return ret;
101}
102
103//==============================================================================
104//==============================================================================
105//==============================================================================
106
107////////////////////////////////////////////////////////////////////////////////
108/// Constructor.
109
110REveEllipsoidProjected::REveEllipsoidProjected(const std::string& /*n*/, const std::string& /*t*/) :
112{
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Destructor.
117
119{
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Draw archade around base vectors.
124
125void REveEllipsoidProjected::DrawArchProjected(float phiStart, float phiEnd, float phiStep, REveVector& v0, REveVector& v1, REveVector& v2)
126{
127 float phi = phiStart;
128
129 REveVector f = v1;
130 while (phi < phiEnd ) {
131 REveVector v = v0 + v1*((float)cos(phi)) + v2*((float)sin(phi));
132 fArchPnts.push_back(f);
133 fArchPnts.push_back(v);
134 f=v;
135 phi += phiStep;
136 }
137
138 REveVector v = v0 + v1*((float)cos(phiEnd)) + v2*((float)sin(phiEnd));
139 fArchPnts.push_back(f);
140 fArchPnts.push_back(v);
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Get surface size of projected ellipse
145
147{
148 REveEllipsoid& orig = * dynamic_cast<REveEllipsoid*>(fProjectable);
149 REveTrans * trans = orig.PtrMainTrans(kFALSE);
151
152 // project center of ellipse
153 REveTrans trans0;
154 TVector3 v0 = trans->GetPos();
155 REveVector p0(v0.x(), v0.y(), v0.z());
156 proj.ProjectPointfv(&trans0, p0, p0, fDepth);
157
158 // first axis point
159 REveVector p1 = v1;
160 proj.ProjectPointfv(trans,v1, p1, fDepth);
161
162 // second axis point
163 REveVector p2 = v2;
164 proj.ProjectPointfv(trans, v2, p2, fDepth);
165
166 return (p1-p0).Mag2()+ (p2-p0).Mag2();
167}
168
169////////////////////////////////////////////////////////////////////////////////
170/// Find longest projection of axes and draw an arch.
171
173{
174 REveEllipsoid& orig = * dynamic_cast<REveEllipsoid*>(fProjectable);
175 // find ellipse with biggest surface
176 float max = 0;
177 {
178 REveVector v1 = orig.fV0;
179 REveVector v2 = orig.fV1;
180 float d = GetEllipseSurface(v1, v2);
181 if (d > max) {
182 fMV0 = v1;
183 fMV1 = v2;
184 max = d;
185 }
186 }
187 {
188 REveVector v1 = orig.fV1;
189 REveVector v2 = orig.fV2;
190 float d = GetEllipseSurface(v1, v2);
191 if (d > max) {
192 fMV0 = v1;
193 fMV1 = v2;
194 max = d;
195 }
196 }
197 {
198 REveVector v1 = orig.fV0;
199 REveVector v2 = orig.fV2;
200 float d = GetEllipseSurface(v1, v2);
201 if (d > max) {
202 fMV0 = v1;
203 fMV1 = v2;
204 max = d;
205 }
206 }
207 if (gDebug) {
208 printf("REveEllipsoidProjected::OutlineProjected, printing axes %s\n", GetCName());
209 fMV0.Dump();
210 fMV1.Dump();
211 }
212
213 REveVector p0;
215}
216
217////////////////////////////////////////////////////////////////////////////////
218/// Crates 3D point array for rendering.
219
221{
223}
224
225
226
227////////////////////////////////////////////////////////////////////////////////
228/// This is virtual method from base-class REveProjected.
229
231{
233 CopyVizParams(dynamic_cast<REveElement*>(model));
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Callback that actually performs the projection.
238/// Called when projection parameters have been updated.
239
241{
244 REveEllipsoid& orig = * dynamic_cast<REveEllipsoid*>(fProjectable);
245
246 REveTrans *trans = orig.PtrMainTrans(kFALSE);
247
248 // Lines
249 Int_t num_lines = (int)fArchPnts.size();
250 if (proj.HasSeveralSubSpaces())
251 num_lines += TMath::Max(1, num_lines/10);
252 fLinePlex.Reset(sizeof(Line_t), num_lines);
253 REveVector p1, p2;
254 for (size_t i = 0; i <fArchPnts.size(); i+=2 )
255 {
256 proj.ProjectPointfv(trans, fArchPnts[i], p1, fDepth);
257 proj.ProjectPointfv(trans, fArchPnts[i+1], p2, fDepth);
258
259 if (proj.AcceptSegment(p1, p2, 0.1f))
260 {
261 AddLine(p1, p2);
262 }
263 else
264 {
265 REveVector bp1(fArchPnts[i]), bp2(fArchPnts[i+1]);
266 if (trans) {
267 trans->MultiplyIP(bp1);
268 trans->MultiplyIP(bp2);
269 }
270 proj.BisectBreakPoint(bp1, bp2, kTRUE, fDepth);
271
272 AddLine(p1, bp1);
273 AddLine(bp2, p2);
274 }
275 }
276 if (proj.HasSeveralSubSpaces())
278
279 // Markers
280 fMarkerPlex.Reset(sizeof(Marker_t), orig.GetMarkerPlex().Size());
282 REveVector pp;
283 while (mi.next())
284 {
285 Marker_t &m = * (Marker_t*) mi();
286
287 proj.ProjectPointfv(trans, m.fV, pp, fDepth);
288 AddMarker(pp, m.fLineId);
289 }
290}
291
292////////////////////////////////////////////////////////////////////////////////
293/// Fill core part of JSON representation.
294
296{
297 Int_t ret = REveStraightLineSet::WriteCoreJson(j, rnr_offset);
298
299 j["fSecondarySelect"] = false;
300 // printf("REveStraightLineSet::WriteCoreJson %d \n", ret);
301 return ret;
302}
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
double cos(double)
double sin(double)
Int_t gDebug
Definition TROOT.cxx:590
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.
virtual 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:80
TVector3 is a general three vector class, which can be used for the description of different vectors ...
Definition TVector3.h:22
const Int_t n
Definition legend1.C:16
Short_t Max(Short_t a, Short_t b)
Definition TMathBase.h:212
constexpr Double_t TwoPi()
Definition TMath.h:44
auto * m
Definition textangle.C:8