| [531] | 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 | //
|
|---|
| [1140] | 27 | // $Id: G4VSceneHandler.hh,v 1.41 2009/10/21 14:26:59 allison Exp $
|
|---|
| [954] | 28 | // GEANT4 tag $Name: $
|
|---|
| [531] | 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // John Allison 19th July 1996.
|
|---|
| 32 | //
|
|---|
| 33 | // Class description
|
|---|
| 34 | //
|
|---|
| 35 | // Abstract interface class for graphics scene handlers.
|
|---|
| 36 | // Inherits from G4VGraphicsScene, in the intercoms category, which is
|
|---|
| 37 | // a minimal abstract interface for the GEANT4 kernel.
|
|---|
| 38 |
|
|---|
| 39 | #ifndef G4VSCENEHANDLER_HH
|
|---|
| 40 | #define G4VSCENEHANDLER_HH
|
|---|
| 41 |
|
|---|
| 42 | #include "globals.hh"
|
|---|
| 43 |
|
|---|
| 44 | #include "G4VGraphicsScene.hh"
|
|---|
| 45 | #include "G4ViewerList.hh"
|
|---|
| 46 | #include "G4ViewParameters.hh"
|
|---|
| [1140] | 47 | #include "G4THitsMap.hh"
|
|---|
| [531] | 48 |
|
|---|
| 49 | class G4Scene;
|
|---|
| 50 | class G4VViewer;
|
|---|
| 51 | class G4Colour;
|
|---|
| 52 | class G4Visible;
|
|---|
| 53 | class G4ModelingParameters;
|
|---|
| 54 | class G4VModel;
|
|---|
| 55 | class G4VGraphicsSystem;
|
|---|
| 56 | class G4LogicalVolume;
|
|---|
| 57 | class G4VPhysicalVolume;
|
|---|
| 58 | class G4Material;
|
|---|
| 59 | class G4Event;
|
|---|
| [593] | 60 | class G4AttHolder;
|
|---|
| [531] | 61 |
|
|---|
| 62 | class G4VSceneHandler: public G4VGraphicsScene {
|
|---|
| 63 |
|
|---|
| 64 | public: // With description
|
|---|
| 65 |
|
|---|
| 66 | friend std::ostream& operator << (std::ostream& os, const G4VSceneHandler& s);
|
|---|
| 67 |
|
|---|
| 68 | enum MarkerSizeType {world, screen};
|
|---|
| 69 |
|
|---|
| 70 | G4VSceneHandler (G4VGraphicsSystem& system,
|
|---|
| 71 | G4int id,
|
|---|
| 72 | const G4String& name = "");
|
|---|
| 73 |
|
|---|
| 74 | virtual ~G4VSceneHandler ();
|
|---|
| 75 |
|
|---|
| 76 | ///////////////////////////////////////////////////////////////////
|
|---|
| 77 | // Methods for adding raw GEANT4 objects to the scene handler. They
|
|---|
| 78 | // must always be called in the triplet PreAddSolid, AddSolid and
|
|---|
| 79 | // PostAddSolid. The transformation and visualization attributes
|
|---|
| 80 | // must be set by the call to PreAddSolid. If your graphics system
|
|---|
| 81 | // is sophisticated enough to handle a particular solid shape as a
|
|---|
| 82 | // primitive, in your derived class write a function to override one
|
|---|
| 83 | // or more of the following. See the implementation of
|
|---|
| 84 | // G4VSceneHandler::AddSolid (const G4Box& box) for more
|
|---|
| 85 | // suggestions. If not, please implement the base class invocation.
|
|---|
| 86 |
|
|---|
| 87 | virtual void PreAddSolid (const G4Transform3D& objectTransformation,
|
|---|
| 88 | const G4VisAttributes& visAttribs);
|
|---|
| 89 | // objectTransformation is the transformation in the world
|
|---|
| 90 | // coordinate system of the object about to be added, and visAttribs
|
|---|
| 91 | // is its visualization attributes.
|
|---|
| 92 | // IMPORTANT: invoke this from your polymorphic versions, e.g.:
|
|---|
| 93 | // void MyXXXSceneHandler::PreAddSolid
|
|---|
| 94 | // (const G4Transform3D& objectTransformation,
|
|---|
| 95 | // const G4VisAttributes& visAttribs) {
|
|---|
| 96 | // G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs);
|
|---|
| 97 | // ...
|
|---|
| 98 | // }
|
|---|
| 99 |
|
|---|
| 100 | virtual void PostAddSolid ();
|
|---|
| 101 | // IMPORTANT: invoke this from your polymorphic versions, e.g.:
|
|---|
| 102 | // void MyXXXSceneHandler::PostAddSolid () {
|
|---|
| 103 | // ...
|
|---|
| 104 | // G4VSceneHandler::PostAddSolid ();
|
|---|
| 105 | // }
|
|---|
| 106 |
|
|---|
| 107 | virtual void AddSolid (const G4Box&);
|
|---|
| 108 | virtual void AddSolid (const G4Cons&);
|
|---|
| 109 | virtual void AddSolid (const G4Tubs&);
|
|---|
| 110 | virtual void AddSolid (const G4Trd&);
|
|---|
| 111 | virtual void AddSolid (const G4Trap&);
|
|---|
| 112 | virtual void AddSolid (const G4Sphere&);
|
|---|
| 113 | virtual void AddSolid (const G4Para&);
|
|---|
| 114 | virtual void AddSolid (const G4Torus&);
|
|---|
| 115 | virtual void AddSolid (const G4Polycone&);
|
|---|
| 116 | virtual void AddSolid (const G4Polyhedra&);
|
|---|
| 117 | virtual void AddSolid (const G4VSolid&); // For solids not above.
|
|---|
| 118 |
|
|---|
| 119 | ///////////////////////////////////////////////////////////////////
|
|---|
| 120 | // Methods for adding "compound" GEANT4 objects to the scene
|
|---|
| 121 | // handler. These methods may either (a) invoke "user code" that
|
|---|
| 122 | // uses the "user interface", G4VVisManager (see, for example,
|
|---|
| 123 | // G4VSceneHandler, which for trajectories uses
|
|---|
| 124 | // G4VTrajectory::DrawTrajectory, via G4TrajectoriesModel in the
|
|---|
| 125 | // Modeling Category) or (b) invoke AddPrimitives below (between
|
|---|
| 126 | // calls to Begin/EndPrimitives) or (c) use graphics-system-specific
|
|---|
| 127 | // code or (d) any combination of the above.
|
|---|
| 128 |
|
|---|
| 129 | virtual void AddCompound (const G4VTrajectory&);
|
|---|
| 130 | virtual void AddCompound (const G4VHit&);
|
|---|
| [1140] | 131 | virtual void AddCompound (const G4THitsMap<G4double>&);
|
|---|
| [531] | 132 |
|
|---|
| 133 | //////////////////////////////////////////////////////////////
|
|---|
| 134 | // Functions for adding primitives.
|
|---|
| 135 |
|
|---|
| 136 | virtual void BeginModeling ();
|
|---|
| 137 | // IMPORTANT: invoke this from your polymorphic versions, e.g.:
|
|---|
| 138 | // void MyXXXSceneHandler::BeginModeling () {
|
|---|
| 139 | // G4VSceneHandler::BeginModeling ();
|
|---|
| 140 | // ...
|
|---|
| 141 | // }
|
|---|
| 142 |
|
|---|
| 143 | virtual void EndModeling ();
|
|---|
| 144 | // IMPORTANT: invoke this from your polymorphic versions, e.g.:
|
|---|
| 145 | // void MyXXXSceneHandler::EndModeling () {
|
|---|
| 146 | // ...
|
|---|
| 147 | // G4VSceneHandler::EndModeling ();
|
|---|
| 148 | // }
|
|---|
| 149 |
|
|---|
| 150 | virtual void BeginPrimitives
|
|---|
| 151 | (const G4Transform3D& objectTransformation);
|
|---|
| 152 | // IMPORTANT: invoke this from your polymorphic versions, e.g.:
|
|---|
| 153 | // void MyXXXSceneHandler::BeginPrimitives
|
|---|
| 154 | // (const G4Transform3D& objectTransformation) {
|
|---|
| 155 | // G4VSceneHandler::BeginPrimitives (objectTransformation);
|
|---|
| 156 | // ...
|
|---|
| 157 | // }
|
|---|
| 158 |
|
|---|
| 159 | virtual void EndPrimitives ();
|
|---|
| 160 | // IMPORTANT: invoke this from your polymorphic versions, e.g.:
|
|---|
| 161 | // void MyXXXSceneHandler::EndPrimitives () {
|
|---|
| 162 | // ...
|
|---|
| 163 | // G4VSceneHandler::EndPrimitives ();
|
|---|
| 164 | // }
|
|---|
| 165 |
|
|---|
| [688] | 166 | virtual void BeginPrimitives2D
|
|---|
| 167 | (const G4Transform3D& objectTransformation);
|
|---|
| [531] | 168 | // The x,y coordinates of the primitives passed to AddPrimitive are
|
|---|
| 169 | // intrepreted as screen coordinates, -1 < x,y < 1. The
|
|---|
| 170 | // z-coordinate is ignored.
|
|---|
| 171 | // IMPORTANT: invoke this from your polymorphic versions, e.g.:
|
|---|
| 172 | // void MyXXXSceneHandler::BeginPrimitives2D
|
|---|
| 173 | // (const G4Transform3D& objectTransformation) {
|
|---|
| 174 | // G4VSceneHandler::BeginPrimitives2D ();
|
|---|
| 175 | // ...
|
|---|
| 176 | // }
|
|---|
| 177 |
|
|---|
| 178 | virtual void EndPrimitives2D ();
|
|---|
| 179 | // IMPORTANT: invoke this from your polymorphic versions, e.g.:
|
|---|
| 180 | // void MyXXXSceneHandler::EndPrimitives2D () {
|
|---|
| 181 | // ...
|
|---|
| 182 | // G4VSceneHandler::EndPrimitives2D ();
|
|---|
| 183 | // }
|
|---|
| 184 |
|
|---|
| 185 | virtual void AddPrimitive (const G4Polyline&) = 0;
|
|---|
| 186 | virtual void AddPrimitive (const G4Scale&);
|
|---|
| 187 | // Default implementation in this class but can be over-ridden.
|
|---|
| 188 | virtual void AddPrimitive (const G4Text&) = 0;
|
|---|
| 189 | virtual void AddPrimitive (const G4Circle&) = 0;
|
|---|
| 190 | virtual void AddPrimitive (const G4Square&) = 0;
|
|---|
| 191 | virtual void AddPrimitive (const G4Polymarker&);
|
|---|
| 192 | // Default implementation in this class but can be over-ridden.
|
|---|
| 193 | virtual void AddPrimitive (const G4Polyhedron&) = 0;
|
|---|
| 194 | virtual void AddPrimitive (const G4NURBS&) = 0;
|
|---|
| 195 |
|
|---|
| 196 | //////////////////////////////////////////////////////////////
|
|---|
| 197 | // Access functions.
|
|---|
| 198 | const G4String& GetName () const;
|
|---|
| 199 | G4int GetSceneHandlerId () const;
|
|---|
| 200 | G4int GetViewCount () const;
|
|---|
| 201 | G4VGraphicsSystem* GetGraphicsSystem () const;
|
|---|
| 202 | G4Scene* GetScene () const;
|
|---|
| 203 | const G4ViewerList& GetViewerList () const;
|
|---|
| 204 | G4VModel* GetModel () const;
|
|---|
| 205 | G4VViewer* GetCurrentViewer () const;
|
|---|
| 206 | G4bool GetMarkForClearingTransientStore () const;
|
|---|
| 207 | G4bool IsReadyForTransients () const;
|
|---|
| 208 | G4bool GetTransientsDrawnThisEvent () const;
|
|---|
| 209 | G4bool GetTransientsDrawnThisRun () const;
|
|---|
| 210 | void SetName (const G4String&);
|
|---|
| 211 | void SetCurrentViewer (G4VViewer*);
|
|---|
| 212 | void SetScene (G4Scene*);
|
|---|
| 213 | G4ViewerList& SetViewerList (); // Non-const so you can change.
|
|---|
| 214 | void SetModel (G4VModel*);
|
|---|
| 215 | void SetMarkForClearingTransientStore (G4bool);
|
|---|
| 216 | // Sets flag which will cause transient store to be cleared at the
|
|---|
| 217 | // next call to BeginPrimitives(). Maintained by vis manager.
|
|---|
| 218 | void SetTransientsDrawnThisEvent (G4bool);
|
|---|
| 219 | void SetTransientsDrawnThisRun (G4bool);
|
|---|
| 220 | // Maintained by vis manager.
|
|---|
| 221 |
|
|---|
| 222 | //////////////////////////////////////////////////////////////
|
|---|
| 223 | // Public utility functions.
|
|---|
| 224 |
|
|---|
| 225 | const G4Colour& GetColour (const G4Visible&);
|
|---|
| 226 | const G4Colour& GetColor (const G4Visible&);
|
|---|
| 227 | // Returns colour of G4Visible object, or default global colour.
|
|---|
| 228 |
|
|---|
| 229 | const G4Colour& GetTextColour (const G4Text&);
|
|---|
| 230 | const G4Colour& GetTextColor (const G4Text&);
|
|---|
| 231 | // Returns colour of G4Text object, or default text colour.
|
|---|
| 232 |
|
|---|
| [593] | 233 | G4double GetLineWidth(const G4VisAttributes*);
|
|---|
| 234 | // Returns line width of G4VisAttributes multiplied by GlobalLineWidthScale.
|
|---|
| [531] | 235 |
|
|---|
| 236 | G4ViewParameters::DrawingStyle GetDrawingStyle (const G4VisAttributes*);
|
|---|
| 237 | // Returns drawing style from current view parameters, unless the user
|
|---|
| 238 | // has forced through the vis attributes, thereby over-riding the
|
|---|
| 239 | // current view parameter.
|
|---|
| 240 |
|
|---|
| 241 | G4bool GetAuxEdgeVisible (const G4VisAttributes*);
|
|---|
| 242 | // Returns auxiliary edge visibility from current view parameters,
|
|---|
| 243 | // unless the user has forced through the vis attributes, thereby
|
|---|
| 244 | // over-riding the current view parameter.
|
|---|
| 245 |
|
|---|
| [593] | 246 | G4int GetNoOfSides(const G4VisAttributes*);
|
|---|
| [531] | 247 | // Returns no. of sides (lines segments per circle) from current
|
|---|
| 248 | // view parameters, unless the user has forced through the vis
|
|---|
| 249 | // attributes, thereby over-riding the current view parameter.
|
|---|
| 250 |
|
|---|
| 251 | G4double GetMarkerSize (const G4VMarker&, MarkerSizeType&);
|
|---|
| 252 | // Returns applicable marker size (diameter) and type (in second
|
|---|
| 253 | // argument). Uses global default marker if marker sizes are not
|
|---|
| 254 | // set. Multiplies by GlobalMarkerScale.
|
|---|
| 255 |
|
|---|
| 256 | G4double GetMarkerDiameter (const G4VMarker&, MarkerSizeType&);
|
|---|
| 257 | // Alias for GetMarkerSize.
|
|---|
| 258 |
|
|---|
| 259 | G4double GetMarkerRadius (const G4VMarker&, MarkerSizeType&);
|
|---|
| 260 | // GetMarkerSize / 2.
|
|---|
| 261 |
|
|---|
| 262 | G4ModelingParameters* CreateModelingParameters ();
|
|---|
| 263 | // Only the scene handler and view know what the Modeling Parameters should
|
|---|
| 264 | // be. For historical reasons, the GEANT4 Visualization Environment
|
|---|
| 265 | // maintains its own Scene Data and View Parameters, which must be
|
|---|
| 266 | // converted, when needed, to Modeling Parameters.
|
|---|
| 267 |
|
|---|
| 268 | void DrawEvent(const G4Event*);
|
|---|
| 269 | // Checks scene's end-of-event model list and draws trajectories,
|
|---|
| 270 | // hits, etc.
|
|---|
| 271 |
|
|---|
| 272 | //////////////////////////////////////////////////////////////
|
|---|
| 273 | // Administration functions.
|
|---|
| 274 |
|
|---|
| 275 | G4int IncrementViewCount ();
|
|---|
| 276 |
|
|---|
| 277 | virtual void ClearStore ();
|
|---|
| 278 | // Clears graphics database (display lists) if any. This base class
|
|---|
| 279 | // implements some common functionality so...
|
|---|
| 280 | // IMPORTANT: invoke this from your polymorphic versions, e.g.:
|
|---|
| 281 | // void MyXXXSceneHandler::ClearStore () {
|
|---|
| 282 | // G4VSceneHandler::ClearStore ();
|
|---|
| 283 | // ...
|
|---|
| 284 | // }
|
|---|
| 285 |
|
|---|
| 286 | virtual void ClearTransientStore ();
|
|---|
| 287 | // Clears transient part of graphics database (display lists) if any.
|
|---|
| 288 | // This base class implements some common functionality so...
|
|---|
| 289 | // IMPORTANT: invoke this from your polymorphic versions, e.g.:
|
|---|
| 290 | // void MyXXXSceneHandler::ClearTransientStore () {
|
|---|
| 291 | // G4VSceneHandler::ClearTransientStore ();
|
|---|
| 292 | // ...
|
|---|
| 293 | // }
|
|---|
| 294 |
|
|---|
| 295 | void AddViewerToList (G4VViewer* pView); // Add view to view List.
|
|---|
| 296 | void RemoveViewerFromList (G4VViewer* pView); // Remove view from view List.
|
|---|
| 297 |
|
|---|
| 298 | protected:
|
|---|
| 299 |
|
|---|
| 300 | //////////////////////////////////////////////////////////////
|
|---|
| 301 | // Default routine used by default AddSolid ().
|
|---|
| 302 |
|
|---|
| 303 | virtual void RequestPrimitives (const G4VSolid& solid);
|
|---|
| 304 |
|
|---|
| 305 | //////////////////////////////////////////////////////////////
|
|---|
| 306 | // Other internal routines...
|
|---|
| 307 |
|
|---|
| 308 | virtual const G4Polyhedron* CreateSectionPolyhedron ();
|
|---|
| 309 | virtual const G4Polyhedron* CreateCutawayPolyhedron ();
|
|---|
| 310 | // Generic clipping using the BooleanProcessor in graphics_reps is
|
|---|
| 311 | // implemented in this class. Subclasses that implement their own
|
|---|
| 312 | // clipping should provide an override that returns zero.
|
|---|
| [593] | 313 | void LoadAtts(const G4Visible&, G4AttHolder*);
|
|---|
| 314 | // Load G4AttValues and G4AttDefs associated with the G4Visible
|
|---|
| 315 | // object onto the G4AttHolder object. It checks fpModel, and also
|
|---|
| 316 | // loads the G4AttValues and G4AttDefs from G4PhysicalVolumeModel,
|
|---|
| 317 | // G4VTrajectory, G4VTrajectoryPoint, or G4VHits, as appropriate.
|
|---|
| 318 | // The G4AttHolder object is an object of a class that publicly
|
|---|
| 319 | // inherits G4AttHolder - see, e.g., SoG4Polyhedron in the Open
|
|---|
| 320 | // Inventor driver. G4AttHolder deletes G4AttValues in its
|
|---|
| 321 | // destructor to ensure proper clean-up of G4AttValues.
|
|---|
| [531] | 322 |
|
|---|
| 323 | //////////////////////////////////////////////////////////////
|
|---|
| 324 | // Data members
|
|---|
| 325 |
|
|---|
| 326 | G4VGraphicsSystem& fSystem; // Graphics system.
|
|---|
| 327 | const G4int fSceneHandlerId; // Id of this instance.
|
|---|
| 328 | G4String fName;
|
|---|
| 329 | G4int fViewCount; // To determine view ids.
|
|---|
| 330 | G4ViewerList fViewerList; // Viewers.
|
|---|
| 331 | G4VViewer* fpViewer; // Current viewer.
|
|---|
| 332 | G4Scene* fpScene; // Scene for this scene handler.
|
|---|
| 333 | G4bool fMarkForClearingTransientStore;
|
|---|
| 334 | G4bool fReadyForTransients; // I.e., not processing the
|
|---|
| 335 | // run-duration part of scene.
|
|---|
| 336 | G4bool fTransientsDrawnThisEvent; // Maintained by vis
|
|---|
| 337 | G4bool fTransientsDrawnThisRun; // manager.
|
|---|
| 338 | G4bool fProcessingSolid; // True if within Pre/PostAddSolid.
|
|---|
| 339 | G4bool fSecondPassRequested;
|
|---|
| 340 | G4bool fSecondPass; // ...in process.
|
|---|
| 341 | G4VModel* fpModel; // Current model.
|
|---|
| 342 | const G4Transform3D* fpObjectTransformation; // Current accumulated
|
|---|
| 343 | // object transformation.
|
|---|
| 344 | G4int fNestingDepth; // For Begin/EndPrimitives.
|
|---|
| 345 | const G4VisAttributes* fpVisAttribs; // Working vis attributes.
|
|---|
| 346 | const G4Transform3D fIdentityTransformation;
|
|---|
| 347 |
|
|---|
| 348 | private:
|
|---|
| 349 |
|
|---|
| 350 | G4VSceneHandler (const G4VSceneHandler&);
|
|---|
| 351 | G4VSceneHandler& operator = (const G4VSceneHandler&);
|
|---|
| 352 |
|
|---|
| 353 | //////////////////////////////////////////////////////////////
|
|---|
| 354 | // Friend function accessed only by views of this scene.
|
|---|
| 355 |
|
|---|
| 356 | friend void G4VViewer::ProcessView ();
|
|---|
| 357 |
|
|---|
| 358 | //////////////////////////////////////////////////////////////
|
|---|
| 359 | // Private functions, etc..
|
|---|
| 360 |
|
|---|
| 361 | void ProcessScene (G4VViewer& view);
|
|---|
| 362 | // Accessed by G4VViewer::ProcessView ().
|
|---|
| 363 |
|
|---|
| 364 | };
|
|---|
| 365 |
|
|---|
| 366 | #include "G4VSceneHandler.icc"
|
|---|
| 367 |
|
|---|
| 368 | #endif
|
|---|