LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
BaseCore.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
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 LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #ifndef LSST_AFW_GEOM_ELLIPSES_BaseCore_h_INCLUDED
26 #define LSST_AFW_GEOM_ELLIPSES_BaseCore_h_INCLUDED
27 
35 #include "boost/shared_ptr.hpp"
36 #include "boost/make_shared.hpp"
37 #include <memory>
38 #include "Eigen/Core"
39 
40 #include "lsst/pex/exceptions.h"
42 
43 namespace lsst { namespace afw { namespace geom { namespace ellipses {
44 
45 class Parametric;
46 
54 class BaseCore {
55 public:
56 #ifndef SWIG
57  class Transformer;
58  class GridTransform;
59  class Convolution;
60  template <typename Output> struct Converter;
61 #endif
62 
63  typedef boost::shared_ptr<BaseCore> Ptr;
64  typedef boost::shared_ptr<BaseCore const> ConstPtr;
65 
66  typedef Eigen::Vector3d ParameterVector;
67  typedef Eigen::Matrix3d Jacobian;
68 
69  static Ptr make(std::string const & name);
70 
71  static Ptr make(std::string const & name, ParameterVector const & parameters);
72 
73  static Ptr make(std::string const & name, double v1, double v2, double v3);
74 
75  static Ptr make(std::string const & name, BaseCore const & other);
76 
77 #ifndef SWIG
78  static Ptr make(std::string const & name, Transformer const & other);
79 
80  static Ptr make(std::string const & name, Convolution const & other);
81 #endif
82 
84  virtual std::string getName() const = 0;
85 
87  Ptr clone() const { return _clone(); }
88 
93  virtual void normalize() = 0;
94 
96  void grow(double buffer);
97 
99  void scale(double factor);
100 
102  double getArea() const;
103 
110  double getDeterminantRadius() const;
111 
117  double getTraceRadius() const;
118 
127  Transformer transform(LinearTransform const & transform);
128  Transformer const transform(LinearTransform const & transform) const;
130 
137  GridTransform const getGridTransform() const;
138 
143  Convolution convolve(BaseCore const & other);
144  Convolution const convolve(BaseCore const & other) const;
146 
148  Extent2D computeDimensions() const;
149 
150  virtual void readParameters(double const * iter) = 0;
151 
152  virtual void writeParameters(double * iter) const = 0;
153 
155  ParameterVector const getParameterVector() const;
156 
158  void setParameterVector(ParameterVector const & vector);
159 
165  bool operator==(BaseCore const & other) const;
166 
172  bool operator!=(BaseCore const & other) const { return !operator==(other); }
173 
179  BaseCore & operator=(BaseCore const & other);
180 
182  Jacobian dAssign(BaseCore const & other);
183 
187  template <typename Output> Converter<Output> as() const;
188 
189  virtual ~BaseCore() {}
190 
191 protected:
192 #ifndef SWIG
193  friend class Parametric;
194 
195  static void registerSubclass(Ptr const & example);
196 
197  template <typename T>
198  struct Registrar {
199  Registrar() { registerSubclass(boost::make_shared<T>()); }
200  };
201 
202  virtual BaseCore::Ptr _clone() const = 0;
203 
204  static void _assignQuadrupoleToAxes(
205  double ixx, double iyy, double ixy,
206  double & a, double & b, double & theta
207  );
208 
210  double ixx, double iyy, double ixy,
211  double & a, double & b, double & theta
212  );
213 
214  static void _assignAxesToQuadrupole(
215  double a, double b, double theta,
216  double & ixx, double & iyy, double & ixy
217  );
218 
220  double a, double b, double theta,
221  double & ixx, double & iyy, double & ixy
222  );
223 
224  virtual void _assignToQuadrupole(double & ixx, double & iyy, double & ixy) const = 0;
225  virtual void _assignFromQuadrupole(double ixx, double iyy, double ixy) = 0;
226 
227  virtual void _assignToAxes(double & a, double & b, double & theta) const = 0;
228  virtual void _assignFromAxes(double a, double b, double theta) = 0;
229 
230  virtual Jacobian _dAssignToQuadrupole(double & ixx, double & iyy, double & ixy) const = 0;
231  virtual Jacobian _dAssignFromQuadrupole(double ixx, double iyy, double ixy) = 0;
232 
233  virtual Jacobian _dAssignToAxes(double & a, double & b, double & theta) const = 0;
234  virtual Jacobian _dAssignFromAxes(double a, double b, double theta) = 0;
235 
236 #endif
237 };
238 
239 #ifndef SWIG
240 template <typename Output>
241 struct BaseCore::Converter {
242  BaseCore const & input;
243 
244  explicit Converter(BaseCore const & input_) : input(input_) {}
245 
246  operator Output() const { return Output(input); }
247  boost::shared_ptr<Output> copy() const { return boost::shared_ptr<Output>(new Output(input)); }
248 };
249 
250 template <typename Output>
252  return Converter<Output>(*this);
253 }
254 
255 #endif
256 
257 }}}} // namespace lsst::afw::geom::ellipses
258 
259 #endif // !LSST_AFW_GEOM_ELLIPSES_BaseCore_h_INCLUDED
int iter
Extent2D computeDimensions() const
Return the size of the bounding box for the ellipse core.
A temporary-only expression object for ellipse core transformations.
Definition: Transformer.h:47
static Jacobian _dAssignQuadrupoleToAxes(double ixx, double iyy, double ixy, double &a, double &b, double &theta)
A temporary-only expression object representing a LinearTransform that maps the ellipse core to a uni...
Definition: GridTransform.h:46
table::Key< std::string > name
Definition: ApCorrMap.cc:71
virtual Jacobian _dAssignToQuadrupole(double &ixx, double &iyy, double &ixy) const =0
boost::shared_ptr< BaseCore > Ptr
Definition: BaseCore.h:60
Include files required for standard LSST Exception handling.
virtual Jacobian _dAssignToAxes(double &a, double &b, double &theta) const =0
ParameterVector const getParameterVector() const
Return the core parameters as a vector.
Jacobian dAssign(BaseCore const &other)
Assign other to this and return the derivative of the conversion, d(this)/d(other).
BaseCore & operator=(BaseCore const &other)
Set the parameters of this ellipse core from another.
double getArea() const
Return the area of the ellipse core.
Transformer transform(LinearTransform const &transform)
Definition: Transformer.h:117
boost::shared_ptr< BaseCore const > ConstPtr
Definition: BaseCore.h:64
A 2D linear coordinate transformation.
Ptr clone() const
Deep-copy the Core.
Definition: BaseCore.h:87
void setParameterVector(ParameterVector const &vector)
Set the core parameters from a vector.
void grow(double buffer)
Increase the major and minor radii of the ellipse core by the given buffer.
Eigen::Vector3d ParameterVector
Parameter vector type.
Definition: BaseCore.h:66
Convolution convolve(BaseCore const &other)
Definition: Convolution.h:97
GridTransform const getGridTransform() const
Return the transform that maps the ellipse to the unit circle.
Converter< Output > as() const
Convert this to the core type specified as a template parameter.
Definition: BaseCore.h:251
double getTraceRadius() const
Return the radius defined as the square root of one half the trace of the quadrupole matrix...
virtual void _assignFromAxes(double a, double b, double theta)=0
void scale(double factor)
Scale the size of the ellipse core by the given factor.
static Ptr make(std::string const &name)
virtual void _assignToAxes(double &a, double &b, double &theta) const =0
virtual void normalize()=0
Put the parameters into a &quot;standard form&quot;, and throw InvalidParameterError if they cannot be normaliz...
static void _assignQuadrupoleToAxes(double ixx, double iyy, double ixy, double &a, double &b, double &theta)
double getDeterminantRadius() const
Return the radius defined as the 4th root of the determinant of the quadrupole matrix.
Eigen::Matrix3d Jacobian
Parameter Jacobian matrix type.
Definition: BaseCore.h:67
boost::shared_ptr< Output > copy() const
Definition: BaseCore.h:247
A base class for parametrizations of the &quot;core&quot; of an ellipse - the ellipticity and size...
Definition: BaseCore.h:54
virtual void readParameters(double const *iter)=0
A functor that returns points on the boundary of the ellipse as a function of a parameter that runs b...
Definition: Parametric.h:36
afw::table::Key< double > b
virtual std::string getName() const =0
Return a string that identifies this parametrization.
static void _assignAxesToQuadrupole(double a, double b, double theta, double &ixx, double &iyy, double &ixy)
virtual Jacobian _dAssignFromAxes(double a, double b, double theta)=0
virtual Jacobian _dAssignFromQuadrupole(double ixx, double iyy, double ixy)=0
static void registerSubclass(Ptr const &example)
bool operator!=(BaseCore const &other) const
Compare two ellipse cores for inequality.
Definition: BaseCore.h:172
virtual void _assignToQuadrupole(double &ixx, double &iyy, double &ixy) const =0
static Jacobian _dAssignAxesToQuadrupole(double a, double b, double theta, double &ixx, double &iyy, double &ixy)
A temporary-only expression object for ellipse core convolution.
Definition: Convolution.h:44
virtual void writeParameters(double *iter) const =0
virtual void _assignFromQuadrupole(double ixx, double iyy, double ixy)=0
bool operator==(BaseCore const &other) const
Compare two ellipse cores for equality.
virtual BaseCore::Ptr _clone() const =0