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_clipEta(this, "Clip Eta", 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_clipEta.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this));
147  m_clipPhi.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this));
148  m_clipDelta1.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this));
149  m_clipDelta2.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this));
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);
242  viewerGL()->RequestDraw();
243 }
244 
245 void
247 {
248  // called from popup menu via FWGUIManager
249  /*
250  m_showMuonBarrel.set(1);
251  m_showMuonEndcap.set(true);
252  m_showPixelBarrel.set(true);
253  m_showPixelEndcap.set(true);
254  m_showTrackerBarrel.set(true);
255  */
256  m_clipEta.set(eta);
257  m_clipPhi.set(phi);
258  m_clipEnable.set(true);
259 }
260 
261 void
263 {
264  // TEveScene* gs = (TEveScene*)gEve->GetScenes()->FindChild(TString("TopGeoNodeScene"));
265  //printf("node scene %p\n", gs);
266  if (m_clipEnable.value())
267  {
268  float eta = m_clipEta.value();
269  float phi = m_clipPhi.value();
270  using namespace TMath;
271  TEveVector in(Sin(eta)*Cos(phi), Sin(eta)*Sin(phi), Cos(eta));
272 
273  // one side of cross section plane is paralel to XY plane
274  TEveVector normXY(0., 1., 0);
275  TEveVector b0 = in.Cross(normXY);
276  TEveVector b1 = in.Cross(b0);
277 
278  float delta1 = m_clipDelta1.value();
279  float delta2 = m_clipDelta2.value();
280  b0.Normalize();
281  b0 *= Sin(delta1);
282  b1.Normalize();
283  b1 *= Sin(delta2);
284 
285  TEveVector c[4];
286  c[0] += b0; c[0] += b1;
287  c[1] -= b0; c[1] += b1;
288  c[2] -= b0; c[2] -= b1;
289  c[3] += b0; c[3] -= b1;
290  for (int i = 0; i < 4; ++i)
291  c[i] += in;
292 
293  ((Clipsi*)m_glClip)->SetPlaneInfo(&c[0]);
294 
295  /*
296  // debug
297  TEveStraightLineSet* ls = (TEveStraightLineSet*)eventScene()->FindChild(TString("Frust"));
298  if (!ls) {
299  ls = new TEveStraightLineSet("Frust");
300  eventScene()->AddElement(ls);
301  ls->SetMainColor(kWhite);
302  }
303 
304  in *= 500;
305  ls->AddLine(0, 0, 0, in.fX, in.fY, in.fZ);
306  */
307 
308 
309  TEvePointSet* psi = (TEvePointSet*)eventScene()->FindChild(TString("marker"));
310  TEvePointSet* marker = (TEvePointSet*)(psi);
311  if (!marker) {
312  marker = new TEvePointSet(8);
313  marker->Reset(4);
314  marker->SetName("marker");
315  marker->SetMarkerColor(kOrange);
316  marker->SetMarkerStyle(3);
317  marker->SetMarkerSize(0.2);
318  }
319  for (int i = 0; i < 4; ++i)
320  marker->SetPoint(i, c[i].fX, c[i].fY, c[i].fZ);
321  eventScene()->AddElement(marker);
322  }
323  /*
324  else {
325  fwLog(fwlog::kError) << "Clipping is not enabled!\n";
326  }
327  */
328 }
329 
330 //______________________________________________________________________________
331 void
333 {
334  // take care of parameters
335  FWEveView::addTo(iTo);
336  TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
337  if (camera)
338  addToPerspectiveCamera(camera, "Plain3D", iTo);
339 }
340 
341 //______________________________________________________________________________
342 void
344 {
345  // take care of parameters
346  FWEveView::setFrom(iFrom);
347 
348  TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
349  if (camera)
350  setFromPerspectiveCamera(camera, "Plain3D", iFrom);
351 
352  if (iFrom.version() < 5)
353  {
354  // transparency moved to common preferences in FWEveView version 5
355  std::string tName("Detector Transparency");
356  std::istringstream s(iFrom.valueForKey(tName)->value());
357  int transp;
358  s>> transp;
359  context().colorManager()->setGeomTransparency(transp, false);
360  }
361 }
362 
364 {
366 }
367 
368 void FW3DViewBase::setCurrentDMTVertex(double x, double y, double z)
369 {
371  printf( "ERROR!!!! FW3DViewBase::setCurrentDMTVertex \n");
372 
373  m_DMTline->SetPoint(m_DMT->m_action, x, y, z);
374  m_DMTline->ElementChanged();
375  viewerGL()->RequestDraw();
376 
377  m_DMT->refCurrentVertex().Set(x, y,z);
378  m_DMT->resetAction();
379 }
380 
381 void
383 {
385 
386  gui.requestTab("Detector").
387  addParam(&m_showMuonBarrel).
388  addParam(&m_showMuonEndcap).
389  addParam(&m_showTrackerBarrel).
390  addParam(&m_showTrackerEndcap).
391  addParam(&m_showPixelBarrel).
392  addParam(&m_showPixelEndcap).
393  addParam(&m_showEcalBarrel).
394  addParam(&m_rnrStyle).
395  addParam(&m_selectable).
396  separator().
397  addParam(&m_clipEnable).
398  addParam(&m_clipEta).
399  addParam(&m_clipPhi).
400  addParam(&m_clipDelta1).
401  addParam(&m_clipDelta2);
402 
403 
404  gui.requestTab("Style").separator();
405  gui.getTabContainer()->AddFrame(new TGTextButton(gui.getTabContainer(), "Root controls",
406  Form("TEveGedEditor::SpawnNewEditor((TGLViewer*)0x%lx)", (unsigned long)viewerGL())));
407 
408  gui.requestTab("Tools").addParam(&m_cameraType).separator();
409  gui.getTabContainer()->AddFrame(m_DMT->buildGUI( gui.getTabContainer()), new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
410 }
411 
413  if (x && m_ecalBarrel->GetPlex()->Size() == 0) {
414  const FWGeometry* geom = context().getGeom();
415  std::vector<unsigned int> ids = geom->getMatchedIds(FWGeometry::Detector::Ecal, FWGeometry::SubDetector::PixelBarrel);
416  m_ecalBarrel->Reset(TEveBoxSet::kBT_FreeBox, true, ids.size() );
417  for (std::vector<unsigned int>::iterator it = ids.begin(); it != ids.end(); ++it) {
418  const float* cor = context().getGeom()->getCorners(*it);
419  m_ecalBarrel->AddBox(cor);
420  }
421  m_ecalBarrel->RefitPlex();
422  }
423 
424  if (m_ecalBarrel->GetRnrSelf() != x) {
425  m_ecalBarrel->SetRnrSelf(x);
426  gEve->Redraw3D();
427  }
428 
429  // disable enable grid in 3DView
430  if (typeId() == FWViewType::k3D) {
431  TEveElement* calo = eventScene()->FindChild("calo barrel");
432  if (calo) {
433  TEveCalo3D* c3d = dynamic_cast<TEveCalo3D*>(calo);
434  c3d->SetRnrFrame(!x, !x);
435  c3d->ElementChanged();
436  }
437  }
438 }
FWDoubleParameter m_clipEta
Definition: FW3DViewBase.h:96
virtual ~FW3DViewBase()
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()
TGCompositeFrame * buildGUI(TGCompositeFrame *p)
unsigned int version() const
void setCurrentDMTVertex(double x, double y, double z)
FWBoolParameter m_showTrackerBarrel
Definition: FW3DViewBase.h:84
T eta() const
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)
std::map< std::string, int, std::less< std::string > > psi
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()
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 &)
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
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