15#include "TRestEveEventViewer.h"
17#include "TRestStringOutput.h"
23TRestEveEventViewer::TRestEveEventViewer() {
25 fEnergyDeposits =
new TEvePointSet();
26 fEnergyDeposits->SetElementName(
"Energy deposits");
28 RESTWarning <<
"There are some issues with geometry representation in Eve 3D scenes!" << RESTendl;
30 <<
"We use a geometry scaling factor to place the hits in the scene and correct a placement problem"
32 RESTWarning <<
"Presently the default value of fGeomScale is " << fGeomScale << RESTendl;
33 RESTWarning <<
"Please, report to the dev team if you experience problems visualizing the geometry."
35 RESTWarning <<
"For example: when hit positions seem to do not match geometry positions" << RESTendl;
37 RESTWarning <<
" " << RESTendl;
38 RESTWarning <<
"You may try to fix this using TRestEventViewer::SetGeomScale(1.0);" << RESTendl;
41TRestEveEventViewer::~TRestEveEventViewer() {
42 delete fEnergyDeposits;
48void InitializePerspectiveView() {
49 const std::map<TString, TGLViewer::ECameraType> projectionsMap = {
50 {
"Projection XY", TGLViewer::kCameraOrthoXOY},
51 {
"Projection XZ", TGLViewer::kCameraOrthoXnOZ},
52 {
"Projection YZ", TGLViewer::kCameraOrthoZOY}
54 for (
const auto& [name, cameraType] : projectionsMap) {
55 auto slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
56 auto pack = slot->MakePack();
57 pack->SetElementName(name);
58 pack->SetHorizontal();
59 pack->SetShowTitleBar(kFALSE);
60 pack->NewSlot()->MakeCurrent();
61 auto f3DView = gEve->SpawnNewViewer(
"3D View", pack->GetName());
62 f3DView->AddScene(gEve->GetGlobalScene());
63 f3DView->AddScene(gEve->GetEventScene());
64 f3DView->GetGLViewer()->SetCurrentCamera(cameraType);
68void TRestEveEventViewer::Initialize() {
69 gEve = TEveManager::Create();
70 gEve->GetBrowser()->DontCallClose();
72 gEve->AddEvent(
new TEveEventManager(
"Event",
"Event"));
74 auto singleViewer = gEve->GetDefaultViewer();
75 singleViewer->SetElementName(
"SingleView");
77 singleViewer->GetGLViewer()->SetClearColor(kBlack);
79 InitializePerspectiveView();
83 singleViewer->GetGLViewer()->SetStyle(TGLRnrCtx::kOutline);
85 gEve->GetBrowser()->GetTabRight()->SetTab(0);
87 singleViewer->GetGLViewer()->CurrentCamera().Reset();
88 gEve->FullRedraw3D(kTRUE);
91void TRestEveEventViewer::SetGeometry(TGeoManager* geo) {
92 TRestEventViewer::SetGeometry(geo);
94 if (fGeometry ==
nullptr) {
98 const unsigned int nVolumes = fGeometry->GetListOfVolumes()->GetEntries();
99 double transparencyLevel = 85;
101 transparencyLevel = 90;
103 for (
int i = 0; i < fGeometry->GetListOfVolumes()->GetEntries(); i++) {
104 auto volume = fGeometry->GetVolume(i);
105 auto material = volume->GetMaterial();
106 if (material->GetDensity() <= 0.01) {
107 volume->SetTransparency(99);
108 if (material->GetDensity() <= 0.001) {
110 volume->SetVisibility(kFALSE);
113 volume->SetTransparency(transparencyLevel);
117 TEveGeoTopNode* eveGeoTopNode =
new TEveGeoTopNode(fGeometry, fGeometry->GetTopNode());
118 eveGeoTopNode->SetVisLevel(5);
120 gEve->AddGlobalElement(eveGeoTopNode);
122 viewer3D->AddScene(gEve->GetGlobalScene());
125void TRestEveEventViewer::DeleteCurrentEvent() {
126 cout <<
"Removing event" << endl;
127 delete fEnergyDeposits;
128 fEnergyDeposits =
new TEvePointSet();
129 fEnergyDeposits->SetElementName(
"Energy deposits");
130 gEve->GetViewers()->DeleteAnnotations();
131 gEve->GetCurrentEvent()->DestroyElements();
134void TRestEveEventViewer::DeleteGeometry() {
135 cout <<
"Removing geometry" << endl;
136 gEve->GetGlobalScene()->DestroyElements();
139void TRestEveEventViewer::MultiView() {
140 slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
142 pack = slot->MakePack();
143 pack->SetElementName(
"MultiView");
144 pack->SetHorizontal();
145 pack->SetShowTitleBar(kFALSE);
146 pack->NewSlot()->MakeCurrent();
148 viewer3D = gEve->SpawnNewViewer(
"3DView");
149 viewer3D->AddScene(gEve->GetEventScene());
151 pack = pack->NewSlot()->MakePack();
152 pack->SetShowTitleBar(kFALSE);
153 pack->NewSlot()->MakeCurrent();
154 rphiViewer = gEve->SpawnNewViewer(
"RPhi View");
155 rphiViewer->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
157 rphiScene = gEve->SpawnNewScene(
"RPhi");
158 rphiViewer->AddScene(rphiScene);
160 rphi =
new TEveProjectionManager(TEveProjection::kPT_RPhi);
161 rphiScene->AddElement(rphi);
163 rphiAxes =
new TEveProjectionAxes(rphi);
164 rphiScene->AddElement(rphiAxes);
166 pack = pack->NewSlot()->MakePack();
167 pack->SetShowTitleBar(kFALSE);
168 pack->NewSlot()->MakeCurrent();
169 rhozViewer = gEve->SpawnNewViewer(
"RhoZ View");
170 rhozViewer->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
172 rhozScene = gEve->SpawnNewScene(
"RhoZ");
173 rhozViewer->AddScene(rhozScene);
175 rhoz =
new TEveProjectionManager(TEveProjection::kPT_RhoZ);
176 rhozScene->AddElement(rhoz);
178 rhozAxes =
new TEveProjectionAxes(rhoz);
179 rhozScene->AddElement(rhozAxes);
182void TRestEveEventViewer::DrawTab() {
183 TGLViewer* v2 = viewer3D->GetGLViewer();
184 v2->SetGuideState(TGLUtil::kAxesEdge, kTRUE, kFALSE,
nullptr);
185 v2->SetStyle(TGLRnrCtx::kOutline);
188void TRestEveEventViewer::Update() {
189 gEve->AddElement(fEnergyDeposits);
190 rphi->ImportElements(gEve->GetCurrentEvent());
191 rhoz->ImportElements(gEve->GetCurrentEvent());
193 rphiViewer->Redraw(kTRUE);
194 rhozViewer->Redraw(kTRUE);
197void TRestEveEventViewer::AddSphericalHit(
double x,
double y,
double z,
double radius,
double en) {
198 fEnergyDeposits->SetOwnIds(kTRUE);
199 fEnergyDeposits->SetNextPoint(x * fGeomScale, y * fGeomScale, z * fGeomScale);
200 fEnergyDeposits->SetMarkerColor(kYellow);
201 fEnergyDeposits->SetMarkerSize(Size_t(radius));
202 fEnergyDeposits->SetMarkerStyle(4);