Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:26:27

0001 // This file is part of VecGeom and is distributed under the
0002 // conditions in the file LICENSE.txt in the top directory.
0003 // For the full list of authors see CONTRIBUTORS.txt and `git log`.
0004 
0005 /// \brief Declaration of the data structure for the tessellated shape.
0006 /// \file volumes/UnplacedTessellated.h
0007 /// \author First version created by Mihaela Gheata (CERN/ISS)
0008 
0009 #ifndef VECGEOM_VOLUMES_UNPLACEDTESSELLATED_H_
0010 #define VECGEOM_VOLUMES_UNPLACEDTESSELLATED_H_
0011 
0012 #include "VecGeom/base/Cuda.h"
0013 #include "VecGeom/base/Global.h"
0014 #include "VecGeom/base/AlignedBase.h"
0015 #include "VecGeom/volumes/UnplacedVolume.h"
0016 #include "TessellatedStruct.h"
0017 #include "VecGeom/volumes/kernel/TessellatedImplementation.h"
0018 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0019 
0020 namespace vecgeom {
0021 
0022 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedTessellated;);
0023 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedTessellated);
0024 
0025 inline namespace VECGEOM_IMPL_NAMESPACE {
0026 
0027 /** Class for tessellated shape primitive.
0028 
0029   The tessellated solid is defined by a closed mesh of triangular facets. To construct facets, two
0030   methods are provided: AddTriangularFacet and AddQuadrilateralFacet, taking as input three, respectively
0031   four vertices. Note that quadrilaterals are internally represented as two triangles. The triangles should not
0032   be malformed (zero inner area), otherwise they will be ignored. It is the user responsibility to create a
0033   closed mesh, there is no runtime check for this.
0034 
0035   The class uses scalar navigation interfaces, but has internal vectorization on the triangle components and on
0036   the navigation optimizer.
0037 */
0038 class UnplacedTessellated : public LoopUnplacedVolumeImplHelper<TessellatedImplementation>, public AlignedBase {
0039 protected:
0040   mutable TessellatedStruct<3, Precision> fTessellated; ///< Structure with Tessellated parameters
0041 
0042 public:
0043   /// Default constructor for the unplaced tessellated shape class.
0044   VECCORE_ATT_HOST_DEVICE
0045   UnplacedTessellated() : fTessellated()
0046   {
0047     fGlobalConvexity = false;
0048     ComputeBBox();
0049   }
0050 
0051   /// Getter for the TessellatedStruct object containing the actual data (facets, vertices, clusters of facets)
0052   /** @return The tessellatedStruct object */
0053   VECCORE_ATT_HOST_DEVICE
0054   TessellatedStruct<3, Precision> const &GetStruct() const { return fTessellated; }
0055 
0056   /// Method for adding a new triangular facet, delegated to TessellatedStruct
0057   /** @param vt0      First vertex
0058       @param vt1      Second vertex
0059       @param vt2      Third vertex
0060       @param absolute If true then vt0, vt1 and vt2 are the vertices to be added in
0061         anti-clockwise order looking from the outsider. If false the vertices are relative
0062         to the first: vt0, vt0+vt1, vt0+vt2, in anti-clockwise order when looking from the outsider.
0063   */
0064   VECCORE_ATT_HOST_DEVICE
0065   bool AddTriangularFacet(Vector3D<Precision> const &vt0, Vector3D<Precision> const &vt1,
0066                           Vector3D<Precision> const &vt2, bool absolute = true)
0067   {
0068     bool result = fTessellated.AddTriangularFacet(vt0, vt1, vt2, absolute);
0069     ComputeBBox();
0070     return result;
0071   }
0072 
0073   /// Method for adding a new quadrilateral facet, delegated to TessellatedStruct
0074   /** @param vt0      First vertex
0075       @param vt1      Second vertex
0076       @param vt2      Third vertex
0077       @param vt3      Fourth vertex
0078       @param absolute If true then vt0, vt1, vt2 and vt3 are the vertices to be added in
0079         anti-clockwise order looking from the outsider. If false the vertices are relative
0080         to the first: vt0, vt0+vt1, vt0+vt2, vt0+vt3 in anti-clockwise order when looking from the
0081         outsider.
0082   */
0083   VECCORE_ATT_HOST_DEVICE
0084   bool AddQuadrilateralFacet(Vector3D<Precision> const &vt0, Vector3D<Precision> const &vt1,
0085                              Vector3D<Precision> const &vt2, Vector3D<Precision> const &vt3, bool absolute = true)
0086   {
0087     bool result = fTessellated.AddQuadrilateralFacet(vt0, vt1, vt2, vt3, absolute);
0088     ComputeBBox();
0089     return result;
0090   }
0091 
0092   /// Getter for the number of facets.
0093   VECGEOM_FORCE_INLINE
0094   VECCORE_ATT_HOST_DEVICE
0095   size_t GetNFacets() const { return fTessellated.fFacets.size(); }
0096 
0097   /// Getter for a facet with a given index.
0098   /** @param ifacet Index of the facet
0099       @return Triangle facet pointer at the given index
0100   */
0101   VECGEOM_FORCE_INLINE
0102   VECCORE_ATT_HOST_DEVICE
0103   TriangleFacet<Precision> *GetFacet(int ifacet) const { return fTessellated.fFacets[ifacet]; }
0104 
0105   /// Closing method to be called mandatory by the user once all facets are defined.
0106   VECCORE_ATT_HOST_DEVICE
0107   void Close() { fTessellated.Close(); }
0108 
0109   /// Check if the tessellated solid is closed.
0110   VECCORE_ATT_HOST_DEVICE
0111   bool IsClosed() const { return fTessellated.fSolidClosed; }
0112 
0113   virtual int memory_size() const { return sizeof(*this); }
0114 
0115   VECCORE_ATT_HOST_DEVICE
0116   void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const override { fTessellated.Extent(aMin, aMax); }
0117 
0118   // Computes capacity of the shape in [length^3]
0119   // VECCORE_ATT_HOST_DEVICE
0120   Precision Capacity() const override;
0121 
0122   // VECCORE_ATT_HOST_DEVICE
0123   Precision SurfaceArea() const override;
0124 
0125   /// Randomly chose a facet with a probability proportional to its surface area. Scales like O(N).
0126   /** @return Facet index */
0127   VECCORE_ATT_HOST_DEVICE
0128   int ChooseSurface() const;
0129 
0130   Vector3D<Precision> SamplePointOnSurface() const override;
0131 
0132   VECCORE_ATT_HOST_DEVICE
0133   bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override;
0134 
0135   VECCORE_ATT_HOST_DEVICE
0136   virtual void Print() const override;
0137 
0138   /// Get the solid type as string.
0139   /** @return Name of the solid type as string*/
0140   std::string GetEntityType() const { return "Tessellated"; }
0141 
0142   template <TranslationCode transCodeT, RotationCode rotCodeT>
0143   VECCORE_ATT_DEVICE
0144   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0145 #ifdef VECCORE_CUDA
0146                                const int id,
0147 #endif
0148                                VPlacedVolume *const placement = NULL);
0149 
0150 #ifdef VECGEOM_CUDA_INTERFACE
0151 #ifdef HYBRID_NAVIGATOR_PORTED_TO_CUDA
0152   virtual size_t DeviceSizeOf() const override { return DevicePtr<cuda::UnplacedTessellated>::SizeOf(); }
0153 #else
0154   virtual size_t DeviceSizeOf() const override { return 0; }
0155 #endif
0156   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0157   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0158 #endif
0159 
0160   /// Stream the UnplacedTessellated to an ostream.
0161   std::ostream &StreamInfo(std::ostream &os) const;
0162 
0163   virtual void Print(std::ostream &os) const override;
0164 
0165 private:
0166   VECCORE_ATT_DEVICE
0167   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0168                                            Transformation3D const *const transformation,
0169                                            const TranslationCode trans_code, const RotationCode rot_code,
0170 #ifdef VECCORE_CUDA
0171                                            const int id,
0172 #endif
0173                                            VPlacedVolume *const placement = NULL) const override;
0174 };
0175 } // namespace VECGEOM_IMPL_NAMESPACE
0176 } // namespace vecgeom
0177 
0178 #endif // VECGEOM_VOLUMES_UNPLACEDTESSELLATED_H_