Geant4  10.01.p03
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: G4ViewParameters.hh 66373 2012-12-18 09:41:34Z gcosmo $
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 
77 #include <CLHEP/Units/SystemOfUnits.h>
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 CutawayMode {
102  cutawayUnion, // Union (addition) of result of each cutaway plane.
103  cutawayIntersection // Intersection (multiplication) " .
104  };
105 
107  constrainUpDirection, // Standard, HEP convention.
108  freeRotation // Free, Google-like rotation, using mouse-grab.
109  };
110 
111  friend std::ostream& operator << (std::ostream&,
112  const DrawingStyle&);
113 
114  friend std::ostream& operator << (std::ostream&,
115  const G4ViewParameters&);
116 
117  G4ViewParameters ();
119 
120  // Note: uses default assignment operator and copy constructor.
121 
122  G4bool operator != (const G4ViewParameters&) const;
123 
124  // Get and Is functions.
125  DrawingStyle GetDrawingStyle () const;
126  G4bool IsAuxEdgeVisible () const;
127  G4bool IsCulling () const;
128  G4bool IsCullingInvisible () const;
129  G4bool IsDensityCulling () const;
130  G4double GetVisibleDensity () const;
131  G4bool IsCullingCovered () const;
132  G4bool IsSection () const;
133  const G4Plane3D& GetSectionPlane () const;
134  G4bool IsCutaway () const;
135  CutawayMode GetCutawayMode () const;
136  const G4Planes& GetCutawayPlanes () const;
137  G4bool IsExplode () const;
138  G4double GetExplodeFactor () const;
139  const G4Point3D& GetExplodeCentre () const;
140  G4int GetNoOfSides () const;
141  const G4Vector3D& GetViewpointDirection () const;
142  const G4Vector3D& GetUpVector () const;
143  G4double GetFieldHalfAngle () const;
144  G4double GetZoomFactor () const;
145  const G4Vector3D& GetScaleFactor () const;
146  const G4Point3D& GetCurrentTargetPoint () const;
147  G4double GetDolly () const;
149  const G4Vector3D& GetLightpointDirection () const; // Relative...
150  G4Vector3D& GetActualLightpointDirection (); // Actual...
151  // ... depending on GetLightsMoveWithCamera.
154  const G4VMarker& GetDefaultMarker () const;
157  G4bool IsMarkerNotHidden () const;
158  unsigned int GetWindowSizeHintX () const;
159  unsigned int GetWindowSizeHintY () const;
162  G4int GetWindowLocationHintX () const;
163  G4int GetWindowLocationHintY () const;
164  const G4String& GetXGeometryString () const;
165  // GetXGeometryString is intended to be parsed by XParseGeometry.
166  // It contains the size information, as in GetWindowSizeHint, but
167  // may also contain the window position, e.g., "600x600-0+200. The
168  // viewer should use this in preference to GetWindowSizeHint, since
169  // it contains more information. (The size information in
170  // GetXGeometryString and GetWindowSizeHint is guaranteed to be
171  // identical.)
172  bool IsWindowSizeHintX () const;
173  bool IsWindowSizeHintY () const;
174  bool IsWindowLocationHintX () const;
175  bool IsWindowLocationHintY () const;
176  G4bool IsAutoRefresh () const;
177  const G4Colour& GetBackgroundColour () const;
178  G4bool IsPicking () const;
180  const std::vector<G4ModelingParameters::VisAttributesModifier>&
181  GetVisAttributesModifiers () const;
182 
183  // Here Follow functions to evaluate useful quantities as a
184  // function of the radius of the Bounding Sphere of the object being
185  // viewed. Call them in the order given - for efficiency, later
186  // functions depend on the results of earlier ones (Store the
187  // results of earlier functions in your own temporary variables -
188  // see, for example, G4OpenGLView::SetView ().)
189  G4double GetCameraDistance (G4double radius) const;
190  G4double GetNearDistance (G4double cameraDistance, G4double radius) const;
191  G4double GetFarDistance (G4double cameraDistance,
192  G4double nearDistance, G4double radius) const;
193  G4double GetFrontHalfHeight (G4double nearDistance, G4double radius) const;
194 
195  // Set, Add, Multiply, Increment, Unset and Clear functions.
197  void SetAuxEdgeVisible (G4bool);
198  void SetCulling (G4bool);
200  void SetDensityCulling (G4bool);
201  void SetVisibleDensity (G4double visibleDensity);
202  void SetCullingCovered (G4bool);
203  void SetSectionPlane (const G4Plane3D& sectionPlane);
204  void UnsetSectionPlane ();
206  void AddCutawayPlane (const G4Plane3D& cutawayPlane);
207  void ChangeCutawayPlane (size_t index, const G4Plane3D& cutawayPlane);
208  void ClearCutawayPlanes ();
209  void SetExplodeFactor (G4double explodeFactor);
210  void UnsetExplodeFactor ();
211  void SetExplodeCentre (const G4Point3D& explodeCentre);
212  G4int SetNoOfSides (G4int nSides); // Returns actual number set.
213  void SetViewpointDirection (const G4Vector3D& viewpointDirection);
214  // Calls the following to get lightpoint direction right too.
215  void SetViewAndLights (const G4Vector3D& viewpointDirection);
216  // Also sets lightpoint direction according to G4bool fLightsMoveWithCamera.
217  void SetUpVector (const G4Vector3D& upVector);
218  void SetFieldHalfAngle (G4double fieldHalfAngle);
219  void SetOrthogonalProjection (); // This and next use SetFieldHalfAngle.
220  void SetPerspectiveProjection(G4double fieldHalfAngle = 30. * CLHEP::deg);
221  void SetZoomFactor (G4double zoomFactor);
222  void MultiplyZoomFactor (G4double zoomFactorMultiplier);
223  void SetScaleFactor (const G4Vector3D& scaleFactor);
224  void MultiplyScaleFactor (const G4Vector3D& scaleFactorMultiplier);
225  void SetCurrentTargetPoint (const G4Point3D& currentTargetPoint);
226  void SetDolly (G4double dolly);
227  void IncrementDolly (G4double dollyIncrement);
228  void SetLightpointDirection (const G4Vector3D& lightpointDirection);
229  void SetLightsMoveWithCamera (G4bool moves);
230  void SetPan (G4double right, G4double up);
231  void IncrementPan (G4double right, G4double up);
232  // Increment currentTarget point perpendicular to viewpoint direction.
233  void IncrementPan (G4double right, G4double up, G4double forward);
234  // Increment currentTarget point also along viewpoint direction.
236  void SetDefaultColour (const G4Colour&); // Uses SetDefaultVisAttributes.
238  void SetDefaultTextColour (const G4Colour&); // SetDefaultTextVisAttributes.
239  void SetDefaultMarker (const G4VMarker& defaultMarker);
240  void SetGlobalMarkerScale (G4double globalMarkerScale);
241  void SetGlobalLineWidthScale (G4double globalLineWidthScale);
242  void SetMarkerHidden ();
243  void SetMarkerNotHidden ();
244  void SetWindowSizeHint (G4int xHint, G4int yHint);
245  void SetWindowLocationHint (G4int xHint, G4int yHint);
246  void SetXGeometryString (const G4String&);
247  void SetAutoRefresh (G4bool);
248  void SetBackgroundColour (const G4Colour&);
249  void SetPicking (G4bool);
253 
254  // Command dumping functions.
255  // For camera commands we need to provide the standard target point from
256  // the current scene.
257  G4String CameraAndLightingCommands(const G4Point3D standardTargetPoint) const;
260  G4String TouchableCommands () const;
261 
262  // Other functions.
263  void PrintDifferences (const G4ViewParameters& v) const;
264 
265 private:
266 
267  G4int ParseGeometry ( const char *string, G4int *x, G4int *y, unsigned int *width, unsigned int *height);
268  G4int ReadInteger(char *string, char **NextString);
269 
270  DrawingStyle fDrawingStyle; // Drawing style.
271  G4bool fAuxEdgeVisible; // Auxiliary edge visibility.
272  G4bool fCulling; // Culling requested.
273  G4bool fCullInvisible; // Cull (don't Draw) invisible objects.
274  G4bool fDensityCulling; // Density culling requested. If so...
275  G4double fVisibleDensity; // ...density lower than this not drawn.
276  G4bool fCullCovered; // Cull daughters covered by opaque mothers.
277  G4bool fSection; // Section drawing requested (DCUT in GEANT3).
278  G4Plane3D fSectionPlane; // Cut plane for section drawing (DCUT).
279  CutawayMode fCutawayMode; // Cutaway mode.
280  G4Planes fCutawayPlanes; // Set of planes used for cutaway.
281  G4double fExplodeFactor; // Explode along radius by this factor...
282  G4Point3D fExplodeCentre; // ...about this centre.
283  G4int fNoOfSides; // ...if polygon approximates circle.
285  G4Vector3D fUpVector; // Up vector. (Warning: MUST NOT be parallel
286  // to fViewpointDirection!)
287  G4double fFieldHalfAngle; // Radius / camara distance, 0 for parallel.
288  G4double fZoomFactor; // Magnification relative to Standard View.
289  G4Vector3D fScaleFactor; // (Non-uniform) scale/magnification factor.
290  G4Point3D fCurrentTargetPoint; // Relative to standard target point.
291  G4double fDolly; // Distance towards current target point.
294  // i.e., rel. to object or camera accoding to G4bool fLightsMoveWithCamera.
302  // True if transients are to be drawn and not hidden by
303  // hidden-line-hidden-surface removal algorithms, e.g., z-buffer
304  // testing; false if they are to be hidden-line-hidden-surface
305  // removed.
306  G4int fWindowSizeHintX; // Size hints for pixel-based window systems.
308  G4int fWindowLocationHintX; // Location hints for pixel-based window systems.
310  G4bool fWindowLocationHintXNegative; // Reference of location hints for pixel-based window systems.
312  G4String fXGeometryString; // If non-null, geometry string for X Windows.
313  G4int fGeometryMask; // Corresponding mask.
314  G4bool fAutoRefresh; // ...after change of view parameters.
316  G4bool fPicking; // Request picking.
317  RotationStyle fRotationStyle; // Rotation style.
318  std::vector<G4ModelingParameters::VisAttributesModifier>
320 
321  enum { // Constants for geometry mask in ParseGeometry and related functions.
322  fNoValue = 0,
323  fXValue = 0x0001,
324  fYValue = 0x0002,
325  fWidthValue = 0x0004,
326  fHeightValue = 0x0008,
327  fAllValues = 0x000F,
328  fXNegative = 0x0010,
329  fYNegative = 0x0020
330  };
331 };
332 
333 #include "G4ViewParameters.icc"
334 
335 #endif
bool IsWindowSizeHintY() const
G4String TouchableCommands() const
void SetOrthogonalProjection()
void SetMarkerNotHidden()
G4double GetZoomFactor() const
void IncrementPan(G4double right, G4double up)
void ClearCutawayPlanes()
const G4Colour & GetBackgroundColour() const
G4Vector3D & GetActualLightpointDirection()
bool IsWindowSizeHintX() const
void AddCutawayPlane(const G4Plane3D &cutawayPlane)
G4double GetDolly() const
void SetLightpointDirection(const G4Vector3D &lightpointDirection)
G4double GetVisibleDensity() const
void SetPan(G4double right, G4double up)
void SetScaleFactor(const G4Vector3D &scaleFactor)
void SetAuxEdgeVisible(G4bool)
G4int SetNoOfSides(G4int nSides)
G4int GetWindowAbsoluteLocationHintX(G4int) const
void SetRotationStyle(RotationStyle)
const G4Point3D & GetExplodeCentre() const
void SetPicking(G4bool)
G4bool IsCullingInvisible() const
G4bool operator!=(const G4ViewParameters &) const
G4double GetExplodeFactor() const
CutawayMode fCutawayMode
G4int GetWindowAbsoluteLocationHintY(G4int) const
G4int GetWindowLocationHintY() const
void SetUpVector(const G4Vector3D &upVector)
G4bool IsDensityCulling() const
#define width
G4String SceneModifyingCommands() const
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:35
const G4Planes & GetCutawayPlanes() const
G4int ReadInteger(char *string, char **NextString)
void SetDefaultColour(const G4Colour &)
void SetDensityCulling(G4bool)
G4int GetWindowLocationHintX() const
G4double GetFarDistance(G4double cameraDistance, G4double nearDistance, G4double radius) const
void SetVisibleDensity(G4double visibleDensity)
int G4int
Definition: G4Types.hh:78
void SetDefaultTextVisAttributes(const G4VisAttributes &)
void SetBackgroundColour(const G4Colour &)
G4double GetCameraDistance(G4double radius) const
void SetCutawayMode(CutawayMode)
void SetLightsMoveWithCamera(G4bool moves)
void SetViewAndLights(const G4Vector3D &viewpointDirection)
const G4Point3D & GetCurrentTargetPoint() const
void UnsetExplodeFactor()
G4double GetNearDistance(G4double cameraDistance, G4double radius) const
const G4Vector3D & GetLightpointDirection() const
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
const G4String & GetXGeometryString() const
unsigned int GetWindowSizeHintX() const
const G4Vector3D & GetViewpointDirection() const
void SetPerspectiveProjection(G4double fieldHalfAngle=30.*CLHEP::deg)
void SetExplodeFactor(G4double explodeFactor)
G4bool IsAuxEdgeVisible() const
void SetWindowLocationHint(G4int xHint, G4int yHint)
void SetZoomFactor(G4double zoomFactor)
void ChangeCutawayPlane(size_t index, const G4Plane3D &cutawayPlane)
void SetGlobalMarkerScale(G4double globalMarkerScale)
G4Point3D fCurrentTargetPoint
static const double deg
Definition: G4SIunits.hh:133
void SetDefaultMarker(const G4VMarker &defaultMarker)
bool G4bool
Definition: G4Types.hh:79
std::vector< G4Plane3D > G4Planes
G4double GetFrontHalfHeight(G4double nearDistance, G4double radius) const
void SetCurrentTargetPoint(const G4Point3D &currentTargetPoint)
void SetDolly(G4double dolly)
bool IsWindowLocationHintX() const
void SetXGeometryString(const G4String &)
RotationStyle GetRotationStyle() const
void SetDefaultVisAttributes(const G4VisAttributes &)
void SetFieldHalfAngle(G4double fieldHalfAngle)
CutawayMode GetCutawayMode() const
G4bool IsCullingCovered() const
G4VisAttributes fDefaultVisAttributes
void SetExplodeCentre(const G4Point3D &explodeCentre)
G4double GetGlobalLineWidthScale() const
unsigned int GetWindowSizeHintY() const
G4String DrawingStyleCommands() const
const G4VisAttributes * GetDefaultTextVisAttributes() const
void SetMarkerHidden()
void SetCullingInvisible(G4bool)
G4bool IsExplode() const
G4double fGlobalLineWidthScale
void PrintDifferences(const G4ViewParameters &v) const
G4bool IsSection() const
G4bool IsCutaway() const
void SetAutoRefresh(G4bool)
G4bool IsMarkerNotHidden() const
void MultiplyZoomFactor(G4double zoomFactorMultiplier)
void AddVisAttributesModifier(const G4ModelingParameters::VisAttributesModifier &)
G4Vector3D fRelativeLightpointDirection
void SetDrawingStyle(G4ViewParameters::DrawingStyle style)
const G4VMarker & GetDefaultMarker() const
const G4Vector3D & GetScaleFactor() const
G4int GetNoOfSides() const
void UnsetSectionPlane()
G4bool fWindowLocationHintYNegative
RotationStyle fRotationStyle
DrawingStyle GetDrawingStyle() const
void SetGlobalLineWidthScale(G4double globalLineWidthScale)
G4bool IsPicking() const
HepGeom::Plane3D< G4double > G4Plane3D
Definition: G4Plane3D.hh:37
G4String CameraAndLightingCommands(const G4Point3D standardTargetPoint) const
G4bool GetLightsMoveWithCamera() const
const G4Plane3D & GetSectionPlane() const
G4Vector3D fViewpointDirection
G4double GetFieldHalfAngle() const
void SetWindowSizeHint(G4int xHint, G4int yHint)
void MultiplyScaleFactor(const G4Vector3D &scaleFactorMultiplier)
const G4VisAttributes * GetDefaultVisAttributes() const
double G4double
Definition: G4Types.hh:76
G4bool fWindowLocationHintXNegative
G4VisAttributes fDefaultTextVisAttributes
G4int ParseGeometry(const char *string, G4int *x, G4int *y, unsigned int *width, unsigned int *height)
void SetSectionPlane(const G4Plane3D &sectionPlane)
const G4Vector3D & GetUpVector() const
bool IsWindowLocationHintY() const
friend std::ostream & operator<<(std::ostream &, const DrawingStyle &)
void SetCulling(G4bool)
G4bool IsCulling() const
G4bool IsAutoRefresh() const
void SetCullingCovered(G4bool)
void IncrementDolly(G4double dollyIncrement)
G4Vector3D fActualLightpointDirection
void SetViewpointDirection(const G4Vector3D &viewpointDirection)
std::vector< G4ModelingParameters::VisAttributesModifier > fVisAttributesModifiers
DrawingStyle fDrawingStyle
G4double GetGlobalMarkerScale() const
void SetDefaultTextColour(const G4Colour &)