Geant4 11.4.0
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, const 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 (const 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 1264 of file G4VisCommandsViewer.cc.

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

◆ ~G4VisCommandViewerInterpolate()

G4VisCommandViewerInterpolate::~G4VisCommandViewerInterpolate ( )
virtual

Definition at line 1304 of file G4VisCommandsViewer.cc.

1304 {
1305 delete fpCommand;
1306}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandViewerInterpolate::GetCurrentValue ( G4UIcommand * command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1308 of file G4VisCommandsViewer.cc.

1308 {
1309 return "";
1310}

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 1312 of file G4VisCommandsViewer.cc.

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

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