Geant4 10.7.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, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 
virtual void SetNewValue (G4UIcommand *command, G4String newValue)
 
G4bool operator== (const G4UImessenger &messenger) const
 
G4bool operator!= (const G4UImessenger &messenger) const
 
G4bool CommandsShouldBeInMaster () const
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VVisCommand
static void SetVisManager (G4VisManager *pVisManager)
 
static const G4ColourGetCurrentTextColour ()
 
- Protected Member Functions inherited from G4VVisCommandScene
G4String CurrentSceneName ()
 
- Protected Member Functions inherited from G4VVisCommand
void SetViewParameters (G4VViewer *viewer, const G4ViewParameters &viewParams)
 
void RefreshIfRequired (G4VViewer *viewer)
 
void InterpolateViews (G4VViewer *currentViewer, std::vector< G4ViewParameters > viewVector, const G4int nInterpolationPoints=50, const G4int waitTimePerPointmilliseconds=20, const G4String exportString="")
 
void InterpolateToNewView (G4VViewer *currentViewer, const G4ViewParameters &oldVP, const G4ViewParameters &newVP, const G4int nInterpolationPoints=50, const G4int waitTimePerPointmilliseconds=20, const G4String exportString="")
 
const G4StringConvertToColourGuidance ()
 
void ConvertToColour (G4Colour &colour, const G4String &redOrString, G4double green, G4double blue, G4double opacity)
 
G4bool ProvideValueOfUnit (const G4String &where, const G4String &unit, const G4String &category, G4double &value)
 
void CheckSceneAndNotifyHandlers (G4Scene *=nullptr)
 
G4bool CheckView ()
 
void G4VisCommandsSceneAddUnsuccessful (G4VisManager::Verbosity verbosity)
 
void CopyGuidanceFrom (const G4UIcommand *fromCmd, G4UIcommand *toCmd, G4int startLine=0)
 
void CopyParametersFrom (const G4UIcommand *fromCmd, G4UIcommand *toCmd)
 
void DrawExtent (const G4VisExtent &)
 
- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (G4String s)
 
G4long StoL (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 G4bool ConvertToDoublePair (const G4String &paramString, G4double &xval, G4double &yval)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir = nullptr
 
G4String baseDirName = ""
 
G4bool commandsShouldBeInMaster = false
 
- Static Protected Attributes inherited from G4VVisCommand
static G4VisManagerfpVisManager = 0
 
static G4int fCurrentArrow3DLineSegmentsPerCircle = 6
 
static G4Colour fCurrentColour = G4Colour::White()
 
static G4double fCurrentLineWidth = 1.
 
static G4Colour fCurrentTextColour = G4Colour::Blue()
 
static G4Text::Layout fCurrentTextLayout = G4Text::left
 
static G4double fCurrentTextSize = 12.
 
static G4PhysicalVolumeModel::TouchableProperties fCurrentTouchableProperties
 
static G4VisExtent fCurrentExtentForField
 
static std::vector< G4PhysicalVolumesSearchScene::FindingsfCurrrentPVFindingsForField
 

Detailed Description

Definition at line 369 of file G4VisCommandsSceneAdd.hh.

Constructor & Destructor Documentation

◆ G4VisCommandSceneAddScale()

G4VisCommandSceneAddScale::G4VisCommandSceneAddScale ( )

Definition at line 2034 of file G4VisCommandsSceneAdd.cc.

2034 {
2035 G4bool omitable;
2036 fpCommand = new G4UIcommand ("/vis/scene/add/scale", this);
2037 fpCommand -> SetGuidance
2038 ("Adds an annotated scale line to the current scene.");
2039 fpCommand -> SetGuidance
2040 ("If \"unit\" is \"auto\", length is roughly one tenth of the scene extent.");
2041 fpCommand -> SetGuidance
2042 ("If \"direction\" is \"auto\", scale is roughly in the plane of the current view.");
2043 fpCommand -> SetGuidance
2044 ("If \"placement\" is \"auto\", scale is placed at bottom left of current view."
2045 "\n Otherwise placed at (xmid,ymid,zmid).");
2046 fpCommand -> SetGuidance (G4Scale::GetGuidanceString());
2047 G4UIparameter* parameter;
2048 parameter = new G4UIparameter ("length", 'd', omitable = true);
2049 parameter->SetDefaultValue (1.);
2050 fpCommand->SetParameter (parameter);
2051 parameter = new G4UIparameter ("unit", 's', omitable = true);
2052 parameter->SetDefaultValue ("auto");
2053 fpCommand->SetParameter (parameter);
2054 parameter = new G4UIparameter ("direction", 's', omitable = true);
2055 parameter->SetGuidance ("auto|x|y|z");
2056 parameter->SetDefaultValue ("auto");
2057 fpCommand->SetParameter (parameter);
2058 parameter = new G4UIparameter ("red", 'd', omitable = true);
2059 parameter->SetDefaultValue (1.);
2060 fpCommand->SetParameter (parameter);
2061 parameter = new G4UIparameter ("green", 'd', omitable = true);
2062 parameter->SetDefaultValue (0.);
2063 fpCommand->SetParameter (parameter);
2064 parameter = new G4UIparameter ("blue", 'd', omitable = true);
2065 parameter->SetDefaultValue (0.);
2066 fpCommand->SetParameter (parameter);
2067 parameter = new G4UIparameter ("placement", 's', omitable = true);
2068 parameter -> SetParameterCandidates("auto manual");
2069 parameter->SetDefaultValue ("auto");
2070 fpCommand->SetParameter (parameter);
2071 parameter = new G4UIparameter ("xmid", 'd', omitable = true);
2072 parameter->SetDefaultValue (0.);
2073 fpCommand->SetParameter (parameter);
2074 parameter = new G4UIparameter ("ymid", 'd', omitable = true);
2075 parameter->SetDefaultValue (0.);
2076 fpCommand->SetParameter (parameter);
2077 parameter = new G4UIparameter ("zmid", 'd', omitable = true);
2078 parameter->SetDefaultValue (0.);
2079 fpCommand->SetParameter (parameter);
2080 parameter = new G4UIparameter ("unit", 's', omitable = true);
2081 parameter->SetDefaultValue ("m");
2082 fpCommand->SetParameter (parameter);
2083}
bool G4bool
Definition: G4Types.hh:86
static const G4String & GetGuidanceString()
Definition: G4Scale.cc:65
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:146
void SetDefaultValue(const char *theDefaultValue)
void SetGuidance(const char *theGuidance)

◆ ~G4VisCommandSceneAddScale()

G4VisCommandSceneAddScale::~G4VisCommandSceneAddScale ( )
virtual

Definition at line 2085 of file G4VisCommandsSceneAdd.cc.

2085 {
2086 delete fpCommand;
2087}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandSceneAddScale::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 2089 of file G4VisCommandsSceneAdd.cc.

2089 {
2090 return "";
2091}

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 2093 of file G4VisCommandsSceneAdd.cc.

2093 {
2094
2096 G4bool warn = verbosity >= G4VisManager::warnings;
2097
2099 if (!pScene) {
2100 if (verbosity >= G4VisManager::errors) {
2101 G4cerr << "ERROR: No current scene. Please create one." << G4endl;
2102 }
2103 return;
2104 } else {
2105 if (pScene->GetExtent().GetExtentRadius() <= 0.) {
2106 if (verbosity >= G4VisManager::errors) {
2107 G4cerr
2108 << "ERROR: Scene has no extent. Add volumes or use \"/vis/scene/add/extent\"."
2109 << G4endl;
2110 }
2111 return;
2112 }
2113 }
2114
2115 G4double userLength, red, green, blue, xmid, ymid, zmid;
2116 G4String userLengthUnit, direction, auto_manual, positionUnit;
2117 std::istringstream is (newValue);
2118 is >> userLength >> userLengthUnit >> direction
2119 >> red >> green >> blue
2120 >> auto_manual
2121 >> xmid >> ymid >> zmid >> positionUnit;
2122
2123 G4double length = userLength;
2124 const G4VisExtent& sceneExtent = pScene->GetExtent(); // Existing extent.
2125 if (userLengthUnit == "auto") {
2126 const G4double lengthMax = 0.5 * sceneExtent.GetExtentRadius();
2127 const G4double intLog10Length = std::floor(std::log10(lengthMax));
2128 length = std::pow(10,intLog10Length);
2129 if (5.*length < lengthMax) length *= 5.;
2130 else if (2.*length < lengthMax) length *= 2.;
2131 } else {
2132 length *= G4UIcommand::ValueOf(userLengthUnit);
2133 }
2134 G4String annotation = G4BestUnit(length,"Length");
2135
2136 G4double unit = G4UIcommand::ValueOf(positionUnit);
2137 xmid *= unit; ymid *= unit; zmid *= unit;
2138
2139 G4Scale::Direction scaleDirection (G4Scale::x);
2140 if (direction(0) == 'y') scaleDirection = G4Scale::y;
2141 if (direction(0) == 'z') scaleDirection = G4Scale::z;
2142
2144 if (!pViewer) {
2145 if (verbosity >= G4VisManager::errors) {
2146 G4cerr <<
2147 "ERROR: G4VisCommandSceneAddScale::SetNewValue: no viewer."
2148 "\n Auto direction needs a viewer."
2149 << G4endl;
2150 }
2151 return;
2152 }
2153
2154 const G4Vector3D& vp =
2156 const G4Vector3D& up =
2157 pViewer->GetViewParameters().GetUpVector();
2158
2159 if (direction == "auto") { // Takes cue from viewer.
2160 if (std::abs(vp.x()) > std::abs(vp.y()) &&
2161 std::abs(vp.x()) > std::abs(vp.z())) { // x viewpoint
2162 if (std::abs(up.y()) > std::abs(up.z())) scaleDirection = G4Scale::z;
2163 else scaleDirection = G4Scale::y;
2164 }
2165 else if (std::abs(vp.y()) > std::abs(vp.x()) &&
2166 std::abs(vp.y()) > std::abs(vp.z())) { // y viewpoint
2167 if (std::abs(up.x()) > std::abs(up.z())) scaleDirection = G4Scale::z;
2168 else scaleDirection = G4Scale::x;
2169 }
2170 else if (std::abs(vp.z()) > std::abs(vp.x()) &&
2171 std::abs(vp.z()) > std::abs(vp.y())) { // z viewpoint
2172 if (std::abs(up.y()) > std::abs(up.x())) scaleDirection = G4Scale::x;
2173 else scaleDirection = G4Scale::y;
2174 }
2175 }
2176
2177 G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true;
2178 // Parameters read and interpreted.
2179
2180 // Useful constants, etc...
2181 const G4double halfLength(length / 2.);
2182 const G4double comfort(0.01); // 0.15 seems too big. 0.05 might be better.
2183 const G4double freeLengthFraction (1. + 2. * comfort);
2184
2185 const G4double xmin = sceneExtent.GetXmin();
2186 const G4double xmax = sceneExtent.GetXmax();
2187 const G4double ymin = sceneExtent.GetYmin();
2188 const G4double ymax = sceneExtent.GetYmax();
2189 const G4double zmin = sceneExtent.GetZmin();
2190 const G4double zmax = sceneExtent.GetZmax();
2191
2192 // Test existing extent and issue warnings...
2193 G4bool worried = false;
2194 if (sceneExtent.GetExtentRadius() == 0) {
2195 worried = true;
2196 if (verbosity >= G4VisManager::warnings) {
2197 G4cout <<
2198 "WARNING: Existing scene does not yet have any extent."
2199 "\n Maybe you have not yet added any geometrical object."
2200 << G4endl;
2201 }
2202 }
2203 // Test existing scene for room...
2204 G4bool room = true;
2205 switch (scaleDirection) {
2206 case G4Scale::x:
2207 if (freeLengthFraction * (xmax - xmin) < length) room = false;
2208 break;
2209 case G4Scale::y:
2210 if (freeLengthFraction * (ymax - ymin) < length) room = false;
2211 break;
2212 case G4Scale::z:
2213 if (freeLengthFraction * (zmax - zmin) < length) room = false;
2214 break;
2215 }
2216 if (!room) {
2217 worried = true;
2218 if (verbosity >= G4VisManager::warnings) {
2219 G4cout <<
2220 "WARNING: Not enough room in existing scene. Maybe scale is too long."
2221 << G4endl;
2222 }
2223 }
2224 if (worried) {
2225 if (verbosity >= G4VisManager::warnings) {
2226 G4cout <<
2227 "WARNING: The scale you have asked for is bigger than the existing"
2228 "\n scene. Maybe you have added it too soon. It is recommended that"
2229 "\n you add the scale last so that it can be correctly auto-positioned"
2230 "\n so as not to be obscured by any existing object and so that the"
2231 "\n view parameters can be correctly recalculated."
2232 << G4endl;
2233 }
2234 }
2235
2236 // Let's go ahead a construct a scale and a scale model. Since the
2237 // placing is done here, this G4Scale is *not* auto-placed...
2238 G4Scale scale(length, annotation, scaleDirection,
2239 false, xmid, ymid, zmid,
2241 G4VisAttributes visAttr(G4Colour(red, green, blue));
2242 scale.SetVisAttributes(visAttr);
2243 G4VModel* model = new G4ScaleModel(scale);
2244 G4String globalDescription = model->GetGlobalDescription();
2245 globalDescription += " (" + newValue + ")";
2246 model->SetGlobalDescription(globalDescription);
2247
2248 // Now figure out the extent...
2249 //
2250 // From the G4Scale.hh:
2251 //
2252 // This creates a representation of annotated line in the specified
2253 // direction with tick marks at the end. If autoPlacing is true it
2254 // is required to be centred at the front, right, bottom corner of
2255 // the world space, comfortably outside the existing bounding
2256 // box/sphere so that existing objects do not obscure it. Otherwise
2257 // it is required to be drawn with mid-point at (xmid, ymid, zmid).
2258 //
2259 // The auto placing algorithm might be:
2260 // x = xmin + (1 + comfort) * (xmax - xmin)
2261 // y = ymin - comfort * (ymax - ymin)
2262 // z = zmin + (1 + comfort) * (zmax - zmin)
2263 // if direction == x then (x - length,y,z) to (x,y,z)
2264 // if direction == y then (x,y,z) to (x,y + length,z)
2265 // if direction == z then (x,y,z - length) to (x,y,z)
2266 //
2267 // End of clip from G4Scale.hh:
2268 //
2269 // Implement this in two parts. Here, use the scale's extent to
2270 // "expand" the scene's extent. Then rendering - in
2271 // G4VSceneHandler::AddPrimitive(const G4Scale&) - simply has to
2272 // ensure it's within the new extent.
2273 //
2274
2275 G4double sxmid(xmid), symid(ymid), szmid(zmid);
2276 if (autoPlacing) {
2277 // Aim to place at bottom right of screen in current view.
2278 // Give some comfort zone.
2279 const G4double xComfort = comfort * (xmax - xmin);
2280 const G4double yComfort = comfort * (ymax - ymin);
2281 const G4double zComfort = comfort * (zmax - zmin);
2282 switch (scaleDirection) {
2283 case G4Scale::x:
2284 if (vp.z() > 0.) {
2285 sxmid = xmax + xComfort;
2286 symid = ymin - yComfort;
2287 szmid = zmin - zComfort;
2288 } else {
2289 sxmid = xmin - xComfort;
2290 symid = ymin - yComfort;
2291 szmid = zmax + zComfort;
2292 }
2293 break;
2294 case G4Scale::y:
2295 if (vp.x() > 0.) {
2296 sxmid = xmin - xComfort;
2297 symid = ymax + yComfort;
2298 szmid = zmin - zComfort;
2299 } else {
2300 sxmid = xmax + xComfort;
2301 symid = ymin - yComfort;
2302 szmid = zmin - zComfort;
2303 }
2304 break;
2305 case G4Scale::z:
2306 if (vp.x() > 0.) {
2307 sxmid = xmax + xComfort;
2308 symid = ymin - yComfort;
2309 szmid = zmax + zComfort;
2310 } else {
2311 sxmid = xmin - xComfort;
2312 symid = ymin - yComfort;
2313 szmid = zmax + zComfort;
2314 }
2315 break;
2316 }
2317 }
2318
2319 /* Old code - kept for future reference.
2320 G4double sxmid(xmid), symid(ymid), szmid(zmid);
2321 if (autoPlacing) {
2322 sxmid = xmin + onePlusComfort * (xmax - xmin);
2323 symid = ymin - comfort * (ymax - ymin);
2324 szmid = zmin + onePlusComfort * (zmax - zmin);
2325 switch (scaleDirection) {
2326 case G4Scale::x:
2327 sxmid -= halfLength;
2328 break;
2329 case G4Scale::y:
2330 symid += halfLength;
2331 break;
2332 case G4Scale::z:
2333 szmid -= halfLength;
2334 break;
2335 }
2336 }
2337 */
2338
2339 /* sxmin, etc., not actually used. Comment out to prevent compiler
2340 warnings but keep in case need in future. Extract transform and
2341 scaleExtent into reduced code below.
2342 G4double sxmin(sxmid), sxmax(sxmid);
2343 G4double symin(symid), symax(symid);
2344 G4double szmin(szmid), szmax(szmid);
2345 G4Transform3D transform;
2346 G4VisExtent scaleExtent;
2347 switch (scaleDirection) {
2348 case G4Scale::x:
2349 sxmin = sxmid - halfLength;
2350 sxmax = sxmid + halfLength;
2351 scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
2352 break;
2353 case G4Scale::y:
2354 symin = symid - halfLength;
2355 symax = symid + halfLength;
2356 transform = G4RotateZ3D(halfpi);
2357 scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
2358 break;
2359 case G4Scale::z:
2360 szmin = szmid - halfLength;
2361 szmax = szmid + halfLength;
2362 transform = G4RotateY3D(halfpi);
2363 scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
2364 break;
2365 }
2366 */
2367 G4Transform3D transform;
2368 G4VisExtent scaleExtent;
2369 switch (scaleDirection) {
2370 case G4Scale::x:
2371 scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
2372 break;
2373 case G4Scale::y:
2374 transform = G4RotateZ3D(halfpi);
2375 scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
2376 break;
2377 case G4Scale::z:
2378 transform = G4RotateY3D(halfpi);
2379 scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
2380 break;
2381 }
2382 transform = G4Translate3D(sxmid,symid,szmid) * transform;
2383 ///////// G4VisExtent scaleExtent(sxmin, sxmax, symin, symax, szmin, szmax);
2384
2385 model->SetTransformation(transform);
2386 // Note: it is the responsibility of the model to act upon this, but
2387 // the extent is in local coordinates...
2388 model->SetExtent(scaleExtent);
2389 // This extent gets "added" to existing scene extent in
2390 // AddRunDurationModel below.
2391
2392 const G4String& currentSceneName = pScene -> GetName ();
2393 G4bool successful = pScene -> AddRunDurationModel (model, warn);
2394 if (successful) {
2395 if (verbosity >= G4VisManager::confirmations) {
2396 G4cout << "Scale of " << annotation
2397 << " added to scene \"" << currentSceneName << "\".";
2398 if (verbosity >= G4VisManager::parameters) {
2399 G4cout << "\n with extent " << scaleExtent
2400 << "\n at " << transform.getRotation()
2401 << transform.getTranslation();
2402 }
2403 G4cout << G4endl;
2404 }
2405 }
2406 else G4VisCommandsSceneAddUnsuccessful(verbosity);
2407
2409}
HepGeom::RotateZ3D G4RotateZ3D
HepGeom::Translate3D G4Translate3D
HepGeom::RotateY3D G4RotateY3D
double G4double
Definition: G4Types.hh:83
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
Direction
Definition: G4Scale.hh:41
const G4VisExtent & GetExtent() const
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:348
void SetGlobalDescription(const G4String &)
void SetExtent(const G4VisExtent &)
const G4String & GetGlobalDescription() const
void SetTransformation(const G4Transform3D &)
const G4ViewParameters & GetViewParameters() const
static G4double fCurrentTextSize
void G4VisCommandsSceneAddUnsuccessful(G4VisManager::Verbosity verbosity)
void CheckSceneAndNotifyHandlers(G4Scene *=nullptr)
static G4VisManager * fpVisManager
const G4Vector3D & GetViewpointDirection() const
const G4Vector3D & GetUpVector() const
G4double GetYmin() const
Definition: G4VisExtent.hh:101
G4double GetXmax() const
Definition: G4VisExtent.hh:100
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:75
G4double GetYmax() const
Definition: G4VisExtent.hh:102
G4double GetZmax() const
Definition: G4VisExtent.hh:104
G4double GetZmin() const
Definition: G4VisExtent.hh:103
G4double GetXmin() const
Definition: G4VisExtent.hh:99
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: