Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-06 10:19:25

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file orange/orangeinp/Truncated.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <string>
0011 #include <vector>
0012 
0013 #include "IntersectRegion.hh"
0014 #include "ObjectInterface.hh"
0015 #include "Shape.hh"
0016 
0017 namespace celeritas
0018 {
0019 namespace orangeinp
0020 {
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * A shape formed by truncating another region with axis-aligned planes.
0024  *
0025  * Geant4 uses this for the ellipsoid along \em -/+z and SCALE uses this for
0026  * chords along all three axes.
0027  */
0028 class Truncated final : public ObjectInterface
0029 {
0030   public:
0031     using Plane = InfPlane;
0032     using VecPlane = std::vector<Plane>;
0033     using UPRegion = std::unique_ptr<IntersectRegionInterface>;
0034 
0035   public:
0036     // Return a truncated *or* shape given optional planes
0037     template<class T>
0038     inline static SPConstObject
0039     or_shape(std::string&& label, T&& interior, VecPlane&& truncated);
0040 
0041     // Construct with a region to truncate and a vector of planes
0042     Truncated(std::string&& label, UPRegion&& region, VecPlane&& planes);
0043 
0044     // Build the volume using the volume builder
0045     NodeId build(VolumeBuilder& vb) const final;
0046 
0047     // Output to JSON
0048     void output(JsonPimpl*) const final;
0049 
0050     //// ACCESSORS ////
0051 
0052     //! Get the label for this object
0053     std::string_view label() const final { return label_; }
0054 
0055     //! Get the truncated region
0056     IntersectRegionInterface const& region() const { return *region_; }
0057 
0058     //! Get the truncating planes
0059     VecPlane const& planes() const { return planes_; }
0060 
0061   private:
0062     std::string label_;
0063     std::unique_ptr<IntersectRegionInterface> region_;
0064     VecPlane planes_;
0065 };
0066 
0067 //---------------------------------------------------------------------------//
0068 /*!
0069  * Create a truncated region or just a shape.
0070  */
0071 template<class T>
0072 auto Truncated::or_shape(std::string&& label,
0073                          T&& interior,
0074                          VecPlane&& truncated) -> SPConstObject
0075 {
0076     if (truncated.empty())
0077     {
0078         // Just a shape
0079         return std::make_shared<Shape<T>>(std::move(label),
0080                                           std::forward<T>(interior));
0081     }
0082     return std::make_shared<Truncated>(
0083         std::move(label),
0084         std::make_unique<T>(std::forward<T>(interior)),
0085         std::move(truncated));
0086 }
0087 
0088 //---------------------------------------------------------------------------//
0089 }  // namespace orangeinp
0090 }  // namespace celeritas