Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 08:52:18

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 //
0028 // 
0029 // John Allison  19th July 1996
0030 //
0031 // Class description
0032 //
0033 // View parameters and options.
0034 //
0035 // THE STANDARD VIEW AND ALL THAT.
0036 //
0037 // In GEANT4 visualization, we have the concept of a "Standard
0038 // View".  This is the view when the complete set of objects being
0039 // viewed is comfortably in view from any viewpoint.  It is defined by
0040 // the "Bounding Extent" of "visible" objects when initially
0041 // registered in the scene, and by the View Parameters.
0042 //
0043 // There is also the "Standard Target Point", which is the centre of
0044 // the Bounding Extent (note that this belongs to the scene and is
0045 // stored in the G4Scene object).  The "Current Target Point", defined
0046 // relative to the Standard Target Point, is changed by the
0047 // "dolly" and "zoom" commands, and can be reset to the Standard
0048 // Target Point with the "/vis/viewer/reset" command.
0049 //
0050 // Also, the "Standard Camera Position" is the "Standard Camera
0051 // Distance" along the Viewpoint Direction vector from the Standard
0052 // Target Point.  The Standard Camera Distance is the radius of the
0053 // Bounding Extent divided by fFieldHalfAngle.  It is not stored
0054 // explicitly because of the singularity at fFieldHalfAngle = 0,
0055 // which implies parallel projection.
0056 //
0057 // Similarly, the "Current Camera Position" is the "Current Camera
0058 // Distance" along the Viewpoint Direction vector from the Current
0059 // Target Point.  The Current Camera Distance is given by the formulae
0060 // below, but note that it can be negative, meaning that the camera
0061 // has moved *beyond* the Current Target Point, which is
0062 // conceptually possible, but which might give some problems when
0063 // setting up the view matrix - see, for example, G4OpenGLView::SetView ().
0064 //
0065 // All viewers are expected to keep the "Up Vector" vertical unless
0066 // RotationStyle is freeRotation.
0067 //
0068 // Finally, the view is magnified by the "Zoom Factor" which is
0069 // reset to 1 by the "/vis/viewer/reset" command.
0070 //
0071 // The algorithms for calculating various useful quantities from the
0072 // View Parameters, such as GetCameraDistance, are described below.
0073 
0074 #ifndef G4VIEWPARAMETERS_HH
0075 #define G4VIEWPARAMETERS_HH
0076 
0077 #include <CLHEP/Units/SystemOfUnits.h>
0078 #include "G4Vector3D.hh"
0079 #include "G4Point3D.hh"
0080 #include "G4Plane3D.hh"
0081 #include "G4VisAttributes.hh"
0082 #include "G4VMarker.hh"
0083 #include "G4ModelingParameters.hh"
0084 
0085 #include <vector>
0086 #include <utility>
0087 
0088 typedef std::vector<G4Plane3D> G4Planes;
0089 
0090 class G4ViewParameters {
0091 
0092 public: // With description
0093 
0094   enum DrawingStyle {
0095     wireframe,  // Draw edges    - no hidden line removal.
0096     hlr,        // Draw edges    - hidden lines removed.
0097     hsr,        // Draw surfaces - hidden surfaces removed.
0098     hlhsr,      // Draw surfaces and edges - hidden removed.
0099     cloud       // Draw volume as a cloud of dots.
0100   };
0101 
0102   enum CutawayMode {
0103     cutawayUnion,       // Union (addition) of result of each cutaway plane.
0104     cutawayIntersection // Intersection (multiplication).
0105   };
0106 
0107   enum RotationStyle {
0108     constrainUpDirection,  // Standard, HEP convention.
0109     freeRotation           // Free, Google-like rotation, using mouse-grab.
0110   };
0111 
0112   enum SMROption {  // Special Mesh Rendering Option
0113     meshAsDefault,
0114     meshAsDots,
0115     meshAsSurfaces
0116   };
0117 
0118   friend std::ostream& operator <<
0119   (std::ostream&, DrawingStyle);
0120 
0121   friend std::ostream& operator <<
0122   (std::ostream&, SMROption);
0123 
0124   friend std::ostream& operator <<
0125   (std::ostream&, const G4ViewParameters&);
0126 
0127   G4ViewParameters ();
0128   ~G4ViewParameters ();
0129 
0130   // Note: uses default assignment operator and copy constructor.
0131 
0132   G4bool operator != (const G4ViewParameters&) const;
0133 
0134   // Get and Is functions.
0135         DrawingStyle     GetDrawingStyle         () const;
0136         G4int            GetNumberOfCloudPoints  () const;
0137         G4bool           IsAuxEdgeVisible        () const;
0138         G4bool           IsCulling               () const;
0139         G4bool           IsCullingInvisible      () const;
0140         G4bool           IsDensityCulling        () const;
0141         G4double         GetVisibleDensity       () const;
0142         G4bool           IsCullingCovered        () const;
0143         G4int            GetCBDAlgorithmNumber   () const;
0144   const std::vector<G4double>& GetCBDParameters  () const;
0145         G4bool           IsSection               () const;
0146   const G4Plane3D&       GetSectionPlane         () const;
0147         G4bool           IsCutaway               () const;
0148         CutawayMode      GetCutawayMode          () const;
0149   const G4Planes&        GetCutawayPlanes        () const;
0150         G4bool           IsExplode               () const;
0151         G4double         GetExplodeFactor        () const;
0152   const G4Point3D&       GetExplodeCentre        () const;
0153         G4int            GetNoOfSides            () const;
0154   const G4Vector3D&      GetViewpointDirection   () const;
0155   const G4Vector3D&      GetUpVector             () const;
0156         G4double         GetFieldHalfAngle       () const;
0157         G4double         GetZoomFactor           () const;
0158   const G4Vector3D&      GetScaleFactor          () const;
0159   const G4Point3D&       GetCurrentTargetPoint   () const;
0160         G4double         GetDolly                () const;
0161         G4bool           GetLightsMoveWithCamera () const;
0162   const G4Vector3D&      GetLightpointDirection  () const;  // Relative...
0163         G4Vector3D&      GetActualLightpointDirection  ();  // Actual...
0164   // ... depending on GetLightsMoveWithCamera.
0165   const G4VisAttributes* GetDefaultVisAttributes () const;
0166   const G4VisAttributes* GetDefaultTextVisAttributes () const;
0167   const G4VMarker&       GetDefaultMarker        () const;
0168         G4double         GetGlobalMarkerScale    () const;
0169         G4double         GetGlobalLineWidthScale () const;
0170         G4bool           IsMarkerNotHidden       () const;
0171         unsigned int     GetWindowSizeHintX      () const;
0172         unsigned int     GetWindowSizeHintY      () const;
0173         G4int            GetWindowAbsoluteLocationHintX (G4int) const;
0174         G4int            GetWindowAbsoluteLocationHintY (G4int) const;
0175         G4int            GetWindowLocationHintX  () const;
0176         G4int            GetWindowLocationHintY  () const;
0177         G4bool           IsWindowLocationHintXNegative () const;
0178         G4bool           IsWindowLocationHintYNegative () const;
0179   const G4String&        GetXGeometryString      () const;
0180   // GetXGeometryString is intended to be parsed by XParseGeometry.
0181   // It contains the size information, as in GetWindowSizeHint, but
0182   // may also contain the window position, e.g., "600x600-0+200.  The
0183   // viewer should use this in preference to GetWindowSizeHint, since
0184   // it contains more information.  (The size information in
0185   // GetXGeometryString and GetWindowSizeHint is guaranteed to be
0186   // identical.)
0187         bool             IsWindowSizeHintX       () const;
0188         bool             IsWindowSizeHintY       () const;
0189         bool             IsWindowLocationHintX   () const;
0190         bool             IsWindowLocationHintY   () const;
0191         G4bool           IsAutoRefresh           () const;
0192   const G4Colour&  GetBackgroundColour           () const;
0193         G4bool           IsPicking               () const;
0194         RotationStyle    GetRotationStyle        () const;
0195   const std::vector<G4ModelingParameters::VisAttributesModifier>&
0196                          GetVisAttributesModifiers () const;
0197   const G4ModelingParameters::TimeParameters&
0198                          GetTimeParameters       () const;
0199         G4bool           IsSpecialMeshRendering  () const;
0200         SMROption        GetSpecialMeshRenderingOption () const;
0201   const std::vector<G4ModelingParameters::PVNameCopyNo>& GetSpecialMeshVolumes () const;
0202         G4double         GetTransparencyByDepth  () const;
0203         G4int            GetTransparencyByDepthOption () const;
0204         G4bool           IsZoomToCursor          () const;
0205         G4bool           IsDotsSmooth            () const;
0206         G4double         GetDotsSize             () const;
0207 
0208   // Here Follow functions to evaluate useful quantities as a
0209   // function of the radius of the Bounding Extent of the object being
0210   // viewed.  Call them in the order given - for efficiency, later
0211   // functions depend on the results of earlier ones (Store the
0212   // results of earlier functions in your own temporary variables -
0213   // see, for example, G4OpenGLView::SetView ().)
0214   G4double GetCameraDistance  (G4double radius) const;
0215   G4double GetNearDistance    (G4double cameraDistance, G4double radius) const;
0216   G4double GetFarDistance     (G4double cameraDistance,
0217                    G4double nearDistance, G4double radius) const;
0218   G4double GetFrontHalfHeight (G4double nearDistance, G4double radius) const;
0219 
0220   // Set, Add, Multiply, Increment, Unset and Clear functions.
0221   void SetDrawingStyle         (G4ViewParameters::DrawingStyle style);
0222   G4int SetNumberOfCloudPoints (G4int);  // Returns number actually set.
0223   void SetAuxEdgeVisible       (G4bool);
0224   void SetCulling              (G4bool);
0225   void SetCullingInvisible     (G4bool);
0226   void SetDensityCulling       (G4bool);
0227   void SetVisibleDensity       (G4double visibleDensity);
0228   void SetCullingCovered       (G4bool);
0229   void SetCBDAlgorithmNumber   (G4int);
0230   void SetCBDParameters        (const std::vector<G4double>&);
0231   void SetSectionPlane         (const G4Plane3D& sectionPlane);
0232   void UnsetSectionPlane       ();
0233   void SetCutawayMode          (CutawayMode);
0234   void AddCutawayPlane         (const G4Plane3D& cutawayPlane);
0235   void ChangeCutawayPlane      (size_t index, const G4Plane3D& cutawayPlane);
0236   void ClearCutawayPlanes      ();
0237   void SetExplodeFactor        (G4double explodeFactor);
0238   void UnsetExplodeFactor      ();
0239   void SetExplodeCentre        (const G4Point3D& explodeCentre);
0240   G4int SetNoOfSides           (G4int nSides);  // Returns number actually set.
0241   void SetViewpointDirection   (const G4Vector3D& viewpointDirection);
0242   // Calls the following to get lightpoint direction right too.
0243   void SetViewAndLights        (const G4Vector3D& viewpointDirection);
0244   // Also sets lightpoint direction according to G4bool fLightsMoveWithCamera.
0245   void SetUpVector             (const G4Vector3D& upVector);
0246   void SetFieldHalfAngle       (G4double fieldHalfAngle);
0247   void SetOrthogonalProjection ();  // This and next use SetFieldHalfAngle.
0248   void SetPerspectiveProjection(G4double fieldHalfAngle = 30. * CLHEP::deg);
0249   void SetZoomFactor           (G4double zoomFactor);
0250   void MultiplyZoomFactor      (G4double zoomFactorMultiplier);
0251   void SetScaleFactor          (const G4Vector3D& scaleFactor);
0252   void MultiplyScaleFactor     (const G4Vector3D& scaleFactorMultiplier);
0253   void SetCurrentTargetPoint   (const G4Point3D& currentTargetPoint);
0254   void SetDolly                (G4double dolly);
0255   void IncrementDolly          (G4double dollyIncrement);
0256   void SetLightpointDirection  (const G4Vector3D& lightpointDirection);
0257   void SetLightsMoveWithCamera (G4bool moves);
0258   void SetPan                  (G4double right, G4double up);
0259   void IncrementPan            (G4double right, G4double up);
0260   // Increment currentTarget point perpendicular to viewpoint direction.
0261   void IncrementPan            (G4double right, G4double up, G4double forward);
0262   // Increment currentTarget point also along viewpoint direction.
0263   void SetDefaultVisAttributes (const G4VisAttributes&);
0264   void SetDefaultColour        (const G4Colour&);  // Uses SetDefaultVisAttributes.
0265   void SetDefaultTextVisAttributes (const G4VisAttributes&);
0266   void SetDefaultTextColour    (const G4Colour&);  // SetDefaultTextVisAttributes.
0267   void SetDefaultMarker        (const G4VMarker& defaultMarker);
0268   void SetGlobalMarkerScale    (G4double globalMarkerScale);
0269   void SetGlobalLineWidthScale (G4double globalLineWidthScale);
0270   void SetMarkerHidden         ();
0271   void SetMarkerNotHidden      ();
0272   void SetWindowSizeHint       (G4int xHint, G4int yHint);
0273   void SetWindowLocationHint   (G4int xHint, G4int yHint);
0274   void SetXGeometryString      (const G4String&);
0275   void SetAutoRefresh          (G4bool);
0276   void SetBackgroundColour     (const G4Colour&);
0277   void SetPicking              (G4bool);
0278   void SetRotationStyle        (RotationStyle);
0279   void ClearVisAttributesModifiers ();
0280   void AddVisAttributesModifier(const G4ModelingParameters::VisAttributesModifier&);
0281   void SetTimeParameters       (const G4ModelingParameters::TimeParameters&);
0282   void SetSpecialMeshRendering (G4bool);
0283   void SetSpecialMeshRenderingOption (SMROption);
0284   void SetSpecialMeshVolumes   (const std::vector<G4ModelingParameters::PVNameCopyNo>&);
0285   void SetTransparencyByDepth  (G4double);
0286   void SetTransparencyByDepthOption (G4int);
0287   void SetZoomToCursor         (G4bool);
0288   void SetDotsSmooth           (G4bool);
0289   void SetDotsSize             (G4double);
0290 
0291   // Command dumping functions.
0292   // For camera commands we need to provide the standard target point from
0293   // the current scene.
0294   G4String CameraAndLightingCommands(const G4Point3D standardTargetPoint) const;
0295   G4String DrawingStyleCommands  () const;
0296   G4String SceneModifyingCommands() const;
0297   G4String TouchableCommands     () const;
0298   G4String TimeWindowCommands    () const;
0299 
0300   // Other functions.
0301   void PrintDifferences (const G4ViewParameters& v) const;
0302 
0303   // Interpolation
0304   // Returns a null pointer when no more to be done.  For example:
0305   // do {
0306   //   G4ViewParameters* vp =
0307   //   G4ViewParameters::CatmullRomCubicSplineInterpolation(viewVector,nInterpolationPoints);
0308   //   if (!vp) break;
0309   //     ...
0310   // } while (true);
0311   // Assumes equal intervals
0312   static G4ViewParameters* CatmullRomCubicSplineInterpolation
0313   (const std::vector<G4ViewParameters>& views,
0314    G4int nInterpolationPoints = 50);  // No of interpolations points per interval
0315 
0316 private:
0317   
0318   G4int ParseGeometry ( const char *string, G4int *x, G4int *y, unsigned int *width, unsigned int *height);
0319   G4int ReadInteger(char *string, char **NextString);
0320 
0321   DrawingStyle fDrawingStyle;    // Drawing style.
0322   G4int        fNumberOfCloudPoints; // For drawing in cloud style.
0323                                      // <= 0 means use viewer default.
0324   G4bool       fAuxEdgeVisible;  // Auxiliary edge visibility.
0325   G4bool       fCulling;         // Culling requested.
0326   G4bool       fCullInvisible;   // Cull (don't Draw) invisible objects.
0327   G4bool       fDensityCulling;  // Density culling requested.  If so...
0328   G4double     fVisibleDensity;  // ...density lower than this not drawn.
0329   G4bool       fCullCovered;     // Cull daughters covered by opaque mothers.
0330   G4int        fCBDAlgorithmNumber; // Colour by density algorithm number.
0331   std::vector<G4double> fCBDParameters; // Colour by density parameters.
0332   G4bool       fSection;         // Section drawing requested (DCUT in GEANT3).
0333   G4Plane3D    fSectionPlane;    // Cut plane for section drawing (DCUT).
0334   CutawayMode  fCutawayMode;     // Cutaway mode.
0335   G4Planes     fCutawayPlanes;   // Set of planes used for cutaway.
0336   G4double     fExplodeFactor;   // Explode along radius by this factor...
0337   G4Point3D    fExplodeCentre;   // ...about this centre.
0338   G4int        fNoOfSides;       // ...if polygon approximates circle.
0339   G4Vector3D   fViewpointDirection;
0340   G4Vector3D   fUpVector;        // Up vector.  (Warning: MUST NOT be parallel
0341                                  // to fViewpointDirection!)
0342   G4double     fFieldHalfAngle;  // Radius / camara distance, 0 for parallel.
0343   G4double     fZoomFactor;      // Magnification relative to Standard View.
0344   G4Vector3D   fScaleFactor;     // (Non-uniform) scale/magnification factor.
0345   G4Point3D    fCurrentTargetPoint;  // Relative to standard target point.
0346   G4double     fDolly;           // Distance towards current target point.
0347   G4bool       fLightsMoveWithCamera;
0348   G4Vector3D   fRelativeLightpointDirection;
0349   // i.e., rel. to object or camera accoding to G4bool fLightsMoveWithCamera.
0350   G4Vector3D   fActualLightpointDirection;
0351   G4VisAttributes fDefaultVisAttributes;
0352   G4VisAttributes fDefaultTextVisAttributes;
0353   G4VMarker    fDefaultMarker;
0354   G4double     fGlobalMarkerScale;
0355   G4double     fGlobalLineWidthScale;
0356   G4bool       fMarkerNotHidden;
0357   // True if transients are to be drawn and not hidden by
0358   // hidden-line-hidden-surface removal algorithms, e.g., z-buffer
0359   // testing; false if they are to be hidden-line-hidden-surface
0360   // removed.
0361   G4int        fWindowSizeHintX; // Size hints for pixel-based window systems.
0362   G4int        fWindowSizeHintY;
0363   G4int        fWindowLocationHintX; // Location hints for pixel-based window systems.
0364   G4int        fWindowLocationHintY;
0365   G4bool       fWindowLocationHintXNegative; //  Reference of location hints for pixel-based window systems.
0366   G4bool       fWindowLocationHintYNegative;
0367   G4String     fXGeometryString; // If non-null, geometry string for X Windows.
0368   G4int        fGeometryMask;    // Corresponding mask.
0369   G4bool       fAutoRefresh;     // ...after change of view parameters.
0370   G4Colour     fBackgroundColour;
0371   G4bool       fPicking;         // Request picking.
0372   RotationStyle fRotationStyle;  // Rotation style.
0373   std::vector<G4ModelingParameters::VisAttributesModifier> fVisAttributesModifiers;
0374   G4ModelingParameters::TimeParameters fTimeParameters;  // For time-slicing, etc.
0375   G4bool       fSpecialMeshRendering;  // Request special rendering of parameterised volumes
0376   SMROption    fSpecialMeshRenderingOption;  // Special rendering option
0377   std::vector<G4ModelingParameters::PVNameCopyNo> fSpecialMeshVolumes;  // If empty, all meshes.
0378   G4double     fTransparencyByDepth;  // Transparency ~= (geometry depth) - fTransparencyByDepth
0379   G4int        fTransparencyByDepthOption;  // Its option
0380   G4bool       fZoomToCursor;  // If possible zoom to cursor with mouse wheel
0381   G4bool       fDotsSmooth;  // Use glEnable(GL_POINT_SMOOTH) or equivalent for dots if available
0382   G4double     fDotsSize;  // Size of G4Polymarker::dots
0383 
0384   enum { // Constants for geometry mask in ParseGeometry and related functions.
0385     fNoValue     = 0,
0386     fXValue      = 0x0001,
0387     fYValue      = 0x0002,
0388     fWidthValue  = 0x0004,
0389     fHeightValue = 0x0008,
0390     fAllValues   = 0x000F,
0391     fXNegative   = 0x0010,
0392     fYNegative   = 0x0020
0393   };
0394 };
0395 
0396 #include "G4ViewParameters.icc"
0397 
0398 #endif