Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4VisCommandSceneAddScale Class Reference

#include <G4VisCommandsSceneAdd.hh>

Inheritance diagram for G4VisCommandSceneAddScale:
Collaboration 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, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
G4bool operator== (const G4UImessenger &messenger) const
 
G4bool CommandsShouldBeInMaster () const
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VVisCommand
static void SetVisManager (G4VisManager *)
 
static const G4ColourGetCurrentColour ()
 
static G4double GetCurrentLineWidth ()
 
static const G4ColourGetCurrentTextColour ()
 
static G4Text::Layout GetCurrentTextLayout ()
 
static G4double GetCurrentTextSize ()
 
- Protected Member Functions inherited from 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
 
G4bool commandsShouldBeInMaster
 
- Static Protected Attributes inherited from G4VVisCommand
static G4VisManagerfpVisManager = 0
 
static G4int fErrorCode = 0
 
static G4Colour fCurrentColour = G4Colour::White()
 
static G4double fCurrentLineWidth = 1.
 
static G4Colour fCurrentTextColour = G4Colour::Blue()
 
static G4Text::Layout fCurrentTextLayout = G4Text::left
 
static G4double fCurrentTextSize = 12.
 
static
G4ModelingParameters::PVNameCopyNoPath 
fCurrentTouchablePath
 

Detailed Description

Definition at line 343 of file G4VisCommandsSceneAdd.hh.

Constructor & Destructor Documentation

G4VisCommandSceneAddScale::G4VisCommandSceneAddScale ( )

Definition at line 1874 of file G4VisCommandsSceneAdd.cc.

1874  {
1875  G4bool omitable;
1876  fpCommand = new G4UIcommand ("/vis/scene/add/scale", this);
1877  fpCommand -> SetGuidance
1878  ("Adds an annotated scale line to the current scene.");
1879  fpCommand -> SetGuidance
1880  ("If \"unit\" is \"auto\", length is roughly one tenth of the scene extent.");
1881  fpCommand -> SetGuidance
1882  ("If \"direction\" is \"auto\", scale is roughly in the plane of the current view.");
1883  fpCommand -> SetGuidance
1884  ("If \"placement\" is \"auto\", scale is placed at bottom left of current view."
1885  "\n Otherwise placed at (xmid,ymid,zmid).");
1886  fpCommand -> SetGuidance (G4Scale::GetGuidanceString());
1887  G4UIparameter* parameter;
1888  parameter = new G4UIparameter ("length", 'd', omitable = true);
1889  parameter->SetDefaultValue (1.);
1890  fpCommand->SetParameter (parameter);
1891  parameter = new G4UIparameter ("unit", 's', omitable = true);
1892  parameter->SetDefaultValue ("auto");
1893  fpCommand->SetParameter (parameter);
1894  parameter = new G4UIparameter ("direction", 's', omitable = true);
1895  parameter->SetGuidance ("auto|x|y|z");
1896  parameter->SetDefaultValue ("auto");
1897  fpCommand->SetParameter (parameter);
1898  parameter = new G4UIparameter ("red", 'd', omitable = true);
1899  parameter->SetDefaultValue (1.);
1900  fpCommand->SetParameter (parameter);
1901  parameter = new G4UIparameter ("green", 'd', omitable = true);
1902  parameter->SetDefaultValue (0.);
1903  fpCommand->SetParameter (parameter);
1904  parameter = new G4UIparameter ("blue", 'd', omitable = true);
1905  parameter->SetDefaultValue (0.);
1906  fpCommand->SetParameter (parameter);
1907  parameter = new G4UIparameter ("placement", 's', omitable = true);
1908  parameter -> SetParameterCandidates("auto manual");
1909  parameter->SetDefaultValue ("auto");
1910  fpCommand->SetParameter (parameter);
1911  parameter = new G4UIparameter ("xmid", 'd', omitable = true);
1912  parameter->SetDefaultValue (0.);
1913  fpCommand->SetParameter (parameter);
1914  parameter = new G4UIparameter ("ymid", 'd', omitable = true);
1915  parameter->SetDefaultValue (0.);
1916  fpCommand->SetParameter (parameter);
1917  parameter = new G4UIparameter ("zmid", 'd', omitable = true);
1918  parameter->SetDefaultValue (0.);
1919  fpCommand->SetParameter (parameter);
1920  parameter = new G4UIparameter ("unit", 's', omitable = true);
1921  parameter->SetDefaultValue ("m");
1922  fpCommand->SetParameter (parameter);
1923 }
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:66
void SetGuidance(const char *theGuidance)

Here is the call graph for this function:

G4VisCommandSceneAddScale::~G4VisCommandSceneAddScale ( )
virtual

Definition at line 1925 of file G4VisCommandsSceneAdd.cc.

1925  {
1926  delete fpCommand;
1927 }

Member Function Documentation

G4String G4VisCommandSceneAddScale::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 1929 of file G4VisCommandsSceneAdd.cc.

1929  {
1930  return "";
1931 }
void G4VisCommandSceneAddScale::SetNewValue ( G4UIcommand command,
G4String  newValue 
)
virtual

Reimplemented from G4UImessenger.

Definition at line 1933 of file G4VisCommandsSceneAdd.cc.

1933  {
1934 
1936  G4bool warn = verbosity >= G4VisManager::warnings;
1937 
1938  G4Scene* pScene = fpVisManager->GetCurrentScene();
1939  if (!pScene) {
1940  if (verbosity >= G4VisManager::errors) {
1941  G4cerr << "ERROR: No current scene. Please create one." << G4endl;
1942  }
1943  return;
1944  } else {
1945  if (pScene->GetExtent().GetExtentRadius() <= 0.) {
1946  if (verbosity >= G4VisManager::errors) {
1947  G4cerr
1948  << "ERROR: Scene has no extent. Add volumes or use \"/vis/scene/add/extent\"."
1949  << G4endl;
1950  }
1951  return;
1952  }
1953  }
1954 
1955  G4double userLength, red, green, blue, xmid, ymid, zmid;
1956  G4String userLengthUnit, direction, auto_manual, positionUnit;
1957  std::istringstream is (newValue);
1958  is >> userLength >> userLengthUnit >> direction
1959  >> red >> green >> blue
1960  >> auto_manual
1961  >> xmid >> ymid >> zmid >> positionUnit;
1962 
1963  G4double length = userLength;
1964  const G4VisExtent& sceneExtent = pScene->GetExtent(); // Existing extent.
1965  if (userLengthUnit == "auto") {
1966  const G4double lengthMax = 0.5 * sceneExtent.GetExtentRadius();
1967  const G4double intLog10Length = std::floor(std::log10(lengthMax));
1968  length = std::pow(10,intLog10Length);
1969  if (5.*length < lengthMax) length *= 5.;
1970  else if (2.*length < lengthMax) length *= 2.;
1971  } else {
1972  length *= G4UIcommand::ValueOf(userLengthUnit);
1973  }
1974  G4String annotation = G4BestUnit(length,"Length");
1975 
1976  G4double unit = G4UIcommand::ValueOf(positionUnit);
1977  xmid *= unit; ymid *= unit; zmid *= unit;
1978 
1979  G4Scale::Direction scaleDirection (G4Scale::x);
1980  if (direction(0) == 'y') scaleDirection = G4Scale::y;
1981  if (direction(0) == 'z') scaleDirection = G4Scale::z;
1982 
1983  G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
1984  if (!pViewer) {
1985  if (verbosity >= G4VisManager::errors) {
1986  G4cerr <<
1987  "ERROR: G4VisCommandSceneAddScale::SetNewValue: no viewer."
1988  "\n Auto direction needs a viewer."
1989  << G4endl;
1990  }
1991  return;
1992  }
1993 
1994  const G4Vector3D& vp =
1996  const G4Vector3D& up =
1997  pViewer->GetViewParameters().GetUpVector();
1998 
1999  if (direction == "auto") { // Takes cue from viewer.
2000  if (std::abs(vp.x()) > std::abs(vp.y()) &&
2001  std::abs(vp.x()) > std::abs(vp.z())) { // x viewpoint
2002  if (std::abs(up.y()) > std::abs(up.z())) scaleDirection = G4Scale::z;
2003  else scaleDirection = G4Scale::y;
2004  }
2005  else if (std::abs(vp.y()) > std::abs(vp.x()) &&
2006  std::abs(vp.y()) > std::abs(vp.z())) { // y viewpoint
2007  if (std::abs(up.x()) > std::abs(up.z())) scaleDirection = G4Scale::z;
2008  else scaleDirection = G4Scale::x;
2009  }
2010  else if (std::abs(vp.z()) > std::abs(vp.x()) &&
2011  std::abs(vp.z()) > std::abs(vp.y())) { // z viewpoint
2012  if (std::abs(up.y()) > std::abs(up.x())) scaleDirection = G4Scale::x;
2013  else scaleDirection = G4Scale::y;
2014  }
2015  }
2016 
2017  G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true;
2018  // Parameters read and interpreted.
2019 
2020  // Useful constants, etc...
2021  const G4double halfLength(length / 2.);
2022  const G4double comfort(0.01); // 0.15 seems too big. 0.05 might be better.
2023  const G4double freeLengthFraction (1. + 2. * comfort);
2024 
2025  const G4double xmin = sceneExtent.GetXmin();
2026  const G4double xmax = sceneExtent.GetXmax();
2027  const G4double ymin = sceneExtent.GetYmin();
2028  const G4double ymax = sceneExtent.GetYmax();
2029  const G4double zmin = sceneExtent.GetZmin();
2030  const G4double zmax = sceneExtent.GetZmax();
2031 
2032  // Test existing extent and issue warnings...
2033  G4bool worried = false;
2034  if (sceneExtent.GetExtentRadius() == 0) {
2035  worried = true;
2036  if (verbosity >= G4VisManager::warnings) {
2037  G4cout <<
2038  "WARNING: Existing scene does not yet have any extent."
2039  "\n Maybe you have not yet added any geometrical object."
2040  << G4endl;
2041  }
2042  }
2043  // Test existing scene for room...
2044  G4bool room = true;
2045  switch (scaleDirection) {
2046  case G4Scale::x:
2047  if (freeLengthFraction * (xmax - xmin) < length) room = false;
2048  break;
2049  case G4Scale::y:
2050  if (freeLengthFraction * (ymax - ymin) < length) room = false;
2051  break;
2052  case G4Scale::z:
2053  if (freeLengthFraction * (zmax - zmin) < length) room = false;
2054  break;
2055  }
2056  if (!room) {
2057  worried = true;
2058  if (verbosity >= G4VisManager::warnings) {
2059  G4cout <<
2060  "WARNING: Not enough room in existing scene. Maybe scale is too long."
2061  << G4endl;
2062  }
2063  }
2064  if (worried) {
2065  if (verbosity >= G4VisManager::warnings) {
2066  G4cout <<
2067  "WARNING: The scale you have asked for is bigger than the existing"
2068  "\n scene. Maybe you have added it too soon. It is recommended that"
2069  "\n you add the scale last so that it can be correctly auto-positioned"
2070  "\n so as not to be obscured by any existing object and so that the"
2071  "\n view parameters can be correctly recalculated."
2072  << G4endl;
2073  }
2074  }
2075 
2076  // Let's go ahead a construct a scale and a scale model. Since the
2077  // placing is done here, this G4Scale is *not* auto-placed...
2078  G4Scale scale(length, annotation, scaleDirection,
2079  false, xmid, ymid, zmid,
2081  G4VisAttributes visAttr(G4Colour(red, green, blue));
2082  scale.SetVisAttributes(visAttr);
2083  G4VModel* model = new G4ScaleModel(scale);
2084  G4String globalDescription = model->GetGlobalDescription();
2085  globalDescription += " (" + newValue + ")";
2086  model->SetGlobalDescription(globalDescription);
2087 
2088  // Now figure out the extent...
2089  //
2090  // From the G4Scale.hh:
2091  //
2092  // This creates a representation of annotated line in the specified
2093  // direction with tick marks at the end. If autoPlacing is true it
2094  // is required to be centred at the front, right, bottom corner of
2095  // the world space, comfortably outside the existing bounding
2096  // box/sphere so that existing objects do not obscure it. Otherwise
2097  // it is required to be drawn with mid-point at (xmid, ymid, zmid).
2098  //
2099  // The auto placing algorithm might be:
2100  // x = xmin + (1 + comfort) * (xmax - xmin)
2101  // y = ymin - comfort * (ymax - ymin)
2102  // z = zmin + (1 + comfort) * (zmax - zmin)
2103  // if direction == x then (x - length,y,z) to (x,y,z)
2104  // if direction == y then (x,y,z) to (x,y + length,z)
2105  // if direction == z then (x,y,z - length) to (x,y,z)
2106  //
2107  // End of clip from G4Scale.hh:
2108  //
2109  // Implement this in two parts. Here, use the scale's extent to
2110  // "expand" the scene's extent. Then rendering - in
2111  // G4VSceneHandler::AddPrimitive(const G4Scale&) - simply has to
2112  // ensure it's within the new extent.
2113  //
2114 
2115  G4double sxmid(xmid), symid(ymid), szmid(zmid);
2116  if (autoPlacing) {
2117  // Aim to place at bottom right of screen in current view.
2118  // Give some comfort zone.
2119  const G4double xComfort = comfort * (xmax - xmin);
2120  const G4double yComfort = comfort * (ymax - ymin);
2121  const G4double zComfort = comfort * (zmax - zmin);
2122  switch (scaleDirection) {
2123  case G4Scale::x:
2124  if (vp.z() > 0.) {
2125  sxmid = xmax + xComfort;
2126  symid = ymin - yComfort;
2127  szmid = zmin - zComfort;
2128  } else {
2129  sxmid = xmin - xComfort;
2130  symid = ymin - yComfort;
2131  szmid = zmax + zComfort;
2132  }
2133  break;
2134  case G4Scale::y:
2135  if (vp.x() > 0.) {
2136  sxmid = xmin - xComfort;
2137  symid = ymax + yComfort;
2138  szmid = zmin - zComfort;
2139  } else {
2140  sxmid = xmax + xComfort;
2141  symid = ymin - yComfort;
2142  szmid = zmin - zComfort;
2143  }
2144  break;
2145  case G4Scale::z:
2146  if (vp.x() > 0.) {
2147  sxmid = xmax + xComfort;
2148  symid = ymin - yComfort;
2149  szmid = zmax + zComfort;
2150  } else {
2151  sxmid = xmin - xComfort;
2152  symid = ymin - yComfort;
2153  szmid = zmax + zComfort;
2154  }
2155  break;
2156  }
2157  }
2158 
2159  /* Old code - kept for future reference.
2160  G4double sxmid(xmid), symid(ymid), szmid(zmid);
2161  if (autoPlacing) {
2162  sxmid = xmin + onePlusComfort * (xmax - xmin);
2163  symid = ymin - comfort * (ymax - ymin);
2164  szmid = zmin + onePlusComfort * (zmax - zmin);
2165  switch (scaleDirection) {
2166  case G4Scale::x:
2167  sxmid -= halfLength;
2168  break;
2169  case G4Scale::y:
2170  symid += halfLength;
2171  break;
2172  case G4Scale::z:
2173  szmid -= halfLength;
2174  break;
2175  }
2176  }
2177  */
2178 
2179  /* sxmin, etc., not actually used. Comment out to prevent compiler
2180  warnings but keep in case need in future. Extract transform and
2181  scaleExtent into reduced code below.
2182  G4double sxmin(sxmid), sxmax(sxmid);
2183  G4double symin(symid), symax(symid);
2184  G4double szmin(szmid), szmax(szmid);
2185  G4Transform3D transform;
2186  G4VisExtent scaleExtent;
2187  switch (scaleDirection) {
2188  case G4Scale::x:
2189  sxmin = sxmid - halfLength;
2190  sxmax = sxmid + halfLength;
2191  scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
2192  break;
2193  case G4Scale::y:
2194  symin = symid - halfLength;
2195  symax = symid + halfLength;
2196  transform = G4RotateZ3D(halfpi);
2197  scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
2198  break;
2199  case G4Scale::z:
2200  szmin = szmid - halfLength;
2201  szmax = szmid + halfLength;
2202  transform = G4RotateY3D(halfpi);
2203  scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
2204  break;
2205  }
2206  */
2207  G4Transform3D transform;
2208  G4VisExtent scaleExtent;
2209  switch (scaleDirection) {
2210  case G4Scale::x:
2211  scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
2212  break;
2213  case G4Scale::y:
2214  transform = G4RotateZ3D(halfpi);
2215  scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
2216  break;
2217  case G4Scale::z:
2218  transform = G4RotateY3D(halfpi);
2219  scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
2220  break;
2221  }
2222  transform = G4Translate3D(sxmid,symid,szmid) * transform;
2224 
2225 
2226  model->SetTransformation(transform);
2227  // Note: it is the responsibility of the model to act upon this, but
2228  // the extent is in local coordinates...
2229  model->SetExtent(scaleExtent);
2230  // This extent gets "added" to existing scene extent in
2231  // AddRunDurationModel below.
2232 
2233  const G4String& currentSceneName = pScene -> GetName ();
2234  G4bool successful = pScene -> AddRunDurationModel (model, warn);
2235  if (successful) {
2236  if (verbosity >= G4VisManager::confirmations) {
2237  G4cout << "Scale of " << annotation
2238  << " added to scene \"" << currentSceneName << "\".";
2239  if (verbosity >= G4VisManager::parameters) {
2240  G4cout << "\n with extent " << scaleExtent
2241  << "\n at " << transform.getRotation()
2242  << transform.getTranslation();
2243  }
2244  G4cout << G4endl;
2245  }
2246  }
2247  else G4VisCommandsSceneAddUnsuccessful(verbosity);
2248  UpdateVisManagerScene (currentSceneName);
2249 }
HepGeom::RotateY3D G4RotateY3D
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 &)
static G4double fCurrentTextSize
HepGeom::RotateZ3D G4RotateZ3D
void SetTransformation(const G4Transform3D &)
static void G4VisCommandsSceneAddUnsuccessful(G4VisManager::Verbosity verbosity)
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:73
const G4Vector3D & GetViewpointDirection() const
G4GLOB_DLL std::ostream G4cout
const G4VisExtent & GetExtent() const
const G4String & GetGlobalDescription() const
G4double GetYmax() const
Definition: G4VisExtent.hh:92
CLHEP::HepRotation getRotation() const
bool G4bool
Definition: G4Types.hh:79
G4double GetZmax() const
Definition: G4VisExtent.hh:94
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:309
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
static constexpr double halfpi
Definition: G4SIunits.hh:77
double G4double
Definition: G4Types.hh:76
CLHEP::Hep3Vector getTranslation() const
const G4Vector3D & GetUpVector() const
const XML_Char XML_Content * model
Definition: expat.h:151
void SetGlobalDescription(const G4String &)
G4Scene * GetCurrentScene() const
G4GLOB_DLL std::ostream G4cerr
static G4VisManager * fpVisManager

Here is the call graph for this function:


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