lsst.afw  13.0-109-g62eb66483
TransformMap.h
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2014 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #if !defined(LSST_AFW_CAMERAGEOM_TRANSFORMMAP_H)
24 #define LSST_AFW_CAMERAGEOM_TRANSFORMMAP_H
25 
26 #include <vector>
27 #include <map>
28 #include <unordered_map>
29 
30 #include "boost/iterator/transform_iterator.hpp"
31 #include "astshim/FrameSet.h"
32 
34 #include "lsst/afw/geom/Point.h"
36 
37 namespace lsst {
38 namespace afw {
39 namespace cameraGeom {
40 
57 class TransformMap final {
58 private:
59  // Functor for boost::transform_iterator: given an entry in a std::map or unordered_map, return the key
60  struct GetKey {
61  CameraSys const &operator()(std::pair<const CameraSys, int> const &p) const { return p.first; };
62  };
63 
64 public:
65  using Transforms = std::unordered_map<CameraSys, std::shared_ptr<geom::TransformPoint2ToPoint2>>;
66  using CameraSysFrameIdMap = std::unordered_map<CameraSys, int>;
67  using CameraSysIterator = boost::transform_iterator<GetKey, CameraSysFrameIdMap::const_iterator>;
68 
81  CameraSys const &reference,
82  std::unordered_map<CameraSys, std::shared_ptr<geom::TransformPoint2ToPoint2>> const &transforms);
83 
89  TransformMap(TransformMap const &other);
90 
96  TransformMap(TransformMap const &&other);
97 
100  TransformMap &operator=(TransformMap const &) = delete;
101  TransformMap &operator=(TransformMap &&) = delete;
103 
115  geom::Point2D transform(geom::Point2D const &point, CameraSys const &fromSys,
116  CameraSys const &toSys) const;
117 
123  std::vector<geom::Point2D> transform(std::vector<geom::Point2D> const &pointList,
124  CameraSys const &fromSys, CameraSys const &toSys) const;
125 
126  CameraSysIterator begin() const { return boost::make_transform_iterator(_frameIds.begin(), GetKey()); }
127 
128  CameraSysIterator end() const { return boost::make_transform_iterator(_frameIds.end(), GetKey()); }
129 
138  bool contains(CameraSys const &system) const noexcept;
139 
150  std::shared_ptr<geom::TransformPoint2ToPoint2> getTransform(CameraSys const &fromSys,
151  CameraSys const &toSys) const;
152 
158  size_t size() const noexcept;
159 
160 private:
172  int _getFrame(CameraSys const &system) const;
173 
183  std::shared_ptr<ast::Mapping const> _getMapping(CameraSys const &fromSys,
184  CameraSys const &toSys) const;
185 
187  static geom::Point2Endpoint _pointConverter;
188 
190  // May be shared between multiple copies of TransformMap, since TransformMap is immutable
191  std::shared_ptr<ast::FrameSet const> const _transforms;
192 
198  CameraSysFrameIdMap const _frameIds;
199 };
200 
201 } // namespace cameraGeom
202 } // namespace afw
203 } // namespace lsst
204 
205 #endif
A registry of 2-dimensional coordinate transforms for a specific camera.
Definition: TransformMap.h:57
Camera coordinate system; used as a key in in TransformMap.
Definition: CameraSys.h:77
TransformMap(CameraSys const &reference, std::unordered_map< CameraSys, std::shared_ptr< geom::TransformPoint2ToPoint2 >> const &transforms)
Define a set of camera transforms.
CameraSysIterator end() const
Definition: TransformMap.h:128
TransformMap & operator=(TransformMap const &)=delete
A base class for image defects.
Definition: cameraGeom.dox:3
std::unordered_map< CameraSys, std::shared_ptr< geom::TransformPoint2ToPoint2 > > Transforms
Definition: TransformMap.h:65
bool contains(CameraSys const &system) const noexcept
Can this transform to and from the specified coordinate system?
std::unordered_map< CameraSys, int > CameraSysFrameIdMap
Definition: TransformMap.h:66
boost::transform_iterator< GetKey, CameraSysFrameIdMap::const_iterator > CameraSysIterator
Definition: TransformMap.h:67
size_t size() const noexcept
Get the number of supported coordinate systems.
An endpoint for Point2D.
Definition: Endpoint.h:236
geom::Point2D transform(geom::Point2D const &point, CameraSys const &fromSys, CameraSys const &toSys) const
Convert a point from one camera coordinate system to another.
CameraSysIterator begin() const
Definition: TransformMap.h:126
std::shared_ptr< geom::TransformPoint2ToPoint2 > getTransform(CameraSys const &fromSys, CameraSys const &toSys) const
Get a Transform from one camera coordinate system to another.