LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
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 <vector>
26#include <unordered_map>
27#include <memory>
28
29#include "boost/iterator/transform_iterator.hpp"
30#include "astshim/FrameSet.h"
31
34#include "lsst/geom/Point.h"
36
37namespace lsst {
38namespace afw {
39namespace cameraGeom {
40
62class TransformMap final : public table::io::PersistableFacade<TransformMap>, public table::io::Persistable {
63private:
64
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
71
72public:
73
75 using CameraSysIterator = boost::transform_iterator<GetKey, CameraSysFrameIdMap::const_iterator>;
76
91
106 CameraSys const &reference,
107 Transforms const &transforms
108 );
109
126 CameraSys const &reference,
127 std::vector<Connection> const & connections
128 );
129
134 TransformMap(TransformMap const &other) = delete;
135 TransformMap(TransformMap &&other) = delete;
139
140 ~TransformMap() noexcept;
141
153 lsst::geom::Point2D transform(lsst::geom::Point2D const &point, CameraSys const &fromSys,
154 CameraSys const &toSys) const;
155
161 std::vector<lsst::geom::Point2D> transform(std::vector<lsst::geom::Point2D> const &pointList,
162 CameraSys const &fromSys, CameraSys const &toSys) const;
163
164 CameraSysIterator begin() const { return boost::make_transform_iterator(_frameIds.begin(), GetKey()); }
165
166 CameraSysIterator end() const { return boost::make_transform_iterator(_frameIds.end(), GetKey()); }
167
176 bool contains(CameraSys const &system) const noexcept;
177
189 CameraSys const &toSys) const;
190
196 size_t size() const noexcept;
197
205 std::vector<Connection> getConnections() const;
206
210 bool isPersistable() const noexcept override { return true; }
211
212private:
213
214 // Helper class used in persistence.
215 class Factory;
216
217 // Private ctor, only called by `make` static methods and `Factory`.
218 explicit TransformMap(std::vector<Connection> && connections);
219
220 /*
221 * Return the internal frame ID corresponding to a coordinate system.
222 *
223 * @param system The system to convert.
224 * @return the ID by which the coordinate system can be found in transforms.
225 *
226 * @throws lsst::pex::exceptions::InvalidParameterError Thrown if `system`
227 * is not in frameIds.
228 *
229 * @exceptsafe Provides strong exception guarantee.
230 */
231 int _getFrame(CameraSys const &system) const;
232
233 /*
234 * Return ast::Mapping that transforms between two coordinate systems.
235 *
236 * @param fromSys, toSys Coordinate systems between which to transform
237 * @return an invertible Mapping that converts from `fromSys` to `toSys`
238 *
239 * @throws lsst::pex::exceptions::InvalidParameterError Thrown if either
240 * `fromSys` or `toSys` is not supported.
241 */
242 std::shared_ptr<ast::Mapping const> _getMapping(CameraSys const &fromSys, CameraSys const &toSys) const;
243
244 std::string getPersistenceName() const override;
245
246 std::string getPythonModule() const override;
247
248 void write(OutputArchiveHandle& handle) const override;
249
250 /*
251 * Sequence of connections that define the edges of the graph.
252 * Ordered by distance from the reference system.
253 */
254 std::vector<Connection> _connections;
255
256 // Stores information on all relationships between Transforms.
258
259 /*
260 * Translates from LSST coordinate ID to AST frame ID.
261 *
262 * Must have exactly one mapping for each Frame in `transforms`.
263 */
264 CameraSysFrameIdMap _frameIds;
265
266};
267
268
269std::ostream & operator<<(std::ostream & os, TransformMap::Connection const & connection);
270
271} // namespace cameraGeom
272} // namespace afw
273} // namespace lsst
274
275#endif
table::Key< int > transform
T begin(T... args)
Camera coordinate system; used as a key in in TransformMap.
Definition CameraSys.h:83
A registry of 2-dimensional coordinate transforms for a specific camera.
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
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
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.
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
T end(T... args)
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