LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
centroid.cc
Go to the documentation of this file.
1/*
2 * This file is part of gauss2d.
3 *
4 * Developed for the LSST Data Management System.
5 * This product includes software developed by the LSST Project
6 * (https://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef LSST_GAUSS2D_CENTROID_H
25
26#include <memory>
27#include <string>
28
32
33namespace lsst::gauss2d {
34
35double CentroidValues::get_x() const { return *_x; }
36std::array<double, 2> CentroidValues::get_xy() const { return {*_x, *_y}; }
37double CentroidValues::get_y() const { return *_y; }
38
39void CentroidValues::set_x(double x) { *_x = x; }
41 *_x = xy[0];
42 *_y = xy[1];
43};
44void CentroidValues::set_y(double y) { *_y = y; }
45
46std::string CentroidValues::repr(bool name_keywords, std::string_view namespace_separator) const {
47 return type_name_str<CentroidValues>(false, namespace_separator) + "(" + (name_keywords ? "x=" : "")
48 + to_string_float(*_x) + ", " + (name_keywords ? "y=" : "") + to_string_float(*_y) + ")";
49}
50
52 return type_name_str<CentroidValues>(true) + "(x=" + to_string_float(*_x) + ", y=" + to_string_float(*_y)
53 + ")";
54}
55
57 return (this->get_x() == other.get_x()) && (this->get_y() == other.get_y());
58};
59
60bool CentroidValues::operator!=(const CentroidValues& other) const { return !(*this == other); }
61
63 : _x(x == nullptr ? std::make_shared<double>(0) : std::move(x)),
64 _y(y == nullptr ? std::make_shared<double>(0) : std::move(y)) {}
65
67 : _x(std::make_shared<double>(x)), _y(std::make_shared<double>(y)) {}
68
69void Centroid::convolve(const Centroid& cen) {
70 this->set_x(this->get_x() + cen.get_x());
71 this->set_y(this->get_y() + cen.get_y());
72}
73
74const CentroidData& Centroid::get_data() const { return *_data; }
75
76double Centroid::get_x() const { return _data->get_x(); }
77
78std::array<double, 2> Centroid::get_xy() const { return _data->get_xy(); }
79
80double Centroid::get_y() const { return _data->get_y(); }
81
86 // TODO: Replace with cloning derived data
87 std::unique_ptr<Centroid> cen_ret = std::make_unique<Centroid>(this->get_x(), this->get_y());
88 cen_ret->convolve(cen);
89 return cen_ret;
90}
91
92void Centroid::set_x(double x) { _data->set_x(x); }
93void Centroid::set_xy(const std::array<double, 2>& xy) { _data->set_xy(xy); }
94void Centroid::set_y(double y) { _data->set_y(y); }
95
96std::string Centroid::repr(bool name_keywords, std::string_view namespace_separator) const {
97 return type_name_str<Centroid>(false, namespace_separator) + "(" + (name_keywords ? "data=" : "")
98 + _data->repr(name_keywords, namespace_separator) + ")";
99}
100
101std::string Centroid::str() const { return type_name_str<Centroid>(true) + "(data=" + _data->str() + ")"; }
102
103bool Centroid::operator==(const Centroid& other) const {
104 return (this->get_x() == other.get_x()) && (this->get_y() == other.get_y());
105};
106
107bool Centroid::operator!=(const Centroid& other) const { return !(*this == other); }
108
110 : _data(data == nullptr ? std::make_shared<CentroidValues>() : std::move(data)) {}
111
112Centroid::Centroid(double x, double y) : _data(std::make_shared<CentroidValues>()) {
113 set_x(x);
114 set_y(y);
115}
116
117} // namespace lsst::gauss2d
118
119#endif
char * data
Definition BaseRecord.cc:61
int y
Definition SpanSet.cc:48
Interface for an object storing Centroid data.
Definition centroid.h:43
A 2D coordinate representing the center of a plane figure.
Definition centroid.h:114
double get_y() const
Get the y value.
Definition centroid.cc:80
std::shared_ptr< Centroid > make_convolution(const Centroid &cen) const
Return the convolution of this with another centroid.
Definition centroid.cc:82
std::array< double, 2 > get_xy() const
Get the x and y values.
Definition centroid.cc:78
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 centroid.cc:96
std::string str() const override
Return a brief, human-readable string representation of this.
Definition centroid.cc:101
void set_xy(const std::array< double, 2 > &xy)
Definition centroid.cc:93
bool operator!=(const Centroid &other) const
Definition centroid.cc:107
void set_y(double y)
Definition centroid.cc:94
bool operator==(const Centroid &other) const
Definition centroid.cc:103
void set_x(double x)
Definition centroid.cc:92
std::unique_ptr< Centroid > make_convolution_uniq(const Centroid &cen) const
Same as make_convolution(), but returning a unique_ptr.
Definition centroid.cc:85
const CentroidData & get_data() const
Get this centroid's data.
Definition centroid.cc:74
Centroid(std::shared_ptr< CentroidData > data)
Definition centroid.cc:109
double get_x() const
Get the x value.
Definition centroid.cc:76
void convolve(const Centroid &cen)
Convolve this with another centroid.
Definition centroid.cc:69
A CentroidData storing centroid values as shared_ptrs.
Definition centroid.h:74
void set_y(double y) override
Definition centroid.cc:44
void set_xy(const std::array< double, 2 > &xy) override
Definition centroid.cc:40
double get_y() const override
Get the y value.
Definition centroid.cc:37
bool operator!=(const CentroidValues &other) const
Definition centroid.cc:60
bool operator==(const CentroidValues &other) const
Definition centroid.cc:56
void set_x(double x) override
Definition centroid.cc:39
std::string str() const override
Return a brief, human-readable string representation of this.
Definition centroid.cc:51
std::string repr(bool name_keywords, std::string_view namespace_separator) const override
Return a full, callable string representation of this.
Definition centroid.cc:46
CentroidValues(std::shared_ptr< double > x, std::shared_ptr< double > y)
Construct a new Centroid Values object.
Definition centroid.cc:62
std::array< double, 2 > get_xy() const override
Get the x and y values.
Definition centroid.cc:36
double get_x() const override
Get the x value.
Definition centroid.cc:35
std::string to_string_float(const T value, const int precision=6, const bool scientific=true)
Definition to_string.h:15
STL namespace.