Geant4 10.7.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 ()
 
 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 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="")
 
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 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 (G4String s)
 
G4long StoL (G4String s)
 
G4double StoD (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 = 0
 
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
 

Detailed Description

Definition at line 209 of file G4VisCommandsViewer.hh.

Constructor & Destructor Documentation

◆ G4VisCommandViewerInterpolate()

G4VisCommandViewerInterpolate::G4VisCommandViewerInterpolate ( )

Definition at line 1223 of file G4VisCommandsViewer.cc.

1223 {
1224 G4bool omitable;
1225 fpCommand = new G4UIcommand ("/vis/viewer/interpolate", this);
1226 fpCommand -> SetGuidance
1227 ("Interpolate views defined by the first argument, which can contain "
1228 "Unix-shell-style pattern matching characters such as '*', '?' and '[' "
1229 "- see \"man sh\" and look for \"Pattern Matching\". The contents "
1230 "of each file are assumed to be \"/vis/viewer\" commands "
1231 "that specify a particular view. The files are processed in alphanumeric "
1232 "order of filename. The files may be written by hand or produced by the "
1233 "\"/vis/viewer/save\" command.");
1234 fpCommand -> SetGuidance
1235 ("The default is to search the working directory for files with a .g4view "
1236 "extension. Another procedure is to assemble view files in a subdirectory, "
1237 "e.g., \"myviews\"; then they can be interpolated with\n"
1238 "\"/vis/viewer/interpolate myviews/*\".");
1239 fpCommand -> SetGuidance
1240 ("To export interpolated views to file for a future possible movie, "
1241 "write \"export\" as 5th parameter (OpenGL only).");
1242 G4UIparameter* parameter;
1243 parameter = new G4UIparameter("pattern", 's', omitable = true);
1244 parameter -> SetGuidance("Pattern that defines the view files.");
1245 parameter -> SetDefaultValue("*.g4view");
1246 fpCommand -> SetParameter(parameter);
1247 parameter = new G4UIparameter("no-of-points", 'i', omitable = true);
1248 parameter -> SetGuidance ("Number of interpolation points per interval.");
1249 parameter -> SetDefaultValue(50);
1250 fpCommand -> SetParameter(parameter);
1251 parameter = new G4UIparameter("wait-time", 's', omitable = true);
1252 parameter -> SetGuidance("Wait time per interpolated point");
1253 parameter -> SetDefaultValue("20.");
1254 fpCommand -> SetParameter(parameter);
1255 parameter = new G4UIparameter("time-unit", 's', omitable = true);
1256 parameter -> SetDefaultValue("millisecond");
1257 fpCommand -> SetParameter (parameter);
1258 parameter = new G4UIparameter("export", 's', omitable = true);
1259 parameter -> SetDefaultValue("no");
1260 fpCommand -> SetParameter (parameter);
1261}
bool G4bool
Definition: G4Types.hh:86

◆ ~G4VisCommandViewerInterpolate()

G4VisCommandViewerInterpolate::~G4VisCommandViewerInterpolate ( )
virtual

Definition at line 1263 of file G4VisCommandsViewer.cc.

1263 {
1264 delete fpCommand;
1265}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandViewerInterpolate::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1267 of file G4VisCommandsViewer.cc.

1267 {
1268 return "";
1269}

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 1271 of file G4VisCommandsViewer.cc.

1271 {
1272
1274
1275 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1276 if (!currentViewer) {
1277 if (verbosity >= G4VisManager::errors) {
1278 G4cerr <<
1279 "ERROR: G4VisCommandViewerInterpolate::SetNewValue: no current viewer."
1280 << G4endl;
1281 }
1282 return;
1283 }
1284
1285 G4String pattern;
1286 G4int nInterpolationPoints;
1287 G4String waitTimePerPointString;
1288 G4String timeUnit;
1289 G4String exportString;
1290
1291 std::istringstream iss (newValue);
1292 iss
1293 >> pattern
1294 >> nInterpolationPoints
1295 >> waitTimePerPointString
1296 >> timeUnit
1297 >> exportString;
1298 G4String waitTimePerPointDimString(waitTimePerPointString + ' ' + timeUnit);
1299 const G4double waitTimePerPoint =
1300 G4UIcommand::ConvertToDimensionedDouble(waitTimePerPointDimString.c_str());
1301 G4int waitTimePerPointmilliseconds = waitTimePerPoint/millisecond;
1302 if (waitTimePerPointmilliseconds < 0) waitTimePerPointmilliseconds = 0;
1303
1305
1306 // Save current view parameters
1307 G4ViewParameters saveVP = currentViewer->GetViewParameters();
1308
1309 // Save current verbosities
1311 G4int keepUIVerbosity = uiManager->GetVerboseLevel();
1312
1313 // Set verbosities for this operation
1315 uiManager->SetVerboseLevel(0);
1316
1317 // Switch off auto-refresh while we read in the view files (it will be
1318 // restored later). Note: the view files do not set auto-refresh.
1319 G4ViewParameters non_auto = saveVP;
1320 non_auto.SetAutoRefresh(false);
1321 currentViewer->SetViewParameters(non_auto);
1322
1323 // View vector of way points
1324 std::vector<G4ViewParameters> viewVector;
1325
1326 const G4int safety = 9999;
1327 G4int safetyCount = 0;
1328 G4String pathname;
1329
1330#ifndef WIN32
1331
1332 // Execute pattern and get resulting list of files
1333 G4String shellCommand = "echo " + pattern;
1334 FILE *filelist = popen(shellCommand.c_str(), "r");
1335 if (!filelist) {
1336 if (verbosity >= G4VisManager::errors) {
1337 G4cerr
1338 << "ERROR: G4VisCommandViewerInterpolate::SetNewValue:"
1339 << "\n Error obtaining pipe."
1340 << G4endl;
1341 }
1342 return;
1343 }
1344
1345 // Build view vector of way points
1346 const size_t BUFLENGTH = 999999;
1347 char buf[BUFLENGTH];
1348 char* result = std::fgets(buf, BUFLENGTH, filelist);
1349 if (result) {
1350 std::istringstream fileliststream(result);
1351 while (fileliststream >> pathname
1352 && safetyCount++ < safety) { // Loop checking, 16.02.2016, J.Allison
1353 uiManager->ApplyCommand("/control/execute " + pathname);
1354 G4ViewParameters vp = currentViewer->GetViewParameters();
1355 // Set original auto-refresh status.
1356 vp.SetAutoRefresh(saveVP.IsAutoRefresh());
1357 viewVector.push_back(vp);
1358 }
1359 }
1360 pclose(filelist);
1361
1362#else // WIN32 (popen is not available in Windows)
1363
1364 std::filesystem::path filePattern = pattern.c_str();
1365
1366 // Default pattern : *.g4view
1367 // Translated to a regexp : ^.*\\.g4view
1368 // Convert pattern into a regexp
1369 std::string regexp_pattern("^" + filePattern.filename().string());
1370 std::string result_pattern = "";
1371 // Replace '.' by "\\."
1372 size_t currentPos = 0;
1373 size_t nextPos = 0;
1374 std::string currentReplacement = "";
1375 size_t pos1 = regexp_pattern.find('.', nextPos);
1376 size_t pos2 = regexp_pattern.find('*', nextPos);
1377 size_t pos3 = regexp_pattern.find('?', nextPos);
1378 while ((pos1 != std::string::npos) || (pos2 != std::string::npos) || (pos3 != std::string::npos)) {
1379 nextPos = pos1;
1380 currentReplacement = "\\.";
1381 if (pos2 < nextPos) {
1382 nextPos = pos2;
1383 currentReplacement = ".*";
1384 }
1385 if (pos3 < nextPos) {
1386 nextPos = pos3;
1387 currentReplacement = "(.{1,1})";
1388 }
1389 result_pattern += regexp_pattern.substr(currentPos, nextPos - currentPos) + currentReplacement;
1390 nextPos++;
1391 currentPos = nextPos;
1392 pos1 = regexp_pattern.find('.', currentPos);
1393 pos2 = regexp_pattern.find('*', currentPos);
1394 pos3 = regexp_pattern.find('?', currentPos);
1395 }
1396 result_pattern += regexp_pattern.substr(currentPos);
1397
1398 // Build view vector of way points
1399 // Add "./" for empty paths
1400 G4String parentPath(filePattern.parent_path().string().length() ? filePattern.parent_path().string() : std::string("./"));
1401 std::filesystem::path parentPathPattern = parentPath.c_str();
1402 // Iterate through files in directory and apply regex match to filter appropriate files
1403 std::regex result_pattern_regex (result_pattern, std::regex_constants::basic | std::regex_constants::icase);
1404 for (auto iter = std::filesystem::directory_iterator(parentPathPattern);
1405 iter != std::filesystem::directory_iterator() && safetyCount++ < safety;
1406 ++iter)
1407 {
1408 const auto& file = iter->path();
1409
1410 G4String filename(file.filename().string());
1411 if (std::regex_match(filename, result_pattern_regex))
1412 {
1413 uiManager->ApplyCommand("/control/execute " + filename);
1414 G4ViewParameters vp = currentViewer->GetViewParameters();
1415 // Set original auto-refresh status.
1416 vp.SetAutoRefresh(saveVP.IsAutoRefresh());
1417 viewVector.push_back(vp);
1418 }
1419 }
1420
1421#endif // WIN32
1422
1423 if (safetyCount >= safety) {
1424 if (verbosity >= G4VisManager::errors) {
1425 G4cout <<
1426 "/vis/viewer/interpolate:"
1427 "\n the number of way points exceeds the maximum currently allowed: "
1428 << safety << G4endl;
1429 }
1430 return;
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}
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:570
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:193
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:192
const G4ViewParameters & GetViewParameters() const
void SetViewParameters(const G4ViewParameters &vp)
Definition: G4VViewer.cc:119
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: