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 dawn options and return a G4Dawn struct.
36G4Dawn getG4Dawn(const std::shared_ptr<GOptions>& gopts) {
37 G4Dawn gdawn;
38
39 auto phi = gopts->getOptionMapInNode("dawn", "phi").as<std::string>();
40 auto theta = gopts->getOptionMapInNode("dawn", "theta").as<std::string>();
41
42 // Normalize explicit "null" (string) to the “not defined” sentinel used by options.
43 if (phi == "null") phi = goptions::NODFLT;
44 if (theta == "null") theta = goptions::NODFLT;
45
46 gdawn.phi = phi;
47 gdawn.theta = theta;
48
49 return gdawn;
50}
51
52// Define and return the option set for the g4display module.
55
56 // The module also defines options for g4scene helpers (same executable context).
58
59 std::string help;
60
61 // g4view
62 std::vector<GVariable> g4view = {
63 {"driver", std::string(GDEFAULTVIEWERDRIVER), "Geant4 vis driver"},
64 {"dimension", std::string(GDEFAULTVIEWERSIZE), "g4 viewer dimension"},
65 {"position", std::string(GDEFAULTVIEWERPOS), "g4 viewer position"},
66 {"segsPerCircle", GDEFAULTVSEGPERCIRCLE, "Number of segments per circle"}
67 };
68
69 help = "Defines the geant4 viewer properties: \n ";
70 help += " - screen dimensions \n ";
71 help += " - screen position \n ";
72 help += " - resolution in terms of segments per circle \n ";
73 help +=
74 " Example: -g4view={viewer: \"OGL\", dimension: \"1100x800\", position: \"+200+100\", segsPerCircle: 100} \n \n";
75 help += "-g4view=\"[{dimensions: 1200x1000}]\"\n";
76
77 goptions.defineOption("g4view", "Defines the geant4 viewer properties", g4view, help);
78
79 // g4camera
80 std::vector<GVariable> g4camera = {
81 {"phi", "0*deg", "geant4 camera phi"},
82 {"theta", "0*deg", "geant4 camera theta"}
83 };
84
85 help = "Defines the geant4 camera view point \n \n ";
86 help += "Example: -g4camera=\"[{phi: 20*deg, theta: 15*deg}]\" \n ";
87
88 goptions.defineOption("g4camera", "Defines the geant4 camera view point", g4camera, help);
89
90 // dawn
91 help = "Defines the dawn camera view point and take a dawn screenshot \n \n ";
92 help += "Example: -dawn=\"[{phi: 20*deg, theta: 15*deg}]\" \n ";
93
94 std::vector<GVariable> dawn = {
95 {"phi", 30, "dawn phi"},
96 {"theta", 30, "dawn theta"}
97 };
98
99 goptions.defineOption("dawn", "Defines the dawn view point", dawn, help);
100 goptions.defineSwitch("useDawn", "Take a dawn screenshot");
101
102 // scenetext
103 goptions.addGOptions(addSceneTextsOptions());
104
105 return goptions;
106}
107} // 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
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.
Viewer configuration derived from the g4view option node.