lsst.meas.base  13.0-33-gb1a1d47+4
ShapeUtilities.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2015 AURA/LSST.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #ifndef LSST_MEAS_BASE_ShapeUtilities_h_INCLUDED
25 #define LSST_MEAS_BASE_ShapeUtilities_h_INCLUDED
26 
28 #include "lsst/afw/table/aggregates.h"
29 
30 namespace lsst { namespace meas { namespace base {
31 
40 struct ShapeResult {
41  ShapeElement xx; // image or model second moment for x^2
42  ShapeElement yy; // image or model second moment for y^2
43  ShapeElement xy; // image or model second moment for xy^2
50 
52  ShapeResult();
53 
55  explicit ShapeResult(ShapeElement xx_, ShapeElement yy_, ShapeElement xy_, ShapeCov const & matrix):
56  xx(xx_),
57  yy(yy_),
58  xy(xy_),
59  xxSigma(std::sqrt(matrix(0, 0))),
60  yySigma(std::sqrt(matrix(1, 1))),
61  xySigma(std::sqrt(matrix(2, 2))),
62  xx_yy_Cov(matrix(0, 1)),
63  xx_xy_Cov(matrix(0, 2)),
64  yy_xy_Cov(matrix(1, 2))
65  {}
66 
69  ErrElement xxSigma_, ErrElement yySigma_, ErrElement xySigma_) :
70  xx(xx_),
71  yy(yy_),
72  xy(xy_),
73  xxSigma(xxSigma_),
74  yySigma(yySigma_),
75  xySigma(xySigma_),
76  xx_yy_Cov(0.0),
77  xx_xy_Cov(0.0),
78  yy_xy_Cov(0.0)
79  {}
80 
87  Shape const getShape() const;
88 
89  // get the Quadrupole corresponding to this ShapeResult
90  afw::geom::ellipses::Quadrupole getQuadrupole()
91  {
92  return afw::geom::ellipses::Quadrupole(xx, yy, xy);
93  }
94 
96  void setShape(Shape const & shape);
97 
99  ShapeCov const getShapeErr() const;
100 
102  void setShapeErr(ShapeCov const & matrix);
103 
105  void setShapeErr(ErrElement xxSigma, ErrElement yySigma, ErrElement xySigma);
106 
107 };
108 
115 class ShapeResultKey : public afw::table::FunctorKey<ShapeResult> {
116 public:
117 
129  static ShapeResultKey addFields(
130  afw::table::Schema & schema,
131  std::string const & name,
132  std::string const & doc,
133  UncertaintyEnum uncertainty,
134  afw::table::CoordinateType coordType=afw::table::CoordinateType::PIXEL
135  );
136 
138  ShapeResultKey() : _shape(), _shapeErr() {}
139 
142  afw::table::QuadrupoleKey const & shape,
143  afw::table::CovarianceMatrixKey<ErrElement,3> const & shapeErr
144  ) :
145  _shape(shape), _shapeErr(shapeErr)
146  {}
147 
157  ShapeResultKey(afw::table::SubSchema const & s);
158 
160  virtual ShapeResult get(afw::table::BaseRecord const & record) const;
161 
163  virtual void set(afw::table::BaseRecord & record, ShapeResult const & value) const;
164 
166  bool operator==(ShapeResultKey const & other) const {
168  return _shape == other._shape && _shapeErr == other._shapeErr;
169  }
170  bool operator!=(ShapeResultKey const & other) const { return !(*this == other); }
172 
174  bool isValid() const { return _shape.isValid() && _shapeErr.isValid(); }
175 
177  afw::table::QuadrupoleKey getShape() const { return _shape; }
178 
180  afw::table::CovarianceMatrixKey<ErrElement,3> getShapeErr() const { return _shapeErr; }
181 
183  afw::table::Key<ShapeElement> getIxx() const { return _shape.getIxx(); }
184 
186  afw::table::Key<ShapeElement> getIyy() const { return _shape.getIyy(); }
187 
189  afw::table::Key<ShapeElement> getIxy() const { return _shape.getIxy(); }
190 
191 private:
192  afw::table::QuadrupoleKey _shape;
193  afw::table::CovarianceMatrixKey<ErrElement,3> _shapeErr;
194 };
195 
216 ShapeTrMatrix makeShapeTransformMatrix(afw::geom::LinearTransform const & xform);
217 
218 }}} // lsst::meas::base
219 
220 #endif // !LSST_MEAS_BASE_ShapeUtilities_h_INCLUDED
ShapeResultKey(afw::table::QuadrupoleKey const &shape, afw::table::CovarianceMatrixKey< ErrElement, 3 > const &shapeErr)
Construct from a pair of Keys.
ShapeTrMatrix makeShapeTransformMatrix(afw::geom::LinearTransform const &xform)
Construct a matrix suitable for transforming second moments.
ErrElement yy_xy_Cov
yy,xy term in the uncertainty convariance matrix
Eigen::Matrix< ErrElement, 3, 3, Eigen::DontAlign > ShapeCov
Definition: constants.h:59
UncertaintyEnum
An enum used to specify how much uncertainty information measurement algorithms provide.
Definition: constants.h:41
Shape const getShape() const
Return an afw::geom::ellipses object corresponding to xx, yy, xy.
ShapeResultKey()
Default constructor; instance will not be usuable unless subsequently assigned to.
afw::geom::ellipses::Quadrupole getQuadrupole()
STL namespace.
afw::table::Key< ShapeElement > getIyy() const
Return a Key for the yy moment.
ErrElement xySigma
1-Sigma uncertainty on xy (sqrt of variance)
float ErrElement
Definition: constants.h:53
A FunctorKey for ShapeResult.
afw::table::Key< ShapeElement > getIxx() const
Return a Key for the xx moment.
afw::table::CovarianceMatrixKey< ErrElement, 3 > getShapeErr() const
Return a FunctorKey to just the uncertainty matrix.
bool operator!=(ShapeResultKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Keys.
ErrElement xx_xy_Cov
xx,xy term in the uncertainty convariance matrix
void setShapeErr(ShapeCov const &matrix)
Set the struct uncertainty elements from the given matrix, with rows and columns ordered (xx...
ErrElement xx_yy_Cov
xx,yy term in the uncertainty convariance matrix
afw::geom::ellipses::Quadrupole Shape
Definition: constants.h:58
A reusable struct for moments-based shape measurements.
Definition: mainpage.dox:3
ShapeResult()
Constructor; initializes everything to NaN.
ShapeResult(ShapeElement xx_, ShapeElement yy_, ShapeElement xy_, ShapeCov const &matrix)
Constructor; initializes everything from values.
bool isValid() const
Return True if the shape key is valid.
ShapeResult(ShapeElement xx_, ShapeElement yy_, ShapeElement xy_, ErrElement xxSigma_, ErrElement yySigma_, ErrElement xySigma_)
Constructor; initializes everything from values.
ErrElement yySigma
1-Sigma uncertainty on yy (sqrt of variance)
double ShapeElement
Definition: constants.h:55
ErrElement xxSigma
1-Sigma uncertainty on xx (sqrt of variance)
void setShape(Shape const &shape)
Set struct elements from the given Quadrupole object.
Eigen::Matrix< ShapeElement, 3, 3, Eigen::DontAlign > ShapeTrMatrix
Definition: constants.h:60
afw::table::Key< ShapeElement > getIxy() const
Return a Key for the xy moment.
afw::table::QuadrupoleKey getShape() const
Return a FunctorKey to just the shape value.
ShapeCov const getShapeErr() const
Return the 3x3 symmetric covariance matrix, with rows and columns ordered (xx, yy, xy)