Import Geant4 10.3.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2016-06-30 14:12:05 +02:00
parent a654a7ab1f
commit 4ec577e5c4
2021 changed files with 100995 additions and 78277 deletions
+138 -1
View File
@@ -1,4 +1,4 @@
$Id: History 93811 2015-11-02 11:28:41Z gcosmo $
$Id: History 97548 2016-06-03 15:56:56Z gcosmo $
-------------------------------------------------------------------
@@ -26,6 +26,143 @@ committal in the CVS repository !
History file for visualization management sub-category
------------------------------------------------------
3rd June 2016 John Allison (visman-V10-02-13)
- G4ViewParameters.cc: Fixed compilation warnings on gcc-6.1.
1st June 2016 John Allison (visman-V10-02-12)
- Fixed compiler error on Windows. /vis/viewer/interpolate is not
available on Windows because it uses popen, a way of getting
output from a system command. _popen (with an underscore) is
said to be available in Windows but this has not been tried.
1st June 2016 John Allison (visman-V10-02-11)
- Introduced /vis/viewer/interpolate. See History from development
branch visman-V10-02-02-branch as follows:
17th February 2016 John Allison (visman-V10-02-02-branch-12)
- G4ViewParameters::CatmullRomCubicSplineInterpolation:
o Protected some parameters from going negative, as appropriate.
- G4VisCommandsViewer.cc: /vis/viewer/interpolate:
o Changed first argument to Unix-style pattern. From the guidance:
Interpolate views defined by the first argument, which can contain Unix-shell-style pattern matching characters such as '*', '?' and '[' - see "man sh" and look for "Pattern Matching". The contents of each file are assumed to be "/vis/viewer" commands that specify a particular view. The files are processed in alphanumeric order of filename. The files may be written by hand or produced by the "/vis/viewer/save" command.
The default is to search the working directory for files with a .view extension. Another procedure is to assemble view files in a subdirectory, e.g., "myviews"; then they can be interpolated with
"/vis/viewer/interpolate myviews/*".
16th February 2016 John Allison (visman-V10-02-02-branch-11)
- /vis/viewer/interpolate:
Added safety check to while and do loops.
- Restored mysteriously lost G4VisCommandViewerClearVisAttributesModifiers.
28th January 2016 John Allison (visman-V10-02-02-branch-10)
- Interpolation: Added vis attributes modifiers (colours only).
- Tidied.
28th January 2016 John Allison (visman-V10-02-02-branch-09)
- Tidied.
28th January 2016 John Allison (visman-V10-02-02-branch-08)
- Interpolation: Added cutaway planes.
27th January 2016 John Allison (visman-V10-02-02-branch-07)
- Interpolation: Added planes and colours.
27th January 2016 John Allison (visman-V10-02-02-branch-06)
- /vis/viewer/interpolate:
o Allow export of files for possible movie. Write \"export\" as
5th parameter (OpenGL only).
27th January 2016 John Allison (visman-V10-02-02-branch-05)
- Needs modeling-V10-02-01.
- G4VisManager.cc: Added instantiation of
G4VisCommandViewerClearVisAttributesModifiers.
- G4VisCommandsViewer: Added /vis/viewer/clearVisAttributesModifiers.
- G4VisCommandsTouchable.cc: Improved guidance.
- G4ViewParameters:
o Added ClearVisAttributesModifiers.
o Augmented AddVisAttributesModifier so that if a target already
exists the modifier is not added, only the vis attributes of the
existing modifier are changed.
26th January 2016 John Allison
- Merged visman-V10-02-03: G4VisManager::G4VisSubThread:
GetNavigatorForTracking -> SetWorldVolume
This is required for OriginVolume drawing and filtering.
24th January 2016 John Allison (visman-V10-02-02-branch-04)
- Refinements.
23rd January 2016 John Allison (visman-V10-02-02-branch-01)
- Improved /vis/viewer/interpolate.
22nd January 2016 John Allison (visman-V10-02-02-branch-00)
- Introduced G4ViewParameters::CatmullRomCubicSplineInterpolation.
- Moved the following:
#ifndef __MIC__
#define G4VIS_USE_STD11
#endif
from G4VisManager.cc to G4VisManager.hh.
- G4VisManager.cc: Instantiated G4VisCommandViewerInterpolate.
- G4VisCommandsViewer:
o Introduced /vis/viewer/interpolate. Note this command is not
available on Windows. Code is protected by #ifndef WIN32.
This is because popen, which allows one to retrieve output
from a system shell command, is not available on Windows.
o Improved guidance for /vis/viewer/save.
30th May 2016 John Allison (visman-V10-02-10)
- G4VisManager::SetCurrentViewer: Added fpViewer->SetView().
- G4VisCommandsViewer.cc:
o /vis/viewer/select: Added comment: Calling the above calls SetView().
o /vis/viewer/clear: Added viewer->SetView().
4th May 2016 John Allison (visman-V10-02-09)
- G4VisExecutive.icc: Win32 now opens with "/vis/open OGL" if Qt
is not built.
2nd May 2016 John Allison (visman-V10-02-08)
- G4VisCommandsSceneAdd.cc: Fixed gcc-6.1 warnings.
2nd May 2016 John Allison (visman-V10-02-07)
- G4VisManager: MT mode: moved end of run instructions (ShowView,
etc.) to end of vis thread. This is so that all trajectories are
flushed from vis thread before switching back to master thread.
Also fixes picking in MT mode.
30th March 2016 John Allison
- Gave fallback trajectory model the name "DefaultModel".
29th March 2016 John Allison (visman-V10-02-06)
- G4VisManager.cc: Cosmetic. Change of name of fallback traj. model.
- G4VisCommandsSceneAdd.cc:
o /vis/scene/add/volume: Removed incorrect check on existing models.
It was preventing parallel worlds being added individually. There
are enough checks in G4Scene::AddRunDurationModel.
11th March 2016 John Allison (visman-V10-02-05)
- Fixed mistake in introductory vis manager message.
- Inhibited use of BeginRun, BeginEvent, EndEvent and EndRun
when vis is not enabled, for example after /vis/disable.
In particular this prevents the start of the vis thread in
multithreading mode.
15th February 2016 John Allison (visman-V10-02-04)
- Requires modeling-V10-02-02.
- G4VisExecutive.icc:
Registered drawing and filtering by touched volume. I.e.,
/vis/modeling/trajectories/create/drawByTouchedVolume
/vis/filtering/trajectories/create/touchedVolumeFilter
26th January 2016 John Allison (visman-V10-02-03)
- G4VisManager::G4VisSubThread:
GetNavigatorForTracking -> SetWorldVolume
This is required for OriginVolume drawing and filtering.
14th January 2016 John Allison (visman-V10-02-02)
- Improved /vis/viewer/save.
14th January 2016 John Allison (visman-V10-02-01)
- Fixed unused variable problem.
14th January 2016 John Allison (visman-V10-02-00)
- Improved error tracking:
o G4VVisCommand: Introduced error code to track error conditions.
o G4VisCommandsCompound.cc: Tracked error conditions for
/vis/open and /vis/drawTree.
- G4VisCommandsSceneHandler.cc: Code tidying.
11th December 2015 Laurent Garnier
- G4VViewer:
o Add ComputeFlyThrough method (beta)
o Add an G4Spline class for testing
1st November 2015 John Allison (visman-V10-01-20)
- Introduced (again!) <chrono> for queue handling in MT mode.
o Except for Xeon Phi, which is protected by #ifndef __MIC__
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VViewer.hh 90651 2015-06-05 13:30:54Z gcosmo $
// $Id: G4VViewer.hh 95006 2016-01-15 08:26:18Z gcosmo $
//
//
// John Allison 27th March 1996
@@ -98,6 +98,8 @@ public: // With description
// It is not yet the end of all drawing; that is signalled by
// ShowView ().)
std::vector<G4ThreeVector> ComputeFlyThrough(G4Vector3D*);
#ifdef G4MULTITHREADED
// In MT mode these functions are called in the following order for each run:
// Called on the master thread before starting the vis sub-thread.
@@ -194,4 +196,26 @@ void G4VViewer::DrawView () { // Default - concrete view usually overrides.
*********************************************/
class G4Spline
{
public:
// Constructors and destructor
G4Spline();
~G4Spline();
// Operations
void AddSplinePoint(const G4Vector3D& v);
G4Vector3D GetInterpolatedSplinePoint(float t); // t = 0...1; 0=vp[0] ... 1=vp[max]
int GetNumPoints();
G4Vector3D GetPoint(int);
// method for computing the Catmull-Rom parametric equation
// given a time (t) and a vector quadruple (p1,p2,p3,p4).
G4Vector3D CatmullRom_Eq(float t, const G4Vector3D& p1, const G4Vector3D& p2,
const G4Vector3D& p3, const G4Vector3D& p4);
private:
std::vector<G4Vector3D> vp;
float delta_t;
};
#endif
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VVisCommand.hh 83403 2014-08-21 15:07:30Z gcosmo $
// $Id: G4VVisCommand.hh 95006 2016-01-15 08:26:18Z gcosmo $
// Base class for visualization commands - John Allison 9th August 1998
// It is really a messenger - we have one command per messenger.
@@ -74,6 +74,9 @@ protected:
// Data members.
static G4VisManager* fpVisManager;
// Error management
static G4int fErrorCode;
// Current quantities for use in appropriate commands
static G4Colour fCurrentColour;
//static G4VMarker::FillStyle fCurrentFillStyle; Not yet used.
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4ViewParameters.hh 66373 2012-12-18 09:41:34Z gcosmo $
// $Id: G4ViewParameters.hh 97316 2016-06-01 12:12:58Z gcosmo $
//
//
// John Allison 19th July 1996
@@ -248,6 +248,7 @@ public: // With description
void SetBackgroundColour (const G4Colour&);
void SetPicking (G4bool);
void SetRotationStyle (RotationStyle);
void ClearVisAttributesModifiers ();
void AddVisAttributesModifier
(const G4ModelingParameters::VisAttributesModifier&);
@@ -262,6 +263,19 @@ public: // With description
// Other functions.
void PrintDifferences (const G4ViewParameters& v) const;
// Interpolation
// Returns a null pointer when no more to be done. For example:
// do {
// G4ViewParameters* vp =
// G4ViewParameters::CatmullRomCubicSplineInterpolation(viewVector,nInterpolationPoints);
// if (!vp) break;
// ...
// } while (true);
// Assumes equal intervals
static G4ViewParameters* CatmullRomCubicSplineInterpolation
(const std::vector<G4ViewParameters>& views,
G4int nInterpolationPoints = 50); // No of interpolations points per interval
private:
G4int ParseGeometry ( const char *string, G4int *x, G4int *y, unsigned int *width, unsigned int *height);
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4ViewParameters.icc 86974 2014-11-21 11:58:31Z gcosmo $
// $Id: G4ViewParameters.icc 97316 2016-06-01 12:12:58Z gcosmo $
//
//
// John Allison 20th October 1996
@@ -387,7 +387,6 @@ inline void G4ViewParameters::SetRotationStyle
fRotationStyle = style;
}
inline void G4ViewParameters::AddVisAttributesModifier
(const G4ModelingParameters::VisAttributesModifier& vam) {
fVisAttributesModifiers.push_back(vam);
inline void G4ViewParameters::ClearVisAttributesModifiers () {
fVisAttributesModifiers.clear ();
}
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VisCommandsViewer.hh 66373 2012-12-18 09:41:34Z gcosmo $
// $Id: G4VisCommandsViewer.hh 97316 2016-06-01 12:12:58Z gcosmo $
// /vis/viewer commands - John Allison 25th October 1998
@@ -115,6 +115,18 @@ private:
G4UIcmdWithAString* fpCommand;
};
class G4VisCommandViewerClearVisAttributesModifiers: public G4VVisCommandViewer {
public:
G4VisCommandViewerClearVisAttributesModifiers ();
virtual ~G4VisCommandViewerClearVisAttributesModifiers ();
G4String GetCurrentValue (G4UIcommand* command);
void SetNewValue (G4UIcommand* command, G4String newValue);
private:
G4VisCommandViewerClearVisAttributesModifiers (const G4VisCommandViewerClearVisAttributesModifiers&);
G4VisCommandViewerClearVisAttributesModifiers& operator = (const G4VisCommandViewerClearVisAttributesModifiers&);
G4UIcmdWithoutParameter* fpCommand;
};
class G4VisCommandViewerClone: public G4VVisCommandViewer {
public:
G4VisCommandViewerClone ();
@@ -182,6 +194,20 @@ private:
G4UIcmdWithAString* fpCommand;
};
#ifndef WIN32
class G4VisCommandViewerInterpolate: public G4VVisCommandViewer {
public:
G4VisCommandViewerInterpolate ();
virtual ~G4VisCommandViewerInterpolate ();
G4String GetCurrentValue (G4UIcommand* command);
void SetNewValue (G4UIcommand* command, G4String newValue);
private:
G4VisCommandViewerInterpolate (const G4VisCommandViewerInterpolate&);
G4VisCommandViewerInterpolate& operator = (const G4VisCommandViewerInterpolate&);
G4UIcommand* fpCommand;
};
#endif
class G4VisCommandViewerList: public G4VVisCommandViewer {
public:
G4VisCommandViewerList ();
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VisExecutive.icc 91686 2015-07-31 09:40:08Z gcosmo $
// $Id: G4VisExecutive.icc 96765 2016-05-04 13:28:37Z gcosmo $
//
//
// John Allison 24th January 1998.
@@ -197,6 +197,10 @@ G4VisExecutive::RegisterGraphicsSystems () {
#ifdef G4VIS_USE_OPENGLQT
ogliwin32->AddNickname("OGLIQt_FALLBACK");
oglswin32->AddNickname("OGLSQt_FALLBACK");
#else
ogliwin32->AddNickname("OGLI");
oglswin32->AddNickname("OGL");
oglswin32->AddNickname("OGLS");
#endif
#endif
@@ -235,16 +239,18 @@ G4VisExecutive::RegisterModelFactories()
{
// Trajectory draw models
RegisterModelFactory(new G4TrajectoryGenericDrawerFactory());
RegisterModelFactory(new G4TrajectoryDrawByAttributeFactory());
RegisterModelFactory(new G4TrajectoryDrawByChargeFactory());
RegisterModelFactory(new G4TrajectoryDrawByOriginVolumeFactory());
RegisterModelFactory(new G4TrajectoryDrawByParticleIDFactory());
RegisterModelFactory(new G4TrajectoryDrawByOriginVolumeFactory());
RegisterModelFactory(new G4TrajectoryDrawByAttributeFactory());
RegisterModelFactory(new G4TrajectoryDrawByTouchedVolumeFactory());
// Trajectory filter models
RegisterModelFactory(new G4TrajectoryChargeFilterFactory());
RegisterModelFactory(new G4TrajectoryParticleFilterFactory());
RegisterModelFactory(new G4TrajectoryOriginVolumeFilterFactory());
RegisterModelFactory(new G4TrajectoryAttributeFilterFactory());
RegisterModelFactory(new G4TrajectoryChargeFilterFactory());
RegisterModelFactory(new G4TrajectoryOriginVolumeFilterFactory());
RegisterModelFactory(new G4TrajectoryParticleFilterFactory());
RegisterModelFactory(new G4TrajectoryTouchedVolumeFilterFactory());
// Hit filter models
RegisterModelFactory(new G4HitAttributeFilterFactory());
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VisManager.hh 93026 2015-09-30 16:07:07Z gcosmo $
// $Id: G4VisManager.hh 97316 2016-06-01 12:12:58Z gcosmo $
//
//
@@ -80,6 +80,11 @@
#ifndef G4VISMANAGER_HH
#define G4VISMANAGER_HH
// Temporary definition until Xeon Phi can handle full C++11.
#ifndef __MIC__
#define G4VIS_USE_STD11
#endif
#include "G4VVisManager.hh"
#include "globals.hh"
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VViewer.cc 90651 2015-06-05 13:30:54Z gcosmo $
// $Id: G4VViewer.cc 95006 2016-01-15 08:26:18Z gcosmo $
//
//
// John Allison 27th March 1996
@@ -132,6 +132,157 @@ void G4VViewer::SetViewParameters (const G4ViewParameters& vp) {
}
std::vector <G4ThreeVector> G4VViewer::ComputeFlyThrough(G4Vector3D* /*aVect*/)
{
enum CurveType {
Bezier,
G4SplineTest};
// Choose a curve type (for testing)
int myCurveType = Bezier;
// number if step points
int stepPoints = 500;
G4Spline* spline = new G4Spline();
// At the moment we don't use the aVect parameters, but build it here :
// Good step points for exampleB5
spline->AddSplinePoint(G4Vector3D(0,1000,-14000));
spline->AddSplinePoint(G4Vector3D(0,1000,0));
spline->AddSplinePoint(G4Vector3D(-4000,1000,4000));
std::vector <G4ThreeVector> viewVect;
if(myCurveType == Bezier) {
// Draw the spline
for (int i = 0; i < stepPoints; i++) {
float t = (float)i / (float)stepPoints;
G4Vector3D cameraPosition = spline->GetInterpolatedSplinePoint(t);
// G4Vector3D targetPoint = spline->GetInterpolatedSplinePoint(t);
// viewParam->SetViewAndLights(G4ThreeVector (cameraPosition.x(), cameraPosition.y(), cameraPosition.z()));
// viewParam->SetCurrentTargetPoint(targetPoint);
G4cout << "FLY CR("<< i << "):" << cameraPosition << G4endl;
viewVect.push_back(G4ThreeVector (cameraPosition.x(), cameraPosition.y(), cameraPosition.z()));
}
} else if (myCurveType == G4SplineTest) {
/*
This method is a inspire from a Bezier curve. The problem of the Bezier curve is that the path does not go straight between two waypoints.
This method add "stay straight" parameter which could be between 0 and 1 where the pass will follow exactly the line between the waypoints
Ex : stay straight = 50%
m1 = 3*(P1+P0)/2
Ex : stay straight = 0%
m1 = (P1+P0)/2
P1
/ \
/ \
a--x--b
/ ° ° \
/ ° ° \
m1 m2
/ \
/ \
/ \
/ \
P0 P2
*/
G4Vector3D a;
G4Vector3D b;
G4Vector3D m1;
G4Vector3D m2;
G4Vector3D P0;
G4Vector3D P1;
G4Vector3D P2;
G4double stayStraight = 0;
G4double bezierSpeed = 0.4; // Spend 40% time in bezier curve (time between m1-m2 is 40% of time between P0-P1)
G4Vector3D firstPoint;
G4Vector3D lastPoint;
float nbBezierSteps = (stepPoints * bezierSpeed*(1-stayStraight)) * (2./spline->GetNumPoints());
float nbFirstSteps = ((stepPoints/2-nbBezierSteps/2) /(1+stayStraight)) * (2./spline->GetNumPoints());
// First points
firstPoint = spline->GetPoint(0);
lastPoint = (firstPoint + spline->GetPoint(1))/2;
for( float j=0; j<1; j+= 1/nbFirstSteps) {
G4ThreeVector pt = firstPoint + (lastPoint - firstPoint) * j;
viewVect.push_back(pt);
G4cout << "FLY Bezier A1("<< viewVect.size()<< "):" << pt << G4endl;
}
for (int i = 0; i < spline->GetNumPoints()-2; i++) {
P0 = spline->GetPoint(i);
P1 = spline->GetPoint(i+1);
P2 = spline->GetPoint(i+2);
m1 = P1 - (P1-P0)*(1-stayStraight)/2;
m2 = P1 + (P2-P1)*(1-stayStraight)/2;
// We have to get straight path from (middile of P0-P1) to (middile of P0-P1 + (dist P0-P1) * stayStraight/2)
if (stayStraight >0) {
firstPoint = (P0 + P1)/2;
lastPoint = (P0 + P1)/2 + (P1-P0)*stayStraight/2;
for( float j=0; j<1; j+= 1/(nbFirstSteps*stayStraight)) {
G4ThreeVector pt = firstPoint + (lastPoint - firstPoint)* j;
viewVect.push_back(pt);
G4cout << "FLY Bezier A2("<< viewVect.size()<< "):" << pt << G4endl;
}
}
// Compute Bezier curve
for( float delta = 0 ; delta < 1 ; delta += 1/nbBezierSteps)
{
// The Green Line
a = m1 + ( (P1 - m1) * delta );
b = P1 + ( (m2 - P1) * delta );
// Final point
G4ThreeVector pt = a + ((b-a) * delta );
viewVect.push_back(pt);
G4cout << "FLY Bezier("<< viewVect.size()<< "):" << pt << G4endl;
}
// We have to get straight path
if (stayStraight >0) {
firstPoint = (P1 + P2)/2 - (P2-P1)*stayStraight/2;
lastPoint = (P1 + P2)/2;
for( float j=0; j<1; j+= 1/(nbFirstSteps*stayStraight)) {
G4ThreeVector pt = firstPoint + (lastPoint - firstPoint)* j;
viewVect.push_back(pt);
G4cout << "FLY Bezier B1("<< viewVect.size()<< "):" << pt << G4endl;
}
}
}
// last points
firstPoint = spline->GetPoint(spline->GetNumPoints()-2);
lastPoint = spline->GetPoint(spline->GetNumPoints()-1);
for( float j=1; j>0; j-= 1/nbFirstSteps) {
G4ThreeVector pt = lastPoint - ((lastPoint-firstPoint)*((1-stayStraight)/2) * j );
viewVect.push_back(pt);
G4cout << "FLY Bezier B2("<< viewVect.size()<< "):" << pt << G4endl;
}
}
return viewVect;
}
#ifdef G4MULTITHREADED
void G4VViewer::DoneWithMasterThread () {
@@ -165,3 +316,64 @@ std::ostream& operator << (std::ostream& os, const G4VViewer& v) {
os << v.fVP;
return os;
}
// ===== G4Spline class =====
G4Spline::G4Spline()
: vp(), delta_t(0)
{
}
G4Spline::~G4Spline()
{}
// Solve the Catmull-Rom parametric equation for a given time(t) and vector quadruple (p1,p2,p3,p4)
G4Vector3D G4Spline::CatmullRom_Eq(float t, const G4Vector3D& p1, const G4Vector3D& p2, const G4Vector3D& p3, const G4Vector3D& p4)
{
float t2 = t * t;
float t3 = t2 * t;
float b1 = .5 * ( -t3 + 2*t2 - t);
float b2 = .5 * ( 3*t3 - 5*t2 + 2);
float b3 = .5 * (-3*t3 + 4*t2 + t);
float b4 = .5 * ( t3 - t2 );
return (p1*b1 + p2*b2 + p3*b3 + p4*b4);
}
void G4Spline::AddSplinePoint(const G4Vector3D& v)
{
vp.push_back(v);
delta_t = (float)1 / (float)vp.size();
}
G4Vector3D G4Spline::GetPoint(int a)
{
return vp[a];
}
int G4Spline::GetNumPoints()
{
return vp.size();
}
G4Vector3D G4Spline::GetInterpolatedSplinePoint(float t)
{
// Find out in which interval we are on the spline
int p = (int)(t / delta_t);
// Compute local control point indices
#define BOUNDS(pp) { if (pp < 0) pp = 0; else if (pp >= (int)vp.size()-1) pp = vp.size() - 1; }
int p0 = p - 1; BOUNDS(p0);
int p1 = p; BOUNDS(p1);
int p2 = p + 1; BOUNDS(p2);
int p3 = p + 2; BOUNDS(p3);
// Relative (local) time
float lt = (t - delta_t*(float)p) / delta_t;
// Interpolate
return CatmullRom_Eq(lt, vp[p0], vp[p1], vp[p2], vp[p3]);
}
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VVisCommand.cc 85021 2014-10-23 09:53:47Z gcosmo $
// $Id: G4VVisCommand.cc 95006 2016-01-15 08:26:18Z gcosmo $
// Base class for visualization commands - John Allison 9th August 1998
// It is really a messenger - we have one command per messenger.
@@ -36,6 +36,8 @@
#include "G4UnitsTable.hh"
#include <sstream>
G4int G4VVisCommand::fErrorCode = 0;
G4Colour G4VVisCommand::fCurrentColour = G4Colour::White();
G4Colour G4VVisCommand::fCurrentTextColour = G4Colour::Blue();
G4Text::Layout G4VVisCommand::fCurrentTextLayout = G4Text::left;
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4ViewParameters.cc 91686 2015-07-31 09:40:08Z gcosmo $
// $Id: G4ViewParameters.cc 97548 2016-06-03 15:56:56Z gcosmo $
//
//
// John Allison 19th July 1996
@@ -248,6 +248,22 @@ void G4ViewParameters::IncrementPan (G4double right, G4double up, G4double dista
fCurrentTargetPoint += right * unitRight + up * unitUp + distance * fViewpointDirection;
}
void G4ViewParameters::AddVisAttributesModifier
(const G4ModelingParameters::VisAttributesModifier& vam) {
// If target exists, just change vis attributes.
G4bool duplicateTarget = false;
auto i = fVisAttributesModifiers.begin();
for (; i < fVisAttributesModifiers.end(); ++i) {
if (vam.GetPVNameCopyNoPath() == (*i).GetPVNameCopyNoPath() &&
vam.GetVisAttributesSignifier() == (*i).GetVisAttributesSignifier()) {
duplicateTarget = true;
break;
}
}
if (duplicateTarget) (*i).SetVisAttributes(vam.GetVisAttributes());
else fVisAttributesModifiers.push_back(vam);
}
G4String G4ViewParameters::CameraAndLightingCommands
(const G4Point3D standardTargetPoint) const
{
@@ -464,7 +480,9 @@ G4String G4ViewParameters::TouchableCommands() const
{
std::ostringstream oss;
oss << "#\n# Touchable commands";
oss
<< "#\n# Touchable commands"
<< "\n/vis/viewer/clearVisAttributesModifiers";
const std::vector<G4ModelingParameters::VisAttributesModifier>& vams =
fVisAttributesModifiers;
@@ -1107,3 +1125,255 @@ G4int G4ViewParameters::ReadInteger(char *string, char **NextString)
else
return (-Result);
}
G4ViewParameters* G4ViewParameters::CatmullRomCubicSplineInterpolation
(const std::vector<G4ViewParameters>& views,
G4int nInterpolationPoints) // No of interpolations points per interval
{
// Returns a null pointer when no more to be done. For example:
// do {
// G4ViewParameters* vp =
// G4ViewParameters::CatmullRomCubicSplineInterpolation(viewVector,nInterpolationPoints);
// if (!vp) break;
// ...
// } while (true);
// See https://en.wikipedia.org/wiki/Cubic_Hermite_spline
// Assumes equal intervals
if (views.size() < 2) {
G4Exception
("G4ViewParameters::CatmullRomCubicSplineInterpolation",
"visman0301", JustWarning,
"There must be at least two views.");
return 0;
}
if (nInterpolationPoints < 1) {
G4Exception
("G4ViewParameters::CatmullRomCubicSplineInterpolation",
"visman0302", JustWarning,
"Number of interpolation points cannot be zero or negative.");
return 0;
}
const size_t nIntervals = views.size() - 1;
const G4double dt = 1./nInterpolationPoints;
static G4ViewParameters holdingValues;
static G4double t = 0.; // 0. <= t <= 1.
static G4int iInterpolationPoint = 0;
static size_t iInterval = 0;
// G4cout << "Interval " << iInterval << ", t = " << t << G4endl;
// Hermite polynomials.
const G4double h00 = 2.*t*t*t - 3.*t*t +1;
const G4double h10 = t*t*t -2.*t*t + t;
const G4double h01 = -2.*t*t*t + 3.*t*t;
const G4double h11 = t*t*t - t*t;
// Aliases (to simplify code)
const size_t& n = nIntervals;
size_t& i = iInterval;
const std::vector<G4ViewParameters>& v = views;
// The Catmull-Rom cubic spline prescription is as follows:
// Slope at first way point is v[1] - v[0].
// Slope at last way point is v[n] - v[n-1].
// Otherwise slope at way point i is 0.5*(v[i+1] - v[i-1]).
// Result = h00*v[i] + h10*m[i] + h01*v[i+1] + h11*m[i+1],
// where m[i] amd m[i+1] are the slopes at the start and end
// of the interval for the particular value.
// If (n == 1), linear interpolation results.
// If (n == 2), quadratic interpolation results.
// Working variables
G4double mi, mi1, real, x, y, z;
// First, a crude interpolation of all parameters. Then, below, a
// smooth interpolation of those for which it makes sense.
holdingValues = t < 0.5? v[i]: v[i+1];
// Catmull-Rom cubic spline interpolation
#define INTERPOLATE(param) \
/* This works out the interpolated param in i'th interval */ \
/* Assumes n >= 1 */ \
if (i == 0) { \
/* First interval */ \
mi = v[1].param - v[0].param; \
/* If there is only one interval, make start and end slopes equal */ \
/* (This results in a linear interpolation) */ \
if (n == 1) mi1 = mi; \
/* else the end slope of the interval takes account of the next waypoint along */ \
else mi1 = 0.5 * (v[2].param - v[0].param); \
} else if (i >= n - 1) { \
/* Similarly for last interval */ \
mi1 = v[i+1].param - v[i].param; \
/* If there is only one interval, make start and end slopes equal */ \
if (n == 1) mi = mi1; \
/* else the start slope of the interval takes account of the previous waypoint */ \
else mi = 0.5 * (v[i+1].param - v[i-1].param); \
} else { \
/* Full Catmull-Rom slopes use previous AND next waypoints */ \
mi = 0.5 * (v[i+1].param - v[i-1].param); \
mi1 = 0.5 * (v[i+2].param - v[i ].param); \
} \
real = h00 * v[i].param + h10 * mi + h01 * v[i+1].param + h11 * mi1;
// Real parameters
INTERPOLATE(fVisibleDensity);
if (real < 0.) real = 0.;
holdingValues.fVisibleDensity = real;
INTERPOLATE(fExplodeFactor);
if (real < 0.) real = 0.;
holdingValues.fExplodeFactor = real;
INTERPOLATE(fFieldHalfAngle);
if (real < 0.) real = 0.;
holdingValues.fFieldHalfAngle = real;
INTERPOLATE(fZoomFactor);
if (real < 0.) real = 0.;
holdingValues.fZoomFactor = real;
INTERPOLATE(fDolly);
holdingValues.fDolly = real;
INTERPOLATE(fGlobalMarkerScale);
if (real < 0.) real = 0.;
holdingValues.fGlobalMarkerScale = real;
INTERPOLATE(fGlobalLineWidthScale);
if (real < 0.) real = 0.;
holdingValues.fGlobalLineWidthScale = real;
// Unit vectors
#define INTERPOLATEUNITVECTOR(vector) \
INTERPOLATE(vector.x()); x = real; \
INTERPOLATE(vector.y()); y = real; \
INTERPOLATE(vector.z()); z = real;
INTERPOLATEUNITVECTOR(fViewpointDirection);
holdingValues.fViewpointDirection = G4Vector3D(x,y,z).unit();
INTERPOLATEUNITVECTOR(fUpVector);
holdingValues.fUpVector = G4Vector3D(x,y,z).unit();
INTERPOLATEUNITVECTOR(fRelativeLightpointDirection);
holdingValues.fRelativeLightpointDirection = G4Vector3D(x,y,z).unit();
INTERPOLATEUNITVECTOR(fActualLightpointDirection);
holdingValues.fActualLightpointDirection = G4Vector3D(x,y,z).unit();
// Un-normalised vectors
#define INTERPOLATEVECTOR(vector) \
INTERPOLATE(vector.x()); x = real; \
INTERPOLATE(vector.y()); y = real; \
INTERPOLATE(vector.z()); z = real;
INTERPOLATEVECTOR(fScaleFactor);
holdingValues.fScaleFactor = G4Vector3D(x,y,z);
// Points
#define INTERPOLATEPOINT(point) \
INTERPOLATE(point.x()); x = real; \
INTERPOLATE(point.y()); y = real; \
INTERPOLATE(point.z()); z = real;
INTERPOLATEPOINT(fExplodeCentre);
holdingValues.fExplodeCentre = G4Point3D(x,y,z);
INTERPOLATEPOINT(fCurrentTargetPoint);
holdingValues.fCurrentTargetPoint = G4Point3D(x,y,z);
// Colour
G4double red, green, blue, alpha;
#define INTERPOLATECOLOUR(colour) \
INTERPOLATE(colour.GetRed()); red = real; \
INTERPOLATE(colour.GetGreen()); green = real; \
INTERPOLATE(colour.GetBlue()); blue = real; \
INTERPOLATE(colour.GetAlpha()); alpha = real;
INTERPOLATECOLOUR(fBackgroundColour);
// Components are clamped to 0. <= component <= 1.
holdingValues.fBackgroundColour = G4Colour(red,green,blue,alpha);
// For some parameters we need to check some continuity
G4bool continuous;
#define CONTINUITY(quantity) \
continuous = false; \
/* This follows the logic of the INTERPOLATE macro above; see comments therein */ \
if (i == 0) { \
if (v[1].quantity == v[0].quantity) { \
if (n == 1) continuous = true; \
else if (v[2].quantity == v[0].quantity) \
continuous = true; \
} \
} else if (i >= n - 1) { \
if (v[i+1].quantity == v[i].quantity) { \
if (n == 1) continuous = true; \
else if (v[i+1].quantity == v[i-1].quantity) \
continuous = true; \
} \
} else { \
if (v[i-1].quantity == v[i].quantity && \
v[i+1].quantity == v[i].quantity && \
v[i+2].quantity == v[i].quantity) \
continuous = true; \
}
G4double a, b, c, d;
#define INTERPOLATEPLANE(plane) \
INTERPOLATE(plane.a()); a = real; \
INTERPOLATE(plane.b()); b = real; \
INTERPOLATE(plane.c()); c = real; \
INTERPOLATE(plane.d()); d = real;
// Section plane
CONTINUITY(fSection);
if (continuous) {
INTERPOLATEPLANE(fSectionPlane);
holdingValues.fSectionPlane = G4Plane3D(a,b,c,d);
}
// Cutaway planes
if (v[i].fCutawayPlanes.size()) {
CONTINUITY(fCutawayPlanes.size());
if (continuous) {
for (size_t j = 0; j < v[i].fCutawayPlanes.size(); ++j) {
INTERPOLATEPLANE(fCutawayPlanes[j]);
holdingValues.fCutawayPlanes[j] = G4Plane3D(a,b,c,d);
}
}
}
// Vis attributes modifiers
// Really, we are only intersted in colour - other attributes can follow
// the "crude" interpolation that is guaranteed above.
if (v[i].fVisAttributesModifiers.size()) {
CONTINUITY(fVisAttributesModifiers.size());
if (continuous) { \
for (size_t j = 0; j < v[i].fVisAttributesModifiers.size(); ++j) { \
CONTINUITY(fVisAttributesModifiers[j].GetPVNameCopyNoPath());
if (continuous) {
CONTINUITY(fVisAttributesModifiers[j].GetVisAttributesSignifier());
if (continuous) {
if (v[i].fVisAttributesModifiers[j].GetVisAttributesSignifier() ==
G4ModelingParameters::VASColour) {
INTERPOLATECOLOUR(fVisAttributesModifiers[j].GetVisAttributes().GetColour());
G4VisAttributes workingVA = v[i].fVisAttributesModifiers[j].GetVisAttributes();
workingVA.SetColour(G4Colour(red,green,blue,alpha));
holdingValues.fVisAttributesModifiers[j].SetVisAttributes(workingVA);
}
}
}
}
}
}
// Increment counters
iInterpolationPoint++;
t += dt;
if (iInterpolationPoint > nInterpolationPoints) {
iInterpolationPoint = 1; // Ready for next interval.
t = dt;
iInterval++;
}
if (iInterval >= nIntervals) {
iInterpolationPoint = 0; // Ready for a complete restart.
t = 0.;
iInterval = 0;
return 0;
}
return &holdingValues;
}
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VisCommandsCompound.cc 91686 2015-07-31 09:40:08Z gcosmo $
// $Id: G4VisCommandsCompound.cc 95006 2016-01-15 08:26:18Z gcosmo $
// Compound /vis/ commands - John Allison 15th May 2000
@@ -35,6 +35,7 @@
#include "G4UIcmdWithAString.hh"
#include <sstream>
#include <set>
////////////// /vis/drawTree ///////////////////////////////////////
@@ -64,6 +65,20 @@ void G4VisCommandDrawTree::SetNewValue(G4UIcommand*, G4String newValue) {
std::istringstream is(newValue);
is >> pvname >> system;
// Note: The second parameter, "system", is intended to allow the user
// a choice of dedicated tree printing/displaying systems but at present
// the only such dedicated system is ASCIITree. It doesn't make sense to
// specify OGLSX, for example. So to avoid confusion we restrict this
// feature to systems that have "Tree" in the name or nickname.
// Of course, some other systems, such as OGLSQt, have a tree browser
// built-in. The HepRApp offline browser also has a tree browser
// built in.
if (!system.contains("Tree")) {
system = "ATree";
}
G4VGraphicsSystem* keepSystem = fpVisManager->GetCurrentGraphicsSystem();
G4Scene* keepScene = fpVisManager->GetCurrentScene();
G4VSceneHandler* keepSceneHandler = fpVisManager->GetCurrentSceneHandler();
@@ -77,19 +92,20 @@ void G4VisCommandDrawTree::SetNewValue(G4UIcommand*, G4String newValue) {
newVerbose = 2;
UImanager->SetVerboseLevel(newVerbose);
UImanager->ApplyCommand(G4String("/vis/open " + system));
UImanager->ApplyCommand(G4String("/vis/drawVolume " + pvname));
UImanager->ApplyCommand("/vis/viewer/flush");
UImanager->SetVerboseLevel(keepVerbose);
if (keepViewer) {
if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) {
G4cout << "Reverting to " << keepViewer->GetName() << G4endl;
if (fErrorCode == 0) {
UImanager->ApplyCommand(G4String("/vis/drawVolume " + pvname));
UImanager->ApplyCommand("/vis/viewer/flush");
if (keepViewer) {
if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) {
G4cout << "Reverting to " << keepViewer->GetName() << G4endl;
}
fpVisManager->SetCurrentGraphicsSystem(keepSystem);
fpVisManager->SetCurrentScene(keepScene);
fpVisManager->SetCurrentSceneHandler(keepSceneHandler);
fpVisManager->SetCurrentViewer(keepViewer);
}
fpVisManager->SetCurrentGraphicsSystem(keepSystem);
fpVisManager->SetCurrentScene(keepScene);
fpVisManager->SetCurrentSceneHandler(keepSceneHandler);
fpVisManager->SetCurrentViewer(keepViewer);
}
UImanager->SetVerboseLevel(keepVerbose);
}
////////////// /vis/drawView ///////////////////////////////////////
@@ -195,8 +211,8 @@ G4VisCommandDrawVolume::G4VisCommandDrawVolume() {
"\nworld and parallel worlds, if any - are drawn. Otherwise a search of"
"\nall worlds is made, taking the first matching occurence only. To see"
"\na representation of the geometry hierarchy of the worlds, try"
"\n\"/vis/drawTree [worlds]\" or one of the driver/browser combinations"
"\nthat have the required functionality, e.g., HepRep");
"\n\"/vis/drawTree worlds\" or one of the driver/browser combinations"
"\nthat have the required functionality, e.g., HepRepFile/HepRApp.");
fpCommand->SetParameterName("physical-volume-name", omitable = true);
fpCommand->SetDefaultValue("world");
}
@@ -262,8 +278,26 @@ void G4VisCommandOpen::SetNewValue (G4UIcommand*, G4String newValue) {
fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
newVerbose = 2;
UImanager->SetVerboseLevel(newVerbose);
UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName));
UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint));
fErrorCode = UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName));
if (fErrorCode == 0) {
UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint));
} else {
// Use set to get alphabetical order
std::set<G4String> candidates;
for (const auto gs: fpVisManager -> GetAvailableGraphicsSystems()) {
// Just list nicknames, but exclude FALLBACK nicknames
for (const auto& nickname: gs->GetNicknames()) {
if (!nickname.contains("FALLBACK")) {
candidates.insert(nickname);
}
}
}
G4cerr << "Candidates are:";
for (const auto& candidate: candidates) {
G4cerr << ' ' << candidate;
}
G4cerr << G4endl;
}
UImanager->SetVerboseLevel(keepVerbose);
}
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VisCommandsSceneAdd.cc 93069 2015-10-02 09:54:27Z gcosmo $
// $Id: G4VisCommandsSceneAdd.cc 96733 2016-05-02 11:52:48Z gcosmo $
// /vis/scene/add commands - John Allison 9th August 1998
#include "G4VisCommandsSceneAdd.hh"
@@ -1421,13 +1421,16 @@ void G4VisCommandSceneAddLogo::SetNewValue (G4UIcommand*, G4String newValue) {
switch (logoDirection) {
case X:
case minusX:
if (freeHeightFraction * (xmax - xmin) < height) room = false; break;
if (freeHeightFraction * (xmax - xmin) < height) room = false;
break;
case Y:
case minusY:
if (freeHeightFraction * (ymax - ymin) < height) room = false; break;
if (freeHeightFraction * (ymax - ymin) < height) room = false;
break;
case Z:
case minusZ:
if (freeHeightFraction * (zmax - zmin) < height) room = false; break;
if (freeHeightFraction * (zmax - zmin) < height) room = false;
break;
}
if (!room) {
worried = true;
@@ -2029,11 +2032,14 @@ void G4VisCommandSceneAddScale::SetNewValue (G4UIcommand*, G4String newValue) {
G4bool room = true;
switch (scaleDirection) {
case G4Scale::x:
if (freeLengthFraction * (xmax - xmin) < length) room = false; break;
if (freeLengthFraction * (xmax - xmin) < length) room = false;
break;
case G4Scale::y:
if (freeLengthFraction * (ymax - ymin) < length) room = false; break;
if (freeLengthFraction * (ymax - ymin) < length) room = false;
break;
case G4Scale::z:
if (freeLengthFraction * (zmax - zmin) < length) room = false; break;
if (freeLengthFraction * (zmax - zmin) < length) room = false;
break;
}
if (!room) {
worried = true;
@@ -2826,6 +2832,7 @@ void G4VisCommandSceneAddVolume::SetNewValue (G4UIcommand*,
}
}
// Get the world (the initial value of the iterator points to the mass world).
G4VPhysicalVolume* world = *(transportationManager->GetWorldsIterator());
if (!world) {
@@ -2839,32 +2846,6 @@ void G4VisCommandSceneAddVolume::SetNewValue (G4UIcommand*,
return;
}
const std::vector<G4Scene::Model>& rdModelList = pScene -> GetRunDurationModelList();
std::vector<G4Scene::Model>::const_iterator it;
for (it = rdModelList.begin(); it != rdModelList.end(); ++it) {
if (it->fpModel->GetGlobalDescription().find("G4PhysicalVolumeModel")
!= std::string::npos) {
if (((G4PhysicalVolumeModel*)(it->fpModel))->GetTopPhysicalVolume () == world) break;
}
}
if (it != rdModelList.end()) {
if (verbosity >= G4VisManager::warnings) {
G4cout << "WARNING: There is already a volume, \""
<< it -> fpModel -> GetGlobalDescription()
<< "\",\n in the run-duration model list of scene \""
<< pScene -> GetName()
<< "\".\n To get a clean scene:"
<< "\n /vis/drawVolume " << name
<< "\n or"
<< "\n /vis/scene/create"
<< "\n /vis/scene/add/volume " << name
<< "\n /vis/sceneHandler/attach"
<< "\n (and also, if necessary, /vis/viewer/flush)"
<< G4endl;
}
return;
}
std::vector<G4PhysicalVolumeModel*> models;
std::vector<G4VPhysicalVolume*> foundVolumes;
G4VPhysicalVolume* foundWorld = 0;
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VisCommandsSceneHandler.cc 91721 2015-08-03 12:06:54Z gcosmo $
// $Id: G4VisCommandsSceneHandler.cc 95006 2016-01-15 08:26:18Z gcosmo $
// /vis/sceneHandler commands - John Allison 10th October 1998
@@ -150,11 +150,12 @@ G4VisCommandSceneHandlerCreate::G4VisCommandSceneHandlerCreate (): fId (0) {
const G4GraphicsSystemList& gslist =
fpVisManager -> GetAvailableGraphicsSystems ();
G4String candidates;
for (auto&& gs: gslist) {
for (const auto gs: gslist) {
const G4String& name = gs -> GetName ();
candidates += name + ' ';
for (auto&& nickname: gs -> GetNicknames ())
candidates += nickname + ' ';
for (const auto& nickname: gs -> GetNicknames ()) {
if (nickname != name) candidates += nickname + ' ';
}
}
candidates = candidates.strip ();
parameter -> SetParameterCandidates(candidates);
@@ -34,14 +34,14 @@
#include "G4TransportationManager.hh"
#include "G4TouchableDumpScene.hh"
////////////// /vis/touchable/dump ///////////////////////////////////////
G4VisCommandsTouchable::G4VisCommandsTouchable()
{
fpCommandDump = new G4UIcmdWithoutParameter("/vis/touchable/dump",this);
fpCommandDump->SetGuidance("Dump touchable attributes.");
fpCommandDump->SetGuidance
("Use \"/vis/set/touchable\" to set current touchable.");
fpCommandDump->SetGuidance
("Use \"/vis/touchable/set\" to set attributes.");
}
G4VisCommandsTouchable::~G4VisCommandsTouchable() {
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4VisCommandsViewer.cc 93303 2015-10-15 15:19:40Z gcosmo $
// $Id: G4VisCommandsViewer.cc 97316 2016-06-01 12:12:58Z gcosmo $
// /vis/viewer commands - John Allison 25th October 1998
@@ -41,10 +41,17 @@
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWith3Vector.hh"
#include "G4Point3D.hh"
#include "G4SystemOfUnits.hh"
#include "G4UnitsTable.hh"
#include "G4ios.hh"
#ifdef G4VIS_USE_STD11
#include <chrono>
#include <thread>
#endif
#include <sstream>
#include <fstream>
#include <sstream>
#include <iomanip>
G4VVisCommandViewer::G4VVisCommandViewer () {}
@@ -275,6 +282,7 @@ void G4VisCommandViewerClear::SetNewValue (G4UIcommand*, G4String newValue) {
return;
}
viewer->SetView();
viewer->ClearView();
viewer->FinishView();
if (verbosity >= G4VisManager::confirmations) {
@@ -372,6 +380,47 @@ void G4VisCommandViewerClearTransients::SetNewValue (G4UIcommand*, G4String newV
}
////////////// /vis/viewer/clearVisAttributesModifiers ///////////////////////////////////////
G4VisCommandViewerClearVisAttributesModifiers::G4VisCommandViewerClearVisAttributesModifiers () {
fpCommand = new G4UIcmdWithoutParameter
("/vis/viewer/clearVisAttributesModifiers", this);
fpCommand -> SetGuidance ("Clear vis attribute modifiers of current viewer.");
fpCommand -> SetGuidance ("(These are used for touchables, etc.)");
}
G4VisCommandViewerClearVisAttributesModifiers::~G4VisCommandViewerClearVisAttributesModifiers () {
delete fpCommand;
}
G4String G4VisCommandViewerClearVisAttributesModifiers::GetCurrentValue (G4UIcommand*) {
return "";
}
void G4VisCommandViewerClearVisAttributesModifiers::SetNewValue (G4UIcommand*, G4String) {
G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
if (!viewer) {
if (verbosity >= G4VisManager::errors) {
G4cerr <<
"ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
<< G4endl;
}
return;
}
G4ViewParameters vp = viewer->GetViewParameters();
vp.ClearVisAttributesModifiers();
if (verbosity >= G4VisManager::confirmations) {
G4cout << "Vis attributes modifiers for viewer \"" << viewer->GetName()
<< "\" now cleared." << G4endl;
}
SetViewParameters(viewer, vp);
}
////////////// /vis/viewer/clone ///////////////////////////////////////
G4VisCommandViewerClone::G4VisCommandViewerClone () {
@@ -907,6 +956,182 @@ void G4VisCommandViewerFlush::SetNewValue (G4UIcommand*, G4String newValue) {
}
}
////////////// /vis/viewer/interpolate ///////////////////////////////////////
#ifndef WIN32
// popen is not available in Windows. _popen is said to be available in
// Windows but this has not been tried.
G4VisCommandViewerInterpolate::G4VisCommandViewerInterpolate () {
G4bool omitable;
fpCommand = new G4UIcommand ("/vis/viewer/interpolate", this);
fpCommand -> SetGuidance
("Interpolate views defined by the first argument, which can contain "
"Unix-shell-style pattern matching characters such as '*', '?' and '[' "
"- see \"man sh\" and look for \"Pattern Matching\". The contents "
"of each file are assumed to be \"/vis/viewer\" commands "
"that specify a particular view. The files are processed in alphanumeric "
"order of filename. The files may be written by hand or produced by the "
"\"/vis/viewer/save\" command.");
fpCommand -> SetGuidance
("The default is to search the working directory for files with a .view "
"extension. Another procedure is to assemble view files in a subdirectory, "
"e.g., \"myviews\"; then they can be interpolated with\n"
"\"/vis/viewer/interpolate myviews/*\".");
fpCommand -> SetGuidance
("To export interpolated views to file for a future possible movie, "
"write \"export\" as 5th parameter (OpenGL only).");
G4UIparameter* parameter;
parameter = new G4UIparameter("pattern", 's', omitable = true);
parameter -> SetGuidance("Pattern that defines the view files.");
parameter -> SetDefaultValue("*.view");
fpCommand -> SetParameter(parameter);
parameter = new G4UIparameter("no-of-points", 'i', omitable = true);
parameter -> SetGuidance ("Number of interpolation points per interval.");
parameter -> SetDefaultValue(50);
fpCommand -> SetParameter(parameter);
parameter = new G4UIparameter("wait-time", 's', omitable = true);
parameter -> SetGuidance("Wait time per interpolated point");
parameter -> SetDefaultValue("20.");
fpCommand -> SetParameter(parameter);
parameter = new G4UIparameter("time-unit", 's', omitable = true);
parameter -> SetDefaultValue("millisecond");
fpCommand -> SetParameter (parameter);
parameter = new G4UIparameter("export", 's', omitable = true);
parameter -> SetDefaultValue("no");
fpCommand -> SetParameter (parameter);
}
G4VisCommandViewerInterpolate::~G4VisCommandViewerInterpolate () {
delete fpCommand;
}
G4String G4VisCommandViewerInterpolate::GetCurrentValue (G4UIcommand*) {
return "";
}
void G4VisCommandViewerInterpolate::SetNewValue (G4UIcommand*, G4String newValue) {
G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
G4String pattern;
G4int nInterpolationPoints;
G4String waitTimePerPointString;
G4String timeUnit;
G4String exportString;
std::istringstream iss (newValue);
iss
>> pattern
>> nInterpolationPoints
>> waitTimePerPointString
>> timeUnit
>> exportString;
const G4double waitTimePerPoint =
G4UIcommand::ConvertToDimensionedDouble((waitTimePerPointString + ' ' + timeUnit).c_str());
G4int waitTimePerPointmilliseconds = waitTimePerPoint/millisecond;
if (waitTimePerPointmilliseconds < 0) waitTimePerPointmilliseconds = 0;
// Execute pattern and get resulting list of filles
G4String shellCommand = "echo " + pattern;
FILE *filelist = popen(shellCommand.c_str(), "r");
if (!filelist) {
if (verbosity >= G4VisManager::errors) {
G4cerr
<< "ERROR: G4VisCommandViewerInterpolate::SetNewValue:"
<< "\n Error obtaining pipe."
<< G4endl;
}
return;
}
G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
if (!currentViewer) {
if (verbosity >= G4VisManager::errors) {
G4cerr <<
"ERROR: G4VisCommandViewerInterpolate::SetNewValue: no current viewer."
<< G4endl;
}
return;
}
// Save current view parameters
G4ViewParameters saveVP = currentViewer->GetViewParameters();
// Save current verbosities
G4VisManager::Verbosity keepVisVerbosity = fpVisManager->GetVerbosity();
G4UImanager* ui = G4UImanager::GetUIpointer();
G4int keepUIVerbosity = ui->GetVerboseLevel();
// Set verbosities for this operation
fpVisManager->SetVerboseLevel(G4VisManager::errors);
ui->SetVerboseLevel(0);
// Switch off auto-refresh (it will be restored later)
// Note: the view files do not set autoRefresh.
G4ViewParameters non_auto = saveVP;
non_auto.SetAutoRefresh(false);
currentViewer->SetViewParameters(non_auto);
// Build view vector of way points
std::vector<G4ViewParameters> viewVector;
const size_t BUFLENGTH = 999999;
char buf[BUFLENGTH];
fgets(buf, BUFLENGTH, filelist);
std::istringstream fileliststream(buf);
const G4int safety = 9999;
G4int safetyCount = 0;
G4String pathname;
while (fileliststream >> pathname
&& safetyCount++ < safety) { // Loop checking, 16.02.2016, J.Allison
ui->ApplyCommand("/control/execute " + pathname);
viewVector.push_back(currentViewer->GetViewParameters());
}
if (safetyCount >= safety) {
if (verbosity >= G4VisManager::errors) {
G4cout <<
"/vis/viewer/interpolate:"
"\n the number of way points exceeds the maximum currently allowed: "
<< safety << G4endl;
}
return;
}
// Interpolate views
safetyCount = 0;
do {
G4ViewParameters* vp =
G4ViewParameters::CatmullRomCubicSplineInterpolation(viewVector,nInterpolationPoints);
if (!vp) break;
currentViewer->SetViewParameters(*vp);
currentViewer->RefreshView();
if (exportString == "export" &&
currentViewer->GetName().contains("OpenGL"))
ui->ApplyCommand("/vis/ogl/export");
#ifdef G4VIS_USE_STD11
if (waitTimePerPointmilliseconds > 0)
std::this_thread::sleep_for(std::chrono::milliseconds(waitTimePerPointmilliseconds));
#endif
} while (safetyCount++ < safety); // Loop checking, 16.02.2016, J.Allison
// Restore original verbosities
ui->SetVerboseLevel(keepUIVerbosity);
fpVisManager->SetVerboseLevel(keepVisVerbosity);
// Restore original view parameters
currentViewer->SetViewParameters(saveVP);
currentViewer->RefreshView();
if (verbosity >= G4VisManager::confirmations) {
G4cout << "Viewer \"" << currentViewer -> GetName () << "\""
<< " restored." << G4endl;
}
pclose(filelist);
}
#endif // WIN32 - popen is not available in Windows. _popen is there but not tried.
////////////// /vis/viewer/list ///////////////////////////////////////
G4VisCommandViewerList::G4VisCommandViewerList () {
@@ -1316,9 +1541,19 @@ G4VisCommandViewerSave::G4VisCommandViewerSave () {
fpCommand -> SetGuidance
("Write commands that define the current view to file.");
fpCommand -> SetGuidance
("Read them back into the same or any viewer with \"/control/execute <filename>\".");
fpCommand -> SetParameterName ("file-name", omitable = true);
fpCommand -> SetDefaultValue ("G4cout");
("Read them back into the same or any viewer with \"/control/execute\".");
fpCommand -> SetGuidance
("If the filename is omitted the view is saved to a file "
"\"g4_nn.view\", where nn is a sequential two-digit number.");
fpCommand -> SetGuidance
("If the filename is \"-\", the data are written to G4cout.");
fpCommand -> SetGuidance
("If you are wanting to save views for future interpolation a recommended "
"procedure is: save views to \"g4_nn.view\", as above, then move the files "
"into a sub-directory, say, \"views\", then interpolate with"
"\"/vis/viewer/interpolate views/\" (note the trailing \'/\').");
fpCommand -> SetParameterName ("filename", omitable = true);
fpCommand -> SetDefaultValue ("");
}
G4VisCommandViewerSave::~G4VisCommandViewerSave () {
@@ -1334,7 +1569,7 @@ namespace {
void WriteCommands
(std::ostream& os,
const G4ViewParameters& vp,
const G4Point3D& stp)
const G4Point3D& stp) // Standard Target Point
{
os
<< vp.CameraAndLightingCommands(stp)
@@ -1368,38 +1603,12 @@ void G4VisCommandViewerSave::SetNewValue (G4UIcommand*, G4String newValue) {
}
return;
}
std::ofstream ofs;
if (newValue != "G4cout") {
// Check if file exists
std::ifstream ifs(newValue);
if (ifs) {
if (verbosity >= G4VisManager::errors) {
G4cerr <<
"ERROR: G4VisCommandsViewerSave::SetNewValue: File \""
<< newValue << "\" already exists."
<< G4endl;
}
ifs.close();
return;
}
ofs.open(newValue);
if (!ofs) {
if (verbosity >= G4VisManager::errors) {
G4cerr <<
"ERROR: G4VisCommandsViewerSave::SetNewValue: Trouble opening file \""
<< newValue << "\"."
<< G4endl;
}
ofs.close();
return;
}
}
// Get view parameters and ther relevant information.
G4ViewParameters vp = currentViewer->GetViewParameters();
// Concatenate any private vis attributes modifiers...
const std::vector<G4ModelingParameters::VisAttributesModifier>*
privateVAMs = currentViewer->GetPrivateVisAttributesModifiers();
privateVAMs = currentViewer->GetPrivateVisAttributesModifiers();
if (privateVAMs) {
std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator i;
for (i = privateVAMs->begin(); i != privateVAMs->end(); ++i) {
@@ -1407,23 +1616,58 @@ void G4VisCommandViewerSave::SetNewValue (G4UIcommand*, G4String newValue) {
}
}
const G4Point3D& stp = currentScene->GetStandardTargetPoint();
if (newValue == "G4cout") {
G4String filename = newValue;
if (newValue.length() == 0) {
// Null filename - generate a filename
const G4int maxNoOfFiles = 100;
static G4int sequenceNumber = 0;
if (sequenceNumber >= maxNoOfFiles) {
if (verbosity >= G4VisManager::errors) {
G4cerr
<< "ERROR: G4VisCommandsViewerSave::SetNewValue: Maximum number, "
<< maxNoOfFiles
<< ", of files exceeded."
<< G4endl;
}
return;
}
std::ostringstream oss;
oss << std::setw(2) << std::setfill('0') << sequenceNumber++;
filename = "g4_" + oss.str() + ".view";
}
if (filename == "-") {
// Write to standard output
WriteCommands(G4cout,vp,stp);
} else {
// Write to file
std::ofstream ofs(filename);
if (!ofs) {
if (verbosity >= G4VisManager::errors) {
G4cerr <<
"ERROR: G4VisCommandsViewerSave::SetNewValue: Trouble opening file \""
<< filename << "\"."
<< G4endl;
}
ofs.close();
return;
}
WriteCommands(ofs,vp,stp);
ofs.close();
}
if (verbosity >= G4VisManager::confirmations) {
if (verbosity >= G4VisManager::warnings) {
G4cout << "Viewer \"" << currentViewer -> GetName ()
<< "\"" << " saved to ";
if (newValue == "G4cout") {
if (filename == "-") {
G4cout << "G4cout.";
} else {
G4cout << "file \'" << newValue << "\"." <<
"\n Read view parameters back into this or any viewer with"
"\n \"/control/execute " << newValue << "\"";
G4cout << "file \'" << filename << "\"." <<
"\n Read the view back into this or any viewer with"
"\n \"/control/execute " << filename << "\" or use"
"\n \"/vis/viewer/interpolate\" if you have several saved files -"
"\n see \"help /vis/viewer/interpolate\" for guidance.";
}
G4cout << G4endl;
}
@@ -1553,7 +1797,8 @@ void G4VisCommandViewerSelect::SetNewValue (G4UIcommand*, G4String newValue) {
return;
}
fpVisManager -> SetCurrentViewer (viewer); // Prints confirmation.
// Set pointers, call SetView and print confirmation.
fpVisManager -> SetCurrentViewer (viewer);
RefreshIfRequired(viewer);
}
@@ -23,17 +23,13 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4VisManager.cc 94688 2015-12-02 17:15:08Z gunter $
// $Id: G4VisManager.cc 97388 2016-06-02 10:04:52Z gcosmo $
//
//
// GEANT4 Visualization Manager - John Allison 02/Jan/1996.
#include "G4VisManager.hh"
#ifndef __MIC__
#define G4VIS_USE_STD11
#endif
#include "G4VisCommands.hh"
#include "G4VisCommandsCompound.hh"
#include "G4VisCommandsGeometry.hh"
@@ -271,7 +267,7 @@ void G4VisManager::Initialise () {
"\n external packages or libraries, and, optionally, drivers under"
"\n control of environment variables."
"\n Also you should implement RegisterModelFactories()."
"\n See visualization/include/G4VisExecutive.hh/icc, for example."
"\n See visualization/management/include/G4VisExecutive.hh/icc, for example."
"\n In your main() you will have something like:"
"\n #ifdef G4VIS_USE"
"\n G4VisManager* visManager = new G4VisExecutive;"
@@ -488,11 +484,15 @@ void G4VisManager::RegisterMessengers () {
RegisterMessenger(new G4VisCommandViewerClear);
RegisterMessenger(new G4VisCommandViewerClearCutawayPlanes);
RegisterMessenger(new G4VisCommandViewerClearTransients);
RegisterMessenger(new G4VisCommandViewerClearVisAttributesModifiers);
RegisterMessenger(new G4VisCommandViewerClone);
RegisterMessenger(new G4VisCommandViewerCopyViewFrom);
RegisterMessenger(new G4VisCommandViewerCreate);
RegisterMessenger(new G4VisCommandViewerDolly);
RegisterMessenger(new G4VisCommandViewerFlush);
#ifndef WIN32
RegisterMessenger(new G4VisCommandViewerInterpolate);
#endif
RegisterMessenger(new G4VisCommandViewerList);
RegisterMessenger(new G4VisCommandViewerPan);
RegisterMessenger(new G4VisCommandViewerRebuild);
@@ -621,11 +621,10 @@ G4VisManager::CurrentTrajDrawModel() const
if (0 == model) {
// No model was registered with the trajectory model manager.
// Use G4TrajectoryDrawByCharge as a default.
fpTrajDrawModelMgr->Register(new G4TrajectoryDrawByCharge("AutoGenerated"));
// Use G4TrajectoryDrawByCharge as a fallback.
fpTrajDrawModelMgr->Register(new G4TrajectoryDrawByCharge("DefaultModel"));
if (fVerbosity >= warnings) {
G4cout<<"G4VisManager: Using G4TrajectoryDrawByCharge as default trajectory model."<<G4endl;
G4cout<<"G4VisManager: Using G4TrajectoryDrawByCharge as fallback trajectory model."<<G4endl;
G4cout<<"See commands in /vis/modeling/trajectories/ for other options."<<G4endl;
}
}
@@ -636,7 +635,7 @@ G4VisManager::CurrentTrajDrawModel() const
return model;
}
void G4VisManager::RegisterModel(G4VTrajectoryModel* model)
void G4VisManager::RegisterModel(G4VTrajectoryModel* model)
{
fpTrajDrawModelMgr->Register(model);
}
@@ -1422,6 +1421,7 @@ void G4VisManager::SetCurrentViewer (G4VViewer* pViewer) {
}
return;
}
fpViewer->SetView();
fpSceneHandler -> SetCurrentViewer (pViewer);
fpScene = fpSceneHandler -> GetScene ();
fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem ();
@@ -1615,8 +1615,13 @@ G4ThreadFunReturnType G4VisManager::G4VisSubThread(G4ThreadFunArgType p)
// G4cout << "G4VisManager::G4VisSubThread: thread: "
// << G4Threading::G4GetThreadId() << std::endl;
// Set up geometry and navigation for a thread
G4GeometryWorkspacePool::GetInstance()->CreateAndUseWorkspace();
G4SolidsWorkspacePool::GetInstance()->CreateAndUseWorkspace();
G4Navigator* navigator =
G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
navigator->SetWorldVolume
(G4MTRunManager::GetMasterRunManagerKernel()->GetCurrentWorld());
pViewer->SwitchToVisSubThread();
@@ -1657,11 +1662,9 @@ G4ThreadFunReturnType G4VisManager::G4VisSubThread(G4ThreadFunArgType p)
if (pScene->GetRefreshAtEndOfEvent()) {
// ShowView guarantees the view comes to the screen. No action
// is taken for passive viewers like OGL*X (without picking enabled),
// but it passes control to interactive viewers, such as OGL*X (with
// picking enabled) or OGL*Xm, and allows file-writing viewers to
// close the file.
// ShowView guarantees the view is flushed to the screen. It also
// triggers other features such picking (if enabled) and allows
// file-writing viewers to close the file.
pViewer->ShowView();
pSceneHandler->SetMarkForClearingTransientStore(true);
@@ -1682,7 +1685,11 @@ G4ThreadFunReturnType G4VisManager::G4VisSubThread(G4ThreadFunArgType p)
G4MUTEXLOCK(&mtVisSubThreadMutex);
G4int runInProgress = mtRunInProgress;
G4MUTEXUNLOCK(&mtVisSubThreadMutex);
if (!runInProgress) break;
if (!runInProgress) {
// EndOfRun on master thread has signalled end of run. There is
// nothing to draw so...
break;
}
// Run still in progress but nothing to draw, so wait a while.
#ifdef G4VIS_USE_STD11
@@ -1692,7 +1699,22 @@ G4ThreadFunReturnType G4VisManager::G4VisSubThread(G4ThreadFunArgType p)
#endif
}
// Inform viewer that we have finished all sub-thread drawing for now...
// EndOfRun on master thread has signalled end of run
if (pScene->GetRefreshAtEndOfRun()) {
pSceneHandler->DrawEndOfRunModels();
// ShowView guarantees the view is flushed to the screen. It also
// triggers other features such picking (if enabled) and allows
// file-writing viewers to close the file.
pViewer->ShowView();
// An extra refresh for auto-refresh viewers.
// ???? I DON'T THINK THIS IS NECESSARY ???? JA ????
// if (pViewer->GetViewParameters().IsAutoRefresh()) {
// pViewer->RefreshView();
// }
pSceneHandler->SetMarkForClearingTransientStore(true);
}
// Inform viewer that we have finished all sub-thread drawing
pViewer->DoneWithVisSubThread();
pViewer->MovingToMasterThread();
// G4cout << "G4VisManager::G4VisSubThread: Vis sub-thread: ending" << G4endl;
@@ -1711,6 +1733,9 @@ namespace {
void G4VisManager::BeginOfRun ()
{
if (fIgnoreStateChanges) return;
if (!GetConcreteInstance()) return;
#ifdef G4MULTITHREADED
if (G4Threading::IsWorkerThread()) return;
#endif
@@ -1768,6 +1793,9 @@ void G4VisManager::BeginOfRun ()
void G4VisManager::BeginOfEvent ()
{
if (fIgnoreStateChanges) return;
if (!GetConcreteInstance()) return;
// G4cout << "G4VisManager::BeginOfEvent: thread: "
// << G4Threading::G4GetThreadId() << G4endl;
@@ -1927,11 +1955,9 @@ void G4VisManager::EndOfEvent ()
// Unless last event (in which case wait end of run)...
if (eventID < nEventsToBeProcessed - 1) {
// ShowView guarantees the view comes to the screen. No action
// is taken for passive viewers like OGL*X (without picking enabled),
// but it passes control to interactive viewers, such as OGL*X (with
// picking enabled) or OGL*Xm, and allows file-writing viewers to
// close the file.
// ShowView guarantees the view is flushed to the screen. It also
// triggers other features such picking (if enabled) and allows
// file-writing viewers to close the file.
fpViewer->ShowView();
} else { // Last event...
// Keep, but only if user has not kept any...
@@ -1989,6 +2015,9 @@ void G4VisManager::EndOfEvent ()
void G4VisManager::EndOfRun ()
{
if (fIgnoreStateChanges) return;
if (!GetConcreteInstance()) return;
#ifdef G4MULTITHREADED
if (G4Threading::IsWorkerThread()) return;
#endif
@@ -2103,12 +2132,13 @@ void G4VisManager::EndOfRun ()
// // figured out why). ???? JA ????
// if (!fpSceneHandler->GetMarkForClearingTransientStore()) {
if (fpScene->GetRefreshAtEndOfRun()) {
// Some instructions that should NOT be in multithreaded version.
#ifndef G4MULTITHREADED
// These instructions are in G4VisSubThread for multithreading.
fpSceneHandler->DrawEndOfRunModels();
// ShowView guarantees the view comes to the screen. No action
// is taken for passive viewers like OGL*X (without picking enabled),
// but it passes control to interactive viewers, such as OGL*X (with
// picking enabled) or OGL*Xm, and allows file-writing viewers to
// close the file.
// ShowView guarantees the view is flushed to the screen. It also
// triggers other features such picking (if enabled) and allows
// file-writing viewers to close the file.
fpViewer->ShowView();
// // An extra refresh for auto-refresh viewers.
// // ???? I DON'T THINK THIS IS NECESSARY ???? JA ????
@@ -2116,6 +2146,7 @@ void G4VisManager::EndOfRun ()
// fpViewer->RefreshView();
// }
fpSceneHandler->SetMarkForClearingTransientStore(true);
#endif
} else {
if (fpGraphicsSystem->GetFunctionality() ==
G4VGraphicsSystem::fileWriter) {