LSSTApplications  11.0-22-g33de520,13.0+153,14.0+52,14.0+57,14.0-1-g013352c+36,14.0-1-g13ef843+9,14.0-1-g4b114ac+14,14.0-1-g7257b6a+12,14.0-1-g8b7e855+51,14.0-13-g7a60b79+2,14.0-14-g87d16e8+10,14.0-14-gbf7a6f8a,14.0-17-g4f4ea82+5,14.0-2-g319577b+11,14.0-2-ga5af9b6+10,14.0-22-gc48c03f+3,14.0-3-g20413be+3,14.0-46-g76222d5f+3,14.0-47-g0a51fac97,14.0-5-g744ff5f+2,14.0-5-g86eb1bd+31,14.0-6-gd5b81a9+6,14.0-6-ge2c9487+42,14.0-8-g7f6dd6b+6,14.0-8-gb81b6e9+4,14.0-9-g11010eb,14.0-9-g330837b+5
LSSTDataManagementBasePackage
Transform.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2017 LSST Corporation.
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_AFW_GEOM_TRANSFORM_H
25 #define LSST_AFW_GEOM_TRANSFORM_H
26 
27 #include <memory>
28 #include <vector>
29 
30 #include "astshim.h"
31 #include "Eigen/Core"
32 #include "ndarray.h"
33 
34 #include "lsst/afw/geom/Endpoint.h"
36 
37 namespace lsst {
38 namespace afw {
39 namespace geom {
40 
41 class SkyWcs;
42 
68 template <class FromEndpoint, class ToEndpoint>
69 class Transform final :
70  public table::io::PersistableFacade<Transform<FromEndpoint,ToEndpoint>>,
72 {
73  // SkyWcs is a friend so it can call a protected Transform constructor
74  friend class SkyWcs;
75 
76 public:
77  using FromArray = typename FromEndpoint::Array;
78  using FromPoint = typename FromEndpoint::Point;
79  using ToArray = typename ToEndpoint::Array;
80  using ToPoint = typename ToEndpoint::Point;
81 
82  Transform(Transform const &) = default;
83  Transform(Transform &&) = default;
84  Transform &operator=(Transform const &) = delete;
85  Transform &operator=(Transform &&) = delete;
86  ~Transform() = default;
87 
98  explicit Transform(ast::Mapping const &mapping, bool simplify = true);
99 
120  explicit Transform(ast::FrameSet const &frameSet, bool simplify = true);
121 
127  bool hasForward() const { return _frameSet->hasForward(); }
128 
134  bool hasInverse() const { return _frameSet->hasInverse(); }
135 
139  FromEndpoint getFromEndpoint() const { return _fromEndpoint; }
140 
145 
149  ToEndpoint getToEndpoint() const { return _toEndpoint; }
150 
154  ToPoint applyForward(FromPoint const &point) const;
155 
163  ToArray applyForward(FromArray const &array) const;
164 
168  FromPoint applyInverse(ToPoint const &point) const;
169 
177  FromArray applyInverse(ToArray const &array) const;
178 
188 
210  Eigen::MatrixXd getJacobian(FromPoint const &x) const;
211 
232  template <class NextToEndpoint>
234  Transform<ToEndpoint, NextToEndpoint> const &next, bool simplify = true) const;
235 
245 
252 
255 
268  void writeStream(std::ostream &os) const;
269 
271  std::string writeString() const;
272 
274  bool isPersistable() const override { return true; }
275 
276 protected:
283 
284  // implement afw::table::io::Persistable interface
285  std::string getPersistenceName() const override { return getShortClassName(); }
286 
287  // implement afw::table::io::Persistable interface
288  std::string getPythonModule() const override { return "lsst.afw.geom"; }
289 
290  // implement afw::table::io::Persistable interface
291  void write(OutputArchiveHandle &handle) const override;
292 
293 private:
294  FromEndpoint _fromEndpoint;
296  ToEndpoint _toEndpoint;
297 };
298 
306 template <class FromEndpoint, class ToEndpoint>
307 std::ostream &operator<<(std::ostream &os, Transform<FromEndpoint, ToEndpoint> const &transform);
308 
309 // typedefs for the most common transforms; names match Python names
310 
314 
315 } // namespace geom
316 } // namespace afw
317 } // namespace lsst
318 
319 #endif
ToEndpoint getToEndpoint() const
Get the "to" endpoint.
Definition: Transform.h:149
FromEndpoint getFromEndpoint() const
Get the "from" endpoint.
Definition: Transform.h:139
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:114
bool hasInverse() const
Test if this method has an inverse transform.
Definition: Transform.h:134
Transform & operator=(Transform const &)=delete
An object passed to Persistable::write to allow it to persist itself.
std::shared_ptr< Transform< ToEndpoint, FromEndpoint > > getInverse() const
The inverse of this Transform.
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition: Transform.h:288
std::shared_ptr< const ast::FrameSet > getFrameSet() const
Get the contained frameset.
Definition: Transform.h:144
Transform(Transform const &)=default
FromEndpoint _fromEndpoint
Definition: Transform.h:294
An abstract base class for objects which transform one set of coordinates to another.
Definition: Mapping.h:59
STL class.
static std::string getShortClassName()
Return a short version of the class name with no punctuation.
ToPoint applyForward(FromPoint const &point) const
Transform one point in the forward direction ("from" to "to")
STL class.
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
bool hasForward() const
Test if this method has a forward transform.
Definition: Transform.h:127
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: Transform.h:285
std::shared_ptr< Transform< FromEndpoint, NextToEndpoint > > then(Transform< ToEndpoint, NextToEndpoint > const &next, bool simplify=true) const
Concatenate two Transforms.
static std::shared_ptr< Transform< FromEndpoint, ToEndpoint > > readStream(std::istream &is)
Deserialize a Transform of this type from an input stream.
A base class for image defects.
Definition: cameraGeom.dox:3
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
std::shared_ptr< const ast::FrameSet > _frameSet
Definition: Transform.h:295
double x
Eigen::MatrixXd getJacobian(FromPoint const &x) const
The Jacobian matrix of this Transform.
bool isPersistable() const override
Whether the Transform is persistable via afw::table::io (always true).
Definition: Transform.h:274
void writeStream(std::ostream &os) const
Serialize this Transform to an output stream.
std::string writeString() const
Serialize this Transform to a string, using the same format as writeStream.
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
table::Key< int > transform
STL class.
static std::shared_ptr< Transform< FromEndpoint, ToEndpoint > > readString(std::string &str)
Deserialize a Transform of this type from a string, using the same format as readStream.
A FrameSet consists of a set of one or more Frames (which describe coordinate systems), connected together by Mappings (which describe how the coordinate systems are inter-related).
Definition: FrameSet.h:99
FromPoint applyInverse(ToPoint const &point) const
Transform one point in the inverse direction ("to" to "from")
Transform LSST spatial data, such as Point2D and IcrsCoord, using an AST transform.
Definition: Transform.h:69