File indexing completed on 2025-09-16 08:57:16
0001
0002
0003
0004
0005
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
0020
0021
0022
0023
0024
0025
0026
0027 class ImageLineView
0028 {
0029 public:
0030
0031
0032 using ParamsRef = NativeCRef<ImageParamsData>;
0033 using StateRef = NativeRef<ImageStateData>;
0034
0035
0036 public:
0037
0038 inline CELER_FUNCTION ImageLineView(ParamsRef const& params,
0039 StateRef const& state,
0040 size_type row_index);
0041
0042
0043 inline CELER_FUNCTION Real3 start_pos() const;
0044
0045
0046 CELER_FUNCTION Real3 const& start_dir() const { return scalars_.right; }
0047
0048
0049 CELER_FUNCTION real_type pixel_width() const
0050 {
0051 return scalars_.pixel_width;
0052 }
0053
0054
0055 CELER_FUNCTION real_type max_length() const { return scalars_.max_length; }
0056
0057
0058 CELER_FUNCTION size_type max_index() const { return scalars_.dims[1]; }
0059
0060
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
0071
0072
0073
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
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
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 }