LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
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/geom/Point.h"
34 #include "lsst/geom/SpherePoint.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;
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 { return !(*this == other); }
110 
119  virtual std::vector<double> dataFromPoint(Point const &point) const = 0;
120 
130  virtual ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const = 0;
131 
138  virtual Point pointFromData(std::vector<double> const &data) const = 0;
139 
149  virtual Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const = 0;
150 
154  virtual std::shared_ptr<ast::Frame> makeFrame() const;
155 
163  virtual void normalizeFrame(std::shared_ptr<ast::Frame> framePtr) const {};
164 
165 protected:
173  explicit BaseEndpoint(int nAxes);
174 
175  void _assertNAxes(int nAxes) const;
176 
177  int _getNAxes(ndarray::Array<double, 2, 2> const &data) const { return data.getSize<0>(); }
178 
179  int _getNAxes(ndarray::Array<double, 1, 1> const &data) const { return data.getSize<0>(); }
180 
181  int _getNAxes(std::vector<double> const &data) const { return data.size(); }
182 
183  int _getNPoints(ndarray::Array<double, 2, 2> const &data) const { return data.getSize<1>(); }
184 
185 private:
186  int _nAxes;
187 };
188 
194 template <typename PointT>
195 class BaseVectorEndpoint : public BaseEndpoint<PointT, std::vector<PointT>> {
196 public:
198  using Point = PointT;
199 
204 
205  ~BaseVectorEndpoint() override = default;
206 
207  int getNPoints(Array const &arr) const override;
208 
209 protected:
217  explicit BaseVectorEndpoint(int nAxes) : BaseEndpoint<Point, Array>(nAxes){};
218 };
219 
226 class GenericEndpoint : public BaseEndpoint<std::vector<double>, ndarray::Array<double, 2, 2>> {
227 public:
228  GenericEndpoint(GenericEndpoint const &) = default;
232 
240  explicit GenericEndpoint(int nAxes) : BaseEndpoint(nAxes){};
241 
242  ~GenericEndpoint() override = default;
243 
244  int getNPoints(Array const &arr) const override { return arr.getSize<1>(); }
245 
246  std::vector<double> dataFromPoint(Point const &point) const override;
247 
248  ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const override;
249 
250  Point pointFromData(std::vector<double> const &data) const override;
251 
252  Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const override;
253 
255  static std::string getClassPrefix() { return "Generic"; };
256 };
257 
261 class Point2Endpoint : public BaseVectorEndpoint<lsst::geom::Point2D> {
262 public:
263  Point2Endpoint(Point2Endpoint const &) = default;
267 
272 
283  explicit Point2Endpoint(int nAxes);
284 
285  ~Point2Endpoint() override = default;
286 
287  std::vector<double> dataFromPoint(Point const &point) const override;
288 
289  ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const override;
290 
291  Point pointFromData(std::vector<double> const &data) const override;
292 
293  Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const override;
294 
304  void normalizeFrame(std::shared_ptr<ast::Frame> framePtr) const override;
305 
307  static std::string getClassPrefix() { return "Point2"; };
308 };
309 
315 class SpherePointEndpoint : public BaseVectorEndpoint<lsst::geom::SpherePoint> {
316 public:
321 
326 
337  explicit SpherePointEndpoint(int nAxes);
338 
339  ~SpherePointEndpoint() override = default;
340 
341  std::vector<double> dataFromPoint(Point const &point) const override;
342 
343  ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const override;
344 
345  Point pointFromData(std::vector<double> const &data) const override;
346 
347  Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const override;
348 
350  std::shared_ptr<ast::Frame> makeFrame() const override;
351 
353  void normalizeFrame(std::shared_ptr<ast::Frame> framePtr) const override;
354 
356  static std::string getClassPrefix() { return "SpherePoint"; };
357 };
358 
360 std::ostream &operator<<(std::ostream &os, GenericEndpoint const &endpoint);
361 
363 std::ostream &operator<<(std::ostream &os, Point2Endpoint const &endpoint);
364 
366 std::ostream &operator<<(std::ostream &os, SpherePointEndpoint const &endpoint);
367 
368 } // namespace geom
369 } // namespace afw
370 } // namespace lsst
371 
372 #endif
char * data
Definition: BaseRecord.cc:62
ItemVariant const * other
Definition: Schema.cc:56
std::ostream * os
Definition: Schema.cc:746
Virtual base class for endpoints, which are helper classes for Transform.
Definition: Endpoint.h:67
int _getNPoints(ndarray::Array< double, 2, 2 > const &data) const
Definition: Endpoint.h:183
virtual ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const =0
Get raw data from an array of points.
BaseEndpoint(BaseEndpoint &&)=default
virtual void normalizeFrame(std::shared_ptr< ast::Frame > framePtr) const
Adjust and check the frame as needed.
Definition: Endpoint.h:163
bool operator!=(BaseEndpoint const &other) const noexcept
Determine whether two endpoints do not represent the same conversion.
Definition: Endpoint.h:109
BaseEndpoint & operator=(BaseEndpoint const &)=delete
virtual std::shared_ptr< ast::Frame > makeFrame() const
Create a Frame that can be used with this end point in a Transform.
Definition: Endpoint.cc:69
virtual Point pointFromData(std::vector< double > const &data) const =0
Get a single point from raw data.
BaseEndpoint(BaseEndpoint const &)=default
int _getNAxes(ndarray::Array< double, 1, 1 > const &data) const
Definition: Endpoint.h:179
virtual bool operator==(BaseEndpoint const &other) const noexcept
Determine whether two endpoints represent the same conversion.
Definition: Endpoint.cc:64
int _getNAxes(std::vector< double > const &data) const
Definition: Endpoint.h:181
virtual int getNPoints(Array const &arr) const =0
Return the number of points in an array.
BaseEndpoint & operator=(BaseEndpoint &&)=delete
void _assertNAxes(int nAxes) const
Definition: Endpoint.cc:74
int _getNAxes(ndarray::Array< double, 2, 2 > const &data) const
Definition: Endpoint.h:177
virtual Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const =0
Get an array of points from raw data.
virtual std::vector< double > dataFromPoint(Point const &point) const =0
Get raw data from a single point.
virtual ~BaseEndpoint()=default
Base class for endpoints with Array = std::vector<Point> where Point has 2 dimensions.
Definition: Endpoint.h:195
BaseVectorEndpoint(BaseVectorEndpoint &&)=default
BaseVectorEndpoint(int nAxes)
Construct a BaseVectorEndpoint.
Definition: Endpoint.h:217
BaseVectorEndpoint & operator=(BaseVectorEndpoint &&)=delete
BaseVectorEndpoint & operator=(BaseVectorEndpoint const &)=delete
BaseVectorEndpoint(BaseVectorEndpoint const &)=default
int getNPoints(Array const &arr) const override
Return the number of points in an array.
Definition: Endpoint.cc:83
~BaseVectorEndpoint() override=default
A generic endpoint for data in the format used by ast::Mapping.
Definition: Endpoint.h:226
GenericEndpoint(int nAxes)
Construct a GenericEndpoint with the specified number of axes.
Definition: Endpoint.h:240
std::vector< double > dataFromPoint(Point const &point) const override
Definition: Endpoint.cc:87
Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
Definition: Endpoint.cc:102
GenericEndpoint(GenericEndpoint &&)=default
GenericEndpoint & operator=(GenericEndpoint const &)=delete
GenericEndpoint(GenericEndpoint const &)=default
Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
Definition: Endpoint.cc:97
int getNPoints(Array const &arr) const override
Return the number of points in an array.
Definition: Endpoint.h:244
ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const override
Definition: Endpoint.cc:92
GenericEndpoint & operator=(GenericEndpoint &&)=delete
static std::string getClassPrefix()
Get the class name prefix, e.g. "Point2" for "Point2Endpoint".
Definition: Endpoint.h:255
~GenericEndpoint() override=default
An endpoint for lsst::geom::Point2D.
Definition: Endpoint.h:261
Point2Endpoint()
Construct a Point2Endpoint.
Definition: Endpoint.h:271
ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const override
Get raw data from an array of points.
Definition: Endpoint.cc:124
Point2Endpoint & operator=(Point2Endpoint const &)=delete
~Point2Endpoint() override=default
std::vector< double > dataFromPoint(Point const &point) const override
Get raw data from a single point.
Definition: Endpoint.cc:115
Point2Endpoint(Point2Endpoint const &)=default
static std::string getClassPrefix()
Get the class name prefix, e.g. "Point2" for "Point2Endpoint".
Definition: Endpoint.h:307
Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
Definition: Endpoint.cc:138
Point2Endpoint(Point2Endpoint &&)=default
Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
Definition: Endpoint.cc:148
Point2Endpoint & operator=(Point2Endpoint &&)=delete
void normalizeFrame(std::shared_ptr< ast::Frame > framePtr) const override
Check that framePtr points to a Frame, not a subclass.
Definition: Endpoint.cc:160
An endpoint for lsst::geom::SpherePoint.
Definition: Endpoint.h:315
ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const override
Get raw data from an array of points.
Definition: Endpoint.cc:187
std::vector< double > dataFromPoint(Point const &point) const override
Get raw data from a single point.
Definition: Endpoint.cc:178
SpherePointEndpoint()
Construct a SpherePointEndpoint.
Definition: Endpoint.h:325
SpherePointEndpoint & operator=(SpherePointEndpoint const &)=delete
SpherePointEndpoint(SpherePointEndpoint &&)=default
Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
Definition: Endpoint.cc:206
std::shared_ptr< ast::Frame > makeFrame() const override
Create a Frame that can be used with this end point in a Transform.
Definition: Endpoint.cc:218
static std::string getClassPrefix()
Get the class name prefix, e.g. "Point2" for "Point2Endpoint".
Definition: Endpoint.h:356
SpherePointEndpoint(SpherePointEndpoint const &)=default
SpherePointEndpoint & operator=(SpherePointEndpoint &&)=delete
Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
Definition: Endpoint.cc:201
void normalizeFrame(std::shared_ptr< ast::Frame > framePtr) const override
Check that framePtr points to a SkyFrame and set longitude axis to 0, latitude to 1.
Definition: Endpoint.cc:222
~SpherePointEndpoint() override=default
std::ostream & operator<<(std::ostream &os, GenericEndpoint const &endpoint)
Print "GenericEndpoint(_n_)" to the ostream where _n_ is the number of axes, e.g. "GenericAxes(4)".
Definition: Endpoint.cc:240
Point< double, 2 > Point2D
Definition: Point.h:324
A base class for image defects.