Logo ROOT   6.21/01
Reference Guide
REveEllipsoid.cxx
Go to the documentation of this file.
1 #include <ROOT/REveEllipsoid.hxx>
2 #include <ROOT/REveTrans.hxx>
5 
6 #include "TMath.h"
7 #include "TClass.h"
8 
9 #include <cassert>
10 
11 #include "json.hpp"
12 
13 using namespace ROOT::Experimental;
14 
15 
16 ////////////////////////////////////////////////////////////////////////////////
17 /// Constructor.
18 
19 REveEllipsoid::REveEllipsoid(const std::string &n , const std::string &t):
21 {
22  fPhiStep = 0.01f;
23 }
24 
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Draw archade as straight line set.
28 
29 void REveEllipsoid::DrawArch(float phiStart, float phiEnd, float phiStep, REveVector& v0, REveVector& v1, REveVector& v2)
30 {
31  float phi = phiStart;
32 
33  REveVector f = v1;
34  while (phi < phiEnd ) {
35  REveVector v = v0 + v1*((float)cos(phi)) + v2*((float)sin(phi));
36  AddLine(f, v);
37  f=v;
38  phi += phiStep;
39  }
40  REveVector v = v0 + v1*((float)cos(phiEnd)) + v2*((float)sin(phiEnd));
41  AddLine(f, v);
42 }
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Set size of phi step in archade drawing.
46 
48 {
49  fPhiStep = ps;
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Three defining base vectors of ellipse.
54 
56 {
57  fV0 = v0;
58  fV1 = v1;
59  fV2 = v2;
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// Draw archade around base vectors.
64 
66 {
67  REveVector v0;
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Virtual from REveProjectable, returns REveEllipsoidProjected class.
75 
77 {
78  return TClass::GetClass<REveEllipsoidProjected>();
79 }
80 
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Fill core part of JSON representation.
84 
86 {
87  Int_t ret = REveStraightLineSet::WriteCoreJson(j, rnr_offset);
88 
89  j["fSecondarySelect"] = false;
90  // printf("REveStraightLineSet::WriteCoreJson %d \n", ret);
91  return ret;
92 }
93 
94 //==============================================================================
95 //==============================================================================
96 //==============================================================================
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Constructor.
100 
101 REveEllipsoidProjected::REveEllipsoidProjected(const std::string& /*n*/, const std::string& /*t*/) :
103 {
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Destructor.
108 
110 {
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Draw archade around base vectors.
115 
116 void REveEllipsoidProjected::DrawArchProjected(float phiStart, float phiEnd, float phiStep, REveVector& v0, REveVector& v1, REveVector& v2)
117 {
118  float phi = phiStart;
119 
120  REveVector f = v1;
121  while (phi < phiEnd ) {
122  REveVector v = v0 + v1*((float)cos(phi)) + v2*((float)sin(phi));
123  fArchPnts.push_back(f);
124  fArchPnts.push_back(v);
125  f=v;
126  phi += phiStep;
127  }
128 
129  REveVector v = v0 + v1*((float)cos(phiEnd)) + v2*((float)sin(phiEnd));
130  fArchPnts.push_back(f);
131  fArchPnts.push_back(v);
132 }
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 /// Get surface size of projected ellipse
136 
138 {
139  REveEllipsoid& orig = * dynamic_cast<REveEllipsoid*>(fProjectable);
140  REveTrans * trans = orig.PtrMainTrans(kFALSE);
142 
143  // project center of ellipse
144  REveTrans trans0;
145  TVector3 v0 = trans->GetPos();
146  REveVector p0(v0.x(), v0.y(), v0.z());
147  proj.ProjectPointfv(&trans0, p0, p0, fDepth);
148 
149  // first axis point
150  REveVector p1 = v1;
151  proj.ProjectPointfv(trans,v1, p1, fDepth);
152 
153  // second axis point
154  REveVector p2 = v2;
155  proj.ProjectPointfv(trans, v2, p2, fDepth);
156 
157  return (p1-p0).Mag2()+ (p2-p0).Mag2();
158 }
159 
160 ////////////////////////////////////////////////////////////////////////////////
161 /// Find longest projection of axes and draw an arch.
162 
164 {
165  REveEllipsoid& orig = * dynamic_cast<REveEllipsoid*>(fProjectable);
166  // find ellipse with biggest surface
167  float max = 0;
168  {
169  REveVector v1 = orig.fV0;
170  REveVector v2 = orig.fV1;
171  float d = GetEllipseSurface(v1, v2);
172  if (d > max) {
173  fMV0 = v1;
174  fMV1 = v2;
175  max = d;
176  }
177  }
178  {
179  REveVector v1 = orig.fV1;
180  REveVector v2 = orig.fV2;
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.fV0;
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  if (gDebug) {
199  printf("REveEllipsoidProjected::OutlineProjected, printing axes %s\n", GetCName());
200  fMV0.Dump();
201  fMV1.Dump();
202  }
203 
204  REveVector p0;
205  DrawArchProjected(0, TMath::TwoPi(), orig.fPhiStep, p0, fMV0, fMV1);
206 }
207 
208 ////////////////////////////////////////////////////////////////////////////////
209 /// Crates 3D point array for rendering.
210 
212 {
214 }
215 
216 
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// This is virtual method from base-class REveProjected.
220 
222 {
223  REveProjected::SetProjection(mng, model);
224  CopyVizParams(dynamic_cast<REveElement*>(model));
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Callback that actually performs the projection.
229 /// Called when projection parameters have been updated.
230 
232 {
235  REveEllipsoid& orig = * dynamic_cast<REveEllipsoid*>(fProjectable);
236 
237  REveTrans *trans = orig.PtrMainTrans(kFALSE);
238 
239  // Lines
240  Int_t num_lines = (int)fArchPnts.size();
241  if (proj.HasSeveralSubSpaces())
242  num_lines += TMath::Max(1, num_lines/10);
243  fLinePlex.Reset(sizeof(Line_t), num_lines);
244  REveVector p1, p2;
245  for (size_t i = 0; i <fArchPnts.size(); i+=2 )
246  {
247  proj.ProjectPointfv(trans, fArchPnts[i], p1, fDepth);
248  proj.ProjectPointfv(trans, fArchPnts[i+1], p2, fDepth);
249 
250  if (proj.AcceptSegment(p1, p2, 0.1f))
251  {
252  AddLine(p1, p2);
253  }
254  else
255  {
256  REveVector bp1(fArchPnts[i]), bp2(fArchPnts[i+1]);
257  if (trans) {
258  trans->MultiplyIP(bp1);
259  trans->MultiplyIP(bp2);
260  }
261  proj.BisectBreakPoint(bp1, bp2, kTRUE, fDepth);
262 
263  AddLine(p1, bp1);
264  AddLine(bp2, p2);
265  }
266  }
267  if (proj.HasSeveralSubSpaces())
268  fLinePlex.Refit();
269 
270  // Markers
271  fMarkerPlex.Reset(sizeof(Marker_t), orig.GetMarkerPlex().Size());
273  REveVector pp;
274  while (mi.next())
275  {
276  Marker_t &m = * (Marker_t*) mi();
277 
278  proj.ProjectPointfv(trans, m.fV, pp, fDepth);
279  AddMarker(pp, m.fLineId);
280  }
281 }
282 
283 ////////////////////////////////////////////////////////////////////////////////
284 /// Fill core part of JSON representation.
285 
287 {
288  Int_t ret = REveStraightLineSet::WriteCoreJson(j, rnr_offset);
289 
290  j["fSecondarySelect"] = false;
291  // printf("REveStraightLineSet::WriteCoreJson %d \n", ret);
292  return ret;
293 }
virtual Bool_t AcceptSegment(REveVector &, REveVector &, Float_t) const
void DrawArch(float phiStart, float phiEnd, float phiStep, REveVector &v0, REveVector &v1, REveVector &v2)
Draw archade as straight line set.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
virtual void SetProjection(REveProjectionManager *mng, REveProjectable *model)
Sets projection manager and reference in the projectable object.
auto * m
Definition: textangle.C:8
REveEllipsoid(const REveEllipsoid &)=delete
float GetEllipseSurface(const REveVector &v1, const REveVector &v2)
Get surface size of projected ellipse.
void SetPhiStep(float ps)
Set size of phi step in archade drawing.
constexpr Double_t TwoPi()
Definition: TMath.h:45
void Reset(Int_t atom_size, Int_t chunk_size)
Empty the container and reset it with given atom and chunk sizes.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
TClass * ProjectedClass(const REveProjection *p) const override
Virtual from REveProjectable, returns REveEllipsoidProjected class.
void BuildRenderData() override
Crates 3D point array for rendering.
virtual void OutlineProjected()
Find longest projection of axes and draw an arch.
static constexpr double ps
void DrawArchProjected(float phiStart, float phiEnd, float phiStep, REveVector &v0, REveVector &v1, REveVector &v2)
Draw archade around base vectors.
virtual void SetProjection(REveProjectionManager *mng, REveProjectable *model) override
This is virtual method from base-class REveProjected.
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
void Refit()
Refit the container so that all current data fits into a single chunk.
virtual Bool_t HasSeveralSubSpaces() const
const char * GetCName() const
REveEllipsoidProjected(const REveEllipsoidProjected &)=delete
virtual void Outline()
Draw archade around base vectors.
double cos(double)
REveStraightLineSetProjected Projected copy of a REveStraightLineSet.
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.
double sin(double)
REveProjection Base for specific classes that implement non-linear projections.
Marker_t * AddMarker(Float_t x, Float_t y, Float_t z, Int_t line_id=-1)
Add a marker with given position.
TVector3 is a general three vector class, which can be used for the description of different vectors ...
Definition: TVector3.h:22
void SetBaseVectors(REveVector &v0, REveVector &v1, REveVector &v3)
Three defining base vectors of ellipse.
REveProjectionManager Manager class for steering of projections and managing projected objects...
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
T Mag2(const SVector< T, D > &rhs)
Vector magnitude square Template to compute .
Definition: Functions.h:229
REveStraightLineSet Set of straight lines with optional markers along the lines.
const Bool_t kFALSE
Definition: RtypesCore.h:88
virtual REveTrans * PtrMainTrans(Bool_t create=kTRUE)
Return pointer to main transformation.
#define d(i)
Definition: RSha256.hxx:102
void GetPos(Double_t &x, Double_t &y, Double_t &z) const
Get position (base-vec 4).
Definition: REveTrans.cxx:535
Line_t * AddLine(Float_t x1, Float_t y1, Float_t z1, Float_t x2, Float_t y2, Float_t z2)
Add a line.
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
void Dump() const
Dump to stdout as "(x, y, z)\n".
Definition: REveVector.cxx:28
R__EXTERN Int_t gDebug
Definition: Rtypes.h:91
virtual void BisectBreakPoint(REveVector &vL, REveVector &vR, Float_t eps_sqr)
Find break-point on both sides of the discontinuity.
void BuildRenderData() override
Crates 3D point array for rendering.
const Bool_t kTRUE
Definition: RtypesCore.h:87
const Int_t n
Definition: legend1.C:16
void UpdateProjection() override
Callback that actually performs the projection.
void ProjectPointfv(Float_t *v, Float_t d)
Project float array.
void MultiplyIP(TVector3 &v, Double_t w=1) const
Multiply vector in-place.
Definition: REveTrans.cxx:730