CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/Fireworks/Core/src/FW3DViewBase.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FW3DViewBase
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Thu Feb 21 11:22:41 EST 2008
00011 // $Id: FW3DViewBase.cc,v 1.26 2011/10/15 02:39:09 amraktad Exp $
00012 //
00013 #include <boost/bind.hpp>
00014 
00015 // user include files
00016 
00017 #include "TGButton.h"
00018 #include "TGLScenePad.h"
00019 #include "TGLViewer.h"
00020 #include "TGLPerspectiveCamera.h"
00021 #include "TEveManager.h"
00022 #include "TEveElement.h"
00023 #include "TEveScene.h"
00024 #include "TGLLogicalShape.h"
00025 
00026 #include "Fireworks/Core/interface/FW3DViewBase.h"
00027 #include "Fireworks/Core/interface/FW3DViewGeometry.h"
00028 #include "Fireworks/Core/interface/Context.h"
00029 #include "Fireworks/Core/interface/FWViewContext.h"
00030 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
00031 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
00032 
00033 namespace {
00034 class TGLClipsiLogical : public TGLLogicalShape
00035 {
00036 protected:
00037    virtual void DirectDraw(TGLRnrCtx & rnrCtx) const{}
00038 
00039 public:
00040    TGLClipsiLogical() : TGLLogicalShape() {}
00041    virtual ~TGLClipsiLogical() {}
00042    void Resize(Double_t ext){}
00043 };
00044 
00045 const float fgColor[4] = { 1.0, 0.6, 0.2, 0.5 };
00046 
00047 class Clipsi : public TGLClip
00048 {
00049 private:
00050    TGLRnrCtx* m_rnrCtx;
00051    Clipsi(const Clipsi&);            // Not implemented
00052    Clipsi& operator=(const Clipsi&); // Not implemented
00053 
00054 public:
00055    Clipsi(TGLRnrCtx* ctx):TGLClip(* new TGLClipsiLogical, TGLMatrix(), fgColor), m_rnrCtx(ctx){}
00056    virtual ~Clipsi() {}
00057    virtual void Setup(const TGLBoundingBox & bbox) {}
00058    virtual void PlaneSet(TGLPlaneSet_t & planeSet) const
00059    {
00060       TGLCamera& cam = m_rnrCtx->RefCamera();
00061 
00062       TGLVertex3 f[4];
00063 
00064       f[0] =  Intersection(cam.FrustumPlane(TGLCamera::kFar),
00065                            cam.FrustumPlane(TGLCamera::kBottom),
00066                            cam.FrustumPlane(TGLCamera::kLeft)).second;
00067          
00068       f[1] =  Intersection(cam.FrustumPlane(TGLCamera::kFar),
00069                            cam.FrustumPlane(TGLCamera::kBottom),
00070                            cam.FrustumPlane(TGLCamera::kRight)).second;
00071          
00072       f[2] =  Intersection(cam.FrustumPlane(TGLCamera::kFar),
00073                            cam.FrustumPlane(TGLCamera::kTop),
00074                            cam.FrustumPlane(TGLCamera::kRight)).second;
00075 
00076       f[3] =  Intersection(cam.FrustumPlane(TGLCamera::kFar),
00077                            cam.FrustumPlane(TGLCamera::kTop),
00078                            cam.FrustumPlane(TGLCamera::kLeft)).second;
00079 
00080       TGLVector3 dd  =  cam.FrustumPlane(TGLCamera::kNear).Norm();
00081       dd *= (cam.GetFarClip() -cam.GetNearClip() );
00082 
00083       f[0] -= dd;
00084       f[1] -= dd;
00085       f[2] -= dd;
00086       f[3] -= dd;
00087 
00088       TGLVertex3 c;//(cam.GetCenterVec());
00089       planeSet.push_back(TGLPlane(c, f[0], f[1]));
00090       planeSet.push_back(TGLPlane(c, f[1], f[2]));
00091       planeSet.push_back(TGLPlane(c, f[2], f[3]));
00092       planeSet.push_back(TGLPlane(c, f[3], f[0]));
00093    }
00094 };
00095 }
00096 //
00097 // constants, enums and typedefs
00098 //
00099 
00100 //
00101 // static data member definitions
00102 //
00103 //double FW3DViewBase::m_scale = 1;
00104 //
00105 // constructors and destructor
00106 //
00107 FW3DViewBase::FW3DViewBase(TEveWindowSlot* iParent, FWViewType::EType typeId):
00108    FWEveView(iParent, typeId),
00109    m_geometry(0),
00110    m_glClip(0),
00111    m_showMuonBarrel(this, "Show Muon Barrel",  0l, 0l, 2l ),
00112    m_showMuonEndcap(this, "Show Muon Endcap", false ),
00113    m_showPixelBarrel(this, "Show Pixel Barrel", false ),
00114    m_showPixelEndcap(this, "Show Pixel Endcap", false),
00115    m_showTrackerBarrel(this, "Show Tracker Barrel", false ),
00116    m_showTrackerEndcap(this, "Show Tracker Endcap", false),
00117    m_rnrStyle(this, "Render Style", 0l, 0l, 2l),
00118    m_clipParam(this, "View dependent Clip", false),
00119    m_selectable(this, "Enable Tooltips", false)
00120 {
00121    viewerGL()->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
00122 
00123    m_showMuonBarrel.addEntry(0, "Hide");
00124    m_showMuonBarrel.addEntry(1, "Simplified");
00125    m_showMuonBarrel.addEntry(2, "Full");
00126    m_showMuonBarrel.changed_.connect(boost::bind(&FW3DViewBase::showMuonBarrel,this,_1));
00127 
00128    m_rnrStyle.addEntry(TGLRnrCtx::kFill, "Fill");
00129    m_rnrStyle.addEntry(TGLRnrCtx::kOutline, "Outline");
00130    m_rnrStyle.addEntry(TGLRnrCtx::kWireFrame, "WireFrame");
00131    m_rnrStyle.changed_.connect(boost::bind(&FW3DViewBase::rnrStyle,this, _1));
00132    m_clipParam.changed_.connect(boost::bind(&FW3DViewBase::sceneClip,this, _1));
00133 
00134    m_selectable.changed_.connect(boost::bind(&FW3DViewBase::selectable,this, _1));
00135 
00136 }
00137 
00138 FW3DViewBase::~FW3DViewBase()
00139 {
00140   delete m_glClip;
00141 }
00142 
00143 void FW3DViewBase::setContext(const fireworks::Context& context)
00144 {
00145    FWEveView::setContext(context);
00146 
00147    m_geometry = new FW3DViewGeometry(context);
00148    geoScene()->AddElement(m_geometry);
00149    
00150    m_showPixelBarrel.changed_.connect(boost::bind(&FW3DViewGeometry::showPixelBarrel,m_geometry,_1));
00151    m_showPixelEndcap.changed_.connect(boost::bind(&FW3DViewGeometry::showPixelEndcap,m_geometry,_1));
00152    m_showTrackerBarrel.changed_.connect(boost::bind(&FW3DViewGeometry::showTrackerBarrel,m_geometry,_1));
00153    m_showTrackerEndcap.changed_.connect(boost::bind(&FW3DViewGeometry::showTrackerEndcap,m_geometry,_1));
00154    m_showMuonEndcap.changed_.connect(boost::bind(&FW3DViewGeometry::showMuonEndcap,m_geometry,_1));
00155 }
00156 
00157 void FW3DViewBase::showMuonBarrel(long x)
00158 {
00159    if (m_geometry)
00160    {
00161       m_geometry->showMuonBarrel(x == 1);
00162       m_geometry->showMuonBarrelFull(x == 2);
00163    }
00164 }
00165 
00166 void
00167 FW3DViewBase::rnrStyle( long x)
00168 {
00169    geoScene()->GetGLScene()->SetStyle(x);  
00170    viewerGL()->Changed();
00171    gEve->Redraw3D();
00172 }
00173 
00174 void
00175 FW3DViewBase::selectable( bool x)
00176 {
00177       geoScene()->GetGLScene()->SetSelectable(x);
00178 }
00179 void
00180 FW3DViewBase::sceneClip( bool x)
00181 {
00182    if (m_glClip == 0)  {
00183       m_glClip = new Clipsi(viewerGL()->GetRnrCtx());
00184    }
00185 
00186    geoScene()->GetGLScene()->SetClip(x ? m_glClip : 0);
00187    viewerGL()->RequestDraw();
00188 }
00189 
00190 //______________________________________________________________________________
00191 void
00192 FW3DViewBase::addTo(FWConfiguration& iTo) const
00193 {
00194    // take care of parameters
00195    FWEveView::addTo(iTo);
00196    TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
00197    if (camera)
00198       addToPerspectiveCamera(camera, "Plain3D", iTo);   
00199 }
00200 
00201 //______________________________________________________________________________
00202 void
00203 FW3DViewBase::setFrom(const FWConfiguration& iFrom)
00204 {
00205    // take care of parameters
00206    FWEveView::setFrom(iFrom);
00207 
00208    TGLPerspectiveCamera* camera = dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->CurrentCamera()));
00209    if (camera)
00210       setFromPerspectiveCamera(camera, "Plain3D", iFrom);
00211 
00212    if (iFrom.version() < 5)
00213    {
00214       // transparency moved to common preferences in FWEveView version 5
00215       std::string tName("Detector Transparency");
00216       std::istringstream s(iFrom.valueForKey(tName)->value());
00217       int transp;
00218       s>> transp;
00219       context().colorManager()->setGeomTransparency(transp, false);
00220    }
00221 }
00222 
00223 
00224 void 
00225 FW3DViewBase::populateController(ViewerParameterGUI& gui) const
00226 {
00227    FWEveView::populateController(gui);
00228 
00229    gui.requestTab("Detector").
00230       addParam(&m_showMuonBarrel).
00231       addParam(&m_showMuonEndcap).
00232       addParam(&m_showTrackerBarrel).
00233       addParam(&m_showTrackerEndcap).
00234       addParam(&m_showPixelBarrel).
00235       addParam(&m_showPixelEndcap).  
00236       separator().
00237       addParam(&m_rnrStyle).
00238       addParam(&m_clipParam).
00239       addParam(&m_selectable);
00240 
00241 
00242    gui.requestTab("Style").separator();
00243    gui.getTabContainer()->AddFrame(new TGTextButton(gui.getTabContainer(), "Root controls",
00244                                                     Form("TEveGedEditor::SpawnNewEditor((TGLViewer*)0x%lx)", (unsigned long)viewerGL())));
00245 }
00246 
00247 
00248