24#ifndef LSST_GAUSS2D_IMAGE_H
25#define LSST_GAUSS2D_IMAGE_H
45template <
typename T,
class Data,
class Indices>
48template <
typename T,
class C>
69template <
typename T1,
class C1,
typename T2,
class C2>
73 bool return_msg = msg !=
nullptr;
74 if (!return_msg && !coordsys_equal)
return false;
77 bool passed = coordsys_equal && cols_equal && rows_equal;
80 if (!coordsys_equal) {
106template <
typename T,
class C>
116 : _coordsys_ptr(coordsys == nullptr ? nullptr :
std::move(coordsys)),
117 _coordsys(_coordsys_ptr == nullptr ? COORDS_DEFAULT : *_coordsys_ptr) {}
129 return self()._get_value_unchecked_impl(
row,
col);
145 size_t get_n_cols()
const {
return static_cast<const C&
>(*this).get_n_cols_impl(); }
147 size_t get_n_rows()
const {
return static_cast<const C&
>(*this).get_n_rows_impl(); }
153 self().add_value_unchecked_impl(
row,
col, value);
156 self()._get_value_unchecked(
row,
col) += value;
158 void fill(T value) { self().fill_impl(value); }
162 for (
size_t row = 0;
row < n_rows; ++
row) {
163 for (
size_t col = 0;
col < n_cols; ++
col) {
171 return self_const().get_value_unchecked(
row,
col);
174 return self_const().get_value_unchecked_impl(
row,
col);
180 self().set_value_unchecked_impl(
row,
col, value);
183 self()._get_value_unchecked(
row,
col) = value;
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=" :
"")
198 return type_name_str<C>(
true) +
"(coordsys=" + _coordsys.
str() +
", n_rows="
205 for (
size_t row = 0;
row < n_rows; ++
row) {
206 for (
size_t col = 0;
col < n_cols; ++
col) {
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>) {
233 if (images_compatible<T, C, T, C>(*
this, other)) {
236 for (
size_t row = 0;
row < n_rows; ++
row) {
237 for (
size_t col = 0;
col < n_cols; ++
col) {
255 inline C& self() {
return static_cast<C&
>(*this); };
256 inline const C& self_const()
const {
return static_cast<const C&
>(*this); };
267template <
typename T,
class C>
281 typename Data::iterator
begin() noexcept {
return _images.
begin(); }
282 typename Data::iterator
end() noexcept {
return _images.
end(); };
284 typename Data::const_iterator
cbegin() const noexcept {
return _images.
cbegin(); };
285 typename Data::const_iterator
cend() const noexcept {
return _images.
begin(); };
289 std::string repr(
bool name_keywords, std::string_view namespace_separator)
const override {
290 std::string str = type_name_str<ImageArray<T, C>>(
false, namespace_separator) +
"("
291 + (name_keywords ?
"data=" :
"")
292 +
repr_iter_ptr(_images, name_keywords, namespace_separator) +
")";
302 if (data_in !=
nullptr) {
307 for (
size_t i = 0; i < n_data; ++i) {
308 if (
data[i] ==
nullptr) {
310 +
"] can't be null");
312 if (!images_compatible<T, C, T, C>(*
data[i], *
data[0])) {
314 +
"] must be compatible with data[0] (and all others)");
316 _images[i] =
data[i];
A coordinate system specifying image scale and orientation.
std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
std::string str() const override
Return a brief, human-readable string representation of this.
A class that evaluates 2D Gaussians and renders them in images.
An array of compatible Images.
typename Data::const_iterator const_iterator
typename Data::iterator iterator
std::string str() const override
Return a brief, human-readable string representation of this.
Data::const_iterator cbegin() const noexcept
std::string repr(bool name_keywords, std::string_view namespace_separator) const override
Return a full, callable string representation of this.
ImageT & operator[](size_t i)
Data::iterator begin() noexcept
const ImageT & operator[](size_t i) const
ImageT & at(size_t i=0) const
Data::iterator end() noexcept
ImageArray(const Data *data_in)
std::vector< std::shared_ptr< C > > Data
Data::const_iterator cend() const noexcept
A 2D image with scalar numeric values, using CRTP.
bool operator==(const Image &other) const
void set_value_impl(size_t row, size_t col, T value)
void add_value_unchecked_impl(size_t row, size_t col, T value)
size_t get_n_rows_impl()=delete
const CoordinateSystem & get_coordsys() const
std::array< size_t, 2 > shape() const
Image< T, C > & operator*=(T value)
const bool operator!=(const Image &other) const
std::string str() const override
Return a brief, human-readable string representation of this.
Image< T, C > & operator+=(T value)
void set_value(size_t row, size_t col, T value)
T & _get_value_impl(size_t row, size_t col)
std::shared_ptr< const CoordinateSystem > get_coordsys_ptr_const() const
T get_value_unchecked(size_t row, size_t col) const
void set_value_unchecked_impl(size_t row, size_t col, T value)
T get_value(size_t row, size_t col) const
size_t get_n_rows() const
void add_value_impl(size_t row, size_t col, T value)
Image(std::shared_ptr< const CoordinateSystem > coordsys=nullptr)
T get_value_unchecked_impl(size_t row, size_t col) const =delete
void add_value(size_t row, size_t col, T value)
static constexpr T _value_default
void _check_row_col_impl(size_t row, size_t col) const
T & _get_value_unchecked_impl(size_t row, size_t col)=delete
Image(size_t n_rows, size_t n_cols, const T *value_init=_value_default_ptr(), std::shared_ptr< const CoordinateSystem > coordsys=nullptr)=delete
size_t get_n_cols_impl() const =delete
void add_value_unchecked(size_t row, size_t col, T value)
size_t get_n_cols() const
T get_value_impl(size_t row, size_t col) const
std::string repr(bool name_keywords, std::string_view namespace_separator) const override
Return a full, callable string representation of this.
static const T * _value_default_ptr()
void set_value_unchecked(size_t row, size_t col, T value)
void _check_row_col(size_t row, size_t col) const
T & _get_value_unchecked(size_t row, size_t col)
T & _get_value(size_t row, size_t col)
A generic object from the gauss2d library.
std::string repr_iter_ptr(const T &container, bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR)
bool images_compatible(const Image< T1, C1 > &img1, const Image< T2, C2 > &img2, bool compare_coordsys=true, std::string *msg=nullptr)
Return if two images are compatible.
std::string str_iter_ptr(const T &container)