LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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
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:294
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.
Point< double, 2 > Point2D
Definition: Point.h:324
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.
table::Box2IKey bbox
Definition: Detector.cc:166
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.
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.