Geant4 11.2.2
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, 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 (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 380 of file G4VisCommandsSceneAdd.hh.

Constructor & Destructor Documentation

◆ G4VisCommandSceneAddScale()

G4VisCommandSceneAddScale::G4VisCommandSceneAddScale ( )

Definition at line 2151 of file G4VisCommandsSceneAdd.cc.

2151 {
2152 G4bool omitable;
2153 fpCommand = new G4UIcommand ("/vis/scene/add/scale", this);
2154 fpCommand -> SetGuidance
2155 ("Adds an annotated scale line to the current scene.");
2156 fpCommand -> SetGuidance
2157 ("If \"unit\" is \"auto\", length is roughly one tenth of the scene extent.");
2158 fpCommand -> SetGuidance
2159 ("If \"direction\" is \"auto\", scale is roughly in the plane of the current view.");
2160 fpCommand -> SetGuidance
2161 ("If \"placement\" is \"auto\", scale is placed at bottom left of current view."
2162 "\n Otherwise placed at (xmid,ymid,zmid).");
2163 fpCommand -> SetGuidance
2164 ("An annotated line in the specified direction with tick marks at the"
2165 "\nend. If autoPlacing is true it is required to be centred at the"
2166 "\nfront, right, bottom corner of the world space, comfortably outside"
2167 "\nthe existing bounding box/sphere so that existing objects do not"
2168 "\nobscure it. Otherwise it is required to be drawn with mid-point at"
2169 "\n(xmid, ymid, zmid)."
2170 "\n"
2171 "\nThe auto placing algorithm is (approx):"
2172 "\n x = xmin + (1 + comfort) * (xmax - xmin);"
2173 "\n y = ymin - comfort * (ymax - ymin);"
2174 "\n z = zmin + (1 + comfort) * (zmax - zmin);"
2175 "\n if direction == x then (x - length,y,z) to (x,y,z);"
2176 "\n if direction == y then (x,y,z) to (x,y + length,z);"
2177 "\n if direction == z then (x,y,z - length) to (x,y,z);"
2178 );
2179 G4UIparameter* parameter;
2180 parameter = new G4UIparameter ("length", 'd', omitable = true);
2181 parameter->SetDefaultValue (1.);
2182 fpCommand->SetParameter (parameter);
2183 parameter = new G4UIparameter ("unit", 's', omitable = true);
2184 parameter->SetDefaultValue ("auto");
2185 fpCommand->SetParameter (parameter);
2186 parameter = new G4UIparameter ("direction", 's', omitable = true);
2187 parameter->SetGuidance ("auto|x|y|z");
2188 parameter->SetDefaultValue ("auto");
2189 fpCommand->SetParameter (parameter);
2190 parameter = new G4UIparameter ("red", 'd', omitable = true);
2191 parameter->SetDefaultValue (1.);
2192 fpCommand->SetParameter (parameter);
2193 parameter = new G4UIparameter ("green", 'd', omitable = true);
2194 parameter->SetDefaultValue (0.);
2195 fpCommand->SetParameter (parameter);
2196 parameter = new G4UIparameter ("blue", 'd', omitable = true);
2197 parameter->SetDefaultValue (0.);
2198 fpCommand->SetParameter (parameter);
2199 parameter = new G4UIparameter ("placement", 's', omitable = true);
2200 parameter -> SetParameterCandidates("auto manual");
2201 parameter->SetDefaultValue ("auto");
2202 fpCommand->SetParameter (parameter);
2203 parameter = new G4UIparameter ("xmid", 'd', omitable = true);
2204 parameter->SetDefaultValue (0.);
2205 fpCommand->SetParameter (parameter);
2206 parameter = new G4UIparameter ("ymid", 'd', omitable = true);
2207 parameter->SetDefaultValue (0.);
2208 fpCommand->SetParameter (parameter);
2209 parameter = new G4UIparameter ("zmid", 'd', omitable = true);
2210 parameter->SetDefaultValue (0.);
2211 fpCommand->SetParameter (parameter);
2212 parameter = new G4UIparameter ("unit", 's', omitable = true);
2213 parameter->SetDefaultValue ("m");
2214 fpCommand->SetParameter (parameter);
2215}
bool G4bool
Definition G4Types.hh:86
void SetParameter(G4UIparameter *const newParameter)
void SetDefaultValue(const char *theDefaultValue)
void SetGuidance(const char *theGuidance)

◆ ~G4VisCommandSceneAddScale()

G4VisCommandSceneAddScale::~G4VisCommandSceneAddScale ( )
virtual

Definition at line 2217 of file G4VisCommandsSceneAdd.cc.

2217 {
2218 delete fpCommand;
2219}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandSceneAddScale::GetCurrentValue ( G4UIcommand * command)
virtual

Reimplemented from G4UImessenger.

Definition at line 2221 of file G4VisCommandsSceneAdd.cc.

2221 {
2222 return "";
2223}

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 2225 of file G4VisCommandsSceneAdd.cc.

2225 {
2226
2228 G4bool warn = verbosity >= G4VisManager::warnings;
2229
2231 if (!pScene) {
2232 if (verbosity >= G4VisManager::errors) {
2233 G4warn << "ERROR: No current scene. Please create one." << G4endl;
2234 }
2235 return;
2236 } else {
2237 if (pScene->GetExtent().GetExtentRadius() <= 0.) {
2238 if (verbosity >= G4VisManager::errors) {
2239 G4warn
2240 << "ERROR: Scene has no extent. Add volumes or use \"/vis/scene/add/extent\"."
2241 << G4endl;
2242 }
2243 return;
2244 }
2245 }
2246
2247 G4double userLength, red, green, blue, xmid, ymid, zmid;
2248 G4String userLengthUnit, direction, placement, positionUnit;
2249 std::istringstream is (newValue);
2250 is >> userLength >> userLengthUnit >> direction
2251 >> red >> green >> blue
2252 >> placement
2253 >> xmid >> ymid >> zmid >> positionUnit;
2254
2255 G4double length = userLength;
2256 const G4VisExtent& sceneExtent = pScene->GetExtent(); // Existing extent.
2257 if (userLengthUnit == "auto") {
2258 const G4double lengthMax = 0.5 * sceneExtent.GetExtentRadius();
2259 const G4double intLog10Length = std::floor(std::log10(lengthMax));
2260 length = std::pow(10,intLog10Length);
2261 if (5.*length < lengthMax) length *= 5.;
2262 else if (2.*length < lengthMax) length *= 2.;
2263 } else {
2264 length *= G4UIcommand::ValueOf(userLengthUnit);
2265 }
2266 G4String annotation = G4BestUnit(length,"Length");
2267
2268 G4double unit = G4UIcommand::ValueOf(positionUnit);
2269 xmid *= unit; ymid *= unit; zmid *= unit;
2270
2271 Scale::Direction scaleDirection (Scale::x);
2272 if (direction[0] == 'y') scaleDirection = Scale::y;
2273 if (direction[0] == 'z') scaleDirection = Scale::z;
2274
2276 if (!pViewer) {
2277 if (verbosity >= G4VisManager::errors) {
2278 G4warn <<
2279 "ERROR: G4VisCommandSceneAddScale::SetNewValue: no viewer."
2280 "\n Auto direction needs a viewer."
2281 << G4endl;
2282 }
2283 return;
2284 }
2285
2286 const G4Vector3D& vp =
2288 const G4Vector3D& up =
2289 pViewer->GetViewParameters().GetUpVector();
2290
2291 if (direction == "auto") { // Takes cue from viewer.
2292 if (std::abs(vp.x()) > std::abs(vp.y()) &&
2293 std::abs(vp.x()) > std::abs(vp.z())) { // x viewpoint
2294 if (std::abs(up.y()) > std::abs(up.z())) scaleDirection = Scale::z;
2295 else scaleDirection = Scale::y;
2296 }
2297 else if (std::abs(vp.y()) > std::abs(vp.x()) &&
2298 std::abs(vp.y()) > std::abs(vp.z())) { // y viewpoint
2299 if (std::abs(up.x()) > std::abs(up.z())) scaleDirection = Scale::z;
2300 else scaleDirection = Scale::x;
2301 }
2302 else if (std::abs(vp.z()) > std::abs(vp.x()) &&
2303 std::abs(vp.z()) > std::abs(vp.y())) { // z viewpoint
2304 if (std::abs(up.y()) > std::abs(up.x())) scaleDirection = Scale::x;
2305 else scaleDirection = Scale::y;
2306 }
2307 }
2308
2309 G4bool autoPlacing = false; if (placement == "auto") autoPlacing = true;
2310 // Parameters read and interpreted.
2311
2312 // Useful constants, etc...
2313 const G4double halfLength(length / 2.);
2314 const G4double comfort(0.01); // 0.15 seems too big. 0.05 might be better.
2315 const G4double freeLengthFraction (1. + 2. * comfort);
2316
2317 const G4double xmin = sceneExtent.GetXmin();
2318 const G4double xmax = sceneExtent.GetXmax();
2319 const G4double ymin = sceneExtent.GetYmin();
2320 const G4double ymax = sceneExtent.GetYmax();
2321 const G4double zmin = sceneExtent.GetZmin();
2322 const G4double zmax = sceneExtent.GetZmax();
2323
2324 // Test existing extent and issue warnings...
2325 G4bool worried = false;
2326 if (sceneExtent.GetExtentRadius() == 0) {
2327 worried = true;
2328 if (verbosity >= G4VisManager::warnings) {
2329 G4warn <<
2330 "WARNING: Existing scene does not yet have any extent."
2331 "\n Maybe you have not yet added any geometrical object."
2332 << G4endl;
2333 }
2334 }
2335
2336 // Test existing scene for room...
2337 G4bool room = true;
2338 switch (scaleDirection) {
2339 case Scale::x:
2340 if (freeLengthFraction * (xmax - xmin) < length) room = false;
2341 break;
2342 case Scale::y:
2343 if (freeLengthFraction * (ymax - ymin) < length) room = false;
2344 break;
2345 case Scale::z:
2346 if (freeLengthFraction * (zmax - zmin) < length) room = false;
2347 break;
2348 }
2349 if (!room) {
2350 worried = true;
2351 if (verbosity >= G4VisManager::warnings) {
2352 G4warn <<
2353 "WARNING: Not enough room in existing scene. Maybe scale is too long."
2354 << G4endl;
2355 }
2356 }
2357 if (worried) {
2358 if (verbosity >= G4VisManager::warnings) {
2359 G4warn <<
2360 "WARNING: The scale you have asked for is bigger than the existing"
2361 "\n scene. Maybe you have added it too soon. It is recommended that"
2362 "\n you add the scale last so that it can be correctly auto-positioned"
2363 "\n so as not to be obscured by any existing object and so that the"
2364 "\n view parameters can be correctly recalculated."
2365 << G4endl;
2366 }
2367 }
2368
2369 // Now figure out the extent...
2370 //
2371 // This creates a representation of annotated line in the specified
2372 // direction with tick marks at the end. If autoPlacing is true it
2373 // is required to be centred at the front, right, bottom corner of
2374 // the world space, comfortably outside the existing bounding
2375 // box/sphere so that existing objects do not obscure it. Otherwise
2376 // it is required to be drawn with mid-point at (xmid, ymid, zmid).
2377 //
2378 // The auto placing algorithm might be:
2379 // x = xmin + (1 + comfort) * (xmax - xmin)
2380 // y = ymin - comfort * (ymax - ymin)
2381 // z = zmin + (1 + comfort) * (zmax - zmin)
2382 // if direction == x then (x - length,y,z) to (x,y,z)
2383 // if direction == y then (x,y,z) to (x,y + length,z)
2384 // if direction == z then (x,y,z - length) to (x,y,z)
2385 //
2386 // Implement this in two parts. Here, use the scale's extent to
2387 // "expand" the scene's extent. Then rendering - in
2388 // G4VSceneHandler::AddPrimitive(const G4Scale&) - simply has to
2389 // ensure it's within the new extent.
2390 //
2391
2392 G4double sxmid(xmid), symid(ymid), szmid(zmid);
2393 if (autoPlacing) {
2394 // Aim to place at bottom right of screen in current view.
2395 // Give some comfort zone.
2396 const G4double xComfort = comfort * (xmax - xmin);
2397 const G4double yComfort = comfort * (ymax - ymin);
2398 const G4double zComfort = comfort * (zmax - zmin);
2399 switch (scaleDirection) {
2400 case Scale::x:
2401 if (vp.z() > 0.) {
2402 sxmid = xmax + xComfort;
2403 symid = ymin - yComfort;
2404 szmid = zmin - zComfort;
2405 } else {
2406 sxmid = xmin - xComfort;
2407 symid = ymin - yComfort;
2408 szmid = zmax + zComfort;
2409 }
2410 break;
2411 case Scale::y:
2412 if (vp.x() > 0.) {
2413 sxmid = xmin - xComfort;
2414 symid = ymax + yComfort;
2415 szmid = zmin - zComfort;
2416 } else {
2417 sxmid = xmax + xComfort;
2418 symid = ymin - yComfort;
2419 szmid = zmin - zComfort;
2420 }
2421 break;
2422 case Scale::z:
2423 if (vp.x() > 0.) {
2424 sxmid = xmax + xComfort;
2425 symid = ymin - yComfort;
2426 szmid = zmax + zComfort;
2427 } else {
2428 sxmid = xmin - xComfort;
2429 symid = ymin - yComfort;
2430 szmid = zmax + zComfort;
2431 }
2432 break;
2433 }
2434 }
2435
2436 G4Transform3D transform;
2437 const G4double h = halfLength;
2438 const G4double t = h/5.;
2439 G4VisExtent scaleExtent(-h,h,-t,t,-t,t);
2440 switch (scaleDirection) {
2441 case Scale::x:
2442 break;
2443 case Scale::y:
2444 transform = G4RotateZ3D(halfpi);
2445 break;
2446 case Scale::z:
2447 transform = G4RotateY3D(halfpi);
2448 break;
2449 }
2450 transform = G4Translate3D(sxmid,symid,szmid) * transform;
2451 scaleExtent = scaleExtent.Transform(transform);
2452
2453 G4Colour colour(red, green, blue);
2454 if (direction == "auto") {
2455 switch (scaleDirection) {
2456 case Scale::x:
2457 colour = G4Colour::Red();
2458 break;
2459 case Scale::y:
2460 colour = G4Colour::Green();
2461 break;
2462 case Scale::z:
2463 colour = G4Colour::Blue();
2464 break;
2465 }
2466 }
2467 G4VisAttributes visAttr(colour);
2468
2469 Scale* scale = new Scale
2470 (visAttr, length, transform,
2471 annotation, fCurrentTextSize, colour);
2472 G4VModel* model = new G4CallbackModel<Scale>(scale);
2473 model->SetType("Scale");
2474 model->SetGlobalTag("Scale");
2475 model->SetGlobalDescription("Scale: " + newValue);
2476 model->SetExtent(scaleExtent);
2477
2478 const G4String& currentSceneName = pScene -> GetName ();
2479 G4bool successful = pScene -> AddRunDurationModel (model, warn);
2480 if (successful) {
2481 if (verbosity >= G4VisManager::confirmations) {
2482 G4cout << "Scale of " << annotation
2483 << " added to scene \"" << currentSceneName << "\".";
2484 if (verbosity >= G4VisManager::parameters) {
2485 G4cout << "\n with extent " << scaleExtent
2486 << "\n at " << transform.getRotation()
2487 << " " << transform.getTranslation();
2488 }
2489 G4cout << G4endl;
2490 }
2491 }
2492 else G4VisCommandsSceneAddUnsuccessful(verbosity);
2493
2495}
#define G4warn
Definition G4Scene.cc:41
#define G4BestUnit(a, b)
HepGeom::RotateZ3D G4RotateZ3D
HepGeom::RotateY3D G4RotateY3D
HepGeom::Translate3D G4Translate3D
double G4double
Definition G4Types.hh:83
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4Colour Green()
Definition G4Colour.hh:162
static G4Colour Red()
Definition G4Colour.hh:161
static G4Colour Blue()
Definition G4Colour.hh:163
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
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: