lsst.afw  14.0-56-gfbf220870
Endpoint.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2017 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
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 LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #ifndef LSST_AFW_GEOM_ENDPOINT_H
25 #define LSST_AFW_GEOM_ENDPOINT_H
26 
27 #include <memory>
28 #include <vector>
29 
30 #include "astshim.h"
31 #include "ndarray.h"
32 
33 #include "lsst/afw/coord/Coord.h"
34 #include "lsst/afw/geom/Point.h"
35 
36 namespace lsst {
37 namespace afw {
38 namespace geom {
39 
66 template <typename PointT, typename ArrayT>
67 class BaseEndpoint {
68 public:
69  using Point = PointT;
70  using Array = ArrayT;
71 
72  BaseEndpoint(BaseEndpoint const &) = default;
73  BaseEndpoint(BaseEndpoint &&) = default;
74  BaseEndpoint &operator=(BaseEndpoint const &) = delete;
75  BaseEndpoint &operator=(BaseEndpoint &&) = delete;
76 
77  virtual ~BaseEndpoint() = default;
78 
79  int getNAxes() const { return _nAxes; }
80 
84  virtual int getNPoints(Array const &arr) const = 0;
85 
99  // Note: while defining operator==(BaseEndpoint<OtherPoint, OtherArray> const &)
100  // would be more Pythonic, it's very hard to get such a method template to play well with pybind11
101  virtual bool operator==(BaseEndpoint const & other) const noexcept;
102 
109  bool operator!=(BaseEndpoint const & other) const noexcept {
110  return !(*this == other);
111  }
112 
121  virtual std::vector<double> dataFromPoint(Point const &point) const = 0;
122 
132  virtual ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const = 0;
133 
140  virtual Point pointFromData(std::vector<double> const &data) const = 0;
141 
151  virtual Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const = 0;
152 
156  virtual std::shared_ptr<ast::Frame> makeFrame() const;
157 
165  virtual void normalizeFrame(std::shared_ptr<ast::Frame> framePtr) const {};
166 
167 protected:
175  explicit BaseEndpoint(int nAxes);
176 
177  void _assertNAxes(int nAxes) const;
178 
179  int _getNAxes(ndarray::Array<double, 2, 2> const &data) const { return data.getSize<0>(); }
180 
181  int _getNAxes(ndarray::Array<double, 1, 1> const &data) const { return data.getSize<0>(); }
182 
183  int _getNAxes(std::vector<double> const &data) const { return data.size(); }
184 
185  int _getNPoints(ndarray::Array<double, 2, 2> const &data) const { return data.getSize<1>(); }
186 
187 private:
188  int _nAxes;
189 };
190 
191 
197 template <typename PointT>
198 class BaseVectorEndpoint : public BaseEndpoint<PointT, std::vector<PointT>> {
199 public:
201  using Point = PointT;
202 
203  BaseVectorEndpoint(BaseVectorEndpoint const &) = default;
207 
208  virtual ~BaseVectorEndpoint() = default;
209 
210  virtual int getNPoints(Array const &arr) const override;
211 
212 protected:
220  explicit BaseVectorEndpoint(int nAxes) : BaseEndpoint<Point, Array>(nAxes){};
221 };
222 
229 class GenericEndpoint : public BaseEndpoint<std::vector<double>, ndarray::Array<double, 2, 2>> {
230 public:
231  GenericEndpoint(GenericEndpoint const &) = default;
232  GenericEndpoint(GenericEndpoint &&) = default;
233  GenericEndpoint &operator=(GenericEndpoint const &) = delete;
235 
243  explicit GenericEndpoint(int nAxes) : BaseEndpoint(nAxes){};
244 
245  virtual ~GenericEndpoint() = default;
246 
247  virtual int getNPoints(Array const &arr) const override { return arr.getSize<1>(); }
248 
249  virtual std::vector<double> dataFromPoint(Point const &point) const override;
250 
251  virtual ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const override;
252 
253  virtual Point pointFromData(std::vector<double> const &data) const override;
254 
255  virtual Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const override;
256 
258  static std::string getClassPrefix() { return "Generic"; };
259 };
260 
264 class Point2Endpoint : public BaseVectorEndpoint<Point2D> {
265 public:
266  Point2Endpoint(Point2Endpoint const &) = default;
267  Point2Endpoint(Point2Endpoint &&) = default;
268  Point2Endpoint &operator=(Point2Endpoint const &) = delete;
270 
275 
286  explicit Point2Endpoint(int nAxes);
287 
288  virtual ~Point2Endpoint() = default;
289 
290  virtual std::vector<double> dataFromPoint(Point const &point) const override;
291 
292  virtual ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const override;
293 
294  virtual Point pointFromData(std::vector<double> const &data) const override;
295 
296  virtual Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const override;
297 
307  virtual void normalizeFrame(std::shared_ptr<ast::Frame> framePtr) const override;
308 
310  static std::string getClassPrefix() { return "Point2"; };
311 };
312 
318 class IcrsCoordEndpoint : public BaseVectorEndpoint<coord::IcrsCoord> {
319 public:
320  IcrsCoordEndpoint(IcrsCoordEndpoint const &) = default;
321  IcrsCoordEndpoint(IcrsCoordEndpoint &&) = default;
322  IcrsCoordEndpoint &operator=(IcrsCoordEndpoint const &) = delete;
324 
329 
340  explicit IcrsCoordEndpoint(int nAxes);
341 
342  virtual ~IcrsCoordEndpoint() = default;
343 
344  virtual std::vector<double> dataFromPoint(Point const &point) const override;
345 
346  virtual ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const override;
347 
348  virtual Point pointFromData(std::vector<double> const &data) const override;
349 
350  virtual Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const override;
351 
353  virtual std::shared_ptr<ast::Frame> makeFrame() const override;
354 
356  virtual void normalizeFrame(std::shared_ptr<ast::Frame> framePtr) const override;
357 
359  static std::string getClassPrefix() { return "IcrsCoord"; };
360 };
361 
364 
366 std::ostream &operator<<(std::ostream &os, Point2Endpoint const &endpoint);
367 
370 
371 } // namespace geom
372 } // namespace afw
373 } // namespace lsst
374 
375 #endif
static std::string getClassPrefix()
Get the class name prefix, e.g. "Point2" for "Point2Endpoint".
Definition: Endpoint.h:258
int _getNPoints(ndarray::Array< double, 2, 2 > const &data) const
Definition: Endpoint.h:185
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
void _assertNAxes(int nAxes) const
Point2Endpoint()
Construct a Point2Endpoint.
Definition: Endpoint.h:274
virtual void normalizeFrame(std::shared_ptr< ast::Frame > framePtr) const
Adjust and check the frame as needed.
Definition: Endpoint.h:165
Base class for endpoints with Array = std::vector<Point> where Point has 2 dimensions.
Definition: Endpoint.h:198
virtual Point pointFromData(std::vector< double > const &data) const =0
Get a single point from raw data.
virtual Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const =0
Get an array of points from raw data.
IcrsCoordEndpoint()
Construct a IcrsCoordEndpoint.
Definition: Endpoint.h:328
BaseVectorEndpoint(int nAxes)
Construct a BaseVectorEndpoint.
Definition: Endpoint.h:220
STL class.
int _getNAxes(ndarray::Array< double, 1, 1 > const &data) const
Definition: Endpoint.h:181
virtual int getNPoints(Array const &arr) const =0
Return the number of points in an array.
virtual std::vector< double > dataFromPoint(Point const &point) const =0
Get raw data from a single point.
A base class for image defects.
static std::string getClassPrefix()
Get the class name prefix, e.g. "Point2" for "Point2Endpoint".
Definition: Endpoint.h:359
A generic endpoint for data in the format used by ast::Mapping.
Definition: Endpoint.h:229
virtual ~BaseEndpoint()=default
virtual ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const =0
Get raw data from an array of points.
bool operator!=(BaseEndpoint const &other) const noexcept
Determine whether two endpoints do not represent the same conversion.
Definition: Endpoint.h:109
virtual int getNPoints(Array const &arr) const override
Return the number of points in an array.
Definition: Endpoint.h:247
int _getNAxes(ndarray::Array< double, 2, 2 > const &data) const
Definition: Endpoint.h:179
T size(T... args)
STL class.
An endpoint for IcrsCoord.
Definition: Endpoint.h:318
virtual bool operator==(BaseEndpoint const &other) const noexcept
Determine whether two endpoints represent the same conversion.
static std::string getClassPrefix()
Get the class name prefix, e.g. "Point2" for "Point2Endpoint".
Definition: Endpoint.h:310
An endpoint for Point2D.
Definition: Endpoint.h:264
virtual std::shared_ptr< ast::Frame > makeFrame() const
Create a Frame that can be used with this end point in a Transform.
int _getNAxes(std::vector< double > const &data) const
Definition: Endpoint.h:183
STL class.
A class to handle Icrs coordinates (inherits from Coord)
Definition: Coord.h:291
BaseEndpoint(BaseEndpoint const &)=default
GenericEndpoint(int nAxes)
Construct a GenericEndpoint with the specified number of axes.
Definition: Endpoint.h:243
Virtual base class for endpoints, which are helper classes for Transform.
Definition: Endpoint.h:67
BaseEndpoint & operator=(BaseEndpoint const &)=delete