Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 // 27 // 28 // 28 // 29 // John Allison 27th March 1996 29 // John Allison 27th March 1996 30 // 30 // 31 // Class description 31 // Class description 32 // 32 // 33 // Abstract interface class for graphics viewe 33 // Abstract interface class for graphics viewers. 34 34 35 #ifndef G4VVIEWER_HH 35 #ifndef G4VVIEWER_HH 36 #define G4VVIEWER_HH 36 #define G4VVIEWER_HH 37 37 38 #include "globals.hh" 38 #include "globals.hh" 39 39 40 #include "G4SceneTreeItem.hh" << 41 << 42 #include "G4ViewParameters.hh" 40 #include "G4ViewParameters.hh" 43 #include "G4PhysicalVolumeModel.hh" 41 #include "G4PhysicalVolumeModel.hh" 44 #include "G4PseudoScene.hh" << 45 << 46 #include <vector> << 47 #include <list> << 48 42 49 class G4VSceneHandler; 43 class G4VSceneHandler; 50 44 51 // clang-format off << 52 class G4VViewer { 45 class G4VViewer { 53 46 54 public: // With description 47 public: // With description 55 48 56 friend std::ostream& operator << (std::ostre 49 friend std::ostream& operator << (std::ostream& os, const G4VViewer& v); 57 50 58 G4VViewer (G4VSceneHandler&, G4int id, const 51 G4VViewer (G4VSceneHandler&, G4int id, const G4String& name = ""); 59 virtual ~G4VViewer (); 52 virtual ~G4VViewer (); 60 53 61 virtual void Initialise (); 54 virtual void Initialise (); 62 // Called immediately after construction for 55 // Called immediately after construction for those operations that 63 // must await complete contruction of viewer 56 // must await complete contruction of viewer and all its bases. For 64 // example, if this class (G4VViewer) is inh 57 // example, if this class (G4VViewer) is inherited virtually, as in 65 // the OpenGL sub-category, it will not be f 58 // the OpenGL sub-category, it will not be fully constructed until 66 // *after* the the derived viewer (this is t 59 // *after* the the derived viewer (this is the rule about order of 67 // construction for virtual inheritance), so 60 // construction for virtual inheritance), so the derived viewer may 68 // not use information in G4VViewer in its c 61 // not use information in G4VViewer in its contructor. Hence such 69 // code must be in Initialise(). 62 // code must be in Initialise(). 70 63 71 //////////////////////////////////////////// 64 ////////////////////////////////////////////////////////////// 72 // View manipulation functions. 65 // View manipulation functions. 73 66 74 virtual void ResetView (); 67 virtual void ResetView (); 75 // Reset view parameters to default, includi 68 // Reset view parameters to default, including sub-class parameters, if any. 76 // The sub-class should always invoke the ba 69 // The sub-class should always invoke the base class implementation, i.e: 77 // virtual void SubClass::ResetView () { 70 // virtual void SubClass::ResetView () { 78 // G4VViewer::ResetView(); 71 // G4VViewer::ResetView(); 79 // // Then reset sub-class parameters 72 // // Then reset sub-class parameters 80 // ... 73 // ... 81 74 82 virtual void SetView () = 0; 75 virtual void SetView () = 0; 83 // Take view parameters and work out model/v 76 // Take view parameters and work out model/view transformation, 84 // projection transformation, lighting, etc. 77 // projection transformation, lighting, etc. 85 78 86 virtual void ClearView () = 0; 79 virtual void ClearView () = 0; 87 // Clear screen/viewing buffers. 80 // Clear screen/viewing buffers. 88 81 89 virtual void DrawView () = 0; 82 virtual void DrawView () = 0; 90 // Draw view of the scene currently attached 83 // Draw view of the scene currently attached to the scene handler - 91 // see example of a minimal function at end 84 // see example of a minimal function at end of this file. 92 85 93 void RefreshView (); 86 void RefreshView (); 94 // Simply invokes SetView, ClearView, DrawVi 87 // Simply invokes SetView, ClearView, DrawView. 95 88 96 virtual void ShowView (); 89 virtual void ShowView (); 97 // Show view (for graphics systems which req 90 // Show view (for graphics systems which require to process 98 // all drawn objects before finalising the v 91 // all drawn objects before finalising the view). 99 92 100 virtual void FinishView (); 93 virtual void FinishView (); 101 // Called at the end of drawing scene. Used 94 // Called at the end of drawing scene. Used to flush streams, or 102 // swap buffers. (Perhaps it is inappropria 95 // swap buffers. (Perhaps it is inappropriately named, perhaps its 103 // function could be incorporated into EndMo 96 // function could be incorporated into EndModeling (). It marks the 104 // end of scene drawing; be aware hits and d 97 // end of scene drawing; be aware hits and digi drawing may Follow. 105 // It is not yet the end of all drawing; tha 98 // It is not yet the end of all drawing; that is signalled by 106 // ShowView ().) 99 // ShowView ().) 107 100 108 virtual G4bool ReadyToDraw() {return true;} << 109 << 110 std::vector<G4ThreeVector> ComputeFlyThrough 101 std::vector<G4ThreeVector> ComputeFlyThrough(G4Vector3D*); 111 102 >> 103 #ifdef G4MULTITHREADED 112 // Note: the order of calling of MovingToVis 104 // Note: the order of calling of MovingToVisSubThread and SwitchToVisSubThread 113 // is undefined, so you may need to implemen 105 // is undefined, so you may need to implement mutexes to ensure your preferred 114 // order - see, e.g., G4OpenGLQtViewer. To s 106 // order - see, e.g., G4OpenGLQtViewer. To summarise, the order of calling is 115 // as follows - see G4VisManager.cc. 107 // as follows - see G4VisManager.cc. 116 // DoneWithMasterThread 108 // DoneWithMasterThread 117 // MovingToVisSubThread ) or ( SwitchToVisSu 109 // MovingToVisSubThread ) or ( SwitchToVisSubThread 118 // SwitchToVisSubThread ) ( MovingToVisSu 110 // SwitchToVisSubThread ) ( MovingToVisSubThread 119 // DoneWithVisSubThread 111 // DoneWithVisSubThread 120 // MovingToMasterThread 112 // MovingToMasterThread 121 // SwitchToMasterThread 113 // SwitchToMasterThread 122 114 123 // Called on the master thread before starti 115 // Called on the master thread before starting the vis sub-thread. 124 virtual void DoneWithMasterThread () {} << 116 virtual void DoneWithMasterThread (); 125 117 126 // Called on the master thread after startin 118 // Called on the master thread after starting the vis sub-thread. 127 virtual void MovingToVisSubThread () {} << 119 virtual void MovingToVisSubThread (); 128 120 129 // Called on the vis sub-thread at start of 121 // Called on the vis sub-thread at start of vis sub-thread. 130 virtual void SwitchToVisSubThread () {} << 122 virtual void SwitchToVisSubThread (); 131 123 132 // Called on the vis sub-thread when all eve 124 // Called on the vis sub-thread when all events have been processed. 133 virtual void DoneWithVisSubThread () {} << 125 virtual void DoneWithVisSubThread (); 134 126 135 // Called on the vis sub-thread when all eve 127 // Called on the vis sub-thread when all events have been processed. 136 virtual void MovingToMasterThread () {} << 128 virtual void MovingToMasterThread (); 137 129 138 // Called on the master thread after the vis 130 // Called on the master thread after the vis sub-thread has terminated. 139 virtual void SwitchToMasterThread () {} << 131 virtual void SwitchToMasterThread (); 140 << 132 #endif 141 //////////////////////////////////////////// << 142 // Stuff for scene tree. << 143 /** << 144 - The scene tree is a tree of G4SceneTreeIt << 145 - Its root is a data member fSceneTree of a << 146 G4VViewer inheritance, << 147 - G4SceneTreeItem is an aggregate of data m << 148 properties of objects in the scene (G4Scene << 149 low-level types - G4String, G4VisAttributes << 150 that it can be used across categories, avoi << 151 - The root item has children that represent << 152 sub-classes) in the scene. << 153 - For a G4PhysicalVolumeModel (detector com << 154 children's children, etc., imitate the geom << 155 model. These descendants are called "toucha << 156 - There may be more than one G4PhysicalVolu << 157 the user creates his/her scene. << 158 - The scene tree is reviewed, and updated i << 159 of G4VSceneHandler::ProcessScene. This is << 160 - A kernel visit is triggered by some vis c << 161 /vis/viewer/rebuild) and by a viewer if it << 162 example, a kernel visit may not be required << 163 but required for a change from surface to w << 164 - The idea is that the scene tree can be pa << 165 create a tree widget, and interactions with << 166 /vis/scene/activateModel, /vis/set/touchabl << 167 The viewer decides if this requires a kerne << 168 must update fSceneTree itself (utilities ar << 169 G4VViewer::TouchableSetVisibility/Colour). << 170 */ << 171 class SceneTreeScene: public G4PseudoScene { << 172 // G4PhysicalVolumeModel sends touchables << 173 public: << 174 SceneTreeScene(G4VViewer*, G4PhysicalVolum << 175 ~SceneTreeScene() = default; << 176 private: << 177 void ProcessVolume(const G4VSolid& solid) << 178 std::list<G4SceneTreeItem>::iterator FindO << 179 (const G4String& modelID, G4SceneTreeItem& << 180 G4int depth, const G4String& partialPathS << 181 G4VViewer* fpViewer = nullptr; << 182 G4PhysicalVolumeModel* fpPVModel = nullptr << 183 std::list<G4SceneTreeItem>::iterator fMod << 184 G4int fMaximumExpandedDepth = 0; // To << 185 const G4int fMaximumExpanded = 30; // So << 186 }; << 187 void InsertModelInSceneTree(G4VModel*); << 188 const G4SceneTreeItem& GetSceneTree() {retur << 189 G4SceneTreeItem& AccessSceneTree() {return f << 190 void UpdateGUISceneTree(); // A utility << 191 const G4int fMaxNTouchables = 10000; // Lim << 192 G4bool fCurtailDescent = false; // Flag to << 193 133 194 //////////////////////////////////////////// 134 ////////////////////////////////////////////////////////////// 195 // Access functions. 135 // Access functions. 196 const G4String& GetName () 136 const G4String& GetName () const; 197 const G4String& GetShortName () 137 const G4String& GetShortName () const; 198 void SetName (c 138 void SetName (const G4String&); 199 G4int GetViewId () 139 G4int GetViewId () const; 200 G4VSceneHandler* GetSceneHandler () 140 G4VSceneHandler* GetSceneHandler () const; 201 const G4ViewParameters& GetViewParameters 141 const G4ViewParameters& GetViewParameters () const; 202 const G4ViewParameters& GetDefaultViewParame 142 const G4ViewParameters& GetDefaultViewParameters () const; 203 G4double GetKernelVisitElapse << 204 143 205 virtual const std::vector<G4ModelingParamete 144 virtual const std::vector<G4ModelingParameters::VisAttributesModifier>* 206 GetPrivateVisAttributesModifiers() const; 145 GetPrivateVisAttributesModifiers() const; 207 // So that privately accumulated vis attribu 146 // So that privately accumulated vis attributes modifiers may be 208 // concatenated with the standard vis attrib 147 // concatenated with the standard vis attributes modifiers for commands 209 // such as /vis/viewer/set/all and /vis/view 148 // such as /vis/viewer/set/all and /vis/viewer/save. 210 149 211 void SetViewParameters (const G4View 150 void SetViewParameters (const G4ViewParameters& vp); 212 void SetDefaultViewParameters (const G4View 151 void SetDefaultViewParameters (const G4ViewParameters& vp); 213 152 214 //////////////////////////////////////////// 153 ////////////////////////////////////////////////////////////// 215 // Public utility functions. 154 // Public utility functions. 216 155 217 const G4VisAttributes* GetApplicableVisAttr 156 const G4VisAttributes* GetApplicableVisAttributes 218 (c 157 (const G4VisAttributes*) const; 219 158 220 void SetNeedKernelVisit (G4bool need); 159 void SetNeedKernelVisit (G4bool need); 221 // Sets individual need-visit flag. 160 // Sets individual need-visit flag. 222 161 223 void NeedKernelVisit (); 162 void NeedKernelVisit (); 224 // Flags all views the need to re-visit the 163 // Flags all views the need to re-visit the GEANT4 kernel to refresh 225 // the scene. 164 // the scene. 226 165 227 void ProcessView (); 166 void ProcessView (); 228 // Used by DrawView (). Invokes SetView (). 167 // Used by DrawView (). Invokes SetView (). The basic logic is here. 229 168 230 protected: 169 protected: 231 170 232 //////////////////////////////////////////// 171 ////////////////////////////////////////////////////////////// 233 // Protected utility functions. 172 // Protected utility functions. 234 173 235 void SetTouchable 174 void SetTouchable 236 (const std::vector<G4PhysicalVolumeModel::G4 175 (const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath); 237 // Set the touchable for /vis/touchable/set/ 176 // Set the touchable for /vis/touchable/set/... commands. 238 177 239 void TouchableSetVisibility 178 void TouchableSetVisibility 240 (const std::vector<G4PhysicalVolumeModel::G4 179 (const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath, 241 G4bool visibility); 180 G4bool visibility); 242 // Set the touchable visibility attribute. 181 // Set the touchable visibility attribute. 243 // Changes the Vis Attribute Modifiers WITHO 182 // Changes the Vis Attribute Modifiers WITHOUT triggering a rebuild. 244 183 245 void TouchableSetColour 184 void TouchableSetColour 246 (const std::vector<G4PhysicalVolumeModel::G4 185 (const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath, 247 const G4Colour&); 186 const G4Colour&); 248 // Set the touchable colour attribute. 187 // Set the touchable colour attribute. 249 // Changes the Vis Attribute Modifiers WITHO 188 // Changes the Vis Attribute Modifiers WITHOUT triggering a rebuild. 250 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 251 //////////////////////////////////////////// 213 ////////////////////////////////////////////////////////////// 252 // Data members 214 // Data members 253 G4VSceneHandler& fSceneHandler; / 215 G4VSceneHandler& fSceneHandler; // Abstract scene for this view. 254 G4int fViewId; // Id of this i 216 G4int fViewId; // Id of this instance. 255 G4String fName; 217 G4String fName; 256 G4String fShortName; // Up to first 218 G4String fShortName; // Up to first ' ' character, if any. 257 G4ViewParameters fVP; // View paramet 219 G4ViewParameters fVP; // View parameters. 258 G4ViewParameters fDefaultVP; // Default view 220 G4ViewParameters fDefaultVP; // Default view parameters. 259 G4double fKernelVisitElapsedTimeSeco << 260 // Note: fKernelVisitElapsedTimeSeconds is m << 261 G4SceneTreeItem fSceneTree; << 262 221 263 //////////////////////////////////////////// 222 ////////////////////////////////////////////////////////////// 264 // Other parameters. 223 // Other parameters. 265 G4bool fNeedKernelVisit; // See D 224 G4bool fNeedKernelVisit; // See DrawView() for comments. 266 }; 225 }; 267 226 268 #include "G4VViewer.icc" 227 #include "G4VViewer.icc" 269 228 270 /********************************************* 229 /********************************************* 271 230 272 Here is a minimal DrawView () as it might be i 231 Here is a minimal DrawView () as it might be implemented in the 273 concrete viewer. 232 concrete viewer. 274 233 275 void G4VViewer::DrawView () { // Default - co 234 void G4VViewer::DrawView () { // Default - concrete view usually overrides. 276 235 277 // First, a view should decide when to re-vi 236 // First, a view should decide when to re-visit the G4 kernel. 278 // Sometimes it might not be necessary, e.g. 237 // Sometimes it might not be necessary, e.g., if the scene is stored 279 // in a graphical database (e.g., OpenGL's d 238 // in a graphical database (e.g., OpenGL's display lists) and only 280 // the viewing angle has changed. But graph 239 // the viewing angle has changed. But graphics systems without a 281 // graphical database will always need to vi 240 // graphical database will always need to visit the G4 kernel. 282 241 283 NeedKernelVisit (); // Default is - always 242 NeedKernelVisit (); // Default is - always visit G4 kernel. 284 // Note: this routine sets the fNeedKernelVi 243 // Note: this routine sets the fNeedKernelVisit flag of *all* the views of 285 // the scene. 244 // the scene. 286 245 287 ProcessView (); // The basic log 246 ProcessView (); // The basic logic is here. 288 247 289 // Then a view may have more to do, e.g., di 248 // Then a view may have more to do, e.g., display the graphical 290 // database. That code should come here bef 249 // database. That code should come here before finally... 291 250 292 FinishView (); // Flush streams 251 FinishView (); // Flush streams and/or swap buffers. 293 } 252 } 294 253 295 *********************************************/ 254 *********************************************/ 296 255 297 #endif 256 #endif 298 257