LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
LSSTDataManagementBasePackage
SipApproximation.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * Developed for the LSST Data Management System.
4  * This product includes software developed by the LSST Project
5  * (https://www.lsst.org).
6  * See the COPYRIGHT file at the top-level directory of this distribution
7  * for details of code ownership.
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 GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef LSST_AFW_GEOM_SipApproximation_h_INCLUDED
24 #define LSST_AFW_GEOM_SipApproximation_h_INCLUDED
25 
26 #include <memory>
27 #include <vector>
28 
29 #include "Eigen/Core"
30 
32 #include "lsst/afw/geom/Box.h"
34 
35 namespace lsst { namespace afw { namespace geom {
36 
94 class SipApproximation final {
95 public:
96 
129  Point2D const & crpix,
130  Eigen::Matrix2d const & cd,
131  Box2D const & bbox,
132  Extent2I const & gridShape,
133  int order,
134  bool useInverse=true,
135  double svdThreshold=-1
136  );
137 
178  Point2D const & crpix,
179  Eigen::Matrix2d const & cd,
180  Box2D const & bbox,
181  Extent2I const & gridShape,
182  ndarray::Array<double const, 2> const & a,
183  ndarray::Array<double const, 2> const & b,
184  ndarray::Array<double const, 2> const & ap,
185  ndarray::Array<double const, 2> const & bp,
186  bool useInverse=true
187  );
188 
189  // No copies just because they'd be a pain to implement and probably aren't necessary
190  SipApproximation(SipApproximation const &) = delete;
191  SipApproximation & operator=(SipApproximation const &) = delete;
192 
193  // Moves are fine.
194  SipApproximation(SipApproximation &&) noexcept = default;
195  SipApproximation & operator=(SipApproximation &&) noexcept = default;
196 
197  // Needs to be defined in .cc, where compiler can see the definitions of forward-declared
198  // private implementation classes.
199  ~SipApproximation() noexcept;
200 
202  int getOrder() const noexcept;
203 
211  double getA(int p, int q) const;
212 
220  double getB(int p, int q) const;
221 
229  double getAP(int p, int q) const;
230 
238  double getBP(int p, int q) const;
239 
241  Eigen::MatrixXd getA() const noexcept;
242 
244  Eigen::MatrixXd getB() const noexcept;
245 
247  Eigen::MatrixXd getAP() const noexcept;
248 
250  Eigen::MatrixXd getBP() const noexcept;
251 
259  Point2D applyForward(Point2D const & pix) const;
260 
267 
275  Point2D applyInverse(Point2D const & iwcs) const;
276 
283 
285  Extent2D getGridStep() const noexcept;
286 
288  Extent2I getGridShape() const noexcept;
289 
291  Box2D getBBox() const noexcept { return _bbox; }
292 
294  Point2D getPixelOrigin() const noexcept { return Point2D(_crpix); }
295 
297  Eigen::Matrix2d getCdMatrix() const noexcept { return _cdInv.inverted().getMatrix(); }
298 
311  void updateGrid(Extent2I const & shape);
312 
321  void refineGrid(int factor=2);
322 
338  void fit(int order, double svdThreshold=-1);
339 
353 
354 private:
355 
356  struct Grid;
357  struct Solution;
358 
359  bool _useInverse;
361  Box2D _bbox;
362  Extent2D _crpix;
363  LinearTransform _cdInv;
366 };
367 
368 }}} // namespace lsst::afw::geom
369 
370 #endif // !LSST_AFW_GEOM_SipApproximation_h_INCLUDED
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
Eigen::MatrixXd getA() const noexcept
Return the coefficients of the forward transform polynomial.
Point2D getPixelOrigin() const noexcept
Return the pixel origin of the WCS being approximated.
Eigen::Matrix2d getCdMatrix() const noexcept
Return the CD matrix of the WCS being approximated.
Matrix const & getMatrix() const noexcept
SipApproximation(std::shared_ptr< TransformPoint2ToPoint2 > pixelToIwc, Point2D const &crpix, Eigen::Matrix2d const &cd, Box2D const &bbox, Extent2I const &gridShape, int order, bool useInverse=true, double svdThreshold=-1)
Construct a new approximation by fitting on a grid of points.
A fitter and results class for approximating a general Transform in a form compatible with FITS WCS p...
table::Key< table::Array< double > > cd
Definition: OldWcs.cc:132
A floating-point coordinate rectangle geometry.
Definition: Box.h:413
table::PointKey< double > crpix
Definition: OldWcs.cc:131
table::Key< int > b
table::Key< int > a
Point2D applyForward(Point2D const &pix) const
Convert a point from pixels to intermediate world coordinates.
Eigen::MatrixXd getB() const noexcept
Return the coefficients of the forward transform polynomial.
A base class for image defects.
Eigen::MatrixXd getBP() const noexcept
Return the coefficients of the reverse transform polynomial.
Point2D applyInverse(Point2D const &iwcs) const
Convert a point from intermediate world coordinates to pixels.
Eigen::MatrixXd getAP() const noexcept
Return the coefficients of the reverse transform polynomial.
Extent2D getGridStep() const noexcept
Return the distance between grid points in pixels.
void refineGrid(int factor=2)
Update the grid by making it finer by a given integer factor.
STL class.
std::pair< double, double > computeMaxDeviation() const noexcept
Return the maximum deviation of the solution from the exact transform on the current grid...
Extent2I getGridShape() const noexcept
Return the number of grid points in x and y.
void fit(int order, double svdThreshold=-1)
Obtain a new solution at the given order with the current grid.
LinearTransform const inverted() const
Return the inverse transform.
SipApproximation & operator=(SipApproximation const &)=delete
Box2D getBBox() const noexcept
Return the pixel-coordinate bounding box over which the approximation should be valid.
void updateGrid(Extent2I const &shape)
Update the grid to the given number of points in x and y.
int getOrder() const noexcept
Return the polynomial order of the current solution (same for forward and reverse).
A 2D linear coordinate transformation.