LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
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.