CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FW3DViewBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FW3DViewBase
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Thu Feb 21 11:22:41 EST 2008
11 //
12 #include <boost/bind.hpp>
13 
14 // user include files
15 
16 #include "TGButton.h"
17 #include "TGLScenePad.h"
18 #include "TGLViewer.h"
19 #include "TGLClip.h"
20 #include "TGLPerspectiveCamera.h"
21 #include "TEveManager.h"
22 #include "TEveElement.h"
23 #include "TEveLine.h"
24 #include "TEveBoxSet.h"
25 #include "TEveScene.h"
26 #include "TGLLogicalShape.h"
27 #include "TEveCalo.h"
28 #include "TEveCaloData.h"
29 #include "TEveStraightLineSet.h"
30 
39 
40 namespace {
41 class TGLClipsiLogical : public TGLLogicalShape
42 {
43 protected:
44  virtual void DirectDraw(TGLRnrCtx & rnrCtx) const override{}
45 
46 public:
47  TGLClipsiLogical() : TGLLogicalShape() {}
48  virtual ~TGLClipsiLogical() {}
49  void Resize(Double_t ext){}
50 };
51 
52 const float fgColor[4] = { 1.0, 0.6, 0.2, 0.5 };
53 
54 class Clipsi : public TGLClip
55 {
56 private:
57  TGLRnrCtx* m_rnrCtx;
58  Clipsi(const Clipsi&); // Not implemented
59  Clipsi& operator=(const Clipsi&); // Not implemented
60 
61  TGLVertex3 vtx[4];
62 
63 public:
64  Clipsi(TGLRnrCtx* ctx):TGLClip(* new TGLClipsiLogical, TGLMatrix(), fgColor), m_rnrCtx(ctx){}
65  virtual ~Clipsi() {}
66  using TGLClip::Setup;
67  virtual void Setup(const TGLBoundingBox & bbox) override {}
68 
69  void SetPlaneInfo(TEveVector* vec)
70  {
71  for (int i = 0; i < 4; ++i) {
72  // vec[i].Dump();
73  vtx[i].Set(vec[i].fX, vec[i].fY, vec[i].fZ);
74  }
75  }
76 
77  using TGLClip::PlaneSet;
78  virtual void PlaneSet(TGLPlaneSet_t & planeSet) const override
79  {
80  TGLVertex3 o;
81  planeSet.push_back(TGLPlane(o, vtx[0], vtx[1]));
82  planeSet.push_back(TGLPlane(o, vtx[1], vtx[2]));
83  planeSet.push_back(TGLPlane(o, vtx[2], vtx[3]));
84  planeSet.push_back(TGLPlane(o, vtx[3], vtx[0]));
85  }
86 };
87 }
88 
90 //
91 //
92 // FW3DViewBase
93 //
94 //
95 //
97 FW3DViewBase::FW3DViewBase(TEveWindowSlot* iParent, FWViewType::EType typeId, unsigned int version):
98  FWEveView(iParent, typeId, version ),
99  m_geometry(0),
100  m_glClip(0),
101  m_showMuonBarrel(this, "Show Muon Barrel", 0l, 0l, 2l ),
102  m_showMuonEndcap(this, "Show Muon Endcap", false ),
103  m_showPixelBarrel(this, "Show Pixel Barrel", false ),
104  m_showPixelEndcap(this, "Show Pixel Endcap", false),
105  m_showTrackerBarrel(this, "Show Tracker Barrel", false ),
106  m_showTrackerEndcap(this, "Show Tracker Endcap", false),
107  m_ecalBarrel(0),
108  m_showEcalBarrel(this, "Show Ecal Barrel", typeId == FWViewType::kISpy ? true : false),
109  m_rnrStyle(this, "Render Style", 0l, 0l, 2l),
110  m_selectable(this, "Enable Tooltips", false),
111  m_cameraType(this, "Camera Type", 0l, 0l, 5l),
112  m_clipEnable(this, "Enable Clip", false),
113  m_clipTheta(this, "Clip Theta", 0.0, -5.0, 5.0),
114  m_clipPhi(this, "Clip Phi", 0.0, -2.0, 2.0),
115  m_clipDelta1(this, "Clip Delta1", 0.2, 0.01, 2),
116  m_clipDelta2(this, "Clip Delta2", 0.2, 0.01, 2),
117  m_DMT(0),
118  m_DMTline(0)
119 {
120  viewerGL()->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
122 
123  m_showMuonBarrel.addEntry(0, "Hide");
124  m_showMuonBarrel.addEntry(1, "Simplified");
125  m_showMuonBarrel.addEntry(2, "Full");
126  m_showMuonBarrel.changed_.connect(boost::bind(&FW3DViewBase::showMuonBarrel,this,_1));
127 
128  m_rnrStyle.addEntry(TGLRnrCtx::kFill, "Fill");
129  m_rnrStyle.addEntry(TGLRnrCtx::kOutline, "Outline");
130  m_rnrStyle.addEntry(TGLRnrCtx::kWireFrame, "WireFrame");
131  m_rnrStyle.changed_.connect(boost::bind(&FW3DViewBase::rnrStyle,this, _1));
132 
133  m_selectable.changed_.connect(boost::bind(&FW3DViewBase::selectable,this, _1));
134 
135 
136  m_cameraType.addEntry(TGLViewer::kCameraPerspXOZ,"PerspXOZ" );
137  m_cameraType.addEntry(TGLViewer::kCameraOrthoXOY,"OrthoXOY");
138  m_cameraType.addEntry(TGLViewer::kCameraOrthoXOZ,"OrthoXOZ");
139  m_cameraType.addEntry(TGLViewer::kCameraOrthoZOY,"OrthoZOY" );
140  m_cameraType.addEntry(TGLViewer::kCameraOrthoXnOY,"OrthoXnOY");
141  m_cameraType.addEntry(TGLViewer::kCameraOrthoXnOZ,"OrthoXnOZ");
142  m_cameraType.addEntry(TGLViewer::kCameraOrthoZnOY,"OrthoZnOY" );
143  m_cameraType.changed_.connect(boost::bind(&FW3DViewBase::setCameraType,this, _1));
144 
145  m_clipEnable.changed_.connect(boost::bind(&FW3DViewBase::enableSceneClip,this, _1));
146  m_clipTheta.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this, false));
147  m_clipPhi.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this, false));
148  m_clipDelta1.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this, false));
149  m_clipDelta2.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this, false));
150 
151 
152  m_ecalBarrel = new TEveBoxSet("ecalBarrel");
153  m_ecalBarrel->UseSingleColor();
154  m_ecalBarrel->SetMainColor(kAzure+10);
155  m_ecalBarrel->SetMainTransparency(98);
156  geoScene()->AddElement(m_ecalBarrel);
157 }
158 
160 {
161  delete m_glClip;
162 }
163 
165 {
166  FWEveView::setContext(context);
167 
168  m_geometry = new FW3DViewGeometry(context);
169  geoScene()->AddElement(m_geometry);
170 
176  m_showEcalBarrel.changed_.connect(boost::bind(&FW3DViewBase::showEcalBarrel, this,_1));
177 
178  // don't clip event scene -- ideally, would have TGLClipNoClip in root
179  TGLClipPlane* c=new TGLClipPlane();
180  c->Setup(TGLVector3(1e10,0,0), TGLVector3(-1,0,0));
181  eventScene()->GetGLScene()->SetClip(c);
182 
183  m_DMTline = new TEveLine();
184  m_DMTline->SetLineColor(1016);
185  m_DMTline->SetLineStyle(5);
186 
187 
188  m_DMTline->SetPoint(0, 0, 0, 0);
189  m_DMTline->SetPoint(1, 0, 0, 0);
190  eventScene()->AddElement(m_DMTline);
192 }
193 
195 {
196  if (m_geometry)
197  {
198  m_geometry->showMuonBarrel(x == 1);
200  }
201 }
202 
204 {
205  viewerGL()->RefCamera(TGLViewer::ECameraType(x)).IncTimeStamp();
206  viewerGL()->SetCurrentCamera(TGLViewer::ECameraType(x));
207 
208  //if (viewerGL()->CurrentCamera().IsOrthographic())
209  // ((TGLOrthoCamera*)(&viewerGL()->CurrentCamera()))->SetEnableRotate(1);
210 }
211 
212 void
214 {
215  geoScene()->GetGLScene()->SetStyle(x);
216  viewerGL()->Changed();
217  gEve->Redraw3D();
218 }
219 
220 void
222 {
223  geoScene()->GetGLScene()->SetSelectable(x);
224 }
225 void
227 {
228  if (m_glClip == 0) {
229  m_glClip = new Clipsi(viewerGL()->GetRnrCtx());
230 
231  m_glClip->SetMode(TGLClip::kOutside);
232  }
233 
234  geoScene()->GetGLScene()->SetClip(x ? m_glClip : 0);
235  for (TEveElement::List_i it =gEve->GetScenes()->BeginChildren(); it != gEve->GetScenes()->EndChildren(); ++it )
236  {
237  if (strncmp((*it)->GetElementName(), "TopGeoNodeScene", 15) == 0)
238  ((TEveScene*)(*it))->GetGLScene()->SetClip(x ? m_glClip : 0);
239  }
240  eventScene()->GetGLScene()->SetClip(x ? m_glClip : 0);
241  updateClipPlanes(true);
242  viewerGL()->RequestDraw();
243 }
244 
245 void
247 {
248  // called from popup menu via FWGUIManager
249 
250  // limit to 2 decimals, else TGNumber entry in the view controller shows only last 5 irrelevant digits
251  double base = 100.0;
252  int thetaInt = theta*base;
253  int phiInt = phi*base;
254  m_clipTheta.set(thetaInt/base);
255  m_clipPhi.set(phiInt/base);
256  m_clipEnable.set(true);
257 }
258 
259 namespace {
260 float getBBoxLineLength(TEveScene* scene, TEveVector in)
261 {
262  if (!scene->NumChildren()) return 0;
263 
264  scene->Repaint();
265  scene->GetGLScene()->CalcBoundingBox();
266  const TGLBoundingBox& bb = scene->GetGLScene()->BoundingBox();
267  if (bb.IsEmpty()) return 0;
268 
269  TGLPlaneSet_t ps; bb.PlaneSet(ps);
270  TEveVector inn = in; inn.Normalize();
271  inn *= 10000;
272  TGLLine3 line(TGLVertex3(), TGLVertex3(inn.fX, inn.fY, inn.fZ));
273  std::vector<float> res;
274  for (TGLPlaneSet_i i = ps.begin(); i!= ps.end(); ++i)
275  {
276  std::pair<Bool_t, TGLVertex3> r = Intersection(*i, line, false);
277  if(r.first) {
278  TGLVector3 vr(r.second.X(), r.second.Y(), r.second.Z());
279  res.push_back(vr.Mag());
280  }
281  }
282  std::sort(res.begin(), res.end());
283  return res.front();
284 }
285 
286 void setBBoxClipped(TGLBoundingBox& bbox, TEveVector dir, TEveVector b0, TEveVector b1, float fac)
287 {
288  dir *= fac;
289  b0 *= fac;
290  b1 *= fac;
291 
292  TEveVectorD bb[8];
293  bb[0] += b0; bb[0] += b1;
294  bb[1] -= b0; bb[1] += b1;
295  bb[2] -= b0; bb[2] -= b1;
296  bb[3] += b0; bb[3] -= b1;
297 
298  for (int i = 4; i < 8; ++i)
299  bb[i] = dir;
300 
301  bb[0+4] += b0; bb[0+4] += b1;
302  bb[1+4] -= b0; bb[1+4] += b1;
303  bb[2+4] -= b0; bb[2+4] -= b1;
304  bb[3+4] += b0; bb[3+4] -= b1;
305 
306  TGLVertex3 bbv[8];
307  for (int i = 0; i < 8; ++i) {
308  bbv[i].Set(bb[i].fX, bb[i].fY, bb[i].fZ);
309  }
310  bbox.Set(bbv);
311 }
312 }
313 
314 void
316 {
317  // TEveScene* gs = (TEveScene*)gEve->GetScenes()->FindChild(TString("TopGeoNodeScene"));
318  //printf("node scene %p\n", gs);
319  if (m_clipEnable.value())
320  {
321  float theta = m_clipTheta.value();
322  float phi = m_clipPhi.value();
323  using namespace TMath;
324  TEveVector in(Sin(theta)*Cos(phi), Sin(theta)*Sin(phi), Cos(theta));
325 
326  // one side of cross section plane is paralel to XY plane
327  TEveVector normXY(0., 1., 0);
328  TEveVector b0 = in.Cross(normXY);
329  TEveVector b1 = in.Cross(b0);
330 
331  float delta1 = m_clipDelta1.value();
332  float delta2 = m_clipDelta2.value();
333  b0.Normalize();
334  b0 *= Sin(delta1);
335  b1.Normalize();
336  b1 *= Sin(delta2);
337 
338  TEveVector c[4];
339  c[0] += b0; c[0] += b1;
340  c[1] -= b0; c[1] += b1;
341  c[2] -= b0; c[2] -= b1;
342  c[3] += b0; c[3] -= b1;
343  for (int i = 0; i < 4; ++i)
344  c[i] += in;
345 
346  ((Clipsi*)m_glClip)->SetPlaneInfo(&c[0]);
347 
348 
349  if (resetCamera) {
350  TGLBoundingBox bbox;
351  float es = getBBoxLineLength(eventScene(), in);
352  float gs = getBBoxLineLength(geoScene(), in);
353  setBBoxClipped(bbox, in, b0, b1, TMath::Max(es, gs));
354 
355  /*
356  TEvePointSet* bmarker = new TEvePointSet(8);
357  bmarker->Reset(4);
358  bmarker->SetName("bbox");
359  bmarker->SetMarkerColor(kOrange);
360  bmarker->SetMarkerStyle(3);
361  bmarker->SetMarkerSize(0.2);
362  for (int i = 0; i < 8; ++i)
363  bmarker->SetPoint(i, bbox[i].X(), bbox[i].Y(), bbox[i].Z());
364  eventScene()->AddElement(bmarker);
365  */
366 
367 
368  TGLCamera& cam = viewerGL()->CurrentCamera();
369  cam.SetExternalCenter(true);
370  cam.SetCenterVec(bbox.Center().X(), bbox.Center().Y(), bbox.Center().Z());
371  cam.Setup(bbox, true);
372  }
373  else {
374  eventScene()->Repaint();
375  }
376  }
377 
378  gEve->Redraw3D();
379 
380 }
381 
382 //______________________________________________________________________________
383 void
385 {
386  // take care of parameters
387  FWEveView::addTo(iTo);
388  TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
389  if (camera)
390  addToPerspectiveCamera(camera, "Plain3D", iTo);
391 }
392 
393 //______________________________________________________________________________
394 void
396 {
397  // take care of parameters
398  FWEveView::setFrom(iFrom);
399 
400  TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
401  if (camera)
402  setFromPerspectiveCamera(camera, "Plain3D", iFrom);
403 
404  if (iFrom.version() < 5)
405  {
406  // transparency moved to common preferences in FWEveView version 5
407  std::string tName("Detector Transparency");
408  std::istringstream s(iFrom.valueForKey(tName)->value());
409  int transp;
410  s>> transp;
411  context().colorManager()->setGeomTransparency(transp, false);
412  }
413 }
414 
416 {
418 }
419 
420 void FW3DViewBase::setCurrentDMTVertex(double x, double y, double z)
421 {
423  printf( "ERROR!!!! FW3DViewBase::setCurrentDMTVertex \n");
424 
425  m_DMTline->SetPoint(m_DMT->m_action, x, y, z);
426  m_DMTline->ElementChanged();
427  viewerGL()->RequestDraw();
428 
429  m_DMT->refCurrentVertex().Set(x, y,z);
430  m_DMT->resetAction();
431 }
432 
433 void
435 {
437 
438  gui.requestTab("Detector").
439  addParam(&m_showMuonBarrel).
440  addParam(&m_showMuonEndcap).
441  addParam(&m_showTrackerBarrel).
442  addParam(&m_showTrackerEndcap).
443  addParam(&m_showPixelBarrel).
444  addParam(&m_showPixelEndcap).
445  addParam(&m_showEcalBarrel).
446  addParam(&m_rnrStyle).
447  addParam(&m_selectable).
448  separator().
449  addParam(&m_clipEnable).
450  addParam(&m_clipTheta).
451  addParam(&m_clipPhi).
452  addParam(&m_clipDelta1).
453  addParam(&m_clipDelta2);
454 
455 
456  gui.requestTab("Style").separator();
457  gui.getTabContainer()->AddFrame(new TGTextButton(gui.getTabContainer(), "Root controls",
458  Form("TEveGedEditor::SpawnNewEditor((TGLViewer*)0x%lx)", (unsigned long)viewerGL())));
459 
460  gui.requestTab("Tools").addParam(&m_cameraType).separator();
461  gui.getTabContainer()->AddFrame(m_DMT->buildGUI( gui.getTabContainer()), new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
462 }
463 
465  if (x && m_ecalBarrel->GetPlex()->Size() == 0) {
466  const FWGeometry* geom = context().getGeom();
467  std::vector<unsigned int> ids = geom->getMatchedIds(FWGeometry::Detector::Ecal, FWGeometry::SubDetector::PixelBarrel);
468  m_ecalBarrel->Reset(TEveBoxSet::kBT_FreeBox, true, ids.size() );
469  for (std::vector<unsigned int>::iterator it = ids.begin(); it != ids.end(); ++it) {
470  const float* cor = context().getGeom()->getCorners(*it);
471  m_ecalBarrel->AddBox(cor);
472  }
473  m_ecalBarrel->RefitPlex();
474  }
475 
476  if (m_ecalBarrel->GetRnrSelf() != x) {
477  m_ecalBarrel->SetRnrSelf(x);
478  gEve->Redraw3D();
479  }
480 
481  // disable enable grid in 3DView
482  if (typeId() == FWViewType::k3D) {
483  TEveElement* calo = eventScene()->FindChild("calo barrel");
484  if (calo) {
485  TEveCalo3D* c3d = dynamic_cast<TEveCalo3D*>(calo);
486  c3d->SetRnrFrame(!x, !x);
487  c3d->ElementChanged();
488  }
489  }
490 }
virtual ~FW3DViewBase()
tuple base
Main Program
Definition: newFWLiteAna.py:92
FWDoubleParameter m_clipTheta
Definition: FW3DViewBase.h:96
virtual bool requestGLHandlerPick() const
int i
Definition: DBlmapReader.cc:9
TEveScene * eventScene()
Definition: FWEveView.h:82
void showEcalBarrel(bool)
void showMuonBarrel(long)
void rnrStyle(long)
virtual void setFrom(const FWConfiguration &)
FWBoolParameter m_showMuonEndcap
Definition: FW3DViewBase.h:81
void showMuonBarrel(bool)
void setClip(float eta, float phi)
virtual void populateController(ViewerParameterGUI &) const
Definition: FWEveView.cc:556
const FWGeometry * getGeom() const
Definition: Context.h:83
FWColorManager * colorManager() const
Definition: Context.h:65
ViewerParameterGUI & requestTab(const char *)
void showTrackerEndcap(bool)
virtual void setFrom(const FWConfiguration &)
Definition: FWEveView.cc:364
ViewerParameterGUI & separator()
Geom::Theta< T > theta() const
TGCompositeFrame * buildGUI(TGCompositeFrame *p)
unsigned int version() const
void setCurrentDMTVertex(double x, double y, double z)
FWBoolParameter m_showTrackerBarrel
Definition: FW3DViewBase.h:84
TGLViewer * viewerGL() const
Definition: FWEveView.cc:194
sigc::signal< void, T > changed_
FW3DViewDistanceMeasureTool * m_DMT
Definition: FW3DViewBase.h:102
void selectable(bool)
void showMuonBarrelFull(bool)
float float float z
void setCameraType(long)
FWDoubleParameter m_clipPhi
Definition: FW3DViewBase.h:97
void showTrackerBarrel(bool)
void enableSceneClip(bool)
void setGeomTransparency(Color_t idx, bool projectedType)
virtual void addTo(FWConfiguration &) const
virtual void populateController(ViewerParameterGUI &) const
void showMuonEndcap(bool)
FWEnumParameter m_rnrStyle
Definition: FW3DViewBase.h:90
void updateClipPlanes(bool resetCamera)
FWBoolParameter m_clipEnable
Definition: FW3DViewBase.h:95
FWBoolParameter m_showPixelEndcap
Definition: FW3DViewBase.h:83
FWDoubleParameter m_clipDelta1
Definition: FW3DViewBase.h:98
bool addEntry(Long_t id, const std::string &txt)
virtual void setContext(const fireworks::Context &)
T Max(T a, T b)
Definition: MathUtil.h:44
const std::string & value(unsigned int iIndex=0) const
const fireworks::Context & context()
Definition: FWEveView.h:67
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:280
void setFromPerspectiveCamera(TGLPerspectiveCamera *, const std::string &, const FWConfiguration &)
Definition: FWEveView.cc:503
void showPixelBarrel(bool)
FWBoolParameter m_showEcalBarrel
Definition: FW3DViewBase.h:88
TEveScene * geoScene()
Definition: FWEveView.h:83
TGLClip * m_glClip
Definition: FW3DViewBase.h:77
ViewerParameterGUI & addParam(const FWParameterBase *)
TGCompositeFrame * getTabContainer()
void showPixelEndcap(bool)
std::vector< unsigned int > getMatchedIds(Detector det, SubDetector subdet) const
Definition: FWGeometry.cc:197
TEveLine * m_DMTline
Definition: FW3DViewBase.h:103
TEveBoxSet * m_ecalBarrel
Definition: FW3DViewBase.h:87
FWEnumParameter m_showMuonBarrel
Definition: FW3DViewBase.h:80
FW3DViewBase(TEveWindowSlot *, FWViewType::EType, unsigned int version=8)
Definition: FW3DViewBase.cc:97
FW3DViewGeometry * m_geometry
Definition: FW3DViewBase.h:76
const FWConfiguration * valueForKey(const std::string &iKey) const
dbl *** dir
Definition: mlp_gen.cc:35
volatile std::atomic< bool > shutdown_flag false
Definition: DDAxes.h:10
FWBoolParameter m_selectable
Definition: FW3DViewBase.h:91
FWEnumParameter m_cameraType
Definition: FW3DViewBase.h:93
virtual void addTo(FWConfiguration &) const
Definition: FWEveView.cc:346
virtual void setContext(const fireworks::Context &x)
Definition: FWEveView.cc:275
FWBoolParameter m_showTrackerEndcap
Definition: FW3DViewBase.h:85
FWDoubleParameter m_clipDelta2
Definition: FW3DViewBase.h:99
FWBoolParameter m_showPixelBarrel
Definition: FW3DViewBase.h:82
FWViewType::EType typeId() const
Definition: FWViewBase.h:41
Definition: DDAxes.h:10
void addToPerspectiveCamera(TGLPerspectiveCamera *, const std::string &, FWConfiguration &) const
Definition: FWEveView.cc:474