Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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):
20  REveStraightLineSet(n, 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 
47 void REveEllipsoid::SetPhiStep(float ps)
48 {
49  fPhiStep = ps;
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Three defining base vectors of ellipse.
54 
55 void REveEllipsoid::SetBaseVectors(REveVector& v0, REveVector& v1, REveVector& v2)
56 {
57  fV0 = v0;
58  fV1 = v1;
59  fV2 = v2;
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// Draw archade around base vectors.
64 
65 void REveEllipsoid::Outline()
66 {
67  REveVector v0;
68  DrawArch(0, TMath::TwoPi(),fPhiStep, v0, fV0, fV1);
69  DrawArch(0, TMath::TwoPi(),fPhiStep, v0, fV0, fV2);
70  DrawArch(0, TMath::TwoPi(),fPhiStep, v0, fV1, fV2);
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Virtual from REveProjectable, returns REveEllipsoidProjected class.
75 
76 TClass* REveEllipsoid::ProjectedClass(const REveProjection*) const
77 {
78  return TClass::GetClass<REveEllipsoidProjected>();
79 }
80 
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Fill core part of JSON representation.
84 
85 Int_t REveEllipsoid::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
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*/) :
102  REveStraightLineSetProjected()
103 {
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Destructor.
108 
109 REveEllipsoidProjected::~REveEllipsoidProjected()
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 
137 float REveEllipsoidProjected::GetEllipseSurface (const REveVector& v1, const REveVector& v2)
138 {
139  REveEllipsoid& orig = * dynamic_cast<REveEllipsoid*>(fProjectable);
140  REveTrans * trans = orig.PtrMainTrans(kFALSE);
141  REveProjection& proj = * fManager->GetProjection();
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 
163 void REveEllipsoidProjected::OutlineProjected()
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 
211 void REveEllipsoidProjected::BuildRenderData()
212 {
213  REveStraightLineSetProjected::BuildRenderData();
214 }
215 
216 
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// This is virtual method from base-class REveProjected.
220 
221 void REveEllipsoidProjected::SetProjection(REveProjectionManager* mng, REveProjectable* model)
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 
231 void REveEllipsoidProjected::UpdateProjection()
232 {
233  OutlineProjected();
234  REveProjection& proj = * fManager->GetProjection();
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());
272  REveChunkManager::iterator mi(orig.GetMarkerPlex());
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 
286 Int_t REveEllipsoidProjected::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
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 }