G4LogicalVolumeModel.cc

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  26th July 1999.
00031 // Model for logical volumes.
00032 
00033 #include "G4LogicalVolumeModel.hh"
00034 
00035 #include "G4VSolid.hh"
00036 #include "G4LogicalVolume.hh"
00037 #include "G4PVPlacement.hh"
00038 #include "G4ModelingParameters.hh"
00039 #include "G4VGraphicsScene.hh"
00040 #include "G4DrawVoxels.hh"
00041 #include "G4VSensitiveDetector.hh"
00042 #include "G4VReadOutGeometry.hh"
00043 
00044 G4LogicalVolumeModel::G4LogicalVolumeModel
00045 (G4LogicalVolume*            pLV,
00046  G4int                       soughtDepth,
00047  G4bool                      booleans,
00048  G4bool                      voxels,
00049  G4bool                      readout,
00050  const G4Transform3D&        modelTransformation,
00051  const G4ModelingParameters* pMP):
00052   // Instantiate a G4PhysicalVolumeModel with a G4PVPlacement to
00053   // represent this logical volume.  It has no rotation and a null
00054   // translation so that the logical volume will be seen in its own
00055   // reference system.  It will be added to the physical volume store
00056   // but it will not be part of the normal geometry heirarchy so it
00057   // has no mother.
00058   G4PhysicalVolumeModel
00059 (new G4PVPlacement (0,                   // No rotation.
00060                     G4ThreeVector(),     // Null traslation.
00061                     "PhysVol representation of LogVol " + pLV -> GetName (),
00062                     pLV,
00063                     0,                   // No mother.
00064                     false,               // Not "MANY".
00065                     0),                  // Copy number.
00066  soughtDepth,
00067  modelTransformation,
00068  pMP,
00069  true),                                  // Use full extent.
00070   fpLV (pLV),
00071   fBooleans (booleans),
00072   fVoxels (voxels),
00073   fReadout (readout)
00074 {
00075   fType = "G4LogicalVolumeModel";
00076   fGlobalTag = fpLV -> GetName ();
00077   fGlobalDescription = "G4LogicalVolumeModel " + fGlobalTag;
00078 }
00079 
00080 G4LogicalVolumeModel::~G4LogicalVolumeModel () {}
00081 
00082 void G4LogicalVolumeModel::DescribeYourselfTo
00083 (G4VGraphicsScene& sceneHandler) {
00084 
00085   // Store current modeling parameters and ensure nothing is culled.
00086   const G4ModelingParameters* tmpMP = fpMP;
00087   G4ModelingParameters nonCulledMP;
00088   if (fpMP) nonCulledMP = *fpMP;
00089   nonCulledMP.SetCulling (false);
00090   fpMP = &nonCulledMP;    
00091   G4PhysicalVolumeModel::DescribeYourselfTo (sceneHandler);
00092   fpMP = tmpMP;
00093 
00094   if (fVoxels) {
00095     if (fpTopPV->GetLogicalVolume()->GetVoxelHeader()) {
00096       // Add Voxels.
00097       G4DrawVoxels dv;
00098       G4PlacedPolyhedronList* pPPL =
00099         dv.CreatePlacedPolyhedra (fpTopPV -> GetLogicalVolume ());
00100       for (size_t i = 0; i < pPPL -> size (); i++) {
00101         const G4Transform3D& transform = (*pPPL)[i].GetTransform ();
00102         const G4Polyhedron& polyhedron = (*pPPL)[i].GetPolyhedron ();
00103         sceneHandler.BeginPrimitives (transform);
00104         sceneHandler.AddPrimitive (polyhedron);
00105         sceneHandler.EndPrimitives ();
00106       }
00107       delete pPPL;
00108     }
00109   }
00110 
00111   if (fReadout) {
00112     // Draw readout geometry...
00113     G4VSensitiveDetector* sd = fpLV->GetSensitiveDetector();
00114     if (sd) {
00115       G4VReadOutGeometry* roGeom = sd->GetROgeometry();
00116       if (roGeom) {
00117         G4VPhysicalVolume* roWorld = roGeom->GetROWorld();
00118         G4cout << "Readout geometry \"" << roGeom->GetName()
00119                << "\" with top physical volume \""
00120                << roWorld->GetName()
00121                << "\"" << G4endl;
00122         G4PhysicalVolumeModel pvModel(roWorld);
00123         pvModel.SetModelingParameters(fpMP);
00124         pvModel.DescribeYourselfTo(sceneHandler);
00125       }
00126     }
00127   }
00128 }
00129 
00130 // This called from G4PhysicalVolumeModel::DescribeAndDescend by the
00131 // virtual function mechanism.
00132 void G4LogicalVolumeModel::DescribeSolid
00133 (const G4Transform3D& theAT,
00134  G4VSolid* pSol,
00135  const G4VisAttributes* pVisAttribs,
00136  G4VGraphicsScene& sceneHandler) {
00137 
00138   if (fBooleans) {
00139     // Look for "constituents".  Could be a Boolean solid.
00140     G4VSolid* pSol0 = pSol -> GetConstituentSolid (0);
00141     if (pSol0) {  // Composite solid...
00142       G4VSolid* pSol1 = pSol -> GetConstituentSolid (1);
00143       if (!pSol1) {
00144         G4Exception
00145           ("G4PhysicalVolumeModel::DescribeSolid",
00146            "modeling0001", FatalException,
00147            "2nd component solid in Boolean is missing.");
00148       }
00149       // Draw these constituents white and "forced wireframe"...
00150       G4VisAttributes constituentAttributes;
00151       constituentAttributes.SetForceWireframe(true);
00152       DescribeSolid (theAT, pSol0, &constituentAttributes, sceneHandler);
00153       DescribeSolid (theAT, pSol1, &constituentAttributes, sceneHandler);
00154     }
00155   }
00156 
00157   // In any case draw the original/resultant solid...
00158   sceneHandler.PreAddSolid (theAT, *pVisAttribs);
00159   pSol -> DescribeYourselfTo (sceneHandler);
00160   sceneHandler.PostAddSolid ();
00161 }

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