Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ViewParameters.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28//
29// John Allison 19th July 1996
30// View parameters and options.
31
32#include "G4ViewParameters.hh"
33
34#include "G4VisManager.hh"
35#include "G4VPhysicalVolume.hh"
36#include "G4UnitsTable.hh"
37#include "G4SystemOfUnits.hh"
38#include "G4Polyhedron.hh"
39
40#include <sstream>
41#include <cmath>
42
43#define G4warn G4cout
44
46 fDrawingStyle (wireframe),
47 fNumberOfCloudPoints(10000),
48 fAuxEdgeVisible (false),
49 fCulling (true),
50 fCullInvisible (true),
51 fDensityCulling (false),
52 fVisibleDensity (0.01 * g / cm3),
53 fCullCovered (false),
54 fCBDAlgorithmNumber (0),
55 fSection (false),
56 fSectionPlane (),
57 fCutawayMode (cutawayUnion),
58 fCutawayPlanes (),
59 fExplodeFactor (1.),
60 fNoOfSides (),
61 fViewpointDirection (G4Vector3D (0., 0., 1.)), // On z-axis.
62 fUpVector (G4Vector3D (0., 1., 0.)), // y-axis up.
63 fFieldHalfAngle (0.), // Orthogonal projection.
64 fZoomFactor (1.),
65 fScaleFactor (G4Vector3D (1., 1., 1.)),
66 fCurrentTargetPoint (),
67 fDolly (0.),
68 fLightsMoveWithCamera (false),
69 fRelativeLightpointDirection (G4Vector3D (1., 1., 1.)),
70 fActualLightpointDirection (G4Vector3D (1., 1., 1.)),
71 fDefaultVisAttributes (),
72 fDefaultTextVisAttributes (G4Colour (0., 0., 1.)),
73 fDefaultMarker (),
74 fGlobalMarkerScale (1.),
75 fGlobalLineWidthScale (1.),
76 fMarkerNotHidden (true),
77 fWindowSizeHintX (600),
78 fWindowSizeHintY (600),
79 fWindowLocationHintX(0),
80 fWindowLocationHintY(0),
81 fWindowLocationHintXNegative(true),
82 fWindowLocationHintYNegative(false),
83 fGeometryMask(0),
84 fAutoRefresh (false),
85 fBackgroundColour (G4Colour(0.,0.,0.)), // Black
86 fPicking (false),
87 fRotationStyle (constrainUpDirection),
88 fSpecialMeshRendering(false),
89 fSpecialMeshRenderingOption(meshAsDefault),
90 fTransparencyByDepth(0.),
91 fTransparencyByDepthOption(1),
92 fZoomToCursor(false),
93 fDotsSmooth(true),
94 fDotsSize(1.)
95{
96 // Pick up default no of sides from G4Polyhedron.
97 // Note that this parameter is variously called:
98 // No of sides
99 // NumberOfRotationSteps
100 // Line segments per circle
101 // It refers to the approximation of a circle by a polygon of
102 // stated number of sides.
104
105 fDefaultMarker.SetScreenSize (5.);
106 // Markers are 5 pixels "overall" size, i.e., diameter.
107}
108
110
112(const G4Vector3D& scaleFactorMultiplier) {
113 fScaleFactor.setX(fScaleFactor.x() * scaleFactorMultiplier.x());
114 fScaleFactor.setY(fScaleFactor.y() * scaleFactorMultiplier.y());
115 fScaleFactor.setZ(fScaleFactor.z() * scaleFactorMultiplier.z());
116}
117
119 SetViewAndLights (fViewpointDirection);
120 return fActualLightpointDirection;
121}
122
123// Useful quantities - begin snippet.
124// Here Follow functions to evaluate the above algorithms as a
125// function of the radius of the Bounding Sphere of the object being
126// viewed. Call them in the order given - for efficiency, later
127// functions depend on the results of earlier ones (Store the
128// results of earlier functions in your own temporary variables -
129// see, for example, G4OpenGLView::SetView ().)
130
132 G4double cameraDistance;
133 if (fFieldHalfAngle == 0.) {
134 cameraDistance = radius;
135 }
136 else {
137 cameraDistance = radius / std::sin (fFieldHalfAngle) - fDolly;
138 }
139 return cameraDistance;
140}
141
143 G4double radius) const {
144 const G4double small = 1.e-6 * radius;
145 G4double nearDistance = cameraDistance - radius;
146 if (nearDistance < small) nearDistance = small;
147 return nearDistance;
148}
149
151 G4double nearDistance,
152 G4double radius) const {
153 G4double farDistance = cameraDistance + radius;
154 if (farDistance < nearDistance) farDistance = nearDistance;
155 return farDistance;
156}
157
159 G4double radius) const {
160 G4double frontHalfHeight;
161 if (fFieldHalfAngle == 0.) {
162 frontHalfHeight = radius / fZoomFactor;
163 }
164 else {
165 frontHalfHeight = nearDistance * std::tan (fFieldHalfAngle) / fZoomFactor;
166 }
167 return frontHalfHeight;
168}
169// Useful quantities - end snippet.
170
172 if (fCutawayPlanes.size () < 3 ) {
173 fCutawayPlanes.push_back (cutawayPlane);
174 }
175 else {
176 G4warn <<
177 "ERROR: G4ViewParameters::AddCutawayPlane:"
178 "\n A maximum of 3 cutaway planes supported." << G4endl;
179 }
180}
181
183(size_t index, const G4Plane3D& cutawayPlane) {
184 if (index >= fCutawayPlanes.size()) {
185 G4warn <<
186 "ERROR: G4ViewParameters::ChangeCutawayPlane:"
187 "\n Plane " << index << " does not exist." << G4endl;
188 } else {
189 fCutawayPlanes[index] = cutawayPlane;
190 }
191}
192
194 const G4double reasonableMaximum = 10.0 * g / cm3;
195 if (visibleDensity < 0) {
196 G4warn << "G4ViewParameters::SetVisibleDensity: attempt to set negative "
197 "density - ignored." << G4endl;
198 }
199 else {
200 if (visibleDensity > reasonableMaximum) {
201 G4warn << "G4ViewParameters::SetVisibleDensity: density > "
202 << G4BestUnit (reasonableMaximum, "Volumic Mass")
203 << " - did you mean this?"
204 << G4endl;
205 }
206 fVisibleDensity = visibleDensity;
207 }
208}
209
211 const G4int nSidesMin = fDefaultVisAttributes.GetMinLineSegmentsPerCircle();
212 if (nSides < nSidesMin) {
213 nSides = nSidesMin;
214 G4warn << "G4ViewParameters::SetNoOfSides: attempt to set the"
215 "\nnumber of sides per circle < " << nSidesMin
216 << "; forced to " << nSides << G4endl;
217 }
218 fNoOfSides = nSides;
219 return fNoOfSides;
220}
221
223 const G4int nPointsMin = 100;
224 if (nPoints < nPointsMin) {
225 nPoints = nPointsMin;
226 G4warn << "G4ViewParameters::SetNumberOfCloudPoints:"
227 "\nnumber of points per cloud set to minimum " << nPoints
228 << G4endl;
229 }
230 fNumberOfCloudPoints = nPoints;
231 return fNumberOfCloudPoints;
232}
233
235(const G4Vector3D& viewpointDirection) {
236
237 fViewpointDirection = viewpointDirection;
238
239 // If the requested viewpoint direction is parallel to the up
240 // vector, the orientation of the view is undefined...
241 if (fViewpointDirection.unit() * fUpVector.unit() > .9999) {
242 static G4bool firstTime = true;
243 if (firstTime) {
244 firstTime = false;
245 G4warn <<
246 "WARNING: Viewpoint direction is very close to the up vector direction."
247 "\n Change the up vector or \"/vis/viewer/set/rotationStyle freeRotation\"."
248 << G4endl;
249 }
250 }
251
252 // Move the lights too if requested...
253 if (fLightsMoveWithCamera) {
254 G4Vector3D zprime = fViewpointDirection.unit ();
255 G4Vector3D xprime = (fUpVector.cross (zprime)).unit ();
256 G4Vector3D yprime = zprime.cross (xprime);
257 fActualLightpointDirection =
258 fRelativeLightpointDirection.x () * xprime +
259 fRelativeLightpointDirection.y () * yprime +
260 fRelativeLightpointDirection.z () * zprime;
261 } else {
262 fActualLightpointDirection = fRelativeLightpointDirection;
263 }
264}
265
267(const G4Vector3D& lightpointDirection) {
268 fRelativeLightpointDirection = lightpointDirection;
269 SetViewAndLights (fViewpointDirection);
270}
271
273 G4Vector3D unitRight = (fUpVector.cross (fViewpointDirection)).unit();
274 G4Vector3D unitUp = (fViewpointDirection.cross (unitRight)).unit();
275 fCurrentTargetPoint = right * unitRight + up * unitUp;
276}
277
279 IncrementPan (right,up, 0);
280}
281
283 G4Vector3D unitRight = (fUpVector.cross (fViewpointDirection)).unit();
284 G4Vector3D unitUp = (fViewpointDirection.cross (unitRight)).unit();
285 fCurrentTargetPoint += right * unitRight + up * unitUp + distance * fViewpointDirection;
286}
287
290 // If target exists with same signifier just change vis attributes.
291 G4bool duplicateTarget = false;
292 auto i = fVisAttributesModifiers.begin();
293 for (; i < fVisAttributesModifiers.end(); ++i) {
294 if (vam.GetPVNameCopyNoPath() == (*i).GetPVNameCopyNoPath() &&
295 vam.GetVisAttributesSignifier() == (*i).GetVisAttributesSignifier()) {
296 duplicateTarget = true;
297 break;
298 }
299 }
300 if (duplicateTarget) (*i).SetVisAttributes(vam.GetVisAttributes());
301 else fVisAttributesModifiers.push_back(vam);
302}
303
305(const G4Point3D standardTargetPoint) const
306{
307 std::ostringstream oss;
308
309 oss << "#\n# Camera and lights commands";
310
311 oss << "\n/vis/viewer/set/viewpointVector "
312 << fViewpointDirection.x()
313 << ' ' << fViewpointDirection.y()
314 << ' ' << fViewpointDirection.z();
315
316 oss << "\n/vis/viewer/set/upVector "
317 << fUpVector.x()
318 << ' ' << fUpVector.y()
319 << ' ' << fUpVector.z();
320
321 oss << "\n/vis/viewer/set/projection ";
322 if (fFieldHalfAngle == 0.) {
323 oss
324 << "orthogonal";
325 } else {
326 oss
327 << "perspective "
328 << fFieldHalfAngle/deg
329 << " deg";
330 }
331
332 oss << "\n/vis/viewer/zoomTo "
333 << fZoomFactor;
334
335 oss << "\n/vis/viewer/scaleTo "
336 << fScaleFactor.x()
337 << ' ' << fScaleFactor.y()
338 << ' ' << fScaleFactor.z();
339
340 oss << "\n/vis/viewer/set/targetPoint "
341 << G4BestUnit(standardTargetPoint+fCurrentTargetPoint,"Length")
342 << "\n# Note that if you have not set a target point, the vis system sets"
343 << "\n# a target point based on the scene - plus any panning and dollying -"
344 << "\n# so don't be alarmed by strange coordinates here.";
345
346 oss << "\n/vis/viewer/dollyTo "
347 << G4BestUnit(fDolly,"Length");
348
349 oss << "\n/vis/viewer/set/lightsMove ";
350 if (fLightsMoveWithCamera) {
351 oss << "camera";
352 } else {
353 oss << "object";
354 }
355
356 oss << "\n/vis/viewer/set/lightsVector "
357 << fRelativeLightpointDirection.x()
358 << ' ' << fRelativeLightpointDirection.y()
359 << ' ' << fRelativeLightpointDirection.z();
360
361 oss << "\n/vis/viewer/set/rotationStyle ";
362 if (fRotationStyle == constrainUpDirection) {
363 oss << "constrainUpDirection";
364 } else {
365 oss << "freeRotation";
366 }
367
368 G4Colour c = fBackgroundColour;
369 oss << "\n/vis/viewer/set/background "
370 << c.GetRed()
371 << ' ' << c.GetGreen()
372 << ' ' << c.GetBlue()
373 << ' ' << c.GetAlpha();
374
375 c = fDefaultVisAttributes.GetColour();
376 oss << "\n/vis/viewer/set/defaultColour "
377 << c.GetRed()
378 << ' ' << c.GetGreen()
379 << ' ' << c.GetBlue()
380 << ' ' << c.GetAlpha();
381
382 c = fDefaultTextVisAttributes.GetColour();
383 oss << "\n/vis/viewer/set/defaultTextColour "
384 << c.GetRed()
385 << ' ' << c.GetGreen()
386 << ' ' << c.GetBlue()
387 << ' ' << c.GetAlpha();
388
389 oss << std::endl;
390
391 return oss.str();
392}
393
395{
396 std::ostringstream oss;
397
398 oss << "#\n# Drawing style commands";
399
400 oss << "\n/vis/viewer/set/style ";
401 switch (fDrawingStyle) {
402 case wireframe:
403 case hlr:
404 oss << "wireframe";
405 break;
406 case hsr:
407 case hlhsr:
408 oss << "surface";
409 break;
410 case cloud:
411 oss << "cloud";
412 break;
413 }
414
415 oss << "\n/vis/viewer/set/hiddenEdge ";
416 if (fDrawingStyle == hlr || fDrawingStyle == hlhsr) {
417 oss << "true";
418 } else {
419 oss << "false";
420 }
421
422 oss << "\n/vis/viewer/set/auxiliaryEdge ";
423 if (fAuxEdgeVisible) {
424 oss << "true";
425 } else {
426 oss << "false";
427 }
428
429 oss << "\n/vis/viewer/set/hiddenMarker ";
430 if (fMarkerNotHidden) {
431 oss << "false";
432 } else {
433 oss << "true";
434 }
435
436 oss << "\n/vis/viewer/set/globalLineWidthScale "
437 << fGlobalLineWidthScale;
438
439 oss << "\n/vis/viewer/set/globalMarkerScale "
440 << fGlobalMarkerScale;
441
442 oss << "\n/vis/viewer/set/numberOfCloudPoints "
443 << fNumberOfCloudPoints;
444
445 oss << "\n/vis/viewer/set/specialMeshRendering ";
446 if (fSpecialMeshRendering) {
447 oss << "true";
448 } else {
449 oss << "false";
450 }
451
452 oss << "\n/vis/viewer/set/specialMeshRenderingOption "
453 << fSpecialMeshRenderingOption;
454
455 oss << "\n/vis/viewer/set/specialMeshVolumes";
456 for (const auto& volume : fSpecialMeshVolumes) {
457 oss << ' ' << volume.GetName() << ' ' << volume.GetCopyNo();
458 }
459
460 oss << "\n/vis/viewer/set/zoomToCursor ";
461 if (fZoomToCursor) {
462 oss << "true";
463 } else {
464 oss << "false";
465 }
466
467 oss << "\n/vis/viewer/set/dotsSmooth ";
468 if (fDotsSmooth) {
469 oss << "true";
470 } else {
471 oss << "false";
472 }
473
474 oss << "\n/vis/viewer/set/dotsSize " << fDotsSize;
475
476 oss << std::endl;
477
478 return oss.str();
479}
480
482{
483 std::ostringstream oss;
484
485 oss << "#\n# Scene-modifying commands";
486
487 oss << "\n/vis/viewer/set/culling global ";
488 if (fCulling) {
489 oss << "true";
490 } else {
491 oss << "false";
492 }
493
494 oss << "\n/vis/viewer/set/culling invisible ";
495 if (fCullInvisible) {
496 oss << "true";
497 } else {
498 oss << "false";
499 }
500
501 oss << "\n/vis/viewer/set/culling density ";
502 if (fDensityCulling) {
503 oss << "true " << fVisibleDensity/(g/cm3) << " g/cm3";
504 } else {
505 oss << "false";
506 }
507
508 oss << "\n/vis/viewer/set/culling coveredDaughters ";
509 if (fCullCovered) {
510 oss << "true";
511 } else {
512 oss << "false";
513 }
514
515 oss << "\n/vis/viewer/colourByDensity "
516 << fCBDAlgorithmNumber << " g/cm3";
517 for (auto p: fCBDParameters) {
518 oss << ' ' << p/(g/cm3);
519 }
520
521 oss << "\n/vis/viewer/set/sectionPlane ";
522 if (fSection) {
523 oss << "on "
524 << G4BestUnit(fSectionPlane.point(),"Length")
525 << fSectionPlane.normal().x()
526 << ' ' << fSectionPlane.normal().y()
527 << ' ' << fSectionPlane.normal().z();
528 } else {
529 oss << "off";
530 }
531
532 oss << "\n/vis/viewer/set/cutawayMode ";
533 if (fCutawayMode == cutawayUnion) {
534 oss << "union";
535 } else {
536 oss << "intersection";
537 }
538
539 oss << "\n/vis/viewer/clearCutawayPlanes";
540 if (fCutawayPlanes.size()) {
541 for (const auto& fCutawayPlane : fCutawayPlanes) {
542 oss << "\n/vis/viewer/addCutawayPlane "
543 << G4BestUnit(fCutawayPlane.point(),"Length")
544 << fCutawayPlane.normal().x()
545 << ' ' << fCutawayPlane.normal().y()
546 << ' ' << fCutawayPlane.normal().z();
547 }
548 } else {
549 oss << "\n# No cutaway planes defined.";
550 }
551
552 oss << "\n/vis/viewer/set/explodeFactor "
553 << fExplodeFactor
554 << ' ' << G4BestUnit(fExplodeCentre,"Length");
555
556 oss << "\n/vis/viewer/set/lineSegmentsPerCircle "
557 << fNoOfSides;
558
559 oss << "\n/vis/viewer/set/transparencyByDepth "
560 << fTransparencyByDepth << ' ' << fTransparencyByDepthOption;
561
562 oss << std::endl;
563
564 return oss.str();
565}
566
568{
569 std::ostringstream oss;
570
571 oss << "#\n# Touchable commands";
572
573 const std::vector<G4ModelingParameters::VisAttributesModifier>& vams =
574 fVisAttributesModifiers;
575
576 if (vams.empty()) {
577 oss
578 << "\n# None"
579 << "\n/vis/viewer/clearVisAttributesModifiers";
580 oss << std::endl;
581 return oss.str();
582 }
583
584 oss
585 << "\n/vis/viewer/clearVisAttributesModifiers";
586
588 std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator
589 iModifier;
590 for (iModifier = vams.begin();
591 iModifier != vams.end();
592 ++iModifier) {
594 iModifier->GetPVNameCopyNoPath();
595 if (vamPath != lastPath) {
596 lastPath = vamPath;
597 oss << "\n/vis/set/touchable";
599 for (iVAM = vamPath.begin();
600 iVAM != vamPath.end();
601 ++iVAM) {
602 oss << ' ' << iVAM->GetName() << ' ' << iVAM->GetCopyNo();
603 }
604 }
605 const G4VisAttributes& vamVisAtts = iModifier->GetVisAttributes();
606 const G4Colour& c = vamVisAtts.GetColour();
607 switch (iModifier->GetVisAttributesSignifier()) {
609 oss << "\n/vis/touchable/set/visibility ";
610 if (vamVisAtts.IsVisible()) {
611 oss << "true";
612 } else {
613 oss << "false";
614 }
615 break;
617 oss << "\n/vis/touchable/set/daughtersInvisible ";
618 if (vamVisAtts.IsDaughtersInvisible()) {
619 oss << "true";
620 } else {
621 oss << "false";
622 }
623 break;
625 oss << "\n/vis/touchable/set/colour "
626 << c.GetRed()
627 << ' ' << c.GetGreen()
628 << ' ' << c.GetBlue()
629 << ' ' << c.GetAlpha();
630 break;
632 oss << "\n/vis/touchable/set/lineStyle ";
633 switch (vamVisAtts.GetLineStyle()) {
635 oss << "unbroken";
636 break;
638 oss << "dashed";
639 break;
641 oss << "dotted";
642 }
643 break;
645 oss << "\n/vis/touchable/set/lineWidth "
646 << vamVisAtts.GetLineWidth();
647 break;
649 if (vamVisAtts.IsForceDrawingStyle()) {
651 oss << "\n/vis/touchable/set/forceWireframe ";
652 if (vamVisAtts.IsForceDrawingStyle()) {
653 oss << "true";
654 } else {
655 oss << "false";
656 }
657 }
658 }
659 break;
661 if (vamVisAtts.IsForceDrawingStyle()) {
662 if (vamVisAtts.GetForcedDrawingStyle() == G4VisAttributes::solid) {
663 oss << "\n/vis/touchable/set/forceSolid ";
664 if (vamVisAtts.IsForceDrawingStyle()) {
665 oss << "true";
666 } else {
667 oss << "false";
668 }
669 }
670 }
671 break;
673 if (vamVisAtts.IsForceDrawingStyle()) {
674 if (vamVisAtts.GetForcedDrawingStyle() == G4VisAttributes::cloud) {
675 oss << "\n/vis/touchable/set/forceCloud ";
676 if (vamVisAtts.IsForceDrawingStyle()) {
677 oss << "true";
678 } else {
679 oss << "false";
680 }
681 }
682 }
683 break;
685 if (vamVisAtts.IsForceAuxEdgeVisible()) {
686 oss << "\n/vis/touchable/set/forceAuxEdgeVisible ";
687 if (vamVisAtts.IsForcedAuxEdgeVisible()) {
688 oss << "true";
689 } else {
690 oss << "false";
691 }
692 }
693 break;
695 oss << "\n/vis/touchable/set/lineSegmentsPerCircle "
696 << vamVisAtts.GetForcedLineSegmentsPerCircle();
697 break;
699 oss << "\n/vis/touchable/set/numberOfCloudPoints "
700 << vamVisAtts.GetForcedNumberOfCloudPoints();
701 break;
702 }
703 }
704
705 oss << std::endl;
706
707 return oss.str();
708}
709
711{
712 std::ostringstream oss;
713
714 oss << "#\n# Time window commands";
715
716 oss
717 << "\n/vis/viewer/set/timeWindow/startTime "
718 << fTimeParameters.fStartTime/ns << " ns ";
719
720 oss
721 << "\n/vis/viewer/set/timeWindow/endTime "
722 << fTimeParameters.fEndTime/ns << " ns ";
723
724 oss << "\n/vis/viewer/set/timeWindow/fadeFactor "
725 << fTimeParameters.fFadeFactor;
726
727 oss
728 << "\n/vis/viewer/set/timeWindow/displayHeadTime ";
729 if (!fTimeParameters.fDisplayHeadTime) {
730 oss << "false";
731 } else {
732 oss
733 << "true"
734 << ' ' << fTimeParameters.fDisplayHeadTimeX
735 << ' ' << fTimeParameters.fDisplayHeadTimeY
736 << ' ' << fTimeParameters.fDisplayHeadTimeSize
737 << ' ' << fTimeParameters.fDisplayHeadTimeRed
738 << ' ' << fTimeParameters.fDisplayHeadTimeGreen
739 << ' ' << fTimeParameters.fDisplayHeadTimeBlue;
740 }
741
742 oss
743 << "\n/vis/viewer/set/timeWindow/displayLightFront ";
744 if (!fTimeParameters.fDisplayLightFront) {
745 oss << "false";
746 } else {
747 oss
748 << "true"
749 << ' ' << fTimeParameters.fDisplayLightFrontX/mm
750 << ' ' << fTimeParameters.fDisplayLightFrontY/mm
751 << ' ' << fTimeParameters.fDisplayLightFrontZ/mm
752 << " mm"
753 << ' ' << fTimeParameters.fDisplayLightFrontT/ns
754 << " ns"
755 << ' ' << fTimeParameters.fDisplayLightFrontRed
756 << ' ' << fTimeParameters.fDisplayLightFrontGreen
757 << ' ' << fTimeParameters.fDisplayLightFrontBlue;
758 }
759
760 oss << std::endl;
761
762 return oss.str();
763}
764
766
767 // Put performance-sensitive parameters first.
768 if (
769 // This first to optimise spin, etc.
770 (fViewpointDirection != v.fViewpointDirection) ||
771
772 // No particular order from here on.
773 (fDrawingStyle != v.fDrawingStyle) ||
774 (fNumberOfCloudPoints != v.fNumberOfCloudPoints) ||
775 (fAuxEdgeVisible != v.fAuxEdgeVisible) ||
776 (fCulling != v.fCulling) ||
777 (fCullInvisible != v.fCullInvisible) ||
778 (fDensityCulling != v.fDensityCulling) ||
779 (fVisibleDensity != v.fVisibleDensity) ||
780 (fCullCovered != v.fCullCovered) ||
781 (fCBDAlgorithmNumber != v.fCBDAlgorithmNumber) ||
782 (fSection != v.fSection) ||
783 (fNoOfSides != v.fNoOfSides) ||
784 (fUpVector != v.fUpVector) ||
785 (fFieldHalfAngle != v.fFieldHalfAngle) ||
786 (fZoomFactor != v.fZoomFactor) ||
787 (fScaleFactor != v.fScaleFactor) ||
788 (fCurrentTargetPoint != v.fCurrentTargetPoint) ||
789 (fDolly != v.fDolly) ||
790 (fRelativeLightpointDirection != v.fRelativeLightpointDirection) ||
791 (fLightsMoveWithCamera != v.fLightsMoveWithCamera) ||
792 (fDefaultVisAttributes != v.fDefaultVisAttributes) ||
793 (fDefaultTextVisAttributes != v.fDefaultTextVisAttributes) ||
794 (fDefaultMarker != v.fDefaultMarker) ||
795 (fGlobalMarkerScale != v.fGlobalMarkerScale) ||
796 (fGlobalLineWidthScale != v.fGlobalLineWidthScale) ||
797 (fMarkerNotHidden != v.fMarkerNotHidden) ||
798 (fWindowSizeHintX != v.fWindowSizeHintX) ||
799 (fWindowSizeHintY != v.fWindowSizeHintY) ||
800 (fXGeometryString != v.fXGeometryString) ||
801 (fGeometryMask != v.fGeometryMask) ||
802 (fAutoRefresh != v.fAutoRefresh) ||
803 (fBackgroundColour != v.fBackgroundColour) ||
804 (fPicking != v.fPicking) ||
805 (fRotationStyle != v.fRotationStyle) ||
806 (fTransparencyByDepth != v.fTransparencyByDepth) ||
807 (fTransparencyByDepthOption != v.fTransparencyByDepthOption) ||
808 (fZoomToCursor != v.fZoomToCursor) ||
809 (fDotsSmooth != v.fDotsSmooth) ||
810 (fDotsSize != v.fDotsSize)
811 )
812 G4cout << "Difference in 1st batch." << G4endl;
813
814 if (fCBDAlgorithmNumber > 0) {
815 if (fCBDParameters.size() != v.fCBDParameters.size()) {
816 G4cout << "Difference in number of colour by density parameters." << G4endl;
817 } else if (fCBDParameters != v.fCBDParameters) {
818 G4cout << "Difference in values of colour by density parameters." << G4endl;
819 }
820 }
821
822 if (fSection) {
823 if (!(fSectionPlane == v.fSectionPlane))
824 G4cout << "Difference in section planes batch." << G4endl;
825 }
826
827 if (IsCutaway()) {
828 if (fCutawayPlanes.size () != v.fCutawayPlanes.size ()) {
829 G4cout << "Difference in no of cutaway planes." << G4endl;
830 }
831 else {
832 for (size_t i = 0; i < fCutawayPlanes.size (); i++) {
833 if (!(fCutawayPlanes[i] == v.fCutawayPlanes[i]))
834 G4cout << "Difference in cutaway plane no. " << i << G4endl;
835 }
836 }
837 }
838
839 if (IsExplode()) {
840 if (fExplodeFactor != v.fExplodeFactor)
841 G4cout << "Difference in explode factor." << G4endl;
842 if (fExplodeCentre != v.fExplodeCentre)
843 G4cout << "Difference in explode centre." << G4endl;
844 }
845
846 if (fVisAttributesModifiers != v.fVisAttributesModifiers) {
847 G4cout << "Difference in vis attributes modifiers." << G4endl;
848 }
849
850 if (fTimeParameters.fStartTime != v.fTimeParameters.fStartTime ||
851 fTimeParameters.fEndTime != v.fTimeParameters.fEndTime) {
852 G4cout << "Difference in time window." << G4endl;
853 }
854
855 if (fTimeParameters.fFadeFactor != v.fTimeParameters.fFadeFactor) {
856 G4cout << "Difference in time window fade factor." << G4endl;
857 }
858
859 if (fTimeParameters.fDisplayHeadTime != v.fTimeParameters.fDisplayHeadTime) {
860 G4cout << "Difference in display head time flag." << G4endl;
861 } else {
862 if (fTimeParameters.fDisplayHeadTimeX != v.fTimeParameters.fDisplayHeadTimeX ||
863 fTimeParameters.fDisplayHeadTimeY != v.fTimeParameters.fDisplayHeadTimeY ||
864 fTimeParameters.fDisplayHeadTimeSize != v.fTimeParameters.fDisplayHeadTimeSize ||
865 fTimeParameters.fDisplayHeadTimeRed != v.fTimeParameters.fDisplayHeadTimeRed ||
866 fTimeParameters.fDisplayHeadTimeGreen != v.fTimeParameters.fDisplayHeadTimeGreen ||
867 fTimeParameters.fDisplayHeadTimeBlue != v.fTimeParameters.fDisplayHeadTimeBlue) {
868 G4cout << "Difference in display head time parameters." << G4endl;
869 }
870 }
871
872 if (fTimeParameters.fDisplayLightFront != v.fTimeParameters.fDisplayLightFront) {
873 G4cout << "Difference in display light front flag." << G4endl;
874 } else {
875 if (fTimeParameters.fDisplayLightFrontX != v.fTimeParameters.fDisplayLightFrontX ||
876 fTimeParameters.fDisplayLightFrontY != v.fTimeParameters.fDisplayLightFrontY ||
877 fTimeParameters.fDisplayLightFrontZ != v.fTimeParameters.fDisplayLightFrontZ ||
878 fTimeParameters.fDisplayLightFrontT != v.fTimeParameters.fDisplayLightFrontT ||
879 fTimeParameters.fDisplayLightFrontRed != v.fTimeParameters.fDisplayLightFrontRed ||
880 fTimeParameters.fDisplayLightFrontGreen != v.fTimeParameters.fDisplayLightFrontGreen ||
881 fTimeParameters.fDisplayLightFrontBlue != v.fTimeParameters.fDisplayLightFrontBlue) {
882 G4cout << "Difference in display light front parameters." << G4endl;
883 }
884 }
885}
886
887std::ostream& operator <<
888 (std::ostream& os, G4ViewParameters::DrawingStyle style)
889{
890 switch (style) {
892 os << "wireframe"; break;
894 os << "hlr - hidden lines removed"; break;
896 os << "hsr - hidden surfaces removed"; break;
898 os << "hlhsr - hidden line, hidden surface removed"; break;
900 os << "cloud - draw volume as a cloud of dots"; break;
901 default: os << "unrecognised"; break;
902 }
903 return os;
904}
905
906std::ostream& operator <<
907(std::ostream& os, G4ViewParameters::SMROption option)
908{
909 switch (option) {
911 os << "default"; break;
913 os << "dots"; break;
915 os << "surfaces"; break;
916 }
917 return os;
918}
919
920std::ostream& operator << (std::ostream& os, const G4ViewParameters& v) {
921 os << "View parameters and options:";
922
923 os << "\n Drawing style: " << v.fDrawingStyle;
924
925 os << "\n Number of cloud points: " << v.fNumberOfCloudPoints;
926
927 os << "\n Auxiliary edges: ";
928 if (!v.fAuxEdgeVisible) os << "in";
929 os << "visible";
930
931 os << "\n Culling: ";
932 if (v.fCulling) os << "on";
933 else os << "off";
934
935 os << "\n Culling invisible objects: ";
936 if (v.fCullInvisible) os << "on";
937 else os << "off";
938
939 os << "\n Density culling: ";
940 if (v.fDensityCulling) {
941 os << "on - invisible if density less than "
942 << v.fVisibleDensity / (1. * g / cm3) << " g cm^-3";
943 }
944 else os << "off";
945
946 os << "\n Culling daughters covered by opaque mothers: ";
947 if (v.fCullCovered) os << "on";
948 else os << "off";
949
950 os << "\n Colour by density: ";
951 if (v.fCBDAlgorithmNumber <= 0) {
952 os << "inactive";
953 } else {
954 os << "Algorithm " << v.fCBDAlgorithmNumber << ", Parameters:";
955 for (auto p: v.fCBDParameters) {
956 os << ' ' << G4BestUnit(p,"Volumic Mass");
957 }
958 }
959
960 os << "\n Section flag: ";
961 if (v.fSection) os << "true, section/cut plane: " << v.fSectionPlane;
962 else os << "false";
963
964 if (v.IsCutaway()) {
965 os << "\n Cutaway planes: ";
966 for (const auto& fCutawayPlane : v.fCutawayPlanes) {
967 os << ' ' << fCutawayPlane;
968 }
969 }
970 else {
971 os << "\n No cutaway planes";
972 }
973
974 os << "\n Explode factor: " << v.fExplodeFactor
975 << " about centre: " << v.fExplodeCentre;
976
977 os << "\n No. of sides used in circle polygon approximation: "
978 << v.fNoOfSides;
979
980 os << "\n Viewpoint direction: " << v.fViewpointDirection;
981
982 os << "\n Up vector: " << v.fUpVector;
983
984 os << "\n Field half angle: " << v.fFieldHalfAngle;
985
986 os << "\n Zoom factor: " << v.fZoomFactor;
987
988 os << "\n Scale factor: " << v.fScaleFactor;
989
990 os << "\n Current target point: " << v.fCurrentTargetPoint;
991
992 os << "\n Dolly distance: " << v.fDolly;
993
994 os << "\n Light ";
995 if (v.fLightsMoveWithCamera) os << "moves";
996 else os << "does not move";
997 os << " with camera";
998
999 os << "\n Relative lightpoint direction: "
1000 << v.fRelativeLightpointDirection;
1001
1002 os << "\n Actual lightpoint direction: "
1003 << v.fActualLightpointDirection;
1004
1005 os << "\n Derived parameters for standard view of object of unit radius:";
1006 G4ViewParameters tempVP = v;
1007 tempVP.fDolly = 0.;
1008 tempVP.fZoomFactor = 1.;
1009 const G4double radius = 1.;
1010 const G4double cameraDistance = tempVP.GetCameraDistance (radius);
1011 const G4double nearDistance =
1012 tempVP.GetNearDistance (cameraDistance, radius);
1013 const G4double farDistance =
1014 tempVP.GetFarDistance (cameraDistance, nearDistance, radius);
1015 const G4double right = tempVP.GetFrontHalfHeight (nearDistance, radius);
1016 os << "\n Camera distance: " << cameraDistance;
1017 os << "\n Near distance: " << nearDistance;
1018 os << "\n Far distance: " << farDistance;
1019 os << "\n Front half height: " << right;
1020
1021 os << "\n Default VisAttributes:\n " << v.fDefaultVisAttributes;
1022
1023 os << "\n Default TextVisAttributes:\n " << v.fDefaultTextVisAttributes;
1024
1025 os << "\n Default marker:\n " << v.fDefaultMarker;
1026
1027 os << "\n Global marker scale: " << v.fGlobalMarkerScale;
1028
1029 os << "\n Global lineWidth scale: " << v.fGlobalLineWidthScale;
1030
1031 os << "\n Marker ";
1032 if (v.fMarkerNotHidden) os << "not ";
1033 os << "hidden by surfaces.";
1034
1035 os << "\n Window size hint: "
1036 << v.fWindowSizeHintX << 'x'<< v.fWindowSizeHintX;
1037
1038 os << "\n X geometry string: " << v.fXGeometryString;
1039 os << "\n X geometry mask: "
1040 << std::showbase << std::hex << v.fGeometryMask
1041 << std::noshowbase << std::dec;
1042
1043 os << "\n Auto refresh: ";
1044 if (v.fAutoRefresh) os << "true";
1045 else os << "false";
1046
1047 os << "\n Background colour: " << v.fBackgroundColour;
1048
1049 os << "\n Picking requested: ";
1050 if (v.fPicking) os << "true";
1051 else os << "false";
1052
1053 os << "\n Rotation style: ";
1054 switch (v.fRotationStyle) {
1056 os << "constrainUpDirection (conventional HEP view)"; break;
1058 os << "freeRotation (Google-like rotation, using mouse-grab)"; break;
1059 default: os << "unrecognised"; break;
1060 }
1061
1062 os << "\nVis attributes modifiers: ";
1063 const std::vector<G4ModelingParameters::VisAttributesModifier>& vams =
1064 v.fVisAttributesModifiers;
1065 if (vams.empty()) {
1066 os << "None";
1067 } else {
1068 os << vams;
1069 }
1070
1071 os << "\nTime window parameters:"
1072 << "\n Start time: " << v.fTimeParameters.fStartTime/ns << " ns"
1073 << "\n End time: " << v.fTimeParameters.fEndTime/ns << " ns"
1074 << "\n Fade factor: " << v.fTimeParameters.fFadeFactor;
1075 if (!v.fTimeParameters.fDisplayHeadTime) {
1076 os << "\n Head time display not requested.";
1077 } else {
1078 os
1079 << "\n Head time position: "
1080 << v.fTimeParameters.fDisplayHeadTimeX << ' ' << v.fTimeParameters.fDisplayHeadTimeY
1081 << "\n Head time size: " << v.fTimeParameters.fDisplayHeadTimeSize
1082 << "\n Head time colour: " << v.fTimeParameters.fDisplayHeadTimeRed
1083 << ' ' << v.fTimeParameters.fDisplayHeadTimeGreen << ' ' << v.fTimeParameters.fDisplayHeadTimeBlue;
1084 }
1085 if (!v.fTimeParameters.fDisplayLightFront) {
1086 os << "\n Light front display not requested.";
1087 } else {
1088 os
1089 << "\n Light front position: "
1090 << v.fTimeParameters.fDisplayLightFrontX/mm << ' ' << v.fTimeParameters.fDisplayLightFrontY/mm
1091 << ' ' << v.fTimeParameters.fDisplayLightFrontZ/mm << " mm"
1092 << "\n Light front time: " << v.fTimeParameters.fDisplayLightFrontT/ns << " ns"
1093 << "\n Light front colour: " << v.fTimeParameters.fDisplayLightFrontRed
1094 << ' ' << v.fTimeParameters.fDisplayLightFrontGreen << ' ' << v.fTimeParameters.fDisplayLightFrontBlue;
1095 }
1096
1097 os << "\nSpecial Mesh Rendering";
1098 if (v.fSpecialMeshRendering) {
1099 os << " requested with option \"" << v.fSpecialMeshRenderingOption;
1100 os << "\" for ";
1101 if (v.fSpecialMeshVolumes.empty()) {
1102 os << "any mesh";
1103 } else {
1104 os << "selected meshes";
1105 for (const auto& vol: v.fSpecialMeshVolumes) {
1106 os << "\n " << vol.GetName() << ':' << vol.GetCopyNo();
1107 }
1108 }
1109 } else os << ": off";
1110
1111 os << "\nTransparency by depth: " << v.fTransparencyByDepth
1112 << ", option: " << v.fTransparencyByDepthOption;
1113
1114 os << "\nZoom to cursor requested: ";
1115 if (v.fZoomToCursor) os << "true";
1116 else os << "false";
1117
1118 os << "\nSmooth dots requested: ";
1119 if (v.fDotsSmooth) os << "true";
1120 else os << "false";
1121
1122 os << "\nDots size: " << v.fDotsSize;
1123
1124 return os;
1125}
1126
1128
1129 // Put performance-sensitive parameters first.
1130 if (
1131 // This first to optimise spin, etc.
1132 (fViewpointDirection != v.fViewpointDirection) ||
1133
1134 // No particular order from here on.
1135 (fDrawingStyle != v.fDrawingStyle) ||
1136 (fNumberOfCloudPoints != v.fNumberOfCloudPoints) ||
1137 (fAuxEdgeVisible != v.fAuxEdgeVisible) ||
1138 (fCulling != v.fCulling) ||
1139 (fCullInvisible != v.fCullInvisible) ||
1140 (fDensityCulling != v.fDensityCulling) ||
1141 (fCullCovered != v.fCullCovered) ||
1142 (fCBDAlgorithmNumber != v.fCBDAlgorithmNumber) ||
1143 (fSection != v.fSection) ||
1144 (IsCutaway() != v.IsCutaway()) ||
1145 (IsExplode() != v.IsExplode()) ||
1146 (fNoOfSides != v.fNoOfSides) ||
1147 (fUpVector != v.fUpVector) ||
1148 (fFieldHalfAngle != v.fFieldHalfAngle) ||
1149 (fZoomFactor != v.fZoomFactor) ||
1150 (fScaleFactor != v.fScaleFactor) ||
1151 (fCurrentTargetPoint != v.fCurrentTargetPoint) ||
1152 (fDolly != v.fDolly) ||
1153 (fRelativeLightpointDirection != v.fRelativeLightpointDirection) ||
1154 (fLightsMoveWithCamera != v.fLightsMoveWithCamera) ||
1155 (fDefaultVisAttributes != v.fDefaultVisAttributes) ||
1156 (fDefaultTextVisAttributes != v.fDefaultTextVisAttributes) ||
1157 (fDefaultMarker != v.fDefaultMarker) ||
1158 (fGlobalMarkerScale != v.fGlobalMarkerScale) ||
1159 (fGlobalLineWidthScale != v.fGlobalLineWidthScale) ||
1160 (fMarkerNotHidden != v.fMarkerNotHidden) ||
1161 (fWindowSizeHintX != v.fWindowSizeHintX) ||
1162 (fWindowSizeHintY != v.fWindowSizeHintY) ||
1163 (fXGeometryString != v.fXGeometryString) ||
1164 (fGeometryMask != v.fGeometryMask) ||
1165 (fAutoRefresh != v.fAutoRefresh) ||
1166 (fBackgroundColour != v.fBackgroundColour) ||
1167 (fPicking != v.fPicking) ||
1168 (fRotationStyle != v.fRotationStyle) ||
1169 (fSpecialMeshRendering != v.fSpecialMeshRendering) ||
1170 (fSpecialMeshRenderingOption != v.fSpecialMeshRenderingOption) ||
1171 (fTransparencyByDepth != v.fTransparencyByDepth) ||
1172 (fTransparencyByDepthOption != v.fTransparencyByDepthOption) ||
1173 (fZoomToCursor != v.fZoomToCursor) ||
1174 (fDotsSmooth != v.fDotsSmooth) ||
1175 (fDotsSize != v.fDotsSize)
1176 )
1177 return true;
1178
1179 if (fDensityCulling &&
1180 (fVisibleDensity != v.fVisibleDensity)) return true;
1181
1182 if (fCBDAlgorithmNumber > 0) {
1183 if (fCBDParameters.size() != v.fCBDParameters.size()) return true;
1184 else if (fCBDParameters != v.fCBDParameters) return true;
1185 }
1186
1187 if (fSection &&
1188 (!(fSectionPlane == v.fSectionPlane))) return true;
1189
1190 if (IsCutaway()) {
1191 if (fCutawayPlanes.size () != v.fCutawayPlanes.size ())
1192 return true;
1193 else {
1194 for (size_t i = 0; i < fCutawayPlanes.size (); i++) {
1195 if (!(fCutawayPlanes[i] == v.fCutawayPlanes[i])) return true;
1196 }
1197 }
1198 }
1199
1200 if (IsExplode() &&
1201 ((fExplodeFactor != v.fExplodeFactor) ||
1202 (fExplodeCentre != v.fExplodeCentre))) return true;
1203
1204 if (fVisAttributesModifiers != v.fVisAttributesModifiers) return true;
1205
1206 if (fTimeParameters.fStartTime != v.fTimeParameters.fStartTime ||
1207 fTimeParameters.fEndTime != v.fTimeParameters.fEndTime ||
1208 fTimeParameters.fFadeFactor != v.fTimeParameters.fFadeFactor) return true;
1209
1210 if (fTimeParameters.fDisplayHeadTime != v.fTimeParameters.fDisplayHeadTime) return true;
1211 if (fTimeParameters.fDisplayHeadTime) {
1212 if (fTimeParameters.fDisplayHeadTimeX != v.fTimeParameters.fDisplayHeadTimeX ||
1213 fTimeParameters.fDisplayHeadTimeY != v.fTimeParameters.fDisplayHeadTimeY ||
1214 fTimeParameters.fDisplayHeadTimeSize != v.fTimeParameters.fDisplayHeadTimeSize ||
1215 fTimeParameters.fDisplayHeadTimeRed != v.fTimeParameters.fDisplayHeadTimeRed ||
1216 fTimeParameters.fDisplayHeadTimeGreen != v.fTimeParameters.fDisplayHeadTimeGreen ||
1217 fTimeParameters.fDisplayHeadTimeBlue != v.fTimeParameters.fDisplayHeadTimeBlue) {
1218 return true;
1219 }
1220 }
1221
1222 if (fTimeParameters.fDisplayLightFront != v.fTimeParameters.fDisplayLightFront) return true;
1223 if (fTimeParameters.fDisplayLightFront) {
1224 if (fTimeParameters.fDisplayLightFrontX != v.fTimeParameters.fDisplayLightFrontX ||
1225 fTimeParameters.fDisplayLightFrontY != v.fTimeParameters.fDisplayLightFrontY ||
1226 fTimeParameters.fDisplayLightFrontZ != v.fTimeParameters.fDisplayLightFrontZ ||
1227 fTimeParameters.fDisplayLightFrontT != v.fTimeParameters.fDisplayLightFrontT ||
1228 fTimeParameters.fDisplayLightFrontRed != v.fTimeParameters.fDisplayLightFrontRed ||
1229 fTimeParameters.fDisplayLightFrontGreen != v.fTimeParameters.fDisplayLightFrontGreen ||
1230 fTimeParameters.fDisplayLightFrontBlue != v.fTimeParameters.fDisplayLightFrontBlue) {
1231 return true;
1232 }
1233 }
1234
1235 if (fSpecialMeshRendering) {
1236 if (fSpecialMeshVolumes != v.fSpecialMeshVolumes)
1237 return true;;
1238 }
1239
1240 return false;
1241}
1242
1244{
1245 const G4String delimiters("xX+-");
1246 G4String::size_type i = geomString.find_first_of(delimiters);
1247 if (i == G4String::npos) {
1248 // Does not contain "xX+-".
1249 // Is it a single number?
1250 std::istringstream iss(geomString);
1251 G4int size;
1252 iss >> size;
1253 if (iss) {
1254 // It is a number
1255 fWindowSizeHintX = size;
1256 fWindowSizeHintY = size;
1257 }
1258 // Accept other or all defaults (in G4ViewParameters constructor)
1259 // Reconstruct a geometry string coherent with the above
1260 char signX, signY;
1261 if (fWindowLocationHintXNegative) signX = '-'; else signX ='+';
1262 if (fWindowLocationHintYNegative) signY = '-'; else signY ='+';
1263 std::ostringstream oss;
1264 oss << fWindowSizeHintX << 'x' << fWindowSizeHintY
1265 << signX << fWindowLocationHintX << signY << fWindowLocationHintY;
1266 fXGeometryString = oss.str();
1267 return;
1268 }
1269
1270 // Assume it's a parseable X geometry string
1271 G4int x = 0, y = 0;
1272 unsigned int w = 0, h = 0;
1273 fGeometryMask = ParseGeometry( geomString, &x, &y, &w, &h );
1274
1275 // Handle special case :
1276 if ((fGeometryMask & fYValue) == 0)
1277 { // Using default
1278 y = fWindowLocationHintY;
1279 }
1280 if ((fGeometryMask & fXValue) == 0)
1281 { // Using default
1282 x = fWindowLocationHintX;
1283 }
1284
1285 // Check errors
1286 // if there is no Width and Height
1287 if ( ((fGeometryMask & fHeightValue) == 0 ) &&
1288 ((fGeometryMask & fWidthValue) == 0 )) {
1289 h = fWindowSizeHintY;
1290 w = fWindowSizeHintX;
1291 } else if ((fGeometryMask & fHeightValue) == 0 ) {
1292
1293 // if there is only Width. Special case to be backward compatible
1294 // We set Width and Height the same to obtain a square windows.
1295
1296 G4warn << "Unrecognised geometry string \""
1297 << geomString
1298 << "\". No Height found. Using Width value instead"
1299 << G4endl;
1300 h = w;
1301 }
1302 if ( ((fGeometryMask & fXValue) == 0 ) ||
1303 ((fGeometryMask & fYValue) == 0 )) {
1304 //Using defaults
1305 x = fWindowLocationHintX;
1306 y = fWindowLocationHintY;
1307 }
1308 // Set the string
1309 fXGeometryString = geomString;
1310
1311 // Set values
1312 fWindowSizeHintX = w;
1313 fWindowSizeHintY = h;
1314 fWindowLocationHintX = x;
1315 fWindowLocationHintY = y;
1316
1317 if ( ((fGeometryMask & fXValue)) &&
1318 ((fGeometryMask & fYValue))) {
1319
1320 if ( (fGeometryMask & fXNegative) ) {
1321 fWindowLocationHintXNegative = true;
1322 } else {
1323 fWindowLocationHintXNegative = false;
1324 }
1325 if ( (fGeometryMask & fYNegative) ) {
1326 fWindowLocationHintYNegative = true;
1327 } else {
1328 fWindowLocationHintYNegative = false;
1329 }
1330 }
1331}
1332
1334 if ( fWindowLocationHintXNegative ) {
1335 return sizeX + fWindowLocationHintX - fWindowSizeHintX;
1336 }
1337 return fWindowLocationHintX;
1338}
1339
1341 if ( fWindowLocationHintYNegative ) {
1342 return sizeY + fWindowLocationHintY - fWindowSizeHintY;
1343 }
1344 return fWindowLocationHintY;
1345}
1346
1347/* Keep from :
1348 * ftp://ftp.trolltech.com/qt/source/qt-embedded-free-3.0.6.tar.gz/qt-embedded-free-3.0.6/src/kernel/qapplication_qws.cpp
1349 *
1350 * ParseGeometry parses strings of the form
1351 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
1352 * width, height, xoffset, and yoffset are unsigned integers.
1353 * Example: "=80x24+300-49"
1354 * The equal sign is optional.
1355 * It returns a bitmask that indicates which of the four values
1356 * were actually found in the string. For each value found,
1357 * the corresponding argument is updated; for each value
1358 * not found, the corresponding argument is left unchanged.
1359 */
1360
1361int G4ViewParameters::ParseGeometry (
1362 const char *string,
1363 G4int *x,
1364 G4int *y,
1365 unsigned int *width,
1366 unsigned int *height)
1367{
1368
1369 G4int mask = fNoValue;
1370 char *strind;
1371 unsigned int tempWidth = 0;
1372 unsigned int tempHeight = 0;
1373 G4int tempX = 0;
1374 G4int tempY = 0;
1375 char *nextCharacter;
1376 if ( (string == NULL) || (*string == '\0')) {
1377 return(mask);
1378 }
1379 if (*string == '=')
1380 string++; /* ignore possible '=' at beg of geometry spec */
1381 strind = (char *)string;
1382 if (*strind != '+' && *strind != '-' && *strind != 'x') {
1383 tempWidth = ReadInteger(strind, &nextCharacter);
1384 if (strind == nextCharacter)
1385 return (0);
1386 strind = nextCharacter;
1387 mask |= fWidthValue;
1388 }
1389 if (*strind == 'x' || *strind == 'X') {
1390 strind++;
1391 tempHeight = ReadInteger(strind, &nextCharacter);
1392 if (strind == nextCharacter)
1393 return (0);
1394 strind = nextCharacter;
1395 mask |= fHeightValue;
1396 }
1397
1398 if ((*strind == '+') || (*strind == '-')) {
1399 if (*strind == '-') {
1400 strind++;
1401 tempX = -ReadInteger(strind, &nextCharacter);
1402 if (strind == nextCharacter)
1403 return (0);
1404 strind = nextCharacter;
1405 mask |= fXNegative;
1406
1407 }
1408 else
1409 { strind++;
1410 tempX = ReadInteger(strind, &nextCharacter);
1411 if (strind == nextCharacter)
1412 return(0);
1413 strind = nextCharacter;
1414 }
1415 mask |= fXValue;
1416 if ((*strind == '+') || (*strind == '-')) {
1417 if (*strind == '-') {
1418 strind++;
1419 tempY = -ReadInteger(strind, &nextCharacter);
1420 if (strind == nextCharacter)
1421 return(0);
1422 strind = nextCharacter;
1423 mask |= fYNegative;
1424 }
1425 else
1426 {
1427 strind++;
1428 tempY = ReadInteger(strind, &nextCharacter);
1429 if (strind == nextCharacter)
1430 return(0);
1431 strind = nextCharacter;
1432 }
1433 mask |= fYValue;
1434 }
1435 }
1436 /* If strind isn't at the end of the string the it's an invalid
1437 geometry specification. */
1438 if (*strind != '\0') return (0);
1439 if (mask & fXValue)
1440 *x = tempX;
1441 if (mask & fYValue)
1442 *y = tempY;
1443 if (mask & fWidthValue)
1444 *width = tempWidth;
1445 if (mask & fHeightValue)
1446 *height = tempHeight;
1447 return (mask);
1448}
1449
1450/* Keep from :
1451 * ftp://ftp.trolltech.com/qt/source/qt-embedded-free-3.0.6.tar.gz/qt-embedded-free-3.0.6/src/kernel/qapplication_qws.cpp
1452 *
1453 */
1454G4int G4ViewParameters::ReadInteger(char *string, char **NextString)
1455{
1456 G4int Result = 0;
1457 G4int Sign = 1;
1458
1459 if (*string == '+')
1460 string++;
1461 else if (*string == '-')
1462 {
1463 string++;
1464 Sign = -1;
1465 }
1466 for (; (*string >= '0') && (*string <= '9'); string++)
1467 {
1468 Result = (Result * 10) + (*string - '0');
1469 }
1470 *NextString = string;
1471 if (Sign >= 0)
1472 return (Result);
1473 else
1474 return (-Result);
1475}
1476
1478(const std::vector<G4ViewParameters>& views,
1479 G4int nInterpolationPoints) // No of interpolations points per interval
1480{
1481 // Returns a null pointer when no more to be done. For example:
1482 // do {
1483 // G4ViewParameters* vp =
1484 // G4ViewParameters::CatmullRomCubicSplineInterpolation(viewVector,nInterpolationPoints);
1485 // if (!vp) break;
1486 // ...
1487 // } while (true);
1488
1489 // See https://en.wikipedia.org/wiki/Cubic_Hermite_spline
1490
1491 // Assumes equal intervals
1492
1493 if (views.size() < 2) {
1495 ("G4ViewParameters::CatmullRomCubicSplineInterpolation",
1496 "visman0301", JustWarning,
1497 "There must be at least two views.");
1498 return 0;
1499 }
1500
1501 if (nInterpolationPoints < 1) {
1503 ("G4ViewParameters::CatmullRomCubicSplineInterpolation",
1504 "visman0302", JustWarning,
1505 "Number of interpolation points cannot be zero or negative.");
1506 return 0;
1507 }
1508
1509 const size_t nIntervals = views.size() - 1;
1510 const G4double dt = 1./nInterpolationPoints;
1511
1512 static G4ViewParameters holdingValues;
1513 static G4double t = 0.; // 0. <= t <= 1.
1514 static G4int iInterpolationPoint = 0;
1515 static size_t iInterval = 0;
1516
1517// G4cout << "Interval " << iInterval << ", t = " << t << G4endl;
1518
1519 // Hermite polynomials.
1520 const G4double h00 = 2.*t*t*t - 3.*t*t +1;
1521 const G4double h10 = t*t*t -2.*t*t + t;
1522 const G4double h01 = -2.*t*t*t + 3.*t*t;
1523 const G4double h11 = t*t*t - t*t;
1524
1525 // Aliases (to simplify code)
1526 const size_t& n = nIntervals;
1527 size_t& i = iInterval;
1528 const std::vector<G4ViewParameters>& v = views;
1529
1530 // The Catmull-Rom cubic spline prescription is as follows:
1531 // Slope at first way point is v[1] - v[0].
1532 // Slope at last way point is v[n] - v[n-1].
1533 // Otherwise slope at way point i is 0.5*(v[i+1] - v[i-1]).
1534 // Result = h00*v[i] + h10*m[i] + h01*v[i+1] + h11*m[i+1],
1535 // where m[i] amd m[i+1] are the slopes at the start and end
1536 // of the interval for the particular value.
1537 // If (n == 1), linear interpolation results.
1538 // If (n == 2), quadratic interpolation results.
1539
1540 // Working variables
1541 G4double mi, mi1, real, x, y, z;
1542
1543 // First, a crude interpolation of all parameters. Then, below, a
1544 // smooth interpolation of those for which it makes sense.
1545 holdingValues = t < 0.5? v[i]: v[i+1];
1546
1547 // Catmull-Rom cubic spline interpolation
1548#define INTERPOLATE(param) \
1549/* This works out the interpolated param in i'th interval */ \
1550/* Assumes n >= 1 */ \
1551if (i == 0) { \
1552/* First interval */ \
1553mi = v[1].param - v[0].param; \
1554/* If there is only one interval, make start and end slopes equal */ \
1555/* (This results in a linear interpolation) */ \
1556if (n == 1) mi1 = mi; \
1557/* else the end slope of the interval takes account of the next waypoint along */ \
1558else mi1 = 0.5 * (v[2].param - v[0].param); \
1559} else if (i >= n - 1) { \
1560/* Similarly for last interval */ \
1561mi1 = v[i+1].param - v[i].param; \
1562/* If there is only one interval, make start and end slopes equal */ \
1563if (n == 1) mi = mi1; \
1564/* else the start slope of the interval takes account of the previous waypoint */ \
1565else mi = 0.5 * (v[i+1].param - v[i-1].param); \
1566} else { \
1567/* Full Catmull-Rom slopes use previous AND next waypoints */ \
1568mi = 0.5 * (v[i+1].param - v[i-1].param); \
1569mi1 = 0.5 * (v[i+2].param - v[i ].param); \
1570} \
1571real = h00 * v[i].param + h10 * mi + h01 * v[i+1].param + h11 * mi1;
1572
1573#define INTERPOLATELOG(param) \
1574if (i == 0) { \
1575mi = std::log(v[1].param) - std::log(v[0].param); \
1576if (n == 1) mi1 = mi; \
1577else mi1 = 0.5 * (std::log(v[2].param) - std::log(v[0].param)); \
1578} else if (i >= n - 1) { \
1579mi1 = std::log(v[i+1].param) - std::log(v[i].param); \
1580if (n == 1) mi = mi1; \
1581else mi = 0.5 * (std::log(v[i+1].param) - std::log(v[i-1].param)); \
1582} else { \
1583mi = 0.5 * (std::log(v[i+1].param) - std::log(v[i-1].param)); \
1584mi1 = 0.5 * (std::log(v[i+2].param) - std::log(v[i ].param)); \
1585} \
1586real = std::exp(h00 * std::log(v[i].param) + h10 * mi + h01 * std::log(v[i+1].param) + h11 * mi1);
1587
1588 // Real parameters
1589 INTERPOLATE(fVisibleDensity);
1590 if (real < 0.) real = 0.;
1591 holdingValues.fVisibleDensity = real;
1592 INTERPOLATELOG(fExplodeFactor);
1593 holdingValues.fExplodeFactor = real;
1594 INTERPOLATE(fFieldHalfAngle);
1595 if (real < 0.) real = 0.;
1596 holdingValues.fFieldHalfAngle = real;
1597 INTERPOLATELOG(fZoomFactor);
1598 holdingValues.fZoomFactor = real;
1599 INTERPOLATE(fDolly);
1600 holdingValues.fDolly = real;
1601 INTERPOLATE(fGlobalMarkerScale);
1602 if (real < 0.) real = 0.;
1603 holdingValues.fGlobalMarkerScale = real;
1604 INTERPOLATE(fGlobalLineWidthScale);
1605 if (real < 0.) real = 0.;
1606 holdingValues.fGlobalLineWidthScale = real;
1607
1608 // Unit vectors
1609#define INTERPOLATEUNITVECTOR(vector) \
1610INTERPOLATE(vector.x()); x = real; \
1611INTERPOLATE(vector.y()); y = real; \
1612INTERPOLATE(vector.z()); z = real;
1613 INTERPOLATEUNITVECTOR(fViewpointDirection);
1614 holdingValues.fViewpointDirection = G4Vector3D(x,y,z).unit();
1615 INTERPOLATEUNITVECTOR(fUpVector);
1616 holdingValues.fUpVector = G4Vector3D(x,y,z).unit();
1617 INTERPOLATEUNITVECTOR(fRelativeLightpointDirection);
1618 holdingValues.fRelativeLightpointDirection = G4Vector3D(x,y,z).unit();
1619 INTERPOLATEUNITVECTOR(fActualLightpointDirection);
1620 holdingValues.fActualLightpointDirection = G4Vector3D(x,y,z).unit();
1621
1622 // Un-normalised vectors
1623#define INTERPOLATEVECTOR(vector) \
1624INTERPOLATE(vector.x()); x = real; \
1625INTERPOLATE(vector.y()); y = real; \
1626INTERPOLATE(vector.z()); z = real;
1627 INTERPOLATEVECTOR(fScaleFactor);
1628 holdingValues.fScaleFactor = G4Vector3D(x,y,z);
1629
1630 // Points
1631#define INTERPOLATEPOINT(point) \
1632INTERPOLATE(point.x()); x = real; \
1633INTERPOLATE(point.y()); y = real; \
1634INTERPOLATE(point.z()); z = real;
1635 INTERPOLATEPOINT(fExplodeCentre);
1636 holdingValues.fExplodeCentre = G4Point3D(x,y,z);
1637 INTERPOLATEPOINT(fCurrentTargetPoint);
1638 holdingValues.fCurrentTargetPoint = G4Point3D(x,y,z);
1639
1640 // Colour
1641 G4double red, green, blue, alpha;
1642#define INTERPOLATECOLOUR(colour) \
1643INTERPOLATE(colour.GetRed()); red = real; \
1644INTERPOLATE(colour.GetGreen()); green = real; \
1645INTERPOLATE(colour.GetBlue()); blue = real; \
1646INTERPOLATE(colour.GetAlpha()); alpha = real;
1647 INTERPOLATECOLOUR(fBackgroundColour);
1648 // Components are clamped to 0. <= component <= 1.
1649 holdingValues.fBackgroundColour = G4Colour(red,green,blue,alpha);
1650
1651 // For some parameters we need to check some continuity
1652 G4bool continuous;
1653#define CONTINUITY(quantity) \
1654 continuous = false; \
1655 /* This follows the logic of the INTERPOLATE macro above; see comments therein */ \
1656 if (i == 0) { \
1657 if (v[1].quantity == v[0].quantity) { \
1658 if (n == 1) continuous = true; \
1659 else if (v[2].quantity == v[0].quantity) \
1660 continuous = true; \
1661 } \
1662 } else if (i >= n - 1) { \
1663 if (v[i+1].quantity == v[i].quantity) { \
1664 if (n == 1) continuous = true; \
1665 else if (v[i+1].quantity == v[i-1].quantity) \
1666 continuous = true; \
1667 } \
1668 } else { \
1669 if (v[i-1].quantity == v[i].quantity && \
1670 v[i+1].quantity == v[i].quantity && \
1671 v[i+2].quantity == v[i].quantity) \
1672 continuous = true; \
1673 }
1674
1675 G4double a, b, c, d;
1676#define INTERPOLATEPLANE(plane) \
1677INTERPOLATE(plane.a()); a = real; \
1678INTERPOLATE(plane.b()); b = real; \
1679INTERPOLATE(plane.c()); c = real; \
1680INTERPOLATE(plane.d()); d = real;
1681
1682 // Section plane
1683 CONTINUITY(fSection);
1684 if (continuous) {
1685 INTERPOLATEPLANE(fSectionPlane);
1686 holdingValues.fSectionPlane = G4Plane3D(a,b,c,d);
1687 }
1688
1689 // Cutaway planes
1690 if (v[i].fCutawayPlanes.size()) {
1691 CONTINUITY(fCutawayPlanes.size());
1692 if (continuous) {
1693 for (size_t j = 0; j < v[i].fCutawayPlanes.size(); ++j) {
1694 INTERPOLATEPLANE(fCutawayPlanes[j]);
1695 holdingValues.fCutawayPlanes[j] = G4Plane3D(a,b,c,d);
1696 }
1697 }
1698 }
1699
1700 // Vis attributes modifiers
1701 // Really, we are only interested in colour - other attributes can follow
1702 // the "crude" interpolation that is guaranteed above.
1703 static G4VisAttributes workingVA;
1704 if (v[i].fVisAttributesModifiers.size()) {
1705 CONTINUITY(fVisAttributesModifiers.size());
1706 if (continuous) {
1707 for (size_t j = 0; j < v[i].fVisAttributesModifiers.size(); ++j) {
1708 CONTINUITY(fVisAttributesModifiers[j].GetPVNameCopyNoPath());
1709 if (continuous) {
1710 CONTINUITY(fVisAttributesModifiers[j].GetVisAttributesSignifier());
1711 if (continuous) {
1712 if (v[i].fVisAttributesModifiers[j].GetVisAttributesSignifier() ==
1714 INTERPOLATECOLOUR(fVisAttributesModifiers[j].GetVisAttributes().GetColour());
1715 workingVA = v[i].fVisAttributesModifiers[j].GetVisAttributes();
1716 workingVA.SetColour(G4Colour(red,green,blue,alpha));
1717 holdingValues.fVisAttributesModifiers[j].SetVisAttributes(workingVA);
1718 }
1719 }
1720 }
1721 }
1722 }
1723 }
1724
1725 // Time window parameters (for showing particles in flight)
1726 // Only two parameters are interpolated. The others are usually chosen
1727 // once and for all by the user for a given series of views - or at least,
1728 // if not, they will be interpolated by the default "crude" method above.
1729 INTERPOLATE(fTimeParameters.fStartTime)
1730 holdingValues.fTimeParameters.fStartTime = real;
1731 INTERPOLATE(fTimeParameters.fEndTime)
1732 holdingValues.fTimeParameters.fEndTime = real;
1733
1734 // Increment counters
1735 iInterpolationPoint++;
1736 t += dt;
1737 if (iInterpolationPoint > nInterpolationPoints) {
1738 iInterpolationPoint = 1; // Ready for next interval.
1739 t = dt;
1740 iInterval++;
1741 }
1742 if (iInterval >= nIntervals) {
1743 iInterpolationPoint = 0; // Ready for a complete restart.
1744 t = 0.;
1745 iInterval = 0;
1746 return 0;
1747 }
1748
1749 return &holdingValues;
1750}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
HepGeom::Plane3D< G4double > G4Plane3D
Definition G4Plane3D.hh:34
HepGeom::Point3D< G4double > G4Point3D
Definition G4Point3D.hh:34
#define G4warn
Definition G4Scene.cc:41
#define G4BestUnit(a, b)
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
HepGeom::Vector3D< G4double > G4Vector3D
Definition G4Vector3D.hh:34
#define INTERPOLATECOLOUR(colour)
std::ostream & operator<<(std::ostream &os, G4ViewParameters::DrawingStyle style)
#define INTERPOLATEVECTOR(vector)
#define INTERPOLATE(param)
#define INTERPOLATEPLANE(plane)
#define CONTINUITY(quantity)
#define INTERPOLATEPOINT(point)
#define INTERPOLATEUNITVECTOR(vector)
#define INTERPOLATELOG(param)
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition G4Colour.cc:140
G4double GetBlue() const
Definition G4Colour.hh:172
G4double GetAlpha() const
Definition G4Colour.hh:173
G4double GetRed() const
Definition G4Colour.hh:170
G4double GetGreen() const
Definition G4Colour.hh:171
const PVNameCopyNoPath & GetPVNameCopyNoPath() const
VisAttributesSignifier GetVisAttributesSignifier() const
const G4VisAttributes & GetVisAttributes() const
PVNameCopyNoPath::const_iterator PVNameCopyNoPathConstIterator
std::vector< PVNameCopyNo > PVNameCopyNoPath
G4int SetNumberOfCloudPoints(G4int)
static G4ViewParameters * CatmullRomCubicSplineInterpolation(const std::vector< G4ViewParameters > &views, G4int nInterpolationPoints=50)
G4int SetNoOfSides(G4int nSides)
void SetViewAndLights(const G4Vector3D &viewpointDirection)
G4int GetWindowAbsoluteLocationHintY(G4int) const
G4String CameraAndLightingCommands(const G4Point3D standardTargetPoint) const
G4double GetCameraDistance(G4double radius) const
void PrintDifferences(const G4ViewParameters &v) const
void SetVisibleDensity(G4double visibleDensity)
G4bool IsCutaway() const
void AddVisAttributesModifier(const G4ModelingParameters::VisAttributesModifier &)
G4Vector3D & GetActualLightpointDirection()
void SetXGeometryString(const G4String &)
G4double GetFarDistance(G4double cameraDistance, G4double nearDistance, G4double radius) const
void MultiplyScaleFactor(const G4Vector3D &scaleFactorMultiplier)
G4double GetFrontHalfHeight(G4double nearDistance, G4double radius) const
G4int GetWindowAbsoluteLocationHintX(G4int) const
G4bool IsExplode() const
G4String SceneModifyingCommands() const
void IncrementPan(G4double right, G4double up)
G4String TimeWindowCommands() const
G4String TouchableCommands() const
void ChangeCutawayPlane(size_t index, const G4Plane3D &cutawayPlane)
void SetPan(G4double right, G4double up)
void SetLightpointDirection(const G4Vector3D &lightpointDirection)
G4String DrawingStyleCommands() const
G4bool operator!=(const G4ViewParameters &) const
G4double GetNearDistance(G4double cameraDistance, G4double radius) const
void AddCutawayPlane(const G4Plane3D &cutawayPlane)
G4int GetForcedNumberOfCloudPoints() const
G4double GetLineWidth() const
G4bool IsDaughtersInvisible() const
void SetColour(const G4Colour &)
G4int GetForcedLineSegmentsPerCircle() const
LineStyle GetLineStyle() const
const G4Colour & GetColour() const
G4bool IsVisible() const
G4bool IsForceAuxEdgeVisible() const
G4bool IsForcedAuxEdgeVisible() const
ForcedDrawingStyle GetForcedDrawingStyle() const
G4bool IsForceDrawingStyle() const
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
BasicVector3D< T > unit() const
static G4int GetNumberOfRotationSteps()
#define ns(x)
Definition xmltok.c:1649