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

#include <G4VisCommandsViewer.hh>

+ Inheritance diagram for G4VisCommandViewerInterpolate:

Public Member Functions

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

Additional Inherited Members

- Static Public Member Functions inherited from G4VVisCommand
static G4VisManagerGetVisManager ()
 
static void SetVisManager (G4VisManager *pVisManager)
 
static const G4ColourGetCurrentTextColour ()
 
- Protected Member Functions inherited from G4VVisCommand
void SetViewParameters (G4VViewer *viewer, const G4ViewParameters &viewParams)
 
void RefreshIfRequired (G4VViewer *viewer)
 
void InterpolateViews (G4VViewer *currentViewer, std::vector< G4ViewParameters > viewVector, const G4int nInterpolationPoints=50, const G4int waitTimePerPointmilliseconds=20, const G4String exportString="")
 
void InterpolateToNewView (G4VViewer *currentViewer, const G4ViewParameters &oldVP, const G4ViewParameters &newVP, const G4int nInterpolationPoints=50, const G4int waitTimePerPointmilliseconds=20, const G4String exportString="")
 
void Twinkle (G4VViewer *currentViewer, const G4ViewParameters &baseVP, const std::vector< std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > > &paths)
 
const G4StringConvertToColourGuidance ()
 
void ConvertToColour (G4Colour &colour, const G4String &redOrString, G4double green, G4double blue, G4double opacity)
 
G4bool ProvideValueOfUnit (const G4String &where, const G4String &unit, const G4String &category, G4double &value)
 
void CopyCameraParameters (G4ViewParameters &target, const G4ViewParameters &from)
 
void CheckSceneAndNotifyHandlers (G4Scene *=nullptr)
 
G4bool CheckView ()
 
void G4VisCommandsSceneAddUnsuccessful (G4VisManager::Verbosity verbosity)
 
void CopyGuidanceFrom (const G4UIcommand *fromCmd, G4UIcommand *toCmd, G4int startLine=0)
 
void CopyParametersFrom (const G4UIcommand *fromCmd, G4UIcommand *toCmd)
 
void DrawExtent (const G4VisExtent &)
 
- 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)
 
- Static Protected Member Functions inherited from G4VVisCommand
static G4String ConvertToString (G4double x, G4double y, const char *unitName)
 
static G4bool ConvertToDoublePair (const G4String &paramString, G4double &xval, G4double &yval)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir = nullptr
 
G4String baseDirName = ""
 
G4bool commandsShouldBeInMaster = false
 
- Static Protected Attributes inherited from G4VVisCommand
static G4VisManagerfpVisManager = nullptr
 
static G4int fCurrentArrow3DLineSegmentsPerCircle = 6
 
static G4Colour fCurrentColour = G4Colour::White()
 
static G4double fCurrentLineWidth = 1.
 
static G4Colour fCurrentTextColour = G4Colour::Blue()
 
static G4Text::Layout fCurrentTextLayout = G4Text::left
 
static G4double fCurrentTextSize = 12.
 
static G4PhysicalVolumeModel::TouchableProperties fCurrentTouchableProperties
 
static G4VisExtent fCurrentExtentForField
 
static std::vector< G4PhysicalVolumesSearchScene::FindingsfCurrrentPVFindingsForField
 
static G4bool fThereWasAViewer = false
 
static G4ViewParameters fExistingVP
 
static G4SceneTreeItem fExistingSceneTree
 

Detailed Description

Definition at line 209 of file G4VisCommandsViewer.hh.

Constructor & Destructor Documentation

◆ G4VisCommandViewerInterpolate()

G4VisCommandViewerInterpolate::G4VisCommandViewerInterpolate ( )

Definition at line 1274 of file G4VisCommandsViewer.cc.

1274 {
1275 G4bool omitable;
1276 fpCommand = new G4UIcommand ("/vis/viewer/interpolate", this);
1277 fpCommand -> SetGuidance
1278 ("Interpolate views defined by the first argument, which can contain "
1279 "Unix-shell-style pattern matching characters such as '*', '?' and '[' "
1280 "- see \"man sh\" and look for \"Pattern Matching\". The contents "
1281 "of each file are assumed to be \"/vis/viewer\" commands "
1282 "that specify a particular view. The files are processed in alphanumeric "
1283 "order of filename. The files may be written by hand or produced by the "
1284 "\"/vis/viewer/save\" command.");
1285 fpCommand -> SetGuidance
1286 ("The default is to search the working directory for files with a .g4view "
1287 "extension. Another procedure is to assemble view files in a subdirectory, "
1288 "e.g., \"myviews\"; then they can be interpolated with\n"
1289 "\"/vis/viewer/interpolate myviews\".");
1290 fpCommand -> SetGuidance
1291 ("To export interpolated views to file for a future possible movie, "
1292 "write \"export\" as 5th parameter (OpenGL only).");
1293 G4UIparameter* parameter;
1294 parameter = new G4UIparameter("pattern", 's', omitable = true);
1295 parameter -> SetGuidance("Pattern that defines the view files.");
1296 parameter -> SetDefaultValue("*.g4view");
1297 fpCommand -> SetParameter(parameter);
1298 parameter = new G4UIparameter("no-of-points", 'i', omitable = true);
1299 parameter -> SetGuidance ("Number of interpolation points per interval.");
1300 parameter -> SetDefaultValue(50);
1301 fpCommand -> SetParameter(parameter);
1302 parameter = new G4UIparameter("wait-time", 's', omitable = true);
1303 parameter -> SetGuidance("Wait time per interpolated point");
1304 parameter -> SetDefaultValue("20.");
1305 fpCommand -> SetParameter(parameter);
1306 parameter = new G4UIparameter("time-unit", 's', omitable = true);
1307 parameter -> SetDefaultValue("millisecond");
1308 fpCommand -> SetParameter (parameter);
1309 parameter = new G4UIparameter("export", 's', omitable = true);
1310 parameter -> SetDefaultValue("no");
1311 fpCommand -> SetParameter (parameter);
1312}
bool G4bool
Definition G4Types.hh:86

◆ ~G4VisCommandViewerInterpolate()

G4VisCommandViewerInterpolate::~G4VisCommandViewerInterpolate ( )
virtual

Definition at line 1314 of file G4VisCommandsViewer.cc.

1314 {
1315 delete fpCommand;
1316}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandViewerInterpolate::GetCurrentValue ( G4UIcommand * command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1318 of file G4VisCommandsViewer.cc.

1318 {
1319 return "";
1320}

◆ SetNewValue()

void G4VisCommandViewerInterpolate::SetNewValue ( G4UIcommand * command,
G4String newValue )
virtual

Reimplemented from G4UImessenger.

Definition at line 1322 of file G4VisCommandsViewer.cc.

1322 {
1323
1325
1326 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1327 if (!currentViewer) {
1328 if (verbosity >= G4VisManager::errors) {
1329 G4warn <<
1330 "ERROR: G4VisCommandViewerInterpolate::SetNewValue: no current viewer."
1331 << G4endl;
1332 }
1333 return;
1334 }
1335
1336 G4String pattern;
1337 G4int nInterpolationPoints;
1338 G4String waitTimePerPointString;
1339 G4String timeUnit;
1340 G4String exportString;
1341
1342 std::istringstream iss (newValue);
1343 iss
1344 >> pattern
1345 >> nInterpolationPoints
1346 >> waitTimePerPointString
1347 >> timeUnit
1348 >> exportString;
1349 G4String waitTimePerPointDimString(waitTimePerPointString + ' ' + timeUnit);
1350 const G4double waitTimePerPoint =
1351 G4UIcommand::ConvertToDimensionedDouble(waitTimePerPointDimString.c_str());
1352 G4int waitTimePerPointmilliseconds = waitTimePerPoint/millisecond;
1353 if (waitTimePerPointmilliseconds < 0) waitTimePerPointmilliseconds = 0;
1354
1356
1357 // Save current view parameters
1358 G4ViewParameters saveVP = currentViewer->GetViewParameters();
1359
1360 // Save current verbosities
1362 G4int keepUIVerbosity = uiManager->GetVerboseLevel();
1363
1364 // Set verbosities for this operation
1366 uiManager->SetVerboseLevel(0);
1367
1368 // Switch off auto-refresh while we read in the view files (it will be
1369 // restored later). Note: the view files do not set auto-refresh.
1370 G4ViewParameters non_auto = saveVP;
1371 non_auto.SetAutoRefresh(false);
1372 currentViewer->SetViewParameters(non_auto);
1373
1374 const G4int safety = 99;
1375 G4int safetyCount = 0;
1376 G4fs::path pathPattern = pattern.c_str();
1377
1378 // Parent path - add "./" for empty directory
1379 G4String parentPathString
1380 (pathPattern.parent_path().string().length() ?
1381 pathPattern.parent_path().string() :
1382 std::string("./"));
1383 G4fs::path parentPath = parentPathString.c_str();
1384
1385 // Fill selected paths
1386 std::set<G4fs::path> paths; // Use std::set to ensure order
1387
1388 if (G4fs::is_directory(pathPattern)) {
1389
1390 // The user has specified a directory. Find all files.
1391 for (const auto& path: G4fs::directory_iterator(pathPattern)) {
1392 if (safetyCount++ >= safety) break;
1393 paths.insert(path);
1394 }
1395
1396 } else {
1397
1398 // Assume user has specified a Unix "glob" pattern in leaf
1399 // Default pattern is *.g4view, which translates to ^.*\\.g4view
1400 // Convert pattern into a regexp
1401 G4String regexp_pattern("^");
1402 for (G4int i = 0; i < (G4int)pattern.length(); ++i) {
1403 if (pattern[i] == '.') {
1404 regexp_pattern += "\\.";
1405 } else if (pattern[i] == '*') {
1406 regexp_pattern += ".*";
1407 } else if (pattern[i] == '?') {
1408 regexp_pattern += "(.{1,1})";
1409 } else {
1410 regexp_pattern += pattern[i];
1411 }
1412 }
1413 std::regex regexp(regexp_pattern, std::regex_constants::basic | std::regex_constants::icase);
1414
1415 for (const auto& path: G4fs::directory_iterator(parentPath)) {
1416 const auto& pathname = path.path().relative_path().string();
1417 if (std::regex_match(pathname, regexp)) {
1418 if (safetyCount++ >= safety) break;
1419 paths.insert(path);
1420 }
1421 }
1422 }
1423
1424 if (safetyCount > safety) {
1425 if (verbosity >= G4VisManager::errors) {
1426 G4warn <<
1427 "/vis/viewer/interpolate:"
1428 "\n the number of way points has been limited to the maximum currently allowed: "
1429 << safety << G4endl;
1430 }
1431 }
1432
1433 // Fill view vector of way points
1434 std::vector<G4ViewParameters> viewVector;
1435 for (const auto& path: paths) {
1436 uiManager->ApplyCommand("/control/execute " + path.relative_path().string());
1437 G4ViewParameters vp = currentViewer->GetViewParameters();
1438 // Set original auto-refresh status.
1439 vp.SetAutoRefresh(saveVP.IsAutoRefresh());
1440 viewVector.push_back(vp);
1441 }
1442
1444 (currentViewer,viewVector,
1445 nInterpolationPoints,waitTimePerPointmilliseconds,exportString);
1446
1447 // Restore original verbosities
1448 uiManager->SetVerboseLevel(keepUIVerbosity);
1449 fpVisManager->SetVerboseLevel(keepVisVerbosity);
1450
1451 // Restore original view parameters
1452 currentViewer->SetViewParameters(saveVP);
1453 currentViewer->RefreshView();
1454 if (verbosity >= G4VisManager::confirmations) {
1455 G4cout << "Viewer \"" << currentViewer -> GetName () << "\""
1456 << " restored." << G4endl;
1457 }
1458}
#define G4warn
Definition G4Scene.cc:41
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4double ConvertToDimensionedDouble(const char *st)
G4int ApplyCommand(const char *aCommand)
G4int GetVerboseLevel() const
static G4UImanager * GetUIpointer()
void SetVerboseLevel(G4int val)
const G4ViewParameters & GetViewParameters() const
void SetViewParameters(const G4ViewParameters &vp)
Definition G4VViewer.cc:128
void RefreshView()
static G4VisManager * fpVisManager
void InterpolateViews(G4VViewer *currentViewer, std::vector< G4ViewParameters > viewVector, const G4int nInterpolationPoints=50, const G4int waitTimePerPointmilliseconds=20, const G4String exportString="")
void SetAutoRefresh(G4bool)
G4bool IsAutoRefresh() const
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()
void SetVerboseLevel(G4int)

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