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

#include <G4VisCommandsSceneAdd.hh>

+ Inheritance diagram for G4VisCommandSceneAddScale:

Public Member Functions

 G4VisCommandSceneAddScale ()
 
virtual ~G4VisCommandSceneAddScale ()
 
G4String GetCurrentValue (G4UIcommand *command)
 
void SetNewValue (G4UIcommand *command, G4String newValue)
 
- Public Member Functions inherited from G4VVisCommandScene
 G4VVisCommandScene ()
 
virtual ~G4VVisCommandScene ()
 
- Public Member Functions inherited from G4VVisCommand
 G4VVisCommand ()
 
virtual ~G4VVisCommand ()
 
- Public Member Functions inherited from G4UImessenger
 G4UImessenger ()
 
 G4UImessenger (const G4String &path, const G4String &dsc)
 
virtual ~G4UImessenger ()
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 
virtual void SetNewValue (G4UIcommand *command, G4String newValue)
 
G4bool operator== (const G4UImessenger &messenger) const
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VVisCommand
static void SetVisManager (G4VisManager *)
 
- Protected Member Functions inherited from G4VVisCommandScene
G4String CurrentSceneName ()
 
- 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)
 
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
 
- Static Protected Attributes inherited from G4VVisCommand
static G4VisManagerfpVisManager = 0
 
static G4Colour fCurrentColour = G4Colour::White()
 
static G4Colour fCurrentTextColour = G4Colour::Blue()
 
static G4Text::Layout fCurrentTextLayout = G4Text::left
 
static G4double fCurrentLineWidth = 1.
 
static G4ModelingParameters::PVNameCopyNoPath fCurrentTouchablePath
 

Detailed Description

Definition at line 312 of file G4VisCommandsSceneAdd.hh.

Constructor & Destructor Documentation

◆ G4VisCommandSceneAddScale()

G4VisCommandSceneAddScale::G4VisCommandSceneAddScale ( )

Definition at line 1711 of file G4VisCommandsSceneAdd.cc.

1711 {
1712 G4bool omitable;
1713 fpCommand = new G4UIcommand ("/vis/scene/add/scale", this);
1714 fpCommand -> SetGuidance
1715 ("Adds an annotated scale line to the current scene.");
1716 fpCommand -> SetGuidance (G4Scale::GetGuidanceString());
1717 G4UIparameter* parameter;
1718 parameter = new G4UIparameter ("length", 'd', omitable = true);
1719 parameter->SetDefaultValue (1.);
1720 fpCommand->SetParameter (parameter);
1721 parameter = new G4UIparameter ("unit", 's', omitable = true);
1722 parameter->SetGuidance
1723 ("auto or valid length unit - defaults to auto."
1724 "\nIf auto, length is roughly one tenth of the scene extent.");
1725 parameter->SetDefaultValue ("auto");
1726 fpCommand->SetParameter (parameter);
1727 parameter = new G4UIparameter ("direction", 's', omitable = true);
1728 parameter->SetGuidance
1729 ("auto|x|y|z - defaults to auto."
1730 "\nIf auto, scale is roughly in the plane of the current view.");
1731 parameter->SetDefaultValue ("auto");
1732 fpCommand->SetParameter (parameter);
1733 parameter = new G4UIparameter ("red", 'd', omitable = true);
1734 parameter->SetDefaultValue (1.);
1735 fpCommand->SetParameter (parameter);
1736 parameter = new G4UIparameter ("green", 'd', omitable = true);
1737 parameter->SetDefaultValue (0.);
1738 fpCommand->SetParameter (parameter);
1739 parameter = new G4UIparameter ("blue", 'd', omitable = true);
1740 parameter->SetDefaultValue (0.);
1741 fpCommand->SetParameter (parameter);
1742 parameter = new G4UIparameter ("auto|manual", 's', omitable = true);
1743 parameter->SetGuidance
1744 ("Automatic placement or manual placement at (xmid,ymid,zmid)."
1745 "\nIf automatic, scale is placed at bottom left of current view.");
1746 parameter -> SetParameterCandidates("auto manual");
1747 parameter->SetDefaultValue ("auto");
1748 fpCommand->SetParameter (parameter);
1749 parameter = new G4UIparameter ("xmid", 'd', omitable = true);
1750 parameter->SetDefaultValue (0.);
1751 fpCommand->SetParameter (parameter);
1752 parameter = new G4UIparameter ("ymid", 'd', omitable = true);
1753 parameter->SetDefaultValue (0.);
1754 fpCommand->SetParameter (parameter);
1755 parameter = new G4UIparameter ("zmid", 'd', omitable = true);
1756 parameter->SetDefaultValue (0.);
1757 fpCommand->SetParameter (parameter);
1758 parameter = new G4UIparameter ("unit", 's', omitable = true);
1759 parameter->SetDefaultValue ("m");
1760 fpCommand->SetParameter (parameter);
1761}
bool G4bool
Definition: G4Types.hh:67
static const G4String & GetGuidanceString()
Definition: G4Scale.cc:64
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetDefaultValue(const char *theDefaultValue)
void SetGuidance(const char *theGuidance)

◆ ~G4VisCommandSceneAddScale()

G4VisCommandSceneAddScale::~G4VisCommandSceneAddScale ( )
virtual

Definition at line 1763 of file G4VisCommandsSceneAdd.cc.

1763 {
1764 delete fpCommand;
1765}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandSceneAddScale::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1767 of file G4VisCommandsSceneAdd.cc.

1767 {
1768 return "";
1769}

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 1771 of file G4VisCommandsSceneAdd.cc.

1771 {
1772
1774 G4bool warn = verbosity >= G4VisManager::warnings;
1775
1777 if (!pScene) {
1778 if (verbosity >= G4VisManager::errors) {
1779 G4cout << "ERROR: No current scene. Please create one." << G4endl;
1780 }
1781 return;
1782 }
1783
1784 G4double userLength, red, green, blue, xmid, ymid, zmid;
1785 G4String userLengthUnit, direction, auto_manual, positionUnit;
1786 std::istringstream is (newValue);
1787 is >> userLength >> userLengthUnit >> direction
1788 >> red >> green >> blue
1789 >> auto_manual
1790 >> xmid >> ymid >> zmid >> positionUnit;
1791
1792 G4double length = userLength;
1793 const G4VisExtent& sceneExtent = pScene->GetExtent(); // Existing extent.
1794 if (userLengthUnit == "auto") {
1795 length *= sceneExtent.GetExtentRadius();
1796 G4double intLog10Length = std::floor(std::log10(length));
1797 length = std::pow(10,intLog10Length);
1798 } else {
1799 length *= G4UIcommand::ValueOf(userLengthUnit);
1800 }
1801 G4String annotation = G4BestUnit(length,"Length");
1802
1803 G4double unit = G4UIcommand::ValueOf(positionUnit);
1804 xmid *= unit; ymid *= unit; zmid *= unit;
1805
1806 G4Scale::Direction scaleDirection (G4Scale::x);
1807 if (direction(0) == 'y') scaleDirection = G4Scale::y;
1808 if (direction(0) == 'z') scaleDirection = G4Scale::z;
1809
1811 if (!pViewer) {
1812 if (verbosity >= G4VisManager::errors) {
1813 G4cout <<
1814 "ERROR: G4VisCommandSceneAddScale::SetNewValue: no viewer."
1815 "\n Auto direction needs a viewer."
1816 << G4endl;
1817 }
1818 return;
1819 }
1820
1821 const G4Vector3D& vp =
1823 const G4Vector3D& up =
1824 pViewer->GetViewParameters().GetUpVector();
1825
1826 if (direction == "auto") { // Takes cue from viewer.
1827 if (std::abs(vp.x()) > std::abs(vp.y()) &&
1828 std::abs(vp.x()) > std::abs(vp.z())) { // x viewpoint
1829 if (std::abs(up.y()) > std::abs(up.z())) scaleDirection = G4Scale::z;
1830 else scaleDirection = G4Scale::y;
1831 }
1832 else if (std::abs(vp.y()) > std::abs(vp.x()) &&
1833 std::abs(vp.y()) > std::abs(vp.z())) { // y viewpoint
1834 if (std::abs(up.x()) > std::abs(up.z())) scaleDirection = G4Scale::z;
1835 else scaleDirection = G4Scale::x;
1836 }
1837 else if (std::abs(vp.z()) > std::abs(vp.x()) &&
1838 std::abs(vp.z()) > std::abs(vp.y())) { // z viewpoint
1839 if (std::abs(up.y()) > std::abs(up.x())) scaleDirection = G4Scale::x;
1840 else scaleDirection = G4Scale::y;
1841 }
1842 }
1843
1844 G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true;
1845 // Parameters read and interpreted.
1846
1847 // Useful constants, etc...
1848 const G4double halfLength(length / 2.);
1849 const G4double comfort(0.01); // 0.15 seems too big. 0.05 might be better.
1850 const G4double freeLengthFraction (1. + 2. * comfort);
1851
1852 const G4double xmin = sceneExtent.GetXmin();
1853 const G4double xmax = sceneExtent.GetXmax();
1854 const G4double ymin = sceneExtent.GetYmin();
1855 const G4double ymax = sceneExtent.GetYmax();
1856 const G4double zmin = sceneExtent.GetZmin();
1857 const G4double zmax = sceneExtent.GetZmax();
1858
1859 // Test existing extent and issue warnings...
1860 G4bool worried = false;
1861 if (sceneExtent.GetExtentRadius() == 0) {
1862 worried = true;
1863 if (verbosity >= G4VisManager::warnings) {
1864 G4cout <<
1865 "WARNING: Existing scene does not yet have any extent."
1866 "\n Maybe you have not yet added any geometrical object."
1867 << G4endl;
1868 }
1869 }
1870 // Test existing scene for room...
1871 G4bool room = true;
1872 switch (scaleDirection) {
1873 case G4Scale::x:
1874 if (freeLengthFraction * (xmax - xmin) < length) room = false; break;
1875 case G4Scale::y:
1876 if (freeLengthFraction * (ymax - ymin) < length) room = false; break;
1877 case G4Scale::z:
1878 if (freeLengthFraction * (zmax - zmin) < length) room = false; break;
1879 }
1880 if (!room) {
1881 worried = true;
1882 if (verbosity >= G4VisManager::warnings) {
1883 G4cout <<
1884 "WARNING: Not enough room in existing scene. Maybe scale is too long."
1885 << G4endl;
1886 }
1887 }
1888 if (worried) {
1889 if (verbosity >= G4VisManager::warnings) {
1890 G4cout <<
1891 "WARNING: The scale you have asked for is bigger than the existing"
1892 "\n scene. Maybe you have added it too soon. It is recommended that"
1893 "\n you add the scale last so that it can be correctly auto-positioned"
1894 "\n so as not to be obscured by any existing object and so that the"
1895 "\n view parameters can be correctly recalculated."
1896 << G4endl;
1897 }
1898 }
1899
1900 // Let's go ahead a construct a scale and a scale model. Since the
1901 // placing is done here, this G4Scale is *not* auto-placed...
1902 G4Scale scale(length, annotation, scaleDirection,
1903 false, xmid, ymid, zmid);
1904 G4VisAttributes* pVisAttr = new G4VisAttributes(G4Colour(red, green, blue));
1905 // Created of the heap because it needs a long lifetime. This is a
1906 // mess. The model determines the life but the vis atttributes are
1907 // associated with the scale. There's no way of knowing when to
1908 // delete the vis atttributes!!!
1909 scale.SetVisAttributes(pVisAttr);
1910 G4VModel* model = new G4ScaleModel(scale);
1911
1912 // Now figure out the extent...
1913 //
1914 // From the G4Scale.hh:
1915 //
1916 // This creates a representation of annotated line in the specified
1917 // direction with tick marks at the end. If autoPlacing is true it
1918 // is required to be centred at the front, right, bottom corner of
1919 // the world space, comfortably outside the existing bounding
1920 // box/sphere so that existing objects do not obscure it. Otherwise
1921 // it is required to be drawn with mid-point at (xmid, ymid, zmid).
1922 //
1923 // The auto placing algorithm might be:
1924 // x = xmin + (1 + comfort) * (xmax - xmin)
1925 // y = ymin - comfort * (ymax - ymin)
1926 // z = zmin + (1 + comfort) * (zmax - zmin)
1927 // if direction == x then (x - length,y,z) to (x,y,z)
1928 // if direction == y then (x,y,z) to (x,y + length,z)
1929 // if direction == z then (x,y,z - length) to (x,y,z)
1930 //
1931 // End of clip from G4Scale.hh:
1932 //
1933 // Implement this in two parts. Here, use the scale's extent to
1934 // "expand" the scene's extent. Then rendering - in
1935 // G4VSceneHandler::AddPrimitive(const G4Scale&) - simply has to
1936 // ensure it's within the new extent.
1937 //
1938
1939 G4double sxmid(xmid), symid(ymid), szmid(zmid);
1940 if (autoPlacing) {
1941 // Aim to place at bottom right of screen in current view.
1942 // Give some comfort zone.
1943 const G4double xComfort = comfort * (xmax - xmin);
1944 const G4double yComfort = comfort * (ymax - ymin);
1945 const G4double zComfort = comfort * (zmax - zmin);
1946 switch (scaleDirection) {
1947 case G4Scale::x:
1948 if (vp.z() > 0.) {
1949 sxmid = xmax + xComfort;
1950 symid = ymin - yComfort;
1951 szmid = zmin - zComfort;
1952 } else {
1953 sxmid = xmin - xComfort;
1954 symid = ymin - yComfort;
1955 szmid = zmax + zComfort;
1956 }
1957 break;
1958 case G4Scale::y:
1959 if (vp.x() > 0.) {
1960 sxmid = xmin - xComfort;
1961 symid = ymax + yComfort;
1962 szmid = zmin - zComfort;
1963 } else {
1964 sxmid = xmax + xComfort;
1965 symid = ymin - yComfort;
1966 szmid = zmin - zComfort;
1967 }
1968 break;
1969 case G4Scale::z:
1970 if (vp.x() > 0.) {
1971 sxmid = xmax + xComfort;
1972 symid = ymin - yComfort;
1973 szmid = zmax + zComfort;
1974 } else {
1975 sxmid = xmin - xComfort;
1976 symid = ymin - yComfort;
1977 szmid = zmax + zComfort;
1978 }
1979 break;
1980 }
1981 }
1982
1983 /* Old code - kept for future reference.
1984 G4double sxmid(xmid), symid(ymid), szmid(zmid);
1985 if (autoPlacing) {
1986 sxmid = xmin + onePlusComfort * (xmax - xmin);
1987 symid = ymin - comfort * (ymax - ymin);
1988 szmid = zmin + onePlusComfort * (zmax - zmin);
1989 switch (scaleDirection) {
1990 case G4Scale::x:
1991 sxmid -= halfLength;
1992 break;
1993 case G4Scale::y:
1994 symid += halfLength;
1995 break;
1996 case G4Scale::z:
1997 szmid -= halfLength;
1998 break;
1999 }
2000 }
2001 */
2002
2003 /* sxmin, etc., not actually used. Comment out to prevent compiler
2004 warnings but keep in case need in future. Extract transform and
2005 scaleExtent into reduced code below.
2006 G4double sxmin(sxmid), sxmax(sxmid);
2007 G4double symin(symid), symax(symid);
2008 G4double szmin(szmid), szmax(szmid);
2009 G4Transform3D transform;
2010 G4VisExtent scaleExtent;
2011 switch (scaleDirection) {
2012 case G4Scale::x:
2013 sxmin = sxmid - halfLength;
2014 sxmax = sxmid + halfLength;
2015 scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
2016 break;
2017 case G4Scale::y:
2018 symin = symid - halfLength;
2019 symax = symid + halfLength;
2020 transform = G4RotateZ3D(halfpi);
2021 scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
2022 break;
2023 case G4Scale::z:
2024 szmin = szmid - halfLength;
2025 szmax = szmid + halfLength;
2026 transform = G4RotateY3D(halfpi);
2027 scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
2028 break;
2029 }
2030 */
2031 G4Transform3D transform;
2032 G4VisExtent scaleExtent;
2033 switch (scaleDirection) {
2034 case G4Scale::x:
2035 scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
2036 break;
2037 case G4Scale::y:
2038 transform = G4RotateZ3D(halfpi);
2039 scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
2040 break;
2041 case G4Scale::z:
2042 transform = G4RotateY3D(halfpi);
2043 scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
2044 break;
2045 }
2046 transform = G4Translate3D(sxmid,symid,szmid) * transform;
2047 ///////// G4VisExtent scaleExtent(sxmin, sxmax, symin, symax, szmin, szmax);
2048
2049
2050 model->SetTransformation(transform);
2051 // Note: it is the responsibility of the model to act upon this, but
2052 // the extent is in local coordinates...
2053 model->SetExtent(scaleExtent);
2054 // This extent gets "added" to existing scene extent in
2055 // AddRunDurationModel below.
2056
2057 const G4String& currentSceneName = pScene -> GetName ();
2058 G4bool successful = pScene -> AddRunDurationModel (model, warn);
2059 if (successful) {
2060 if (verbosity >= G4VisManager::confirmations) {
2061 G4cout << "Scale of " << annotation
2062 << " added to scene \"" << currentSceneName << "\".";
2063 if (verbosity >= G4VisManager::parameters) {
2064 G4cout << "\n with extent " << scaleExtent
2065 << "\n at " << transform.getRotation()
2066 << transform.getTranslation();
2067 }
2068 G4cout << G4endl;
2069 }
2070 }
2071 else G4VisCommandsSceneAddUnsuccessful(verbosity);
2072 UpdateVisManagerScene (currentSceneName);
2073}
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
HepGeom::RotateZ3D G4RotateZ3D
HepGeom::Translate3D G4Translate3D
HepGeom::RotateY3D G4RotateY3D
double G4double
Definition: G4Types.hh:64
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
Direction
Definition: G4Scale.hh:42
const G4VisExtent & GetExtent() const
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:288
void SetExtent(const G4VisExtent &)
void SetTransformation(const G4Transform3D &)
const G4ViewParameters & GetViewParameters() const
static G4VisManager * fpVisManager
void UpdateVisManagerScene(const G4String &sceneName="")
const G4Vector3D & GetViewpointDirection() const
const G4Vector3D & GetUpVector() const
G4double GetYmin() const
Definition: G4VisExtent.hh:91
G4double GetXmax() const
Definition: G4VisExtent.hh:90
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:73
G4double GetYmax() const
Definition: G4VisExtent.hh:92
G4double GetZmax() const
Definition: G4VisExtent.hh:94
G4double GetZmin() const
Definition: G4VisExtent.hh:93
G4double GetXmin() const
Definition: G4VisExtent.hh:89
G4Scene * GetCurrentScene() const
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()
CLHEP::HepRotation getRotation() const
CLHEP::Hep3Vector getTranslation() const

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