CMS 3D CMS Logo

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