Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:57:16

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