Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VtkMessenger Class Reference

#include <G4VtkMessenger.hh>

+ Inheritance diagram for G4VtkMessenger:

Public Member Functions

 ~G4VtkMessenger () override
 
G4String GetCurrentValue (G4UIcommand *command) override
 
void SetNewValue (G4UIcommand *command, G4String newValue) override
 
- Public Member Functions inherited from G4UImessenger
 G4UImessenger ()=default
 
 G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
G4bool CommandsShouldBeInMaster () const
 

Static Public Member Functions

static G4VtkMessengerGetInstance ()
 

Additional Inherited Members

- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String LtoS (G4long l)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (const G4String &s)
 
G4long StoL (const G4String &s)
 
G4double StoD (const G4String &s)
 
G4bool StoB (G4String s)
 
void AddUIcommand (G4UIcommand *newCommand)
 
void CreateDirectory (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
template<typename T >
T * CreateCommand (const G4String &cname, const G4String &dsc)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir = nullptr
 
G4String baseDirName = ""
 
G4bool commandsShouldBeInMaster = false
 

Detailed Description

Definition at line 39 of file G4VtkMessenger.hh.

Constructor & Destructor Documentation

◆ ~G4VtkMessenger()

G4VtkMessenger::~G4VtkMessenger ( )
override

Definition at line 274 of file G4VtkMessenger.cc.

275{
276 delete fpDirectory;
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;
286}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VtkMessenger::GetCurrentValue ( G4UIcommand * command)
overridevirtual

Reimplemented from G4UImessenger.

Definition at line 288 of file G4VtkMessenger.cc.

289{
290 return G4String();
291}

◆ GetInstance()

G4VtkMessenger * G4VtkMessenger::GetInstance ( )
static

Definition at line 42 of file G4VtkMessenger.cc.

43{
44 if (fpInstance == nullptr) fpInstance = new G4VtkMessenger;
45 return fpInstance;
46}

Referenced by G4Vtk::G4Vtk(), and G4VtkOffscreen::G4VtkOffscreen().

◆ SetNewValue()

void G4VtkMessenger::SetNewValue ( G4UIcommand * command,
G4String newValue )
overridevirtual

Reimplemented from G4UImessenger.

Definition at line 293 of file G4VtkMessenger.cc.

294{
296
297 G4VViewer* pViewer = pVisManager->GetCurrentViewer();
298 if (pViewer == nullptr) {
299 G4cout << "G4VtkMessenger::SetNewValue: No current viewer.\n"
300 << "\"/vis/open\", or similar, to get one." << G4endl;
301 return;
302 }
303
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;
309 return;
310 }
311
312 if (command == fpCommandClearNonG4) {
313 auto sceneHandler = dynamic_cast<G4VtkSceneHandler*>(pViewer->GetSceneHandler());
314 auto transientStore = sceneHandler->GetTransientStore();
315
316 transientStore.ClearNonG4();
317 }
318 else if (command == fpCommandExport) {
319 G4String format, name;
320
321 std::istringstream iss(newValue);
322 iss >> format >> name;
323
324 if (format == "jpg" || format == "tiff" || format == "png" || format == "bmp" || format == "pnm"
325 || format == "ps")
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
336 G4cout << "Unknown /vis/vtk/export file format" << G4endl;
337 }
338 else if (command == fpCommandExportCutter) {
339 std::istringstream iss(newValue);
340
341 G4String fileName;
342 iss >> fileName;
343 pVtkViewer->ExportVTPCutter(fileName);
344 }
345 else if (command == fpCommandWarnings) {
346 if (G4UIcommand::ConvertToBool(newValue)) {
347 vtkObject::GlobalWarningDisplayOn();
348 }
349 else {
350 vtkObject::GlobalWarningDisplayOff();
351 }
352 }
353 else if (command == fpCommandHUD) {
354 if (G4UIcommand::ConvertToBool(newValue)) {
355 pVtkViewer->EnableHUD();
356 }
357 else {
358 pVtkViewer->DisableHUD();
359 }
360 }
361 else if (command == fpCameraOrientation) {
362 G4cout << newValue << G4endl;
363 if (G4UIcommand::ConvertToBool(newValue)) {
364 pVtkViewer->EnableCameraOrientationWidget();
365 }
366 else {
367 pVtkViewer->DisableCameraOrientationWidget();
368 }
369 }
370 else if (command == fpCommandDebugPrint) {
371 pVtkViewer->Print();
372 }
373 else if (command == fpCommandPolyhedronPipeline) {
374 G4String temp;
375
376 std::istringstream iss(newValue);
377
378 G4String pipelineType;
379 iss >> pipelineType;
380
381 pVtkViewer->SetPolyhedronPipeline(pipelineType);
382 }
383 else if (command == fpCommandImageOverlay) {
384 G4String temp;
385
386 G4String fileName;
387 G4double imageBottomLeft[2] = {0, 0};
388 G4double imageTopRight[2] = {1, 1};
389 G4double worldBottomLeft[2] = {0, 0};
390 G4double worldTopRight[2] = {1, 1};
391 G4double rotation[3] = {0, 0, 0};
392 G4double translation[3] = {0, 0, 0};
393 G4double alpha = 0.5;
394
395 std::istringstream iss(newValue);
396
397 iss >> fileName >> imageBottomLeft[0] >> imageBottomLeft[1] >> imageTopRight[0]
398 >> imageTopRight[1] >> worldBottomLeft[0] >> worldBottomLeft[1] >> worldTopRight[0]
399 >> worldTopRight[1] >> rotation[0] >> rotation[1] >> rotation[2] >> translation[0]
400 >> translation[1] >> translation[2] >> alpha;
401
402 pVtkViewer->AddImageOverlay(fileName, alpha, imageBottomLeft, worldBottomLeft, imageTopRight,
403 worldTopRight, rotation, translation);
404 }
405 else if (command == fpCommandGeometryOverlay) {
406 G4String temp;
407
408 G4String fileName;
409 G4double scale[3] = {1, 1, 1};
410 G4double rotation[3] = {0,0,0};
411 G4double translation[3] = {0,0,0};
412 G4double colour[3] = {0.5, 0.5, 0.5};
413 G4double alpha = 1.0;
414 G4String representation = "w";
415
416 std::istringstream iss(newValue);
417
418 iss >> fileName
419 >> scale[0] >> scale[1] >> scale[2]
420 >> rotation[0] >> rotation[1] >> rotation[2]
421 >> translation[0] >> translation[1] >> translation[2]
422 >> alpha >> representation;
423
424 G4cout << fileName << G4endl;
425 pVtkViewer->AddGeometryOverlay(fileName, colour, alpha, representation,
426 scale, rotation, translation);
427 }
428
429
430 else if (command == fpCommandClipper) {
431 pVtkViewer->EnableClipper(G4Plane3D(), true);
432 }
433 else if (command == fpCommandCutter) {
434 pVtkViewer->EnableCutter(G4Plane3D(), true);
435 }
436 else if (command == fpCommandShadow) {
437 pVtkViewer->EnableShadows();
438 }
439 else if (command == fpCommandInteractorStart) {
440 pVtkViewer->StartInteractor();
441 }
442}
HepGeom::Plane3D< G4double > G4Plane3D
Definition G4Plane3D.hh:34
double G4double
Definition G4Types.hh:83
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4bool ConvertToBool(const char *st)
const G4String & GetName() const
G4VSceneHandler * GetSceneHandler() const
G4VViewer * GetCurrentViewer() const
static G4VisManager * GetInstance()
G4VtkStore & GetTransientStore()
void ClearNonG4()
const char * name(G4int ptype)

The documentation for this class was generated from the following files: