Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VisCommandViewerInterpolate Class Reference

#include <G4VisCommandsViewer.hh>

Inheritance diagram for G4VisCommandViewerInterpolate:
Collaboration diagram for G4VisCommandViewerInterpolate:

Public Member Functions

 G4VisCommandViewerInterpolate ()
 
virtual ~G4VisCommandViewerInterpolate ()
 
G4String GetCurrentValue (G4UIcommand *command)
 
void SetNewValue (G4UIcommand *command, G4String newValue)
 
- Public Member Functions inherited from G4VVisCommandViewer
 G4VVisCommandViewer ()
 
virtual ~G4VVisCommandViewer ()
 
- 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 ()
 
G4bool operator== (const G4UImessenger &messenger) const
 
G4bool CommandsShouldBeInMaster () const
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VVisCommand
static void SetVisManager (G4VisManager *)
 
static const G4ColourGetCurrentColour ()
 
static G4double GetCurrentLineWidth ()
 
static const G4ColourGetCurrentTextColour ()
 
static G4Text::Layout GetCurrentTextLayout ()
 
static G4double GetCurrentTextSize ()
 
- Protected Member Functions inherited from G4VVisCommandViewer
void SetViewParameters (G4VViewer *, const G4ViewParameters &)
 
void RefreshIfRequired (G4VViewer *)
 
- Protected Member Functions inherited from G4VVisCommand
void UpdateVisManagerScene (const G4String &sceneName="")
 
- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (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 void ConvertToDoublePair (const G4String &paramString, G4double &xval, G4double &yval)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir
 
G4String baseDirName
 
G4bool commandsShouldBeInMaster
 
- Static Protected Attributes inherited from G4VVisCommand
static G4VisManagerfpVisManager = 0
 
static G4int fErrorCode = 0
 
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
G4ModelingParameters::PVNameCopyNoPath 
fCurrentTouchablePath
 

Detailed Description

Definition at line 197 of file G4VisCommandsViewer.hh.

Constructor & Destructor Documentation

G4VisCommandViewerInterpolate::G4VisCommandViewerInterpolate ( )

Definition at line 965 of file G4VisCommandsViewer.cc.

965  {
966  G4bool omitable;
967  fpCommand = new G4UIcommand ("/vis/viewer/interpolate", this);
968  fpCommand -> SetGuidance
969  ("Interpolate views defined by the first argument, which can contain "
970  "Unix-shell-style pattern matching characters such as '*', '?' and '[' "
971  "- see \"man sh\" and look for \"Pattern Matching\". The contents "
972  "of each file are assumed to be \"/vis/viewer\" commands "
973  "that specify a particular view. The files are processed in alphanumeric "
974  "order of filename. The files may be written by hand or produced by the "
975  "\"/vis/viewer/save\" command.");
976  fpCommand -> SetGuidance
977  ("The default is to search the working directory for files with a .g4view "
978  "extension. Another procedure is to assemble view files in a subdirectory, "
979  "e.g., \"myviews\"; then they can be interpolated with\n"
980  "\"/vis/viewer/interpolate myviews/*\".");
981  fpCommand -> SetGuidance
982  ("To export interpolated views to file for a future possible movie, "
983  "write \"export\" as 5th parameter (OpenGL only).");
984  G4UIparameter* parameter;
985  parameter = new G4UIparameter("pattern", 's', omitable = true);
986  parameter -> SetGuidance("Pattern that defines the view files.");
987  parameter -> SetDefaultValue("*.g4view");
988  fpCommand -> SetParameter(parameter);
989  parameter = new G4UIparameter("no-of-points", 'i', omitable = true);
990  parameter -> SetGuidance ("Number of interpolation points per interval.");
991  parameter -> SetDefaultValue(50);
992  fpCommand -> SetParameter(parameter);
993  parameter = new G4UIparameter("wait-time", 's', omitable = true);
994  parameter -> SetGuidance("Wait time per interpolated point");
995  parameter -> SetDefaultValue("20.");
996  fpCommand -> SetParameter(parameter);
997  parameter = new G4UIparameter("time-unit", 's', omitable = true);
998  parameter -> SetDefaultValue("millisecond");
999  fpCommand -> SetParameter (parameter);
1000  parameter = new G4UIparameter("export", 's', omitable = true);
1001  parameter -> SetDefaultValue("no");
1002  fpCommand -> SetParameter (parameter);
1003 }
bool G4bool
Definition: G4Types.hh:79
G4VisCommandViewerInterpolate::~G4VisCommandViewerInterpolate ( )
virtual

Definition at line 1005 of file G4VisCommandsViewer.cc.

1005  {
1006  delete fpCommand;
1007 }

Member Function Documentation

G4String G4VisCommandViewerInterpolate::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1009 of file G4VisCommandsViewer.cc.

1009  {
1010  return "";
1011 }
void G4VisCommandViewerInterpolate::SetNewValue ( G4UIcommand command,
G4String  newValue 
)
virtual

Reimplemented from G4UImessenger.

Definition at line 1013 of file G4VisCommandsViewer.cc.

1013  {
1014 
1016 
1017  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1018  if (!currentViewer) {
1019  if (verbosity >= G4VisManager::errors) {
1020  G4cerr <<
1021  "ERROR: G4VisCommandViewerInterpolate::SetNewValue: no current viewer."
1022  << G4endl;
1023  }
1024  return;
1025  }
1026 
1027  G4String pattern;
1028  G4int nInterpolationPoints;
1029  G4String waitTimePerPointString;
1030  G4String timeUnit;
1031  G4String exportString;
1032 
1033  std::istringstream iss (newValue);
1034  iss
1035  >> pattern
1036  >> nInterpolationPoints
1037  >> waitTimePerPointString
1038  >> timeUnit
1039  >> exportString;
1040  G4String waitTimePerPointDimString(waitTimePerPointString + ' ' + timeUnit);
1041  const G4double waitTimePerPoint =
1042  G4UIcommand::ConvertToDimensionedDouble(waitTimePerPointDimString.c_str());
1043  G4int waitTimePerPointmilliseconds = waitTimePerPoint/millisecond;
1044  if (waitTimePerPointmilliseconds < 0) waitTimePerPointmilliseconds = 0;
1045 
1046  G4UImanager* uiManager = G4UImanager::GetUIpointer();
1047 
1048  // Save current view parameters
1049  G4ViewParameters saveVP = currentViewer->GetViewParameters();
1050 
1051  // Save current verbosities
1052  G4VisManager::Verbosity keepVisVerbosity = fpVisManager->GetVerbosity();
1053  G4int keepUIVerbosity = uiManager->GetVerboseLevel();
1054 
1055  // Set verbosities for this operation
1057  uiManager->SetVerboseLevel(0);
1058 
1059  // Switch off auto-refresh while we read in the view files (it will be
1060  // restored later). Note: the view files do not set auto-refresh.
1061  G4ViewParameters non_auto = saveVP;
1062  non_auto.SetAutoRefresh(false);
1063  currentViewer->SetViewParameters(non_auto);
1064 
1065  // View vector of way points
1066  std::vector<G4ViewParameters> viewVector;
1067 
1068  const G4int safety = 9999;
1069  G4int safetyCount = 0;
1070  G4String pathname;
1071 
1072 #ifndef WIN32
1073 
1074  // Execute pattern and get resulting list of filles
1075  G4String shellCommand = "echo " + pattern;
1076  FILE *filelist = popen(shellCommand.c_str(), "r");
1077  if (!filelist) {
1078  if (verbosity >= G4VisManager::errors) {
1079  G4cerr
1080  << "ERROR: G4VisCommandViewerInterpolate::SetNewValue:"
1081  << "\n Error obtaining pipe."
1082  << G4endl;
1083  }
1084  return;
1085  }
1086 
1087  // Build view vector of way points
1088  const size_t BUFLENGTH = 999999;
1089  char buf[BUFLENGTH];
1090  fgets(buf, BUFLENGTH, filelist);
1091  std::istringstream fileliststream(buf);
1092  while (fileliststream >> pathname
1093  && safetyCount++ < safety) { // Loop checking, 16.02.2016, J.Allison
1094  uiManager->ApplyCommand("/control/execute " + pathname);
1095  viewVector.push_back(currentViewer->GetViewParameters());
1096  }
1097  pclose(filelist);
1098 
1099 #else // WIN32 (popen is not available in Windows)
1100 
1101  std::experimental::filesystem::v1::path filePattern(pattern);
1102 
1103  // Default pattern : *.g4view
1104  // Translated to a regexp : ^.*\\.g4view
1105  // Convert pattern into a regexp
1106  std::string regexp_pattern("^" + filePattern.filename().string());
1107  std::string result_pattern = "";
1108  // Replace '.' by "\\."
1109  size_t currentPos = 0;
1110  size_t nextPos = 0;
1111  std::string currentReplacement = "";
1112  size_t pos1 = regexp_pattern.find('.', nextPos);
1113  size_t pos2 = regexp_pattern.find('*', nextPos);
1114  size_t pos3 = regexp_pattern.find('?', nextPos);
1115  while ((pos1 != std::string::npos) || (pos2 != std::string::npos) || (pos3 != std::string::npos)) {
1116  nextPos = pos1;
1117  currentReplacement = "\\.";
1118  if (pos2 < nextPos) {
1119  nextPos = pos2;
1120  currentReplacement = ".*";
1121  }
1122  if (pos3 < nextPos) {
1123  nextPos = pos3;
1124  currentReplacement = "(.{1,1})";
1125  }
1126  result_pattern += regexp_pattern.substr(currentPos, nextPos - currentPos) + currentReplacement;
1127  nextPos++;
1128  currentPos = nextPos;
1129  pos1 = regexp_pattern.find('.', currentPos);
1130  pos2 = regexp_pattern.find('*', currentPos);
1131  pos3 = regexp_pattern.find('?', currentPos);
1132  }
1133  result_pattern += regexp_pattern.substr(currentPos);
1134 
1135  // Build view vector of way points
1136  // Add "./" for empty paths
1137  G4String parentPath(filePattern.parent_path().string().length() ? filePattern.parent_path().string() : std::string("./"));
1138  // Iterate through files in directory and apply regex match to filter appropriate files
1139  std::regex result_pattern_regex (result_pattern, std::regex_constants::basic | std::regex_constants::icase);
1140  for (auto iter = std::experimental::filesystem::v1::directory_iterator(parentPath);
1141  iter != std::experimental::filesystem::v1::directory_iterator() && safetyCount++ < safety;
1142  ++iter)
1143  {
1144  const auto& file = iter->path();
1145 
1146  G4String filename(file.filename().string());
1147  if (std::regex_match(filename, result_pattern_regex))
1148  {
1149  uiManager->ApplyCommand("/control/execute " + filename);
1150  viewVector.push_back(currentViewer->GetViewParameters());
1151  }
1152  }
1153 
1154 #endif // WIN32
1155 
1156  if (safetyCount >= safety) {
1157  if (verbosity >= G4VisManager::errors) {
1158  G4cout <<
1159  "/vis/viewer/interpolate:"
1160  "\n the number of way points exceeds the maximum currently allowed: "
1161  << safety << G4endl;
1162  }
1163  return;
1164  }
1165 
1166  // Interpolate views
1167  safetyCount = 0;
1168  do {
1169  G4ViewParameters* vp =
1170  G4ViewParameters::CatmullRomCubicSplineInterpolation(viewVector,nInterpolationPoints);
1171  if (!vp) break; // Finished.
1172  // Set original auto-refresh status.
1173  vp->SetAutoRefresh(saveVP.IsAutoRefresh());
1174  currentViewer->SetViewParameters(*vp);
1175  currentViewer->RefreshView();
1176  if (exportString == "export" &&
1177  currentViewer->GetName().contains("OpenGL"))
1178  uiManager->ApplyCommand("/vis/ogl/export");
1179 #ifdef G4VIS_USE_STD11
1180  if (waitTimePerPointmilliseconds > 0)
1181  std::this_thread::sleep_for(std::chrono::milliseconds(waitTimePerPointmilliseconds));
1182 #endif
1183  } while (safetyCount++ < safety); // Loop checking, 16.02.2016, J.Allison
1184 
1185  // Restore original verbosities
1186  uiManager->SetVerboseLevel(keepUIVerbosity);
1187  fpVisManager->SetVerboseLevel(keepVisVerbosity);
1188 
1189  // Restore original view parameters
1190  currentViewer->SetViewParameters(saveVP);
1191  currentViewer->RefreshView();
1192  if (verbosity >= G4VisManager::confirmations) {
1193  G4cout << "Viewer \"" << currentViewer -> GetName () << "\""
1194  << " restored." << G4endl;
1195  }
1196 }
const G4String & GetName() const
void SetVerboseLevel(G4int)
const G4ViewParameters & GetViewParameters() const
void SetViewParameters(const G4ViewParameters &vp)
Definition: G4VViewer.cc:120
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:227
int G4int
Definition: G4Types.hh:78
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:463
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:225
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
G4GLOB_DLL std::ostream G4cout
G4bool contains(const std::string &) const
void SetAutoRefresh(G4bool)
static constexpr double millisecond
Definition: G4SIunits.hh:159
static Verbosity GetVerbosity()
void RefreshView()
#define G4endl
Definition: G4ios.hh:61
G4VViewer * GetCurrentViewer() const
double G4double
Definition: G4Types.hh:76
static G4ViewParameters * CatmullRomCubicSplineInterpolation(const std::vector< G4ViewParameters > &views, G4int nInterpolationPoints=50)
G4bool IsAutoRefresh() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:447
G4GLOB_DLL std::ostream G4cerr
static G4VisManager * fpVisManager

Here is the call graph for this function:


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