44 if (fpInstance ==
nullptr) fpInstance =
new G4VtkMessenger;
48G4VtkMessenger::G4VtkMessenger()
57 fpCommandClearNonG4 =
new G4UIcommand(
"/vis/vtk/clearNonG4",
this);
58 fpCommandClearNonG4->
SetGuidance(
"Clear non G4 objects from visualisation (image/3d overlays");
61 fpCommandExport =
new G4UIcommand(
"/vis/vtk/export",
this);
62 fpCommandExport->
SetGuidance(
"Export a screenshot or OBJ file of current Vtk viewer");
65 auto parameterExport =
new G4UIparameter(
"format",
's', omitable =
false);
66 fpCommandExport->
SetGuidance(
"File type (jpg,tiff,eps,ps,obj,vtp,gltf,vrml,x3d)");
70 parameterExport =
new G4UIparameter(
"file-name",
's', omitable =
false);
75 fpCommandExportCutter =
new G4UIcommand(
"/vis/vtk/exportCutter",
this);
76 fpCommandExportCutter->
SetGuidance(
"Export a VTP file of the cutters if they exist");
79 auto parameterExportCutter =
new G4UIparameter(
"file-name",
's', omitable =
true);
80 parameterExportCutter->SetGuidance(
"File name");
81 parameterExportCutter->SetDefaultValue(
"cutter.vtp");
82 fpCommandExportCutter->
SetParameter(parameterExportCutter);
85 fpCommandDebugPrint =
new G4UIcommand(
"/vis/vtk/printDebug",
this);
86 fpCommandDebugPrint->
SetGuidance(
"Debug print of pipelines");
89 fpCommandInteractorStart =
new G4UIcommand(
"/vis/vtk/startInteraction",
this);
90 fpCommandInteractorStart->
SetGuidance(
"Start VtkNative window interaction");
94 fpDirectorySet->
SetGuidance(
"G4VtkViewer set commands");
99 fpCommandWarnings->
SetGuidance(
"Enable (True) or disable (False) VTK warnings");
103 fpCommandHUD->
SetGuidance(
"Enable or disable HUD for VTK");
106 fpCameraOrientation =
new G4UIcmdWithABool(
"/vis/vtk/set/orientation",
this);
107 fpCameraOrientation->
SetGuidance(
"Enable or disable camera orientation widget");
110 fpCommandClipper =
new G4UIcommand(
"/vis/vtk/set/clipper",
this);
111 fpCommandClipper->
SetGuidance(
"Enable a cutaway plane (clipper) in VTK");
112 auto fpCommandClipperParam =
new G4UIparameter(
"widget",
'b', omitable =
true);
113 fpCommandClipperParam->SetDefaultValue(1);
117 fpCommandCutter =
new G4UIcommand(
"/vis/vtk/set/cutter",
this);
118 fpCommandCutter->
SetGuidance(
"Enable a section plane (cutter) in VTK");
119 auto fpCommandCutterParam =
new G4UIparameter(
"widget",
'b', omitable =
true);
120 fpCommandCutterParam->SetDefaultValue(1);
124 auto fpCommandPolyhedronPipelineParam =
new G4UIparameter(
"format",
's', omitable =
true);
125 fpCommandPolyhedronPipeline =
new G4UIcommand(
"/vis/vtk/set/polyhedronPipeline",
this);
126 fpCommandPolyhedronPipeline->
SetGuidance(
"Select type of polyhedron pipeline");
127 fpCommandPolyhedronPipeline->
SetGuidance(
"Type (separate, tensor, append, bake)");
128 fpCommandPolyhedronPipeline->
SetParameter(fpCommandPolyhedronPipelineParam);
131 fpCommandShadow =
new G4UIcommand(
"/vis/vtk/set/shadows",
this);
132 fpCommandShadow->
SetGuidance(
"Enable/disable shadows in VTK");
133 auto fpCommandShadowParam =
new G4UIparameter(
"enable",
'b', omitable =
true);
134 fpCommandShadowParam->SetDefaultValue(1);
139 fpDirectoryAdd->
SetGuidance(
"G4VtkViewer add commands");
141 fpCommandImageOverlay =
new G4UIcommand(
"/vis/vtk/add/imageOverlay",
this);
142 auto parameterImageOverlay =
new G4UIparameter(
"filename",
's', omitable =
false);
143 parameterImageOverlay->SetGuidance(
"Image file name ");
144 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
146 parameterImageOverlay =
new G4UIparameter(
"imageBottomLeftX",
'd', omitable =
false);
147 parameterImageOverlay->SetGuidance(
"image bottom left x");
148 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
150 parameterImageOverlay =
new G4UIparameter(
"imageBottomLeftY",
'd', omitable =
false);
151 parameterImageOverlay->SetGuidance(
"image bottom left y");
152 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
154 parameterImageOverlay =
new G4UIparameter(
"imageTopRightX",
'd', omitable =
false);
155 parameterImageOverlay->SetGuidance(
"image top right x");
156 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
158 parameterImageOverlay =
new G4UIparameter(
"imageTopRightY",
'd', omitable =
false);
159 parameterImageOverlay->SetGuidance(
"image top right y");
160 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
162 parameterImageOverlay =
new G4UIparameter(
"worldBottomLeftX",
'd', omitable =
false);
163 parameterImageOverlay->SetGuidance(
"world bottom left x");
164 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
166 parameterImageOverlay =
new G4UIparameter(
"worldBottomLeftY",
'd', omitable =
false);
167 parameterImageOverlay->SetGuidance(
"world bottom left y");
168 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
170 parameterImageOverlay =
new G4UIparameter(
"worldTopRightX",
'd', omitable =
false);
171 parameterImageOverlay->SetGuidance(
"world top right x");
172 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
174 parameterImageOverlay =
new G4UIparameter(
"worldTopRightY",
'd', omitable =
false);
175 parameterImageOverlay->SetGuidance(
"world top right y");
176 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
178 parameterImageOverlay =
new G4UIparameter(
"xRotation",
'd', omitable =
true);
179 parameterImageOverlay->SetGuidance(
"rotation in x");
180 parameterImageOverlay->SetDefaultValue(0.0);
181 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
183 parameterImageOverlay =
new G4UIparameter(
"yRotation",
'd', omitable =
true);
184 parameterImageOverlay->SetGuidance(
"rotation in y");
185 parameterImageOverlay->SetDefaultValue(0.0);
186 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
188 parameterImageOverlay =
new G4UIparameter(
"zRotation",
'd', omitable =
true);
189 parameterImageOverlay->SetGuidance(
"rotation in z");
190 parameterImageOverlay->SetDefaultValue(0.0);
191 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
193 parameterImageOverlay =
new G4UIparameter(
"xTranslation",
'd', omitable =
true);
194 parameterImageOverlay->SetGuidance(
"translation in x");
195 parameterImageOverlay->SetDefaultValue(0.0);
196 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
198 parameterImageOverlay =
new G4UIparameter(
"yTranslation",
'd', omitable =
true);
199 parameterImageOverlay->SetGuidance(
"translation in y");
200 parameterImageOverlay->SetDefaultValue(0.0);
201 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
203 parameterImageOverlay =
new G4UIparameter(
"zTranslation",
'd', omitable =
true);
204 parameterImageOverlay->SetGuidance(
"translation in z");
205 parameterImageOverlay->SetDefaultValue(0.0);
206 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
208 parameterImageOverlay =
new G4UIparameter(
"alpha",
'd', omitable =
true);
209 parameterImageOverlay->SetGuidance(
"alpha");
210 parameterImageOverlay->SetDefaultValue(0.5);
211 fpCommandImageOverlay->
SetParameter(parameterImageOverlay);
213 fpCommandGeometryOverlay =
new G4UIcommand(
"/vis/vtk/add/geometryOverlay",
this);
214 auto parameterGeometryOverlay =
new G4UIparameter(
"filename",
's', omitable =
false);
215 parameterGeometryOverlay->SetGuidance(
"Geometry file name ");
216 fpCommandGeometryOverlay->
SetParameter(parameterGeometryOverlay);
218 parameterGeometryOverlay =
new G4UIparameter(
"xScale",
'd', omitable =
true);
219 parameterGeometryOverlay->SetGuidance(
"scale in x");
220 parameterGeometryOverlay->SetDefaultValue(0.0);
221 fpCommandGeometryOverlay->
SetParameter(parameterGeometryOverlay);
223 parameterGeometryOverlay =
new G4UIparameter(
"yScale",
'd', omitable =
true);
224 parameterGeometryOverlay->SetGuidance(
"scale in y");
225 parameterGeometryOverlay->SetDefaultValue(0.0);
226 fpCommandGeometryOverlay->
SetParameter(parameterGeometryOverlay);
228 parameterGeometryOverlay =
new G4UIparameter(
"zScale",
'd', omitable =
true);
229 parameterGeometryOverlay->SetGuidance(
"scale in z");
230 parameterGeometryOverlay->SetDefaultValue(0.0);
231 fpCommandGeometryOverlay->
SetParameter(parameterGeometryOverlay);
233 parameterGeometryOverlay =
new G4UIparameter(
"xRotation",
'd', omitable =
true);
234 parameterGeometryOverlay->SetGuidance(
"rotation in x");
235 parameterGeometryOverlay->SetDefaultValue(0.0);
236 fpCommandGeometryOverlay->
SetParameter(parameterGeometryOverlay);
238 parameterGeometryOverlay =
new G4UIparameter(
"yRotation",
'd', omitable =
true);
239 parameterGeometryOverlay->SetGuidance(
"rotation in y");
240 parameterGeometryOverlay->SetDefaultValue(0.0);
241 fpCommandGeometryOverlay->
SetParameter(parameterGeometryOverlay);
243 parameterGeometryOverlay =
new G4UIparameter(
"zRotation",
'd', omitable =
true);
244 parameterGeometryOverlay->SetGuidance(
"rotation in z");
245 parameterGeometryOverlay->SetDefaultValue(0.0);
246 fpCommandGeometryOverlay->
SetParameter(parameterGeometryOverlay);
248 parameterGeometryOverlay =
new G4UIparameter(
"xTranslation",
'd', omitable =
true);
249 parameterGeometryOverlay->SetGuidance(
"translation in x");
250 parameterGeometryOverlay->SetDefaultValue(0.0);
251 fpCommandGeometryOverlay->
SetParameter(parameterGeometryOverlay);
253 parameterGeometryOverlay =
new G4UIparameter(
"yTranslation",
'd', omitable =
true);
254 parameterGeometryOverlay->SetGuidance(
"translation in y");
255 parameterGeometryOverlay->SetDefaultValue(0.0);
256 fpCommandGeometryOverlay->
SetParameter(parameterGeometryOverlay);
258 parameterGeometryOverlay =
new G4UIparameter(
"zTranslation",
'd', omitable =
true);
259 parameterGeometryOverlay->SetGuidance(
"translation in z");
260 parameterGeometryOverlay->SetDefaultValue(0.0);
261 fpCommandGeometryOverlay->
SetParameter(parameterGeometryOverlay);
263 parameterGeometryOverlay =
new G4UIparameter(
"alpha",
'd', omitable =
true);
264 parameterGeometryOverlay->SetGuidance(
"alpha");
265 parameterGeometryOverlay->SetDefaultValue(0.5);
266 fpCommandGeometryOverlay->
SetParameter(parameterGeometryOverlay);
268 parameterGeometryOverlay =
new G4UIparameter(
"representation",
's', omitable =
true);
269 parameterGeometryOverlay->SetGuidance(
"representation of mesh");
270 parameterGeometryOverlay->SetDefaultValue(
"s");
271 fpCommandGeometryOverlay->
SetParameter(parameterGeometryOverlay);
277 delete fpDirectorySet;
278 delete fpDirectoryAdd;
279 delete fpCommandExport;
280 delete fpCommandExportCutter;
281 delete fpCommandWarnings;
282 delete fpCommandDebugPrint;
283 delete fpCommandPolyhedronPipeline;
284 delete fpCommandImageOverlay;
285 delete fpCommandGeometryOverlay;
298 if (pViewer ==
nullptr) {
299 G4cout <<
"G4VtkMessenger::SetNewValue: No current viewer.\n"
300 <<
"\"/vis/open\", or similar, to get one." <<
G4endl;
304 auto* pVtkViewer =
dynamic_cast<G4VtkViewer*
>(pViewer);
305 if (pVtkViewer ==
nullptr) {
306 G4cout <<
"G4VtkMessenger::SetNewValue: Current viewer is not of type VTK. \n"
307 <<
"(It is \"" << pViewer->
GetName() <<
"\".)\n"
308 <<
"Use \"/vis/viewer/select\" or \"/vis/open\"." <<
G4endl;
312 if (command == fpCommandClearNonG4) {
318 else if (command == fpCommandExport) {
321 std::istringstream iss(newValue);
322 iss >> format >> name;
324 if (format ==
"jpg" || format ==
"tiff" || format ==
"png" || format ==
"bmp" || format ==
"pnm"
326 pVtkViewer->ExportScreenShot(name, format);
327 else if (format ==
"obj")
328 pVtkViewer->ExportOBJScene(name);
329 else if (format ==
"vrml")
330 pVtkViewer->ExportVRMLScene(name);
331 else if (format ==
"vtp")
332 pVtkViewer->ExportVTPScene(name);
333 else if (format ==
"gltf")
334 pVtkViewer->ExportGLTFScene(name);
335 else if (format ==
"x3d")
336 pVtkViewer->ExportX3DScene(name);
338 G4cout <<
"Unknown /vis/vtk/export file format" <<
G4endl;
340 else if (command == fpCommandExportCutter) {
341 std::istringstream iss(newValue);
345 pVtkViewer->ExportVTPCutter(fileName);
347 else if (command == fpCommandWarnings) {
349 vtkObject::GlobalWarningDisplayOn();
352 vtkObject::GlobalWarningDisplayOff();
355 else if (command == fpCommandHUD) {
357 pVtkViewer->EnableHUD();
360 pVtkViewer->DisableHUD();
363 else if (command == fpCameraOrientation) {
366 pVtkViewer->EnableCameraOrientationWidget();
369 pVtkViewer->DisableCameraOrientationWidget();
372 else if (command == fpCommandDebugPrint) {
375 else if (command == fpCommandPolyhedronPipeline) {
378 std::istringstream iss(newValue);
383 pVtkViewer->SetPolyhedronPipeline(pipelineType);
385 else if (command == fpCommandImageOverlay) {
389 G4double imageBottomLeft[2] = {0, 0};
391 G4double worldBottomLeft[2] = {0, 0};
394 G4double translation[3] = {0, 0, 0};
397 std::istringstream iss(newValue);
399 iss >> fileName >> imageBottomLeft[0] >> imageBottomLeft[1] >> imageTopRight[0]
400 >> imageTopRight[1] >> worldBottomLeft[0] >> worldBottomLeft[1] >> worldTopRight[0]
401 >> worldTopRight[1] >> rotation[0] >> rotation[1] >> rotation[2] >> translation[0]
402 >> translation[1] >> translation[2] >> alpha;
404 pVtkViewer->AddImageOverlay(fileName, alpha, imageBottomLeft, worldBottomLeft, imageTopRight,
405 worldTopRight, rotation, translation);
407 else if (command == fpCommandGeometryOverlay) {
414 G4double colour[3] = {0.5, 0.5, 0.5};
418 std::istringstream iss(newValue);
421 >> scale[0] >> scale[1] >> scale[2]
422 >> rotation[0] >> rotation[1] >> rotation[2]
423 >> translation[0] >> translation[1] >> translation[2]
424 >> alpha >> representation;
427 pVtkViewer->AddGeometryOverlay(fileName, colour, alpha, representation,
428 scale, rotation, translation);
432 else if (command == fpCommandClipper) {
433 pVtkViewer->EnableClipper(
G4Plane3D(),
true);
435 else if (command == fpCommandCutter) {
436 pVtkViewer->EnableCutter(
G4Plane3D(),
true);
438 else if (command == fpCommandShadow) {
439 pVtkViewer->EnableShadows();
441 else if (command == fpCommandInteractorStart) {
442 pVtkViewer->StartInteractor();
HepGeom::Plane3D< G4double > G4Plane3D
G4GLOB_DLL std::ostream G4cout
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
void SetGuidance(const char *aGuidance)
static G4bool ConvertToBool(const char *st)
const G4String & GetName() const
G4VSceneHandler * GetSceneHandler() const
G4VViewer * GetCurrentViewer() const
static G4VisManager * GetInstance()
G4String GetCurrentValue(G4UIcommand *command) override
~G4VtkMessenger() override
static G4VtkMessenger * GetInstance()
void SetNewValue(G4UIcommand *command, G4String newValue) override
G4VtkStore & GetTransientStore()