30#include "pybind11/pybind11.h"
32#include "pybind11/stl.h"
33#include "ndarray/pybind11.h"
40using namespace py::literals;
54template <
typename PyClass>
55void addStrAndRepr(PyClass &cls) {
56 using Class =
typename PyClass::type;
57 utils::python::addOutputOp(cls,
"__str__");
58 cls.def(
"__repr__", [](Class
const &self) {
60 os <<
"lsst.afw.geom." << self;
63 cls.def_static(
"getClassPrefix", &Class::getClassPrefix);
69template <
typename PyClass>
70void addDataConverters(PyClass &cls) {
71 using Class =
typename PyClass::type;
72 cls.def(
"getNPoints", &Class::getNPoints);
73 cls.def(
"dataFromPoint", &Class::dataFromPoint);
74 cls.def(
"dataFromArray", &Class::dataFromArray);
75 cls.def(
"arrayFromData", &Class::arrayFromData);
76 cls.def(
"pointFromData", &Class::pointFromData);
82template <
typename PyClass>
83void addMakeFrame(PyClass &cls) {
84 using Class =
typename PyClass::type;
86 cls.def(
"makeFrame", [](Class
const &self) {
87 auto frame = self.makeFrame();
93template <
typename SelfClass,
typename OtherClass,
typename PyClass>
94std::enable_if_t<std::is_base_of<SelfClass, OtherClass>::value> addEquals(PyClass &cls) {
95 cls.def(
"__eq__", &SelfClass::operator==);
96 cls.def(
"__ne__", &SelfClass::operator!=);
99template <
typename SelfClass,
typename OtherClass,
typename PyClass>
100std::enable_if_t<!std::is_base_of<SelfClass, OtherClass>::value> addEquals(PyClass &cls) {
101 cls.def(
"__eq__", [](SelfClass
const &self, OtherClass
const &other) {
return false; });
102 cls.def(
"__ne__", [](SelfClass
const &self, OtherClass
const &other) {
return true; });
105template <
typename SelfClass,
typename PyClass>
106void addAllEquals(PyClass &cls) {
107 addEquals<SelfClass, GenericEndpoint>(cls);
108 addEquals<SelfClass, Point2Endpoint>(cls);
109 addEquals<SelfClass, SpherePointEndpoint>(cls);
116template <
typename Po
int,
typename Array>
117void declareBaseEndpoint(lsst::utils::python::WrapperCollection &wrappers,
std::string const &suffix) {
118 using Class = BaseEndpoint<Point, Array>;
119 std::string const pyClassName =
"_BaseEndpoint" + suffix;
121 [](
auto &mod,
auto &cls) {
122 cls.def_property_readonly(
"nAxes", &Class::getNAxes);
123 addDataConverters(cls);
125 cls.def(
"normalizeFrame", &Class::normalizeFrame);
126 addAllEquals<Class>(cls);
132template <
typename Po
int>
133void declareBaseVectorEndpoint(lsst::utils::python::WrapperCollection &wrappers,
std::string const &suffix) {
134 using Class = BaseVectorEndpoint<Point>;
135 using Array =
typename Class::Array;
137 std::string const pyClassName =
"_BaseVectorEndpoint" + suffix;
139 declareBaseEndpoint<Point, Array>(wrappers, suffix);
141 wrappers.module, pyClassName.
c_str()),
142 [](
auto &mod,
auto &cls) { addDataConverters(cls); });
146void declareGenericEndpoint(lsst::utils::python::WrapperCollection &wrappers) {
147 using Class = GenericEndpoint;
148 using Point =
typename Class::Point;
149 using Array =
typename Class::Array;
151 declareBaseEndpoint<Point, Array>(wrappers,
"Generic");
154 wrappers.module,
"GenericEndpoint"),
155 [](
auto &mod,
auto &cls) {
156 cls.def(py::init<int>(),
"nAxes"_a);
163void declarePoint2Endpoint(lsst::utils::python::WrapperCollection &wrappers) {
164 using Class = Point2Endpoint;
165 using Point =
typename Class::Point;
167 std::string const pyClassName = pointNumStr +
"Endpoint";
169 declareBaseVectorEndpoint<Point>(wrappers, pointNumStr);
172 wrappers.module, pyClassName.
c_str()),
173 [](
auto &mod,
auto &cls) {
174 cls.def(py::init<>());
177 cls.def(
"normalizeFrame", &Class::normalizeFrame);
183void declareSpherePointEndpoint(lsst::utils::python::WrapperCollection &wrappers) {
184 using Class = SpherePointEndpoint;
185 using Point =
typename Class::Point;
187 declareBaseVectorEndpoint<Point>(wrappers,
"SpherePoint");
190 wrappers.module,
"SpherePointEndpoint"),
191 [](
auto &mod,
auto &cls) {
192 cls.def(py::init<>());
196 cls.def(
"normalizeFrame", &Class::normalizeFrame);
202 wrappers.addSignatureDependency(
"lsst.geom");
203 declareGenericEndpoint(wrappers);
204 declarePoint2Endpoint(wrappers);
205 declareSpherePointEndpoint(wrappers);
void wrapEndpoint(lsst::utils::python::WrapperCollection &wrappers)