Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:22

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         G4double         GetStartTime            () const;
0198         G4double         GetEndTime              () const;
0199         G4double         GetFadeFactor           () const;
0200         G4bool           IsDisplayHeadTime       () const;
0201         G4double         GetDisplayHeadTimeX     () const;
0202         G4double         GetDisplayHeadTimeY     () const;
0203         G4double         GetDisplayHeadTimeSize  () const;
0204         G4double         GetDisplayHeadTimeRed   () const;
0205         G4double         GetDisplayHeadTimeGreen () const;
0206         G4double         GetDisplayHeadTimeBlue  () const;
0207         G4bool           IsDisplayLightFront     () const;
0208         G4double         GetDisplayLightFrontX   () const;
0209         G4double         GetDisplayLightFrontY   () const;
0210         G4double         GetDisplayLightFrontZ   () const;
0211         G4double         GetDisplayLightFrontT   () const;
0212         G4double         GetDisplayLightFrontRed () const;
0213         G4double         GetDisplayLightFrontGreen () const;
0214         G4double         GetDisplayLightFrontBlue () const;
0215         G4bool           IsSpecialMeshRendering  () const;
0216         SMROption        GetSpecialMeshRenderingOption () const;
0217   const std::vector<G4ModelingParameters::PVNameCopyNo>& GetSpecialMeshVolumes() const;
0218 
0219   // Here Follow functions to evaluate useful quantities as a
0220   // function of the radius of the Bounding Extent of the object being
0221   // viewed.  Call them in the order given - for efficiency, later
0222   // functions depend on the results of earlier ones (Store the
0223   // results of earlier functions in your own temporary variables -
0224   // see, for example, G4OpenGLView::SetView ().)
0225   G4double GetCameraDistance  (G4double radius) const;
0226   G4double GetNearDistance    (G4double cameraDistance, G4double radius) const;
0227   G4double GetFarDistance     (G4double cameraDistance,
0228                    G4double nearDistance, G4double radius) const;
0229   G4double GetFrontHalfHeight (G4double nearDistance, G4double radius) const;
0230 
0231   // Set, Add, Multiply, Increment, Unset and Clear functions.
0232   void SetDrawingStyle         (G4ViewParameters::DrawingStyle style);
0233   G4int SetNumberOfCloudPoints (G4int);  // Returns number actually set.
0234   void SetAuxEdgeVisible       (G4bool);
0235   void SetCulling              (G4bool);
0236   void SetCullingInvisible     (G4bool);
0237   void SetDensityCulling       (G4bool);
0238   void SetVisibleDensity       (G4double visibleDensity);
0239   void SetCullingCovered       (G4bool);
0240   void SetCBDAlgorithmNumber   (G4int);
0241   void SetCBDParameters        (const std::vector<G4double>&);
0242   void SetSectionPlane         (const G4Plane3D& sectionPlane);
0243   void UnsetSectionPlane       ();
0244   void SetCutawayMode          (CutawayMode);
0245   void AddCutawayPlane         (const G4Plane3D& cutawayPlane);
0246   void ChangeCutawayPlane      (size_t index, const G4Plane3D& cutawayPlane);
0247   void ClearCutawayPlanes      ();
0248   void SetExplodeFactor        (G4double explodeFactor);
0249   void UnsetExplodeFactor      ();
0250   void SetExplodeCentre        (const G4Point3D& explodeCentre);
0251   G4int SetNoOfSides           (G4int nSides);  // Returns number actually set.
0252   void SetViewpointDirection   (const G4Vector3D& viewpointDirection);
0253   // Calls the following to get lightpoint direction right too.
0254   void SetViewAndLights        (const G4Vector3D& viewpointDirection);
0255   // Also sets lightpoint direction according to G4bool fLightsMoveWithCamera.
0256   void SetUpVector             (const G4Vector3D& upVector);
0257   void SetFieldHalfAngle       (G4double fieldHalfAngle);
0258   void SetOrthogonalProjection ();  // This and next use SetFieldHalfAngle.
0259   void SetPerspectiveProjection(G4double fieldHalfAngle = 30. * CLHEP::deg);
0260   void SetZoomFactor           (G4double zoomFactor);
0261   void MultiplyZoomFactor      (G4double zoomFactorMultiplier);
0262   void SetScaleFactor          (const G4Vector3D& scaleFactor);
0263   void MultiplyScaleFactor     (const G4Vector3D& scaleFactorMultiplier);
0264   void SetCurrentTargetPoint   (const G4Point3D& currentTargetPoint);
0265   void SetDolly                (G4double dolly);
0266   void IncrementDolly          (G4double dollyIncrement);
0267   void SetLightpointDirection  (const G4Vector3D& lightpointDirection);
0268   void SetLightsMoveWithCamera (G4bool moves);
0269   void SetPan                  (G4double right, G4double up);
0270   void IncrementPan            (G4double right, G4double up);
0271   // Increment currentTarget point perpendicular to viewpoint direction.
0272   void IncrementPan            (G4double right, G4double up, G4double forward);
0273   // Increment currentTarget point also along viewpoint direction.
0274   void SetDefaultVisAttributes (const G4VisAttributes&);
0275   void SetDefaultColour        (const G4Colour&);  // Uses SetDefaultVisAttributes.
0276   void SetDefaultTextVisAttributes (const G4VisAttributes&);
0277   void SetDefaultTextColour    (const G4Colour&);  // SetDefaultTextVisAttributes.
0278   void SetDefaultMarker        (const G4VMarker& defaultMarker);
0279   void SetGlobalMarkerScale    (G4double globalMarkerScale);
0280   void SetGlobalLineWidthScale (G4double globalLineWidthScale);
0281   void SetMarkerHidden         ();
0282   void SetMarkerNotHidden      ();
0283   void SetWindowSizeHint       (G4int xHint, G4int yHint);
0284   void SetWindowLocationHint   (G4int xHint, G4int yHint);
0285   void SetXGeometryString      (const G4String&);
0286   void SetAutoRefresh          (G4bool);
0287   void SetBackgroundColour     (const G4Colour&);
0288   void SetPicking              (G4bool);
0289   void SetRotationStyle        (RotationStyle);
0290   void ClearVisAttributesModifiers ();
0291   void AddVisAttributesModifier(const G4ModelingParameters::VisAttributesModifier&);
0292   void SetStartTime            (G4double);
0293   void SetEndTime              (G4double);
0294   void SetFadeFactor           (G4double);
0295   void SetDisplayHeadTime      (G4bool);
0296   void SetDisplayHeadTimeX     (G4double);
0297   void SetDisplayHeadTimeY     (G4double);
0298   void SetDisplayHeadTimeSize  (G4double);
0299   void SetDisplayHeadTimeRed   (G4double);
0300   void SetDisplayHeadTimeGreen (G4double);
0301   void SetDisplayHeadTimeBlue  (G4double);
0302   void SetDisplayLightFront    (G4bool);
0303   void SetDisplayLightFrontX   (G4double);
0304   void SetDisplayLightFrontY   (G4double);
0305   void SetDisplayLightFrontZ   (G4double);
0306   void SetDisplayLightFrontT   (G4double);
0307   void SetDisplayLightFrontRed (G4double);
0308   void SetDisplayLightFrontGreen (G4double);
0309   void SetDisplayLightFrontBlue (G4double);
0310   void SetSpecialMeshRendering (G4bool);
0311   void SetSpecialMeshRenderingOption (SMROption);
0312   void SetSpecialMeshVolumes   (const std::vector<G4ModelingParameters::PVNameCopyNo>&);
0313 
0314   // Command dumping functions.
0315   // For camera commands we need to provide the standard target point from
0316   // the current scene.
0317   G4String CameraAndLightingCommands(const G4Point3D standardTargetPoint) const;
0318   G4String DrawingStyleCommands  () const;
0319   G4String SceneModifyingCommands() const;
0320   G4String TouchableCommands     () const;
0321   G4String TimeWindowCommands    () const;
0322 
0323   // Other functions.
0324   void PrintDifferences (const G4ViewParameters& v) const;
0325 
0326   // Interpolation
0327   // Returns a null pointer when no more to be done.  For example:
0328   // do {
0329   //   G4ViewParameters* vp =
0330   //   G4ViewParameters::CatmullRomCubicSplineInterpolation(viewVector,nInterpolationPoints);
0331   //   if (!vp) break;
0332   //     ...
0333   // } while (true);
0334   // Assumes equal intervals
0335   static G4ViewParameters* CatmullRomCubicSplineInterpolation
0336   (const std::vector<G4ViewParameters>& views,
0337    G4int nInterpolationPoints = 50);  // No of interpolations points per interval
0338 
0339 private:
0340   
0341   G4int ParseGeometry ( const char *string, G4int *x, G4int *y, unsigned int *width, unsigned int *height);
0342   G4int ReadInteger(char *string, char **NextString);
0343 
0344   DrawingStyle fDrawingStyle;    // Drawing style.
0345   G4int        fNumberOfCloudPoints; // For drawing in cloud style.
0346                                      // <= 0 means use viewer default.
0347   G4bool       fAuxEdgeVisible;  // Auxiliary edge visibility.
0348   G4bool       fCulling;         // Culling requested.
0349   G4bool       fCullInvisible;   // Cull (don't Draw) invisible objects.
0350   G4bool       fDensityCulling;  // Density culling requested.  If so...
0351   G4double     fVisibleDensity;  // ...density lower than this not drawn.
0352   G4bool       fCullCovered;     // Cull daughters covered by opaque mothers.
0353   G4int        fCBDAlgorithmNumber; // Colour by density algorithm number.
0354   std::vector<G4double> fCBDParameters; // Colour by density parameters.
0355   G4bool       fSection;         // Section drawing requested (DCUT in GEANT3).
0356   G4Plane3D    fSectionPlane;    // Cut plane for section drawing (DCUT).
0357   CutawayMode  fCutawayMode;     // Cutaway mode.
0358   G4Planes     fCutawayPlanes;   // Set of planes used for cutaway.
0359   G4double     fExplodeFactor;   // Explode along radius by this factor...
0360   G4Point3D    fExplodeCentre;   // ...about this centre.
0361   G4int        fNoOfSides;       // ...if polygon approximates circle.
0362   G4Vector3D   fViewpointDirection;
0363   G4Vector3D   fUpVector;        // Up vector.  (Warning: MUST NOT be parallel
0364                                  // to fViewpointDirection!)
0365   G4double     fFieldHalfAngle;  // Radius / camara distance, 0 for parallel.
0366   G4double     fZoomFactor;      // Magnification relative to Standard View.
0367   G4Vector3D   fScaleFactor;     // (Non-uniform) scale/magnification factor.
0368   G4Point3D    fCurrentTargetPoint;  // Relative to standard target point.
0369   G4double     fDolly;           // Distance towards current target point.
0370   G4bool       fLightsMoveWithCamera;
0371   G4Vector3D   fRelativeLightpointDirection;
0372   // i.e., rel. to object or camera accoding to G4bool fLightsMoveWithCamera.
0373   G4Vector3D   fActualLightpointDirection;
0374   G4VisAttributes fDefaultVisAttributes;
0375   G4VisAttributes fDefaultTextVisAttributes;
0376   G4VMarker    fDefaultMarker;
0377   G4double     fGlobalMarkerScale;
0378   G4double     fGlobalLineWidthScale;
0379   G4bool       fMarkerNotHidden;
0380   // True if transients are to be drawn and not hidden by
0381   // hidden-line-hidden-surface removal algorithms, e.g., z-buffer
0382   // testing; false if they are to be hidden-line-hidden-surface
0383   // removed.
0384   G4int        fWindowSizeHintX; // Size hints for pixel-based window systems.
0385   G4int        fWindowSizeHintY;
0386   G4int        fWindowLocationHintX; // Location hints for pixel-based window systems.
0387   G4int        fWindowLocationHintY;
0388   G4bool       fWindowLocationHintXNegative; //  Reference of location hints for pixel-based window systems.
0389   G4bool       fWindowLocationHintYNegative;
0390   G4String     fXGeometryString; // If non-null, geometry string for X Windows.
0391   G4int        fGeometryMask;    // Corresponding mask.
0392   G4bool       fAutoRefresh;     // ...after change of view parameters.
0393   G4Colour     fBackgroundColour;
0394   G4bool       fPicking;         // Request picking.
0395   RotationStyle fRotationStyle;  // Rotation style.
0396   std::vector<G4ModelingParameters::VisAttributesModifier> fVisAttributesModifiers;
0397   G4double     fStartTime, fEndTime;  // Time range (e.g., for trajectory steps).
0398   G4double     fFadeFactor;  // 0: no fade; 1: maximum fade with time within range.
0399   G4bool       fDisplayHeadTime;  // Display head time (fEndTime) in 2D text.
0400   G4double     fDisplayHeadTimeX, fDisplayHeadTimeY;  // 2D screen coords.
0401   G4double     fDisplayHeadTimeSize;  // Screen size.
0402   G4double     fDisplayHeadTimeRed, fDisplayHeadTimeGreen, fDisplayHeadTimeBlue;
0403   G4bool       fDisplayLightFront;// Display light front at head time originating at
0404   G4double     fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ,
0405                fDisplayLightFrontT;
0406   G4double     fDisplayLightFrontRed, fDisplayLightFrontGreen, fDisplayLightFrontBlue;
0407   G4bool       fSpecialMeshRendering;  // Request special rendering of parameterised volumes
0408   SMROption    fSpecialMeshRenderingOption;  // Special rendering option
0409   std::vector<G4ModelingParameters::PVNameCopyNo> fSpecialMeshVolumes;  // If empty, all meshes.
0410 
0411   enum { // Constants for geometry mask in ParseGeometry and related functions.
0412     fNoValue     = 0,
0413     fXValue      = 0x0001,
0414     fYValue      = 0x0002,
0415     fWidthValue  = 0x0004,
0416     fHeightValue = 0x0008,
0417     fAllValues   = 0x000F,
0418     fXNegative   = 0x0010,
0419     fYNegative   = 0x0020
0420   };
0421 };
0422 
0423 #include "G4ViewParameters.icc"
0424 
0425 #endif