Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:24

0001 #include "TEveManager.h"
0002 #include "TEveViewer.h"
0003 #include "TEveScene.h"
0004 #include "TEveGeoNode.h"
0005 #include "TEveTrans.h"
0006 
0007 #include "TGLUtil.h"
0008 #include "TGLViewer.h"
0009 #include "TGLCamera.h"
0010 #include "TGLClip.h"
0011 
0012 #include "TGeoManager.h"
0013 #include "TGeoNode.h"
0014 #include "TGeoVolume.h"
0015 #include "TGeoShape.h"
0016 #include "TGeoMaterial.h"
0017 #include "TGeoMedium.h"
0018 #include "TGeoMatrix.h"
0019 
0020 #include "TGListTree.h"
0021 
0022 #include "TPRegexp.h"
0023 
0024 typedef TGLClip::EType EClipType;
0025 
0026 //==============================================================================
0027 // Creation, initialization
0028 //==============================================================================
0029 
0030 void std_init()
0031 {
0032    TEveManager::Create();
0033    gGeoManager = gEve->GetGeometry("cmsSimGeom-14.root");
0034    gGeoManager->DefaultColors();
0035 }
0036 
0037 TEveGeoTopNode* make_node(const TString& path, Int_t vis_level, Bool_t global_cs)
0038 {
0039   if (! gGeoManager->cd(path))
0040   {
0041     Warning("make_node", "Path '%s' not found.", path.Data());
0042     return 0;
0043   }
0044 
0045   TEveGeoTopNode* tn = new TEveGeoTopNode(gGeoManager, gGeoManager->GetCurrentNode());
0046   tn->SetVisLevel(vis_level);
0047   if (global_cs)
0048   {
0049     tn->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
0050   }
0051   gEve->AddGlobalElement(tn);
0052 
0053   return tn;
0054 }
0055 
0056 void std_camera_clip()
0057 {
0058    // EClipType not exported to CINT (see TGLUtil.h):
0059    // 0 - no clip, 1 - clip plane, 2 - clip box
0060 
0061    TGLViewer *v = gEve->GetDefaultGLViewer();
0062    v->GetClipSet()->SetClipType((EClipType) 1);
0063    v->SetGuideState(TGLUtil::kAxesEdge, kTRUE, kFALSE, 0);
0064    v->RefreshPadEditor(v);
0065 
0066    v->CurrentCamera().RotateRad(-1.2, 0.5);
0067    v->DoDraw();
0068 }
0069 
0070 
0071 //==============================================================================
0072 // EVE helpers
0073 //==============================================================================
0074 
0075 void update_evegeonodes(TEveElement* el, Bool_t top)
0076 {
0077    TEveGeoNode *en = dynamic_cast<TEveGeoNode*>(el);
0078 
0079    if (en && !top)
0080    {
0081       TGeoNode *n = en->GetNode();
0082       en->SetRnrSelfChildren(n->IsVisible(), n->IsVisDaughters());
0083       en->SetMainColor(n->GetVolume()->GetLineColor());
0084       en->SetMainTransparency(n->GetVolume()->GetTransparency());
0085    }
0086 
0087    for (TEveElement::List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
0088    {
0089       update_evegeonodes(*i, kFALSE);
0090    }
0091 }
0092 
0093 void full_update()
0094 {
0095    TEveScene *gs = gEve->GetGlobalScene();
0096    for (TEveElement::List_i i = gs->BeginChildren(); i != gs->EndChildren(); ++i)
0097    {
0098       update_evegeonodes(*i, kTRUE);
0099    }
0100    gEve->FullRedraw3D();
0101    gEve->GetListTree()->ClearViewPort();
0102 }
0103 
0104 
0105 //==============================================================================
0106 // Global node / volume toggles
0107 //==============================================================================
0108 
0109 void visibility_all_volumes(Bool_t vis_state)
0110 {
0111    TGeoVolume *v;
0112    TIter it(gGeoManager->GetListOfVolumes());
0113    while ((v = (TGeoVolume*) it()) != 0)
0114    {
0115       v->SetVisibility(vis_state);
0116    }
0117    full_update();
0118 }
0119 
0120 void visibility_all_nodes(Bool_t vis_state)
0121 {
0122    TGeoVolume *v;
0123    TIter it(gGeoManager->GetListOfVolumes());
0124    while ((v = (TGeoVolume*) it()) != 0)
0125    {
0126       TGeoNode *n;
0127       TIter it2(v->GetNodes());
0128       while ((n = (TGeoNode*) it2()) != 0)
0129       {
0130          n->SetVisibility(vis_state);
0131       }
0132    }
0133    full_update();
0134 }
0135 
0136 
0137 //==============================================================================
0138 // Utilities by material type
0139 //==============================================================================
0140 
0141 // List materials:
0142 //   gGeoManager->GetListOfMaterials()->ls()
0143 //   gGeoManager->GetListOfMaterials()->ls("*Si*")
0144 //
0145 // Print materials:
0146 //   gGeoManager->GetListOfMaterials()->Print()
0147 //   gGeoManager->GetListOfMaterials()->Print("", "*Si*")
0148 
0149 void set_volume_color_by_material(const char* material_re, Color_t color, Char_t transparency=-1)
0150 {
0151    // Note: material_re is a perl regexp!
0152    // If you want exact match, enclose in begin / end meta characters (^ / $):
0153    //   set_volume_color_by_material("^materials:Silicon$", kRed);
0154 
0155    TPMERegexp re(material_re, "o");
0156    TGeoMaterial *m;
0157    TIter it(gGeoManager->GetListOfMaterials());
0158    while ((m = (TGeoMaterial*) it()) != 0)
0159    {
0160       if (re.Match(m->GetName()))
0161       {
0162          if (transparency != -1)
0163          {
0164             m->SetTransparency(transparency);
0165          }
0166          TGeoVolume *v;
0167          TIter it2(gGeoManager->GetListOfVolumes());
0168          while ((v = (TGeoVolume*) it2()) != 0)
0169          {
0170             if (v->GetMaterial() == m)
0171             {
0172                v->SetLineColor(color);
0173             }
0174          }
0175       }
0176    }
0177    full_update();
0178 }
0179 
0180 void visibility_volume_by_material(const char* material_re, Bool_t vis_state)
0181 {
0182    TPMERegexp re(material_re, "o");
0183    TGeoMaterial *m;
0184    TIter it(gGeoManager->GetListOfMaterials());
0185    while ((m = (TGeoMaterial*) it()) != 0)
0186    {
0187       if (re.Match(m->GetName()))
0188       {
0189          TGeoVolume *v;
0190          TIter it2(gGeoManager->GetListOfVolumes());
0191          while ((v = (TGeoVolume*) it2()) != 0)
0192          {
0193             if (v->GetMaterial() == m)
0194             {
0195                v->SetVisibility(vis_state);
0196             }
0197          }
0198       }
0199    }
0200    full_update();
0201 }