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 auto g4light = g4display::getG4Light(gopts);
28
29 std::vector<std::string> commands;
30
31 // Create a named scene. Caller is expected to apply these commands to the Geant4 UI manager.
32 cmds.emplace_back("/vis/scene/create gemc");
33
34 if (use_dawn) {
35 // DAWNFILE workflow: open the DAWN viewer and adjust a minimal set of scene properties.
36 cmds.emplace_back("/vis/open DAWNFILE");
37 cmds.emplace_back("/vis/geometry/set/visibility World 0 false");
38 cmds.emplace_back("/vis/viewer/set/style surface");
39 }
40 if (gui || g4view.driver == "TOOLSSG_OFFSCREEN") {
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 double lightThetaValue = gutilities::getG4Number(g4light.theta) * toDegrees;
52 double lightPhiValue = gutilities::getG4Number(g4light.phi) * toDegrees;
53
54 // Disable auto refresh and quieten vis messages whilst scene and trajectories are established.
55 cmds.emplace_back("/vis/viewer/set/autoRefresh false");
56
57 cmds.emplace_back("/vis/viewer/set/viewpointThetaPhi " + std::to_string(thetaValue) + " " + std::to_string(phiValue));
58 cmds.emplace_back("/vis/viewer/set/lightsThetaPhi " + std::to_string(lightThetaValue) + " " + std::to_string(lightPhiValue));
59 cmds.emplace_back("/vis/viewer/set/lineSegmentsPerCircle " + std::to_string(g4view.segsPerCircle));
60
61 cmds.emplace_back("/vis/viewer/set/autoRefresh true");
62 }
63
64 return cmds;
65}
66
67std::vector<std::string> G4SceneProperties::addSceneTexts(const std::shared_ptr<GOptions> &gopts) {
68 std::vector<std::string> commands;
69
70 std::vector<g4display::G4SceneText> text_to_add = g4display::getSceneTexts(gopts);
71
72 // Map each configured text item into Geant4 text commands.
73 for (const auto &text: text_to_add) {
74 commands.emplace_back("/vis/set/textColour " + text.color);
75
76 std::string position = std::to_string(text.x) + " " + std::to_string(text.y);
77 std::string size = " " + std::to_string(text.size) + " ! ! ";
78
79 if (text.z != GNOT_SPECIFIED_SCENE_TEXT_Z) {
80 // Z specified: treat as 2D text positioned in 3D.
81 position += " " + std::to_string(text.z);
82 commands.emplace_back(
83 std::string("/vis/scene/add/text2D ").append(position).append(size).append(text.text));
84 } else {
85 // Z not specified: treat as normal scene text.
86 commands.emplace_back(std::string("/vis/scene/add/text ").append(position).append(size).append(text.text));
87 }
88
89 // Restore default text color.
90 commands.emplace_back("/vis/set/textColour");
91 }
92
93 return commands;
94}
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
G4Light getG4Light(const std::shared_ptr< GOptions > &gopts)
Read the g4light option node and return a projected G4Light struct.
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)