File indexing completed on 2025-01-30 10:26:26
0001
0002
0003
0004 #ifndef VECGEOM_VOLUMES_UNPLACEDSCALEDSHAPE_H_
0005 #define VECGEOM_VOLUMES_UNPLACEDSCALEDSHAPE_H_
0006
0007 #include "VecGeom/base/Cuda.h"
0008 #include "VecGeom/base/Global.h"
0009 #include "VecGeom/base/AlignedBase.h"
0010 #include "VecGeom/base/Vector3D.h"
0011 #include "VecGeom/base/Scale3D.h"
0012 #include "ScaledShapeStruct.h"
0013 #include "VecGeom/volumes/UnplacedVolume.h"
0014 #include "VecGeom/volumes/PlacedVolume.h"
0015 #include "VecGeom/volumes/LogicalVolume.h"
0016 #include "VecGeom/volumes/kernel/ScaledShapeImplementation.h"
0017 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0018
0019 namespace vecgeom {
0020
0021 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedScaledShape;);
0022 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedScaledShape);
0023
0024 inline namespace VECGEOM_IMPL_NAMESPACE {
0025
0026 #ifdef GOT_AROUND_TO_SPECIALIZE_SCALED_SHAPE
0027 template <typename Specialized_t>
0028 class SUnplacedScaledShape {
0029 };
0030
0031 return ScaledShape::MakeInstance<BaseShape_t>(scale, Argtypes... args);
0032
0033 template <typename Shape_t>
0034 Scale(Shape_t vol, ... Scale)
0035 {
0036 return SUnplacedScaleShabe<Shape_t>(scale, vol);
0037 }
0038
0039 UnplacedScaledScale(UnplacedTube, scale)
0040 {
0041 if (dynamic_cast<...>()) }
0042
0043 template <typename BaseShape_t, Argtypes... Args>
0044 static UnplacedScaledShape *MakeScaledInstance(Scale3D scale, Argtypes... args)
0045 {
0046 auto svol = BaseShape_t::MakeInstance(args...);
0047 return Scale(svol, scale);
0048 }
0049 #endif
0050
0051
0052
0053
0054 class UnplacedScaledShape : public SIMDUnplacedVolumeImplHelper<ScaledShapeImplementation>, public AlignedBase {
0055
0056 public:
0057 ScaledShapeStruct<Precision> fScaled;
0058
0059 public:
0060
0061 VECCORE_ATT_HOST_DEVICE
0062 UnplacedScaledShape() : fScaled()
0063 {
0064 fGlobalConvexity = fScaled.fPlaced->GetUnplacedVolume()->IsConvex();
0065 ComputeBBox();
0066 }
0067
0068
0069 VECCORE_ATT_HOST_DEVICE
0070 UnplacedScaledShape(VPlacedVolume const *placed, Precision sx, Precision sy, Precision sz)
0071 : fScaled(placed, sx, sy, sz)
0072 {
0073 fGlobalConvexity = fScaled.fPlaced->GetUnplacedVolume()->IsConvex();
0074 ComputeBBox();
0075 }
0076
0077 #if defined(VECCORE_CUDA)
0078
0079 VECCORE_ATT_HOST_DEVICE
0080 UnplacedScaledShape(VPlacedVolume const *placed, Precision sx, Precision sy, Precision sz, bool globalConvexity)
0081 : fScaled(placed, sx, sy, sz)
0082 {
0083
0084 fGlobalConvexity = globalConvexity;
0085
0086
0087
0088
0089
0090
0091 }
0092 #endif
0093
0094
0095 #if !defined(VECCORE_CUDA)
0096 UnplacedScaledShape(VUnplacedVolume const *shape, Precision sx, Precision sy, Precision sz)
0097 : fScaled(nullptr, sx, sy, sz)
0098 {
0099
0100
0101 LogicalVolume *lvol = new LogicalVolume("", shape);
0102 fScaled.fPlaced = lvol->Place();
0103 fGlobalConvexity = fScaled.fPlaced->GetUnplacedVolume()->IsConvex();
0104 ComputeBBox();
0105 }
0106 #endif
0107
0108
0109
0110 UnplacedScaledShape(UnplacedScaledShape const &other) : fScaled()
0111 {
0112 fScaled.fPlaced = other.fScaled.fPlaced->GetLogicalVolume()->Place();
0113 fScaled.fScale = other.fScaled.fScale;
0114 fGlobalConvexity = other.fGlobalConvexity;
0115 ComputeBBox();
0116 }
0117
0118
0119
0120 UnplacedScaledShape &operator=(UnplacedScaledShape const &other)
0121 {
0122 if (&other != this) {
0123 fScaled.fPlaced = other.fScaled.fPlaced->GetLogicalVolume()->Place();
0124 fScaled.fScale = other.fScaled.fScale;
0125 fGlobalConvexity = other.fGlobalConvexity;
0126 }
0127 return *this;
0128 }
0129
0130
0131 VECCORE_ATT_HOST_DEVICE
0132 virtual ~UnplacedScaledShape()
0133 {
0134
0135
0136
0137
0138
0139
0140 }
0141
0142
0143 VECCORE_ATT_HOST_DEVICE
0144 ScaledShapeStruct<Precision> const &GetStruct() const { return fScaled; }
0145
0146 virtual int MemorySize() const final { return (sizeof(*this) + fScaled.fPlaced->MemorySize()); }
0147
0148 #ifdef VECGEOM_CUDA_INTERFACE
0149 virtual size_t DeviceSizeOf() const override { return DevicePtr<cuda::UnplacedScaledShape>::SizeOf(); }
0150 virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0151 virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0152 #endif
0153
0154 VECGEOM_FORCE_INLINE
0155 const VUnplacedVolume *UnscaledShape() const { return fScaled.fPlaced->GetLogicalVolume()->GetUnplacedVolume(); }
0156
0157 VECGEOM_FORCE_INLINE
0158 VPlacedVolume const *GetPlaced() const { return fScaled.fPlaced; }
0159
0160 VECGEOM_FORCE_INLINE
0161 Scale3D const &GetScale() const { return fScaled.fScale; }
0162
0163 Precision Volume() const
0164 {
0165 Precision capacity = ((VPlacedVolume *)fScaled.fPlaced)->Capacity();
0166 const Vector3D<Precision> &scl = fScaled.fScale.Scale();
0167 capacity *= scl[0] * scl[1] * scl[2];
0168 return capacity;
0169 }
0170
0171 Precision Capacity() const override { return Volume(); }
0172
0173
0174 Precision SurfaceArea() const override
0175 {
0176
0177 Precision area = VUnplacedVolume::EstimateSurfaceArea(1000000);
0178 return area;
0179 }
0180
0181 VECCORE_ATT_HOST_DEVICE
0182 bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override;
0183
0184 VECCORE_ATT_HOST_DEVICE
0185 void Extent(Vector3D<Precision> &min, Vector3D<Precision> &max) const override;
0186
0187 Vector3D<Precision> SamplePointOnSurface() const override;
0188
0189 virtual std::string GetEntityType() const { return "ScaledShape"; }
0190
0191 VECCORE_ATT_HOST_DEVICE
0192 virtual void Print() const final;
0193
0194 virtual void Print(std::ostream &os) const final;
0195
0196 template <TranslationCode trans_code, RotationCode rot_code>
0197 VECCORE_ATT_DEVICE
0198 static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0199 #ifdef VECCORE_CUDA
0200 const int id, const int copy_no, const int child_id,
0201 #endif
0202 VPlacedVolume *const placement = NULL);
0203
0204 VECCORE_ATT_DEVICE
0205 static VPlacedVolume *CreateSpecializedVolume(LogicalVolume const *const volume,
0206 Transformation3D const *const transformation,
0207 const TranslationCode trans_code, const RotationCode rot_code,
0208 #ifdef VECCORE_CUDA
0209 const int id, const int copy_no, const int child_id,
0210 #endif
0211 VPlacedVolume *const placement = NULL);
0212
0213 private:
0214 VECCORE_ATT_DEVICE
0215 virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0216 Transformation3D const *const transformation,
0217 const TranslationCode trans_code, const RotationCode rot_code,
0218 #ifdef VECCORE_CUDA
0219 const int id, const int copy_no, const int child_id,
0220 #endif
0221 VPlacedVolume *const placement = NULL) const final
0222 {
0223 return CreateSpecializedVolume(volume, transformation, trans_code, rot_code,
0224 #ifdef VECCORE_CUDA
0225 id, copy_no, child_id,
0226 #endif
0227 placement);
0228 }
0229 void SetPlaced(VPlacedVolume const *pvol) { fScaled.fPlaced = pvol; }
0230 void SetScale(Scale3D const &scale) { fScaled.fScale = scale; }
0231
0232 friend class GeoManager;
0233 };
0234 }
0235 }
0236
0237 #endif