lsst.afw  13.0-49-g6f23dda
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/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(){};
78 
79  int getNAxes() const { return _nAxes; }
80 
84  virtual int getNPoints(Array const &arr) const = 0;
85 
94  virtual std::vector<double> dataFromPoint(Point const &point) const = 0;
95 
105  virtual ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const = 0;
106 
113  virtual Point pointFromData(std::vector<double> const &data) const = 0;
114 
124  virtual Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const = 0;
125 
129  virtual std::shared_ptr<ast::Frame> makeFrame() const;
130 
138  virtual void normalizeFrame(std::shared_ptr<ast::Frame> framePtr) const {};
139 
140 protected:
148  explicit BaseEndpoint(int nAxes);
149 
150  void _assertNAxes(int nAxes) const;
151 
152  int _getNAxes(ndarray::Array<double, 2, 2> const &data) const { return data.getSize<0>(); }
153 
154  int _getNAxes(ndarray::Array<double, 1, 1> const &data) const { return data.getSize<0>(); }
155 
156  int _getNAxes(std::vector<double> const &data) const { return data.size(); }
157 
158  int _getNPoints(ndarray::Array<double, 2, 2> const &data) const { return data.getSize<1>(); }
159 
160 private:
161  int _nAxes;
162 };
163 
169 template <typename PointT>
170 class BaseVectorEndpoint : public BaseEndpoint<PointT, std::vector<PointT>> {
171 public:
172  using Array = std::vector<PointT>;
173  using Point = PointT;
174 
175  BaseVectorEndpoint(BaseVectorEndpoint const &) = default;
179 
180  virtual ~BaseVectorEndpoint(){};
181 
182  virtual int getNPoints(Array const &arr) const override { return arr.size(); }
183 
184  virtual std::vector<double> dataFromPoint(Point const &point) const override;
185 
186  virtual ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const override;
187 
188  virtual Point pointFromData(std::vector<double> const &data) const override;
189 
190 protected:
198  explicit BaseVectorEndpoint(int nAxes) : BaseEndpoint<Point, Array>(nAxes){};
199 };
200 
207 class GenericEndpoint : public BaseEndpoint<std::vector<double>, ndarray::Array<double, 2, 2>> {
208 public:
209  GenericEndpoint(GenericEndpoint const &) = default;
210  GenericEndpoint(GenericEndpoint &&) = default;
211  GenericEndpoint &operator=(GenericEndpoint const &) = delete;
213 
221  explicit GenericEndpoint(int nAxes) : BaseEndpoint(nAxes){};
222 
223  virtual ~GenericEndpoint(){};
224 
225  virtual int getNPoints(Array const &arr) const override { return arr.getSize<1>(); }
226 
227  virtual std::vector<double> dataFromPoint(Point const &point) const override;
228 
229  virtual ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const override;
230 
231  virtual Point pointFromData(std::vector<double> const &data) const override;
232 
233  virtual Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const override;
234 };
235 
239 class Point2Endpoint : public BaseVectorEndpoint<Point2D> {
240 public:
241  Point2Endpoint(Point2Endpoint const &) = default;
242  Point2Endpoint(Point2Endpoint &&) = default;
243  Point2Endpoint &operator=(Point2Endpoint const &) = delete;
245 
250 
261  explicit Point2Endpoint(int nAxes);
262 
263  virtual ~Point2Endpoint(){};
264 
265  virtual Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const override;
266 
276  virtual void normalizeFrame(std::shared_ptr<ast::Frame> framePtr) const override;
277 };
278 
284 class SpherePointEndpoint : public BaseVectorEndpoint<SpherePoint> {
285 public:
286  SpherePointEndpoint(SpherePointEndpoint const &) = default;
290 
295 
306  explicit SpherePointEndpoint(int nAxes);
307 
308  virtual ~SpherePointEndpoint(){};
309 
310  virtual Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const override;
311 
315  virtual std::shared_ptr<ast::Frame> makeFrame() const override;
316 
320  virtual void normalizeFrame(std::shared_ptr<ast::Frame> framePtr) const override;
321 };
322 
326 std::ostream &operator<<(std::ostream &os, GenericEndpoint const &endpoint);
327 
329 std::ostream &operator<<(std::ostream &os, Point2Endpoint const &endpoint);
330 
332 std::ostream &operator<<(std::ostream &os, SpherePointEndpoint const &endpoint);
333 
334 } // geom
335 } // afw
336 } // lsst
337 
338 #endif
virtual Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:60
virtual void normalizeFrame(std::shared_ptr< ast::Frame > framePtr) const override
Check that framePtr points to a Frame, not a subclass.
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
BaseVectorEndpoint(BaseVectorEndpoint const &)=default
Point2Endpoint()
Construct a Point2Endpoint.
Definition: Endpoint.h:249
virtual ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const override
Get raw data from an array of points.
Base class for endpoints with Array = std::vector&lt;Point&gt; where Point has 2 dimensions.
Definition: Endpoint.h:170
virtual Point pointFromData(std::vector< double > const &data) const =0
Get a single point from raw data.
std::vector< PointT > Array
Definition: Endpoint.h:172
virtual void normalizeFrame(std::shared_ptr< ast::Frame > framePtr) const
Adjust and check the frame as needed.
Definition: Endpoint.h:138
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 override
Get raw data from a single point.
virtual Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
int _getNAxes(ndarray::Array< double, 2, 2 > const &data) const
Definition: Endpoint.h:152
SpherePointEndpoint & operator=(SpherePointEndpoint const &)=delete
A coordinate class intended to represent absolute positions.
BaseVectorEndpoint(int nAxes)
Construct a BaseVectorEndpoint.
Definition: Endpoint.h:198
virtual int getNPoints(Array const &arr) const =0
Return the number of points in an array.
virtual std::shared_ptr< ast::Frame > makeFrame() const
Create a Frame that can be used with this end point in a Transform.
virtual std::vector< double > dataFromPoint(Point const &point) const =0
Get raw data from a single point.
GenericEndpoint(GenericEndpoint const &)=default
A generic endpoint for data in the format used by ast::Mapping.
Definition: Endpoint.h:207
virtual std::vector< double > dataFromPoint(Point const &point) const override
Get raw data from a single point.
An endpoint for SpherePoint.
Definition: Endpoint.h:284
virtual ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const =0
Get raw data from an array of points.
virtual ndarray::Array< double, 2, 2 > dataFromArray(Array const &arr) const override
Get raw data from an array of points.
SpherePointEndpoint()
Construct a SpherePointEndpoint.
Definition: Endpoint.h:294
virtual int getNPoints(Array const &arr) const override
Return the number of points in an array.
Definition: Endpoint.h:225
virtual Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
virtual Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
GenericEndpoint & operator=(GenericEndpoint const &)=delete
Point2Endpoint & operator=(Point2Endpoint const &)=delete
virtual int getNPoints(Array const &arr) const override
Return the number of points in an array.
Definition: Endpoint.h:182
int _getNAxes(ndarray::Array< double, 1, 1 > const &data) const
Definition: Endpoint.h:154
An endpoint for Point2D.
Definition: Endpoint.h:239
int _getNAxes(std::vector< double > const &data) const
Definition: Endpoint.h:156
virtual Point pointFromData(std::vector< double > const &data) const override
Get a single point from raw data.
int _getNPoints(ndarray::Array< double, 2, 2 > const &data) const
Definition: Endpoint.h:158
virtual std::shared_ptr< ast::Frame > makeFrame() const override
Create a Frame that can be used with this end point in a Transform.
void _assertNAxes(int nAxes) const
BaseEndpoint(BaseEndpoint const &)=default
BaseVectorEndpoint & operator=(BaseVectorEndpoint const &)=delete
GenericEndpoint(int nAxes)
Construct a GenericEndpoint with the specified number of axes.
Definition: Endpoint.h:221
Virtual base class for endpoints, which are helper classes for Transform.
Definition: Endpoint.h:67
BaseEndpoint & operator=(BaseEndpoint const &)=delete
virtual 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...