23 #include "pybind11/pybind11.h" 24 #include "pybind11/stl.h" 26 #include "numpy/arrayobject.h" 27 #include "ndarray/pybind11.h" 31 namespace py = pybind11;
39 using PyAffineTransform = py::class_<AffineTransform, std::shared_ptr<AffineTransform>>;
42 py::module mod(
"affineTransform");
44 py::module::import(
"lsst.afw.geom.linearTransform");
45 py::module::import(
"lsst.afw.geom.coordinates");
48 if (_import_array() < 0) {
49 PyErr_SetString(PyExc_ImportError,
"numpy.core.multiarray failed to import");
53 PyAffineTransform
cls(mod,
"AffineTransform");
56 cls.attr(
"XX") = py::cast(
int(AffineTransform::Parameters::XX));
57 cls.attr(
"YX") = py::cast(
int(AffineTransform::Parameters::YX));
58 cls.attr(
"XY") = py::cast(
int(AffineTransform::Parameters::XY));
59 cls.attr(
"YY") = py::cast(
int(AffineTransform::Parameters::YY));
64 cls.def(py::init<>());
65 cls.def(py::init<Eigen::Matrix3d const &>(),
"matrix"_a);
66 cls.def(py::init<Eigen::Matrix2d const &>(),
"linear"_a);
67 cls.def(py::init<Eigen::Vector2d const &>(),
"translation"_a);
68 cls.def(py::init<Eigen::Matrix2d const &, Eigen::Vector2d const &>(),
"linear"_a,
"translation"_a);
69 cls.def(py::init<LinearTransform const &>(),
"linear"_a);
70 cls.def(py::init<Extent2D const &>(),
"translation"_a);
71 cls.def(py::init<LinearTransform const &, Extent2D const &>(),
"linear"_a,
"translation"_a);
74 cls.def(
"__mul__", &AffineTransform::operator*, py::is_operator());
75 cls.def(
"__call__", (
Point2D (AffineTransform::*)(
Point2D const &)
const) & AffineTransform::operator());
77 (
Extent2D (AffineTransform::*)(
Extent2D const &)
const) & AffineTransform::operator());
78 cls.def(
"__setitem__", [](AffineTransform &
self,
int i,
double value) {
80 PyErr_Format(PyExc_IndexError,
"Invalid index for AffineTransform: %d", i);
81 throw py::error_already_set();
85 cls.def(
"__getitem__", [](AffineTransform
const &
self,
int row,
int col) {
86 if (row < 0 || row > 2 || col < 0 || col > 2) {
87 PyErr_Format(PyExc_IndexError,
"Invalid index for AffineTransform: %d, %d", row, col);
88 throw py::error_already_set();
90 return (
self.getMatrix())(row, col);
92 cls.def(
"__getitem__", [](AffineTransform
const &
self,
int i) {
94 PyErr_Format(PyExc_IndexError,
"Invalid index for AffineTransform: %d", i);
95 throw py::error_already_set();
99 cls.def(
"__str__", [](AffineTransform
const &
self) {
return py::str(py::cast(
self.getMatrix())); });
100 cls.def(
"__repr__", [](AffineTransform
const &
self) {
101 return py::str(
"AffineTransform(\n{}\n)").format(py::cast(
self.getMatrix()));
103 cls.def(
"__reduce__", [
cls](AffineTransform
const &
self) {
104 return py::make_tuple(
cls, py::make_tuple(py::cast(
self.getMatrix())));
108 cls.def(
"invert", &AffineTransform::invert);
109 cls.def(
"isIdentity", &AffineTransform::isIdentity);
110 cls.def(
"getTranslation", (
Extent2D & (AffineTransform::*)()) & AffineTransform::getTranslation);
111 cls.def(
"getLinear", (LinearTransform & (AffineTransform::*)()) & AffineTransform::getLinear);
112 cls.def(
"getMatrix", &AffineTransform::getMatrix);
113 cls.def(
"getParameterVector", &AffineTransform::getParameterVector);
114 cls.def(
"setParameterVector", &AffineTransform::setParameterVector);
115 cls.def_static(
"makeScaling", (AffineTransform(*)(
double)) & AffineTransform::makeScaling);
116 cls.def_static(
"makeScaling", (AffineTransform(*)(
double,
double)) & AffineTransform::makeScaling);
117 cls.def_static(
"makeRotation", &AffineTransform::makeRotation,
"angle"_a);
118 cls.def_static(
"makeTranslation", &AffineTransform::makeTranslation,
"translation"_a);
Extent< double, 2 > Extent2D
PYBIND11_PLUGIN(_cameraPoint)
A base class for image defects.
Point< double, 2 > Point2D
AffineTransform makeAffineTransformFromTriple(Point2D const &p1, Point2D const &p2, Point2D const &p3, Point2D const &q1, Point2D const &q2, Point2D const &q3)