LSST Applications 30.0.7,g0e76e35be5+e8e946ae08,g19811a7679+138f7293ba,g199a45376c+5e234f8357,g1fd858c14a+2f48dbc4c4,g262e1987ae+fb36cac54d,g29ae962dfc+d9108a0941,g2c21b0017a+4f59a27f16,g31e44d4a5c+b0138be388,g33ac35c1f1+28b9f72785,g35bb328faa+b0138be388,g40c9b15c53+823ad735c1,g47891489e3+bcc48a0b46,g53246c7159+b0138be388,g64539dfbff+e8e946ae08,g67b6fd64d1+bcc48a0b46,g74acd417e5+422380537a,g76965917b2+a5ca99c4d9,g786e29fd12+796b79145d,g7aefaa3e3d+dc0c200193,g86b635cae8+734fe384f0,g87389fa792+d8b5378923,g89139ef638+bcc48a0b46,g8bbb235e95+3f4f7f9447,g8ea07a8fe4+78a4c88802,g9290983e33+ffdc83c6f7,g92c671f44c+e8e946ae08,gaa753fd333+03f406da14,gbf99507273+b0138be388,gc49b57b85e+8df26ee1f0,gca7fc764a6+bcc48a0b46,gd7ef33dd92+bcc48a0b46,gdab6d2f7ff+422380537a,ge1c02a5578+b0138be388,ge410e46f29+bcc48a0b46,ge80df9fc40+e6db5413d1,geaed405ab2+1de65a85c6,gf5dcc679e7+35a0ce2edd,gf5f1c85443+e8e946ae08
LSST Data Management Base Package
Loading...
Searching...
No Matches
TransformMap.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#if !defined(LSST_AFW_CAMERAGEOM_TRANSFORMMAP_H)
23#define LSST_AFW_CAMERAGEOM_TRANSFORMMAP_H
24
25#include <optional>
26#include <vector>
27#include <unordered_map>
28#include <memory>
29
30#include "boost/iterator/transform_iterator.hpp"
31#include "astshim/FrameSet.h"
32
35#include "lsst/geom/Point.h"
37
38namespace lsst {
39namespace afw {
40namespace cameraGeom {
41
42class DetectorBase;
43
65class TransformMap final : public table::io::PersistableFacade<TransformMap>, public table::io::Persistable {
66private:
67 // Functor for boost::transform_iterator: given an entry in a std::map or unordered_map, return the key
68 struct GetKey {
69 CameraSys const &operator()(std::pair<const CameraSys, int> const &p) const { return p.first; };
70 };
71
72 using CameraSysFrameIdMap = std::unordered_map<CameraSys, int>;
73
74public:
76 using CameraSysIterator = boost::transform_iterator<GetKey, CameraSysFrameIdMap::const_iterator>;
77
92
106 static std::shared_ptr<TransformMap const> make(CameraSys const &reference, Transforms const &transforms);
107
123 static std::shared_ptr<TransformMap const> make(CameraSys const &reference,
124 std::vector<Connection> const &connections);
125
130 TransformMap(TransformMap const &other) = delete;
131 TransformMap(TransformMap &&other) = delete;
135
136 ~TransformMap() noexcept;
137
149 lsst::geom::Point2D transform(lsst::geom::Point2D const &point, CameraSys const &fromSys,
150 CameraSys const &toSys) const;
151
157 std::vector<lsst::geom::Point2D> transform(std::vector<lsst::geom::Point2D> const &pointList,
158 CameraSys const &fromSys, CameraSys const &toSys) const;
159
160 CameraSysIterator begin() const { return boost::make_transform_iterator(_frameIds.begin(), GetKey()); }
161
162 CameraSysIterator end() const { return boost::make_transform_iterator(_frameIds.end(), GetKey()); }
163
172 bool contains(CameraSys const &system) const noexcept;
173
185 CameraSys const &toSys) const;
186
192 size_t size() const noexcept;
193
201 std::vector<Connection> getConnections() const;
202
210 bool getFocalPlaneParity() const noexcept;
211
215 bool isPersistable() const noexcept override { return true; }
216
231 std::string const & focalPlaneUnit = "mm"
232 ) const;
233
234private:
235 // Helper class used in persistence.
236 class Factory;
237
238 // Private ctor, only called by `make` static methods and `Factory`.
239 explicit TransformMap(std::vector<Connection> &&connections);
240
241 /*
242 * Return the internal frame ID corresponding to a coordinate system.
243 *
244 * @param system The system to convert.
245 * @return the ID by which the coordinate system can be found in transforms.
246 *
247 * @throws lsst::pex::exceptions::InvalidParameterError Thrown if `system`
248 * is not in frameIds.
249 *
250 * @exceptsafe Provides strong exception guarantee.
251 */
252 int _getFrame(CameraSys const &system) const;
253
254 /*
255 * Return ast::Mapping that transforms between two coordinate systems.
256 *
257 * @param fromSys, toSys Coordinate systems between which to transform
258 * @return an invertible Mapping that converts from `fromSys` to `toSys`
259 *
260 * @throws lsst::pex::exceptions::InvalidParameterError Thrown if either
261 * `fromSys` or `toSys` is not supported.
262 */
263 std::shared_ptr<ast::Mapping const> _getMapping(CameraSys const &fromSys, CameraSys const &toSys) const;
264
265 std::string getPersistenceName() const override;
266
267 std::string getPythonModule() const override;
268
269 void write(OutputArchiveHandle &handle) const override;
270
271 /*
272 * Sequence of connections that define the edges of the graph.
273 * Ordered by distance from the reference system.
274 */
275 std::vector<Connection> _connections;
276
277 // Stores information on all relationships between Transforms.
279
280 /*
281 * Translates from LSST coordinate ID to AST frame ID.
282 *
283 * Must have exactly one mapping for each Frame in `transforms`.
284 */
285 CameraSysFrameIdMap _frameIds;
286
287 bool _focalPlaneParity;
288};
289
290std::ostream &operator<<(std::ostream &os, TransformMap::Connection const &connection);
291
292} // namespace cameraGeom
293} // namespace afw
294} // namespace lsst
295
296#endif
Camera coordinate system; used as a key in in TransformMap.
Definition CameraSys.h:83
An abstract base class that provides common accessors for Detector and Detector::Builder.
Definition Detector.h:56
static std::shared_ptr< TransformMap const > make(CameraSys const &reference, Transforms const &transforms)
Construct a TransformMap with all transforms relative to a single reference CameraSys.
bool isPersistable() const noexcept override
TransformMaps should always be Persistable.
TransformMap & operator=(TransformMap const &)=delete
bool getFocalPlaneParity() const noexcept
Return True if there is an x-axis flip from FOCAL_PLANE to FIELD_ANGLE, false otherwise.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
CameraSysIterator begin() const
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
boost::transform_iterator< GetKey, CameraSysFrameIdMap::const_iterator > CameraSysIterator
TransformMap(TransformMap const &other)=delete
std::unordered_map< CameraSys, std::shared_ptr< geom::TransformPoint2ToPoint2 > > Transforms
CameraSysIterator end() const
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
size_t size() const noexcept
Get the number of supported coordinate systems.
bool contains(CameraSys const &system) const noexcept
Can this transform to and from the specified coordinate system?
TransformMap(TransformMap &&other)=delete
TransformMap & operator=(TransformMap &&)=delete
std::vector< Connection > getConnections() const
Return the sequence of connections used to construct this Transform.
std::shared_ptr< geom::TransformPoint2ToPoint2 > getTransform(CameraSys const &fromSys, CameraSys const &toSys) const
Get a Transform from one camera coordinate system to another.
std::unique_ptr< ast::FrameSet > makeFrameSet(std::vector< std::shared_ptr< DetectorBase > > const &detectors, std::string const &focalPlaneUnit="mm") const
Return an AST FrameSet with the standard transforms for this camera.
lsst::geom::Point2D transform(lsst::geom::Point2D const &point, CameraSys const &fromSys, CameraSys const &toSys) const
Convert a point from one camera coordinate system to another.
A CRTP facade class for subclasses of Persistable.
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition Persistable.h:74
io::OutputArchiveHandle OutputArchiveHandle
std::ostream & operator<<(std::ostream &os, CameraSysPrefix const &detSysPrefix)
Definition CameraSys.cc:47
STL namespace.
Representation of a single edge in the graph defined by a TransformMap.
void reverse()
Reverse the connection, by swapping fromSys and toSys and inverting the transform.
std::shared_ptr< geom::TransformPoint2ToPoint2 const > transform