Skip to content

Instantly share code, notes, and snippets.

@JeremyMcCormick
Last active September 2, 2020 00:44
Show Gist options
  • Save JeremyMcCormick/f556f7f9de556720b5ea51b50f126b38 to your computer and use it in GitHub Desktop.
Save JeremyMcCormick/f556f7f9de556720b5ea51b50f126b38 to your computer and use it in GitHub Desktop.
eve_geom_test2.C
#include <vector>
#include <iostream>
#include "TEveManager.h"
#include "TEveBrowser.h"
#include "TEveGeoNode.h"
#include "TEveScene.h"
#include "TEveViewer.h"
#include "TGLViewer.h"
#include "TGeoManager.h"
#include "TGTab.h"
TEveScene *_XZGeomScene = 0;
TEveScene *_YZGeomScene = 0;
TEveScene *_XYGeomScene = 0;
void MakeGeometry() {
TGeoManager *geom = new TGeoManager("simple1", "Simple geometry");
//--- define some materials
TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0, 0, 0);
TGeoMaterial *matAl = new TGeoMaterial("Al", 26.98, 13, 2.7);
//--- define some media
TGeoMedium *Vacuum = new TGeoMedium("Vacuum", 1, matVacuum);
TGeoMedium *Al = new TGeoMedium("Root Material", 2, matAl);
TGeoVolume *top = geom->MakeBox("TOP", Vacuum, 270., 270., 120.);
geom->SetTopVolume(top);
TGeoVolume *box = geom->MakeBox("Box", Al, 10., 10., 10.);
top->AddNode(box, 1, new TGeoTranslation(-15, 0, 0));
top->AddNode(box, 2, new TGeoTranslation(15, 0, 0));
//--- close the geometry
geom->CloseGeometry();
gGeoManager->DefaultColors();
// geom->Export("testgeo.root", "TestGeo");
}
void CleanScene(TString projection, TEveElement *scene) {
TString toBeRemoved;
if (projection == "YZ")
return;
else if (projection == "XZ")
toBeRemoved = "Box_1";
else if (projection == "XY")
toBeRemoved = "Box_2";
else
return;
for (TEveElement::List_i it = scene->BeginChildren(); it != scene->EndChildren(); it++) {
std::cout << projection << " " << (*it)->GetElementName() << " " << *it << '\n';
if ((*it)->GetElementName() == toBeRemoved) {
std::cout << projection << " Trying to remove " << (*it)->GetElementName() << " " << *it << '\n';
dynamic_cast<TEveElement*>(*it)->SetRnrSelf(false);
} else {
CleanScene(projection, *it);
}
}
}
void FillScene(TEveElement *parent, int depth)
{
// Expects gGeoManager / navigator at proper position.
if (depth <= 0) return;
TGeoNode *n = gGeoManager->GetCurrentNode();
TGeoVolume *v = gGeoManager->GetCurrentVolume();
TEveGeoShape* s = new TEveGeoShape(n->GetName(), v->GetMaterial()->GetName());
s->SetMainColor(v->GetLineColor());
s->SetMainTransparency(v->GetTransparency());
// s->SetPickable(kTRUE);
s->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
s->SetShape((TGeoShape*) v->GetShape()->Clone());
Int_t Nc = n->GetNdaughters();
printf("FillScene: %s, Nc=%d, depth=%d\n", gGeoManager->GetCurrentNode()->GetName(), Nc, depth);
for (Int_t i = 0; i < Nc; ++i)
{
gGeoManager->CdDown(i);
FillScene(s, depth - 1);
gGeoManager->CdUp();
}
parent->AddElement(s);
}
void test2() {
gEve = new TEveManager(1200, 600, true, "");
auto _slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
auto _pack = _slot->MakePack();
_pack->SetElementName("Multi View");
_pack->SetHorizontal();
_pack->SetShowTitleBar(kFALSE);
_XZGeomScene = gEve->SpawnNewScene("XOZG", "XOZ Geometry Scene");
_YZGeomScene = gEve->SpawnNewScene("YOZG", "YOZ Geometry Scene");
_XYGeomScene = gEve->SpawnNewScene("XOYG", "XOY Geometry Scene");
_pack->NewSlot()->MakeCurrent();
auto _XZView = gEve->SpawnNewViewer("XZ View", "");
_XZView->AddScene(_XZGeomScene);
_XZView->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoZOX);
_pack->NewSlot()->MakeCurrent();
auto _YZView = gEve->SpawnNewViewer("YZ View", "");
_YZView->AddScene(_YZGeomScene);
_YZView->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoZnOY);
_pack->NewSlot()->MakeCurrent();
auto _XYView = gEve->SpawnNewViewer("XY View", "");
_XYView->AddScene(_XYGeomScene);
_XYView->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
gEve->GetBrowser()->HideBottomTab();
gEve->GetBrowser()->GetTabRight()->SetTab(1);
MakeGeometry();
gGeoManager->CdTop();
TEveScene *scenes[] = {_XZGeomScene, _YZGeomScene, _XYGeomScene };
TString names[] = { "XZ", "YZ", "XY" };
for (int i = 0; i < 3; ++i)
{
FillScene(scenes[i], 2);
CleanScene(names[i], scenes[i]);
}
gEve->FullRedraw3D();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment