Back to home page

EIC code displayed by LXR

 
 

    


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

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