LSST Applications g042eb84c57+730a74494b,g04e9c324dd+8c5ae1fdc5,g134cb467dc+1f1e3e7524,g199a45376c+0ba108daf9,g1fd858c14a+fa7d31856b,g210f2d0738+f66ac109ec,g262e1987ae+83a3acc0e5,g29ae962dfc+d856a2cb1f,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+a1e0c9f713,g47891489e3+0d594cb711,g4d44eb3520+c57ec8f3ed,g4d7b6aa1c5+f66ac109ec,g53246c7159+8c5ae1fdc5,g56a1a4eaf3+fd7ad03fde,g64539dfbff+f66ac109ec,g67b6fd64d1+0d594cb711,g67fd3c3899+f66ac109ec,g6985122a63+0d594cb711,g74acd417e5+3098891321,g786e29fd12+668abc6043,g81db2e9a8d+98e2ab9f28,g87389fa792+8856018cbb,g89139ef638+0d594cb711,g8d7436a09f+80fda9ce03,g8ea07a8fe4+760ca7c3fc,g90f42f885a+033b1d468d,g97be763408+a8a29bda4b,g99822b682c+e3ec3c61f9,g9d5c6a246b+0d5dac0c3d,ga41d0fce20+9243b26dd2,gbf99507273+8c5ae1fdc5,gd7ef33dd92+0d594cb711,gdab6d2f7ff+3098891321,ge410e46f29+0d594cb711,geaed405ab2+c4bbc419c6,gf9a733ac38+8c5ae1fdc5,w.2025.38
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
63class TransformMap final : public table::io::PersistableFacade<TransformMap>, public table::io::Persistable {
64private:
65 // Functor for boost::transform_iterator: given an entry in a std::map or unordered_map, return the key
66 struct GetKey {
67 CameraSys const &operator()(std::pair<const CameraSys, int> const &p) const { return p.first; };
68 };
69
70 using CameraSysFrameIdMap = std::unordered_map<CameraSys, int>;
71
72public:
74 using CameraSysIterator = boost::transform_iterator<GetKey, CameraSysFrameIdMap::const_iterator>;
75
90
104 static std::shared_ptr<TransformMap const> make(CameraSys const &reference, Transforms const &transforms);
105
121 static std::shared_ptr<TransformMap const> make(CameraSys const &reference,
122 std::vector<Connection> const &connections);
123
128 TransformMap(TransformMap const &other) = delete;
129 TransformMap(TransformMap &&other) = delete;
133
134 ~TransformMap() noexcept;
135
147 lsst::geom::Point2D transform(lsst::geom::Point2D const &point, CameraSys const &fromSys,
148 CameraSys const &toSys) const;
149
155 std::vector<lsst::geom::Point2D> transform(std::vector<lsst::geom::Point2D> const &pointList,
156 CameraSys const &fromSys, CameraSys const &toSys) const;
157
158 CameraSysIterator begin() const { return boost::make_transform_iterator(_frameIds.begin(), GetKey()); }
159
160 CameraSysIterator end() const { return boost::make_transform_iterator(_frameIds.end(), GetKey()); }
161
170 bool contains(CameraSys const &system) const noexcept;
171
183 CameraSys const &toSys) const;
184
190 size_t size() const noexcept;
191
199 std::vector<Connection> getConnections() const;
200
208 bool getFocalPlaneParity() const noexcept;
209
213 bool isPersistable() const noexcept override { return true; }
214
215private:
216 // Helper class used in persistence.
217 class Factory;
218
219 // Private ctor, only called by `make` static methods and `Factory`.
220 explicit TransformMap(std::vector<Connection> &&connections);
221
222 /*
223 * Return the internal frame ID corresponding to a coordinate system.
224 *
225 * @param system The system to convert.
226 * @return the ID by which the coordinate system can be found in transforms.
227 *
228 * @throws lsst::pex::exceptions::InvalidParameterError Thrown if `system`
229 * is not in frameIds.
230 *
231 * @exceptsafe Provides strong exception guarantee.
232 */
233 int _getFrame(CameraSys const &system) const;
234
235 /*
236 * Return ast::Mapping that transforms between two coordinate systems.
237 *
238 * @param fromSys, toSys Coordinate systems between which to transform
239 * @return an invertible Mapping that converts from `fromSys` to `toSys`
240 *
241 * @throws lsst::pex::exceptions::InvalidParameterError Thrown if either
242 * `fromSys` or `toSys` is not supported.
243 */
244 std::shared_ptr<ast::Mapping const> _getMapping(CameraSys const &fromSys, CameraSys const &toSys) const;
245
246 std::string getPersistenceName() const override;
247
248 std::string getPythonModule() const override;
249
250 void write(OutputArchiveHandle &handle) const override;
251
252 /*
253 * Sequence of connections that define the edges of the graph.
254 * Ordered by distance from the reference system.
255 */
256 std::vector<Connection> _connections;
257
258 // Stores information on all relationships between Transforms.
260
261 /*
262 * Translates from LSST coordinate ID to AST frame ID.
263 *
264 * Must have exactly one mapping for each Frame in `transforms`.
265 */
266 CameraSysFrameIdMap _frameIds;
267
268 bool _focalPlaneParity;
269};
270
271std::ostream &operator<<(std::ostream &os, TransformMap::Connection const &connection);
272
273} // namespace cameraGeom
274} // namespace afw
275} // namespace lsst
276
277#endif
Camera coordinate system; used as a key in in TransformMap.
Definition CameraSys.h:83
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.
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