lsst.afw  16.0-51-gb4b4a8566+2
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 <unordered_map>
28 #include <memory>
29 
30 #include "boost/iterator/transform_iterator.hpp"
31 #include "astshim/FrameSet.h"
32 
34 #include "lsst/geom/Point.h"
36 
37 namespace lsst {
38 namespace afw {
39 namespace cameraGeom {
40 
63 class TransformMap final {
64 private:
65 
66  // Functor for boost::transform_iterator: given an entry in a std::map or unordered_map, return the key
67  struct GetKey {
68  CameraSys const &operator()(std::pair<const CameraSys, int> const &p) const { return p.first; };
69  };
70 
72 
73 public:
74 
76  using CameraSysIterator = boost::transform_iterator<GetKey, CameraSysFrameIdMap::const_iterator>;
77 
78  class Builder;
79 
92  CameraSys const &reference,
93  Transforms const &transforms
94  );
95 
100  TransformMap(TransformMap const &other) = delete;
101  TransformMap(TransformMap &&other) = delete;
102  TransformMap &operator=(TransformMap const &) = delete;
103  TransformMap &operator=(TransformMap &&) = delete;
105 
106  ~TransformMap() noexcept;
107 
119  lsst::geom::Point2D transform(lsst::geom::Point2D const &point, CameraSys const &fromSys,
120  CameraSys const &toSys) const;
121 
127  std::vector<lsst::geom::Point2D> transform(std::vector<lsst::geom::Point2D> const &pointList,
128  CameraSys const &fromSys, CameraSys const &toSys) const;
129 
130  CameraSysIterator begin() const { return boost::make_transform_iterator(_frameIds.begin(), GetKey()); }
131 
132  CameraSysIterator end() const { return boost::make_transform_iterator(_frameIds.end(), GetKey()); }
133 
142  bool contains(CameraSys const &system) const noexcept;
143 
155  CameraSys const &toSys) const;
156 
162  size_t size() const noexcept;
163 
164 private:
165 
166  // Private ctor, only called by Builder::build().
168 
180  int _getFrame(CameraSys const &system) const;
181 
191  std::shared_ptr<ast::Mapping const> _getMapping(CameraSys const &fromSys, CameraSys const &toSys) const;
192 
194  static lsst::afw::geom::Point2Endpoint _pointConverter;
195 
197  std::unique_ptr<ast::FrameSet const> const _transforms;
198 
204  CameraSysFrameIdMap const _frameIds;
205 };
206 
207 
212 public:
213 
218  explicit Builder(CameraSys const & reference);
219 
222  Builder(Builder const &);
223  Builder(Builder &&); // std::vector move construct is not noexcept until C++17
224  Builder & operator=(Builder const &);
225  Builder & operator=(Builder &&); // std::vector move assignment is not noexcept until C++17
227 
228  ~Builder() noexcept;
229 
247  Builder & connect(CameraSys const & fromSys, CameraSys const & toSys,
249 
269  Builder & connect(CameraSys const & fromSys, Transforms const &transforms);
270 
289  Builder & connect(Transforms const &transforms) {
290  return connect(_reference, transforms);
291  }
292 
304 
305 private:
306 
307  struct Connection {
308  mutable bool processed;
310  CameraSys fromSys;
311  CameraSys toSys;
312  };
313 
314  CameraSys _reference;
315  std::vector<Connection> _connections;
316 };
317 
318 
319 } // namespace cameraGeom
320 } // namespace afw
321 } // namespace lsst
322 
323 #endif
A registry of 2-dimensional coordinate transforms for a specific camera.
Definition: TransformMap.h:63
Camera coordinate system; used as a key in in TransformMap.
Definition: CameraSys.h:83
STL namespace.
ItemVariant const * other
Definition: Schema.cc:55
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:50
CameraSysIterator end() const
Definition: TransformMap.h:132
Helper class used to incrementally construct TransformMap instances.
Definition: TransformMap.h:211
TransformMap & operator=(TransformMap const &)=delete
A base class for image defects.
bool contains(CameraSys const &system) const noexcept
Can this transform to and from the specified coordinate system?
Definition: TransformMap.cc:63
boost::transform_iterator< GetKey, CameraSysFrameIdMap::const_iterator > CameraSysIterator
Definition: TransformMap.h:76
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:38
TransformMap(TransformMap const &other)=delete
STL class.
size_t size() const noexcept
Get the number of supported coordinate systems.
Definition: TransformMap.cc:85
An endpoint for lsst::geom::Point2D.
Definition: Endpoint.h:261
Builder & connect(Transforms const &transforms)
Add multiple connections relative to a single reference CameraSys.
Definition: TransformMap.h:289
CameraSysIterator begin() const
Definition: TransformMap.h:130
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:65