110 explicit Image(
size_t n_rows,
size_t n_cols,
const T* value_init = _value_default_ptr(),
111 std::shared_ptr<const CoordinateSystem> coordsys =
nullptr)
115 explicit Image(std::shared_ptr<const CoordinateSystem> coordsys =
nullptr)
116 : _coordsys_ptr(coordsys ==
nullptr ?
nullptr : std::move(coordsys)),
117 _coordsys(_coordsys_ptr ==
nullptr ? COORDS_DEFAULT : *_coordsys_ptr) {}
120 static constexpr T _value_default = 0;
121 static const T* _value_default_ptr() {
return &_value_default; };
123 T& _get_value(
size_t row,
size_t col) {
return static_cast<C&
>(*this)._get_value_impl(row, col); }
124 T& _get_value_impl(
size_t row,
size_t col) {
125 _check_row_col(row, col);
126 return this->_get_value_unchecked(row, col);
128 inline T& _get_value_unchecked(
size_t row,
size_t col) {
129 return self()._get_value_unchecked_impl(row, col);
131 inline T& _get_value_unchecked_impl(
size_t row,
size_t col) =
delete;
133 void _check_row_col(
size_t row,
size_t col)
const {
return self_const()._check_row_col_impl(row, col); }
134 void _check_row_col_impl(
size_t row,
size_t col)
const {
135 if (!((row < this->get_n_rows()) && (col < this->get_n_cols()))) {
136 throw std::out_of_range(
"row,col = " + std::to_string(row) +
"," + std::to_string(col)
137 +
" n_rows,n_cols = " + std::to_string(this->get_n_rows()) +
","
138 + std::to_string(this->get_n_cols()));
143 std::shared_ptr<const CoordinateSystem> get_coordsys_ptr_const()
const {
return _coordsys_ptr; };
145 size_t get_n_cols()
const {
return static_cast<const C&
>(*this).get_n_cols_impl(); }
146 size_t get_n_cols_impl()
const =
delete;
147 size_t get_n_rows()
const {
return static_cast<const C&
>(*this).get_n_rows_impl(); }
148 size_t get_n_rows_impl() =
delete;
150 void add_value(
size_t row,
size_t col, T value) { self().add_value_impl(row, col, value); }
151 void add_value_impl(
size_t row,
size_t col, T value) { this->_get_value(row, col) += value; }
152 void add_value_unchecked(
size_t row,
size_t col, T value) {
153 self().add_value_unchecked_impl(row, col, value);
155 void add_value_unchecked_impl(
size_t row,
size_t col, T value) {
156 self()._get_value_unchecked(row, col) += value;
158 void fill(T value) { self().fill_impl(value); }
159 void fill_impl(T value) {
160 const size_t n_rows = get_n_rows();
161 const size_t n_cols = get_n_cols();
162 for (
size_t row = 0; row < n_rows; ++row) {
163 for (
size_t col = 0; col < n_cols; ++col) {
164 this->set_value_unchecked(row, col, value);
168 inline T get_value(
size_t row,
size_t col)
const {
return self_const().get_value_impl(row, col); }
169 inline T get_value_impl(
size_t row,
size_t col)
const {
170 _check_row_col(row, col);
171 return self_const().get_value_unchecked(row, col);
173 inline T get_value_unchecked(
size_t row,
size_t col)
const {
174 return self_const().get_value_unchecked_impl(row, col);
176 inline T get_value_unchecked_impl(
size_t row,
size_t col)
const =
delete;
177 inline void set_value(
size_t row,
size_t col, T value) {
return self().set_value_impl(row, col, value); }
178 inline void set_value_impl(
size_t row,
size_t col, T value) { self()._get_value(row, col) = value; }
179 inline void set_value_unchecked(
size_t row,
size_t col, T value) {
180 self().set_value_unchecked_impl(row, col, value);
182 inline void set_value_unchecked_impl(
size_t row,
size_t col, T value) {
183 self()._get_value_unchecked(row, col) = value;
186 std::array<size_t, 2> shape()
const {
return {this->get_n_rows(), this->get_n_cols()}; }
188 size_t size()
const {
return this->get_n_rows() * this->get_n_cols(); };
190 std::string
repr(
bool name_keywords, std::string_view namespace_separator)
const override {
191 return type_name_str<C>(
false, namespace_separator) +
"(" + (name_keywords ?
"coordsys=" :
"")
192 + _coordsys.repr(name_keywords, namespace_separator) +
", " + (name_keywords ?
"n_rows=" :
"")
193 + std::to_string(this->get_n_rows()) +
", " + (name_keywords ?
"n_cols=" :
"")
194 + std::to_string(this->get_n_cols()) +
")";
197 std::string
str()
const override {
198 return type_name_str<C>(
true) +
"(coordsys=" + _coordsys.str() +
", n_rows="
199 + std::to_string(this->get_n_rows()) +
", n_cols=" + std::to_string(this->get_n_cols()) +
")";
203 const size_t n_rows = get_n_rows();
204 const size_t n_cols = get_n_cols();
205 for (
size_t row = 0; row < n_rows; ++row) {
206 for (
size_t col = 0; col < n_cols; ++col) {
207 this->add_value_unchecked(row, col, value);
213 Image<T, C>& operator*=(T value) {
214 const size_t n_rows = get_n_rows();
215 const size_t n_cols = get_n_cols();
216 for (
size_t row = 0; row < n_rows; ++row) {
217 for (
size_t col = 0; col < n_cols; ++col) {
219 if constexpr (std::is_same_v<T, bool>) {
220 this->set_value_unchecked(row, col, value && this->get_value_unchecked(row, col));
222 this->set_value_unchecked(row, col, value * this->get_value_unchecked(row, col));
232 bool operator==(
const Image& other)
const {
233 if (images_compatible<T, C, T, C>(*
this, other)) {
234 const size_t n_rows = get_n_rows();
235 const size_t n_cols = get_n_cols();
236 for (
size_t row = 0; row < n_rows; ++row) {
237 for (
size_t col = 0; col < n_cols; ++col) {
238 if (this->get_value_unchecked(row, col) != other.get_value_unchecked(row, col)) {
248 const bool operator!=(
const Image& other)
const {
return !(*
this == other); }
251 friend GaussianEvaluator<T, class Data, class Indices>;
252 const std::shared_ptr<const CoordinateSystem> _coordsys_ptr;
253 const gauss2d::CoordinateSystem& _coordsys;
255 inline C& self() {
return static_cast<C&
>(*this); };
256 inline const C& self_const()
const {
return static_cast<const C&
>(*this); };