25#ifndef LSST_GAUSS2D_GAUSSIAN_H
26#define LSST_GAUSS2D_GAUSSIAN_H
41namespace lsst::gauss2d {
51 virtual double get_value()
const = 0;
52 virtual void set_value(
double value) = 0;
54 virtual std::string
repr(
bool name_keywords =
false, std::string_view namespace_separator
57 virtual std::string
str()
const override = 0;
60 return this->get_value() == other.get_value();
62 virtual bool operator!=(
const GaussianIntegral& other)
const {
return !(*
this == other); }
74 explicit GaussianIntegralValue(
double value = 1.);
75 explicit GaussianIntegralValue(std::shared_ptr<double> value);
77 ~GaussianIntegralValue() {};
79 double get_value()
const override {
return *_value; }
80 void set_value(
double value)
override { *_value = value; }
82 std::string
repr(
bool name_keywords =
false,
84 std::string
str()
const override;
90 std::shared_ptr<double> _value;
108 explicit Gaussian(std::shared_ptr<Centroid> centroid =
nullptr,
109 std::shared_ptr<Ellipse> ellipse =
nullptr,
110 std::shared_ptr<GaussianIntegral> integral =
nullptr);
125 std::shared_ptr<Centroid> get_centroid_ptr();
126 std::shared_ptr<Ellipse> get_ellipse_ptr();
127 std::shared_ptr<GaussianIntegral> get_integral_ptr();
129 const Centroid& get_centroid_const()
const;
130 const Ellipse& get_ellipse_const()
const;
133 void set_const_normal(
double const_normal);
134 void set_integral_value(
double integral);
136 void set_centroid_ptr(std::shared_ptr<Centroid> centroid);
137 void set_ellipse_ptr(std::shared_ptr<Ellipse> ellipse);
138 void set_integral_ptr(std::shared_ptr<GaussianIntegral> integral);
140 std::string
repr(
bool name_keywords =
false,
142 std::string
str()
const override;
144 bool operator==(
const Gaussian& other)
const;
145 bool operator!=(
const Gaussian& other)
const;
148 std::shared_ptr<Centroid> _centroid;
149 std::shared_ptr<Ellipse> _ellipse;
150 std::shared_ptr<GaussianIntegral> _integral;
160 template <
typename T>
161 std::shared_ptr<T> _check_not_nullptr(std::shared_ptr<T> ptr, std::string name) {
162 if (ptr ==
nullptr)
throw std::invalid_argument(this->
str() +
"Can't set " + name +
" to nullptr");
177 typedef std::vector<std::shared_ptr<Gaussian>> Data;
180 explicit Gaussians(std::optional<const Data> data);
181 explicit Gaussians(std::vector<std::optional<const Data>> data);
184 const Gaussian& operator[](
size_t i)
const;
187 const Gaussian& at_const(
size_t i)
const;
188 std::shared_ptr<Gaussian> at_ptr(
size_t i)
const;
190 using iterator =
typename Data::iterator;
191 using const_iterator =
typename Data::const_iterator;
193 typename Data::iterator begin()
noexcept;
194 typename Data::const_iterator cbegin()
const noexcept;
196 typename Data::const_iterator begin()
const noexcept;
197 typename Data::const_iterator end()
const noexcept;
199 typename Data::iterator end()
noexcept;
200 typename Data::const_iterator cend()
const noexcept;
202 Data get_data()
const;
206 std::string
repr(
bool name_keywords =
false,
208 std::string
str()
const override;
213 size_t assign(
const Data& data,
size_t i = 0);
222 explicit ConvolvedGaussian(std::shared_ptr<const Gaussian> source =
nullptr,
223 std::shared_ptr<const Gaussian> kernel =
nullptr);
228 std::unique_ptr<Gaussian> make_convolution()
const;
230 std::string
repr(
bool name_keywords =
false,
232 std::string
str()
const override;
234 bool operator==(
const ConvolvedGaussian& other)
const;
235 bool operator!=(
const ConvolvedGaussian& other)
const;
238 std::shared_ptr<const Gaussian> _source;
239 std::shared_ptr<const Gaussian> _kernel;
249class ConvolvedGaussians :
public Object {
251 typedef std::vector<std::shared_ptr<ConvolvedGaussian>> Data;
254 explicit ConvolvedGaussians(std::optional<const Data> data);
255 explicit ConvolvedGaussians(std::vector<std::optional<const Data>> data);
259 std::shared_ptr<ConvolvedGaussian> at_ptr(
size_t i)
const;
261 using iterator =
typename Data::iterator;
262 using const_iterator =
typename Data::const_iterator;
264 typename Data::iterator begin()
noexcept;
265 typename Data::iterator end()
noexcept;
267 typename Data::const_iterator begin()
const noexcept;
268 typename Data::const_iterator end()
const noexcept;
270 typename Data::const_iterator cbegin()
const noexcept;
271 typename Data::const_iterator cend()
const noexcept;
273 Data get_data()
const;
277 std::string
repr(
bool name_keywords =
false,
279 std::string
str()
const override;
287 size_t assign(
const Data& data,
size_t i = 0);
A 2D coordinate representing the center of a plane figure.
Definition centroid.h:114
Definition gaussian.h:220
std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override
Definition gaussian.cc:233
std::string str() const override
Return a brief, human-readable string representation of this.
Definition gaussian.cc:239
std::string str() const override
Return a brief, human-readable string representation of this.
Definition gaussian.cc:282
std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override
Definition gaussian.cc:275
An Ellipse with sigma_x, sigma_y, and rho values.
Definition ellipse.h:283
std::string str() const override
Return a brief, human-readable string representation of this.
Definition gaussian.cc:43
std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override
Definition gaussian.cc:39
Interface for the normalization (total integrated value) of a 2D Gaussian.
Definition gaussian.h:47
virtual std::string str() const override=0
Return a brief, human-readable string representation of this.
virtual std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override=0
A 2D Gaussian with a Centroid, Ellipse, and integral.
Definition gaussian.h:99
Gaussian(std::shared_ptr< Centroid > centroid=nullptr, std::shared_ptr< Ellipse > ellipse=nullptr, std::shared_ptr< GaussianIntegral > integral=nullptr)
Construct a new Gaussian object.
Definition gaussian.cc:47
Ellipse & get_ellipse()
Get the ellipse object.
Definition gaussian.cc:58
std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override
Definition gaussian.cc:84
GaussianIntegral & get_integral()
Get the integral object.
Definition gaussian.cc:59
double get_integral_value() const
Get the integral value.
Definition gaussian.cc:55
double get_const_normal() const
Get the multiplicative factor for Gaussian function evaluations: integral/(2*area)
Definition gaussian.cc:54
Centroid & get_centroid()
Get the centroid object.
Definition gaussian.cc:57
std::string str() const override
Return a brief, human-readable string representation of this.
Definition gaussian.cc:91
std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override
Definition gaussian.cc:164
std::string str() const override
Return a brief, human-readable string representation of this.
Definition gaussian.cc:171
static constexpr std::string_view CC_NAMESPACE_SEPARATOR
The C++ namespace separator.
Definition object.h:45