Geant4_10
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 // $Id: G4ViewParameters.cc 71534 2013-06-17 16:07:53Z gcosmo $
28 //
29 //
30 // John Allison 19th July 1996
31 // View parameters and options.
32 
33 #include <sstream>
34 
35 #include "G4ViewParameters.hh"
36 
37 #include "G4VisManager.hh"
38 #include "G4UnitsTable.hh"
39 #include "G4SystemOfUnits.hh"
40 #include "G4ios.hh"
41 
43  fDrawingStyle (wireframe),
44  fAuxEdgeVisible (false),
45  fCulling (true),
46  fCullInvisible (true),
47  fDensityCulling (false),
48  fVisibleDensity (0.01 * g / cm3),
49  fCullCovered (false),
50  fSection (false),
51  fSectionPlane (),
52  fCutawayMode (cutawayUnion),
53  fCutawayPlanes (),
54  fExplodeFactor (1.),
55  fNoOfSides (24),
56  fViewpointDirection (G4Vector3D (0., 0., 1.)), // On z-axis.
57  fUpVector (G4Vector3D (0., 1., 0.)), // y-axis up.
58  fFieldHalfAngle (0.), // Orthogonal projection.
59  fZoomFactor (1.),
60  fScaleFactor (G4Vector3D (1., 1., 1.)),
61  fCurrentTargetPoint (),
62  fDolly (0.),
63  fLightsMoveWithCamera (false),
64  fRelativeLightpointDirection (G4Vector3D (1., 1., 1.)),
65  fActualLightpointDirection (G4Vector3D (1., 1., 1.)),
66  fDefaultVisAttributes (),
67  fDefaultTextVisAttributes (G4Colour (0., 0., 1.)),
68  fDefaultMarker (),
69  fGlobalMarkerScale (1.),
70  fGlobalLineWidthScale (1.),
71  fMarkerNotHidden (true),
72  fWindowSizeHintX (600),
73  fWindowSizeHintY (600),
74  fWindowLocationHintX(0),
75  fWindowLocationHintY(0),
76  fWindowLocationHintXNegative(true),
77  fWindowLocationHintYNegative(false),
78  fGeometryMask(0),
79  fAutoRefresh (false),
80  fBackgroundColour (G4Colour(0.,0.,0.)), // Black
81  fPicking (false),
82  fRotationStyle (constrainUpDirection)
83 {
84  fDefaultMarker.SetScreenSize (5.);
85  // Markers are 5 pixels "overall" size, i.e., diameter.
86 }
87 
89 
91 (const G4Vector3D& scaleFactorMultiplier) {
92  fScaleFactor.setX(fScaleFactor.x() * scaleFactorMultiplier.x());
93  fScaleFactor.setY(fScaleFactor.y() * scaleFactorMultiplier.y());
94  fScaleFactor.setZ(fScaleFactor.z() * scaleFactorMultiplier.z());
95 }
96 
98  SetViewAndLights (fViewpointDirection);
99  return fActualLightpointDirection;
100 }
101 
102 // Useful quantities - begin snippet.
103 // Here Follow functions to evaluate the above algorithms as a
104 // function of the radius of the Bounding Sphere of the object being
105 // viewed. Call them in the order given - for efficiency, later
106 // functions depend on the results of earlier ones (Store the
107 // results of earlier functions in your own temporary variables -
108 // see, for example, G4OpenGLView::SetView ().)
109 
111  G4double cameraDistance;
112  if (fFieldHalfAngle == 0.) {
113  cameraDistance = radius;
114  }
115  else {
116  cameraDistance = radius / std::sin (fFieldHalfAngle) - fDolly;
117  }
118  return cameraDistance;
119 }
120 
122  G4double radius) const {
123  const G4double small = 1.e-6 * radius;
124  G4double nearDistance = cameraDistance - radius;
125  if (nearDistance < small) nearDistance = small;
126  return nearDistance;
127 }
128 
130  G4double nearDistance,
131  G4double radius) const {
132  G4double farDistance = cameraDistance + radius;
133  if (farDistance < nearDistance) farDistance = nearDistance;
134  return farDistance;
135 }
136 
138  G4double radius) const {
139  G4double frontHalfHeight;
140  if (fFieldHalfAngle == 0.) {
141  frontHalfHeight = radius / fZoomFactor;
142  }
143  else {
144  frontHalfHeight = nearDistance * std::tan (fFieldHalfAngle) / fZoomFactor;
145  }
146  return frontHalfHeight;
147 }
148 // Useful quantities - end snippet.
149 
150 void G4ViewParameters::AddCutawayPlane (const G4Plane3D& cutawayPlane) {
151  if (fCutawayPlanes.size () < 3 ) {
152  fCutawayPlanes.push_back (cutawayPlane);
153  }
154  else {
155  G4cout <<
156  "ERROR: G4ViewParameters::AddCutawayPlane:"
157  "\n A maximum of 3 cutaway planes supported." << G4endl;
158  }
159 }
160 
162 (size_t index, const G4Plane3D& cutawayPlane) {
163  if (index >= fCutawayPlanes.size()) {
164  G4cout <<
165  "ERROR: G4ViewParameters::ChangeCutawayPlane:"
166  "\n Plane " << index << " does not exist." << G4endl;
167  } else {
168  fCutawayPlanes[index] = cutawayPlane;
169  }
170 }
171 
173  const G4double reasonableMaximum = 10.0 * g / cm3;
174  if (visibleDensity < 0) {
175  G4cout << "G4ViewParameters::SetVisibleDensity: attempt to set negative "
176  "density - ignored." << G4endl;
177  }
178  else {
179  if (visibleDensity > reasonableMaximum) {
180  G4cout << "G4ViewParameters::SetVisibleDensity: density > "
181  << G4BestUnit (reasonableMaximum, "Volumic Mass")
182  << " - did you mean this?"
183  << G4endl;
184  }
185  fVisibleDensity = visibleDensity;
186  }
187 }
188 
190  const G4int nSidesMin = 12;
191  if (nSides < nSidesMin) {
192  nSides = nSidesMin;
193  G4cout << "G4ViewParameters::SetNoOfSides: attempt to set the"
194  "\nnumber of sides per circle < " << nSidesMin
195  << "; forced to " << nSides << G4endl;
196  }
197  fNoOfSides = nSides;
198  return fNoOfSides;
199 }
200 
202 (const G4Vector3D& viewpointDirection) {
203 
204  fViewpointDirection = viewpointDirection;
205 
206  // If the requested viewpoint direction is parallel to the up
207  // vector, the orientation of the view is undefined...
208  if (fViewpointDirection.unit() * fUpVector.unit() > .9999) {
209  G4cout <<
210  "WARNING: Viewpoint direction is very close to the up vector direction."
211  "\n Consider setting the up vector to obtain definable behaviour."
212  << G4endl;
213  }
214 
215  // Move the lights too if requested...
216  if (fLightsMoveWithCamera) {
217  G4Vector3D zprime = fViewpointDirection.unit ();
218  G4Vector3D xprime = (fUpVector.cross (zprime)).unit ();
219  G4Vector3D yprime = zprime.cross (xprime);
220  fActualLightpointDirection =
221  fRelativeLightpointDirection.x () * xprime +
222  fRelativeLightpointDirection.y () * yprime +
223  fRelativeLightpointDirection.x () * zprime;
224  } else {
225  fActualLightpointDirection = fRelativeLightpointDirection;
226  }
227 }
228 
230 (const G4Vector3D& lightpointDirection) {
231  fRelativeLightpointDirection = lightpointDirection;
232  SetViewAndLights (fViewpointDirection);
233 }
234 
236  G4Vector3D unitRight = (fUpVector.cross (fViewpointDirection)).unit();
237  G4Vector3D unitUp = (fViewpointDirection.cross (unitRight)).unit();
238  fCurrentTargetPoint = right * unitRight + up * unitUp;
239 }
240 
242  IncrementPan (right,up, 0);
243 }
244 
246  G4Vector3D unitRight = (fUpVector.cross (fViewpointDirection)).unit();
247  G4Vector3D unitUp = (fViewpointDirection.cross (unitRight)).unit();
248  fCurrentTargetPoint += right * unitRight + up * unitUp + distance * fViewpointDirection;
249 }
250 
252 (const G4Point3D standardTargetPoint) const
253 {
254  std::ostringstream oss;
255 
256  oss << "#\n# Camera and lights commands";
257 
258  oss << "\n/vis/viewer/set/viewpointVector "
259  << fViewpointDirection.x()
260  << ' ' << fViewpointDirection.y()
261  << ' ' << fViewpointDirection.z();
262 
263  oss << "\n/vis/viewer/set/upVector "
264  << fUpVector.x()
265  << ' ' << fUpVector.y()
266  << ' ' << fUpVector.z();
267 
268  oss << "\n/vis/viewer/set/projection ";
269  if (fFieldHalfAngle == 0.) {
270  oss
271  << "orthogonal";
272  } else {
273  oss
274  << "perspective "
275  << fFieldHalfAngle/deg
276  << " deg";
277  }
278 
279  oss << "\n/vis/viewer/zoomTo "
280  << fZoomFactor;
281 
282  oss << "\n/vis/viewer/scaleTo "
283  << fScaleFactor.x()
284  << ' ' << fScaleFactor.y()
285  << ' ' << fScaleFactor.z();
286 
287  oss << "\n/vis/viewer/set/targetPoint "
288  << G4BestUnit(standardTargetPoint+fCurrentTargetPoint,"Length")
289  << "\n# Note that if you have not set a target point, the vis system sets"
290  << "\n# a target point based on the scene - plus any panning and dollying -"
291  << "\n# so don't be alarmed by strange coordinates here.";
292 
293  oss << "\n/vis/viewer/dollyTo "
294  << G4BestUnit(fDolly,"Length");
295 
296  oss << "\n/vis/viewer/set/lightsMove ";
297  if (fLightsMoveWithCamera) {
298  oss << "camera";
299  } else {
300  oss << "object";
301  }
302 
303  oss << "\n/vis/viewer/set/lightsVector "
304  << fRelativeLightpointDirection.x()
305  << ' ' << fRelativeLightpointDirection.y()
306  << ' ' << fRelativeLightpointDirection.z();
307 
308  oss << "\n/vis/viewer/set/rotationStyle ";
309  if (fRotationStyle == constrainUpDirection) {
310  oss << "constrainUpDirection";
311  } else {
312  oss << "freeRotation";
313  }
314 
315  G4Colour c = fBackgroundColour;
316  oss << "\n/vis/viewer/set/background "
317  << c.GetRed()
318  << ' ' << c.GetGreen()
319  << ' ' << c.GetBlue()
320  << ' ' << c.GetAlpha();
321 
322  c = fDefaultVisAttributes.GetColour();
323  oss << "\n/vis/viewer/set/defaultColour "
324  << c.GetRed()
325  << ' ' << c.GetGreen()
326  << ' ' << c.GetBlue()
327  << ' ' << c.GetAlpha();
328 
329  c = fDefaultTextVisAttributes.GetColour();
330  oss << "\n/vis/viewer/set/defaultTextColour "
331  << c.GetRed()
332  << ' ' << c.GetGreen()
333  << ' ' << c.GetBlue()
334  << ' ' << c.GetAlpha();
335 
336  oss << std::endl;
337 
338  return oss.str();
339 }
340 
342 {
343  std::ostringstream oss;
344 
345  oss << "#\n# Drawing style commands";
346 
347  oss << "\n/vis/viewer/set/style ";
348  if (fDrawingStyle == wireframe || fDrawingStyle == hlr) {
349  oss << "wireframe";
350  } else {
351  oss << "surface";
352  }
353 
354  oss << "\n/vis/viewer/set/hiddenEdge ";
355  if (fDrawingStyle == hlr || fDrawingStyle == hlhsr) {
356  oss << "true";
357  } else {
358  oss << "false";
359  }
360 
361  oss << "\n/vis/viewer/set/auxiliaryEdge ";
362  if (fAuxEdgeVisible) {
363  oss << "true";
364  } else {
365  oss << "false";
366  }
367 
368  oss << "\n/vis/viewer/set/hiddenMarker ";
369  if (fMarkerNotHidden) {
370  oss << "false";
371  } else {
372  oss << "true";
373  }
374 
375  oss << "\n/vis/viewer/set/globalLineWidthScale "
376  << fGlobalLineWidthScale;
377 
378  oss << "\n/vis/viewer/set/globalMarkerScale "
379  << fGlobalMarkerScale;
380 
381  oss << std::endl;
382 
383  return oss.str();
384 }
385 
387 {
388  std::ostringstream oss;
389 
390  oss << "#\n# Scene-modifying commands";
391 
392  oss << "\n/vis/viewer/set/culling global ";
393  if (fCulling) {
394  oss << "true";
395  } else {
396  oss << "false";
397  }
398 
399  oss << "\n/vis/viewer/set/culling invisible ";
400  if (fCullInvisible) {
401  oss << "true";
402  } else {
403  oss << "false";
404  }
405 
406  oss << "\n/vis/viewer/set/culling density ";
407  if (fDensityCulling) {
408  oss << "true " << fVisibleDensity/(g/cm3) << " g/cm3";
409  } else {
410  oss << "false";
411  }
412 
413  oss << "\n/vis/viewer/set/culling coveredDaughters ";
414  if (fCullCovered) {
415  oss << "true";
416  } else {
417  oss << "false";
418  }
419 
420  oss << "\n/vis/viewer/set/sectionPlane ";
421  if (fSection) {
422  oss << "on "
423  << G4BestUnit(fSectionPlane.point(),"Length")
424  << fSectionPlane.normal().x()
425  << ' ' << fSectionPlane.normal().y()
426  << ' ' << fSectionPlane.normal().z();
427  } else {
428  oss << "off";
429  }
430 
431  oss << "\n/vis/viewer/set/cutawayMode ";
432  if (fCutawayMode == cutawayUnion) {
433  oss << "union";
434  } else {
435  oss << "intersection";
436  }
437 
438  oss << "\n/vis/viewer/clearCutawayPlanes";
439  if (fCutawayPlanes.size()) {
440  for (size_t i = 0; i < fCutawayPlanes.size(); i++) {
441  oss << "\n/vis/viewer/addCutawayPlane "
442  << G4BestUnit(fCutawayPlanes[i].point(),"Length")
443  << fCutawayPlanes[i].normal().x()
444  << ' ' << fCutawayPlanes[i].normal().y()
445  << ' ' << fCutawayPlanes[i].normal().z();
446  }
447  } else {
448  oss << "\n# No cutaway planes defined.";
449  }
450 
451  oss << "\n/vis/viewer/set/explodeFactor "
452  << fExplodeFactor
453  << ' ' << G4BestUnit(fExplodeCentre,"Length");
454 
455  oss << "\n/vis/viewer/set/lineSegmentsPerCircle "
456  << fNoOfSides;
457 
458  oss << std::endl;
459 
460  return oss.str();
461 }
462 
464 {
465  std::ostringstream oss;
466 
467  oss << "#\n# Touchable commands";
468 
469  const std::vector<G4ModelingParameters::VisAttributesModifier>& vams =
470  fVisAttributesModifiers;
471 
472  if (vams.empty()) {
473  oss << "\n# None";
474  oss << std::endl;
475  return oss.str();
476  }
477 
478  std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator
479  iModifier;
480  for (iModifier = vams.begin();
481  iModifier != vams.end();
482  ++iModifier) {
485  iModifier->GetPVNameCopyNoPath();
486  if (vamPath != lastPath) {
487  lastPath = vamPath;
488  oss << "\n/vis/set/touchable";
490  for (iVAM = vamPath.begin();
491  iVAM != vamPath.end();
492  ++iVAM) {
493  oss << ' ' << iVAM->GetName() << ' ' << iVAM->GetCopyNo();
494  }
495  }
496  const G4VisAttributes& vamVisAtts = iModifier->GetVisAttributes();
497  const G4Colour& c = vamVisAtts.GetColour();
498  switch (iModifier->GetVisAttributesSignifier()) {
500  oss << "\n/vis/touchable/set/visibility ";
501  if (vamVisAtts.IsVisible()) {
502  oss << "true";
503  } else {
504  oss << "false";
505  }
506  break;
508  oss << "\n/vis/touchable/set/daughtersInvisible ";
509  if (vamVisAtts.IsDaughtersInvisible()) {
510  oss << "true";
511  } else {
512  oss << "false";
513  }
514  break;
516  oss << "\n/vis/touchable/set/colour "
517  << c.GetRed()
518  << ' ' << c.GetGreen()
519  << ' ' << c.GetBlue()
520  << ' ' << c.GetAlpha();
521  break;
523  oss << "\n/vis/touchable/set/lineStyle ";
524  switch (vamVisAtts.GetLineStyle()) {
526  oss << "unbroken";
527  break;
529  oss << "dashed";
530  break;
532  oss << "dotted";
533  }
534  break;
536  oss << "\n/vis/touchable/set/lineWidth "
537  << vamVisAtts.GetLineWidth();
538  break;
541  oss << "\n/vis/touchable/set/forceWireframe ";
542  if (vamVisAtts.IsForceDrawingStyle()) {
543  oss << "true";
544  } else {
545  oss << "false";
546  }
547  }
548  break;
550  if (vamVisAtts.GetForcedDrawingStyle() == G4VisAttributes::solid) {
551  oss << "\n/vis/touchable/set/forceSolid ";
552  if (vamVisAtts.IsForceDrawingStyle()) {
553  oss << "true";
554  } else {
555  oss << "false";
556  }
557  }
558  break;
560  oss << "\n/vis/touchable/set/forceAuxEdgeVisible ";
561  if (vamVisAtts.IsForceAuxEdgeVisible()) {
562  oss << "true";
563  } else {
564  oss << "false";
565  }
566  break;
568  oss << "\n/vis/touchable/set/lineSegmentsPerCircle "
569  << vamVisAtts.GetForcedLineSegmentsPerCircle();
570  break;
571  }
572  }
573 
574  oss << std::endl;
575 
576  return oss.str();
577 }
578 
580 
581  // Put performance-sensitive parameters first.
582  if (
583  // This first to optimise spin, etc.
584  (fViewpointDirection != v.fViewpointDirection) ||
585 
586  // No particular order from here on.
587  (fDrawingStyle != v.fDrawingStyle) ||
588  (fAuxEdgeVisible != v.fAuxEdgeVisible) ||
589  (fCulling != v.fCulling) ||
590  (fCullInvisible != v.fCullInvisible) ||
591  (fDensityCulling != v.fDensityCulling) ||
592  (fVisibleDensity != v.fVisibleDensity) ||
593  (fCullCovered != v.fCullCovered) ||
594  (fSection != v.fSection) ||
595  (fNoOfSides != v.fNoOfSides) ||
596  (fUpVector != v.fUpVector) ||
597  (fFieldHalfAngle != v.fFieldHalfAngle) ||
598  (fZoomFactor != v.fZoomFactor) ||
599  (fScaleFactor != v.fScaleFactor) ||
600  (fCurrentTargetPoint != v.fCurrentTargetPoint) ||
601  (fDolly != v.fDolly) ||
602  (fRelativeLightpointDirection != v.fRelativeLightpointDirection) ||
603  (fLightsMoveWithCamera != v.fLightsMoveWithCamera) ||
604  (fDefaultVisAttributes != v.fDefaultVisAttributes) ||
605  (fDefaultTextVisAttributes != v.fDefaultTextVisAttributes) ||
606  (fDefaultMarker != v.fDefaultMarker) ||
607  (fGlobalMarkerScale != v.fGlobalMarkerScale) ||
608  (fGlobalLineWidthScale != v.fGlobalLineWidthScale) ||
609  (fMarkerNotHidden != v.fMarkerNotHidden) ||
610  (fWindowSizeHintX != v.fWindowSizeHintX) ||
611  (fWindowSizeHintY != v.fWindowSizeHintY) ||
612  (fXGeometryString != v.fXGeometryString) ||
613  (fGeometryMask != v.fGeometryMask) ||
614  (fAutoRefresh != v.fAutoRefresh) ||
615  (fBackgroundColour != v.fBackgroundColour) ||
616  (fPicking != v.fPicking) ||
617  (fRotationStyle != v.fRotationStyle)
618  )
619  G4cout << "Difference in 1st batch." << G4endl;
620 
621  if (fSection) {
622  if (!(fSectionPlane == v.fSectionPlane))
623  G4cout << "Difference in section planes batch." << G4endl;
624  }
625 
626  if (IsCutaway()) {
627  if (fCutawayPlanes.size () != v.fCutawayPlanes.size ()) {
628  G4cout << "Difference in no of cutaway planes." << G4endl;
629  }
630  else {
631  for (size_t i = 0; i < fCutawayPlanes.size (); i++) {
632  if (!(fCutawayPlanes[i] == v.fCutawayPlanes[i]))
633  G4cout << "Difference in cutaway plane no. " << i << G4endl;
634  }
635  }
636  }
637 
638  if (IsExplode()) {
639  if (fExplodeFactor != v.fExplodeFactor)
640  G4cout << "Difference in explode factor." << G4endl;
641  if (fExplodeCentre != v.fExplodeCentre)
642  G4cout << "Difference in explode centre." << G4endl;
643  }
644 }
645 
646 std::ostream& operator << (std::ostream& os,
647  const G4ViewParameters::DrawingStyle& style) {
648  switch (style) {
650  os << "wireframe"; break;
652  os << "hlr - hidden lines removed"; break;
654  os << "hsr - hidden surfaces removed"; break;
656  os << "hlhsr - hidden line, hidden surface removed"; break;
657  default: os << "unrecognised"; break;
658  }
659  return os;
660 }
661 
662 std::ostream& operator << (std::ostream& os, const G4ViewParameters& v) {
663  os << "View parameters and options:";
664 
665  os << "\n Drawing style: ";
666  switch (v.fDrawingStyle) {
668  os << "edges, wireframe"; break;
670  os << "edges, hidden line removal"; break;
672  os << "surfaces, hidden surface removal"; break;
674  os << "surfaces and edges, hidden line and surface removal"; break;
675  default: os << "unrecognised"; break;
676  }
677 
678  os << "\n Auxiliary edges: ";
679  if (!v.fAuxEdgeVisible) os << "in";
680  os << "visible";
681 
682  os << "\n Culling: ";
683  if (v.fCulling) os << "on";
684  else os << "off";
685 
686  os << "\n Culling invisible objects: ";
687  if (v.fCullInvisible) os << "on";
688  else os << "off";
689 
690  os << "\n Density culling: ";
691  if (v.fDensityCulling) {
692  os << "on - invisible if density less than "
693  << v.fVisibleDensity / (1. * g / cm3) << " g cm^-3";
694  }
695  else os << "off";
696 
697  os << "\n Culling daughters covered by opaque mothers: ";
698  if (v.fCullCovered) os << "on";
699  else os << "off";
700 
701  os << "\n Section flag: ";
702  if (v.fSection) os << "true, section/cut plane: " << v.fSectionPlane;
703  else os << "false";
704 
705  if (v.IsCutaway()) {
706  os << "\n Cutaway planes: ";
707  for (size_t i = 0; i < v.fCutawayPlanes.size (); i++) {
708  os << ' ' << v.fCutawayPlanes[i];
709  }
710  }
711  else {
712  os << "\n No cutaway planes";
713  }
714 
715  os << "\n Explode factor: " << v.fExplodeFactor
716  << " about centre: " << v.fExplodeCentre;
717 
718  os << "\n No. of sides used in circle polygon approximation: "
719  << v.fNoOfSides;
720 
721  os << "\n Viewpoint direction: " << v.fViewpointDirection;
722 
723  os << "\n Up vector: " << v.fUpVector;
724 
725  os << "\n Field half angle: " << v.fFieldHalfAngle;
726 
727  os << "\n Zoom factor: " << v.fZoomFactor;
728 
729  os << "\n Scale factor: " << v.fScaleFactor;
730 
731  os << "\n Current target point: " << v.fCurrentTargetPoint;
732 
733  os << "\n Dolly distance: " << v.fDolly;
734 
735  os << "\n Light ";
736  if (v.fLightsMoveWithCamera) os << "moves";
737  else os << "does not move";
738  os << " with camera";
739 
740  os << "\n Relative lightpoint direction: "
741  << v.fRelativeLightpointDirection;
742 
743  os << "\n Actual lightpoint direction: "
744  << v.fActualLightpointDirection;
745 
746  os << "\n Derived parameters for standard view of object of unit radius:";
747  G4ViewParameters tempVP = v;
748  tempVP.fDolly = 0.;
749  tempVP.fZoomFactor = 1.;
750  const G4double radius = 1.;
751  const G4double cameraDistance = tempVP.GetCameraDistance (radius);
752  const G4double nearDistance =
753  tempVP.GetNearDistance (cameraDistance, radius);
754  const G4double farDistance =
755  tempVP.GetFarDistance (cameraDistance, nearDistance, radius);
756  const G4double right = tempVP.GetFrontHalfHeight (nearDistance, radius);
757  os << "\n Camera distance: " << cameraDistance;
758  os << "\n Near distance: " << nearDistance;
759  os << "\n Far distance: " << farDistance;
760  os << "\n Front half height: " << right;
761 
762  os << "\n Default VisAttributes:\n " << v.fDefaultVisAttributes;
763 
764  os << "\n Default TextVisAttributes:\n " << v.fDefaultTextVisAttributes;
765 
766  os << "\n Default marker: " << v.fDefaultMarker;
767 
768  os << "\n Global marker scale: " << v.fGlobalMarkerScale;
769 
770  os << "\n Global lineWidth scale: " << v.fGlobalLineWidthScale;
771 
772  os << "\n Marker ";
773  if (v.fMarkerNotHidden) os << "not ";
774  os << "hidden by surfaces.";
775 
776  os << "\n Window size hint: "
777  << v.fWindowSizeHintX << 'x'<< v.fWindowSizeHintX;
778 
779  os << "\n X geometry string: " << v.fXGeometryString;
780  os << "\n X geometry mask: "
781  << std::showbase << std::hex << v.fGeometryMask
782  << std::noshowbase << std::dec;
783 
784  os << "\n Auto refresh: ";
785  if (v.fAutoRefresh) os << "true";
786  else os << "false";
787 
788  os << "\n Background colour: " << v.fBackgroundColour;
789 
790  os << "\n Picking requested: ";
791  if (v.fPicking) os << "true";
792  else os << "false";
793 
794  os << "\n Rotation style: ";
795  switch (v.fRotationStyle) {
797  os << "constrainUpDirection (conventional HEP view)"; break;
799  os << "freeRotation (Google-like rotation, using mouse-grab)"; break;
800  default: os << "unrecognised"; break;
801  }
802 
803  os << "\n Vis attributes modifiers: ";
804  const std::vector<G4ModelingParameters::VisAttributesModifier>& vams =
805  v.fVisAttributesModifiers;
806  if (vams.empty()) {
807  os << "None";
808  } else {
809  os << vams;
810  }
811 
812  return os;
813 }
814 
816 
817  // Put performance-sensitive parameters first.
818  if (
819  // This first to optimise spin, etc.
820  (fViewpointDirection != v.fViewpointDirection) ||
821 
822  // No particular order from here on.
823  (fDrawingStyle != v.fDrawingStyle) ||
824  (fAuxEdgeVisible != v.fAuxEdgeVisible) ||
825  (fCulling != v.fCulling) ||
826  (fCullInvisible != v.fCullInvisible) ||
827  (fDensityCulling != v.fDensityCulling) ||
828  (fCullCovered != v.fCullCovered) ||
829  (fSection != v.fSection) ||
830  (IsCutaway() != v.IsCutaway()) ||
831  (IsExplode() != v.IsExplode()) ||
832  (fNoOfSides != v.fNoOfSides) ||
833  (fUpVector != v.fUpVector) ||
834  (fFieldHalfAngle != v.fFieldHalfAngle) ||
835  (fZoomFactor != v.fZoomFactor) ||
836  (fScaleFactor != v.fScaleFactor) ||
837  (fCurrentTargetPoint != v.fCurrentTargetPoint) ||
838  (fDolly != v.fDolly) ||
839  (fRelativeLightpointDirection != v.fRelativeLightpointDirection) ||
840  (fLightsMoveWithCamera != v.fLightsMoveWithCamera) ||
841  (fDefaultVisAttributes != v.fDefaultVisAttributes) ||
842  (fDefaultTextVisAttributes != v.fDefaultTextVisAttributes) ||
843  (fDefaultMarker != v.fDefaultMarker) ||
844  (fGlobalMarkerScale != v.fGlobalMarkerScale) ||
845  (fGlobalLineWidthScale != v.fGlobalLineWidthScale) ||
846  (fMarkerNotHidden != v.fMarkerNotHidden) ||
847  (fWindowSizeHintX != v.fWindowSizeHintX) ||
848  (fWindowSizeHintY != v.fWindowSizeHintY) ||
849  (fXGeometryString != v.fXGeometryString) ||
850  (fGeometryMask != v.fGeometryMask) ||
851  (fAutoRefresh != v.fAutoRefresh) ||
852  (fBackgroundColour != v.fBackgroundColour) ||
853  (fPicking != v.fPicking) ||
854  (fRotationStyle != v.fRotationStyle)
855  )
856  return true;
857 
858  if (fDensityCulling &&
859  (fVisibleDensity != v.fVisibleDensity)) return true;
860 
861  if (fSection &&
862  (!(fSectionPlane == v.fSectionPlane))) return true;
863 
864  if (IsCutaway()) {
865  if (fCutawayPlanes.size () != v.fCutawayPlanes.size ())
866  return true;
867  else {
868  for (size_t i = 0; i < fCutawayPlanes.size (); i++) {
869  if (!(fCutawayPlanes[i] == v.fCutawayPlanes[i])) return true;
870  }
871  }
872  }
873 
874  if (IsExplode() &&
875  ((fExplodeFactor != v.fExplodeFactor) ||
876  (fExplodeCentre != v.fExplodeCentre))) return true;
877 
878  if (fVisAttributesModifiers != v.fVisAttributesModifiers) return true;
879 
880  return false;
881 }
882 
883 
885 {
886  G4int x,y = 0;
887  unsigned int w,h = 0;
888  G4String geomString = geomStringArg;
889  // Parse windowSizeHintString for backwards compatibility...
890  const G4String delimiters("xX+-");
891  G4String::size_type i = geomString.find_first_of(delimiters);
892  if (i == G4String::npos) { // Does not contain "xX+-". Assume single number
893  std::istringstream iss(geomString);
894  G4int size;
895  iss >> size;
896  if (!iss) {
897  size = 600;
898  G4cout << "Unrecognised windowSizeHint string: \""
899  << geomString
900  << "\". Asuuming " << size << G4endl;
901  }
902  std::ostringstream oss;
903  oss << size << 'x' << size;
904  geomString = oss.str();
905  }
906 
907  fGeometryMask = ParseGeometry( geomString, &x, &y, &w, &h );
908 
909  // Handle special case :
910  if ((fGeometryMask & fYValue) == 0)
911  { // Using default
912  y = fWindowLocationHintY;
913  }
914  if ((fGeometryMask & fXValue) == 0)
915  { // Using default
916  x = fWindowLocationHintX;
917  }
918 
919  // Check errors
920  // if there is no Width and Height
921  if ( ((fGeometryMask & fHeightValue) == 0 ) &&
922  ((fGeometryMask & fWidthValue) == 0 )) {
923  h = fWindowSizeHintY;
924  w = fWindowSizeHintX;
925  } else if ((fGeometryMask & fHeightValue) == 0 ) {
926 
927  // if there is only Width. Special case to be backward compatible
928  // We set Width and Height the same to obtain a square windows.
929 
930  G4cout << "Unrecognised geometry string \""
931  << geomString
932  << "\". No Height found. Using Width value instead"
933  << G4endl;
934  h = w;
935  }
936  if ( ((fGeometryMask & fXValue) == 0 ) ||
937  ((fGeometryMask & fYValue) == 0 )) {
938  //Using defaults
939  x = fWindowLocationHintX;
940  y = fWindowLocationHintY;
941  }
942  // Set the string
943  fXGeometryString = geomString;
944 
945  // Set values
946  fWindowSizeHintX = w;
947  fWindowSizeHintY = h;
948  fWindowLocationHintX = x;
949  fWindowLocationHintY = y;
950 
951  if ( ((fGeometryMask & fXValue)) &&
952  ((fGeometryMask & fYValue))) {
953 
954  if ( (fGeometryMask & fXNegative) ) {
955  fWindowLocationHintXNegative = true;
956  } else {
957  fWindowLocationHintXNegative = false;
958  }
959  if ( (fGeometryMask & fYNegative) ) {
960  fWindowLocationHintYNegative = true;
961  } else {
962  fWindowLocationHintYNegative = false;
963  }
964  }
965 }
966 
968  if ( fWindowLocationHintXNegative ) {
969  return sizeX + fWindowLocationHintX - fWindowSizeHintX;
970  }
971  return fWindowLocationHintX;
972 }
973 
975  if ( fWindowLocationHintYNegative ) {
976  return sizeY + fWindowLocationHintY - fWindowSizeHintY;
977  }
978  return fWindowLocationHintY;
979 }
980 
981 /* Keep from :
982  * 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
983  *
984  * ParseGeometry parses strings of the form
985  * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
986  * width, height, xoffset, and yoffset are unsigned integers.
987  * Example: "=80x24+300-49"
988  * The equal sign is optional.
989  * It returns a bitmask that indicates which of the four values
990  * were actually found in the string. For each value found,
991  * the corresponding argument is updated; for each value
992  * not found, the corresponding argument is left unchanged.
993  */
994 
995 int G4ViewParameters::ParseGeometry (
996  const char *string,
997  G4int *x,
998  G4int *y,
999  unsigned int *width,
1000  unsigned int *height)
1001 {
1002 
1003  G4int mask = fNoValue;
1004  register char *strind;
1005  unsigned int tempWidth = 0;
1006  unsigned int tempHeight = 0;
1007  G4int tempX = 0;
1008  G4int tempY = 0;
1009  char *nextCharacter;
1010  if ( (string == NULL) || (*string == '\0')) {
1011  return(mask);
1012  }
1013  if (*string == '=')
1014  string++; /* ignore possible '=' at beg of geometry spec */
1015  strind = (char *)string;
1016  if (*strind != '+' && *strind != '-' && *strind != 'x') {
1017  tempWidth = ReadInteger(strind, &nextCharacter);
1018  if (strind == nextCharacter)
1019  return (0);
1020  strind = nextCharacter;
1021  mask |= fWidthValue;
1022  }
1023  if (*strind == 'x' || *strind == 'X') {
1024  strind++;
1025  tempHeight = ReadInteger(strind, &nextCharacter);
1026  if (strind == nextCharacter)
1027  return (0);
1028  strind = nextCharacter;
1029  mask |= fHeightValue;
1030  }
1031 
1032  if ((*strind == '+') || (*strind == '-')) {
1033  if (*strind == '-') {
1034  strind++;
1035  tempX = -ReadInteger(strind, &nextCharacter);
1036  if (strind == nextCharacter)
1037  return (0);
1038  strind = nextCharacter;
1039  mask |= fXNegative;
1040 
1041  }
1042  else
1043  { strind++;
1044  tempX = ReadInteger(strind, &nextCharacter);
1045  if (strind == nextCharacter)
1046  return(0);
1047  strind = nextCharacter;
1048  }
1049  mask |= fXValue;
1050  if ((*strind == '+') || (*strind == '-')) {
1051  if (*strind == '-') {
1052  strind++;
1053  tempY = -ReadInteger(strind, &nextCharacter);
1054  if (strind == nextCharacter)
1055  return(0);
1056  strind = nextCharacter;
1057  mask |= fYNegative;
1058  }
1059  else
1060  {
1061  strind++;
1062  tempY = ReadInteger(strind, &nextCharacter);
1063  if (strind == nextCharacter)
1064  return(0);
1065  strind = nextCharacter;
1066  }
1067  mask |= fYValue;
1068  }
1069  }
1070  /* If strind isn't at the end of the string the it's an invalid
1071  geometry specification. */
1072  if (*strind != '\0') return (0);
1073  if (mask & fXValue)
1074  *x = tempX;
1075  if (mask & fYValue)
1076  *y = tempY;
1077  if (mask & fWidthValue)
1078  *width = tempWidth;
1079  if (mask & fHeightValue)
1080  *height = tempHeight;
1081  return (mask);
1082 }
1083 
1084 /* Keep from :
1085  * 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
1086  *
1087  */
1088 G4int G4ViewParameters::ReadInteger(char *string, char **NextString)
1089 {
1090  register G4int Result = 0;
1091  G4int Sign = 1;
1092 
1093  if (*string == '+')
1094  string++;
1095  else if (*string == '-')
1096  {
1097  string++;
1098  Sign = -1;
1099  }
1100  for (; (*string >= '0') && (*string <= '9'); string++)
1101  {
1102  Result = (Result * 10) + (*string - '0');
1103  }
1104  *NextString = string;
1105  if (Sign >= 0)
1106  return (Result);
1107  else
1108  return (-Result);
1109 }
G4bool IsForceAuxEdgeVisible() const
G4String TouchableCommands() const
void IncrementPan(G4double right, G4double up)
G4Vector3D & GetActualLightpointDirection()
G4double GetAlpha() const
Definition: G4Colour.hh:142
void AddCutawayPlane(const G4Plane3D &cutawayPlane)
void SetLightpointDirection(const G4Vector3D &lightpointDirection)
void SetPan(G4double right, G4double up)
Int_t index
Definition: macro.C:9
G4int SetNoOfSides(G4int nSides)
G4int GetWindowAbsoluteLocationHintX(G4int) const
G4double GetLineWidth() const
G4bool operator!=(const G4ViewParameters &) const
BasicVector3D< T > unit() const
G4int GetWindowAbsoluteLocationHintY(G4int) const
G4bool IsVisible() const
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:126
const G4Colour & GetColour() const
#define width
G4String SceneModifyingCommands() const
Normal3D< T > normal() const
Definition: Plane3D.h:90
tuple x
Definition: test.py:50
G4double GetBlue() const
Definition: G4Colour.hh:141
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
G4double GetFarDistance(G4double cameraDistance, G4double nearDistance, G4double radius) const
void SetVisibleDensity(G4double visibleDensity)
int G4int
Definition: G4Types.hh:78
LineStyle GetLineStyle() const
G4double GetCameraDistance(G4double radius) const
void SetViewAndLights(const G4Vector3D &viewpointDirection)
G4double GetNearDistance(G4double cameraDistance, G4double radius) const
Double_t y
Definition: plot.C:279
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4GLOB_DLL std::ostream G4cout
G4double GetRed() const
Definition: G4Colour.hh:139
void ChangeCutawayPlane(size_t index, const G4Plane3D &cutawayPlane)
G4bool IsDaughtersInvisible() const
bool G4bool
Definition: G4Types.hh:79
G4double GetGreen() const
Definition: G4Colour.hh:140
G4double GetFrontHalfHeight(G4double nearDistance, G4double radius) const
void SetXGeometryString(const G4String &)
Point3D< T > point(const Point3D< T > &p) const
Definition: Plane3D.h:108
tuple v
Definition: test.py:18
G4String DrawingStyleCommands() const
G4int GetForcedLineSegmentsPerCircle() const
G4bool IsExplode() const
void PrintDifferences(const G4ViewParameters &v) const
G4bool IsCutaway() const
std::vector< PVNameCopyNo > PVNameCopyNoPath
G4bool IsForceDrawingStyle() const
std::ostream & operator<<(std::ostream &, const BasicVector3D< float > &)
G4String CameraAndLightingCommands(const G4Point3D standardTargetPoint) const
#define G4endl
Definition: G4ios.hh:61
void MultiplyScaleFactor(const G4Vector3D &scaleFactorMultiplier)
double G4double
Definition: G4Types.hh:76
short Sign(short a, short b)
Definition: UUtils.hh:184
tuple c
Definition: test.py:13
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
ForcedDrawingStyle GetForcedDrawingStyle() const
PVNameCopyNoPath::const_iterator PVNameCopyNoPathConstIterator
void SetScreenSize(G4double)