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 // $Id: FW3DViewBase.cc,v 1.29 2012/04/29 20:54:46 amraktad Exp $
12 //
13 #include <boost/bind.hpp>
14 
15 // user include files
16 
17 #include "TGButton.h"
18 #include "TGLScenePad.h"
19 #include "TGLViewer.h"
20 #include "TGLClip.h"
21 #include "TGLPerspectiveCamera.h"
22 #include "TEveManager.h"
23 #include "TEveElement.h"
24 #include "TEveScene.h"
25 #include "TGLLogicalShape.h"
26 
33 
34 namespace {
35 class TGLClipsiLogical : public TGLLogicalShape
36 {
37 protected:
38  virtual void DirectDraw(TGLRnrCtx & rnrCtx) const{}
39 
40 public:
41  TGLClipsiLogical() : TGLLogicalShape() {}
42  virtual ~TGLClipsiLogical() {}
43  void Resize(Double_t ext){}
44 };
45 
46 const float fgColor[4] = { 1.0, 0.6, 0.2, 0.5 };
47 
48 class Clipsi : public TGLClip
49 {
50 private:
51  TGLRnrCtx* m_rnrCtx;
52  Clipsi(const Clipsi&); // Not implemented
53  Clipsi& operator=(const Clipsi&); // Not implemented
54 
55 public:
56  Clipsi(TGLRnrCtx* ctx):TGLClip(* new TGLClipsiLogical, TGLMatrix(), fgColor), m_rnrCtx(ctx){}
57  virtual ~Clipsi() {}
58  virtual void Setup(const TGLBoundingBox & bbox) {}
59  virtual void PlaneSet(TGLPlaneSet_t & planeSet) const
60  {
61  TGLCamera& cam = m_rnrCtx->RefCamera();
62 
63  TGLVertex3 f[4];
64 
65  f[0] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
66  cam.FrustumPlane(TGLCamera::kBottom),
67  cam.FrustumPlane(TGLCamera::kLeft)).second;
68 
69  f[1] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
70  cam.FrustumPlane(TGLCamera::kBottom),
71  cam.FrustumPlane(TGLCamera::kRight)).second;
72 
73  f[2] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
74  cam.FrustumPlane(TGLCamera::kTop),
75  cam.FrustumPlane(TGLCamera::kRight)).second;
76 
77  f[3] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
78  cam.FrustumPlane(TGLCamera::kTop),
79  cam.FrustumPlane(TGLCamera::kLeft)).second;
80 
81  TGLVector3 dd = cam.FrustumPlane(TGLCamera::kNear).Norm();
82  dd *= (cam.GetFarClip() -cam.GetNearClip() );
83 
84  f[0] -= dd;
85  f[1] -= dd;
86  f[2] -= dd;
87  f[3] -= dd;
88 
89  TGLVertex3 c;//(cam.GetCenterVec());
90  planeSet.push_back(TGLPlane(c, f[0], f[1]));
91  planeSet.push_back(TGLPlane(c, f[1], f[2]));
92  planeSet.push_back(TGLPlane(c, f[2], f[3]));
93  planeSet.push_back(TGLPlane(c, f[3], f[0]));
94  }
95 };
96 }
97 //
98 // constants, enums and typedefs
99 //
100 
101 //
102 // static data member definitions
103 //
104 //double FW3DViewBase::m_scale = 1;
105 //
106 // constructors and destructor
107 //
108 FW3DViewBase::FW3DViewBase(TEveWindowSlot* iParent, FWViewType::EType typeId):
109  FWEveView(iParent, typeId, 8),
110  m_geometry(0),
111  m_glClip(0),
112  m_showMuonBarrel(this, "Show Muon Barrel", 0l, 0l, 2l ),
113  m_showMuonEndcap(this, "Show Muon Endcap", false ),
114  m_showPixelBarrel(this, "Show Pixel Barrel", false ),
115  m_showPixelEndcap(this, "Show Pixel Endcap", false),
116  m_showTrackerBarrel(this, "Show Tracker Barrel", false ),
117  m_showTrackerEndcap(this, "Show Tracker Endcap", false),
118  m_rnrStyle(this, "Render Style", 0l, 0l, 2l),
119  m_clipParam(this, "View dependent Clip", false),
120  m_selectable(this, "Enable Tooltips", false)
121 {
122  viewerGL()->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
123 
124  m_showMuonBarrel.addEntry(0, "Hide");
125  m_showMuonBarrel.addEntry(1, "Simplified");
126  m_showMuonBarrel.addEntry(2, "Full");
127  m_showMuonBarrel.changed_.connect(boost::bind(&FW3DViewBase::showMuonBarrel,this,_1));
128 
129  m_rnrStyle.addEntry(TGLRnrCtx::kFill, "Fill");
130  m_rnrStyle.addEntry(TGLRnrCtx::kOutline, "Outline");
131  m_rnrStyle.addEntry(TGLRnrCtx::kWireFrame, "WireFrame");
132  m_rnrStyle.changed_.connect(boost::bind(&FW3DViewBase::rnrStyle,this, _1));
133  m_clipParam.changed_.connect(boost::bind(&FW3DViewBase::sceneClip,this, _1));
134 
135  m_selectable.changed_.connect(boost::bind(&FW3DViewBase::selectable,this, _1));
136 
137 }
138 
140 {
141  delete m_glClip;
142 }
143 
145 {
146  FWEveView::setContext(context);
147 
148  m_geometry = new FW3DViewGeometry(context);
149  geoScene()->AddElement(m_geometry);
150 
156 
157  // don't clip event scene -- ideally, would have TGLClipNoClip in root
158  TGLClipPlane* c=new TGLClipPlane();
159  c->Setup(TGLVector3(1e10,0,0), TGLVector3(-1,0,0));
160  eventScene()->GetGLScene()->SetClip(c);
161 }
162 
164 {
165  if (m_geometry)
166  {
167  m_geometry->showMuonBarrel(x == 1);
169  }
170 }
171 
172 void
174 {
175  geoScene()->GetGLScene()->SetStyle(x);
176  viewerGL()->Changed();
177  gEve->Redraw3D();
178 }
179 
180 void
182 {
183  geoScene()->GetGLScene()->SetSelectable(x);
184 }
185 void
187 {
188  if (m_glClip == 0) {
189  m_glClip = new Clipsi(viewerGL()->GetRnrCtx());
190  }
191 
192  geoScene()->GetGLScene()->SetClip(x ? m_glClip : 0);
193  for (TEveElement::List_i it =gEve->GetScenes()->BeginChildren(); it != gEve->GetScenes()->EndChildren(); ++it )
194  {
195  if (strncmp((*it)->GetElementName(), "TopGeoNodeScene", 15) == 0)
196  ((TEveScene*)(*it))->GetGLScene()->SetClip(x ? m_glClip : 0);
197  }
198  viewerGL()->RequestDraw();
199 }
200 
201 //______________________________________________________________________________
202 void
204 {
205  // take care of parameters
206  FWEveView::addTo(iTo);
207  TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
208  if (camera)
209  addToPerspectiveCamera(camera, "Plain3D", iTo);
210 }
211 
212 //______________________________________________________________________________
213 void
215 {
216  // take care of parameters
217  FWEveView::setFrom(iFrom);
218 
219  TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
220  if (camera)
221  setFromPerspectiveCamera(camera, "Plain3D", iFrom);
222 
223  if (iFrom.version() < 5)
224  {
225  // transparency moved to common preferences in FWEveView version 5
226  std::string tName("Detector Transparency");
227  std::istringstream s(iFrom.valueForKey(tName)->value());
228  int transp;
229  s>> transp;
230  context().colorManager()->setGeomTransparency(transp, false);
231  }
232 }
233 
234 
235 void
237 {
239 
240  gui.requestTab("Detector").
241  addParam(&m_showMuonBarrel).
242  addParam(&m_showMuonEndcap).
243  addParam(&m_showTrackerBarrel).
244  addParam(&m_showTrackerEndcap).
245  addParam(&m_showPixelBarrel).
246  addParam(&m_showPixelEndcap).
247  separator().
248  addParam(&m_rnrStyle).
249  addParam(&m_clipParam).
250  addParam(&m_selectable);
251 
252 
253  gui.requestTab("Style").separator();
254  gui.getTabContainer()->AddFrame(new TGTextButton(gui.getTabContainer(), "Root controls",
255  Form("TEveGedEditor::SpawnNewEditor((TGLViewer*)0x%lx)", (unsigned long)viewerGL())));
256 }
257 
258 
259 
nocap nocap const skelname & operator=(const skelname &)
virtual ~FW3DViewBase()
void sceneClip(bool)
TEveScene * eventScene()
Definition: FWEveView.h:76
void showMuonBarrel(long)
void rnrStyle(long)
virtual void setFrom(const FWConfiguration &)
FWBoolParameter m_showMuonEndcap
Definition: FW3DViewBase.h:70
void showMuonBarrel(bool)
virtual void populateController(ViewerParameterGUI &) const
Definition: FWEveView.cc:548
FWBoolParameter m_clipParam
Definition: FW3DViewBase.h:77
FWColorManager * colorManager() const
Definition: Context.h:66
ViewerParameterGUI & requestTab(const char *)
void showTrackerEndcap(bool)
virtual void setFrom(const FWConfiguration &)
Definition: FWEveView.cc:356
ViewerParameterGUI & separator()
unsigned int version() const
FWBoolParameter m_showTrackerBarrel
Definition: FW3DViewBase.h:73
TGLViewer * viewerGL() const
Definition: FWEveView.cc:198
sigc::signal< void, T > changed_
void selectable(bool)
void showMuonBarrelFull(bool)
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:76
FWBoolParameter m_showPixelEndcap
Definition: FW3DViewBase.h:72
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:65
void setFromPerspectiveCamera(TGLPerspectiveCamera *, const std::string &, const FWConfiguration &)
Definition: FWEveView.cc:495
void showPixelBarrel(bool)
TEveScene * geoScene()
Definition: FWEveView.h:77
TGLClip * m_glClip
Definition: FW3DViewBase.h:66
TGCompositeFrame * getTabContainer()
void showPixelEndcap(bool)
FWEnumParameter m_showMuonBarrel
Definition: FW3DViewBase.h:69
FW3DViewGeometry * m_geometry
Definition: FW3DViewBase.h:65
const FWConfiguration * valueForKey(const std::string &iKey) const
x
Definition: VDTMath.h:216
FWBoolParameter m_selectable
Definition: FW3DViewBase.h:78
FW3DViewBase(TEveWindowSlot *, FWViewType::EType)
virtual void addTo(FWConfiguration &) const
Definition: FWEveView.cc:338
virtual void setContext(const fireworks::Context &x)
Definition: FWEveView.cc:267
FWBoolParameter m_showTrackerEndcap
Definition: FW3DViewBase.h:74
FWBoolParameter m_showPixelBarrel
Definition: FW3DViewBase.h:71
void addToPerspectiveCamera(TGLPerspectiveCamera *, const std::string &, FWConfiguration &) const
Definition: FWEveView.cc:466