LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
gaussian.h
Go to the documentation of this file.
1// -*- LSST-C++ -*-
2/*
3 * This file is part of gauss2d.
4 *
5 * Developed for the LSST Data Management System.
6 * This product includes software developed by the LSST Project
7 * (https://www.lsst.org).
8 * See the COPYRIGHT file at the top-level directory of this distribution
9 * for details of code ownership.
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
25#ifndef LSST_GAUSS2D_GAUSSIAN_H
26#define LSST_GAUSS2D_GAUSSIAN_H
27
28#include <algorithm>
29#include <iostream>
30#include <memory>
31#include <optional>
32#include <stdexcept>
33#include <string>
34#include <utility>
35#include <vector>
36
37#include "centroid.h"
38#include "ellipse.h"
39#include "object.h"
40
41namespace lsst::gauss2d {
42
47class GaussianIntegral : public Object {
48public:
49 virtual ~GaussianIntegral() = default;
50
51 virtual double get_value() const = 0;
52 virtual void set_value(double value) = 0;
53
54 virtual std::string repr(bool name_keywords = false, std::string_view namespace_separator
55 = Object::CC_NAMESPACE_SEPARATOR) const override
56 = 0;
57 virtual std::string str() const override = 0;
58
59 virtual bool operator==(const GaussianIntegral& other) const {
60 return this->get_value() == other.get_value();
61 }
62 virtual bool operator!=(const GaussianIntegral& other) const { return !(*this == other); }
63};
64
73public:
74 explicit GaussianIntegralValue(double value = 1.);
76
78
79 double get_value() const override { return *_value; }
80 void set_value(double value) override { *_value = value; }
81
82 std::string repr(bool name_keywords = false,
83 std::string_view namespace_separator = Object::CC_NAMESPACE_SEPARATOR) const override;
84 std::string str() const override;
85
86private:
87 // TODO: Add some value safety to this
88 // Probably must be a thin wrapper with a getter/setter enforcing >= 0
89 // either that or delete the shared_ptr constructor and add a copy constructor
91};
92
99class Gaussian : public Object {
100public:
108 explicit Gaussian(std::shared_ptr<Centroid> centroid = nullptr,
109 std::shared_ptr<Ellipse> ellipse = nullptr,
110 std::shared_ptr<GaussianIntegral> integral = nullptr);
111 ~Gaussian();
112
114 double get_const_normal() const;
116 double get_integral_value() const;
117
124
128
129 const Centroid& get_centroid_const() const;
130 const Ellipse& get_ellipse_const() const;
132
133 void set_const_normal(double const_normal);
134 void set_integral_value(double integral);
135
139
140 std::string repr(bool name_keywords = false,
141 std::string_view namespace_separator = Object::CC_NAMESPACE_SEPARATOR) const override;
142 std::string str() const override;
143
144 bool operator==(const Gaussian& other) const;
145 bool operator!=(const Gaussian& other) const;
146
147private:
151
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");
163 return ptr;
164 }
165};
166
175class Gaussians : public Object {
176public:
178
179 // These constructors explicitly copy inputs rather than moving
180 explicit Gaussians(std::optional<const Data> data);
181 explicit Gaussians(std::vector<std::optional<const Data>> data);
182
183 Gaussian& operator[](size_t i);
184 const Gaussian& operator[](size_t i) const;
185
186 Gaussian& at(size_t i) const;
187 const Gaussian& at_const(size_t i) const;
188 std::shared_ptr<Gaussian> at_ptr(size_t i) const;
189
190 using iterator = typename Data::iterator;
191 using const_iterator = typename Data::const_iterator;
192
193 typename Data::iterator begin() noexcept;
194 typename Data::const_iterator cbegin() const noexcept;
195
196 typename Data::const_iterator begin() const noexcept;
197 typename Data::const_iterator end() const noexcept;
198
199 typename Data::iterator end() noexcept;
200 typename Data::const_iterator cend() const noexcept;
201
202 Data get_data() const;
203
204 size_t size() const;
205
206 std::string repr(bool name_keywords = false,
207 std::string_view namespace_separator = Object::CC_NAMESPACE_SEPARATOR) const override;
208 std::string str() const override;
209
210private:
211 Data _data = {};
212
213 size_t assign(const Data& data, size_t i = 0);
214};
215
220class ConvolvedGaussian : public Object {
221public:
222 explicit ConvolvedGaussian(std::shared_ptr<const Gaussian> source = nullptr,
223 std::shared_ptr<const Gaussian> kernel = nullptr);
224
225 const Gaussian& get_source() const;
226 const Gaussian& get_kernel() const;
227
229
230 std::string repr(bool name_keywords = false,
231 std::string_view namespace_separator = Object::CC_NAMESPACE_SEPARATOR) const override;
232 std::string str() const override;
233
234 bool operator==(const ConvolvedGaussian& other) const;
235 bool operator!=(const ConvolvedGaussian& other) const;
236
237private:
240};
241
250public:
252
253 // These constructors explicitly copy inputs rather than moving
254 explicit ConvolvedGaussians(std::optional<const Data> data);
255 explicit ConvolvedGaussians(std::vector<std::optional<const Data>> data);
256
257 ConvolvedGaussian& at(size_t i) const;
258 const ConvolvedGaussian& at_const(size_t i) const;
260
261 using iterator = typename Data::iterator;
262 using const_iterator = typename Data::const_iterator;
263
264 typename Data::iterator begin() noexcept;
265 typename Data::iterator end() noexcept;
266
267 typename Data::const_iterator begin() const noexcept;
268 typename Data::const_iterator end() const noexcept;
269
270 typename Data::const_iterator cbegin() const noexcept;
271 typename Data::const_iterator cend() const noexcept;
272
273 Data get_data() const;
274
275 size_t size() const;
276
277 std::string repr(bool name_keywords = false,
278 std::string_view namespace_separator = Object::CC_NAMESPACE_SEPARATOR) const override;
279 std::string str() const override;
280
281 ConvolvedGaussian& operator[](size_t i);
282 const ConvolvedGaussian& operator[](size_t i) const;
283
284private:
285 Data _data = {};
286
287 size_t assign(const Data& data, size_t i = 0);
288};
289
290} // namespace lsst::gauss2d
291#endif
char * data
Definition BaseRecord.cc:61
std::uint64_t * ptr
Definition RangeSet.cc:95
A 2D coordinate representing the center of a plane figure.
Definition centroid.h:114
A convolution of a Gaussian source and kernel.
Definition gaussian.h:220
bool operator!=(const ConvolvedGaussian &other) const
Definition gaussian.cc:248
bool operator==(const ConvolvedGaussian &other) const
Definition gaussian.cc:244
const Gaussian & get_source() const
Definition gaussian.cc:222
std::unique_ptr< Gaussian > make_convolution() const
Definition gaussian.cc:225
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.
Definition gaussian.cc:233
std::string str() const override
Return a brief, human-readable string representation of this.
Definition gaussian.cc:239
ConvolvedGaussian(std::shared_ptr< const Gaussian > source=nullptr, std::shared_ptr< const Gaussian > kernel=nullptr)
Definition gaussian.cc:179
const Gaussian & get_kernel() const
Definition gaussian.cc:223
A collection of ConvolvedGaussian objects.
Definition gaussian.h:249
std::vector< std::shared_ptr< ConvolvedGaussian > > Data
Definition gaussian.h:251
ConvolvedGaussian & at(size_t i) const
Definition gaussian.cc:250
Data::iterator begin() noexcept
Definition gaussian.cc:254
ConvolvedGaussians(std::optional< const Data > data)
Definition gaussian.cc:184
Data::const_iterator cbegin() const noexcept
Definition gaussian.cc:264
typename Data::const_iterator const_iterator
Definition gaussian.h:262
std::shared_ptr< ConvolvedGaussian > at_ptr(size_t i) const
Definition gaussian.cc:252
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.
Definition gaussian.cc:275
Data::iterator end() noexcept
Definition gaussian.cc:255
Data::const_iterator cend() const noexcept
Definition gaussian.cc:267
const ConvolvedGaussian & at_const(size_t i) const
Definition gaussian.cc:251
typename Data::iterator iterator
Definition gaussian.h:261
An Ellipse with sigma_x, sigma_y, and rho values.
Definition ellipse.h:283
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
void set_const_normal(double const_normal)
Definition gaussian.cc:69
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.
Definition gaussian.cc:84
GaussianIntegral & get_integral()
Get the integral object.
Definition gaussian.cc:59
bool operator!=(const Gaussian &other) const
Definition gaussian.cc:101
double get_integral_value() const
Get the integral value.
Definition gaussian.cc:55
void set_integral_value(double integral)
Definition gaussian.cc:72
bool operator==(const Gaussian &other) const
Definition gaussian.cc:96
const Centroid & get_centroid_const() const
Definition gaussian.cc:65
std::shared_ptr< Centroid > get_centroid_ptr()
Definition gaussian.cc:61
std::shared_ptr< Ellipse > get_ellipse_ptr()
Definition gaussian.cc:62
std::shared_ptr< GaussianIntegral > get_integral_ptr()
Definition gaussian.cc:63
void set_centroid_ptr(std::shared_ptr< Centroid > centroid)
Definition gaussian.cc:74
void set_ellipse_ptr(std::shared_ptr< Ellipse > ellipse)
Definition gaussian.cc:77
const GaussianIntegral & get_integral_const() const
Definition gaussian.cc:67
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
const Ellipse & get_ellipse_const() const
Definition gaussian.cc:66
void set_integral_ptr(std::shared_ptr< GaussianIntegral > integral)
Definition gaussian.cc:80
Interface for the normalization (total integrated value) of a 2D Gaussian.
Definition gaussian.h:47
virtual bool operator!=(const GaussianIntegral &other) const
Definition gaussian.h:62
virtual double get_value() const =0
virtual void set_value(double value)=0
virtual bool operator==(const GaussianIntegral &other) const
Definition gaussian.h:59
virtual std::string str() const override=0
Return a brief, human-readable string representation of this.
virtual ~GaussianIntegral()=default
virtual std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override=0
Return a full, callable string representation of this.
A GaussianIntegral storing a float value.
Definition gaussian.h:72
GaussianIntegralValue(double value=1.)
Definition gaussian.cc:35
double get_value() const override
Definition gaussian.h:79
void set_value(double value) override
Definition gaussian.h:80
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
Return a full, callable string representation of this.
Definition gaussian.cc:39
An array of Gaussian objects.
Definition gaussian.h:175
Gaussian & at(size_t i) const
Definition gaussian.cc:148
Data::iterator begin() noexcept
Definition gaussian.cc:152
std::shared_ptr< Gaussian > at_ptr(size_t i) const
Definition gaussian.cc:150
Gaussian & operator[](size_t i)
Definition gaussian.cc:129
const Gaussian & at_const(size_t i) const
Definition gaussian.cc:149
Data::const_iterator cbegin() const noexcept
Definition gaussian.cc:154
Gaussians(std::optional< const Data > data)
Definition gaussian.cc:108
typename Data::iterator iterator
Definition gaussian.h:190
size_t size() const
Definition gaussian.cc:162
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.
Definition gaussian.cc:164
std::vector< std::shared_ptr< Gaussian > > Data
Definition gaussian.h:177
Data::const_iterator end() const noexcept
Definition gaussian.cc:157
typename Data::const_iterator const_iterator
Definition gaussian.h:191
Data::const_iterator cend() const noexcept
Definition gaussian.cc:158
A generic object from the gauss2d library.
Definition object.h:40
static constexpr std::string_view CC_NAMESPACE_SEPARATOR
The C++ namespace separator.
Definition object.h:45
STL namespace.