lsst.afw  13.0-39-g3deb52d
 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 
68 template <typename PointT, typename ArrayT>
69 class BaseEndpoint {
70 public:
71  using Point = PointT;
72  using Array = ArrayT;
73 
74  BaseEndpoint(BaseEndpoint const &) = default;
75  BaseEndpoint(BaseEndpoint &&) = default;
76  BaseEndpoint &operator=(BaseEndpoint const &) = default;
77  BaseEndpoint &operator=(BaseEndpoint &&) = default;
78 
79  virtual ~BaseEndpoint(){};
80 
81  int getNAxes() const { return _nAxes; }
82 
86  virtual int getNPoints(Array const &arr) const = 0;
87 
96  virtual std::vector<double> dataFromPoint(Point const &point) const = 0;
97 
107  virtual ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const = 0;
108 
115  virtual Point pointFromData(std::vector<double> const &data) const = 0;
116 
126  virtual Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const = 0;
127 
131  virtual std::shared_ptr<ast::Frame> makeFrame() const;
132 
140  virtual void normalizeFrame(std::shared_ptr<ast::Frame> framePtr) const {};
141 
142 protected:
148  explicit BaseEndpoint(int nAxes) : _nAxes(nAxes) {}
149 
150  void _assertNAxes(int nAxes) const;
151 
152  int _getNAxes(ndarray::Array<double, 2, 2> const &data) const { return data.getSize<1>(); }
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<0>(); }
159 
160 private:
161  int _nAxes;
162 };
163 
167 template <typename PointT>
168 class BaseVectorEndpoint : public BaseEndpoint<PointT, std::vector<PointT>> {
169 public:
170  using Array = std::vector<PointT>;
171  using Point = PointT;
172 
173  BaseVectorEndpoint(BaseVectorEndpoint const &) = default;
175  BaseVectorEndpoint &operator=(BaseVectorEndpoint const &) = default;
177 
178  virtual ~BaseVectorEndpoint(){};
179 
180  virtual int getNPoints(Array const &arr) const override { return arr.size(); }
181 
182  virtual std::vector<double> dataFromPoint(Point const &point) const override;
183 
184  virtual ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const override;
185 
186  virtual Point pointFromData(std::vector<double> const &data) const override;
187 
188  virtual Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const override;
189 
190 protected:
196  explicit BaseVectorEndpoint(int nAxes) : BaseEndpoint<Point, Array>(nAxes){};
197 };
198 
205 class GenericEndpoint : public BaseEndpoint<std::vector<double>, ndarray::Array<double, 2, 2>> {
206 public:
207  GenericEndpoint(GenericEndpoint const &) = default;
208  GenericEndpoint(GenericEndpoint &&) = default;
209  GenericEndpoint &operator=(GenericEndpoint const &) = default;
211 
213  explicit GenericEndpoint(int nAxes) : BaseEndpoint(nAxes){};
214 
215  virtual ~GenericEndpoint(){};
216 
217  virtual int getNPoints(Array const &arr) const override { return arr.getSize<0>(); }
218 
219  virtual std::vector<double> dataFromPoint(Point const &point) const override;
220 
221  virtual ndarray::Array<double, 2, 2> dataFromArray(Array const &arr) const override;
222 
223  virtual Point pointFromData(std::vector<double> const &data) const override;
224 
225  virtual Array arrayFromData(ndarray::Array<double, 2, 2> const &data) const override;
226 };
227 
233 template <int N>
234 class PointEndpoint : public BaseVectorEndpoint<Point<double, N>> {
235 public:
236  PointEndpoint(PointEndpoint const &) = default;
237  PointEndpoint(PointEndpoint &&) = default;
238  PointEndpoint &operator=(PointEndpoint const &) = default;
239  PointEndpoint &operator=(PointEndpoint &&) = default;
240 
242  explicit PointEndpoint() : BaseVectorEndpoint<Point<double, N>>(N) {}
243 
245  explicit PointEndpoint(int nAxes);
246 
247  virtual ~PointEndpoint(){};
248 
258  virtual void normalizeFrame(std::shared_ptr<ast::Frame> framePtr) const override;
259 };
260 
261 // Aliases for the only allowed <N> of PointEndpoint
264 
272 class SpherePointEndpoint : public BaseVectorEndpoint<SpherePoint> {
273 public:
274  SpherePointEndpoint(SpherePointEndpoint const &) = default;
278 
281 
283  explicit SpherePointEndpoint(int nAxes);
284 
285  virtual ~SpherePointEndpoint(){};
286 
290  virtual std::shared_ptr<ast::Frame> makeFrame() const override;
291 
295  virtual void normalizeFrame(std::shared_ptr<ast::Frame> framePtr) const override;
296 };
297 
301 std::ostream &operator<<(std::ostream &os, GenericEndpoint const &endpoint);
302 
304 std::ostream &operator<<(std::ostream &os, Point2Endpoint const &endpoint);
305 
307 std::ostream &operator<<(std::ostream &os, Point3Endpoint const &endpoint);
308 
310 std::ostream &operator<<(std::ostream &os, SpherePointEndpoint const &endpoint);
311 
312 } // geom
313 } // afw
314 } // lsst
315 
316 #endif
PointEndpoint & operator=(PointEndpoint const &)=default
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:60
BaseEndpoint & operator=(BaseEndpoint const &)=default
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
An endpoint for Point&lt;double, N&gt;
Definition: Endpoint.h:234
BaseVectorEndpoint(BaseVectorEndpoint const &)=default
SpherePointEndpoint & operator=(SpherePointEndpoint const &)=default
virtual Array arrayFromData(ndarray::Array< double, 2, 2 > const &data) const override
Get an array of points from raw data.
BaseVectorEndpoint & operator=(BaseVectorEndpoint const &)=default
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;
Definition: Endpoint.h:168
virtual Point pointFromData(std::vector< double > const &data) const =0
Get a single point from raw data.
std::vector< PointT > Array
Definition: Endpoint.h:170
virtual void normalizeFrame(std::shared_ptr< ast::Frame > framePtr) const
Adjust and check the frame as needed.
Definition: Endpoint.h:140
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.
int _getNAxes(ndarray::Array< double, 2, 2 > const &data) const
Definition: Endpoint.h:152
A coordinate class intended to represent absolute positions.
BaseVectorEndpoint(int nAxes)
Construct a BaseVectorEndpoint.
Definition: Endpoint.h:196
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.
PointEndpoint< 3 > Point3Endpoint
Definition: Endpoint.h:263
GenericEndpoint(GenericEndpoint const &)=default
A generic endpoint for data in the format used by ast::Mapping.
Definition: Endpoint.h:205
virtual std::vector< double > dataFromPoint(Point const &point) const override
Get raw data from a single point.
An endpoint for SpherePoint.
Definition: Endpoint.h:272
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:280
PointEndpoint< 2 > Point2Endpoint
Definition: Endpoint.h:262
virtual int getNPoints(Array const &arr) const override
Return the number of points in an array.
Definition: Endpoint.h:217
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.
virtual int getNPoints(Array const &arr) const override
Return the number of points in an array.
Definition: Endpoint.h:180
int _getNAxes(ndarray::Array< double, 1, 1 > const &data) const
Definition: Endpoint.h:154
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
PointEndpoint()
Construct a PointEndpoint; template parameter N specifies the number of axes.
Definition: Endpoint.h:242
BaseEndpoint(int nAxes)
Construct a BaseEndpoint.
Definition: Endpoint.h:148
virtual void normalizeFrame(std::shared_ptr< ast::Frame > framePtr) const override
Check that framePtr points to a Frame, not a subclass.
BaseEndpoint(BaseEndpoint const &)=default
GenericEndpoint(int nAxes)
Construct a GenericEndpoint with the specified number of axes.
Definition: Endpoint.h:213
Virtual base class for endpoints, which are helper classes for Transform.
Definition: Endpoint.h:69
GenericEndpoint & operator=(GenericEndpoint const &)=default
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...