Geant4 11.4.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 ()=default
 G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
virtual ~G4UImessenger ()
G4bool CommandsShouldBeInMaster () const

Additional Inherited Members

Static Public Member Functions inherited from G4VVisCommand
static G4VisManagerGetVisManager ()
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, const 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="")
void Twinkle (G4VViewer *currentViewer, const G4ViewParameters &baseVP, const std::vector< std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > > &paths)
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 CopyCameraParameters (G4ViewParameters &target, const G4ViewParameters &from)
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 LtoS (G4long l)
G4String DtoS (G4double a)
G4String BtoS (G4bool b)
G4int StoI (const G4String &s)
G4long StoL (const G4String &s)
G4double StoD (const G4String &s)
G4bool StoB (const 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 = nullptr
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
static G4bool fThereWasAViewer = false
static G4ViewParameters fExistingVP
static G4SceneTreeItem fExistingSceneTree

Detailed Description

Definition at line 397 of file G4VisCommandsSceneAdd.hh.

Constructor & Destructor Documentation

◆ G4VisCommandSceneAddScale()

G4VisCommandSceneAddScale::G4VisCommandSceneAddScale ( )

Definition at line 2213 of file G4VisCommandsSceneAdd.cc.

2213 {
2214 G4bool omitable;
2215 fpCommand = new G4UIcommand ("/vis/scene/add/scale", this);
2216 fpCommand -> SetGuidance
2217 ("Adds an annotated scale line to the current scene.");
2218 fpCommand -> SetGuidance
2219 ("If \"unit\" is \"auto\", length is roughly one tenth of the scene extent.");
2220 fpCommand -> SetGuidance
2221 ("If \"direction\" is \"auto\", scale is roughly in the plane of the current view.");
2222 fpCommand -> SetGuidance
2223 ("If \"placement\" is \"auto\", scale is placed at bottom left of current view."
2224 "\n Otherwise placed at (xmid,ymid,zmid).");
2225 fpCommand -> SetGuidance
2226 ("An annotated line in the specified direction with tick marks at the"
2227 "\nend. If autoPlacing is true it is required to be centred at the"
2228 "\nfront, right, bottom corner of the world space, comfortably outside"
2229 "\nthe existing bounding box/sphere so that existing objects do not"
2230 "\nobscure it. Otherwise it is required to be drawn with mid-point at"
2231 "\n(xmid, ymid, zmid)."
2232 "\n"
2233 "\nThe auto placing algorithm is (approx):"
2234 "\n x = xmin + (1 + comfort) * (xmax - xmin);"
2235 "\n y = ymin - comfort * (ymax - ymin);"
2236 "\n z = zmin + (1 + comfort) * (zmax - zmin);"
2237 "\n if direction == x then (x - length,y,z) to (x,y,z);"
2238 "\n if direction == y then (x,y,z) to (x,y + length,z);"
2239 "\n if direction == z then (x,y,z - length) to (x,y,z);"
2240 );
2241 G4UIparameter* parameter;
2242 parameter = new G4UIparameter ("length", 'd', omitable = true);
2243 parameter->SetDefaultValue (1.);
2244 fpCommand->SetParameter (parameter);
2245 parameter = new G4UIparameter ("unit", 's', omitable = true);
2246 parameter->SetDefaultValue ("auto");
2247 fpCommand->SetParameter (parameter);
2248 parameter = new G4UIparameter ("direction", 's', omitable = true);
2249 parameter->SetGuidance ("auto|x|y|z");
2250 parameter->SetDefaultValue ("auto");
2251 fpCommand->SetParameter (parameter);
2252 parameter = new G4UIparameter ("red", 'd', omitable = true);
2253 parameter->SetDefaultValue (1.);
2254 fpCommand->SetParameter (parameter);
2255 parameter = new G4UIparameter ("green", 'd', omitable = true);
2256 parameter->SetDefaultValue (0.);
2257 fpCommand->SetParameter (parameter);
2258 parameter = new G4UIparameter ("blue", 'd', omitable = true);
2259 parameter->SetDefaultValue (0.);
2260 fpCommand->SetParameter (parameter);
2261 parameter = new G4UIparameter ("placement", 's', omitable = true);
2262 parameter -> SetParameterCandidates("auto manual");
2263 parameter->SetDefaultValue ("auto");
2264 fpCommand->SetParameter (parameter);
2265 parameter = new G4UIparameter ("xmid", 'd', omitable = true);
2266 parameter->SetDefaultValue (0.);
2267 fpCommand->SetParameter (parameter);
2268 parameter = new G4UIparameter ("ymid", 'd', omitable = true);
2269 parameter->SetDefaultValue (0.);
2270 fpCommand->SetParameter (parameter);
2271 parameter = new G4UIparameter ("zmid", 'd', omitable = true);
2272 parameter->SetDefaultValue (0.);
2273 fpCommand->SetParameter (parameter);
2274 parameter = new G4UIparameter ("unit", 's', omitable = true);
2275 parameter->SetDefaultValue ("m");
2276 fpCommand->SetParameter (parameter);
2277}
bool G4bool
Definition G4Types.hh:86
void SetDefaultValue(const char *theDefaultValue)
void SetGuidance(const char *theGuidance)

◆ ~G4VisCommandSceneAddScale()

G4VisCommandSceneAddScale::~G4VisCommandSceneAddScale ( )
virtual

Definition at line 2279 of file G4VisCommandsSceneAdd.cc.

2279 {
2280 delete fpCommand;
2281}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandSceneAddScale::GetCurrentValue ( G4UIcommand * command)
virtual

Reimplemented from G4UImessenger.

Definition at line 2283 of file G4VisCommandsSceneAdd.cc.

2283 {
2284 return "";
2285}

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 2287 of file G4VisCommandsSceneAdd.cc.

2287 {
2288
2289 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
2290 G4bool warn = verbosity >= G4VisManager::warnings;
2291
2292 G4Scene* pScene = fpVisManager->GetCurrentScene();
2293 if (!pScene) {
2294 if (verbosity >= G4VisManager::errors) {
2295 G4warn << "ERROR: No current scene. Please create one." << G4endl;
2296 }
2297 return;
2298 } else {
2299 if (pScene->GetExtent().GetExtentRadius() <= 0.) {
2300 if (verbosity >= G4VisManager::errors) {
2301 G4warn
2302 << "ERROR: Scene has no extent. Add volumes or use \"/vis/scene/add/extent\"."
2303 << G4endl;
2304 }
2305 return;
2306 }
2307 }
2308
2309 G4double userLength, red, green, blue, xmid, ymid, zmid;
2310 G4String userLengthUnit, direction, placement, positionUnit;
2311 std::istringstream is (newValue);
2312 is >> userLength >> userLengthUnit >> direction
2313 >> red >> green >> blue
2314 >> placement
2315 >> xmid >> ymid >> zmid >> positionUnit;
2316
2317 G4double length = userLength;
2318 const G4VisExtent& sceneExtent = pScene->GetExtent(); // Existing extent.
2319 if (userLengthUnit == "auto") {
2320 const G4double lengthMax = 0.5 * sceneExtent.GetExtentRadius();
2321 const G4double intLog10Length = std::floor(std::log10(lengthMax));
2322 length = std::pow(10,intLog10Length);
2323 if (5.*length < lengthMax) length *= 5.;
2324 else if (2.*length < lengthMax) length *= 2.;
2325 } else {
2326 length *= G4UIcommand::ValueOf(userLengthUnit);
2327 }
2328 G4String annotation = G4BestUnit(length,"Length");
2329
2330 G4double unit = G4UIcommand::ValueOf(positionUnit);
2331 xmid *= unit; ymid *= unit; zmid *= unit;
2332
2333 Scale::Direction scaleDirection (Scale::x);
2334 if (direction[0] == 'y') scaleDirection = Scale::y;
2335 if (direction[0] == 'z') scaleDirection = Scale::z;
2336
2337 G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
2338 if (!pViewer) {
2339 if (verbosity >= G4VisManager::errors) {
2340 G4warn <<
2341 "ERROR: G4VisCommandSceneAddScale::SetNewValue: no viewer."
2342 "\n Auto direction needs a viewer."
2343 << G4endl;
2344 }
2345 return;
2346 }
2347
2348 const G4Vector3D& vp =
2350 const G4Vector3D& up =
2351 pViewer->GetViewParameters().GetUpVector();
2352
2353 if (direction == "auto") { // Takes cue from viewer.
2354 if (std::abs(vp.x()) > std::abs(vp.y()) &&
2355 std::abs(vp.x()) > std::abs(vp.z())) { // x viewpoint
2356 if (std::abs(up.y()) > std::abs(up.z())) scaleDirection = Scale::z;
2357 else scaleDirection = Scale::y;
2358 }
2359 else if (std::abs(vp.y()) > std::abs(vp.x()) &&
2360 std::abs(vp.y()) > std::abs(vp.z())) { // y viewpoint
2361 if (std::abs(up.x()) > std::abs(up.z())) scaleDirection = Scale::z;
2362 else scaleDirection = Scale::x;
2363 }
2364 else if (std::abs(vp.z()) > std::abs(vp.x()) &&
2365 std::abs(vp.z()) > std::abs(vp.y())) { // z viewpoint
2366 if (std::abs(up.y()) > std::abs(up.x())) scaleDirection = Scale::x;
2367 else scaleDirection = Scale::y;
2368 }
2369 }
2370
2371 G4bool autoPlacing = false; if (placement == "auto") autoPlacing = true;
2372 // Parameters read and interpreted.
2373
2374 // Useful constants, etc...
2375 const G4double halfLength(length / 2.);
2376 const G4double comfort(0.01); // 0.15 seems too big. 0.05 might be better.
2377 const G4double freeLengthFraction (1. + 2. * comfort);
2378
2379 const G4double xmin = sceneExtent.GetXmin();
2380 const G4double xmax = sceneExtent.GetXmax();
2381 const G4double ymin = sceneExtent.GetYmin();
2382 const G4double ymax = sceneExtent.GetYmax();
2383 const G4double zmin = sceneExtent.GetZmin();
2384 const G4double zmax = sceneExtent.GetZmax();
2385
2386 // Test existing extent and issue warnings...
2387 G4bool worried = false;
2388 if (sceneExtent.GetExtentRadius() == 0) {
2389 worried = true;
2390 if (verbosity >= G4VisManager::warnings) {
2391 G4warn <<
2392 "WARNING: Existing scene does not yet have any extent."
2393 "\n Maybe you have not yet added any geometrical object."
2394 << G4endl;
2395 }
2396 }
2397
2398 // Test existing scene for room...
2399 G4bool room = true;
2400 switch (scaleDirection) {
2401 case Scale::x:
2402 if (freeLengthFraction * (xmax - xmin) < length) room = false;
2403 break;
2404 case Scale::y:
2405 if (freeLengthFraction * (ymax - ymin) < length) room = false;
2406 break;
2407 case Scale::z:
2408 if (freeLengthFraction * (zmax - zmin) < length) room = false;
2409 break;
2410 }
2411 if (!room) {
2412 worried = true;
2413 if (verbosity >= G4VisManager::warnings) {
2414 G4warn <<
2415 "WARNING: Not enough room in existing scene. Maybe scale is too long."
2416 << G4endl;
2417 }
2418 }
2419 if (worried) {
2420 if (verbosity >= G4VisManager::warnings) {
2421 G4warn <<
2422 "WARNING: The scale you have asked for is bigger than the existing"
2423 "\n scene. Maybe you have added it too soon. It is recommended that"
2424 "\n you add the scale last so that it can be correctly auto-positioned"
2425 "\n so as not to be obscured by any existing object and so that the"
2426 "\n view parameters can be correctly recalculated."
2427 << G4endl;
2428 }
2429 }
2430
2431 // Now figure out the extent...
2432 //
2433 // This creates a representation of annotated line in the specified
2434 // direction with tick marks at the end. If autoPlacing is true it
2435 // is required to be centred at the front, right, bottom corner of
2436 // the world space, comfortably outside the existing bounding
2437 // box/sphere so that existing objects do not obscure it. Otherwise
2438 // it is required to be drawn with mid-point at (xmid, ymid, zmid).
2439 //
2440 // The auto placing algorithm might be:
2441 // x = xmin + (1 + comfort) * (xmax - xmin)
2442 // y = ymin - comfort * (ymax - ymin)
2443 // z = zmin + (1 + comfort) * (zmax - zmin)
2444 // if direction == x then (x - length,y,z) to (x,y,z)
2445 // if direction == y then (x,y,z) to (x,y + length,z)
2446 // if direction == z then (x,y,z - length) to (x,y,z)
2447 //
2448 // Implement this in two parts. Here, use the scale's extent to
2449 // "expand" the scene's extent. Then rendering - in
2450 // G4VSceneHandler::AddPrimitive(const G4Scale&) - simply has to
2451 // ensure it's within the new extent.
2452 //
2453
2454 G4double sxmid(xmid), symid(ymid), szmid(zmid);
2455 if (autoPlacing) {
2456 // Aim to place at bottom right of screen in current view.
2457 // Give some comfort zone.
2458 const G4double xComfort = comfort * (xmax - xmin);
2459 const G4double yComfort = comfort * (ymax - ymin);
2460 const G4double zComfort = comfort * (zmax - zmin);
2461 switch (scaleDirection) {
2462 case Scale::x:
2463 if (vp.z() > 0.) {
2464 sxmid = xmax + xComfort;
2465 symid = ymin - yComfort;
2466 szmid = zmin - zComfort;
2467 } else {
2468 sxmid = xmin - xComfort;
2469 symid = ymin - yComfort;
2470 szmid = zmax + zComfort;
2471 }
2472 break;
2473 case Scale::y:
2474 if (vp.x() > 0.) {
2475 sxmid = xmin - xComfort;
2476 symid = ymax + yComfort;
2477 szmid = zmin - zComfort;
2478 } else {
2479 sxmid = xmax + xComfort;
2480 symid = ymin - yComfort;
2481 szmid = zmin - zComfort;
2482 }
2483 break;
2484 case Scale::z:
2485 if (vp.x() > 0.) {
2486 sxmid = xmax + xComfort;
2487 symid = ymin - yComfort;
2488 szmid = zmax + zComfort;
2489 } else {
2490 sxmid = xmin - xComfort;
2491 symid = ymin - yComfort;
2492 szmid = zmax + zComfort;
2493 }
2494 break;
2495 }
2496 }
2497
2498 G4Transform3D transform;
2499 const G4double h = halfLength;
2500 const G4double t = h/5.;
2501 G4VisExtent scaleExtent(-h,h,-t,t,-t,t);
2502 switch (scaleDirection) {
2503 case Scale::x:
2504 break;
2505 case Scale::y:
2506 transform = G4RotateZ3D(halfpi);
2507 break;
2508 case Scale::z:
2509 transform = G4RotateY3D(halfpi);
2510 break;
2511 }
2512 transform = G4Translate3D(sxmid,symid,szmid) * transform;
2513 scaleExtent = scaleExtent.Transform(transform);
2514
2515 G4Colour colour(red, green, blue);
2516 if (direction == "auto") {
2517 switch (scaleDirection) {
2518 case Scale::x:
2519 colour = G4Colour::Red();
2520 break;
2521 case Scale::y:
2522 colour = G4Colour::Green();
2523 break;
2524 case Scale::z:
2525 colour = G4Colour::Blue();
2526 break;
2527 }
2528 }
2529 G4VisAttributes visAttr(colour);
2530
2531 Scale* scale = new Scale
2532 (visAttr, length, transform,
2533 annotation, fCurrentTextSize, colour);
2534 G4VModel* model = new G4CallbackModel<Scale>(scale);
2535 model->SetType("Scale");
2536 model->SetGlobalTag("Scale");
2537 model->SetGlobalDescription("Scale: " + newValue);
2538 model->SetExtent(scaleExtent);
2539
2540 const G4String& currentSceneName = pScene -> GetName ();
2541 G4bool successful = pScene -> AddRunDurationModel (model, warn);
2542 if (successful) {
2543 if (verbosity >= G4VisManager::confirmations) {
2544 G4cout << "Scale of " << annotation
2545 << " added to scene \"" << currentSceneName << "\".";
2546 if (verbosity >= G4VisManager::parameters) {
2547 G4cout << "\n with extent " << scaleExtent
2548 << "\n at " << transform.getRotation()
2549 << " " << transform.getTranslation();
2550 }
2551 G4cout << G4endl;
2552 }
2553 }
2554 else G4VisCommandsSceneAddUnsuccessful(verbosity);
2555
2557}
#define G4warn
Definition G4Scene.cc:41
#define G4BestUnit(a, b)
HepGeom::Transform3D G4Transform3D
HepGeom::RotateZ3D G4RotateZ3D
HepGeom::RotateY3D G4RotateY3D
HepGeom::Translate3D G4Translate3D
double G4double
Definition G4Types.hh:83
HepGeom::Vector3D< G4double > G4Vector3D
Definition G4Vector3D.hh:34
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4Colour Green()
Definition G4Colour.hh:181
static G4Colour Red()
Definition G4Colour.hh:180
static G4Colour Blue()
Definition G4Colour.hh:182
const G4VisExtent & GetExtent() const
static G4double ValueOf(const char *unitName)
void SetType(const G4String &)
void SetGlobalDescription(const G4String &)
void SetGlobalTag(const G4String &)
void SetExtent(const G4VisExtent &)
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
G4double GetXmax() const
G4double GetExtentRadius() const
G4double GetYmax() const
G4double GetZmax() const
G4double GetZmin() const
G4double GetXmin() const
CLHEP::HepRotation getRotation() const
CLHEP::Hep3Vector getTranslation() const

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