G4ViewParameters.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // John Allison  19th July 1996
00031 //
00032 // Class description
00033 //
00034 // View parameters and options.
00035 //
00036 // THE STANDARD VIEW AND ALL THAT.
00037 //
00038 // In GEANT4 visualization, we have the concept of a "Standard
00039 // View".  This is the view when the complete set of objects being
00040 // viewed is comfortably in view from any viewpoint.  It is defined by
00041 // the "Bounding Sphere" of "visible" objects when initially
00042 // registered in the scene, and by the View Parameters.
00043 //
00044 // There is also the "Standard Target Point", which is the centre of
00045 // the Bounding Sphere (note that this belongs to the scene and is
00046 // stored in the G4Scene object).  The "Current Target Point", defined
00047 // relative to the Standard Target Point, is changed by the
00048 // "dolly" and "zoom" commands, and can be reset to the Standard
00049 // Target Point with the "/vis/viewer/reset" command.
00050 //
00051 // Also, the "Standard Camera Position" is the "Standard Camera
00052 // Distance" along the Viewpoint Direction vector from the Standard
00053 // Target Point.  The Standard Camera Distance is the radius of the
00054 // Bounding Sphere divided by fFieldHalfAngle.  It is not stored
00055 // explicitly because of the singularity at fFieldHalfAngle = 0,
00056 // which implies parallel projection.
00057 //
00058 // Similarly, the "Current Camera Position" is the "Current Camera
00059 // Distance" along the Viewpoint Direction vector from the Current
00060 // Target Point.  The Current Camera Distance is given by the formulae
00061 // below, but note that it can be negative, meaning that the camera
00062 // has moved *beyond* the Current Target Point, which is
00063 // conceptually possible, but which might give some problems when
00064 // setting up the view matrix - see, for example, G4OpenGLView::SetView ().
00065 //
00066 // All viewers are expected to keep the "Up Vector" vertical.
00067 //
00068 // Finally, the view is magnified by the "Zoom Factor" which is
00069 // reset to 1 by the "/vis/viewer/reset" command.
00070 //
00071 // The algorithms for calculating various useful quantities from the
00072 // View Parameters, such as GetCameraDistance, are described below.
00073 
00074 #ifndef G4VIEWPARAMETERS_HH
00075 #define G4VIEWPARAMETERS_HH
00076 
00077 #include <CLHEP/Units/SystemOfUnits.h>
00078 #include "G4Vector3D.hh"
00079 #include "G4Point3D.hh"
00080 #include "G4Plane3D.hh"
00081 #include "G4VisAttributes.hh"
00082 #include "G4VMarker.hh"
00083 #include "G4ModelingParameters.hh"
00084 
00085 #include <vector>
00086 #include <utility>
00087 
00088 typedef std::vector<G4Plane3D> G4Planes;
00089 
00090 class G4ViewParameters {
00091 
00092 public: // With description
00093 
00094   enum DrawingStyle {
00095     wireframe,  // Draw edges    - no hidden line removal.
00096     hlr,        // Draw edges    - hidden lines removed.
00097     hsr,        // Draw surfaces - hidden surfaces removed.
00098     hlhsr       // Draw surfaces and edges - hidden removed.
00099   };
00100 
00101   enum RepStyle {
00102     polyhedron, // Use G4Polyhedron.
00103     nurbs       // Use G4NURBS.
00104   };
00105 
00106   enum CutawayMode {
00107     cutawayUnion,       // Union (addition) of result of each cutaway plane.
00108     cutawayIntersection // Intersection (multiplication) " .
00109   };
00110 
00111   enum RotationStyle {
00112     constrainUpDirection,  // Standard, HEP convention.
00113     freeRotation           // Free, Google-like rotation, using mouse-grab.
00114   };
00115 
00116   friend std::ostream& operator << (std::ostream&,
00117                                       const DrawingStyle&);
00118 
00119   friend std::ostream& operator << (std::ostream&,
00120                                       const G4ViewParameters&);
00121 
00122   G4ViewParameters ();
00123   ~G4ViewParameters ();
00124 
00125   // Note: uses default assignment operator and copy constructor.
00126 
00127   G4bool operator != (const G4ViewParameters&) const;
00128 
00129   // Get and Is functions.
00130         DrawingStyle     GetDrawingStyle         () const;
00131         G4bool           IsAuxEdgeVisible        () const;
00132         RepStyle         GetRepStyle             () const;
00133         G4bool           IsCulling               () const;
00134         G4bool           IsCullingInvisible      () const;
00135         G4bool           IsDensityCulling        () const;
00136         G4double         GetVisibleDensity       () const;
00137         G4bool           IsCullingCovered        () const;
00138         G4bool           IsSection               () const;
00139   const G4Plane3D&       GetSectionPlane         () const;
00140         G4bool           IsCutaway               () const;
00141         CutawayMode      GetCutawayMode          () const;
00142   const G4Planes&        GetCutawayPlanes        () const;
00143         G4bool           IsExplode               () const;
00144         G4double         GetExplodeFactor        () const;
00145   const G4Point3D&       GetExplodeCentre        () const;
00146         G4int            GetNoOfSides            () const;
00147   const G4Vector3D&      GetViewpointDirection   () const;
00148   const G4Vector3D&      GetUpVector             () const;
00149         G4double         GetFieldHalfAngle       () const;
00150         G4double         GetZoomFactor           () const;
00151   const G4Vector3D&      GetScaleFactor          () const;
00152   const G4Point3D&       GetCurrentTargetPoint   () const;
00153         G4double         GetDolly                () const;
00154         G4bool           GetLightsMoveWithCamera () const;
00155   const G4Vector3D&      GetLightpointDirection  () const;  // Relative...
00156         G4Vector3D&      GetActualLightpointDirection  ();  // Actual...
00157   // ... depending on GetLightsMoveWithCamera.
00158   const G4VisAttributes* GetDefaultVisAttributes () const;
00159   const G4VisAttributes* GetDefaultTextVisAttributes () const;
00160   const G4VMarker&       GetDefaultMarker        () const;
00161         G4double         GetGlobalMarkerScale    () const;
00162         G4double         GetGlobalLineWidthScale () const;
00163         G4bool           IsMarkerNotHidden       () const;
00164         unsigned int     GetWindowSizeHintX      () const;
00165         unsigned int     GetWindowSizeHintY      () const;
00166         G4int            GetWindowAbsoluteLocationHintX (G4int) const;
00167         G4int            GetWindowAbsoluteLocationHintY (G4int) const;
00168         G4int            GetWindowLocationHintX  () const;
00169         G4int            GetWindowLocationHintY  () const;
00170   const G4String&        GetXGeometryString      () const;
00171   // GetXGeometryString is intended to be parsed by XParseGeometry.
00172   // It contains the size information, as in GetWindowSizeHint, but
00173   // may also contain the window position, e.g., "600x600-0+200.  The
00174   // viewer should use this in preference to GetWindowSizeHint, since
00175   // it contains more information.  (The size information in
00176   // GetXGeometryString and GetWindowSizeHint is guaranteed to be
00177   // identical.)
00178         bool             IsWindowSizeHintX       () const;
00179         bool             IsWindowSizeHintY       () const;
00180         bool             IsWindowLocationHintX   () const;
00181         bool             IsWindowLocationHintY   () const;
00182         G4bool           IsAutoRefresh           () const;
00183   const G4Colour&  GetBackgroundColour           () const;
00184         G4bool           IsPicking               () const;
00185         RotationStyle    GetRotationStyle        () const;
00186   const std::vector<G4ModelingParameters::VisAttributesModifier>&
00187                          GetVisAttributesModifiers () const;
00188   
00189   // Here Follow functions to evaluate useful quantities as a
00190   // function of the radius of the Bounding Sphere of the object being
00191   // viewed.  Call them in the order given - for efficiency, later
00192   // functions depend on the results of earlier ones (Store the
00193   // results of earlier functions in your own temporary variables -
00194   // see, for example, G4OpenGLView::SetView ().)
00195   G4double GetCameraDistance  (G4double radius) const;
00196   G4double GetNearDistance    (G4double cameraDistance, G4double radius) const;
00197   G4double GetFarDistance     (G4double cameraDistance,
00198                                G4double nearDistance, G4double radius) const;
00199   G4double GetFrontHalfHeight (G4double nearDistance, G4double radius) const;
00200 
00201   // Set, Add, Multiply, Increment, Unset and Clear functions.
00202   void SetDrawingStyle         (G4ViewParameters::DrawingStyle style);
00203   void SetAuxEdgeVisible       (G4bool);
00204   void SetRepStyle             (G4ViewParameters::RepStyle style);
00205   void SetCulling              (G4bool);
00206   void SetCullingInvisible     (G4bool);
00207   void SetDensityCulling       (G4bool);
00208   void SetVisibleDensity       (G4double visibleDensity);
00209   void SetCullingCovered       (G4bool);
00210   void SetSectionPlane         (const G4Plane3D& sectionPlane);
00211   void UnsetSectionPlane       ();
00212   void SetCutawayMode          (CutawayMode);
00213   void AddCutawayPlane         (const G4Plane3D& cutawayPlane);
00214   void ChangeCutawayPlane      (size_t index, const G4Plane3D& cutawayPlane);
00215   void ClearCutawayPlanes      ();
00216   void SetExplodeFactor        (G4double explodeFactor);
00217   void UnsetExplodeFactor      ();
00218   void SetExplodeCentre        (const G4Point3D& explodeCentre);
00219   G4int SetNoOfSides           (G4int nSides);  // Returns actual number set.
00220   void SetViewpointDirection   (const G4Vector3D& viewpointDirection);
00221   // Calls the following to get lightpoint direction right too.
00222   void SetViewAndLights        (const G4Vector3D& viewpointDirection);
00223   // Also sets lightpoint direction according to G4bool fLightsMoveWithCamera.
00224   void SetUpVector             (const G4Vector3D& upVector);
00225   void SetFieldHalfAngle       (G4double fieldHalfAngle);
00226   void SetOrthogonalProjection ();  // This and next use SetFieldHalfAngle.
00227   void SetPerspectiveProjection(G4double fieldHalfAngle = 30. * CLHEP::deg);
00228   void SetZoomFactor           (G4double zoomFactor);
00229   void MultiplyZoomFactor      (G4double zoomFactorMultiplier);
00230   void SetScaleFactor          (const G4Vector3D& scaleFactor);
00231   void MultiplyScaleFactor     (const G4Vector3D& scaleFactorMultiplier);
00232   void SetCurrentTargetPoint   (const G4Point3D& currentTargetPoint);
00233   void SetDolly                (G4double dolly);
00234   void IncrementDolly          (G4double dollyIncrement);
00235   void SetLightpointDirection  (const G4Vector3D& lightpointDirection);
00236   void SetLightsMoveWithCamera (G4bool moves);
00237   void SetPan                  (G4double right, G4double up);
00238   void IncrementPan            (G4double right, G4double up);
00239   // Increment currentTarget point perpendicular to viewpoint direction.
00240   void IncrementPan            (G4double right, G4double up, G4double forward);
00241   // Increment currentTarget point also along viewpoint direction.
00242   void SetDefaultVisAttributes (const G4VisAttributes&);
00243   void SetDefaultColour        (const G4Colour&);  // Uses SetDefaultVisAttributes.
00244   void SetDefaultTextVisAttributes (const G4VisAttributes&);
00245   void SetDefaultTextColour    (const G4Colour&);  // SetDefaultTextVisAttributes.
00246   void SetDefaultMarker        (const G4VMarker& defaultMarker);
00247   void SetGlobalMarkerScale    (G4double globalMarkerScale);
00248   void SetGlobalLineWidthScale (G4double globalLineWidthScale);
00249   void SetMarkerHidden         ();
00250   void SetMarkerNotHidden      ();
00251   void SetWindowSizeHint       (G4int xHint, G4int yHint);
00252   void SetWindowLocationHint   (G4int xHint, G4int yHint);
00253   void SetXGeometryString      (const G4String&);
00254   void SetAutoRefresh          (G4bool);
00255   void SetBackgroundColour     (const G4Colour&);
00256   void SetPicking              (G4bool);
00257   void SetRotationStyle        (RotationStyle);
00258   void AddVisAttributesModifier
00259   (const G4ModelingParameters::VisAttributesModifier&);
00260 
00261   // Command dumping functions.
00262   // For camera commands we need to provide the standard target point from
00263   // the current scene.
00264   G4String CameraAndLightingCommands(const G4Point3D standardTargetPoint) const;
00265   G4String DrawingStyleCommands  () const;
00266   G4String SceneModifyingCommands() const;
00267   G4String TouchableCommands     () const;
00268   
00269   // Other functions.
00270   void PrintDifferences (const G4ViewParameters& v) const;
00271 
00272 private:
00273   
00274   G4int ParseGeometry ( const char *string, G4int *x, G4int *y, unsigned int *width, unsigned int *height);
00275   G4int ReadInteger(char *string, char **NextString);
00276 
00277   DrawingStyle fDrawingStyle;    // Drawing style.
00278   G4bool       fAuxEdgeVisible;  // Auxiliary edge visibility.
00279   RepStyle     fRepStyle;        // Representation style.
00280   G4bool       fCulling;         // Culling requested.
00281   G4bool       fCullInvisible;   // Cull (don't Draw) invisible objects.
00282   G4bool       fDensityCulling;  // Density culling requested.  If so...
00283   G4double     fVisibleDensity;  // ...density lower than this not drawn.
00284   G4bool       fCullCovered;     // Cull daughters covered by opaque mothers.
00285   G4bool       fSection;         // Section drawing requested (DCUT in GEANT3).
00286   G4Plane3D    fSectionPlane;    // Cut plane for section drawing (DCUT).
00287   CutawayMode  fCutawayMode;     // Cutaway mode.
00288   G4Planes     fCutawayPlanes;   // Set of planes used for cutaway.
00289   G4double     fExplodeFactor;   // Explode along radius by this factor...
00290   G4Point3D    fExplodeCentre;   // ...about this centre.
00291   G4int        fNoOfSides;       // ...if polygon approximates circle.
00292   G4Vector3D   fViewpointDirection;
00293   G4Vector3D   fUpVector;        // Up vector.  (Warning: MUST NOT be parallel
00294                                  // to fViewpointDirection!)
00295   G4double     fFieldHalfAngle;  // Radius / camara distance, 0 for parallel.
00296   G4double     fZoomFactor;      // Magnification relative to Standard View.
00297   G4Vector3D   fScaleFactor;     // (Non-uniform) scale/magnification factor.
00298   G4Point3D    fCurrentTargetPoint;  // Relative to standard target point.
00299   G4double     fDolly;           // Distance towards current target point.
00300   G4bool       fLightsMoveWithCamera;
00301   G4Vector3D   fRelativeLightpointDirection;
00302   // i.e., rel. to object or camera accoding to G4bool fLightsMoveWithCamera.
00303   G4Vector3D   fActualLightpointDirection;
00304   G4VisAttributes fDefaultVisAttributes;
00305   G4VisAttributes fDefaultTextVisAttributes;
00306   G4VMarker    fDefaultMarker;
00307   G4double     fGlobalMarkerScale;
00308   G4double     fGlobalLineWidthScale;
00309   G4bool       fMarkerNotHidden;
00310   // True if transients are to be drawn and not hidden by
00311   // hidden-line-hidden-surface removal algorithms, e.g., z-buffer
00312   // testing; false if they are to be hidden-line-hidden-surface
00313   // removed.
00314   G4int        fWindowSizeHintX; // Size hints for pixel-based window systems.
00315   G4int        fWindowSizeHintY;
00316   G4int        fWindowLocationHintX; // Location hints for pixel-based window systems.
00317   G4int        fWindowLocationHintY;
00318   G4bool       fWindowLocationHintXNegative; //  Reference of location hints for pixel-based window systems.
00319   G4bool       fWindowLocationHintYNegative;
00320   G4String     fXGeometryString; // If non-null, geometry string for X Windows.
00321   G4int        fGeometryMask;    // Corresponding mask.
00322   G4bool       fAutoRefresh;     // ...after change of view parameters.
00323   G4Colour     fBackgroundColour;
00324   G4bool       fPicking;         // Request picking.
00325   RotationStyle fRotationStyle;  // Rotation style.
00326   std::vector<G4ModelingParameters::VisAttributesModifier>
00327   fVisAttributesModifiers;
00328 
00329   enum { // Constants for geometry mask in ParseGeometry and related functions.
00330     fNoValue     = 0,
00331     fXValue      = 0x0001,
00332     fYValue      = 0x0002,
00333     fWidthValue  = 0x0004,
00334     fHeightValue = 0x0008,
00335     fAllValues   = 0x000F,
00336     fXNegative   = 0x0010,
00337     fYNegative   = 0x0020
00338   };
00339 };
00340 
00341 #include "G4ViewParameters.icc"
00342 
00343 #endif

Generated on Mon May 27 17:50:14 2013 for Geant4 by  doxygen 1.4.7