ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VViewer.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VViewer.hh
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 //
28 //
29 // John Allison 27th March 1996
30 //
31 // Class description
32 //
33 // Abstract interface class for graphics viewers.
34 
35 #ifndef G4VVIEWER_HH
36 #define G4VVIEWER_HH
37 
38 #include "globals.hh"
39 
40 #include "G4ViewParameters.hh"
41 #include "G4PhysicalVolumeModel.hh"
42 
43 class G4VSceneHandler;
44 
45 class G4VViewer {
46 
47 public: // With description
48 
49  friend std::ostream& operator << (std::ostream& os, const G4VViewer& v);
50 
51  G4VViewer (G4VSceneHandler&, G4int id, const G4String& name = "");
52  virtual ~G4VViewer ();
53 
54  virtual void Initialise ();
55  // Called immediately after construction for those operations that
56  // must await complete contruction of viewer and all its bases. For
57  // example, if this class (G4VViewer) is inherited virtually, as in
58  // the OpenGL sub-category, it will not be fully constructed until
59  // *after* the the derived viewer (this is the rule about order of
60  // construction for virtual inheritance), so the derived viewer may
61  // not use information in G4VViewer in its contructor. Hence such
62  // code must be in Initialise().
63 
65  // View manipulation functions.
66 
67  virtual void ResetView ();
68  // Reset view parameters to default, including sub-class parameters, if any.
69  // The sub-class should always invoke the base class implementation, i.e:
70  // virtual void SubClass::ResetView () {
71  // G4VViewer::ResetView();
72  // // Then reset sub-class parameters
73  // ...
74 
75  virtual void SetView () = 0;
76  // Take view parameters and work out model/view transformation,
77  // projection transformation, lighting, etc.
78 
79  virtual void ClearView () = 0;
80  // Clear screen/viewing buffers.
81 
82  virtual void DrawView () = 0;
83  // Draw view of the scene currently attached to the scene handler -
84  // see example of a minimal function at end of this file.
85 
86  void RefreshView ();
87  // Simply invokes SetView, ClearView, DrawView.
88 
89  virtual void ShowView ();
90  // Show view (for graphics systems which require to process
91  // all drawn objects before finalising the view).
92 
93  virtual void FinishView ();
94  // Called at the end of drawing scene. Used to flush streams, or
95  // swap buffers. (Perhaps it is inappropriately named, perhaps its
96  // function could be incorporated into EndModeling (). It marks the
97  // end of scene drawing; be aware hits and digi drawing may Follow.
98  // It is not yet the end of all drawing; that is signalled by
99  // ShowView ().)
100 
101  std::vector<G4ThreeVector> ComputeFlyThrough(G4Vector3D*);
102 
103 #ifdef G4MULTITHREADED
104  // Note: the order of calling of MovingToVisSubThread and SwitchToVisSubThread
105  // is undefined, so you may need to implement mutexes to ensure your preferred
106  // order - see, e.g., G4OpenGLQtViewer. To summarise, the order of calling is
107  // as follows - see G4VisManager.cc.
108  // DoneWithMasterThread
109  // MovingToVisSubThread ) or ( SwitchToVisSubThread
110  // SwitchToVisSubThread ) ( MovingToVisSubThread
111  // DoneWithVisSubThread
112  // MovingToMasterThread
113  // SwitchToMasterThread
114 
115  // Called on the master thread before starting the vis sub-thread.
116  virtual void DoneWithMasterThread ();
117 
118  // Called on the master thread after starting the vis sub-thread.
119  virtual void MovingToVisSubThread ();
120 
121  // Called on the vis sub-thread at start of vis sub-thread.
122  virtual void SwitchToVisSubThread ();
123 
124  // Called on the vis sub-thread when all events have been processed.
125  virtual void DoneWithVisSubThread ();
126 
127  // Called on the vis sub-thread when all events have been processed.
128  virtual void MovingToMasterThread ();
129 
130  // Called on the master thread after the vis sub-thread has terminated.
131  virtual void SwitchToMasterThread ();
132 #endif
133 
135  // Access functions.
136  const G4String& GetName () const;
137  const G4String& GetShortName () const;
138  void SetName (const G4String&);
139  G4int GetViewId () const;
141  const G4ViewParameters& GetViewParameters () const;
143 
144  virtual const std::vector<G4ModelingParameters::VisAttributesModifier>*
146  // So that privately accumulated vis attributes modifiers may be
147  // concatenated with the standard vis attributes modifiers for commands
148  // such as /vis/viewer/set/all and /vis/viewer/save.
149 
150  void SetViewParameters (const G4ViewParameters& vp);
152 
154  // Public utility functions.
155 
157  (const G4VisAttributes*) const;
158 
159  void SetNeedKernelVisit (G4bool need);
160  // Sets individual need-visit flag.
161 
162  void NeedKernelVisit ();
163  // Flags all views the need to re-visit the GEANT4 kernel to refresh
164  // the scene.
165 
166  void ProcessView ();
167  // Used by DrawView (). Invokes SetView (). The basic logic is here.
168 
169 protected:
170 
172  // Protected utility functions.
173 
174  void SetTouchable
175  (const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath);
176  // Set the touchable for /vis/touchable/set/... commands.
177 
179  (const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath,
181  // Set the touchable visibility attribute.
182  // Changes the Vis Attribute Modifiers WITHOUT triggering a rebuild.
183 
184  void TouchableSetColour
185  (const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath,
186  const G4Colour&);
187  // Set the touchable colour attribute.
188  // Changes the Vis Attribute Modifiers WITHOUT triggering a rebuild.
189 
190  class G4Spline
191  {
192  public:
193 
194  // Constructors and destructor
195  G4Spline();
196  ~G4Spline();
197 
198  // Operations
199  void AddSplinePoint(const G4Vector3D& v);
200  G4Vector3D GetInterpolatedSplinePoint(float t); // t = 0...1; 0=vp[0] ... 1=vp[max]
201  int GetNumPoints();
202  G4Vector3D GetPoint(int);
203  // method for computing the Catmull-Rom parametric equation
204  // given a time (t) and a vector quadruple (p1,p2,p3,p4).
205  G4Vector3D CatmullRom_Eq(float t, const G4Vector3D& p1, const G4Vector3D& p2,
206  const G4Vector3D& p3, const G4Vector3D& p4);
207 
208  private:
209  std::vector<G4Vector3D> vp;
210  float delta_t;
211  };
212 
214  // Data members
215  G4VSceneHandler& fSceneHandler; // Abstract scene for this view.
216  G4int fViewId; // Id of this instance.
218  G4String fShortName; // Up to first ' ' character, if any.
219  G4ViewParameters fVP; // View parameters.
220  G4ViewParameters fDefaultVP; // Default view parameters.
221 
223  // Other parameters.
224  G4bool fNeedKernelVisit; // See DrawView() for comments.
225 };
226 
227 #include "G4VViewer.icc"
228 
229 /*********************************************
230 
231 Here is a minimal DrawView () as it might be implemented in the
232 concrete viewer.
233 
234 void G4VViewer::DrawView () { // Default - concrete view usually overrides.
235 
236  // First, a view should decide when to re-visit the G4 kernel.
237  // Sometimes it might not be necessary, e.g., if the scene is stored
238  // in a graphical database (e.g., OpenGL's display lists) and only
239  // the viewing angle has changed. But graphics systems without a
240  // graphical database will always need to visit the G4 kernel.
241 
242  NeedKernelVisit (); // Default is - always visit G4 kernel.
243  // Note: this routine sets the fNeedKernelVisit flag of *all* the views of
244  // the scene.
245 
246  ProcessView (); // The basic logic is here.
247 
248  // Then a view may have more to do, e.g., display the graphical
249  // database. That code should come here before finally...
250 
251  FinishView (); // Flush streams and/or swap buffers.
252 }
253 
254 *********************************************/
255 
256 #endif