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