16#include "G4UImanager.hh"
19bool is3DTextKind(
const std::string& kind) {
20 return kind ==
"3D" || kind ==
"3d" || kind ==
"text" || kind ==
"Text";
23std::string colourToRGB(
const std::string& colour) {
24 if (colour.find(
' ') != std::string::npos) {
return colour; }
25 if (colour ==
"black") {
return "0 0 0"; }
26 if (colour ==
"blue") {
return "0 0 1"; }
27 if (colour ==
"cyan") {
return "0 1 1"; }
28 if (colour ==
"green") {
return "0 1 0"; }
29 if (colour ==
"grey" || colour ==
"gray") {
return "0.9 0.9 0.9"; }
30 if (colour ==
"red") {
return "1 0 0"; }
31 if (colour ==
"yellow") {
return "1 1 0"; }
37 std::vector<std::string> cmds;
39 bool gui = gopts->getSwitch(
"gui");
40 bool use_dawn = gopts->getSwitch(
"useDawn");
48 cmds.emplace_back(
"/vis/scene/create gemc");
52 cmds.emplace_back(
"/vis/open DAWNFILE");
53 cmds.emplace_back(
"/vis/geometry/set/visibility World 0 false");
54 cmds.emplace_back(
"/vis/viewer/set/style surface");
56 if (gui || g4view.driver ==
"TOOLSSG_OFFSCREEN") {
58 std::string openArg = g4view.driver +
" " + g4view.dimension;
59 if (g4view.driver !=
"TOOLSSG_OFFSCREEN") openArg += g4view.position;
60 cmds.emplace_back(
"/vis/open " + openArg);
63 const double toDegrees = 180.0 / M_PI;
68 if (lightThetaValue == 0.0 && lightPhiValue == 0.0) {
69 lightThetaValue = thetaValue;
70 lightPhiValue = phiValue;
74 cmds.emplace_back(
"/vis/viewer/set/autoRefresh false");
76 cmds.emplace_back(
"/vis/viewer/set/viewpointThetaPhi " + std::to_string(thetaValue) +
" " + std::to_string(phiValue));
77 cmds.emplace_back(
"/vis/viewer/set/lightsThetaPhi " + std::to_string(lightThetaValue) +
" " + std::to_string(lightPhiValue));
78 cmds.emplace_back(
"/vis/viewer/set/lineSegmentsPerCircle " + std::to_string(g4view.segsPerCircle));
79 cmds.emplace_back(
"/vis/viewer/set/background " + g4view.background);
80 cmds.emplace_back(
"/vis/viewer/set/numberOfCloudPoints " + std::to_string(g4view.cloudPoints));
82 cmds.emplace_back(
"/vis/viewer/set/autoRefresh true");
89 std::vector<std::string> commands;
92 if (decorations.scale) {
93 commands.emplace_back(
"/vis/scene/add/scale " +
94 std::to_string(decorations.scaleLength) +
" " +
95 decorations.scaleUnit +
" " +
96 decorations.scaleDirection +
" " +
97 colourToRGB(decorations.scaleColor));
99 if (decorations.axes) { commands.emplace_back(
"/vis/scene/add/axes"); }
100 if (decorations.date) {
101 commands.emplace_back(
"/vis/scene/add/date " + std::to_string(decorations.dateSize));
103 if (decorations.logo2D) { commands.emplace_back(
"/vis/scene/add/logo2D"); }
104 if (decorations.logo) { commands.emplace_back(
"/vis/scene/add/logo"); }
105 if (decorations.frame) {
106 commands.emplace_back(
"/vis/set/colour " + decorations.frameColor);
107 commands.emplace_back(
"/vis/set/lineWidth " + std::to_string(decorations.frameLineWidth));
108 commands.emplace_back(
"/vis/scene/add/frame");
109 commands.emplace_back(
"/vis/set/colour");
110 commands.emplace_back(
"/vis/set/lineWidth");
117 std::vector<std::string> commands;
122 for (
const auto &text: text_to_add) {
123 commands.emplace_back(
"/vis/set/textColour " + text.color);
124 if (!text.layout.empty()) {
125 commands.emplace_back(
"/vis/set/textLayout " + text.layout);
128 if (is3DTextKind(text.kind)) {
129 commands.emplace_back(
130 "/vis/scene/add/text " +
131 std::to_string(text.x) +
" " +
132 std::to_string(text.y) +
" " +
133 std::to_string(text.z) +
" " +
135 std::to_string(text.size) +
" " +
136 std::to_string(text.dx) +
" " +
137 std::to_string(text.dy) +
" " +
140 commands.emplace_back(
141 "/vis/scene/add/text2D " +
142 std::to_string(text.x) +
" " +
143 std::to_string(text.y) +
" " +
144 std::to_string(text.size) +
" ! ! " +
148 if (!text.layout.empty()) {
149 commands.emplace_back(
"/vis/set/textLayout left");
153 commands.emplace_back(
"/vis/set/textColour");
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 > addSceneDecorations(const std::shared_ptr< GOptions > &gopts)
Build commands for optional scene decorations such as scale, axes, logos, and frame.
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.
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.
G4Camera getG4Camera(const std::shared_ptr< GOptions > &gopts)
Read the g4camera option node and return a projected G4Camera struct.
G4Decorations getG4Decorations(const std::shared_ptr< GOptions > &gopts)
Read the g4decoration option node and return scene decoration settings.
double getG4Number(const string &v, bool warnIfNotUnit=false)