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/ImageLineView.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Assert.hh"
0010 #include "corecel/math/ArrayUtils.hh"
0011 #include "geocel/Types.hh"
0012 
0013 #include "ImageData.hh"
0014 
0015 namespace celeritas
0016 {
0017 //---------------------------------------------------------------------------//
0018 /*!
0019  * Modify a line of a image for rasterization.
0020  *
0021  * The rasterizer starts at the left side of an image and traces rightward.
0022  * Each "line" is a single thread.
0023  *
0024  * \todo Add template parameter to switch from vertical to horizontal
0025  * direction.
0026  */
0027 class ImageLineView
0028 {
0029   public:
0030     //!@{
0031     //! \name Type aliases
0032     using ParamsRef = NativeCRef<ImageParamsData>;
0033     using StateRef = NativeRef<ImageStateData>;
0034     //!@}
0035 
0036   public:
0037     // Construct with image data and thread ID
0038     inline CELER_FUNCTION ImageLineView(ParamsRef const& params,
0039                                         StateRef const& state,
0040                                         size_type row_index);
0041 
0042     // Calculate start position
0043     inline CELER_FUNCTION Real3 start_pos() const;
0044 
0045     //! Start direction (rightward axis)
0046     CELER_FUNCTION Real3 const& start_dir() const { return scalars_.right; }
0047 
0048     //! Pixel width
0049     CELER_FUNCTION real_type pixel_width() const
0050     {
0051         return scalars_.pixel_width;
0052     }
0053 
0054     //! Maximum length to trace
0055     CELER_FUNCTION real_type max_length() const { return scalars_.max_length; }
0056 
0057     //! Number of pixels along the direction of travel
0058     CELER_FUNCTION size_type max_index() const { return scalars_.dims[1]; }
0059 
0060     // Set pixel value
0061     inline CELER_FUNCTION void set_pixel(size_type col, int value);
0062 
0063   private:
0064     ImageParamsScalars const& scalars_;
0065     StateRef const& state_;
0066     size_type row_index_;
0067 };
0068 
0069 //---------------------------------------------------------------------------//
0070 // INLINE DEFINITIONS
0071 //---------------------------------------------------------------------------//
0072 /*!
0073  * Construct with image data and thread ID.
0074  */
0075 CELER_FUNCTION
0076 ImageLineView::ImageLineView(ParamsRef const& params,
0077                              StateRef const& state,
0078                              size_type row_index)
0079     : scalars_{params.scalars}, state_{state}, row_index_{row_index}
0080 {
0081     CELER_EXPECT(row_index_ < scalars_.dims[0]);
0082 }
0083 
0084 //---------------------------------------------------------------------------//
0085 /*!
0086  * Calculate starting position.
0087  */
0088 CELER_FUNCTION auto ImageLineView::start_pos() const -> Real3
0089 {
0090     real_type down_offset = (row_index_ + real_type(0.5))
0091                             * scalars_.pixel_width;
0092     Real3 result = scalars_.origin;
0093     axpy(down_offset, scalars_.down, &result);
0094     return result;
0095 }
0096 
0097 //---------------------------------------------------------------------------//
0098 /*!
0099  * Set the value for a pixel.
0100  */
0101 CELER_FUNCTION void ImageLineView::set_pixel(size_type col, int value)
0102 {
0103     CELER_EXPECT(col < scalars_.dims[1]);
0104     size_type idx = row_index_ * scalars_.dims[1] + col;
0105 
0106     CELER_ASSERT(idx < state_.image.size());
0107     state_.image[ItemId<int>{idx}] = value;
0108 }
0109 
0110 //---------------------------------------------------------------------------//
0111 }  // namespace celeritas