G4PhysicalVolumeModel.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // John Allison  31st December 1997.
00031 //
00032 // Class Description:
00033 //
00034 // Model for physical volumes.  It describes a physical volume and its
00035 // daughters to any desired depth.  Note: the "requested depth" is
00036 // specified in the modeling parameters; enum {UNLIMITED = -1}.
00037 //
00038 // For access to base class information, e.g., modeling parameters,
00039 // use GetModelingParameters() inherited from G4VModel.  See Class
00040 // Description of the base class G4VModel.
00041 //
00042 // G4PhysicalVolumeModel assumes the modeling parameters have been set
00043 // up with meaningful information - default vis attributes and culling
00044 // policy in particular.
00045 //
00046 // The volumes are unpacked and sent to the scene handler.  They are,
00047 // in effect, "touchables" as defined by G4TouchableHistory.  A
00048 // touchable is defined not only by its physical volume name and copy
00049 // number but also by its position in the geometry hierarchy.
00050 //
00051 // It is guaranteed that touchables are presented to the scene handler
00052 // in top-down hierarchy order, i.e., ancesters first, mothers before
00053 // daughters, so the scene handler can be assured that, if it is
00054 // building its own scene graph tree, a mother, if any, will have
00055 // already been encountered and there will already be a node in place
00056 // on which to hang the current volume.  But be aware that the
00057 // visibility and culling policy might mean that some touchables are
00058 // not passed to the scene handler so the drawn tree might have
00059 // missing layers.  GetFullPVPath allows you to know the full
00060 // hierarchy.
00061 
00062 #ifndef G4PHYSICALVOLUMEMODEL_HH
00063 #define G4PHYSICALVOLUMEMODEL_HH
00064 
00065 #include "G4VModel.hh"
00066 #include "G4VTouchable.hh"
00067 
00068 #include "G4Transform3D.hh"
00069 #include "G4Plane3D.hh"
00070 #include <iostream>
00071 #include <vector>
00072 #include <map>
00073 
00074 class G4VPhysicalVolume;
00075 class G4LogicalVolume;
00076 class G4VSolid;
00077 class G4Material;
00078 class G4VisAttributes;
00079 class G4AttDef;
00080 class G4AttValue;
00081 
00082 class G4PhysicalVolumeModel: public G4VModel {
00083 
00084 public: // With description
00085 
00086   enum {UNLIMITED = -1};
00087 
00088   enum ClippingMode {subtraction, intersection};
00089 
00090   class G4PhysicalVolumeNodeID {
00091   public:
00092     G4PhysicalVolumeNodeID
00093     (G4VPhysicalVolume* pPV = 0,
00094      G4int iCopyNo = 0,
00095      G4int depth = 0,
00096      const G4Transform3D& transform = G4Transform3D(),
00097      G4bool drawn = true):
00098       fpPV(pPV),
00099       fCopyNo(iCopyNo),
00100       fNonCulledDepth(depth),
00101       fTransform(transform),
00102       fDrawn(drawn) {}
00103     G4VPhysicalVolume* GetPhysicalVolume() const {return fpPV;}
00104     G4int GetCopyNo() const {return fCopyNo;}
00105     G4int GetNonCulledDepth() const {return fNonCulledDepth;}
00106     const G4Transform3D& GetTransform() const {return fTransform;}
00107     G4bool GetDrawn() const {return fDrawn;}
00108     void SetDrawn(G4bool drawn) {fDrawn = drawn;}
00109     G4bool operator< (const G4PhysicalVolumeNodeID& right) const;
00110   private:
00111     G4VPhysicalVolume* fpPV;
00112     G4int fCopyNo;
00113     G4int fNonCulledDepth;
00114     G4Transform3D fTransform;
00115     G4bool fDrawn;
00116   };
00117   // Nested class for identifying physical volume nodes.
00118 
00119   class G4PhysicalVolumeModelTouchable: public G4VTouchable {
00120   public:
00121     G4PhysicalVolumeModelTouchable
00122     (const std::vector<G4PhysicalVolumeNodeID>& fullPVPath);
00123     const G4ThreeVector& GetTranslation(G4int depth) const;
00124     const G4RotationMatrix* GetRotation(G4int depth) const;
00125     G4VPhysicalVolume* GetVolume(G4int depth) const;
00126     G4VSolid* GetSolid(G4int depth) const;
00127     G4int GetReplicaNumber(G4int depth) const;
00128     G4int GetHistoryDepth() const {return fFullPVPath.size();}
00129   private:
00130     const std::vector<G4PhysicalVolumeNodeID>& fFullPVPath;
00131   };
00132   // Nested class for handling nested parameterisations.
00133 
00134   G4PhysicalVolumeModel
00135   (G4VPhysicalVolume* = 0,
00136    G4int requestedDepth = UNLIMITED,
00137    const G4Transform3D& modelTransformation = G4Transform3D(),
00138    const G4ModelingParameters* = 0,
00139    G4bool useFullExtent = false);
00140 
00141   virtual ~G4PhysicalVolumeModel ();
00142 
00143   void DescribeYourselfTo (G4VGraphicsScene&);
00144   // The main task of a model is to describe itself to the graphics scene
00145   // handler (a object which inherits G4VSceneHandler, which inherits
00146   // G4VGraphicsScene).
00147 
00148   G4String GetCurrentDescription () const;
00149   // A description which depends on the current state of the model.
00150 
00151   G4String GetCurrentTag () const;
00152   // A tag which depends on the current state of the model.
00153 
00154   G4VPhysicalVolume* GetTopPhysicalVolume () const {return fpTopPV;}
00155 
00156   G4int GetRequestedDepth () const {return fRequestedDepth;}
00157 
00158   const G4VSolid* GetClippingSolid () const
00159   {return fpClippingSolid;}
00160 
00161   G4int GetCurrentDepth() const {return fCurrentDepth;}
00162   // Current depth of geom. hierarchy.
00163 
00164   G4VPhysicalVolume* GetCurrentPV() const {return fpCurrentPV;}
00165   // Current physical volume.
00166 
00167   G4LogicalVolume* GetCurrentLV() const {return fpCurrentLV;}
00168   // Current logical volume.
00169 
00170   G4Material* GetCurrentMaterial() const {return fpCurrentMaterial;}
00171   // Current material.
00172 
00173   const std::vector<G4PhysicalVolumeNodeID>& GetFullPVPath() const
00174   {return fFullPVPath;}
00175   // Vector of physical volume node identifiers for the current
00176   // touchable.  It is its path in the geometry hierarchy, similar to
00177   // the concept of "touchable history" available from the navigator
00178   // during tracking.
00179 
00180   const std::vector<G4PhysicalVolumeNodeID>& GetDrawnPVPath() const
00181   {return fDrawnPVPath;}
00182   // Path of the current drawn (non-culled) touchable in terms of
00183   // drawn (non-culled) ancesters.  It is a vector of physical volume
00184   // node identifiers corresponding to the geometry hierarchy actually
00185   // selected, i.e., not culled.
00186 
00187   const std::map<G4String,G4AttDef>* GetAttDefs() const;
00188   // Attribute definitions for current solid.
00189 
00190   std::vector<G4AttValue>* CreateCurrentAttValues() const;
00191   // Attribute values for current solid.  Each must refer to an
00192   // attribute definition in the above map; its name is the key.  The
00193   // user must test the validity of this pointer (it must be non-zero
00194   // and conform to the G4AttDefs, which may be checked with
00195   // G4AttCheck) and delete the list after use.  See
00196   // G4XXXStoredSceneHandler::PreAddSolid for how to access and
00197   // G4VTrajectory::ShowTrajectory for an example of the use of
00198   // G4Atts.
00199   
00200   void SetBaseFullPVPath
00201     (const std::vector<G4PhysicalVolumeNodeID>&
00202      baseFullPVPath) {
00203       fBaseFullPVPath = baseFullPVPath;
00204       fFullPVPath = baseFullPVPath;
00205   }
00206 
00207   void SetRequestedDepth (G4int requestedDepth) {
00208     fRequestedDepth = requestedDepth;
00209   }
00210 
00211   void SetClippingSolid (G4VSolid* pClippingSolid) {
00212     fpClippingSolid = pClippingSolid;
00213   }
00214 
00215   void SetClippingMode (ClippingMode mode) {
00216     fClippingMode = mode;
00217   }
00218 
00219   G4bool Validate (G4bool warn);
00220   // Validate, but allow internal changes (hence non-const function).
00221 
00222   void CurtailDescent() {fCurtailDescent = true;}
00223 
00224 protected:
00225 
00226   void VisitGeometryAndGetVisReps (G4VPhysicalVolume*,
00227                                    G4int requestedDepth,
00228                                    const G4Transform3D&,
00229                                    G4VGraphicsScene&);
00230 
00231   void DescribeAndDescend (G4VPhysicalVolume*,
00232                            G4int requestedDepth,
00233                            G4LogicalVolume*,
00234                            G4VSolid*,
00235                            G4Material*,
00236                            const G4Transform3D&,
00237                            G4VGraphicsScene&);
00238 
00239   virtual void DescribeSolid (const G4Transform3D& theAT,
00240                               G4VSolid* pSol,
00241                               const G4VisAttributes* pVisAttribs,
00242                               G4VGraphicsScene& sceneHandler);
00243 
00244   void CalculateExtent ();
00245 
00247   // Data members...
00248 
00249   G4VPhysicalVolume* fpTopPV;        // The physical volume.
00250   G4String           fTopPVName;     // ...of the physical volume.
00251   G4int              fTopPVCopyNo;   // ...of the physical volume.
00252   G4int              fRequestedDepth;
00253                      // Requested depth of geom. hierarchy search.
00254   G4bool             fUseFullExtent; // ...if requested.
00255   G4int              fCurrentDepth;  // Current depth of geom. hierarchy.
00256   G4VPhysicalVolume* fpCurrentPV;    // Current physical volume.
00257   G4LogicalVolume*   fpCurrentLV;    // Current logical volume.
00258   G4Material*    fpCurrentMaterial;  // Current material.
00259   G4Transform3D* fpCurrentTransform; // Current transform.
00260   std::vector<G4PhysicalVolumeNodeID> fBaseFullPVPath;
00261   std::vector<G4PhysicalVolumeNodeID> fFullPVPath;
00262   std::vector<G4PhysicalVolumeNodeID> fDrawnPVPath;
00263   G4bool             fCurtailDescent;// Can be set to curtail descent.
00264   G4VSolid*          fpClippingSolid;
00265   ClippingMode       fClippingMode;
00266 
00267 private:
00268 
00269   // Private copy constructor and assigment operator - copying and
00270   // assignment not allowed.  Keeps CodeWizard happy.
00271   G4PhysicalVolumeModel (const G4PhysicalVolumeModel&);
00272   G4PhysicalVolumeModel& operator = (const G4PhysicalVolumeModel&);
00273 };
00274 
00275 std::ostream& operator<<
00276   (std::ostream& os, const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID);
00277 
00278 #endif

Generated on Mon May 27 17:49:19 2013 for Geant4 by  doxygen 1.4.7