g4display
Loading...
Searching...
No Matches
g4SceneProperties.cc
Go to the documentation of this file.
1
9// g4display
10#include "g4SceneProperties.h"
11#include "g4Text.h"
12
13// gemc
14#include "gutilities.h"
15
16// geant4
17#include "G4UImanager.hh"
18
19
20
21std::vector<std::string> G4SceneProperties::scene_commands(const std::shared_ptr<GOptions>& gopts) {
22 std::vector<std::string> cmds;
23
24 bool gui = gopts->getSwitch("gui");
25 bool use_dawn = gopts->getSwitch("useDawn");
26
27 // Projecting options onto G4View and G4Camera structs
28 auto g4view = g4display::getG4View(gopts);
29 auto g4camera = g4display::getG4Camera(gopts);
30 // auto g4dawn = g4display::getG4Dawn(gopts);
31
32 std::vector<std::string> commands;
33
34 cmds.emplace_back("/vis/scene/create gemc");
35
36 if (use_dawn) {
37 cmds.emplace_back("/vis/open DAWNFILE");
38 cmds.emplace_back("/vis/geometry/set/visibility World 0 false");
39 cmds.emplace_back("/vis/viewer/set/style surface");
40 }
41
42 if (gui) {
43 cmds.emplace_back("/vis/open " + g4view.driver + " " + g4view.dimension + g4view.position);
44
45 // Scene texts
46 for (const std::string& c : addSceneTexts(gopts)) { commands.emplace_back(c); }
47
48 double toDegrees = 180 / 3.1415;
49 double thetaValue = gutilities::getG4Number(g4camera.theta) * toDegrees;
50 double phiValue = gutilities::getG4Number(g4camera.phi) * toDegrees;
51
52 // Disable auto refresh and quieten vis messages whilst scene and trajectories are established:
53 cmds.emplace_back("/vis/viewer/set/autoRefresh false");
54 cmds.emplace_back("/vis/viewer/set/viewpointThetaPhi " + std::to_string(thetaValue) + " " + std::to_string(phiValue));
55 cmds.emplace_back("/vis/viewer/set/lineSegmentsPerCircle " + std::to_string(g4view.segsPerCircle));
56 cmds.emplace_back("/vis/viewer/set/autoRefresh true");
57 }
58
59
60 return cmds;
61}
62
63
75std::vector<std::string> G4SceneProperties::addSceneTexts(const std::shared_ptr<GOptions>& gopts) {
76 std::vector<std::string> commands;
77
78 std::vector<g4display::G4SceneText> text_to_add = g4display::getSceneTexts(gopts);
79
80 // Iterate over each text object to generate the corresponding visualization commands
81 for (const auto& text : text_to_add) {
82 commands.emplace_back("/vis/set/textColour " + text.color);
83 std::string position = std::to_string(text.x) + " " + std::to_string(text.y);
84 std::string size = " " + std::to_string(text.size) + " ! ! ";
85 if (text.z != GNOT_SPECIFIED_SCENE_TEXT_Z) {
86 position += " " + std::to_string(text.z);
87 commands.emplace_back(std::string("/vis/scene/add/text2D ").append(position).append(size).append(text.text));
88 }
89 else { commands.emplace_back(std::string("/vis/scene/add/text ").append(position).append(size).append(text.text)); }
90
91 commands.emplace_back("/vis/set/textColour");
92 }
93
94 return commands;
95}
std::vector< std::string > addSceneTexts(const std::shared_ptr< GOptions > &gopts)
Generates a vector of scene text commands.
std::vector< std::string > scene_commands(const std::shared_ptr< GOptions > &gopts)
#define GNOT_SPECIFIED_SCENE_TEXT_Z
G4View getG4View(const std::shared_ptr< GOptions > &gopts)
vector< G4SceneText > getSceneTexts(const std::shared_ptr< GOptions > &gopts)
Definition g4Text.cc:11
G4Camera getG4Camera(const std::shared_ptr< GOptions > &gopts)