lsst.astshim  master-g52c76259df
PcdMap.h
1 /*
2  * LSST Data Management System
3  * Copyright 2017 AURA/LSST.
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 <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 #ifndef ASTSHIM_PCDMAP_H
23 #define ASTSHIM_PCDMAP_H
24 
25 #include <memory>
26 #include <sstream>
27 #include <stdexcept>
28 #include <vector>
29 
30 #include "astshim/base.h"
31 #include "astshim/detail/utils.h"
32 #include "astshim/Mapping.h"
33 
34 namespace ast {
35 
73 class PcdMap : public Mapping {
74  friend class Object;
75 
76 public:
87  PcdMap(double disco, std::vector<double> const &pcdcen, std::string const &options = "")
88  : Mapping(reinterpret_cast<AstMapping *>(_makeRawPcdMap(disco, pcdcen, options))) {}
89 
90  virtual ~PcdMap() {}
91 
92  PcdMap(PcdMap const &) = delete;
93  PcdMap(PcdMap &&) = default;
94  PcdMap &operator=(PcdMap const &) = delete;
95  PcdMap &operator=(PcdMap &&) = default;
96 
98  std::shared_ptr<PcdMap> copy() const { return std::static_pointer_cast<PcdMap>(copyPolymorphic()); }
99 
101  double getDisco() const { return getD("Disco"); };
102 
104  double getPcdCen(int axis) const { return getD(detail::formatAxisAttr("PcdCen", axis)); }
105 
107  std::vector<double> getPcdCen() const {
108  std::vector<double> ctr;
109  for (auto axis = 1; axis < 3; ++axis) {
110  ctr.push_back(getPcdCen(axis));
111  }
112  return ctr;
113  }
114 
115 protected:
116  virtual std::shared_ptr<Object> copyPolymorphic() const override {
117  return copyImpl<PcdMap, AstPcdMap>();
118  }
119 
121  explicit PcdMap(AstPcdMap *rawptr) : Mapping(reinterpret_cast<AstMapping *>(rawptr)) {
122  if (!astIsAPcdMap(getRawPtr())) {
123  std::ostringstream os;
124  os << "this is a " << getClassName() << ", which is not a PcdMap";
125  throw std::invalid_argument(os.str());
126  }
127  }
128 
129 private:
130  AstPcdMap *_makeRawPcdMap(double disco, std::vector<double> const &pcdcen,
131  std::string const &options = "") {
132  if (pcdcen.size() != 2) {
133  std::ostringstream os;
134  os << "pcdcen.size() = " << pcdcen.size() << "; must be 2";
135  throw std::invalid_argument(os.str());
136  }
137  return astPcdMap(disco, pcdcen.data(), "%s", options.c_str());
138  }
139 };
140 
141 } // namespace ast
142 
143 #endif
std::shared_ptr< PcdMap > copy() const
Return a deep copy of this object.
Definition: PcdMap.h:98
AstObject const * getRawPtr() const
Definition: Object.h:286
std::vector< double > getPcdCen() const
Get PcdMap_PcdCen PcdCen for both axes: centre coordinates of pincushion/barrel distortion.
Definition: PcdMap.h:107
AST wrapper classes and functions.
Definition: attributes_channel.dox:1
std::string getClassName() const
Definition: Object.h:133
Definition: Mapping.h:59
virtual std::shared_ptr< Object > copyPolymorphic() const override
Definition: PcdMap.h:116
PcdMap(double disco, std::vector< double > const &pcdcen, std::string const &options="")
Definition: PcdMap.h:87
Definition: PcdMap.h:73
double getPcdCen(int axis) const
Get PcdMap_PcdCen PcdCen(axis) for one axis: centre coordinates of pincushion/barrel distortion...
Definition: PcdMap.h:104
double getD(std::string const &attrib) const
Definition: Object.h:373
double getDisco() const
Get Disco: pincushion/barrel distortion coefficient.
Definition: PcdMap.h:101
Definition: Object.h:49
PcdMap(AstPcdMap *rawptr)
Construct a PcdMap from a raw AST pointer.
Definition: PcdMap.h:121