Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
G4VisCommandSceneAddScale Class Reference

#include <G4VisCommandsSceneAdd.hh>

Inheritance diagram for G4VisCommandSceneAddScale:
G4VVisCommandScene G4VVisCommand G4UImessenger

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, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
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, G4bool commandsToBeBroadcasted=true)
 
template<typename T >
T * CreateCommand (const G4String &cname, const G4String &dsc)
 
- Static Protected Member Functions inherited from G4VVisCommand
static G4String ConvertToString (G4double x, G4double y, const char *unitName)
 
static void ConvertToDoublePair (const G4String &paramString, G4double &xval, G4double &yval)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir
 
G4String baseDirName
 
- 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 324 of file G4VisCommandsSceneAdd.hh.

Constructor & Destructor Documentation

G4VisCommandSceneAddScale::G4VisCommandSceneAddScale ( )

Definition at line 1652 of file G4VisCommandsSceneAdd.cc.

References G4Scale::GetGuidanceString(), G4UIparameter::SetDefaultValue(), G4UIparameter::SetGuidance(), and G4UIcommand::SetParameter().

1652  {
1653  G4bool omitable;
1654  fpCommand = new G4UIcommand ("/vis/scene/add/scale", this);
1655  fpCommand -> SetGuidance
1656  ("Adds an annotated scale line to the current scene.");
1657  fpCommand -> SetGuidance
1658  ("If \"unit\" is \"auto\", length is roughly one tenth of the scene extent.");
1659  fpCommand -> SetGuidance
1660  ("If \"direction\" is \"auto\", scale is roughly in the plane of the current view.");
1661  fpCommand -> SetGuidance
1662  ("If \"placement\" is \"auto\", scale is placed at bottom left of current view."
1663  "\n Otherwise placed at (xmid,ymid,zmid).");
1664  fpCommand -> SetGuidance (G4Scale::GetGuidanceString());
1665  G4UIparameter* parameter;
1666  parameter = new G4UIparameter ("length", 'd', omitable = true);
1667  parameter->SetDefaultValue (1.);
1668  fpCommand->SetParameter (parameter);
1669  parameter = new G4UIparameter ("unit", 's', omitable = true);
1670  parameter->SetDefaultValue ("auto");
1671  fpCommand->SetParameter (parameter);
1672  parameter = new G4UIparameter ("direction", 's', omitable = true);
1673  parameter->SetGuidance ("auto|x|y|z");
1674  parameter->SetDefaultValue ("auto");
1675  fpCommand->SetParameter (parameter);
1676  parameter = new G4UIparameter ("red", 'd', omitable = true);
1677  parameter->SetDefaultValue (1.);
1678  fpCommand->SetParameter (parameter);
1679  parameter = new G4UIparameter ("green", 'd', omitable = true);
1680  parameter->SetDefaultValue (0.);
1681  fpCommand->SetParameter (parameter);
1682  parameter = new G4UIparameter ("blue", 'd', omitable = true);
1683  parameter->SetDefaultValue (0.);
1684  fpCommand->SetParameter (parameter);
1685  parameter = new G4UIparameter ("placement", 's', omitable = true);
1686  parameter -> SetParameterCandidates("auto manual");
1687  parameter->SetDefaultValue ("auto");
1688  fpCommand->SetParameter (parameter);
1689  parameter = new G4UIparameter ("xmid", 'd', omitable = true);
1690  parameter->SetDefaultValue (0.);
1691  fpCommand->SetParameter (parameter);
1692  parameter = new G4UIparameter ("ymid", 'd', omitable = true);
1693  parameter->SetDefaultValue (0.);
1694  fpCommand->SetParameter (parameter);
1695  parameter = new G4UIparameter ("zmid", 'd', omitable = true);
1696  parameter->SetDefaultValue (0.);
1697  fpCommand->SetParameter (parameter);
1698  parameter = new G4UIparameter ("unit", 's', omitable = true);
1699  parameter->SetDefaultValue ("m");
1700  fpCommand->SetParameter (parameter);
1701 }
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetDefaultValue(const char *theDefaultValue)
bool G4bool
Definition: G4Types.hh:79
static const G4String & GetGuidanceString()
Definition: G4Scale.cc:64
void SetGuidance(const char *theGuidance)
G4VisCommandSceneAddScale::~G4VisCommandSceneAddScale ( )
virtual

Definition at line 1703 of file G4VisCommandsSceneAdd.cc.

1703  {
1704  delete fpCommand;
1705 }

Member Function Documentation

G4String G4VisCommandSceneAddScale::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1707 of file G4VisCommandsSceneAdd.cc.

1707  {
1708  return "";
1709 }
void G4VisCommandSceneAddScale::SetNewValue ( G4UIcommand command,
G4String  newValue 
)
virtual

Reimplemented from G4UImessenger.

Definition at line 1711 of file G4VisCommandsSceneAdd.cc.

References blue, G4VisManager::confirmations, G4VisManager::errors, G4VVisCommand::fpVisManager, G4BestUnit, G4cout, G4endl, G4VisManager::GetCurrentScene(), G4VisManager::GetCurrentViewer(), G4Scene::GetExtent(), G4VisExtent::GetExtentRadius(), HepGeom::Transform3D::getRotation(), HepGeom::Transform3D::getTranslation(), G4ViewParameters::GetUpVector(), G4VisManager::GetVerbosity(), G4VViewer::GetViewParameters(), G4ViewParameters::GetViewpointDirection(), G4VisExtent::GetXmax(), G4VisExtent::GetXmin(), G4VisExtent::GetYmax(), G4VisExtent::GetYmin(), G4VisExtent::GetZmax(), G4VisExtent::GetZmin(), python.hepunit::halfpi, G4VisManager::parameters, red, G4VModel::SetExtent(), G4VModel::SetTransformation(), G4Visible::SetVisAttributes(), G4VVisCommand::UpdateVisManagerScene(), G4UIcommand::ValueOf(), G4VisManager::warnings, G4Scale::x, HepGeom::BasicVector3D< T >::x(), G4Scale::y, HepGeom::BasicVector3D< T >::y(), G4Scale::z, and HepGeom::BasicVector3D< T >::z().

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

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