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