Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:34

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file geocel/rasterize/detail/RaytraceExecutor.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "../ImageData.hh"
0011 #include "../ImageLineView.hh"
0012 #include "../Raytracer.hh"
0013 
0014 namespace celeritas
0015 {
0016 namespace detail
0017 {
0018 //---------------------------------------------------------------------------//
0019 /*!
0020  * Get the volume ID as an integer, or -1 if outside.
0021  */
0022 struct VolumeIdCalculator
0023 {
0024     template<class GTV>
0025     CELER_FUNCTION int operator()(GTV const& geo) const
0026     {
0027         if (geo.is_outside())
0028             return -1;
0029         return static_cast<int>(geo.volume_id().get());
0030     }
0031 };
0032 
0033 //---------------------------------------------------------------------------//
0034 /*!
0035  * Raytrace a geometry onto an image.
0036  */
0037 template<class GTV, class F>
0038 struct RaytraceExecutor
0039 {
0040     //// TYPES ////
0041 
0042     // TODO: Use observer pointers?
0043     using GeoTrackView = GTV;
0044     using GeoParamsRef = typename GTV::ParamsRef;
0045     using GeoStateRef = typename GTV::StateRef;
0046     using ImgParamsRef = NativeCRef<ImageParamsData>;
0047     using ImgStateRef = NativeRef<ImageStateData>;
0048 
0049     //// DATA ////
0050 
0051     GeoParamsRef geo_params;
0052     GeoStateRef geo_state;
0053     ImgParamsRef img_params;
0054     ImgStateRef img_state;
0055 
0056     F calc_id;
0057 
0058     //// FUNCTIONS ////
0059 
0060     // Initialize track states
0061     inline CELER_FUNCTION void operator()(ThreadId tid) const;
0062 };
0063 
0064 //---------------------------------------------------------------------------//
0065 // INLINE DEFINITIONS
0066 //---------------------------------------------------------------------------//
0067 /*!
0068  * Trace a single line.
0069  */
0070 template<class GTV, class F>
0071 CELER_FUNCTION void RaytraceExecutor<GTV, F>::operator()(ThreadId tid) const
0072 {
0073     CELER_EXPECT(tid < img_params.scalars.dims[0]);
0074     CELER_EXPECT(geo_state.size() == img_params.scalars.dims[0]);
0075 
0076     // Trace one state per vertical line
0077     GeoTrackView geo{geo_params, geo_state, TrackSlotId{tid.unchecked_get()}};
0078     ImageLineView line{img_params, img_state, tid.unchecked_get()};
0079     Raytracer trace(geo, calc_id, line);
0080     for (auto col : range(line.max_index()))
0081     {
0082         int val = trace(col);
0083         line.set_pixel(col, val);
0084     }
0085 }
0086 
0087 //---------------------------------------------------------------------------//
0088 }  // namespace detail
0089 }  // namespace celeritas