File indexing completed on 2026-09-19 09:40:43
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef VECGEOM_VOLUMES_UNPLACEDVOLUME_H_
0010 #define VECGEOM_VOLUMES_UNPLACEDVOLUME_H_
0011
0012 #include "VecGeom/base/Assert.h"
0013 #include "VecGeom/base/Cuda.h"
0014 #include "VecGeom/base/Global.h"
0015 #include "VecGeom/base/Transformation3D.h"
0016 #include "VecGeom/volumes/kernel/BoxImplementation.h"
0017 #include <string>
0018 #include <ostream>
0019
0020 #ifndef VECCORE_CUDA
0021 #include "VecGeom/volumes/SolidMesh.h"
0022 #endif
0023
0024 namespace vecgeom {
0025
0026 VECGEOM_DEVICE_FORWARD_DECLARE(class VUnplacedVolume;);
0027 VECGEOM_DEVICE_DECLARE_CONV(class, VUnplacedVolume);
0028
0029 inline namespace VECGEOM_IMPL_NAMESPACE {
0030
0031 class LogicalVolume;
0032 class VPlacedVolume;
0033
0034
0035
0036
0037
0038
0039
0040
0041 class VUnplacedVolume {
0042
0043 private:
0044 friend class CudaManager;
0045 Vector3D<Precision> fBBox[2];
0046
0047 protected:
0048 bool fGlobalConvexity;
0049 bool fIsAssembly = false;
0050
0051 public:
0052 VECCORE_ATT_HOST_DEVICE
0053 virtual ~VUnplacedVolume() {}
0054
0055 VECCORE_ATT_HOST_DEVICE
0056 virtual bool IsBoolean() const { return false; }
0057
0058 VECCORE_ATT_HOST_DEVICE
0059 VECGEOM_FORCE_INLINE
0060 virtual ESolidType GetType() const { return ESolidType::nosolid; }
0061
0062 VECGEOM_FORCE_INLINE
0063 VECCORE_ATT_HOST_DEVICE
0064 void SetBBox(Vector3D<Precision> const &amin, Vector3D<Precision> const &amax)
0065 {
0066 fBBox[0] = amin;
0067 fBBox[1] = amax;
0068 }
0069
0070 VECGEOM_FORCE_INLINE
0071 VECCORE_ATT_HOST_DEVICE
0072 void GetBBox(Vector3D<Precision> &amin, Vector3D<Precision> &amax) const
0073 {
0074 amin = fBBox[0];
0075 amax = fBBox[1];
0076 }
0077
0078 VECGEOM_FORCE_INLINE
0079 VECCORE_ATT_HOST_DEVICE
0080 void ComputeBBox()
0081 {
0082 #ifndef VECCORE_CUDA_DEVICE_COMPILATION
0083 Extent(fBBox[0], fBBox[1]);
0084 #endif
0085 }
0086
0087
0088
0089
0090
0091
0092 VECCORE_ATT_HOST_DEVICE
0093 virtual bool Contains(Vector3D<Precision> const &pos) const = 0;
0094
0095
0096
0097
0098
0099 VECCORE_ATT_HOST_DEVICE
0100 virtual EnumInside Inside(Vector3D<Precision> const &pos) const = 0;
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 VECCORE_ATT_HOST_DEVICE
0113 virtual Precision DistanceToOut(Vector3D<Precision> const &pos, Vector3D<Precision> const &dir,
0114 Precision step_max = kInfLength) const = 0;
0115
0116
0117
0118
0119
0120
0121
0122
0123 VECCORE_ATT_HOST_DEVICE
0124 virtual Precision SafetyToOut(Vector3D<Precision> const &pos) const = 0;
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136 VECCORE_ATT_HOST_DEVICE
0137 virtual Precision DistanceToIn(Vector3D<Precision> const &position, Vector3D<Precision> const &direction,
0138 const Precision step_max = kInfLength) const = 0;
0139
0140
0141
0142
0143
0144
0145
0146
0147 VECCORE_ATT_HOST_DEVICE
0148 virtual Precision SafetyToIn(Vector3D<Precision> const &pos) const = 0;
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158 VECCORE_ATT_HOST_DEVICE
0159 virtual bool Normal(Vector3D<Precision> const &pos, Vector3D<Precision> &normal) const = 0;
0160
0161
0162
0163
0164
0165
0166 virtual Vector3D<Precision> SamplePointOnSurface() const ;
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176 VECCORE_ATT_HOST_DEVICE
0177 virtual void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const = 0;
0178
0179 VECGEOM_FORCE_INLINE
0180 VECCORE_ATT_HOST_DEVICE
0181 Precision ApproachSolid(Vector3D<Precision> const &point, Vector3D<Precision> const &invDir) const
0182 {
0183 Precision distance = BoxImplementation::IntersectCachedKernel2<Precision, Precision>(
0184 fBBox, point, invDir, invDir.x() < 0, invDir.y() < 0, invDir.z() < 0, 0, kInfLength);
0185 return vecCore::math::Max(distance, Precision(0));
0186 }
0187
0188
0189
0190
0191
0192 VECCORE_ATT_HOST_DEVICE
0193 bool IsConvex() const { return fGlobalConvexity; }
0194
0195
0196
0197
0198 VECCORE_ATT_HOST_DEVICE
0199 bool IsAssembly() const { return fIsAssembly; }
0200
0201
0202
0203
0204
0205 virtual Precision Capacity() const = 0;
0206
0207
0208
0209
0210
0211 Precision EstimateCapacity(int nStat = 100000) const;
0212
0213
0214
0215
0216
0217 virtual Precision SurfaceArea() const = 0;
0218
0219
0220
0221
0222
0223 Precision EstimateSurfaceArea(int nStat = 100000) const;
0224
0225
0226
0227
0228
0229 friend std::ostream &operator<<(std::ostream &os, VUnplacedVolume const &vol);
0230
0231
0232
0233
0234
0235 virtual int MemorySize() const = 0;
0236
0237 #ifdef VECGEOM_CUDA_INTERFACE
0238 virtual size_t DeviceSizeOf() const = 0;
0239
0240
0241
0242
0243
0244 virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const = 0;
0245 virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const = 0;
0246
0247 template <typename Derived, typename... ArgsTypes>
0248 DevicePtr<cuda::VUnplacedVolume> CopyToGpuImpl(DevicePtr<cuda::VUnplacedVolume> const in_gpu_ptr,
0249 ArgsTypes... params) const
0250 {
0251 DevicePtr<CudaType_t<Derived>> gpu_ptr(in_gpu_ptr);
0252 gpu_ptr.Construct(params...);
0253 VECGEOM_DEVICE_API_CALL(GetLastError());
0254
0255
0256
0257 return DevicePtr<cuda::VUnplacedVolume>((void *)gpu_ptr);
0258 }
0259 template <typename Derived>
0260 DevicePtr<cuda::VUnplacedVolume> CopyToGpuImpl() const
0261 {
0262 DevicePtr<CudaType_t<Derived>> gpu_ptr;
0263 gpu_ptr.Allocate();
0264 return this->CopyToGpu(DevicePtr<cuda::VUnplacedVolume>((void *)gpu_ptr));
0265 }
0266
0267 static void CopyBBoxesToGpu(const std::vector<VUnplacedVolume const *> &volumes,
0268 const std::vector<DevicePtr<cuda::VUnplacedVolume>> &gpu_ptrs);
0269
0270 #endif
0271
0272
0273
0274
0275
0276 virtual void Print(std::ostream &os) const = 0;
0277
0278
0279
0280
0281
0282 VECCORE_ATT_HOST_DEVICE
0283 virtual void Print() const = 0;
0284
0285
0286 #ifndef VECCORE_CUDA
0287 virtual SolidMesh *CreateMesh3D(Transformation3D const & , const size_t ) const
0288 {
0289 return nullptr;
0290 };
0291 #endif
0292
0293
0294
0295
0296 VPlacedVolume *PlaceVolume(char const *const label, LogicalVolume const *const volume,
0297 Transformation3D const *const transformation, VPlacedVolume *const placement = NULL) const;
0298
0299 VPlacedVolume *PlaceVolume(LogicalVolume const *const volume, Transformation3D const *const transformation,
0300 VPlacedVolume *const placement = NULL) const;
0301
0302 private:
0303 #ifndef VECCORE_CUDA
0304
0305 virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0306 Transformation3D const *const transformation,
0307 VPlacedVolume *const placement = NULL) const = 0;
0308
0309 #else
0310 VECCORE_ATT_DEVICE
0311 virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0312 Transformation3D const *const transformation, const int id,
0313 const int copy_no, const int child_id,
0314 VPlacedVolume *const placement = NULL) const = 0;
0315
0316 #endif
0317 };
0318
0319
0320
0321
0322
0323 template <typename Shape_t>
0324 struct Maker {
0325 template <typename... ArgTypes>
0326 static Shape_t *MakeInstance(ArgTypes... args)
0327 {
0328
0329 return new Shape_t(args...);
0330 }
0331 };
0332
0333 std::ostream &operator<<(std::ostream &os, VUnplacedVolume const &vol);
0334
0335 }
0336
0337 }
0338
0339 #endif