Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ViewParameters.hh
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$
28 //
29 //
30 // John Allison 19th July 1996
31 //
32 // Class description
33 //
34 // View parameters and options.
35 //
36 // THE STANDARD VIEW AND ALL THAT.
37 //
38 // In GEANT4 visualization, we have the concept of a "Standard
39 // View". This is the view when the complete set of objects being
40 // viewed is comfortably in view from any viewpoint. It is defined by
41 // the "Bounding Sphere" of "visible" objects when initially
42 // registered in the scene, and by the View Parameters.
43 //
44 // There is also the "Standard Target Point", which is the centre of
45 // the Bounding Sphere (note that this belongs to the scene and is
46 // stored in the G4Scene object). The "Current Target Point", defined
47 // relative to the Standard Target Point, is changed by the
48 // "dolly" and "zoom" commands, and can be reset to the Standard
49 // Target Point with the "/vis/viewer/reset" command.
50 //
51 // Also, the "Standard Camera Position" is the "Standard Camera
52 // Distance" along the Viewpoint Direction vector from the Standard
53 // Target Point. The Standard Camera Distance is the radius of the
54 // Bounding Sphere divided by fFieldHalfAngle. It is not stored
55 // explicitly because of the singularity at fFieldHalfAngle = 0,
56 // which implies parallel projection.
57 //
58 // Similarly, the "Current Camera Position" is the "Current Camera
59 // Distance" along the Viewpoint Direction vector from the Current
60 // Target Point. The Current Camera Distance is given by the formulae
61 // below, but note that it can be negative, meaning that the camera
62 // has moved *beyond* the Current Target Point, which is
63 // conceptually possible, but which might give some problems when
64 // setting up the view matrix - see, for example, G4OpenGLView::SetView ().
65 //
66 // All viewers are expected to keep the "Up Vector" vertical.
67 //
68 // Finally, the view is magnified by the "Zoom Factor" which is
69 // reset to 1 by the "/vis/viewer/reset" command.
70 //
71 // The algorithms for calculating various useful quantities from the
72 // View Parameters, such as GetCameraDistance, are described below.
73 
74 #ifndef G4VIEWPARAMETERS_HH
75 #define G4VIEWPARAMETERS_HH
76 
78 #include "G4Vector3D.hh"
79 #include "G4Point3D.hh"
80 #include "G4Plane3D.hh"
81 #include "G4VisAttributes.hh"
82 #include "G4VMarker.hh"
83 #include "G4ModelingParameters.hh"
84 
85 #include <vector>
86 #include <utility>
87 
88 typedef std::vector<G4Plane3D> G4Planes;
89 
91 
92 public: // With description
93 
94  enum DrawingStyle {
95  wireframe, // Draw edges - no hidden line removal.
96  hlr, // Draw edges - hidden lines removed.
97  hsr, // Draw surfaces - hidden surfaces removed.
98  hlhsr // Draw surfaces and edges - hidden removed.
99  };
100 
101  enum RepStyle {
102  polyhedron, // Use G4Polyhedron.
103  nurbs // Use G4NURBS.
104  };
105 
106  enum CutawayMode {
107  cutawayUnion, // Union (addition) of result of each cutaway plane.
108  cutawayIntersection // Intersection (multiplication) " .
109  };
110 
112  constrainUpDirection, // Standard, HEP convention.
113  freeRotation // Free, Google-like rotation, using mouse-grab.
114  };
115 
116  friend std::ostream& operator << (std::ostream&,
117  const DrawingStyle&);
118 
119  friend std::ostream& operator << (std::ostream&,
120  const G4ViewParameters&);
121 
122  G4ViewParameters ();
124 
125  // Note: uses default assignment operator and copy constructor.
126 
127  G4bool operator != (const G4ViewParameters&) const;
128 
129  // Get and Is functions.
130  DrawingStyle GetDrawingStyle () const;
131  G4bool IsAuxEdgeVisible () const;
132  RepStyle GetRepStyle () const;
133  G4bool IsCulling () const;
134  G4bool IsCullingInvisible () const;
135  G4bool IsDensityCulling () const;
136  G4double GetVisibleDensity () const;
137  G4bool IsCullingCovered () const;
138  G4bool IsSection () const;
139  const G4Plane3D& GetSectionPlane () const;
140  G4bool IsCutaway () const;
141  CutawayMode GetCutawayMode () const;
142  const G4Planes& GetCutawayPlanes () const;
143  G4bool IsExplode () const;
144  G4double GetExplodeFactor () const;
145  const G4Point3D& GetExplodeCentre () const;
146  G4int GetNoOfSides () const;
147  const G4Vector3D& GetViewpointDirection () const;
148  const G4Vector3D& GetUpVector () const;
149  G4double GetFieldHalfAngle () const;
150  G4double GetZoomFactor () const;
151  const G4Vector3D& GetScaleFactor () const;
152  const G4Point3D& GetCurrentTargetPoint () const;
153  G4double GetDolly () const;
155  const G4Vector3D& GetLightpointDirection () const; // Relative...
156  G4Vector3D& GetActualLightpointDirection (); // Actual...
157  // ... depending on GetLightsMoveWithCamera.
160  const G4VMarker& GetDefaultMarker () const;
163  G4bool IsMarkerNotHidden () const;
164  unsigned int GetWindowSizeHintX () const;
165  unsigned int GetWindowSizeHintY () const;
168  G4int GetWindowLocationHintX () const;
169  G4int GetWindowLocationHintY () const;
170  const G4String& GetXGeometryString () const;
171  // GetXGeometryString is intended to be parsed by XParseGeometry.
172  // It contains the size information, as in GetWindowSizeHint, but
173  // may also contain the window position, e.g., "600x600-0+200. The
174  // viewer should use this in preference to GetWindowSizeHint, since
175  // it contains more information. (The size information in
176  // GetXGeometryString and GetWindowSizeHint is guaranteed to be
177  // identical.)
178  bool IsWindowSizeHintX () const;
179  bool IsWindowSizeHintY () const;
180  bool IsWindowLocationHintX () const;
181  bool IsWindowLocationHintY () const;
182  G4bool IsAutoRefresh () const;
183  const G4Colour& GetBackgroundColour () const;
184  G4bool IsPicking () const;
186  const std::vector<G4ModelingParameters::VisAttributesModifier>&
187  GetVisAttributesModifiers () const;
188 
189  // Here Follow functions to evaluate useful quantities as a
190  // function of the radius of the Bounding Sphere of the object being
191  // viewed. Call them in the order given - for efficiency, later
192  // functions depend on the results of earlier ones (Store the
193  // results of earlier functions in your own temporary variables -
194  // see, for example, G4OpenGLView::SetView ().)
195  G4double GetCameraDistance (G4double radius) const;
196  G4double GetNearDistance (G4double cameraDistance, G4double radius) const;
197  G4double GetFarDistance (G4double cameraDistance,
198  G4double nearDistance, G4double radius) const;
199  G4double GetFrontHalfHeight (G4double nearDistance, G4double radius) const;
200 
201  // Set, Add, Multiply, Increment, Unset and Clear functions.
203  void SetAuxEdgeVisible (G4bool);
205  void SetCulling (G4bool);
207  void SetDensityCulling (G4bool);
208  void SetVisibleDensity (G4double visibleDensity);
209  void SetCullingCovered (G4bool);
210  void SetSectionPlane (const G4Plane3D& sectionPlane);
211  void UnsetSectionPlane ();
213  void AddCutawayPlane (const G4Plane3D& cutawayPlane);
214  void ChangeCutawayPlane (size_t index, const G4Plane3D& cutawayPlane);
215  void ClearCutawayPlanes ();
216  void SetExplodeFactor (G4double explodeFactor);
217  void UnsetExplodeFactor ();
218  void SetExplodeCentre (const G4Point3D& explodeCentre);
219  G4int SetNoOfSides (G4int nSides); // Returns actual number set.
220  void SetViewpointDirection (const G4Vector3D& viewpointDirection);
221  // Calls the following to get lightpoint direction right too.
222  void SetViewAndLights (const G4Vector3D& viewpointDirection);
223  // Also sets lightpoint direction according to G4bool fLightsMoveWithCamera.
224  void SetUpVector (const G4Vector3D& upVector);
225  void SetFieldHalfAngle (G4double fieldHalfAngle);
226  void SetOrthogonalProjection (); // This and next use SetFieldHalfAngle.
227  void SetPerspectiveProjection(G4double fieldHalfAngle = 30. * CLHEP::deg);
228  void SetZoomFactor (G4double zoomFactor);
229  void MultiplyZoomFactor (G4double zoomFactorMultiplier);
230  void SetScaleFactor (const G4Vector3D& scaleFactor);
231  void MultiplyScaleFactor (const G4Vector3D& scaleFactorMultiplier);
232  void SetCurrentTargetPoint (const G4Point3D& currentTargetPoint);
233  void SetDolly (G4double dolly);
234  void IncrementDolly (G4double dollyIncrement);
235  void SetLightpointDirection (const G4Vector3D& lightpointDirection);
236  void SetLightsMoveWithCamera (G4bool moves);
237  void SetPan (G4double right, G4double up);
238  void IncrementPan (G4double right, G4double up);
239  // Increment currentTarget point perpendicular to viewpoint direction.
240  void IncrementPan (G4double right, G4double up, G4double forward);
241  // Increment currentTarget point also along viewpoint direction.
243  void SetDefaultColour (const G4Colour&); // Uses SetDefaultVisAttributes.
245  void SetDefaultTextColour (const G4Colour&); // SetDefaultTextVisAttributes.
246  void SetDefaultMarker (const G4VMarker& defaultMarker);
247  void SetGlobalMarkerScale (G4double globalMarkerScale);
248  void SetGlobalLineWidthScale (G4double globalLineWidthScale);
249  void SetMarkerHidden ();
250  void SetMarkerNotHidden ();
251  void SetWindowSizeHint (G4int xHint, G4int yHint);
252  void SetWindowLocationHint (G4int xHint, G4int yHint);
253  void SetXGeometryString (const G4String&);
254  void SetAutoRefresh (G4bool);
255  void SetBackgroundColour (const G4Colour&);
256  void SetPicking (G4bool);
260 
261  // Command dumping functions.
262  // For camera commands we need to provide the standard target point from
263  // the current scene.
264  G4String CameraAndLightingCommands(const G4Point3D standardTargetPoint) const;
267  G4String TouchableCommands () const;
268 
269  // Other functions.
270  void PrintDifferences (const G4ViewParameters& v) const;
271 
272 private:
273 
274  G4int ParseGeometry ( const char *string, G4int *x, G4int *y, unsigned int *width, unsigned int *height);
275  G4int ReadInteger(char *string, char **NextString);
276 
277  DrawingStyle fDrawingStyle; // Drawing style.
278  G4bool fAuxEdgeVisible; // Auxiliary edge visibility.
279  RepStyle fRepStyle; // Representation style.
280  G4bool fCulling; // Culling requested.
281  G4bool fCullInvisible; // Cull (don't Draw) invisible objects.
282  G4bool fDensityCulling; // Density culling requested. If so...
283  G4double fVisibleDensity; // ...density lower than this not drawn.
284  G4bool fCullCovered; // Cull daughters covered by opaque mothers.
285  G4bool fSection; // Section drawing requested (DCUT in GEANT3).
286  G4Plane3D fSectionPlane; // Cut plane for section drawing (DCUT).
287  CutawayMode fCutawayMode; // Cutaway mode.
288  G4Planes fCutawayPlanes; // Set of planes used for cutaway.
289  G4double fExplodeFactor; // Explode along radius by this factor...
290  G4Point3D fExplodeCentre; // ...about this centre.
291  G4int fNoOfSides; // ...if polygon approximates circle.
292  G4Vector3D fViewpointDirection;
293  G4Vector3D fUpVector; // Up vector. (Warning: MUST NOT be parallel
294  // to fViewpointDirection!)
295  G4double fFieldHalfAngle; // Radius / camara distance, 0 for parallel.
296  G4double fZoomFactor; // Magnification relative to Standard View.
297  G4Vector3D fScaleFactor; // (Non-uniform) scale/magnification factor.
298  G4Point3D fCurrentTargetPoint; // Relative to standard target point.
299  G4double fDolly; // Distance towards current target point.
300  G4bool fLightsMoveWithCamera;
301  G4Vector3D fRelativeLightpointDirection;
302  // i.e., rel. to object or camera accoding to G4bool fLightsMoveWithCamera.
303  G4Vector3D fActualLightpointDirection;
304  G4VisAttributes fDefaultVisAttributes;
305  G4VisAttributes fDefaultTextVisAttributes;
306  G4VMarker fDefaultMarker;
307  G4double fGlobalMarkerScale;
308  G4double fGlobalLineWidthScale;
309  G4bool fMarkerNotHidden;
310  // True if transients are to be drawn and not hidden by
311  // hidden-line-hidden-surface removal algorithms, e.g., z-buffer
312  // testing; false if they are to be hidden-line-hidden-surface
313  // removed.
314  G4int fWindowSizeHintX; // Size hints for pixel-based window systems.
315  G4int fWindowSizeHintY;
316  G4int fWindowLocationHintX; // Location hints for pixel-based window systems.
317  G4int fWindowLocationHintY;
318  G4bool fWindowLocationHintXNegative; // Reference of location hints for pixel-based window systems.
319  G4bool fWindowLocationHintYNegative;
320  G4String fXGeometryString; // If non-null, geometry string for X Windows.
321  G4int fGeometryMask; // Corresponding mask.
322  G4bool fAutoRefresh; // ...after change of view parameters.
323  G4Colour fBackgroundColour;
324  G4bool fPicking; // Request picking.
325  RotationStyle fRotationStyle; // Rotation style.
326  std::vector<G4ModelingParameters::VisAttributesModifier>
327  fVisAttributesModifiers;
328 
329  enum { // Constants for geometry mask in ParseGeometry and related functions.
330  fNoValue = 0,
331  fXValue = 0x0001,
332  fYValue = 0x0002,
333  fWidthValue = 0x0004,
334  fHeightValue = 0x0008,
335  fAllValues = 0x000F,
336  fXNegative = 0x0010,
337  fYNegative = 0x0020
338  };
339 };
340 
341 #include "G4ViewParameters.icc"
342 
343 #endif