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  virtual void Setup(const TGLBoundingBox & bbox) override {}
60  virtual void PlaneSet(TGLPlaneSet_t & planeSet) const override
61  {
62  TGLCamera& cam = m_rnrCtx->RefCamera();
63 
64  TGLVertex3 f[4];
65 
66  f[0] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
67  cam.FrustumPlane(TGLCamera::kBottom),
68  cam.FrustumPlane(TGLCamera::kLeft)).second;
69 
70  f[1] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
71  cam.FrustumPlane(TGLCamera::kBottom),
72  cam.FrustumPlane(TGLCamera::kRight)).second;
73 
74  f[2] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
75  cam.FrustumPlane(TGLCamera::kTop),
76  cam.FrustumPlane(TGLCamera::kRight)).second;
77 
78  f[3] = Intersection(cam.FrustumPlane(TGLCamera::kFar),
79  cam.FrustumPlane(TGLCamera::kTop),
80  cam.FrustumPlane(TGLCamera::kLeft)).second;
81 
82  TGLVector3 dd = cam.FrustumPlane(TGLCamera::kNear).Norm();
83  dd *= (cam.GetFarClip() -cam.GetNearClip() );
84 
85  f[0] -= dd;
86  f[1] -= dd;
87  f[2] -= dd;
88  f[3] -= dd;
89 
90  TGLVertex3 c;//(cam.GetCenterVec());
91  planeSet.push_back(TGLPlane(c, f[0], f[1]));
92  planeSet.push_back(TGLPlane(c, f[1], f[2]));
93  planeSet.push_back(TGLPlane(c, f[2], f[3]));
94  planeSet.push_back(TGLPlane(c, f[3], f[0]));
95  }
96 };
97 }
98 
100 //
101 //
102 // FW3DViewBase
103 //
104 //
105 //
107 FW3DViewBase::FW3DViewBase(TEveWindowSlot* iParent, FWViewType::EType typeId):
108  FWEveView(iParent, typeId, 8),
109  m_geometry(0),
110  m_glClip(0),
111  m_showMuonBarrel(this, "Show Muon Barrel", 0l, 0l, 2l ),
112  m_showMuonEndcap(this, "Show Muon Endcap", false ),
113  m_showPixelBarrel(this, "Show Pixel Barrel", false ),
114  m_showPixelEndcap(this, "Show Pixel Endcap", false),
115  m_showTrackerBarrel(this, "Show Tracker Barrel", false ),
116  m_showTrackerEndcap(this, "Show Tracker Endcap", false),
117  m_rnrStyle(this, "Render Style", 0l, 0l, 2l),
118  m_clipParam(this, "View dependent Clip", false),
119  m_selectable(this, "Enable Tooltips", false),
120  m_cameraType(this, "Camera Type", 0l, 0l, 5l),
121  m_DMT(0),
122  m_DMTline(0)
123 {
124  viewerGL()->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
126 
127  m_showMuonBarrel.addEntry(0, "Hide");
128  m_showMuonBarrel.addEntry(1, "Simplified");
129  m_showMuonBarrel.addEntry(2, "Full");
130  m_showMuonBarrel.changed_.connect(boost::bind(&FW3DViewBase::showMuonBarrel,this,_1));
131 
132  m_rnrStyle.addEntry(TGLRnrCtx::kFill, "Fill");
133  m_rnrStyle.addEntry(TGLRnrCtx::kOutline, "Outline");
134  m_rnrStyle.addEntry(TGLRnrCtx::kWireFrame, "WireFrame");
135  m_rnrStyle.changed_.connect(boost::bind(&FW3DViewBase::rnrStyle,this, _1));
136  m_clipParam.changed_.connect(boost::bind(&FW3DViewBase::sceneClip,this, _1));
137 
138  m_selectable.changed_.connect(boost::bind(&FW3DViewBase::selectable,this, _1));
139 
140 
141  m_cameraType.addEntry(TGLViewer::kCameraPerspXOZ,"PerspXOZ" );
142  m_cameraType.addEntry(TGLViewer::kCameraOrthoXOY,"OrthoXOY");
143  m_cameraType.addEntry(TGLViewer::kCameraOrthoXOZ,"OrthoXOZ");
144  m_cameraType.addEntry(TGLViewer::kCameraOrthoZOY,"OrthoZOY" );
145  m_cameraType.addEntry(TGLViewer::kCameraOrthoXnOY,"OrthoXnOY");
146  m_cameraType.addEntry(TGLViewer::kCameraOrthoXnOZ,"OrthoXnOZ");
147  m_cameraType.addEntry(TGLViewer::kCameraOrthoZnOY,"OrthoZnOY" );
148  m_cameraType.changed_.connect(boost::bind(&FW3DViewBase::setCameraType,this, _1));
149 }
150 
152 {
153  delete m_glClip;
154 }
155 
157 {
158  FWEveView::setContext(context);
159 
160  m_geometry = new FW3DViewGeometry(context);
161  geoScene()->AddElement(m_geometry);
162 
168 
169  // don't clip event scene -- ideally, would have TGLClipNoClip in root
170  TGLClipPlane* c=new TGLClipPlane();
171  c->Setup(TGLVector3(1e10,0,0), TGLVector3(-1,0,0));
172  eventScene()->GetGLScene()->SetClip(c);
173 
174  m_DMTline = new TEveLine();
175  m_DMTline->SetLineColor(1016);
176  m_DMTline->SetLineStyle(5);
177 
178 
179  m_DMTline->SetPoint(0, 0, 0, 0);
180  m_DMTline->SetPoint(1, 0, 0, 0);
181  eventScene()->AddElement(m_DMTline);
182 }
183 
185 {
186  if (m_geometry)
187  {
188  m_geometry->showMuonBarrel(x == 1);
190  }
191 }
192 
194 {
195  viewerGL()->RefCamera(TGLViewer::ECameraType(x)).IncTimeStamp();
196  viewerGL()->SetCurrentCamera(TGLViewer::ECameraType(x));
197 
198  //if (viewerGL()->CurrentCamera().IsOrthographic())
199  // ((TGLOrthoCamera*)(&viewerGL()->CurrentCamera()))->SetEnableRotate(1);
200 }
201 
202 void
204 {
205  geoScene()->GetGLScene()->SetStyle(x);
206  viewerGL()->Changed();
207  gEve->Redraw3D();
208 }
209 
210 void
212 {
213  geoScene()->GetGLScene()->SetSelectable(x);
214 }
215 void
217 {
218  if (m_glClip == 0) {
219  m_glClip = new Clipsi(viewerGL()->GetRnrCtx());
220  }
221 
222  geoScene()->GetGLScene()->SetClip(x ? m_glClip : 0);
223  for (TEveElement::List_i it =gEve->GetScenes()->BeginChildren(); it != gEve->GetScenes()->EndChildren(); ++it )
224  {
225  if (strncmp((*it)->GetElementName(), "TopGeoNodeScene", 15) == 0)
226  ((TEveScene*)(*it))->GetGLScene()->SetClip(x ? m_glClip : 0);
227  }
228  viewerGL()->RequestDraw();
229 }
230 
231 //______________________________________________________________________________
232 void
234 {
235  // take care of parameters
236  FWEveView::addTo(iTo);
237  TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
238  if (camera)
239  addToPerspectiveCamera(camera, "Plain3D", iTo);
240 }
241 
242 //______________________________________________________________________________
243 void
245 {
246  // take care of parameters
247  FWEveView::setFrom(iFrom);
248 
249  TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
250  if (camera)
251  setFromPerspectiveCamera(camera, "Plain3D", iFrom);
252 
253  if (iFrom.version() < 5)
254  {
255  // transparency moved to common preferences in FWEveView version 5
256  std::string tName("Detector Transparency");
257  std::istringstream s(iFrom.valueForKey(tName)->value());
258  int transp;
259  s>> transp;
260  context().colorManager()->setGeomTransparency(transp, false);
261  }
262 }
263 
265 {
267 }
268 
269 void FW3DViewBase::setCurrentDMTVertex(double x, double y, double z)
270 {
272  printf( "ERROR!!!! FW3DViewBase::setCurrentDMTVertex \n");
273 
274  m_DMTline->SetPoint(m_DMT->m_action, x, y, z);
275  m_DMTline->ElementChanged();
276  viewerGL()->RequestDraw();
277 
278  m_DMT->refCurrentVertex().Set(x, y,z);
279  m_DMT->resetAction();
280 }
281 
282 void
284 {
286 
287  gui.requestTab("Detector").
288  addParam(&m_showMuonBarrel).
289  addParam(&m_showMuonEndcap).
290  addParam(&m_showTrackerBarrel).
291  addParam(&m_showTrackerEndcap).
292  addParam(&m_showPixelBarrel).
293  addParam(&m_showPixelEndcap).
294  separator().
295  addParam(&m_rnrStyle).
296  addParam(&m_clipParam).
297  addParam(&m_selectable);
298 
299 
300  gui.requestTab("Style").separator();
301  gui.getTabContainer()->AddFrame(new TGTextButton(gui.getTabContainer(), "Root controls",
302  Form("TEveGedEditor::SpawnNewEditor((TGLViewer*)0x%lx)", (unsigned long)viewerGL())));
303 
304  gui.requestTab("Tools").addParam(&m_cameraType).separator();
305  gui.getTabContainer()->AddFrame(m_DMT->buildGUI( gui.getTabContainer()), new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
306 
307 }
308 
309 
310 
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