Geant4 11.1.1
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 ()
 
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 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 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
 

Detailed Description

Definition at line 380 of file G4VisCommandsSceneAdd.hh.

Constructor & Destructor Documentation

◆ G4VisCommandSceneAddScale()

G4VisCommandSceneAddScale::G4VisCommandSceneAddScale ( )

Definition at line 2149 of file G4VisCommandsSceneAdd.cc.

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

◆ ~G4VisCommandSceneAddScale()

G4VisCommandSceneAddScale::~G4VisCommandSceneAddScale ( )
virtual

Definition at line 2215 of file G4VisCommandsSceneAdd.cc.

2215 {
2216 delete fpCommand;
2217}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandSceneAddScale::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 2219 of file G4VisCommandsSceneAdd.cc.

2219 {
2220 return "";
2221}

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 2223 of file G4VisCommandsSceneAdd.cc.

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