File indexing completed on 2026-10-03 09:29:42
0001
0002
0003
0004
0005 #ifndef VECGEOM_VOLUMES_UNPLACEDGENTRAP_H_
0006 #define VECGEOM_VOLUMES_UNPLACEDGENTRAP_H_
0007
0008 #include "VecGeom/base/Cuda.h"
0009 #include "VecGeom/base/Global.h"
0010 #include "VecGeom/base/AlignedBase.h"
0011 #include "VecGeom/volumes/GenTrapStruct.h"
0012 #include "VecGeom/volumes/UnplacedVolume.h"
0013 #include "VecGeom/volumes/kernel/GenTrapImplementation.h"
0014 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0015 #include <VecGeom/management/Logger.h>
0016
0017 namespace vecgeom {
0018
0019 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedGenTrap;);
0020 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedGenTrap);
0021
0022 inline namespace VECGEOM_IMPL_NAMESPACE {
0023
0024
0025
0026
0027
0028 class UnplacedGenTrap : public UnplacedVolumeImplHelper<GenTrapImplementation>, public AlignedBase {
0029
0030 public:
0031 using Vertex_t = Vector3D<Precision>;
0032
0033 GenTrapStruct<Precision> fGenTrap;
0034
0035 public:
0036
0037 VECCORE_ATT_HOST_DEVICE
0038 UnplacedGenTrap() : fGenTrap() {}
0039
0040
0041
0042
0043
0044
0045 VECCORE_ATT_HOST_DEVICE
0046 UnplacedGenTrap(const Precision verticesx[], const Precision verticesy[], Precision halfzheight)
0047 : fGenTrap(verticesx, verticesy, halfzheight)
0048 {
0049 fGlobalConvexity = fGenTrap.IsPlanar();
0050 ComputeBBox();
0051 }
0052
0053
0054 VECCORE_ATT_HOST_DEVICE
0055 virtual ~UnplacedGenTrap() {}
0056
0057 VECCORE_ATT_HOST_DEVICE
0058 bool Initialize(const Precision verticesx[], const Precision verticesy[], Precision halfzheight)
0059 {
0060 return fGenTrap.Initialize(verticesx, verticesy, halfzheight);
0061 }
0062
0063 VECCORE_ATT_HOST_DEVICE
0064 VECGEOM_FORCE_INLINE
0065 virtual ESolidType GetType() const override { return ESolidType::gentrap; }
0066
0067
0068 VECCORE_ATT_HOST_DEVICE
0069 GenTrapStruct<Precision> const &GetStruct() const { return fGenTrap; }
0070
0071
0072 VECCORE_ATT_HOST_DEVICE
0073 VECGEOM_FORCE_INLINE
0074 Precision GetDZ() const { return (fGenTrap.fDz); }
0075
0076
0077 VECCORE_ATT_HOST_DEVICE
0078 VECGEOM_FORCE_INLINE
0079 void SetDZ(Precision dz) { fGenTrap.fDz = dz; }
0080
0081
0082 VECCORE_ATT_HOST_DEVICE
0083 VECGEOM_FORCE_INLINE
0084 Precision GetTwist(int i) const { return (fGenTrap.GetTwist(i)); }
0085
0086
0087 VECCORE_ATT_HOST_DEVICE
0088 VECGEOM_FORCE_INLINE
0089 Vertex_t const &GetVertex(int i) const { return fGenTrap.fVertices[i]; }
0090
0091
0092 VECCORE_ATT_HOST_DEVICE
0093 const Precision *GetVerticesX() const
0094 {
0095 static bool printed_once{false};
0096 auto vertx = new Precision[8];
0097 for (auto i = 0; i < 8; ++i)
0098 vertx[i] = fGenTrap.fVertices[i].x();
0099 if (!printed_once) {
0100 VECGEOM_LOG(warning)
0101 << "GetVerticesX is deprecated and you now own the allocated array. Use GetVertices instead.";
0102 printed_once = true;
0103 }
0104 return vertx;
0105 }
0106
0107
0108 VECCORE_ATT_HOST_DEVICE
0109 const Precision *GetVerticesY() const
0110 {
0111 static bool printed_once{false};
0112 auto verty = new Precision[8];
0113 for (auto i = 0; i < 8; ++i)
0114 verty[i] = fGenTrap.fVertices[i].y();
0115 if (!printed_once) {
0116 VECGEOM_LOG(warning)
0117 << "GetVerticesY is deprecated and you now own the allocated array. Use GetVertices instead.";
0118 printed_once = true;
0119 }
0120 return verty;
0121 }
0122
0123
0124 VECCORE_ATT_HOST_DEVICE
0125 VECGEOM_FORCE_INLINE
0126 const Vertex_t *GetVertices() const { return fGenTrap.fVertices; }
0127
0128
0129 VECCORE_ATT_HOST_DEVICE
0130 bool ComputeIsTwisted() { return fGenTrap.ComputeTwistedFaces() > 0; }
0131
0132
0133 VECCORE_ATT_HOST_DEVICE
0134 bool ComputeIsConvexQuadrilaterals() { return fGenTrap.ComputeIsConvexQuadrilaterals(); }
0135
0136
0137 VECCORE_ATT_HOST_DEVICE
0138 VECGEOM_FORCE_INLINE
0139 bool IsPlanar() const { return (fGenTrap.IsPlanar()); }
0140
0141
0142 VECCORE_ATT_HOST_DEVICE
0143 VECGEOM_FORCE_INLINE
0144 bool IsDegenerated(int i) const { return (fGenTrap.IsDegenerated(i)); }
0145
0146
0147
0148 VECCORE_ATT_HOST_DEVICE
0149 bool SegmentsCrossing(Vertex_t pa, Vertex_t pb, Vertex_t pc, Vertex_t pd) const
0150 {
0151 return fGenTrap.SegmentsCrossing(pa, pb, pc, pd);
0152 }
0153
0154
0155 VECCORE_ATT_HOST_DEVICE
0156 void ComputeBoundingBox() { fGenTrap.ComputeBoundingBox(); }
0157
0158
0159 virtual int MemorySize() const final { return sizeof(*this); }
0160
0161
0162 VECCORE_ATT_HOST_DEVICE
0163 virtual void Print() const final { fGenTrap.Print(); }
0164
0165
0166 virtual void Print(std::ostream &os) const final;
0167
0168 #ifndef VECCORE_CUDA
0169 virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0170 #endif
0171
0172 #ifdef VECGEOM_CUDA_INTERFACE
0173
0174 size_t DeviceSizeOf() const final { return DevicePtr<cuda::UnplacedGenTrap>::SizeOf(); }
0175
0176 DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const final;
0177
0178 DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const final;
0179 #endif
0180
0181
0182 Precision Capacity() const override { return volume(); }
0183
0184
0185 Precision volume() const;
0186
0187
0188 Precision SurfaceArea() const override;
0189
0190
0191 VECCORE_ATT_HOST_DEVICE
0192 bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override;
0193
0194
0195 VECCORE_ATT_HOST_DEVICE
0196 void Extent(Vertex_t &amin, Vertex_t &amax) const override { return fGenTrap.Extent(amin, amax); }
0197
0198
0199 Vertex_t SamplePointOnSurface() const override;
0200
0201
0202 std::string GetEntityType() const { return "GenTrap"; }
0203
0204
0205 VECCORE_ATT_DEVICE
0206 static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0207 #ifdef VECCORE_CUDA
0208 const int id, const int copy_no, const int child_id,
0209 #endif
0210 VPlacedVolume *const placement = NULL);
0211
0212
0213 std::ostream &StreamInfo(std::ostream &os) const;
0214
0215 private:
0216
0217 VECCORE_ATT_DEVICE
0218 virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0219 Transformation3D const *const transformation,
0220 #ifdef VECCORE_CUDA
0221 const int id, const int copy_no, const int child_id,
0222 #endif
0223 VPlacedVolume *const placement = NULL) const final;
0224
0225 };
0226 }
0227 }
0228
0229 #endif