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 "TEveScene.h"
25 #include "TGLLogicalShape.h"
26 
34 
35 namespace {
36 class TGLClipsiLogical : public TGLLogicalShape
37 {
38 protected:
39  virtual void DirectDraw(TGLRnrCtx & rnrCtx) const override{}
40 
41 public:
42  TGLClipsiLogical() : TGLLogicalShape() {}
43  virtual ~TGLClipsiLogical() {}
44  void Resize(Double_t ext){}
45 };
46 
47 const float fgColor[4] = { 1.0, 0.6, 0.2, 0.5 };
48 
49 class Clipsi : public TGLClip
50 {
51 private:
52  TGLRnrCtx* m_rnrCtx;
53  Clipsi(const Clipsi&); // Not implemented
54  Clipsi& operator=(const Clipsi&); // Not implemented
55 
56 public:
57  Clipsi(TGLRnrCtx* ctx):TGLClip(* new TGLClipsiLogical, TGLMatrix(), fgColor), m_rnrCtx(ctx){}
58  virtual ~Clipsi() {}
59  using TGLClip::Setup;
60  virtual void Setup(const TGLBoundingBox & bbox) override {}
61 
62  using TGLClip::PlaneSet;
63  virtual void PlaneSet(TGLPlaneSet_t & planeSet) const override
64  {
65  TGLCamera& cam = m_rnrCtx->RefCamera();
66 
67  TGLVertex3 f[4];
68 
69  f[0] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
70  cam.FrustumPlane(TGLCamera::kBottom),
71  cam.FrustumPlane(TGLCamera::kLeft)).second;
72 
73  f[1] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
74  cam.FrustumPlane(TGLCamera::kBottom),
75  cam.FrustumPlane(TGLCamera::kRight)).second;
76 
77  f[2] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
78  cam.FrustumPlane(TGLCamera::kTop),
79  cam.FrustumPlane(TGLCamera::kRight)).second;
80 
81  f[3] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
82  cam.FrustumPlane(TGLCamera::kTop),
83  cam.FrustumPlane(TGLCamera::kLeft)).second;
84 
85  TGLVector3 dd = cam.FrustumPlane(TGLCamera::kNear).Norm();
86  dd *= (cam.GetFarClip() -cam.GetNearClip() );
87 
88  f[0] -= dd;
89  f[1] -= dd;
90  f[2] -= dd;
91  f[3] -= dd;
92 
93  TGLVertex3 c;//(cam.GetCenterVec());
94  planeSet.push_back(TGLPlane(c, f[0], f[1]));
95  planeSet.push_back(TGLPlane(c, f[1], f[2]));
96  planeSet.push_back(TGLPlane(c, f[2], f[3]));
97  planeSet.push_back(TGLPlane(c, f[3], f[0]));
98  }
99 };
100 }
101 
103 //
104 //
105 // FW3DViewBase
106 //
107 //
108 //
110 FW3DViewBase::FW3DViewBase(TEveWindowSlot* iParent, FWViewType::EType typeId):
111  FWEveView(iParent, typeId, 8),
112  m_geometry(0),
113  m_glClip(0),
114  m_showMuonBarrel(this, "Show Muon Barrel", 0l, 0l, 2l ),
115  m_showMuonEndcap(this, "Show Muon Endcap", false ),
116  m_showPixelBarrel(this, "Show Pixel Barrel", false ),
117  m_showPixelEndcap(this, "Show Pixel Endcap", false),
118  m_showTrackerBarrel(this, "Show Tracker Barrel", false ),
119  m_showTrackerEndcap(this, "Show Tracker Endcap", false),
120  m_rnrStyle(this, "Render Style", 0l, 0l, 2l),
121  m_clipParam(this, "View dependent Clip", false),
122  m_selectable(this, "Enable Tooltips", false),
123  m_cameraType(this, "Camera Type", 0l, 0l, 5l),
124  m_DMT(0),
125  m_DMTline(0)
126 {
127  viewerGL()->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
129 
130  m_showMuonBarrel.addEntry(0, "Hide");
131  m_showMuonBarrel.addEntry(1, "Simplified");
132  m_showMuonBarrel.addEntry(2, "Full");
133  m_showMuonBarrel.changed_.connect(boost::bind(&FW3DViewBase::showMuonBarrel,this,_1));
134 
135  m_rnrStyle.addEntry(TGLRnrCtx::kFill, "Fill");
136  m_rnrStyle.addEntry(TGLRnrCtx::kOutline, "Outline");
137  m_rnrStyle.addEntry(TGLRnrCtx::kWireFrame, "WireFrame");
138  m_rnrStyle.changed_.connect(boost::bind(&FW3DViewBase::rnrStyle,this, _1));
139  m_clipParam.changed_.connect(boost::bind(&FW3DViewBase::sceneClip,this, _1));
140 
141  m_selectable.changed_.connect(boost::bind(&FW3DViewBase::selectable,this, _1));
142 
143 
144  m_cameraType.addEntry(TGLViewer::kCameraPerspXOZ,"PerspXOZ" );
145  m_cameraType.addEntry(TGLViewer::kCameraOrthoXOY,"OrthoXOY");
146  m_cameraType.addEntry(TGLViewer::kCameraOrthoXOZ,"OrthoXOZ");
147  m_cameraType.addEntry(TGLViewer::kCameraOrthoZOY,"OrthoZOY" );
148  m_cameraType.addEntry(TGLViewer::kCameraOrthoXnOY,"OrthoXnOY");
149  m_cameraType.addEntry(TGLViewer::kCameraOrthoXnOZ,"OrthoXnOZ");
150  m_cameraType.addEntry(TGLViewer::kCameraOrthoZnOY,"OrthoZnOY" );
151  m_cameraType.changed_.connect(boost::bind(&FW3DViewBase::setCameraType,this, _1));
152 }
153 
155 {
156  delete m_glClip;
157 }
158 
160 {
161  FWEveView::setContext(context);
162 
163  m_geometry = new FW3DViewGeometry(context);
164  geoScene()->AddElement(m_geometry);
165 
171 
172  // don't clip event scene -- ideally, would have TGLClipNoClip in root
173  TGLClipPlane* c=new TGLClipPlane();
174  c->Setup(TGLVector3(1e10,0,0), TGLVector3(-1,0,0));
175  eventScene()->GetGLScene()->SetClip(c);
176 
177  m_DMTline = new TEveLine();
178  m_DMTline->SetLineColor(1016);
179  m_DMTline->SetLineStyle(5);
180 
181 
182  m_DMTline->SetPoint(0, 0, 0, 0);
183  m_DMTline->SetPoint(1, 0, 0, 0);
184  eventScene()->AddElement(m_DMTline);
185 }
186 
188 {
189  if (m_geometry)
190  {
191  m_geometry->showMuonBarrel(x == 1);
193  }
194 }
195 
197 {
198  viewerGL()->RefCamera(TGLViewer::ECameraType(x)).IncTimeStamp();
199  viewerGL()->SetCurrentCamera(TGLViewer::ECameraType(x));
200 
201  //if (viewerGL()->CurrentCamera().IsOrthographic())
202  // ((TGLOrthoCamera*)(&viewerGL()->CurrentCamera()))->SetEnableRotate(1);
203 }
204 
205 void
207 {
208  geoScene()->GetGLScene()->SetStyle(x);
209  viewerGL()->Changed();
210  gEve->Redraw3D();
211 }
212 
213 void
215 {
216  geoScene()->GetGLScene()->SetSelectable(x);
217 }
218 void
220 {
221  if (m_glClip == 0) {
222  m_glClip = new Clipsi(viewerGL()->GetRnrCtx());
223  }
224 
225  geoScene()->GetGLScene()->SetClip(x ? m_glClip : 0);
226  for (TEveElement::List_i it =gEve->GetScenes()->BeginChildren(); it != gEve->GetScenes()->EndChildren(); ++it )
227  {
228  if (strncmp((*it)->GetElementName(), "TopGeoNodeScene", 15) == 0)
229  ((TEveScene*)(*it))->GetGLScene()->SetClip(x ? m_glClip : 0);
230  }
231  viewerGL()->RequestDraw();
232 }
233 
234 //______________________________________________________________________________
235 void
237 {
238  // take care of parameters
239  FWEveView::addTo(iTo);
240  TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
241  if (camera)
242  addToPerspectiveCamera(camera, "Plain3D", iTo);
243 }
244 
245 //______________________________________________________________________________
246 void
248 {
249  // take care of parameters
250  FWEveView::setFrom(iFrom);
251 
252  TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
253  if (camera)
254  setFromPerspectiveCamera(camera, "Plain3D", iFrom);
255 
256  if (iFrom.version() < 5)
257  {
258  // transparency moved to common preferences in FWEveView version 5
259  std::string tName("Detector Transparency");
260  std::istringstream s(iFrom.valueForKey(tName)->value());
261  int transp;
262  s>> transp;
263  context().colorManager()->setGeomTransparency(transp, false);
264  }
265 }
266 
268 {
270 }
271 
272 void FW3DViewBase::setCurrentDMTVertex(double x, double y, double z)
273 {
275  printf( "ERROR!!!! FW3DViewBase::setCurrentDMTVertex \n");
276 
277  m_DMTline->SetPoint(m_DMT->m_action, x, y, z);
278  m_DMTline->ElementChanged();
279  viewerGL()->RequestDraw();
280 
281  m_DMT->refCurrentVertex().Set(x, y,z);
282  m_DMT->resetAction();
283 }
284 
285 void
287 {
289 
290  gui.requestTab("Detector").
291  addParam(&m_showMuonBarrel).
292  addParam(&m_showMuonEndcap).
293  addParam(&m_showTrackerBarrel).
294  addParam(&m_showTrackerEndcap).
295  addParam(&m_showPixelBarrel).
296  addParam(&m_showPixelEndcap).
297  separator().
298  addParam(&m_rnrStyle).
299  addParam(&m_clipParam).
300  addParam(&m_selectable);
301 
302 
303  gui.requestTab("Style").separator();
304  gui.getTabContainer()->AddFrame(new TGTextButton(gui.getTabContainer(), "Root controls",
305  Form("TEveGedEditor::SpawnNewEditor((TGLViewer*)0x%lx)", (unsigned long)viewerGL())));
306 
307  gui.requestTab("Tools").addParam(&m_cameraType).separator();
308  gui.getTabContainer()->AddFrame(m_DMT->buildGUI( gui.getTabContainer()), new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
309 
310 }
311 
312 
313 
virtual ~FW3DViewBase()
virtual bool requestGLHandlerPick() const
void sceneClip(bool)
TEveScene * eventScene()
Definition: FWEveView.h:75
void showMuonBarrel(long)
void rnrStyle(long)
virtual void setFrom(const FWConfiguration &)
FWBoolParameter m_showMuonEndcap
Definition: FW3DViewBase.h:75
void showMuonBarrel(bool)
virtual void populateController(ViewerParameterGUI &) const
Definition: FWEveView.cc:542
FWBoolParameter m_clipParam
Definition: FW3DViewBase.h:82
FWColorManager * colorManager() const
Definition: Context.h:65
ViewerParameterGUI & requestTab(const char *)
void showTrackerEndcap(bool)
virtual void setFrom(const FWConfiguration &)
Definition: FWEveView.cc:355
ViewerParameterGUI & separator()
TGCompositeFrame * buildGUI(TGCompositeFrame *p)
unsigned int version() const
void setCurrentDMTVertex(double x, double y, double z)
FWBoolParameter m_showTrackerBarrel
Definition: FW3DViewBase.h:78
TGLViewer * viewerGL() const
Definition: FWEveView.cc:197
sigc::signal< void, T > changed_
FW3DViewDistanceMeasureTool * m_DMT
Definition: FW3DViewBase.h:87
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:81
FWBoolParameter m_showPixelEndcap
Definition: FW3DViewBase.h:77
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:64
void setFromPerspectiveCamera(TGLPerspectiveCamera *, const std::string &, const FWConfiguration &)
Definition: FWEveView.cc:489
void showPixelBarrel(bool)
TEveScene * geoScene()
Definition: FWEveView.h:76
TGLClip * m_glClip
Definition: FW3DViewBase.h:71
ViewerParameterGUI & addParam(const FWParameterBase *)
TGCompositeFrame * getTabContainer()
void showPixelEndcap(bool)
TEveLine * m_DMTline
Definition: FW3DViewBase.h:88
FWEnumParameter m_showMuonBarrel
Definition: FW3DViewBase.h:74
FW3DViewGeometry * m_geometry
Definition: FW3DViewBase.h:70
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:83
FWEnumParameter m_cameraType
Definition: FW3DViewBase.h:85
FW3DViewBase(TEveWindowSlot *, FWViewType::EType)
virtual void addTo(FWConfiguration &) const
Definition: FWEveView.cc:337
virtual void setContext(const fireworks::Context &x)
Definition: FWEveView.cc:266
FWBoolParameter m_showTrackerEndcap
Definition: FW3DViewBase.h:79
FWBoolParameter m_showPixelBarrel
Definition: FW3DViewBase.h:76
void addToPerspectiveCamera(TGLPerspectiveCamera *, const std::string &, FWConfiguration &) const
Definition: FWEveView.cc:460