LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
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 
37 namespace lsst {
38 namespace afw {
39 namespace cameraGeom {
40 
62 class TransformMap final : public table::io::PersistableFacade<TransformMap>, public table::io::Persistable {
63 private:
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 
72 public:
73 
75  using CameraSysIterator = boost::transform_iterator<GetKey, CameraSysFrameIdMap::const_iterator>;
76 
80  struct Connection final {
84 
89  void reverse();
90  };
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;
136  TransformMap &operator=(TransformMap const &) = 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 
212 private:
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 
269 std::ostream & operator<<(std::ostream & os, TransformMap::Connection const & connection);
270 
271 } // namespace cameraGeom
272 } // namespace afw
273 } // namespace lsst
274 
275 #endif
lsst::afw::cameraGeom::TransformMap::operator=
TransformMap & operator=(TransformMap const &)=delete
FrameSet.h
std::string
STL class.
std::shared_ptr
STL class.
Persistable.h
std::pair
lsst::afw::cameraGeom::TransformMap::TransformMap
TransformMap(TransformMap &&other)=delete
std::vector
STL class.
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::cameraGeom::operator<<
std::ostream & operator<<(std::ostream &os, CameraSysPrefix const &detSysPrefix)
Definition: CameraSys.cc:47
lsst::afw::cameraGeom::TransformMap::begin
CameraSysIterator begin() const
Definition: TransformMap.h:164
lsst::afw::cameraGeom::TransformMap::TransformMap
TransformMap(TransformMap const &other)=delete
lsst::afw::cameraGeom::TransformMap::~TransformMap
~TransformMap() noexcept
lsst::geom::Point2D
Point< double, 2 > Point2D
Definition: Point.h:324
CameraSys.h
lsst.pipe.tasks.mergeDetections.write
def write(self, patchRef, catalog)
Write the output.
Definition: mergeDetections.py:388
lsst::afw::cameraGeom::TransformMap::make
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.
Definition: TransformMap.cc:174
Point.h
lsst::afw::cameraGeom::TransformMap::transform
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.
Definition: TransformMap.cc:203
lsst::afw::cameraGeom::TransformMap::size
size_t size() const noexcept
Get the number of supported coordinate systems.
Definition: TransformMap.cc:238
lsst::afw::cameraGeom::TransformMap::getTransform
std::shared_ptr< geom::TransformPoint2ToPoint2 > getTransform(CameraSys const &fromSys, CameraSys const &toSys) const
Get a Transform from one camera coordinate system to another.
Definition: TransformMap.cc:218
std::ostream
STL class.
lsst::afw::cameraGeom::TransformMap::CameraSysIterator
boost::transform_iterator< GetKey, CameraSysFrameIdMap::const_iterator > CameraSysIterator
Definition: TransformMap.h:75
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::afw::cameraGeom::TransformMap::contains
bool contains(CameraSys const &system) const noexcept
Can this transform to and from the specified coordinate system?
Definition: TransformMap.cc:216
Transform.h
lsst::afw::cameraGeom::TransformMap::isPersistable
bool isPersistable() const noexcept override
TransformMaps should always be Persistable.
Definition: TransformMap.h:210
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::afw::cameraGeom::TransformMap::operator=
TransformMap & operator=(TransformMap &&)=delete
lsst::afw::cameraGeom::TransformMap::end
CameraSysIterator end() const
Definition: TransformMap.h:166
lsst::geom
Definition: AffineTransform.h:36
lsst::afw::table::io::Persistable
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
os
std::ostream * os
Definition: Schema.cc:746
lsst::afw::cameraGeom::TransformMap::getConnections
std::vector< Connection > getConnections() const
Return the sequence of connections used to construct this Transform.
Definition: TransformMap.cc:279
lsst::afw::image.slicing.Factory
Factory
Definition: slicing.py:252
std::unordered_map::begin
T begin(T... args)
std
STL namespace.
lsst::afw::cameraGeom::TransformMap::Connection::transform
std::shared_ptr< geom::TransformPoint2ToPoint2 const > transform
Definition: TransformMap.h:81
lsst::afw::table::io::PersistableFacade
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
lsst::afw::cameraGeom::TransformMap::Connection::reverse
void reverse()
Reverse the connection, by swapping fromSys and toSys and inverting the transform.
Definition: TransformMap.cc:165
std::unordered_map::end
T end(T... args)
lsst::afw::cameraGeom::TransformMap
A registry of 2-dimensional coordinate transforms for a specific camera.
Definition: TransformMap.h:62
std::unique_ptr< ast::FrameSet >
lsst::afw::table::io::Persistable::OutputArchiveHandle
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:108
lsst::afw::cameraGeom::TransformMap::Connection::fromSys
CameraSys fromSys
Definition: TransformMap.h:82
std::unordered_map< CameraSys, int >
lsst::afw::cameraGeom::TransformMap::Connection::toSys
CameraSys toSys
Definition: TransformMap.h:83
lsst::afw::cameraGeom::CameraSys
Camera coordinate system; used as a key in in TransformMap.
Definition: CameraSys.h:83
lsst::afw::cameraGeom::TransformMap::Connection
Representation of a single edge in the graph defined by a TransformMap.
Definition: TransformMap.h:80