Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4UAdapter.icc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 // G4UAdapter inline implementation.
0027 //
0028 // Author: Gabriele Cosmo (CERN), 17.05.2017
0029 // --------------------------------------------------------------------
0030 
0031 template <class UnplacedVolume_t>
0032 G4UAdapter<UnplacedVolume_t>::G4UAdapter(const G4String& name)
0033   : G4VSolid(name)
0034 {
0035   kHalfTolerance = 0.5*kCarTolerance;
0036 }
0037 
0038 template <class UnplacedVolume_t>
0039 template <typename... T>
0040 G4UAdapter<UnplacedVolume_t>::G4UAdapter(const G4String& name,
0041                                          const T &... params)
0042   : G4VSolid(name), UnplacedVolume_t(params...)
0043 {
0044   kHalfTolerance = 0.5*kCarTolerance;
0045 }
0046 
0047 template <class UnplacedVolume_t>
0048 G4UAdapter<UnplacedVolume_t>::~G4UAdapter()
0049 {
0050   delete fPolyhedron; fPolyhedron = nullptr;
0051 }
0052 
0053 template <class UnplacedVolume_t>
0054 G4bool G4UAdapter<UnplacedVolume_t>::
0055 operator==(const G4UAdapter& rhs) const
0056 {
0057   return (this == &rhs) ? true : false;
0058 }
0059 
0060 template <class UnplacedVolume_t>
0061 G4UAdapter<UnplacedVolume_t>::
0062 G4UAdapter(const G4UAdapter& rhs)
0063   : G4VSolid(rhs), UnplacedVolume_t(rhs)
0064 {
0065   kHalfTolerance = 0.5*kCarTolerance;
0066 }
0067 
0068 template <class UnplacedVolume_t>
0069 G4UAdapter<UnplacedVolume_t>& G4UAdapter<UnplacedVolume_t>::
0070 operator=(const G4UAdapter& rhs)
0071 {
0072   // Check assignment to self
0073   //
0074   if (this == &rhs)
0075   {
0076     return *this;
0077   }
0078 
0079   // Copy base class data
0080   //
0081   G4VSolid::operator=(rhs);
0082   UnplacedVolume_t::operator=(rhs);
0083 
0084   // Copy data
0085   //
0086   fRebuildPolyhedron = false;
0087   delete fPolyhedron; fPolyhedron = nullptr;
0088   kHalfTolerance = 0.5*kCarTolerance;
0089 
0090   return *this;
0091 }
0092 
0093 template <class UnplacedVolume_t>
0094 EInside G4UAdapter<UnplacedVolume_t>::
0095 Inside(const G4ThreeVector& p) const
0096 {
0097   U3Vector pt(p.x(), p.y(), p.z());
0098   vecgeom::EnumInside in_temp;
0099   EInside in = kOutside;
0100 
0101   in_temp = UnplacedVolume_t::Inside(pt);
0102 
0103   if (in_temp == vecgeom::EnumInside::eInside) in = kInside;
0104   else if (in_temp == vecgeom::EnumInside::eSurface) in = kSurface;
0105 
0106   return in;
0107 }
0108 
0109 template <class UnplacedVolume_t>
0110 G4ThreeVector G4UAdapter<UnplacedVolume_t>::
0111 SurfaceNormal(const G4ThreeVector& pt) const
0112 {
0113   U3Vector p(pt.x(), pt.y(), pt.z());
0114   U3Vector n;
0115   UnplacedVolume_t::Normal(p, n);
0116   return G4ThreeVector(n.x(), n.y(), n.z());
0117 }
0118 
0119 template <class UnplacedVolume_t>
0120 G4double G4UAdapter<UnplacedVolume_t>::
0121 DistanceToIn(const G4ThreeVector& pt, const G4ThreeVector& d) const
0122 {
0123   U3Vector p(pt.x(), pt.y(), pt.z());
0124   U3Vector v(d.x(), d.y(), d.z());
0125   G4double dist = UnplacedVolume_t::DistanceToIn(p, v, kInfinity);
0126 
0127   // apply Geant4 distance conventions
0128   //
0129   if (dist < kHalfTolerance)  return 0.0;
0130   return (dist > kInfinity) ? kInfinity : dist;
0131 }
0132 
0133 template <class UnplacedVolume_t>
0134 G4double G4UAdapter<UnplacedVolume_t>::
0135 DistanceToIn(const G4ThreeVector& pt) const
0136 {
0137   U3Vector p(pt.x(), pt.y(), pt.z());
0138   G4double dist = UnplacedVolume_t::SafetyToIn(p);
0139 
0140   // Apply Geant4 convention: convert negative values to zero
0141   //
0142   if (dist < kHalfTolerance)  return 0.0;
0143   return (dist > kInfinity) ? kInfinity : dist;
0144 }
0145 
0146 template <class UnplacedVolume_t>
0147 G4double G4UAdapter<UnplacedVolume_t>::
0148 DistanceToOut(const G4ThreeVector& pt, const G4ThreeVector& d,
0149               const G4bool calcNorm, G4bool* validNorm,
0150                     G4ThreeVector* norm) const
0151 {
0152   U3Vector p(pt.x(), pt.y(), pt.z());
0153   U3Vector v(d.x(), d.y(), d.z());
0154 
0155   G4double dist = UnplacedVolume_t::DistanceToOut(p, v, kInfinity);
0156   if(calcNorm)
0157   {
0158     *validNorm = UnplacedVolume_t::IsConvex();
0159     U3Vector n, hitpoint = p + dist * v;
0160     UnplacedVolume_t::Normal(hitpoint, n);
0161     norm->set(n.x(), n.y(), n.z());
0162   }
0163 
0164   // Apply Geant4 distance conventions
0165   //
0166   if (dist < kHalfTolerance)  return 0.0;
0167   return (dist > kInfinity) ? kInfinity : dist;
0168 }
0169 
0170 template <class UnplacedVolume_t>
0171 G4double G4UAdapter<UnplacedVolume_t>::
0172 DistanceToOut(const G4ThreeVector& pt) const
0173 {
0174   U3Vector p(pt.x(), pt.y(), pt.z());
0175   G4double dist = UnplacedVolume_t::SafetyToOut(p);
0176 
0177   // Apply Geant4 convention: convert negative values to zero
0178   //
0179   if (dist < kHalfTolerance)  return 0.0;
0180   return (dist > kInfinity) ? kInfinity : dist;
0181 }
0182 
0183 template <class UnplacedVolume_t>
0184 G4double G4UAdapter<UnplacedVolume_t>::GetCubicVolume()
0185 {
0186   return UnplacedVolume_t::Capacity();
0187 }
0188 
0189 template <class UnplacedVolume_t>
0190 G4double G4UAdapter<UnplacedVolume_t>::GetSurfaceArea()
0191 {
0192   return UnplacedVolume_t::SurfaceArea();
0193 }
0194 
0195 template <class UnplacedVolume_t>
0196 G4ThreeVector G4UAdapter<UnplacedVolume_t>::GetPointOnSurface() const
0197 {
0198   U3Vector p = UnplacedVolume_t::SamplePointOnSurface();
0199   return G4ThreeVector(p.x(), p.y(), p.z());
0200 }
0201 
0202 template <class UnplacedVolume_t>
0203 G4int G4UAdapter<UnplacedVolume_t>::GetNumOfConstituents() const
0204 {
0205   return 1;
0206 }
0207 
0208 template <class UnplacedVolume_t>
0209 G4bool G4UAdapter<UnplacedVolume_t>::IsFaceted() const
0210 {
0211   return false;
0212 }
0213 
0214 // Inline visualization adapters
0215 
0216 namespace
0217 {
0218   G4Mutex pMutex = G4MUTEX_INITIALIZER;
0219 }
0220 
0221 // Free function to enable ostream output
0222 template <class UnplacedVolume_t>
0223 std::ostream&
0224 operator<<(std::ostream& os, const G4UAdapter<UnplacedVolume_t>& uAdapted)
0225 {
0226   return uAdapted.StreamInfo(os);
0227 }
0228 
0229 template <class UnplacedVolume_t>
0230 void G4UAdapter<UnplacedVolume_t>::
0231 ComputeDimensions(G4VPVParameterisation*, const G4int,
0232                                           const G4VPhysicalVolume*)
0233 {
0234     std::ostringstream message;
0235     message << "Illegal call to G4UAdapter::ComputeDimensions()" << G4endl
0236             << "Method not overloaded by derived class !";
0237     G4Exception("G4UAdapter::ComputeDimensions()", "GeomSolids0003",
0238                 FatalException, message);
0239 }
0240 
0241 template <class UnplacedVolume_t>
0242 void G4UAdapter<UnplacedVolume_t>::
0243 DescribeYourselfTo(G4VGraphicsScene& scene) const
0244 {
0245   scene.AddSolid(*this);
0246 }
0247 
0248 template <class UnplacedVolume_t>
0249 G4GeometryType G4UAdapter<UnplacedVolume_t>::
0250 GetEntityType() const
0251 {
0252 
0253   G4String string = "VSolid"; // UnplacedVolume_t::GetEntityType();
0254   return "G4" + string;
0255 }
0256 
0257 template <class UnplacedVolume_t>
0258 std::ostream& G4UAdapter<UnplacedVolume_t>::
0259 StreamInfo(std::ostream& os) const
0260 {
0261   UnplacedVolume_t::Print(os);
0262   return os;
0263 }
0264 
0265 template <class UnplacedVolume_t>
0266 G4VSolid* G4UAdapter<UnplacedVolume_t>::Clone() const
0267 {
0268   std::ostringstream message;
0269   message << "Clone() method not implemented for type: "
0270           << GetEntityType() << "!" << G4endl
0271           << "Returning NULL pointer!";
0272   G4Exception("G4UAdapter::Clone()", "GeomSolids1001", JustWarning, message);
0273   return nullptr;
0274 }
0275 
0276 template <class UnplacedVolume_t>
0277 G4bool G4UAdapter<UnplacedVolume_t>::CalculateExtent(const EAxis pAxis,
0278                                    const G4VoxelLimits& pVoxelLimit,
0279                                    const G4AffineTransform& pTransform,
0280                                    G4double& pMin, G4double& pMax) const
0281 {
0282   U3Vector vmin, vmax;
0283   UnplacedVolume_t::Extent(vmin,vmax);
0284   G4ThreeVector bmin(vmin.x(),vmin.y(),vmin.z());
0285   G4ThreeVector bmax(vmax.x(),vmax.y(),vmax.z());
0286 
0287   // Check correctness of the bounding box
0288   //
0289   if (bmin.x() >= bmax.x() || bmin.y() >= bmax.y() || bmin.z() >= bmax.z())
0290   {
0291     std::ostringstream message;
0292     message << "Bad bounding box (min >= max) for solid: "
0293             << GetName() << " - " << GetEntityType() << " !"
0294             << "\nmin = " << bmin
0295             << "\nmax = " << bmax;
0296     G4Exception("G4UAdapter::CalculateExtent()", "GeomMgt0001",
0297                 JustWarning, message);
0298     StreamInfo(G4cout);
0299   }
0300 
0301   G4BoundingEnvelope bbox(bmin,bmax);
0302   return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
0303 }
0304 
0305 template <class UnplacedVolume_t>
0306 G4Polyhedron* G4UAdapter<UnplacedVolume_t>::CreatePolyhedron() const
0307 {
0308   // Must be implemented in concrete wrappers...
0309 
0310   std::ostringstream message;
0311   message << "Visualization not supported for USolid shape "
0312           << GetEntityType() << "... Sorry!" << G4endl;
0313   G4Exception("G4UAdapter::CreatePolyhedron()", "GeomSolids0003",
0314               FatalException, message);
0315   return nullptr;
0316 }
0317 
0318 template <class UnplacedVolume_t>
0319 G4Polyhedron* G4UAdapter<UnplacedVolume_t>::GetPolyhedron() const
0320 {
0321   if (!fPolyhedron ||
0322       fRebuildPolyhedron ||
0323       fPolyhedron->GetNumberOfRotationStepsAtTimeOfCreation() !=
0324       fPolyhedron->GetNumberOfRotationSteps())
0325   {
0326     G4AutoLock l(&pMutex);
0327     delete fPolyhedron;
0328     fPolyhedron = CreatePolyhedron();
0329     fRebuildPolyhedron = false;
0330     l.unlock();
0331   }
0332   return fPolyhedron;
0333 }
0334 
0335 template <class UnplacedVolume_t>
0336 G4VisExtent G4UAdapter<UnplacedVolume_t>::GetExtent() const
0337 {
0338   U3Vector vmin, vmax;
0339   UnplacedVolume_t::Extent(vmin,vmax);
0340   return G4VisExtent(vmin.x(),vmax.x(),
0341                      vmin.y(),vmax.y(),
0342                      vmin.z(),vmax.z());
0343 }