24#ifndef LSST_GAUSS2D_GAUSSIAN_H
37 : _value(value == nullptr ?
std::make_shared<double>(1) :
std::move(value)) {};
40 return type_name_str<GaussianIntegralValue>(
false, namespace_separator) +
"("
44 return type_name_str<GaussianIntegralValue>(
true) +
"(value=" +
to_string_float(*_value) +
")";
49 : _centroid(centroid != nullptr ?
std::move(centroid) :
std::make_shared<
Centroid>()),
50 _ellipse(ellipse != nullptr ?
std::move(ellipse) :
std::make_shared<
Ellipse>()),
75 _centroid = this->_check_not_nullptr<Centroid>(centroid,
"centroid");
78 _ellipse = this->_check_not_nullptr<Ellipse>(ellipse,
"ellipse");
81 _integral = this->_check_not_nullptr<GaussianIntegral>(integral,
"integral");
85 return type_name_str<Gaussian>(
false, namespace_separator) +
"(" + (name_keywords ?
"centroid=" :
"")
86 + _centroid->repr(name_keywords, namespace_separator) +
", " + (name_keywords ?
"ellipse=" :
"")
87 + _ellipse->repr(name_keywords, namespace_separator) +
", " + (name_keywords ?
"integral=" :
"")
88 + _integral->repr(name_keywords, namespace_separator) +
")";
92 return type_name_str<Gaussian>(
true) +
"(centroid=" + _centroid->str() +
", ellipse=" + _ellipse->str()
93 +
", integral=" + _integral->str() +
")";
110 size_t n_data =
data->size();
112 _data.
resize(n_data,
nullptr);
119 for (
const auto& datum :
data) {
120 if (datum) n_data += datum->size();
125 for (
const auto& datum :
data) i = this->assign(*datum, i);
132size_t Gaussians::assign(
const Data&
data,
size_t i) {
133 const size_t n_data = this->_data.
size();
134 const size_t i_max = i +
data.size();
135 if (!(i_max <= n_data)) {
140 for (
const auto& gauss :
data) {
141 if (gauss ==
nullptr)
166 = type_name_str<Gaussians>(
false, namespace_separator) +
"(" + (name_keywords ?
"data=" :
"");
167 str +=
repr_iter_ptr(_data, name_keywords, namespace_separator);
172 std::string str = type_name_str<Gaussians>(
true) +
"(data=";
181 : _source(source != nullptr ? source : GAUSS_ZERO),
182 _kernel(kernel != nullptr ? kernel : GAUSS_ZERO) {}
186 size_t n_data =
data->size();
195 for (
const auto& datum :
data) {
196 if (datum) n_data += datum->size();
201 for (
const auto& datum :
data) i = this->assign(*datum, i);
205size_t ConvolvedGaussians::assign(
const Data&
data,
size_t i) {
206 const size_t n_data = this->_data.
size();
207 const size_t i_max = i +
data.size();
208 if (!(i_max <= n_data)) {
213 for (
const auto& gauss :
data) {
214 if (gauss ==
nullptr)
216 +
"] can't be null");
226 return std::make_unique<Gaussian>(
227 _source->get_centroid_const().make_convolution(_kernel->get_centroid_const()),
228 _source->get_ellipse_const().make_convolution(_kernel->get_ellipse_const()),
229 std::make_shared<GaussianIntegralValue>(_source->get_integral_value()
230 + _kernel->get_integral_value()));
234 return type_name_str<ConvolvedGaussian>(
false, namespace_separator) +
"("
235 + (name_keywords ?
"source=" :
"") + _source->repr(name_keywords, namespace_separator) +
", "
236 + (name_keywords ?
"kernel=" :
"") + _kernel->repr(name_keywords, namespace_separator) +
")";
240 return type_name_str<ConvolvedGaussian>(
true) +
"(source=" + _source->str() +
", kernel=" + _kernel->str()
258 return _data.
begin();
265 return _data.
begin();
276 std::string str = type_name_str<ConvolvedGaussians>(
false, namespace_separator) +
"("
277 + (name_keywords ?
"data=" :
"");
278 str +=
repr_iter_ptr(_data, name_keywords, namespace_separator);
283 std::string str = type_name_str<ConvolvedGaussians>(
true) +
"(data=";
A 2D coordinate representing the center of a plane figure.
A convolution of a Gaussian source and kernel.
bool operator!=(const ConvolvedGaussian &other) const
bool operator==(const ConvolvedGaussian &other) const
const Gaussian & get_source() const
std::unique_ptr< Gaussian > make_convolution() const
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.
ConvolvedGaussian(std::shared_ptr< const Gaussian > source=nullptr, std::shared_ptr< const Gaussian > kernel=nullptr)
const Gaussian & get_kernel() const
ConvolvedGaussian & at(size_t i) const
std::string str() const override
Return a brief, human-readable string representation of this.
Data::iterator begin() noexcept
ConvolvedGaussians(std::optional< const Data > data)
Data::const_iterator cbegin() const noexcept
std::shared_ptr< ConvolvedGaussian > at_ptr(size_t i) const
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.
Data::iterator end() noexcept
Data::const_iterator cend() const noexcept
const ConvolvedGaussian & at_const(size_t i) const
ConvolvedGaussian & operator[](size_t i)
An Ellipse with sigma_x, sigma_y, and rho values.
A 2D Gaussian with a Centroid, Ellipse, and integral.
Gaussian(std::shared_ptr< Centroid > centroid=nullptr, std::shared_ptr< Ellipse > ellipse=nullptr, std::shared_ptr< GaussianIntegral > integral=nullptr)
Construct a new Gaussian object.
Ellipse & get_ellipse()
Get the ellipse object.
void set_const_normal(double const_normal)
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.
GaussianIntegral & get_integral()
Get the integral object.
bool operator!=(const Gaussian &other) const
double get_integral_value() const
Get the integral value.
void set_integral_value(double integral)
bool operator==(const Gaussian &other) const
const Centroid & get_centroid_const() const
std::shared_ptr< Centroid > get_centroid_ptr()
std::shared_ptr< Ellipse > get_ellipse_ptr()
std::shared_ptr< GaussianIntegral > get_integral_ptr()
void set_centroid_ptr(std::shared_ptr< Centroid > centroid)
void set_ellipse_ptr(std::shared_ptr< Ellipse > ellipse)
const GaussianIntegral & get_integral_const() const
double get_const_normal() const
Get the multiplicative factor for Gaussian function evaluations: integral/(2*area)
Centroid & get_centroid()
Get the centroid object.
std::string str() const override
Return a brief, human-readable string representation of this.
const Ellipse & get_ellipse_const() const
void set_integral_ptr(std::shared_ptr< GaussianIntegral > integral)
Interface for the normalization (total integrated value) of a 2D Gaussian.
A GaussianIntegral storing a float value.
GaussianIntegralValue(double value=1.)
std::string str() const override
Return a brief, human-readable string representation of this.
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.
Gaussian & at(size_t i) const
Data::iterator begin() noexcept
std::shared_ptr< Gaussian > at_ptr(size_t i) const
Gaussian & operator[](size_t i)
const Gaussian & at_const(size_t i) const
Data::const_iterator cbegin() const noexcept
Gaussians(std::optional< const Data > data)
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.
Data::const_iterator end() const noexcept
Data::const_iterator cend() const noexcept
std::ostream & operator<<(std::ostream &out, const Covariance &obj)
std::string repr_iter_ptr(const T &container, bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR)
std::string to_string_float(const T value, const int precision=6, const bool scientific=true)
std::string str_iter_ptr(const T &container)