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 
37 
38 namespace {
39 class TGLClipsiLogical : public TGLLogicalShape
40 {
41 protected:
42  virtual void DirectDraw(TGLRnrCtx & rnrCtx) const override{}
43 
44 public:
45  TGLClipsiLogical() : TGLLogicalShape() {}
46  virtual ~TGLClipsiLogical() {}
47  void Resize(Double_t ext){}
48 };
49 
50 const float fgColor[4] = { 1.0, 0.6, 0.2, 0.5 };
51 
52 class Clipsi : public TGLClip
53 {
54 private:
55  TGLRnrCtx* m_rnrCtx;
56  Clipsi(const Clipsi&); // Not implemented
57  Clipsi& operator=(const Clipsi&); // Not implemented
58 
59 public:
60  Clipsi(TGLRnrCtx* ctx):TGLClip(* new TGLClipsiLogical, TGLMatrix(), fgColor), m_rnrCtx(ctx){}
61  virtual ~Clipsi() {}
62  using TGLClip::Setup;
63  virtual void Setup(const TGLBoundingBox & bbox) override {}
64 
65  using TGLClip::PlaneSet;
66  virtual void PlaneSet(TGLPlaneSet_t & planeSet) const override
67  {
68  TGLCamera& cam = m_rnrCtx->RefCamera();
69 
70  TGLVertex3 f[4];
71 
72  f[0] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
73  cam.FrustumPlane(TGLCamera::kBottom),
74  cam.FrustumPlane(TGLCamera::kLeft)).second;
75 
76  f[1] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
77  cam.FrustumPlane(TGLCamera::kBottom),
78  cam.FrustumPlane(TGLCamera::kRight)).second;
79 
80  f[2] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
81  cam.FrustumPlane(TGLCamera::kTop),
82  cam.FrustumPlane(TGLCamera::kRight)).second;
83 
84  f[3] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
85  cam.FrustumPlane(TGLCamera::kTop),
86  cam.FrustumPlane(TGLCamera::kLeft)).second;
87 
88  TGLVector3 dd = cam.FrustumPlane(TGLCamera::kNear).Norm();
89  dd *= (cam.GetFarClip() -cam.GetNearClip() );
90 
91  f[0] -= dd;
92  f[1] -= dd;
93  f[2] -= dd;
94  f[3] -= dd;
95 
96  TGLVertex3 c;//(cam.GetCenterVec());
97  planeSet.push_back(TGLPlane(c, f[0], f[1]));
98  planeSet.push_back(TGLPlane(c, f[1], f[2]));
99  planeSet.push_back(TGLPlane(c, f[2], f[3]));
100  planeSet.push_back(TGLPlane(c, f[3], f[0]));
101  }
102 };
103 }
104 
106 //
107 //
108 // FW3DViewBase
109 //
110 //
111 //
113 FW3DViewBase::FW3DViewBase(TEveWindowSlot* iParent, FWViewType::EType typeId, unsigned int version):
114  FWEveView(iParent, typeId, version ),
115  m_geometry(0),
116  m_glClip(0),
117  m_showMuonBarrel(this, "Show Muon Barrel", 0l, 0l, 2l ),
118  m_showMuonEndcap(this, "Show Muon Endcap", false ),
119  m_showPixelBarrel(this, "Show Pixel Barrel", false ),
120  m_showPixelEndcap(this, "Show Pixel Endcap", false),
121  m_showTrackerBarrel(this, "Show Tracker Barrel", false ),
122  m_showTrackerEndcap(this, "Show Tracker Endcap", false),
123  m_ecalBarrel(0),
124  m_showEcalBarrel(this, "Show Ecal Barrel", typeId == FWViewType::kISpy ? true : false),
125  m_rnrStyle(this, "Render Style", 0l, 0l, 2l),
126  m_clipParam(this, "View dependent Clip", false),
127  m_selectable(this, "Enable Tooltips", false),
128  m_cameraType(this, "Camera Type", 0l, 0l, 5l),
129  m_DMT(0),
130  m_DMTline(0)
131 {
132  viewerGL()->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
134 
135  m_showMuonBarrel.addEntry(0, "Hide");
136  m_showMuonBarrel.addEntry(1, "Simplified");
137  m_showMuonBarrel.addEntry(2, "Full");
138  m_showMuonBarrel.changed_.connect(boost::bind(&FW3DViewBase::showMuonBarrel,this,_1));
139 
140  m_rnrStyle.addEntry(TGLRnrCtx::kFill, "Fill");
141  m_rnrStyle.addEntry(TGLRnrCtx::kOutline, "Outline");
142  m_rnrStyle.addEntry(TGLRnrCtx::kWireFrame, "WireFrame");
143  m_rnrStyle.changed_.connect(boost::bind(&FW3DViewBase::rnrStyle,this, _1));
144  m_clipParam.changed_.connect(boost::bind(&FW3DViewBase::sceneClip,this, _1));
145 
146  m_selectable.changed_.connect(boost::bind(&FW3DViewBase::selectable,this, _1));
147 
148 
149  m_cameraType.addEntry(TGLViewer::kCameraPerspXOZ,"PerspXOZ" );
150  m_cameraType.addEntry(TGLViewer::kCameraOrthoXOY,"OrthoXOY");
151  m_cameraType.addEntry(TGLViewer::kCameraOrthoXOZ,"OrthoXOZ");
152  m_cameraType.addEntry(TGLViewer::kCameraOrthoZOY,"OrthoZOY" );
153  m_cameraType.addEntry(TGLViewer::kCameraOrthoXnOY,"OrthoXnOY");
154  m_cameraType.addEntry(TGLViewer::kCameraOrthoXnOZ,"OrthoXnOZ");
155  m_cameraType.addEntry(TGLViewer::kCameraOrthoZnOY,"OrthoZnOY" );
156  m_cameraType.changed_.connect(boost::bind(&FW3DViewBase::setCameraType,this, _1));
157 
158 
159  m_ecalBarrel = new TEveBoxSet("ecalBarrel");
160  m_ecalBarrel->UseSingleColor();
161  m_ecalBarrel->SetMainColor(kAzure+10);
162  m_ecalBarrel->SetMainTransparency(98);
163  geoScene()->AddElement(m_ecalBarrel);
164 }
165 
167 {
168  delete m_glClip;
169 }
170 
172 {
173  FWEveView::setContext(context);
174 
175  m_geometry = new FW3DViewGeometry(context);
176  geoScene()->AddElement(m_geometry);
177 
183  m_showEcalBarrel.changed_.connect(boost::bind(&FW3DViewBase::showEcalBarrel, this,_1));
184 
185  // don't clip event scene -- ideally, would have TGLClipNoClip in root
186  TGLClipPlane* c=new TGLClipPlane();
187  c->Setup(TGLVector3(1e10,0,0), TGLVector3(-1,0,0));
188  eventScene()->GetGLScene()->SetClip(c);
189 
190  m_DMTline = new TEveLine();
191  m_DMTline->SetLineColor(1016);
192  m_DMTline->SetLineStyle(5);
193 
194 
195  m_DMTline->SetPoint(0, 0, 0, 0);
196  m_DMTline->SetPoint(1, 0, 0, 0);
197  eventScene()->AddElement(m_DMTline);
199 }
200 
202 {
203  if (m_geometry)
204  {
205  m_geometry->showMuonBarrel(x == 1);
207  }
208 }
209 
211 {
212  viewerGL()->RefCamera(TGLViewer::ECameraType(x)).IncTimeStamp();
213  viewerGL()->SetCurrentCamera(TGLViewer::ECameraType(x));
214 
215  //if (viewerGL()->CurrentCamera().IsOrthographic())
216  // ((TGLOrthoCamera*)(&viewerGL()->CurrentCamera()))->SetEnableRotate(1);
217 }
218 
219 void
221 {
222  geoScene()->GetGLScene()->SetStyle(x);
223  viewerGL()->Changed();
224  gEve->Redraw3D();
225 }
226 
227 void
229 {
230  geoScene()->GetGLScene()->SetSelectable(x);
231 }
232 void
234 {
235  if (m_glClip == 0) {
236  m_glClip = new Clipsi(viewerGL()->GetRnrCtx());
237  }
238 
239  geoScene()->GetGLScene()->SetClip(x ? m_glClip : 0);
240  for (TEveElement::List_i it =gEve->GetScenes()->BeginChildren(); it != gEve->GetScenes()->EndChildren(); ++it )
241  {
242  if (strncmp((*it)->GetElementName(), "TopGeoNodeScene", 15) == 0)
243  ((TEveScene*)(*it))->GetGLScene()->SetClip(x ? m_glClip : 0);
244  }
245  viewerGL()->RequestDraw();
246 }
247 
248 //______________________________________________________________________________
249 void
251 {
252  // take care of parameters
253  FWEveView::addTo(iTo);
254  TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
255  if (camera)
256  addToPerspectiveCamera(camera, "Plain3D", iTo);
257 }
258 
259 //______________________________________________________________________________
260 void
262 {
263  // take care of parameters
264  FWEveView::setFrom(iFrom);
265 
266  TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
267  if (camera)
268  setFromPerspectiveCamera(camera, "Plain3D", iFrom);
269 
270  if (iFrom.version() < 5)
271  {
272  // transparency moved to common preferences in FWEveView version 5
273  std::string tName("Detector Transparency");
274  std::istringstream s(iFrom.valueForKey(tName)->value());
275  int transp;
276  s>> transp;
277  context().colorManager()->setGeomTransparency(transp, false);
278  }
279 }
280 
282 {
284 }
285 
286 void FW3DViewBase::setCurrentDMTVertex(double x, double y, double z)
287 {
289  printf( "ERROR!!!! FW3DViewBase::setCurrentDMTVertex \n");
290 
291  m_DMTline->SetPoint(m_DMT->m_action, x, y, z);
292  m_DMTline->ElementChanged();
293  viewerGL()->RequestDraw();
294 
295  m_DMT->refCurrentVertex().Set(x, y,z);
296  m_DMT->resetAction();
297 }
298 
299 void
301 {
303 
304  gui.requestTab("Detector").
305  addParam(&m_showMuonBarrel).
306  addParam(&m_showMuonEndcap).
307  addParam(&m_showTrackerBarrel).
308  addParam(&m_showTrackerEndcap).
309  addParam(&m_showPixelBarrel).
310  addParam(&m_showPixelEndcap).
311  addParam(&m_showEcalBarrel).
312  separator().
313  addParam(&m_rnrStyle).
314  addParam(&m_clipParam).
315  addParam(&m_selectable);
316 
317 
318  gui.requestTab("Style").separator();
319  gui.getTabContainer()->AddFrame(new TGTextButton(gui.getTabContainer(), "Root controls",
320  Form("TEveGedEditor::SpawnNewEditor((TGLViewer*)0x%lx)", (unsigned long)viewerGL())));
321 
322  gui.requestTab("Tools").addParam(&m_cameraType).separator();
323  gui.getTabContainer()->AddFrame(m_DMT->buildGUI( gui.getTabContainer()), new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
324 
325 }
326 
327 
328 
329 
331  if (x && m_ecalBarrel->GetPlex()->Size() == 0) {
332  const FWGeometry* geom = context().getGeom();
333  std::vector<unsigned int> ids = geom->getMatchedIds(FWGeometry::Detector::Ecal, FWGeometry::SubDetector::PixelBarrel);
334  m_ecalBarrel->Reset(TEveBoxSet::kBT_FreeBox, true, ids.size() );
335  for (std::vector<unsigned int>::iterator it = ids.begin(); it != ids.end(); ++it) {
336  const float* cor = context().getGeom()->getCorners(*it);
337  m_ecalBarrel->AddBox(cor);
338  }
339  m_ecalBarrel->RefitPlex();
340  }
341 
342  if (m_ecalBarrel->GetRnrSelf() != x) {
343  m_ecalBarrel->SetRnrSelf(x);
344  gEve->Redraw3D();
345  }
346 
347  // disable enable grid in 3DView
348  if (typeId() == FWViewType::k3D) {
349  TEveElement* calo = eventScene()->FindChild("calo barrel");
350  if (calo) {
351  TEveCalo3D* c3d = dynamic_cast<TEveCalo3D*>(calo);
352  c3d->SetRnrFrame(!x, !x);
353  c3d->ElementChanged();
354  }
355  }
356 }
virtual ~FW3DViewBase()
virtual bool requestGLHandlerPick() const
void sceneClip(bool)
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:77
void showMuonBarrel(bool)
virtual void populateController(ViewerParameterGUI &) const
Definition: FWEveView.cc:556
const FWGeometry * getGeom() const
Definition: Context.h:83
FWBoolParameter m_clipParam
Definition: FW3DViewBase.h:87
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:80
TGLViewer * viewerGL() const
Definition: FWEveView.cc:194
sigc::signal< void, T > changed_
FW3DViewDistanceMeasureTool * m_DMT
Definition: FW3DViewBase.h:92
void selectable(bool)
void showMuonBarrelFull(bool)
float float float z
void setCameraType(long)
void showTrackerBarrel(bool)
void setGeomTransparency(Color_t idx, bool projectedType)
U second(std::pair< T, U > const &p)
virtual void addTo(FWConfiguration &) const
virtual void populateController(ViewerParameterGUI &) const
void showMuonEndcap(bool)
FWEnumParameter m_rnrStyle
Definition: FW3DViewBase.h:86
FWBoolParameter m_showPixelEndcap
Definition: FW3DViewBase.h:79
bool addEntry(Long_t id, const std::string &txt)
virtual void setContext(const fireworks::Context &)
double f[11][100]
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:84
TEveScene * geoScene()
Definition: FWEveView.h:83
TGLClip * m_glClip
Definition: FW3DViewBase.h:73
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:93
TEveBoxSet * m_ecalBarrel
Definition: FW3DViewBase.h:83
FWEnumParameter m_showMuonBarrel
Definition: FW3DViewBase.h:76
FW3DViewBase(TEveWindowSlot *, FWViewType::EType, unsigned int version=8)
FW3DViewGeometry * m_geometry
Definition: FW3DViewBase.h:72
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:88
FWEnumParameter m_cameraType
Definition: FW3DViewBase.h:90
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:81
FWBoolParameter m_showPixelBarrel
Definition: FW3DViewBase.h:78
FWViewType::EType typeId() const
Definition: FWViewBase.h:41
void addToPerspectiveCamera(TGLPerspectiveCamera *, const std::string &, FWConfiguration &) const
Definition: FWEveView.cc:474