g4display
Loading...
Searching...
No Matches
g4display_options.cc
Go to the documentation of this file.
1// g4display_options.cc
2//
3// Implementation of g4display option projection and option schema definition.
4// Doxygen documentation for public behavior is authoritative in g4display_options.h (see rule 7).
5
6#include "g4display_options.h"
8#include "g4Text.h"
9
10namespace g4display {
11namespace {
12YAML::Node getG4ViewValue(const std::shared_ptr<GOptions>& gopts, const std::string& key) {
13 auto node = gopts->getOptionNode("g4view");
14 if (node.IsMap() && node[key]) {
15 return node[key];
16 }
17 return gopts->getOptionMapInNode("g4view", key);
18}
19
20template<typename T>
21T getOptionValueOrDefault(const std::shared_ptr<GOptions>& gopts,
22 const std::string& option,
23 const std::string& key,
24 const T& defaultValue) {
25 auto node = gopts->getOptionNode(option);
26 if (node.IsMap()) {
27 return gopts->get_variable_in_option<T>(node, key, defaultValue);
28 }
29 return gopts->getOptionMapInNode(option, key).as<T>();
30}
31}
32
33// Read g4view option and return a projected G4View struct.
34G4View getG4View(const std::shared_ptr<GOptions>& gopts) {
35 G4View g4view;
36
37 // Project the YAML-like option node values into strongly-typed fields.
38 g4view.driver = getG4ViewValue(gopts, "driver").as<std::string>();
39 g4view.dimension = getG4ViewValue(gopts, "dimension").as<std::string>();
40 g4view.position = getG4ViewValue(gopts, "position").as<std::string>();
41 g4view.segsPerCircle = getG4ViewValue(gopts, "segsPerCircle").as<int>();
42 g4view.background = getG4ViewValue(gopts, "background").as<std::string>();
43 g4view.cloudPoints = getG4ViewValue(gopts, "cloudPoints").as<int>();
44
45 return g4view;
46}
47
48// Read the g4camera option and return a G4Camera struct.
49G4Camera getG4Camera(const std::shared_ptr<GOptions>& gopts) {
50 G4Camera gcamera;
51
52 // Camera angles are stored as strings (often with units), and can be parsed later.
53 gcamera.phi = gopts->getOptionMapInNode("g4camera", "phi").as<std::string>();
54 gcamera.theta = gopts->getOptionMapInNode("g4camera", "theta").as<std::string>();
55
56 return gcamera;
57}
58
59// Read the g4light option and return a G4Light struct.
60G4Light getG4Light(const std::shared_ptr<GOptions>& gopts) {
61 G4Light glight;
62
63 // Light angles are stored as strings (often with units), and can be parsed later.
64 glight.phi = gopts->getOptionMapInNode("g4light", "phi").as<std::string>();
65 glight.theta = gopts->getOptionMapInNode("g4light", "theta").as<std::string>();
66
67 return glight;
68}
69
70// Read the dawn options and return a G4Dawn struct.
71G4Dawn getG4Dawn(const std::shared_ptr<GOptions>& gopts) {
72 G4Dawn gdawn;
73
74 auto phi = gopts->getOptionMapInNode("dawn", "phi").as<std::string>();
75 auto theta = gopts->getOptionMapInNode("dawn", "theta").as<std::string>();
76
77 // Normalize explicit "null" (string) to the “not defined” sentinel used by options.
78 if (phi == "null") phi = goptions::NODFLT;
79 if (theta == "null") theta = goptions::NODFLT;
80
81 gdawn.phi = phi;
82 gdawn.theta = theta;
83
84 return gdawn;
85}
86
87G4Decorations getG4Decorations(const std::shared_ptr<GOptions>& gopts) {
88 G4Decorations decorations;
89
90 decorations.scale = getOptionValueOrDefault<bool>(gopts, "g4decoration", "scale", false);
91 decorations.scaleLength = getOptionValueOrDefault<double>(gopts, "g4decoration", "scaleLength", 10.0);
92 decorations.scaleUnit = getOptionValueOrDefault<std::string>(gopts, "g4decoration", "scaleUnit", "mm");
93 decorations.scaleDirection = getOptionValueOrDefault<std::string>(gopts, "g4decoration", "scaleDirection", "z");
94 decorations.scaleColor = getOptionValueOrDefault<std::string>(gopts, "g4decoration", "scaleColor", "0.9 0.9 0.9");
95 decorations.axes = getOptionValueOrDefault<bool>(gopts, "g4decoration", "axes", false);
96 decorations.eventID = getOptionValueOrDefault<bool>(gopts, "g4decoration", "eventID", false);
97 decorations.eventIDSize = getOptionValueOrDefault<int>(gopts, "g4decoration", "eventIDSize", 24);
98 decorations.date = getOptionValueOrDefault<bool>(gopts, "g4decoration", "date", false);
99 decorations.dateSize = getOptionValueOrDefault<int>(gopts, "g4decoration", "dateSize", 24);
100 decorations.logo2D = getOptionValueOrDefault<bool>(gopts, "g4decoration", "logo2D", false);
101 decorations.logo = getOptionValueOrDefault<bool>(gopts, "g4decoration", "logo", false);
102 decorations.frame = getOptionValueOrDefault<bool>(gopts, "g4decoration", "frame", false);
103 decorations.frameColor = getOptionValueOrDefault<std::string>(gopts, "g4decoration", "frameColor", "red");
104 decorations.frameLineWidth = getOptionValueOrDefault<double>(gopts, "g4decoration", "frameLineWidth", 2.0);
105
106 return decorations;
107}
108
109// Define and return the option set for the g4display module.
112
113 // The module also defines options for g4scene helpers (same executable context).
115
116 std::string help;
117
118 // g4view
119 std::vector<GVariable> g4view = {
120 {"driver", std::string(GDEFAULTVIEWERDRIVER), "Geant4 visualization driver. Use TOOLSSG_OFFSCREEN in batch mode. "},
121 {"dimension", std::string(GDEFAULTVIEWERSIZE), "Geant4 viewer dimension"},
122 {"position", std::string(GDEFAULTVIEWERPOS), "Geant4 viewer position"},
123 {"segsPerCircle", GDEFAULTVSEGPERCIRCLE, "Number of segments per circle"},
124 {"background", "0 0.07059 0.16863", "Geant4 viewer background color as '<red> <green> <blue>'"},
125 {"cloudPoints", 1000, "Number of points used for cloud volume rendering"}
126 };
127
128 help = "Defines the Geant4 viewer properties: \n ";
129 help += " - screen dimensions \n ";
130 help += " - screen position \n ";
131 help += " - resolution in terms of segments per circle \n \n ";
132 help += " - viewer background color as '<red> <green> <blue>' \n ";
133 help += " - number of cloud points for cloud volume rendering \n \n ";
134 help += " Examples: \n \n ";
135 help += " -g4view=\"[{dimension: 1200x1000}]\"\n";
136 help += " -g4view=\"[{driver: OGL, dimension: 1100x800, position: +200+100, segsPerCircle: 100, background: 0 0.07059 0.16863}]\" \n";
137 help += " -g4view=\"[{driver: TOOLSSG_OFFSCREEN, segsPerCircle: 200, cloudPoints: 3000}]\" takes a screenshot at the end of each run \n";
138
139 goptions.defineOption("g4view", "Defines the geant4 viewer properties", g4view, help);
140
141 // g4camera
142 std::vector<GVariable> g4camera = {
143 {"phi", "0*deg", "Geant4 camera phi"},
144 {"theta", "0*deg", "Geant4 camera theta"}
145 };
146
147 help = "Defines the geant4 camera view point \n \n ";
148 help += "Example: -g4camera=\"[{phi: 20*deg, theta: 15*deg}]\" \n ";
149
150 goptions.defineOption("g4camera", "Defines the geant4 camera view point", g4camera, help);
151
152 // g4light
153 std::vector<GVariable> g4light = {
154 {"phi", "0*deg", "Geant4 light source phi"},
155 {"theta", "0*deg", "Geant4 light source theta"}
156 };
157
158 help = "Defines the geant4 light source direction \n \n ";
159 help += "Example: -g4light=\"[{phi: 20*deg, theta: 15*deg}]\" \n ";
160
161 goptions.defineOption("g4light", "Defines the geant4 light source direction", g4light, help);
162
163 // dawn
164 help = "Defines the dawn camera view point and takes a dawn screenshot \n \n ";
165 help += "Example: -dawn=\"[{phi: 20*deg, theta: 15*deg}]\" \n ";
166
167 std::vector<GVariable> dawn = {
168 {"phi", "30*deg", "dawn camera phi"},
169 {"theta", "30*deg", "dawn camera theta"}
170 };
171
172 goptions.defineOption("dawn", "Defines the dawn view point", dawn, help);
173 goptions.defineSwitch("useDawn", "Take a dawn screenshot");
174
175 // g4decoration
176 std::vector<GVariable> g4decoration = {
177 {"scale", false, "add a simple scale line"},
178 {"scaleLength", 10.0, "scale length"},
179 {"scaleUnit", "mm", "scale length unit"},
180 {"scaleDirection", "z", "scale direction: x, y, or z"},
181 {"scaleColor", "0.9 0.9 0.9", "scale color as 'r g b' or a named color"},
182 {"axes", false, "add simple XYZ axes"},
183 {"eventID", false, "add event ID text at end of event"},
184 {"eventIDSize", 24, "event ID font size in points"},
185 {"date", false, "add a date stamp"},
186 {"dateSize", 24, "date font size in points"},
187 {"logo2D", false, "add the 2D Geant4 logo"},
188 {"logo", false, "add the 3D Geant4 logo"},
189 {"frame", false, "add a frame around the view"},
190 {"frameColor", "red", "frame color"},
191 {"frameLineWidth", 2.0, "frame line width"}
192 };
193
194 help = "Adds optional Geant4 scene decorations. \n \n";
195 help += "Example: -g4decoration=\"[{scale: true, axes: true, eventID: true, date: true, logo2D: true, logo: true, frame: true}]\" \n";
196
197 goptions.defineOption("g4decoration", "Adds optional Geant4 scene decorations", g4decoration, help);
198
199 // scenetext
200 goptions.addGOptions(addSceneTextsOptions());
201
202 return goptions;
203}
204} // namespace g4display
Scene text option structures and helpers for the g4display module.
Conventions and constants used by the g4display module.
#define GDEFAULTVIEWERDRIVER
#define GDEFAULTVSEGPERCIRCLE
#define GDEFAULTVIEWERPOS
#define GDEFAULTVIEWERSIZE
Option structures and helpers for g4display configuration.
constexpr const char * G4SCENE_LOGGER
constexpr const char * G4DISPLAY_LOGGER
G4Light getG4Light(const std::shared_ptr< GOptions > &gopts)
Read the g4light option node and return a projected G4Light struct.
G4Dawn getG4Dawn(const std::shared_ptr< GOptions > &gopts)
Read the dawn option node and return a projected G4Dawn struct.
G4View getG4View(const std::shared_ptr< GOptions > &gopts)
Read the g4view option node and return a projected G4View struct.
GOptions addSceneTextsOptions()
Define the g4text structured option schema.
Definition g4Text.cc:43
GOptions defineOptions()
Define the full set of g4display options.
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.
const std::string NODFLT
Camera angle configuration derived from the g4camera option node.
DAWN view configuration derived from the dawn option node.
Optional scene decorations derived from the g4decoration option node.
Light angle configuration derived from the g4light option node.
Viewer configuration derived from the g4view option node.