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 {
11// Read g4view option and return a projected G4View struct.
12G4View getG4View(const std::shared_ptr<GOptions>& gopts) {
13 G4View g4view;
14
15 // Project the YAML-like option node values into strongly-typed fields.
16 g4view.driver = gopts->getOptionMapInNode("g4view", "driver").as<std::string>();
17 g4view.dimension = gopts->getOptionMapInNode("g4view", "dimension").as<std::string>();
18 g4view.position = gopts->getOptionMapInNode("g4view", "position").as<std::string>();
19 g4view.segsPerCircle = gopts->getOptionMapInNode("g4view", "segsPerCircle").as<int>();
20
21 return g4view;
22}
23
24// Read the g4camera option and return a G4Camera struct.
25G4Camera getG4Camera(const std::shared_ptr<GOptions>& gopts) {
26 G4Camera gcamera;
27
28 // Camera angles are stored as strings (often with units), and can be parsed later.
29 gcamera.phi = gopts->getOptionMapInNode("g4camera", "phi").as<std::string>();
30 gcamera.theta = gopts->getOptionMapInNode("g4camera", "theta").as<std::string>();
31
32 return gcamera;
33}
34
35// Read the g4light option and return a G4Light struct.
36G4Light getG4Light(const std::shared_ptr<GOptions>& gopts) {
37 G4Light glight;
38
39 // Light angles are stored as strings (often with units), and can be parsed later.
40 glight.phi = gopts->getOptionMapInNode("g4light", "phi").as<std::string>();
41 glight.theta = gopts->getOptionMapInNode("g4light", "theta").as<std::string>();
42
43 return glight;
44}
45
46// Read the dawn options and return a G4Dawn struct.
47G4Dawn getG4Dawn(const std::shared_ptr<GOptions>& gopts) {
48 G4Dawn gdawn;
49
50 auto phi = gopts->getOptionMapInNode("dawn", "phi").as<std::string>();
51 auto theta = gopts->getOptionMapInNode("dawn", "theta").as<std::string>();
52
53 // Normalize explicit "null" (string) to the “not defined” sentinel used by options.
54 if (phi == "null") phi = goptions::NODFLT;
55 if (theta == "null") theta = goptions::NODFLT;
56
57 gdawn.phi = phi;
58 gdawn.theta = theta;
59
60 return gdawn;
61}
62
63// Define and return the option set for the g4display module.
66
67 // The module also defines options for g4scene helpers (same executable context).
69
70 std::string help;
71
72 // g4view
73 std::vector<GVariable> g4view = {
74 {"driver", std::string(GDEFAULTVIEWERDRIVER), "Geant4 visualization driver. Use TOOLSSG_OFFSCREEN in batch mode. "},
75 {"dimension", std::string(GDEFAULTVIEWERSIZE), "Geant4 viewer dimension"},
76 {"position", std::string(GDEFAULTVIEWERPOS), "Geant4 viewer position"},
77 {"segsPerCircle", GDEFAULTVSEGPERCIRCLE, "Number of segments per circle"}
78 };
79
80 help = "Defines the Geant4 viewer properties: \n ";
81 help += " - screen dimensions \n ";
82 help += " - screen position \n ";
83 help += " - resolution in terms of segments per circle \n \n ";
84 help += " Examples: \n \n ";
85 help += " -g4view=\"[{dimension: 1200x1000}]\"\n";
86 help += " -g4view=\"[{driver: OGL, dimension: 1100x800, position: +200+100, segsPerCircle: 100}]\" \n";
87 help += " -g4view=\"[{driver: TOOLSSG_OFFSCREEN, segsPerCircle: 200}]\" takes a screenshot at the end of each run \n";
88
89 goptions.defineOption("g4view", "Defines the geant4 viewer properties", g4view, help);
90
91 // g4camera
92 std::vector<GVariable> g4camera = {
93 {"phi", "0*deg", "Geant4 camera phi"},
94 {"theta", "0*deg", "Geant4 camera theta"}
95 };
96
97 help = "Defines the geant4 camera view point \n \n ";
98 help += "Example: -g4camera=\"[{phi: 20*deg, theta: 15*deg}]\" \n ";
99
100 goptions.defineOption("g4camera", "Defines the geant4 camera view point", g4camera, help);
101
102 // g4light
103 std::vector<GVariable> g4light = {
104 {"phi", "0*deg", "Geant4 light source phi"},
105 {"theta", "0*deg", "Geant4 light source theta"}
106 };
107
108 help = "Defines the geant4 light source direction \n \n ";
109 help += "Example: -g4light=\"[{phi: 20*deg, theta: 15*deg}]\" \n ";
110
111 goptions.defineOption("g4light", "Defines the geant4 light source direction", g4light, help);
112
113 // dawn
114 help = "Defines the dawn camera view point and take a dawn screenshot \n \n ";
115 help += "Example: -dawn=\"[{phi: 20*deg, theta: 15*deg}]\" \n ";
116
117 std::vector<GVariable> dawn = {
118 {"phi", 30, "dawn phi"},
119 {"theta", 30, "dawn theta"}
120 };
121
122 goptions.defineOption("dawn", "Defines the dawn view point", dawn, help);
123 goptions.defineSwitch("useDawn", "Take a dawn screenshot");
124
125 // scenetext
126 goptions.addGOptions(addSceneTextsOptions());
127
128 return goptions;
129}
130} // 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:36
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.
const std::string NODFLT
Camera angle configuration derived from the g4camera option node.
DAWN view configuration derived from the dawn option node.
Light angle configuration derived from the g4light option node.
Viewer configuration derived from the g4view option node.