![]() |
|
|||
File indexing completed on 2025-09-18 09:16:08
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 // Abstract interface class for graphics scene handlers. 0034 // Inherits from G4VGraphicsScene, in the intercoms category, which is 0035 // a minimal abstract interface for the GEANT4 kernel. 0036 0037 #ifndef G4VSCENEHANDLER_HH 0038 #define G4VSCENEHANDLER_HH 0039 0040 #include "globals.hh" 0041 0042 #include "G4VGraphicsScene.hh" 0043 #include "G4ViewerList.hh" 0044 #include "G4ViewParameters.hh" 0045 #include "G4THitsMap.hh" 0046 #include "G4PseudoScene.hh" 0047 0048 #include <map> 0049 0050 class G4Scene; 0051 class G4VGraphicsSystem; 0052 class G4AttHolder; 0053 0054 class G4VSceneHandler: public G4VGraphicsScene { 0055 0056 friend class G4VViewer; 0057 friend std::ostream& operator << (std::ostream& os, const G4VSceneHandler& s); 0058 0059 public: // With description 0060 0061 enum MarkerSizeType {world, screen}; 0062 0063 G4VSceneHandler (G4VGraphicsSystem& system, 0064 G4int id, 0065 const G4String& name = ""); 0066 0067 virtual ~G4VSceneHandler (); 0068 0069 /////////////////////////////////////////////////////////////////// 0070 // Methods for adding raw GEANT4 objects to the scene handler. They 0071 // must always be called in the triplet PreAddSolid, AddSolid and 0072 // PostAddSolid. The transformation and visualization attributes 0073 // must be set by the call to PreAddSolid. If your graphics system 0074 // is sophisticated enough to handle a particular solid shape as a 0075 // primitive, in your derived class write a function to override one 0076 // or more of the following. See the implementation of 0077 // G4VSceneHandler::AddSolid (const G4Box& box) for more 0078 // suggestions. If not, please implement the base class invocation. 0079 0080 virtual void PreAddSolid (const G4Transform3D& objectTransformation, 0081 const G4VisAttributes&); 0082 // objectTransformation is the transformation in the world 0083 // coordinate system of the object about to be added, and visAttribs 0084 // is its visualization attributes. 0085 // IMPORTANT: invoke this from your polymorphic versions, e.g.: 0086 // void MyXXXSceneHandler::PreAddSolid 0087 // (const G4Transform3D& objectTransformation, 0088 // const G4VisAttributes& visAttribs) { 0089 // G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs); 0090 // ... 0091 // } 0092 0093 virtual void PostAddSolid (); 0094 // IMPORTANT: invoke this from your polymorphic versions, e.g.: 0095 // void MyXXXSceneHandler::PostAddSolid () { 0096 // ... 0097 // G4VSceneHandler::PostAddSolid (); 0098 // } 0099 0100 // From geometry/solids/CSG 0101 virtual void AddSolid (const G4Box&); 0102 virtual void AddSolid (const G4Cons&); 0103 virtual void AddSolid (const G4Orb&); 0104 virtual void AddSolid (const G4Para&); 0105 virtual void AddSolid (const G4Sphere&); 0106 virtual void AddSolid (const G4Torus&); 0107 virtual void AddSolid (const G4Trap&); 0108 virtual void AddSolid (const G4Trd&); 0109 virtual void AddSolid (const G4Tubs&); 0110 0111 // From geometry/solids/specific 0112 virtual void AddSolid (const G4Ellipsoid&); 0113 virtual void AddSolid (const G4Polycone&); 0114 virtual void AddSolid (const G4Polyhedra&); 0115 virtual void AddSolid (const G4TessellatedSolid&); 0116 0117 // For solids not above. 0118 virtual void AddSolid (const G4VSolid&); 0119 0120 /////////////////////////////////////////////////////////////////// 0121 // Methods for adding "compound" GEANT4 objects to the scene 0122 // handler. These methods may either (a) invoke "user code" that 0123 // uses the "user interface", G4VVisManager (see, for example, 0124 // G4VSceneHandler, which for trajectories uses 0125 // G4VTrajectory::DrawTrajectory, via G4TrajectoriesModel in the 0126 // Modeling Category) or (b) invoke AddPrimitives below (between 0127 // calls to Begin/EndPrimitives) or (c) use graphics-system-specific 0128 // code or (d) any combination of the above. 0129 0130 virtual void AddCompound (const G4VTrajectory&); 0131 virtual void AddCompound (const G4VHit&); 0132 virtual void AddCompound (const G4VDigi&); 0133 virtual void AddCompound (const G4THitsMap<G4double>&); 0134 virtual void AddCompound (const G4THitsMap<G4StatDouble>&); 0135 virtual void AddCompound (const G4Mesh&); 0136 0137 ////////////////////////////////////////////////////////////// 0138 // Functions for adding primitives. 0139 0140 virtual void BeginModeling (); 0141 // IMPORTANT: invoke this from your polymorphic versions, e.g.: 0142 // void MyXXXSceneHandler::BeginModeling () { 0143 // G4VSceneHandler::BeginModeling (); 0144 // ... 0145 // } 0146 0147 virtual void EndModeling (); 0148 // IMPORTANT: invoke this from your polymorphic versions, e.g.: 0149 // void MyXXXSceneHandler::EndModeling () { 0150 // ... 0151 // G4VSceneHandler::EndModeling (); 0152 // } 0153 0154 virtual void BeginPrimitives 0155 (const G4Transform3D& objectTransformation = G4Transform3D()); 0156 // IMPORTANT: invoke this from your polymorphic versions, e.g.: 0157 // void MyXXXSceneHandler::BeginPrimitives 0158 // (const G4Transform3D& objectTransformation) { 0159 // G4VSceneHandler::BeginPrimitives (objectTransformation); 0160 // ... 0161 // } 0162 0163 virtual void EndPrimitives (); 0164 // IMPORTANT: invoke this from your polymorphic versions, e.g.: 0165 // void MyXXXSceneHandler::EndPrimitives () { 0166 // ... 0167 // G4VSceneHandler::EndPrimitives (); 0168 // } 0169 0170 virtual void BeginPrimitives2D 0171 (const G4Transform3D& objectTransformation = G4Transform3D()); 0172 // The x,y coordinates of the primitives passed to AddPrimitive are 0173 // intrepreted as screen coordinates, -1 < x,y < 1. The 0174 // z-coordinate is ignored. 0175 // IMPORTANT: invoke this from your polymorphic versions, e.g.: 0176 // void MyXXXSceneHandler::BeginPrimitives2D 0177 // (const G4Transform3D& objectTransformation) { 0178 // G4VSceneHandler::BeginPrimitives2D (objectTransformation); 0179 // ... 0180 // } 0181 0182 virtual void EndPrimitives2D (); 0183 // IMPORTANT: invoke this from your polymorphic versions, e.g.: 0184 // void MyXXXSceneHandler::EndPrimitives2D () { 0185 // ... 0186 // G4VSceneHandler::EndPrimitives2D (); 0187 // } 0188 0189 virtual void AddPrimitive (const G4Polyline&) = 0; 0190 virtual void AddPrimitive (const G4Text&) = 0; 0191 virtual void AddPrimitive (const G4Circle&) = 0; 0192 virtual void AddPrimitive (const G4Square&) = 0; 0193 virtual void AddPrimitive (const G4Polymarker&); 0194 virtual void AddPrimitive (const G4Polyhedron&) = 0; 0195 virtual void AddPrimitive (const G4Plotter&); 0196 0197 // Other virtual functions 0198 virtual const G4VisExtent& GetExtent() const; 0199 0200 ////////////////////////////////////////////////////////////// 0201 // Access functions. 0202 const G4String& GetName () const; 0203 G4int GetSceneHandlerId () const; 0204 G4int GetViewCount () const; 0205 G4VGraphicsSystem* GetGraphicsSystem () const; 0206 G4Scene* GetScene () const; 0207 const G4ViewerList& GetViewerList () const; 0208 G4VModel* GetModel () const; 0209 G4VViewer* GetCurrentViewer () const; 0210 G4bool GetMarkForClearingTransientStore () const; 0211 G4bool IsReadyForTransients () const; 0212 G4bool GetTransientsDrawnThisEvent () const; 0213 G4bool GetTransientsDrawnThisRun () const; 0214 const G4Transform3D& GetObjectTransformation () const; 0215 void SetName (const G4String&); 0216 void SetCurrentViewer (G4VViewer*); 0217 virtual void SetScene (G4Scene*); 0218 G4ViewerList& SetViewerList (); // Non-const so you can change. 0219 void SetModel (G4VModel*); 0220 void SetMarkForClearingTransientStore (G4bool); 0221 // Sets flag which will cause transient store to be cleared at the 0222 // next call to BeginPrimitives(). Maintained by vis manager. 0223 void SetTransientsDrawnThisEvent (G4bool); 0224 void SetTransientsDrawnThisRun (G4bool); 0225 void SetObjectTransformation (const G4Transform3D&); 0226 // Maintained by vis manager. 0227 0228 ////////////////////////////////////////////////////////////// 0229 // Public utility functions. 0230 0231 const G4Colour& GetColour (); // To be deprecated? 0232 const G4Colour& GetColor (); 0233 // Returns colour - checks fpVisAttribs and gets applicable colour. 0234 // Assumes fpVisAttribs point to the G4VisAttributes of the current object. 0235 // If the pointer is null, the colour is obtained from the default view 0236 // parameters of the current viewer. 0237 0238 const G4Colour& GetColour (const G4Visible&); 0239 const G4Colour& GetColor (const G4Visible&); 0240 // Returns colour, or viewer default colour. 0241 // Makes no assumptions about the validity of data member fpVisAttribs. 0242 // If the G4Visible has no vis attributes, i.e., the pointer is null, 0243 // the colour is obtained from the default view parameters of the 0244 // current viewer. 0245 0246 const G4Colour& GetTextColour (const G4Text&); 0247 const G4Colour& GetTextColor (const G4Text&); 0248 // Returns colour of G4Text object, or default text colour. 0249 0250 G4double GetLineWidth(const G4VisAttributes*); 0251 // Returns line width of G4VisAttributes multiplied by GlobalLineWidthScale. 0252 0253 G4ViewParameters::DrawingStyle GetDrawingStyle (const G4VisAttributes*); 0254 // Returns drawing style from current view parameters, unless the user 0255 // has forced through the vis attributes, thereby over-riding the 0256 // current view parameter. 0257 0258 G4int GetNumberOfCloudPoints (const G4VisAttributes*) const; 0259 // Returns no of cloud points from current view parameters, unless the user 0260 // has forced through the vis attributes, thereby over-riding the 0261 // current view parameter. 0262 0263 G4bool GetAuxEdgeVisible (const G4VisAttributes*); 0264 // Returns auxiliary edge visibility from current view parameters, 0265 // unless the user has forced through the vis attributes, thereby 0266 // over-riding the current view parameter. 0267 0268 G4int GetNoOfSides(const G4VisAttributes*); 0269 // Returns no. of sides (lines segments per circle) from current 0270 // view parameters, unless the user has forced through the vis 0271 // attributes, thereby over-riding the current view parameter. 0272 0273 G4double GetMarkerSize (const G4VMarker&, MarkerSizeType&); 0274 // Returns applicable marker size (diameter) and type (in second 0275 // argument). Uses global default marker if marker sizes are not 0276 // set. Multiplies by GlobalMarkerScale. 0277 0278 G4double GetMarkerDiameter (const G4VMarker&, MarkerSizeType&); 0279 // Alias for GetMarkerSize. 0280 0281 G4double GetMarkerRadius (const G4VMarker&, MarkerSizeType&); 0282 // GetMarkerSize / 2. 0283 0284 G4ModelingParameters* CreateModelingParameters (); 0285 // Only the scene handler and view know what the Modeling Parameters should 0286 // be. For historical reasons, the GEANT4 Visualization Environment 0287 // maintains its own Scene Data and View Parameters, which must be 0288 // converted, when needed, to Modeling Parameters. 0289 0290 void DrawEvent(const G4Event*); 0291 // Checks scene's end-of-event model list and draws trajectories, 0292 // hits, etc. 0293 0294 void DrawEndOfRunModels(); 0295 // Draws end-of-run models. 0296 0297 ////////////////////////////////////////////////////////////// 0298 // Administration functions. 0299 0300 template <class T> void AddSolidT (const T& solid); 0301 template <class T> void AddSolidWithAuxiliaryEdges (const T& solid); 0302 0303 G4int IncrementViewCount (); 0304 0305 virtual void ClearStore (); 0306 // Clears graphics database (display lists) if any. 0307 0308 virtual void ClearTransientStore (); 0309 // Clears transient part of graphics database (display lists) if any. 0310 0311 void AddViewerToList (G4VViewer* pView); // Add view to view List. 0312 void RemoveViewerFromList (G4VViewer* pView); // Remove view from view List. 0313 0314 protected: 0315 0316 ////////////////////////////////////////////////////////////// 0317 // Core routine for looping over models, redrawing stored events, etc. 0318 // Overload with care (see, for example, 0319 // G4OpenGLScenehandler::ProcessScene). 0320 virtual void ProcessScene (); 0321 0322 ////////////////////////////////////////////////////////////// 0323 // Default routine used by default AddSolid (). 0324 virtual void RequestPrimitives (const G4VSolid& solid); 0325 0326 ////////////////////////////////////////////////////////////// 0327 // Other internal routines... 0328 0329 virtual G4DisplacedSolid* CreateSectionSolid (); 0330 virtual G4DisplacedSolid* CreateCutawaySolid (); 0331 // Generic clipping using the BooleanProcessor in graphics_reps is 0332 // implemented in this class. Subclasses that implement their own 0333 // clipping should provide an override that returns zero. 0334 0335 void LoadAtts(const G4Visible&, G4AttHolder*); 0336 // Load G4AttValues and G4AttDefs associated with the G4Visible 0337 // object onto the G4AttHolder object. It checks fpModel, and also 0338 // loads the G4AttValues and G4AttDefs from G4PhysicalVolumeModel, 0339 // G4VTrajectory, G4VTrajectoryPoint, G4VHit or G4VDigi, as 0340 // appropriate. The G4AttHolder object is an object of a class that 0341 // publicly inherits G4AttHolder - see, e.g., SoG4Polyhedron in the 0342 // Open Inventor driver. G4AttHolder deletes G4AttValues in its 0343 // destructor to ensure proper clean-up of G4AttValues. 0344 0345 ////////////////////////////////////////////////////////////// 0346 // Special mesh rendering utilities... 0347 0348 struct NameAndVisAtts { 0349 NameAndVisAtts(const G4String& name = "",const G4VisAttributes& visAtts = G4VisAttributes()) 0350 : fName(name),fVisAtts(visAtts) {} 0351 G4String fName; 0352 G4VisAttributes fVisAtts; 0353 }; 0354 0355 class PseudoSceneFor3DRectMeshPositions: public G4PseudoScene { 0356 public: 0357 PseudoSceneFor3DRectMeshPositions 0358 (G4PhysicalVolumeModel* pvModel // input 0359 , const G4Mesh* pMesh // input...the following are outputs by reference 0360 , std::multimap<const G4Material*,const G4ThreeVector>& positionByMaterial 0361 , std::map<const G4Material*,NameAndVisAtts>& nameAndVisAttsByMaterial) 0362 : fpPVModel(pvModel) 0363 , fpMesh(pMesh) 0364 , fPositionByMaterial(positionByMaterial) 0365 , fNameAndVisAttsByMaterial(nameAndVisAttsByMaterial) 0366 {} 0367 private: 0368 using G4PseudoScene::AddSolid; // except for... 0369 void AddSolid(const G4Box&) override; 0370 void ProcessVolume(const G4VSolid&) override { 0371 // Do nothing if uninteresting solids found, e.g., the container if not marked invisible. 0372 } 0373 G4PhysicalVolumeModel* fpPVModel; 0374 const G4Mesh* fpMesh; 0375 std::multimap<const G4Material*,const G4ThreeVector>& fPositionByMaterial; 0376 std::map<const G4Material*,NameAndVisAtts>& fNameAndVisAttsByMaterial; 0377 }; 0378 0379 class PseudoSceneForTetVertices: public G4PseudoScene { 0380 public: 0381 PseudoSceneForTetVertices 0382 (G4PhysicalVolumeModel* pvModel // input 0383 , const G4Mesh* pMesh // input...the following are outputs by reference 0384 , std::multimap<const G4Material*,std::vector<G4ThreeVector>>& verticesByMaterial 0385 , std::map<const G4Material*,NameAndVisAtts>& nameAndVisAttsByMaterial) 0386 : fpPVModel(pvModel) 0387 , fpMesh(pMesh) 0388 , fVerticesByMaterial(verticesByMaterial) 0389 , fNameAndVisAttsByMaterial(nameAndVisAttsByMaterial) 0390 {} 0391 private: 0392 using G4PseudoScene::AddSolid; // except for... 0393 void AddSolid(const G4VSolid& solid) override; 0394 void ProcessVolume(const G4VSolid&) override { 0395 // Do nothing if uninteresting solids found, e.g., the container if not marked invisible. 0396 } 0397 G4PhysicalVolumeModel* fpPVModel; 0398 const G4Mesh* fpMesh; 0399 std::multimap<const G4Material*,std::vector<G4ThreeVector>>& fVerticesByMaterial; 0400 std::map<const G4Material*,NameAndVisAtts>& fNameAndVisAttsByMaterial; 0401 }; 0402 0403 void StandardSpecialMeshRendering(const G4Mesh&); 0404 // Standard way of special mesh rendering. 0405 // MySceneHandler::AddCompound(const G4Mesh& mesh) may use this if 0406 // appropriate or implement its own special mesh rendereing. 0407 0408 void Draw3DRectMeshAsDots(const G4Mesh&); 0409 // For a rectangular 3-D mesh, draw as coloured dots by colour and material, 0410 // one dot randomly placed in each visible mesh cell. 0411 0412 void Draw3DRectMeshAsSurfaces(const G4Mesh&); 0413 // For a rectangular 3-D mesh, draw as surfaces by colour and material 0414 // with inner shared faces removed. 0415 0416 void DrawTetMeshAsDots(const G4Mesh&); 0417 // For a tetrahedron mesh, draw as coloured dots by colour and material, 0418 // one dot randomly placed in each visible mesh cell. 0419 0420 void DrawTetMeshAsSurfaces(const G4Mesh&); 0421 // For a tetrahedron mesh, draw as surfaces by colour and material 0422 // with inner shared faces removed. 0423 0424 G4ThreeVector GetPointInBox(const G4ThreeVector& pos, 0425 G4double halfX, 0426 G4double halfY, 0427 G4double halfZ) const; 0428 // Sample a random point inside the box 0429 0430 G4ThreeVector GetPointInTet(const std::vector<G4ThreeVector>& vertices) const; 0431 // Sample a random point inside the tetrahedron 0432 0433 ////////////////////////////////////////////////////////////// 0434 // Data members 0435 0436 G4VGraphicsSystem& fSystem; // Graphics system. 0437 const G4int fSceneHandlerId; // Id of this instance. 0438 G4String fName; 0439 G4int fViewCount; // To determine view ids. 0440 G4ViewerList fViewerList; // Viewers. 0441 G4VViewer* fpViewer; // Current viewer. 0442 G4Scene* fpScene; // Scene for this scene handler. 0443 G4bool fMarkForClearingTransientStore; 0444 G4bool fReadyForTransients; // I.e., not processing the 0445 // run-duration part of scene. 0446 G4bool fTransientsDrawnThisEvent; // Maintained by vis 0447 G4bool fTransientsDrawnThisRun; // manager. 0448 G4bool fProcessingSolid; // True if within Pre/PostAddSolid. 0449 G4bool fProcessing2D; // True for 2D. 0450 G4VModel* fpModel; // Current model. 0451 G4Transform3D fObjectTransformation; // Current accumulated 0452 // object transformation. 0453 G4int fNestingDepth; // For Begin/EndPrimitives. 0454 const G4VisAttributes* fpVisAttribs; // Working vis attributes. 0455 const G4Transform3D fIdentityTransformation; 0456 std::map<G4VPhysicalVolume*,G4String> fProblematicVolumes; 0457 0458 private: 0459 0460 G4VSceneHandler (const G4VSceneHandler&); 0461 G4VSceneHandler& operator = (const G4VSceneHandler&); 0462 }; 0463 0464 #include "G4VSceneHandler.icc" 0465 0466 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |