Geant4 11.1.1
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 ()
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 
virtual void SetNewValue (G4UIcommand *command, G4String newValue)
 
G4bool operator== (const G4UImessenger &messenger) const
 
G4bool operator!= (const G4UImessenger &messenger) const
 
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 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
 

Detailed Description

Definition at line 209 of file G4VisCommandsViewer.hh.

Constructor & Destructor Documentation

◆ G4VisCommandViewerInterpolate()

G4VisCommandViewerInterpolate::G4VisCommandViewerInterpolate ( )

Definition at line 1258 of file G4VisCommandsViewer.cc.

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

◆ ~G4VisCommandViewerInterpolate()

G4VisCommandViewerInterpolate::~G4VisCommandViewerInterpolate ( )
virtual

Definition at line 1298 of file G4VisCommandsViewer.cc.

1298 {
1299 delete fpCommand;
1300}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandViewerInterpolate::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1302 of file G4VisCommandsViewer.cc.

1302 {
1303 return "";
1304}

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 1306 of file G4VisCommandsViewer.cc.

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