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

#include <G4VisCommandsViewer.hh>

+ Inheritance diagram for G4VisCommandViewerCentreOn:

Public Member Functions

 G4VisCommandViewerCentreOn ()
 
virtual ~G4VisCommandViewerCentreOn ()
 
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 56 of file G4VisCommandsViewer.hh.

Constructor & Destructor Documentation

◆ G4VisCommandViewerCentreOn()

G4VisCommandViewerCentreOn::G4VisCommandViewerCentreOn ( )

Definition at line 142 of file G4VisCommandsViewer.cc.

142 {
143 G4bool omitable;
144 fpCommandCentreAndZoomInOn = new G4UIcommand ("/vis/viewer/centreAndZoomInOn", this);
145 fpCommandCentreAndZoomInOn->SetGuidance
146 ("Centre and zoom in on the given physical volume.");
147 fpCommandCentreAndZoomInOn->SetGuidance
148 ("The names of all volumes in all worlds are matched against pv-name. If"
149 "\ncopy-no is supplied, it matches the copy number too. If pv-name is of the"
150 "\nform \"/regexp/\", where regexp is a regular expression (see C++ regex),"
151 "\nthe match uses the usual rules of regular expression matching."
152 "\nOtherwise an exact match is required."
153 "\nFor example, \"/Shap/\" matches \"Shape1\" and \"Shape2\".");
154 fpCommandCentreAndZoomInOn->SetGuidance
155 ("It may help to see a textual representation of the geometry hierarchy of"
156 "\nthe worlds. Try \"/vis/drawTree [worlds]\" or one of the driver/browser"
157 "\ncombinations that have the required functionality, e.g., HepRepFile.");
158 fpCommandCentreAndZoomInOn->SetGuidance
159 ("If there are more than one matching physical volumes they will all be"
160 "\nincluded. If this is not what you want, and what you want is to centre on a"
161 "\nparticular touchable, then select the touchable (\"/vis/set/touchable\") and"
162 "\nuse \"/vis/touchable/centreOn\". (You may need \"/vis/touchable/findPath\".)");
163 G4UIparameter* parameter;
164 parameter = new G4UIparameter("pv-name",'s',omitable = false);
165 parameter->SetGuidance ("Physical volume name.");
166 fpCommandCentreAndZoomInOn->SetParameter(parameter);
167 parameter = new G4UIparameter("copy-no",'i',omitable = true);
168 parameter->SetDefaultValue (-1);
169 parameter->SetGuidance ("Copy number. -1 means any or all copy numbers");
170 fpCommandCentreAndZoomInOn->SetParameter(parameter);
171
172 fpCommandCentreOn = new G4UIcommand ("/vis/viewer/centreOn", this);
173 fpCommandCentreOn->SetGuidance ("Centre the view on the given physical volume.");
174 // Pick up additional guidance from /vis/viewer/centreAndZoomInOn
175 CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandCentreOn,1);
176 // Pick up parameters from /vis/viewer/centreAndZoomInOn
177 CopyParametersFrom(fpCommandCentreAndZoomInOn,fpCommandCentreOn);
178}
bool G4bool
Definition G4Types.hh:86
void SetParameter(G4UIparameter *const newParameter)
void SetGuidance(const char *aGuidance)
void SetDefaultValue(const char *theDefaultValue)
void SetGuidance(const char *theGuidance)
void CopyParametersFrom(const G4UIcommand *fromCmd, G4UIcommand *toCmd)
void CopyGuidanceFrom(const G4UIcommand *fromCmd, G4UIcommand *toCmd, G4int startLine=0)

◆ ~G4VisCommandViewerCentreOn()

G4VisCommandViewerCentreOn::~G4VisCommandViewerCentreOn ( )
virtual

Definition at line 180 of file G4VisCommandsViewer.cc.

180 {
181 delete fpCommandCentreAndZoomInOn;
182 delete fpCommandCentreOn;
183}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandViewerCentreOn::GetCurrentValue ( G4UIcommand * command)
virtual

Reimplemented from G4UImessenger.

Definition at line 185 of file G4VisCommandsViewer.cc.

185 {
186 return "";
187}

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 189 of file G4VisCommandsViewer.cc.

189 {
190
192 G4bool warn = verbosity >= G4VisManager::warnings;
193
194 G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer ();
195 if (!currentViewer) {
196 if (verbosity >= G4VisManager::errors) {
197 G4warn <<
198 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
199 << G4endl;
200 }
201 return;
202 }
203
204 G4String pvName;
205 G4int copyNo;
206 std::istringstream is (newValue);
207 is >> pvName >> copyNo;
208
209 // Find physical volumes
210 G4TransportationManager* transportationManager =
212 std::size_t nWorlds = transportationManager->GetNoWorlds();
213 std::vector<G4PhysicalVolumesSearchScene::Findings> findingsVector;
214 std::vector<G4VPhysicalVolume*>::iterator iterWorld =
215 transportationManager->GetWorldsIterator();
216 for (std::size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
217 G4PhysicalVolumeModel searchModel (*iterWorld); // Unlimited depth.
218 G4ModelingParameters mp; // Default - no culling.
219 searchModel.SetModelingParameters (&mp);
220 // Find all instances at any position in the tree
221 G4PhysicalVolumesSearchScene searchScene (&searchModel, pvName, copyNo);
222 searchModel.DescribeYourselfTo (searchScene); // Initiate search.
223 for (const auto& findings: searchScene.GetFindings()) {
224 findingsVector.push_back(findings);
225 }
226 }
227
228 if (findingsVector.empty()) {
229 if (verbosity >= G4VisManager::warnings) {
230 G4warn
231 << "WARNING: Volume \"" << pvName << "\" ";
232 if (copyNo > 0) {
233 G4warn << "copy number " << copyNo;
234 }
235 G4warn << " not found." << G4endl;
236 }
237 return;
238 }
239
240 // A vector of found paths so that we can highlight (twinkle) the found volume(s).
241 std::vector<std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>> foundPaths;
242
243 // Use a temporary scene in order to find vis extent
244 G4Scene tempScene("Centre Scene");
245 G4bool successfullyAdded = true;
246 for (const auto& findings: findingsVector) {
247 // To handle paramaterisations we have to set the copy number
248 findings.fpFoundPV->SetCopyNo(findings.fFoundPVCopyNo);
249 // Create a temporary physical volume model.
250 // They have to be created on the heap because they have
251 // to hang about long enough to be conflated.
253 (findings.fpFoundPV,
254 0, // Only interested in top volume
255 findings.fFoundObjectTransformation,
256 0, // No modelling parameters (these are set later by the scene handler).
257 true, // Use full extent
258 findings.fFoundBasePVPath);
259 // ...and add it to the scene.
260 auto successful = tempScene.AddRunDurationModel(tempPVModel,warn);
261 if (!successful) {
262 successfullyAdded = false;
263 continue;
264 }
265 if (verbosity >= G4VisManager::parameters) {
266 G4cout << "\"" << findings.fpFoundPV->GetName()
267 << "\", copy no. " << findings.fFoundPVCopyNo
268 << ",\n found in searched volume \""
269 << findings.fpSearchPV->GetName()
270 << "\" at depth " << findings.fFoundDepth
271 << ",\n base path: \"" << findings.fFoundBasePVPath
272 << ",\n has been added to temporary scene \"" << tempScene.GetName() << "\"."
273 << G4endl;
274 }
275 foundPaths.push_back(findings.fFoundFullPVPath);
276 }
277 // Delete temporary physical volume models
278 for (const auto& sceneModel: tempScene.GetRunDurationModelList()) {
279 delete sceneModel.fpModel;
280 }
281 if (!successfullyAdded) return;
282
283 // Relevant results
284 const G4VisExtent& newExtent = tempScene.GetExtent();
285 const G4ThreeVector& newTargetPoint = newExtent.GetExtentCentre();
286
287 G4Scene* currentScene = currentViewer->GetSceneHandler()->GetScene();
288 G4ViewParameters saveVP = currentViewer->GetViewParameters();
289 G4ViewParameters newVP = saveVP;
290 if (command == fpCommandCentreAndZoomInOn) {
291 // Calculate the new zoom factor
292 const G4double zoomFactor
293 = currentScene->GetExtent().GetExtentRadius()/newExtent.GetExtentRadius();
294 newVP.SetZoomFactor(zoomFactor);
295 }
296 // Change the target point
297 const G4Point3D& standardTargetPoint = currentScene->GetStandardTargetPoint();
298 newVP.SetCurrentTargetPoint(newTargetPoint - standardTargetPoint);
299
300 // If this particular view is simple enough
301 if (currentViewer->GetKernelVisitElapsedTimeSeconds() < 0.1) {
302 // Interpolate
303 auto keepVisVerbosity = fpVisManager->GetVerbosity();
305 if (newVP != saveVP) InterpolateToNewView(currentViewer, saveVP, newVP);
306 // ...and twinkle
307 Twinkle(currentViewer,newVP,foundPaths);
308 fpVisManager->SetVerboseLevel(keepVisVerbosity);
309 }
310
311 if (verbosity >= G4VisManager::confirmations) {
312 G4cout
313 << "Viewer \"" << currentViewer->GetName()
314 << "\" centred ";
315 if (fpCommandCentreAndZoomInOn) {
316 G4cout << "and zoomed in";
317 }
318 G4cout << " on physical volume(s) \"" << pvName << '\"'
319 << G4endl;
320 }
321
322 SetViewParameters(currentViewer, newVP);
323}
#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
const G4VisExtent & GetExtent() const
const G4Point3D & GetStandardTargetPoint() const
static G4TransportationManager * GetTransportationManager()
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
std::size_t GetNoWorlds() const
G4Scene * GetScene() const
const G4String & GetName() const
const G4ViewParameters & GetViewParameters() const
G4double GetKernelVisitElapsedTimeSeconds() const
G4VSceneHandler * GetSceneHandler() const
static G4VisManager * fpVisManager
void InterpolateToNewView(G4VViewer *currentViewer, const G4ViewParameters &oldVP, const G4ViewParameters &newVP, const G4int nInterpolationPoints=50, const G4int waitTimePerPointmilliseconds=20, const G4String exportString="")
void SetViewParameters(G4VViewer *viewer, const G4ViewParameters &viewParams)
void Twinkle(G4VViewer *currentViewer, const G4ViewParameters &baseVP, const std::vector< std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > > &paths)
void SetCurrentTargetPoint(const G4Point3D &currentTargetPoint)
void SetZoomFactor(G4double zoomFactor)
G4double GetExtentRadius() const
const G4Point3D & GetExtentCentre() const
static Verbosity GetVerbosity()
void SetVerboseLevel(G4int)

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