CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/Fireworks/Core/src/FWGeoTopNode.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWGeoTopNode
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Matevz Tadel, Alja Mrak Tadel  
00010 //         Created:  Thu Jun 23 01:24:51 CEST 2011
00011 // $Id: FWGeoTopNode.cc,v 1.18 2011/07/21 00:56:27 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 
00018 #include "TEveTrans.h"
00019 #include "TEveManager.h"
00020 #include "TEveUtil.h"
00021 
00022 
00023 #include "TROOT.h"
00024 #include "TBuffer3D.h"
00025 #include "TBuffer3DTypes.h"
00026 #include "TVirtualViewer3D.h"
00027 #include "TColor.h"
00028 
00029 #include "TGeoShape.h"
00030 #include "TGeoVolume.h"
00031 #include "TGeoNode.h"
00032 #include "TGeoShapeAssembly.h"
00033 #include "TGeoCompositeShape.h"
00034 #include "TGeoBoolNode.h"
00035 #include "TGeoManager.h"
00036 #include "TGeoMatrix.h"
00037 #include "TVirtualGeoPainter.h"
00038 
00039 #include "Fireworks/Core/interface/FWGeoTopNode.h"
00040 #include "Fireworks/Core/interface/FWGeometryTableView.h"
00041 #include "Fireworks/Core/interface/FWGeometryTableManager.h"
00042 #include "Fireworks/Core/interface/FWGeometryTableViewManager.h"
00043 
00044 FWGeoTopNode::FWGeoTopNode(FWGeometryTableView* t):
00045    m_browser(t),
00046    m_maxLevel(0),
00047    m_filterOff(0)
00048 {
00049    m_entries = &(m_browser->getTableManager()->refEntries());
00050 }
00051 
00052 FWGeoTopNode::~FWGeoTopNode()
00053 {
00054 }
00055 
00056 
00057 //______________________________________________________________________________
00058 void FWGeoTopNode::setupBuffMtx(TBuffer3D& buff, const TGeoHMatrix& mat)
00059 {
00060    const Double_t *r = mat.GetRotationMatrix();
00061    const Double_t *t = mat.GetTranslation();
00062    const Double_t *s = mat.GetScale();
00063    Double_t       *m = buff.fLocalMaster;
00064    m[0]  = r[0]*s[0]; m[1]  = r[1]*s[1]; m[2]  = r[2]*s[2]; m[3]  = 0;
00065    m[4]  = r[3]*s[0]; m[5]  = r[4]*s[1]; m[6]  = r[5]*s[2]; m[7]  = 0;
00066    m[8]  = r[6]*s[0]; m[9]  = r[7]*s[1]; m[10] = r[8]*s[2]; m[11] = 0;
00067    m[12] = t[0];      m[13] = t[1];      m[15] = t[2];      m[15] = 1;
00068 
00069    buff.fLocalFrame = kTRUE;
00070 }
00071 //______________________________________________________________________________
00072 void FWGeoTopNode::Paint(Option_t*)
00073 {
00074 
00075    // workaround for global usage of gGeoManager in TGeoShape
00076    TEveGeoManagerHolder gmgr( FWGeometryTableViewManager::getGeoMangeur());
00077 
00078    int topIdx = m_browser->getTopNodeIdx();
00079    FWGeometryTableManager::Entries_i sit = m_entries->begin(); 
00080 
00081    m_maxLevel = m_browser->getVisLevel() + m_browser->getTableManager()->getLevelOffset() -1;
00082    m_filterOff = m_browser->getFilter().empty();
00083 
00084    TGeoHMatrix mtx;
00085    if (topIdx >= 0)
00086    {
00087       std::advance(sit, topIdx);
00088       m_browser->getTableManager()->getNodeMatrix(*sit, mtx);
00089 
00090       // paint this node
00091       if ( m_filterOff == false)
00092          m_browser->getTableManager()->assertNodeFilterCache(*sit);
00093 
00094       if ( m_browser->getTableManager()->getVisibility(*sit))
00095          paintShape(*sit, mtx);
00096    }
00097 
00098    if ( m_browser->getTableManager()->getVisibilityChld(*sit))
00099       paintChildNodesRecurse( sit, mtx);
00100 }
00101 
00102 // ______________________________________________________________________
00103 
00104 void FWGeoTopNode::paintChildNodesRecurse (FWGeometryTableManager::Entries_i pIt, const TGeoHMatrix& parentMtx)
00105 { 
00106    TGeoNode* parentNode =  pIt->m_node;
00107    int nD = parentNode->GetNdaughters();
00108 
00109    int dOff=0;
00110    pIt++;
00111 
00112    FWGeometryTableManager::Entries_i it;
00113    for (int n = 0; n != nD; ++n)
00114    {
00115       it =  pIt;
00116       std::advance(it,n + dOff);
00117 
00118       TGeoHMatrix nm = parentMtx;
00119       nm.Multiply(it->m_node->GetMatrix());
00120 
00121   
00122       if (m_filterOff)
00123       {
00124          if ( m_browser->getTableManager()->getVisibility(*it))
00125             paintShape(*it, nm);
00126 
00127          if  ( m_browser->getTableManager()->getVisibilityChld(*it) && it->m_level < m_maxLevel )
00128             paintChildNodesRecurse(it, nm);
00129 
00130       }
00131       else
00132       {
00133          m_browser->getTableManager()->assertNodeFilterCache(*it);
00134          if ( m_browser->getTableManager()->getVisibility(*it))
00135             paintShape(*it, nm);
00136 
00137          if ( m_browser->getTableManager()->getVisibilityChld(*it) && ( it->m_level < m_maxLevel || m_browser->getIgnoreVisLevelWhenFilter() ))
00138             paintChildNodesRecurse(it, nm);
00139       }
00140 
00141 
00142       FWGeometryTableManager::getNNodesTotal(parentNode->GetDaughter(n), dOff);  
00143    }
00144 }
00145   
00146 // ______________________________________________________________________
00147 void FWGeoTopNode::paintShape(FWGeometryTableManager::NodeInfo& data, const TGeoHMatrix& nm)
00148 { 
00149    static const TEveException eh("FWGeoTopNode::paintShape ");
00150   
00151 
00152    TGeoShape* shape = data.m_node->GetVolume()->GetShape();
00153    TGeoCompositeShape* compositeShape = dynamic_cast<TGeoCompositeShape*>(shape);
00154    if (compositeShape)
00155    {
00156       // printf("!!!!!!!!!!!!!!!!!!!! composite shape\n");
00157       Double_t halfLengths[3] = { compositeShape->GetDX(), compositeShape->GetDY(), compositeShape->GetDZ() };
00158 
00159       TBuffer3D buff(TBuffer3DTypes::kComposite);
00160       buff.fID           = data.m_node->GetVolume();
00161       //   buff.fColor        = data.m_color;
00162       buff.fColor        =  m_browser->getVolumeMode() ? data.m_node->GetVolume()->GetLineColor(): data.m_color;
00163       buff.fTransparency = data.m_node->GetVolume()->GetTransparency(); 
00164 
00165       nm.GetHomogenousMatrix(buff.fLocalMaster);        
00166       // RefMainTrans().SetBuffer3D(buff);
00167       buff.fLocalFrame   = kTRUE; // Always enforce local frame (no geo manager).
00168       buff.SetAABoundingBox(compositeShape->GetOrigin(), halfLengths);
00169       buff.SetSectionsValid(TBuffer3D::kCore|TBuffer3D::kBoundingBox);
00170 
00171       Bool_t paintComponents = kTRUE;
00172 
00173       // Start a composite shape, identified by this buffer
00174       if (TBuffer3D::GetCSLevel() == 0)
00175          paintComponents = gPad->GetViewer3D()->OpenComposite(buff);
00176 
00177       TBuffer3D::IncCSLevel();
00178 
00179       // Paint the boolean node - will add more buffers to viewer
00180       TGeoHMatrix xxx;
00181       TGeoMatrix *gst = TGeoShape::GetTransform();
00182       TGeoShape::SetTransform(&xxx);
00183       if (paintComponents) compositeShape->GetBoolNode()->Paint("");
00184       TGeoShape::SetTransform(gst);
00185       // Close the composite shape
00186       if (TBuffer3D::DecCSLevel() == 0)
00187       gPad->GetViewer3D()->CloseComposite();
00188 
00189    }
00190    else
00191    {
00192       TBuffer3D& buff = (TBuffer3D&) shape->GetBuffer3D (TBuffer3D::kCore, kFALSE);
00193       setupBuffMtx(buff, nm);
00194       buff.fID           = data.m_node->GetVolume();
00195       buff.fColor        =  m_browser->getVolumeMode() ? data.m_node->GetVolume()->GetLineColor(): data.m_color;
00196       buff.fTransparency =  data.m_node->GetVolume()->GetTransparency();
00197 
00198       nm.GetHomogenousMatrix(buff.fLocalMaster);
00199       buff.fLocalFrame   = kTRUE; // Always enforce local frame (no geo manager).
00200 
00201       Int_t sections = TBuffer3D::kBoundingBox | TBuffer3D::kShapeSpecific;
00202       shape->GetBuffer3D(sections, kTRUE);
00203 
00204            
00205       Int_t reqSec = gPad->GetViewer3D()->AddObject(buff);
00206 
00207       if (reqSec != TBuffer3D::kNone) {
00208          // This shouldn't happen, but I suspect it does sometimes.
00209          if (reqSec & TBuffer3D::kCore)
00210             Warning(eh, "Core section required again for shape='%s'. This shouldn't happen.", GetName());
00211          shape->GetBuffer3D(reqSec, kTRUE);
00212          reqSec = gPad->GetViewer3D()->AddObject(buff);
00213       }
00214 
00215       if (reqSec != TBuffer3D::kNone)  
00216          Warning(eh, "Extra section required: reqSec=%d, shape=%s.", reqSec, GetName());
00217    }
00218 }