g4display
Loading...
Searching...
No Matches
g4SceneProperties.cc
Go to the documentation of this file.
1
8// g4display
9#include "g4SceneProperties.h"
10#include "g4Text.h"
11
12// gemc
13#include "gutilities.h"
14
15// geant4
16#include "G4UImanager.hh"
17
18std::vector<std::string> G4SceneProperties::scene_commands(const std::shared_ptr<GOptions>& gopts) {
19 std::vector<std::string> cmds;
20
21 bool gui = gopts->getSwitch("gui");
22 bool use_dawn = gopts->getSwitch("useDawn");
23
24 // Project options onto simple structs for downstream use.
25 auto g4view = g4display::getG4View(gopts);
26 auto g4camera = g4display::getG4Camera(gopts);
27
28 std::vector<std::string> commands;
29
30 // Create a named scene. Caller is expected to apply these commands to the Geant4 UI manager.
31 cmds.emplace_back("/vis/scene/create gemc");
32
33 if (use_dawn) {
34 // DAWNFILE workflow: open the DAWN viewer and adjust a minimal set of scene properties.
35 cmds.emplace_back("/vis/open DAWNFILE");
36 cmds.emplace_back("/vis/geometry/set/visibility World 0 false");
37 cmds.emplace_back("/vis/viewer/set/style surface");
38 }
39
40 if (gui) {
41 // Open the configured viewer driver with window geometry settings.
42 cmds.emplace_back("/vis/open " + g4view.driver + " " + g4view.dimension + g4view.position);
43
44 // Scene texts: generate and append per configured g4text option.
45 for (const std::string& c : addSceneTexts(gopts)) { commands.emplace_back(c); }
46
47 // Convert configured camera angles to degrees for the Geant4 viewer command.
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(
55 "/vis/viewer/set/viewpointThetaPhi " + std::to_string(thetaValue) + " " + std::to_string(phiValue));
56 cmds.emplace_back("/vis/viewer/set/lineSegmentsPerCircle " + std::to_string(g4view.segsPerCircle));
57 cmds.emplace_back("/vis/viewer/set/autoRefresh true");
58 }
59
60 return cmds;
61}
62
63std::vector<std::string> G4SceneProperties::addSceneTexts(const std::shared_ptr<GOptions>& gopts) {
64 std::vector<std::string> commands;
65
66 std::vector<g4display::G4SceneText> text_to_add = g4display::getSceneTexts(gopts);
67
68 // Map each configured text item into Geant4 text commands.
69 for (const auto& text : text_to_add) {
70 commands.emplace_back("/vis/set/textColour " + text.color);
71
72 std::string position = std::to_string(text.x) + " " + std::to_string(text.y);
73 std::string size = " " + std::to_string(text.size) + " ! ! ";
74
75 if (text.z != GNOT_SPECIFIED_SCENE_TEXT_Z) {
76 // Z specified: treat as 2D text positioned in 3D.
77 position += " " + std::to_string(text.z);
78 commands.emplace_back(
79 std::string("/vis/scene/add/text2D ").append(position).append(size).append(text.text));
80 }
81 else {
82 // Z not specified: treat as normal scene text.
83 commands.emplace_back(std::string("/vis/scene/add/text ").append(position).append(size).append(text.text));
84 }
85
86 // Restore default text color.
87 commands.emplace_back("/vis/set/textColour");
88 }
89
90 return commands;
91}
std::vector< std::string > addSceneTexts(const std::shared_ptr< GOptions > &gopts)
Build commands that insert configured text annotations into the scene.
std::vector< std::string > scene_commands(const std::shared_ptr< GOptions > &gopts)
Build the full command sequence for scene initialization.
Declaration of the G4SceneProperties helper used to initialize Geant4 scene visualization.
Scene text option structures and helpers for the g4display module.
#define GNOT_SPECIFIED_SCENE_TEXT_Z
G4View getG4View(const std::shared_ptr< GOptions > &gopts)
Read the g4view option node and return a projected G4View struct.
vector< G4SceneText > getSceneTexts(const std::shared_ptr< GOptions > &gopts)
Extract scene text entries from the g4text option node.
Definition g4Text.cc:13
G4Camera getG4Camera(const std::shared_ptr< GOptions > &gopts)
Read the g4camera option node and return a projected G4Camera struct.
double getG4Number(const string &v, bool warnIfNotUnit=false)