File indexing completed on 2024-04-06 12:22:31
0001
0002
0003
0004
0005
0006
0007
0008 #include "TEveManager.h"
0009 #include "TEveViewer.h"
0010 #include "TEveScene.h"
0011 #include "TEveGeoNode.h"
0012 #include "TEveTrans.h"
0013
0014 #include "TGLUtil.h"
0015 #include "TGLViewer.h"
0016 #include "TGLCamera.h"
0017 #include "TGLClip.h"
0018
0019 #include "TGeoManager.h"
0020 #include "TGeoNode.h"
0021 #include "TGeoVolume.h"
0022 #include "TGeoShape.h"
0023 #include "TGeoMaterial.h"
0024 #include "TGeoMedium.h"
0025 #include "TGeoMatrix.h"
0026 #include "TGLSAViewer.h"
0027
0028 #include "TGListTree.h"
0029
0030 #include "TPRegexp.h"
0031
0032 #include <iostream>
0033
0034
0035
0036
0037
0038
0039 void macros(){
0040 ((TGLSAViewer*)gEve->GetDefaultGLViewer())->DisableMenuBarHiding();
0041 }
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089 void update_evegeonodes(TEveElement* el, Bool_t top)
0090 {
0091 TEveGeoNode *en = dynamic_cast<TEveGeoNode*>(el);
0092
0093 if (en && !top)
0094 {
0095 TGeoNode *n = en->GetNode();
0096 en->SetRnrSelfChildren(n->IsVisible(), n->IsVisDaughters());
0097 en->SetMainColor(n->GetVolume()->GetLineColor());
0098 en->SetMainTransparency(n->GetVolume()->GetTransparency());
0099 }
0100
0101 for (TEveElement::List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
0102 {
0103 update_evegeonodes(*i, kFALSE);
0104 }
0105 }
0106
0107 void full_update()
0108 {
0109 TEveScene *gs = gEve->GetGlobalScene();
0110 for (TEveElement::List_i i = gs->BeginChildren(); i != gs->EndChildren(); ++i)
0111 {
0112 update_evegeonodes(*i, kTRUE);
0113 }
0114 gEve->FullRedraw3D();
0115 gEve->GetListTree()->ClearViewPort();
0116 }
0117
0118
0119
0120
0121
0122
0123
0124 void visibility_all_volumes(Bool_t vis_state)
0125 {
0126 TGeoVolume *v;
0127 TIter it(gGeoManager->GetListOfVolumes());
0128 while ((v = (TGeoVolume*) it()) != 0)
0129 {
0130 v->SetVisibility(vis_state);
0131 }
0132 full_update();
0133 }
0134
0135
0136
0137
0138
0139 void visibility_all_nodes(Bool_t vis_state, const char* nameFilter=".*")
0140 {
0141
0142 TPMERegexp re(nameFilter, "o");
0143
0144 TGeoVolume *v;
0145 TIter it(gGeoManager->GetListOfVolumes());
0146 while ((v = (TGeoVolume*) it()) != 0)
0147 {
0148 TGeoNode *n;
0149 TIter it2(v->GetNodes());
0150 while ((n = (TGeoNode*) it2()) != 0)
0151 {
0152 TString name(n->GetName());
0153 if (name!="cms:World_1"&&name!="cmsMagneticField:MAGF_1" && re.Match(name)) {
0154 std::cout << name << std::endl;
0155 n->SetVisibility(vis_state);
0156
0157
0158 } else {
0159
0160 }
0161 }
0162 }
0163 full_update();
0164 }
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179 void set_volume_color_by_material(const char* material_re, Color_t color, Char_t transparency=-1)
0180 {
0181
0182
0183
0184
0185 TPMERegexp re(material_re, "o");
0186 TGeoMaterial *m;
0187 TIter it(gGeoManager->GetListOfMaterials());
0188 while ((m = (TGeoMaterial*) it()) != 0)
0189 {
0190 if (re.Match(m->GetName()))
0191 {
0192 if (transparency != -1)
0193 {
0194 m->SetTransparency(transparency);
0195 }
0196 TGeoVolume *v;
0197 TIter it2(gGeoManager->GetListOfVolumes());
0198 while ((v = (TGeoVolume*) it2()) != 0)
0199 {
0200 if (v->GetMaterial() == m)
0201 {
0202 v->SetLineColor(color);
0203 }
0204 }
0205 }
0206 }
0207 full_update();
0208 }
0209
0210 void visibility_volume_by_material(const char* material_re, Bool_t vis_state)
0211 {
0212 TPMERegexp re(material_re, "o");
0213 TGeoMaterial *m;
0214 TIter it(gGeoManager->GetListOfMaterials());
0215 while ((m = (TGeoMaterial*) it()) != 0)
0216 {
0217 if (re.Match(m->GetName()))
0218 {
0219 TGeoVolume *v;
0220 TIter it2(gGeoManager->GetListOfVolumes());
0221 while ((v = (TGeoVolume*) it2()) != 0)
0222 {
0223 if (v->GetMaterial() == m)
0224 {
0225 v->SetVisibility(vis_state);
0226 }
0227 }
0228 }
0229 }
0230 full_update();
0231 }
0232
0233
0234
0235
0236
0237
0238
0239 float GetZoom()
0240 {
0241 TGLViewer* v = gEve->GetDefaultGLViewer();
0242 TGLOrthoCamera& c = (TGLOrthoCamera& )v->CurrentCamera();
0243 printf("zoom %f \n", c.GetZoom());
0244 return c.GetZoom();
0245 }
0246
0247 void SetZoom(float zoom)
0248 {
0249 TGLViewer* v = gEve->GetDefaultGLViewer();
0250 TGLOrthoCamera& c = (TGLOrthoCamera& )v->CurrentCamera();
0251 c.SetZoom(zoom);
0252 c.IncTimeStamp();
0253 v->RequestDraw();
0254 }
0255
0256
0257
0258 void goTo(TString view, bool clip) {
0259
0260 TGLViewer* v = gEve->GetDefaultGLViewer();
0261 TGLClipSet* cs = v->GetClipSet();
0262
0263
0264 if (view=="ZY"){
0265 v->SetCurrentCamera(TGLViewer::kCameraOrthoZOY);
0266
0267
0268
0269
0270 if (clip) {
0271 Double_t clipBox[6] = {0,0,0, 3,1800,4000};
0272 cs->SetClipType(TGLClip::kClipBox);
0273 v->RefreshPadEditor(v);
0274 cs->GetCurrentClip()->SetMode(TGLClip::kOutside);
0275 cs->SetClipState(TGLClip::kClipBox, clipBox);
0276 v->RefreshPadEditor(v);
0277 v->SetStyle(TGLRnrCtx::kOutline);
0278 }
0279 }
0280
0281 else if (view=="XY"){
0282 v->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
0283
0284 if (clip) {
0285 Double_t clipBox[6] = {0,0,0, 1800,1800,3};
0286 cs->SetClipType(TGLClip::kClipBox);
0287 v->RefreshPadEditor(v);
0288 cs->GetCurrentClip()->SetMode(TGLClip::kOutside);
0289 cs->SetClipState(TGLClip::kClipBox, clipBox);
0290 v->RefreshPadEditor(v);
0291 v->SetStyle(TGLRnrCtx::kOutline);
0292 }
0293
0294 }
0295
0296 gEve->FullRedraw3D(kTRUE);
0297
0298 }
0299
0300
0301
0302
0303 void ZYView(float zoom=-999, bool clip=true){
0304
0305 TGLViewer* v = gEve->GetDefaultGLViewer();
0306 v->SetCurrentCamera(TGLViewer::kCameraOrthoZOY);
0307
0308 if (clip) {
0309 TGLClipSet* cs = v->GetClipSet();
0310 Double_t clipBox[6] = {0,0,0, 3,1800,4000};
0311 cs->SetClipType(TGLClip::kClipBox);
0312 v->RefreshPadEditor(v);
0313 cs->GetCurrentClip()->SetMode(TGLClip::kOutside);
0314 cs->SetClipState(TGLClip::kClipBox, clipBox);
0315 v->RefreshPadEditor(v);
0316 v->SetStyle(TGLRnrCtx::kOutline);
0317 }
0318 gEve->FullRedraw3D(kTRUE);
0319
0320 if (zoom>0) SetZoom(zoom);
0321
0322 }
0323
0324
0325 void XYView(float Z=0, bool clip=true){
0326 TGLViewer* v = gEve->GetDefaultGLViewer();
0327 v->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
0328
0329 if (clip) {
0330 TGLClipSet* cs = v->GetClipSet();
0331 Double_t clipBox[6] = {0,0,Z, 1800,1800,3};
0332 cs->SetClipType(TGLClip::kClipBox);
0333 v->RefreshPadEditor(v);
0334 cs->GetCurrentClip()->SetMode(TGLClip::kOutside);
0335 cs->SetClipState(TGLClip::kClipBox, clipBox);
0336 v->RefreshPadEditor(v);
0337 v->SetStyle(TGLRnrCtx::kOutline);
0338 }
0339 gEve->FullRedraw3D(kTRUE);
0340 }
0341
0342
0343 void print(TString filename) {
0344 gEve->GetDefaultGLViewer()->SavePicture(filename);
0345 }
0346
0347
0348
0349
0350
0351
0352
0353
0354