LSSTApplications  16.0-1-gce273f5+17,16.0-1-gf77f410+12,16.0-10-g5a5abec+8,16.0-10-gc1446dd+12,16.0-12-g1dc09ba+6,16.0-12-g569485f,16.0-12-ga22ed6e+1,16.0-13-g4c33ca5+12,16.0-13-gb122224+3,16.0-13-gd9b1b71+12,16.0-14-g22e2ff2,16.0-14-g71e547a+8,16.0-17-g0bdc215+4,16.0-17-g6a7bfb3b+12,16.0-2-g0febb12+14,16.0-2-g839ba83+50,16.0-2-g9d5294e+39,16.0-20-ga7ad2685,16.0-3-g404ea43+9,16.0-3-gbc759ec+10,16.0-3-gcfd6c53+37,16.0-4-g03cf288+28,16.0-4-g13a27c5+14,16.0-4-g5f3a788+13,16.0-4-g8a0f11a+34,16.0-4-ga3eb747+3,16.0-45-g4805a823c,16.0-5-g1991253+12,16.0-5-g1e9226d+1,16.0-5-g865efd9+12,16.0-5-gb3f8a4b+44,16.0-5-gd0f1235+6,16.0-6-gf0acd13+31,16.0-6-gf9cb114+13,16.0-7-g6043bfc,16.0-7-ga8e1655+8,16.0-8-g23bbf3f+3,16.0-8-g4dec96c+25,16.0-8-gfd407c0+2,master-g965b868a3d+1,master-gdc6be1965f+1,w.2018.39
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 
66 template <class FromEndpoint, class ToEndpoint>
67 class Transform final : public table::io::PersistableFacade<Transform<FromEndpoint, ToEndpoint>>,
68  public table::io::Persistable {
69  // SkyWcs is a friend so it can call a protected Transform constructor
70  friend class SkyWcs;
71 
72 public:
73  using FromArray = typename FromEndpoint::Array;
74  using FromPoint = typename FromEndpoint::Point;
75  using ToArray = typename ToEndpoint::Array;
76  using ToPoint = typename ToEndpoint::Point;
77 
78  Transform(Transform const &) = default;
79  Transform(Transform &&) = default;
80  Transform &operator=(Transform const &) = delete;
81  Transform &operator=(Transform &&) = delete;
82  ~Transform() override = default;
83 
91  explicit Transform(ast::Mapping const &mapping, bool simplify = true);
92 
111  explicit Transform(ast::FrameSet const &frameSet, bool simplify = true);
112 
118  bool hasForward() const { return _mapping->hasForward(); }
119 
125  bool hasInverse() const { return _mapping->hasInverse(); }
126 
130  FromEndpoint getFromEndpoint() const { return _fromEndpoint; }
131 
135  std::shared_ptr<const ast::Mapping> getMapping() const { return _mapping; }
136 
140  ToEndpoint getToEndpoint() const { return _toEndpoint; }
141 
145  ToPoint applyForward(FromPoint const &point) const;
146 
154  ToArray applyForward(FromArray const &array) const;
155 
159  FromPoint applyInverse(ToPoint const &point) const;
160 
168  FromArray applyInverse(ToArray const &array) const;
169 
171 
184 
206  Eigen::MatrixXd getJacobian(FromPoint const &x) const;
207 
228  template <class NextToEndpoint>
230  Transform<ToEndpoint, NextToEndpoint> const &next, bool simplify = true) const;
231 
241 
248 
251 
264  void writeStream(std::ostream &os) const;
265 
267  std::string writeString() const;
268 
270  bool isPersistable() const noexcept override { return true; }
271 
272 protected:
277 
278  // implement afw::table::io::Persistable interface
279  std::string getPersistenceName() const override { return getShortClassName(); }
280 
281  // implement afw::table::io::Persistable interface
282  std::string getPythonModule() const override { return "lsst.afw.geom"; }
283 
284  // implement afw::table::io::Persistable interface
285  void write(OutputArchiveHandle &handle) const override;
286 
287 private:
288  FromEndpoint _fromEndpoint;
290  ToEndpoint _toEndpoint;
291 };
292 
300 template <class FromEndpoint, class ToEndpoint>
301 std::ostream &operator<<(std::ostream &os, Transform<FromEndpoint, ToEndpoint> const &transform);
302 
303 // typedefs for the most common transforms; names match Python names
304 
308 
309 } // namespace geom
310 } // namespace afw
311 } // namespace lsst
312 
313 #endif
ToEndpoint getToEndpoint() const
Get the "to" endpoint.
Definition: Transform.h:140
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.
Definition: Transform.cc:151
FromEndpoint getFromEndpoint() const
Get the "from" endpoint.
Definition: Transform.h:130
ToPoint applyForward(FromPoint const &point) const
Transform one point in the forward direction ("from" to "to")
Definition: Transform.cc:79
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:115
bool hasInverse() const
Test if this method has an inverse transform.
Definition: Transform.h:125
std::shared_ptr< Transform< FromEndpoint, NextToEndpoint > > then(Transform< ToEndpoint, NextToEndpoint > const &next, bool simplify=true) const
Concatenate two Transforms.
Definition: Transform.cc:171
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.
Definition: Transform.h:182
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:282
std::shared_ptr< const ast::Mapping > getMapping() const
Get the contained mapping.
Definition: Transform.h:135
std::shared_ptr< Transform< ToEndpoint, FromEndpoint > > inverted() const
The inverse of this Transform.
Definition: Transform.cc:111
Transform(Transform const &)=default
static std::string getShortClassName()
Return a short version of the class name with no punctuation.
Definition: Transform.cc:138
table::Key< int > transform
An abstract base class for objects which transform one set of coordinates to another.
Definition: Mapping.h:59
STL class.
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:118
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: Transform.h:279
A base class for image defects.
Definition: cameraGeom.dox:3
FromPoint applyInverse(ToPoint const &point) const
Transform one point in the inverse direction ("to" to "from")
Definition: Transform.cc:95
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: Transform.cc:243
static std::shared_ptr< Transform< FromEndpoint, ToEndpoint > > readStream(std::istream &is)
Deserialize a Transform of this type from an input stream.
Definition: Transform.cc:145
~Transform() override=default
double x
Eigen::MatrixXd getJacobian(FromPoint const &x) const
The Jacobian matrix of this Transform.
Definition: Transform.cc:123
void writeStream(std::ostream &os) const
Serialize this Transform to an output stream.
Definition: Transform.cc:158
std::string writeString() const
Serialize this Transform to a string, using the same format as writeStream.
Definition: Transform.cc:163
bool isPersistable() const noexcept override
Whether the Transform is persistable via afw::table::io (always true).
Definition: Transform.h:270
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
STL class.
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
std::ostream * os
Definition: Schema.cc:737
Transform LSST spatial data, such as lsst::geom::Point2D and lsst::geom::SpherePoint, using an AST mapping.
Definition: Transform.h:67