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 const auto phi = gopts->getOptionMapInNode("dawn", "phi");
75 const auto theta = gopts->getOptionMapInNode("dawn", "theta");
76 if (phi && !phi.IsNull()) gdawn.phi = phi.as<std::string>();
77 if (theta && !theta.IsNull()) gdawn.theta = theta.as<std::string>();
78
79 return gdawn;
80}
81
82G4Decorations getG4Decorations(const std::shared_ptr<GOptions>& gopts) {
83 G4Decorations decorations;
84
85 decorations.scale = getOptionValueOrDefault<bool>(gopts, "g4decoration", "scale", false);
86 decorations.scaleLength = getOptionValueOrDefault<double>(gopts, "g4decoration", "scaleLength", 10.0);
87 decorations.scaleUnit = getOptionValueOrDefault<std::string>(gopts, "g4decoration", "scaleUnit", "mm");
88 decorations.scaleDirection = getOptionValueOrDefault<std::string>(gopts, "g4decoration", "scaleDirection", "z");
89 decorations.scaleColor = getOptionValueOrDefault<std::string>(gopts, "g4decoration", "scaleColor", "0.9 0.9 0.9");
90 decorations.axes = getOptionValueOrDefault<bool>(gopts, "g4decoration", "axes", false);
91 decorations.eventID = getOptionValueOrDefault<bool>(gopts, "g4decoration", "eventID", false);
92 decorations.eventIDSize = getOptionValueOrDefault<int>(gopts, "g4decoration", "eventIDSize", 24);
93 decorations.date = getOptionValueOrDefault<bool>(gopts, "g4decoration", "date", false);
94 decorations.dateSize = getOptionValueOrDefault<int>(gopts, "g4decoration", "dateSize", 24);
95 decorations.logo2D = getOptionValueOrDefault<bool>(gopts, "g4decoration", "logo2D", false);
96 decorations.logo = getOptionValueOrDefault<bool>(gopts, "g4decoration", "logo", false);
97 decorations.frame = getOptionValueOrDefault<bool>(gopts, "g4decoration", "frame", false);
98 decorations.frameColor = getOptionValueOrDefault<std::string>(gopts, "g4decoration", "frameColor", "red");
99 decorations.frameLineWidth = getOptionValueOrDefault<double>(gopts, "g4decoration", "frameLineWidth", 2.0);
100
101 return decorations;
102}
103
104// Define and return the option set for the g4display module.
107
108 // The module also defines options for g4scene helpers (same executable context).
110
111 std::string help;
112
113 // g4view
114 std::vector<GVariable> g4view = {
115 {"driver", std::string(g4display::GDEFAULTVIEWERDRIVER),
116 "Geant4 visualization driver. See the detailed help for driver tradeoffs. "},
117 {"dimension", std::string(g4display::GDEFAULTVIEWERSIZE), "Geant4 viewer dimension"},
118 {"position", std::string(g4display::GDEFAULTVIEWERPOS), "Geant4 viewer position"},
119 {"segsPerCircle", g4display::GDEFAULTVSEGPERCIRCLE, "Number of segments per circle"},
120 {"background", "0 0.07059 0.16863", "Geant4 viewer background color as '<red> <green> <blue>'"},
121 {"cloudPoints", 1000, "Number of points used for cloud volume rendering"}
122 };
123
124 help = "Defines the Geant4 viewer properties: \n ";
125 help += " - screen dimensions \n ";
126 help += " - screen position \n ";
127 help += " - resolution in terms of segments per circle \n \n ";
128 help += " - viewer background color as '<red> <green> <blue>' \n ";
129 help += " - number of cloud points for cloud volume rendering \n \n ";
130 help += "Viewer drivers (interactive-driver availability depends on the Geant4 build and platform):\n";
131 help += " - ASCIITree (ATree): writes the geometry hierarchy as text; headless, but not graphical.\n";
132 help += " - DAWNFILE (DAWNFILE): exports for high-quality DAWN rendering; external DAWN is required.\n";
133 help += " - RayTracer (RT): software ray tracing to JPEG; realistic, but slower and not interactive.\n";
134 help += " - VRML2FILE (VRML2FILE): exports a portable 3D scene for an external VRML viewer.\n";
135 help += " - gMocrenFile (gMocrenFile): exports medical volume data for the specialized gMocren viewer.\n";
136 help += " - TOOLSSG_OFFSCREEN (TSG_OFFSCREEN, TSG_FILE): headless image/vector output for batch jobs.\n";
137 help += " - OpenGLImmediateQt (OGLIQt, OGLI): Qt/OpenGL with low scene memory, but slower redraws.\n";
138 help += " - OpenGLStoredQt (OGLSQt, OGLS): Qt/OpenGL with fast redraw and picking; uses more memory.\n";
139 help += " - OpenGLImmediateX (OGLIX, OGLIQt_FALLBACK): X11/OpenGL immediate mode; requires X.\n";
140 help += " - OpenGLStoredX (OGLSX, OGLSQt_FALLBACK): fast X11/OpenGL redraw; uses more memory.\n";
141 help += " - RayTracerX (RTX): ray-traced JPEG plus an X window; high quality, but slow and X-only.\n";
142 help += " - TOOLSSG_X11_GLES (TSG_X11_GLES, TSGX11, TSG_QT_GLES_FALLBACK): interactive "
143 "X11/GLES; avoids Qt, but requires an X server and GLES support.\n\n";
144 help += " Examples: \n \n ";
145 help += " -g4view=\"[{dimension: 1200x1000}]\"\n";
146 help += " -g4view=\"[{driver: OGL, dimension: 1100x800, position: +200+100, segsPerCircle: 100, background: 0 0.07059 0.16863}]\" \n";
147 help += " -g4view=\"[{driver: TOOLSSG_OFFSCREEN, segsPerCircle: 200, cloudPoints: 3000}]\" takes a screenshot at the end of each run \n";
148
149 goptions.defineOption("g4view", "Defines the geant4 viewer properties", g4view, help);
150
151 // g4camera
152 std::vector<GVariable> g4camera = {
153 {"phi", "0*deg", "Geant4 camera phi"},
154 {"theta", "0*deg", "Geant4 camera theta"}
155 };
156
157 help = "Defines the geant4 camera view point \n \n ";
158 help += "Example: -g4camera=\"[{phi: 20*deg, theta: 15*deg}]\" \n ";
159
160 goptions.defineOption("g4camera", "Defines the geant4 camera view point", g4camera, help);
161
162 // g4light
163 std::vector<GVariable> g4light = {
164 {"phi", "0*deg", "Geant4 light source phi"},
165 {"theta", "0*deg", "Geant4 light source theta"}
166 };
167
168 help = "Defines the geant4 light source direction \n \n ";
169 help += "Example: -g4light=\"[{phi: 20*deg, theta: 15*deg}]\" \n ";
170
171 goptions.defineOption("g4light", "Defines the geant4 light source direction", g4light, help);
172
173 // dawn
174 help = "Defines the dawn camera view point and takes a dawn screenshot \n \n ";
175 help += "Example: -dawn=\"[{phi: 20*deg, theta: 15*deg}]\" \n ";
176
177 std::vector<GVariable> dawn = {
178 {"phi", "30*deg", "dawn camera phi"},
179 {"theta", "30*deg", "dawn camera theta"}
180 };
181
182 goptions.defineOption("dawn", "Defines the dawn view point", dawn, help);
183 goptions.defineSwitch("useDawn", "Take a dawn screenshot");
184
185 // g4decoration
186 std::vector<GVariable> g4decoration = {
187 {"scale", false, "add a simple scale line"},
188 {"scaleLength", 10.0, "scale length"},
189 {"scaleUnit", "mm", "scale length unit"},
190 {"scaleDirection", "z", "scale direction: x, y, or z"},
191 {"scaleColor", "0.9 0.9 0.9", "scale color as 'r g b' or a named color"},
192 {"axes", false, "add simple XYZ axes"},
193 {"eventID", false, "add event ID text at end of event"},
194 {"eventIDSize", 24, "event ID font size in points"},
195 {"date", false, "add a date stamp"},
196 {"dateSize", 24, "date font size in points"},
197 {"logo2D", false, "add the 2D Geant4 logo"},
198 {"logo", false, "add the 3D Geant4 logo"},
199 {"frame", false, "add a frame around the view"},
200 {"frameColor", "red", "frame color"},
201 {"frameLineWidth", 2.0, "frame line width"}
202 };
203
204 help = "Adds optional Geant4 scene decorations. \n \n";
205 help += "Example: -g4decoration=\"[{scale: true, axes: true, eventID: true, date: true, logo2D: true, logo: true, frame: true}]\" \n";
206
207 goptions.defineOption("g4decoration", "Adds optional Geant4 scene decorations", g4decoration, help);
208
209 help = "Display magnetic field lines in the initial visualization scene. \n \n";
210 help += "The value is the number of field-line integration points. Set to 0 to disable. \n \n";
211 help += "Example: -show_field_lines=100 \n";
212 goptions.defineOption(GVariable("show_field_lines", 0, "number of field-line points to display"), help);
213
214 help = "Display auxiliary edges in the initial visualization scene. \n \n";
215 help += "Example: -show_auxiliary_edges=true \n";
216 goptions.defineOption(GVariable("show_auxiliary_edges", false, "show auxiliary volume edges"), help);
217
218 // scenetext
219 goptions.addGOptions(addSceneTextsOptions());
220
221 return goptions;
222}
223} // namespace g4display
Scene text option structures and helpers for the g4display module.
Conventions and constants used by the g4display module.
Option structures and helpers for g4display configuration.
constexpr const char * G4SCENE_LOGGER
constexpr const char * G4DISPLAY_LOGGER
constexpr char GDEFAULTVIEWERSIZE[]
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:42
constexpr int GDEFAULTVSEGPERCIRCLE
constexpr char GDEFAULTVIEWERPOS[]
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.
constexpr char GDEFAULTVIEWERDRIVER[]
G4Decorations getG4Decorations(const std::shared_ptr< GOptions > &gopts)
Read the g4decoration option node and return scene decoration settings.
Camera angle configuration derived from the g4camera option node.
DAWN view configuration derived from the dawn option node.
std::optional< std::string > phi
std::optional< std::string > theta
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.