Geant4  10.03.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: G4ViewParameters.hh 99418 2016-09-21 09:18:42Z 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 
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 <<
112  (std::ostream&, const DrawingStyle&);
113 
114  friend std::ostream& operator <<
115  (std::ostream&, 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  // Interpolation
266  // Returns a null pointer when no more to be done. For example:
267  // do {
268  // G4ViewParameters* vp =
269  // G4ViewParameters::CatmullRomCubicSplineInterpolation(viewVector,nInterpolationPoints);
270  // if (!vp) break;
271  // ...
272  // } while (true);
273  // Assumes equal intervals
275  (const std::vector<G4ViewParameters>& views,
276  G4int nInterpolationPoints = 50); // No of interpolations points per interval
277 
278 private:
279 
280  G4int ParseGeometry ( const char *string, G4int *x, G4int *y, unsigned int *width, unsigned int *height);
281  G4int ReadInteger(char *string, char **NextString);
282 
283  DrawingStyle fDrawingStyle; // Drawing style.
284  G4bool fAuxEdgeVisible; // Auxiliary edge visibility.
285  G4bool fCulling; // Culling requested.
286  G4bool fCullInvisible; // Cull (don't Draw) invisible objects.
287  G4bool fDensityCulling; // Density culling requested. If so...
288  G4double fVisibleDensity; // ...density lower than this not drawn.
289  G4bool fCullCovered; // Cull daughters covered by opaque mothers.
290  G4bool fSection; // Section drawing requested (DCUT in GEANT3).
291  G4Plane3D fSectionPlane; // Cut plane for section drawing (DCUT).
292  CutawayMode fCutawayMode; // Cutaway mode.
293  G4Planes fCutawayPlanes; // Set of planes used for cutaway.
294  G4double fExplodeFactor; // Explode along radius by this factor...
295  G4Point3D fExplodeCentre; // ...about this centre.
296  G4int fNoOfSides; // ...if polygon approximates circle.
297  G4Vector3D fViewpointDirection;
298  G4Vector3D fUpVector; // Up vector. (Warning: MUST NOT be parallel
299  // to fViewpointDirection!)
300  G4double fFieldHalfAngle; // Radius / camara distance, 0 for parallel.
301  G4double fZoomFactor; // Magnification relative to Standard View.
302  G4Vector3D fScaleFactor; // (Non-uniform) scale/magnification factor.
303  G4Point3D fCurrentTargetPoint; // Relative to standard target point.
304  G4double fDolly; // Distance towards current target point.
305  G4bool fLightsMoveWithCamera;
306  G4Vector3D fRelativeLightpointDirection;
307  // i.e., rel. to object or camera accoding to G4bool fLightsMoveWithCamera.
308  G4Vector3D fActualLightpointDirection;
309  G4VisAttributes fDefaultVisAttributes;
310  G4VisAttributes fDefaultTextVisAttributes;
311  G4VMarker fDefaultMarker;
312  G4double fGlobalMarkerScale;
313  G4double fGlobalLineWidthScale;
314  G4bool fMarkerNotHidden;
315  // True if transients are to be drawn and not hidden by
316  // hidden-line-hidden-surface removal algorithms, e.g., z-buffer
317  // testing; false if they are to be hidden-line-hidden-surface
318  // removed.
319  G4int fWindowSizeHintX; // Size hints for pixel-based window systems.
320  G4int fWindowSizeHintY;
321  G4int fWindowLocationHintX; // Location hints for pixel-based window systems.
322  G4int fWindowLocationHintY;
323  G4bool fWindowLocationHintXNegative; // Reference of location hints for pixel-based window systems.
324  G4bool fWindowLocationHintYNegative;
325  G4String fXGeometryString; // If non-null, geometry string for X Windows.
326  G4int fGeometryMask; // Corresponding mask.
327  G4bool fAutoRefresh; // ...after change of view parameters.
328  G4Colour fBackgroundColour;
329  G4bool fPicking; // Request picking.
330  RotationStyle fRotationStyle; // Rotation style.
331  std::vector<G4ModelingParameters::VisAttributesModifier> fVisAttributesModifiers;
332 
333  enum { // Constants for geometry mask in ParseGeometry and related functions.
334  fNoValue = 0,
335  fXValue = 0x0001,
336  fYValue = 0x0002,
337  fWidthValue = 0x0004,
338  fHeightValue = 0x0008,
339  fAllValues = 0x000F,
340  fXNegative = 0x0010,
341  fYNegative = 0x0020
342  };
343 };
344 
345 #include "G4ViewParameters.icc"
346 
347 #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
G4int GetWindowAbsoluteLocationHintY(G4int) const
G4int GetWindowLocationHintY() const
void SetUpVector(const G4Vector3D &upVector)
G4bool IsDensityCulling() const
#define width
G4String SceneModifyingCommands() const
const G4Planes & GetCutawayPlanes() const
tuple x
Definition: test.py:50
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 ClearVisAttributesModifiers()
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)
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
void SetExplodeCentre(const G4Point3D &explodeCentre)
G4double GetGlobalLineWidthScale() const
unsigned int GetWindowSizeHintY() const
tuple v
Definition: test.py:18
G4String DrawingStyleCommands() const
const G4VisAttributes * GetDefaultTextVisAttributes() const
void SetMarkerHidden()
void SetCullingInvisible(G4bool)
G4bool IsExplode() const
void PrintDifferences(const G4ViewParameters &v) const
G4bool IsSection() const
G4bool IsCutaway() const
void SetAutoRefresh(G4bool)
static constexpr double deg
G4bool IsMarkerNotHidden() const
void MultiplyZoomFactor(G4double zoomFactorMultiplier)
void AddVisAttributesModifier(const G4ModelingParameters::VisAttributesModifier &)
void SetDrawingStyle(G4ViewParameters::DrawingStyle style)
const G4VMarker & GetDefaultMarker() const
const G4Vector3D & GetScaleFactor() const
G4int GetNoOfSides() const
void UnsetSectionPlane()
DrawingStyle GetDrawingStyle() const
void SetGlobalLineWidthScale(G4double globalLineWidthScale)
G4bool IsPicking() const
G4String CameraAndLightingCommands(const G4Point3D standardTargetPoint) const
G4bool GetLightsMoveWithCamera() const
const G4Plane3D & GetSectionPlane() const
G4double GetFieldHalfAngle() const
void SetWindowSizeHint(G4int xHint, G4int yHint)
void MultiplyScaleFactor(const G4Vector3D &scaleFactorMultiplier)
const G4VisAttributes * GetDefaultVisAttributes() const
double G4double
Definition: G4Types.hh:76
static G4ViewParameters * CatmullRomCubicSplineInterpolation(const std::vector< G4ViewParameters > &views, G4int nInterpolationPoints=50)
void SetSectionPlane(const G4Plane3D &sectionPlane)
const G4Vector3D & GetUpVector() const
bool IsWindowLocationHintY() const
void SetCulling(G4bool)
G4bool IsCulling() const
G4bool IsAutoRefresh() const
void SetCullingCovered(G4bool)
void IncrementDolly(G4double dollyIncrement)
void SetViewpointDirection(const G4Vector3D &viewpointDirection)
G4double GetGlobalMarkerScale() const
void SetDefaultTextColour(const G4Colour &)