23 #include "pybind11/pybind11.h" 24 #include "pybind11/stl.h" 26 #include "numpy/arrayobject.h" 27 #include "ndarray/pybind11.h" 29 #include "lsst/utils/python.h" 35 namespace py = pybind11;
43 using PyLinearTransform = py::class_<LinearTransform, std::shared_ptr<LinearTransform>>;
46 py::module mod(
"linearTransform");
48 py::module::import(
"lsst.afw.geom.coordinates");
50 if (_import_array() < 0) {
51 PyErr_SetString(PyExc_ImportError,
"numpy.core.multiarray failed to import");
55 PyLinearTransform
cls(mod,
"LinearTransform");
58 cls.attr(
"XX") = py::cast(
int(LinearTransform::Parameters::XX));
59 cls.attr(
"YX") = py::cast(
int(LinearTransform::Parameters::YX));
60 cls.attr(
"XY") = py::cast(
int(LinearTransform::Parameters::XY));
61 cls.attr(
"YY") = py::cast(
int(LinearTransform::Parameters::YY));
64 cls.def(py::init<>());
65 cls.def(py::init<LinearTransform::Matrix const &>(),
"matrix"_a);
68 cls.def(
"__call__", (
Point2D (LinearTransform::*)(
Point2D const &)
const) & LinearTransform::operator());
70 (
Extent2D (LinearTransform::*)(
Extent2D const &)
const) & LinearTransform::operator());
71 cls.def(
"__getitem__",
72 [](LinearTransform
const &
self,
int i) {
return self[lsst::utils::python::cppIndex(4, i)]; });
73 cls.def(
"__getitem__", [](LinearTransform
const &
self, std::pair<int, int> i) {
74 auto row = lsst::utils::python::cppIndex(2, i.first);
75 auto col = lsst::utils::python::cppIndex(2, i.second);
76 return self.getMatrix()(row, col);
78 cls.def(
"__mul__", &LinearTransform::operator*, py::is_operator());
79 cls.def(
"__add__", &LinearTransform::operator+, py::is_operator());
80 cls.def(
"__sub__", &LinearTransform::operator-, py::is_operator());
81 cls.def(
"__iadd__", &LinearTransform::operator+=);
82 cls.def(
"__isub__", &LinearTransform::operator-=);
85 cls.def_static(
"makeScaling", (LinearTransform(*)(
double))LinearTransform::makeScaling,
"scale"_a);
86 cls.def_static(
"makeScaling", (LinearTransform(*)(
double,
double))LinearTransform::makeScaling);
87 cls.def_static(
"makeRotation", (LinearTransform(*)(
Angle t))LinearTransform::makeRotation,
"angle"_a);
88 cls.def(
"getParameterVector", &LinearTransform::getParameterVector);
90 (LinearTransform::Matrix
const &(LinearTransform::*)()
const) & LinearTransform::getMatrix);
91 cls.def(
"invert", &LinearTransform::invert);
92 cls.def(
"computeDeterminant", &LinearTransform::computeDeterminant);
93 cls.def(
"isIdentity", &LinearTransform::isIdentity);
96 [](LinearTransform &
self,
double xx,
double yx,
double xy,
double yy) {
97 self[LinearTransform::XX] = xx;
98 self[LinearTransform::XY] = xy;
99 self[LinearTransform::YX] = yx;
100 self[LinearTransform::YY] = yy;
102 "xx"_a,
"yx"_a,
"xy"_a,
"yy"_a);
104 cls.def(
"__str__", [](LinearTransform
const &
self) {
return py::str(py::cast(
self.getMatrix())); });
105 cls.def(
"__repr__", [](LinearTransform
const &
self) {
106 return py::str(
"LinearTransform(\n{}\n)").format(py::cast(
self.getMatrix()));
108 cls.def(
"__reduce__", [
cls](LinearTransform
const &
self) {
109 return py::make_tuple(
cls, py::make_tuple(py::cast(
self.getMatrix())));
lsst::afw::geom::Angle Angle
Extent< double, 2 > Extent2D
PYBIND11_PLUGIN(_cameraPoint)
A base class for image defects.
Point< double, 2 > Point2D