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