24 #include "pybind11/pybind11.h"
26 #include "pybind11/eigen.h"
31 #include "pybind11/stl.h"
32 #include "ndarray/pybind11.h"
39 using namespace py::literals;
48 template <
class Class>
52 os <<
"[" <<
self.getFromEndpoint().getNAxes() <<
"->" <<
self.getToEndpoint().getNAxes() <<
"]";
56 template <
class FromEndpo
int,
class ToEndpo
int,
class NextToEndpo
int,
class PyClass>
57 void declareMethodTemplates(
PyClass &cls) {
58 using ThisTransform = Transform<FromEndpoint, ToEndpoint>;
59 using NextTransform = Transform<ToEndpoint, NextToEndpoint>;
60 using SeriesTransform = Transform<FromEndpoint, NextToEndpoint>;
64 ThisTransform::template then<NextToEndpoint>,
65 "next"_a,
"simplify"_a =
true);
71 template <
class FromEndpo
int,
class ToEndpo
int>
73 using Class = Transform<FromEndpoint, ToEndpoint>;
74 using ToPoint =
typename ToEndpoint::Point;
75 using ToArray =
typename ToEndpoint::Array;
76 using FromPoint =
typename FromEndpoint::Point;
77 using FromArray =
typename FromEndpoint::Array;
79 std::string const pyClassName = Class::getShortClassName();
82 [](
auto &mod,
auto &cls) {
83 std::string const pyClassName = Class::getShortClassName();
84 cls.def(py::init<ast::FrameSet const &, bool>(),
"frameSet"_a,
"simplify"_a = true);
85 cls.def(py::init<ast::Mapping const &, bool>(),
"mapping"_a,
"simplify"_a = true);
87 cls.def_property_readonly(
"hasForward", &Class::hasForward);
88 cls.def_property_readonly(
"hasInverse", &Class::hasInverse);
89 cls.def_property_readonly(
"fromEndpoint", &Class::getFromEndpoint);
90 cls.def_property_readonly(
"toEndpoint", &Class::getToEndpoint);
94 cls.def(
"getMapping", [](Class const &self) { return self.getMapping()->copy(); });
96 cls.def(
"applyForward",
97 py::overload_cast<FromArray const &>(&Class::applyForward, py::const_),
"array"_a);
98 cls.def(
"applyForward",
99 py::overload_cast<FromPoint const &>(&Class::applyForward, py::const_),
"point"_a);
100 cls.def(
"applyInverse", py::overload_cast<ToArray const &>(&Class::applyInverse, py::const_),
102 cls.def(
"applyInverse", py::overload_cast<ToPoint const &>(&Class::applyInverse, py::const_),
104 cls.def(
"inverted", &Class::inverted);
111 cls.def_static(
"readString", &Class::readString);
112 cls.def(
"writeString", &Class::writeString);
114 declareMethodTemplates<FromEndpoint, ToEndpoint, GenericEndpoint>(cls);
115 declareMethodTemplates<FromEndpoint, ToEndpoint, Point2Endpoint>(cls);
116 declareMethodTemplates<FromEndpoint, ToEndpoint, SpherePointEndpoint>(cls);
119 cls.def(
"__str__", [pyClassName](Class
const &
self) {
return formatStr(
self, pyClassName); });
121 cls.def(
"__repr__", [pyClassName](Class
const &
self) {
122 return "lsst.afw.geom." + formatStr(
self, pyClassName);
125 table::io::python::addPersistableMethods<Class>(cls);
132 declareTransform<GenericEndpoint, GenericEndpoint>(wrappers);
133 declareTransform<GenericEndpoint, Point2Endpoint>(wrappers);
134 declareTransform<GenericEndpoint, SpherePointEndpoint>(wrappers);
135 declareTransform<Point2Endpoint, GenericEndpoint>(wrappers);
136 declareTransform<Point2Endpoint, Point2Endpoint>(wrappers);
137 declareTransform<Point2Endpoint, SpherePointEndpoint>(wrappers);
138 declareTransform<SpherePointEndpoint, GenericEndpoint>(wrappers);
139 declareTransform<SpherePointEndpoint, Point2Endpoint>(wrappers);
140 declareTransform<SpherePointEndpoint, SpherePointEndpoint>(wrappers);
A helper class for subdividing pybind11 module across multiple translation units (i....
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
void addSignatureDependency(std::string const &name)
Indicate an external module that provides a type used in function/method signatures.
void wrapTransform(lsst::utils::python::WrapperCollection &)
py::class_< PixelAreaBoundedField, std::shared_ptr< PixelAreaBoundedField >, BoundedField > PyClass
A base class for image defects.