LSST Applications g00274db5b6+edbf708997,g00d0e8bbd7+edbf708997,g199a45376c+5137f08352,g1fd858c14a+1d4b6db739,g262e1987ae+f4d9505c4f,g29ae962dfc+7156fb1a53,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3e17d7035e+5b3adc59f5,g3fd5ace14f+852fa6fbcb,g47891489e3+6dc8069a4c,g53246c7159+edbf708997,g64539dfbff+9f17e571f4,g67b6fd64d1+6dc8069a4c,g74acd417e5+ae494d68d9,g786e29fd12+af89c03590,g7ae74a0b1c+a25e60b391,g7aefaa3e3d+536efcc10a,g7cc15d900a+d121454f8d,g87389fa792+a4172ec7da,g89139ef638+6dc8069a4c,g8d7436a09f+28c28d8d6d,g8ea07a8fe4+db21c37724,g92c671f44c+9f17e571f4,g98df359435+b2e6376b13,g99af87f6a8+b0f4ad7b8d,gac66b60396+966efe6077,gb88ae4c679+7dec8f19df,gbaa8f7a6c5+38b34f4976,gbf99507273+edbf708997,gc24b5d6ed1+9f17e571f4,gca7fc764a6+6dc8069a4c,gcc769fe2a4+97d0256649,gd7ef33dd92+6dc8069a4c,gdab6d2f7ff+ae494d68d9,gdbb4c4dda9+9f17e571f4,ge410e46f29+6dc8069a4c,geaed405ab2+e194be0d2b,w.2025.47
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