File indexing completed on 2026-10-04 09:28:15
0001 #ifndef VECGEOM_VOLUMES_UNPLACEDBOX_H_
0002 #define VECGEOM_VOLUMES_UNPLACEDBOX_H_
0003
0004 #include "VecGeom/base/Cuda.h"
0005 #include "VecGeom/base/Global.h"
0006 #include "VecGeom/base/AlignedBase.h"
0007 #include "VecGeom/base/Vector3D.h"
0008 #include "VecGeom/volumes/UnplacedVolume.h"
0009 #include "VecGeom/volumes/BoxStruct.h" // the pure box struct
0010 #include "VecGeom/volumes/kernel/BoxImplementation.h"
0011 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0012
0013 namespace vecgeom {
0014
0015 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedBox;);
0016 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedBox);
0017
0018 inline namespace VECGEOM_IMPL_NAMESPACE {
0019
0020 class UnplacedBox : public UnplacedVolumeImplHelper<BoxImplementation>, public AlignedBase {
0021
0022 private:
0023 BoxStruct<Precision> fBox;
0024
0025 public:
0026 using Kernel = BoxImplementation;
0027 UnplacedBox(Vector3D<Precision> const &dim) : fBox(dim) { ComputeBBox(); }
0028 UnplacedBox(char const *, Vector3D<Precision> const &dim) : fBox(dim) { ComputeBBox(); }
0029
0030 VECCORE_ATT_HOST_DEVICE
0031 UnplacedBox(const Precision dx, const Precision dy, const Precision dz) : fBox(dx, dy, dz)
0032 {
0033 fGlobalConvexity = true;
0034 ComputeBBox();
0035 }
0036 UnplacedBox(char const *, const Precision dx, const Precision dy, const Precision dz) : fBox(dx, dy, dz)
0037 {
0038 fGlobalConvexity = true;
0039 ComputeBBox();
0040 }
0041
0042 VECCORE_ATT_HOST_DEVICE
0043 VECGEOM_FORCE_INLINE
0044 virtual ESolidType GetType() const override { return ESolidType::box; }
0045
0046 VECCORE_ATT_HOST_DEVICE
0047 BoxStruct<Precision> const &GetStruct() const { return fBox; }
0048
0049 VECCORE_ATT_HOST_DEVICE
0050 VECGEOM_FORCE_INLINE
0051 Vector3D<Precision> const &dimensions() const { return fBox.fDimensions; }
0052
0053 VECCORE_ATT_HOST_DEVICE
0054 VECGEOM_FORCE_INLINE
0055 Precision x() const { return dimensions().x(); }
0056
0057 VECCORE_ATT_HOST_DEVICE
0058 VECGEOM_FORCE_INLINE
0059 Precision y() const { return dimensions().y(); }
0060
0061 VECCORE_ATT_HOST_DEVICE
0062 VECGEOM_FORCE_INLINE
0063 Precision z() const { return dimensions().z(); }
0064
0065 void SetX(Precision xx) { fBox.fDimensions[0] = xx; }
0066 void SetY(Precision yy) { fBox.fDimensions[1] = yy; }
0067 void SetZ(Precision zz) { fBox.fDimensions[2] = zz; }
0068
0069 Precision Capacity() const override { return 8.0 * x() * y() * z(); }
0070
0071
0072 Precision SurfaceArea() const override
0073 {
0074
0075 return 8.0 * (x() * y() + y() * z() + x() * z());
0076 }
0077
0078 VECCORE_ATT_HOST_DEVICE
0079 void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const override
0080 {
0081
0082 aMin = -fBox.fDimensions;
0083 aMax = fBox.fDimensions;
0084 }
0085
0086 Vector3D<Precision> SamplePointOnSurface() const override;
0087
0088 VECCORE_ATT_HOST_DEVICE
0089 virtual bool Normal(Vector3D<Precision> const &p, Vector3D<Precision> &normal) const override
0090 {
0091 bool valid;
0092 normal = BoxImplementation::NormalKernel(fBox, p, valid);
0093 return valid;
0094 }
0095
0096 VECCORE_ATT_HOST_DEVICE
0097 virtual void Print() const override;
0098
0099 virtual void Print(std::ostream &os) const override;
0100
0101 #ifndef VECCORE_CUDA
0102 virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0103 #endif
0104
0105 #ifdef VECGEOM_CUDA_INTERFACE
0106 virtual size_t DeviceSizeOf() const override { return DevicePtr<cuda::UnplacedBox>::SizeOf(); }
0107 virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0108 virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0109 #endif
0110
0111 #ifndef VECCORE_CUDA
0112
0113
0114 static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0115 VPlacedVolume *const placement = NULL);
0116
0117 VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume, Transformation3D const *const transformation,
0118 VPlacedVolume *const placement) const override;
0119 #else
0120 VECCORE_ATT_DEVICE static VPlacedVolume *Create(LogicalVolume const *const logical_volume,
0121 Transformation3D const *const transformation, const int id,
0122 const int copy_no, const int child_id,
0123 VPlacedVolume *const placement = NULL);
0124 VECCORE_ATT_DEVICE VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0125 Transformation3D const *const transformation, const int id,
0126 const int copy_no, const int child_id,
0127 VPlacedVolume *const placement) const override;
0128
0129 #endif
0130 };
0131 }
0132 }
0133
0134 #endif