LSSTApplications  16.0-1-gce273f5+15,16.0-1-gf77f410+8,16.0-10-g230e10e+8,16.0-10-g5a5abec+4,16.0-10-gc1446dd+8,16.0-11-g5cf5345,16.0-12-g1dc09ba+2,16.0-12-g726f8f3+6,16.0-13-g4c33ca5+8,16.0-13-g5f6c0b1+8,16.0-13-gd9b1b71+8,16.0-14-g71e547a+4,16.0-17-g0bdc215,16.0-17-g6a7bfb3b+8,16.0-18-g95848a16+2,16.0-2-g0febb12+12,16.0-2-g839ba83+46,16.0-2-g9d5294e+35,16.0-3-g404ea43+7,16.0-3-gbc759ec+6,16.0-3-gcfd6c53+33,16.0-4-g03cf288+24,16.0-4-g13a27c5+10,16.0-4-g2cc461c+3,16.0-4-g5f3a788+11,16.0-4-g8a0f11a+30,16.0-4-ga3eb747+1,16.0-43-gaa65a4573+4,16.0-5-g1991253+8,16.0-5-g865efd9+8,16.0-5-gb3f8a4b+40,16.0-5-gd0f1235+4,16.0-6-g316b399+8,16.0-6-gf0acd13+27,16.0-6-gf9cb114+9,16.0-7-ga8e1655+4,16.0-8-g23bbf3f+1,16.0-8-g4dec96c+21,16.0-8-gfd407c0,w.2018.39
LSSTDataManagementBasePackage
affineTransform.cc
Go to the documentation of this file.
1 /*
2  * Developed for the LSST Data Management System.
3  * This product includes software developed by the LSST Project
4  * (https://www.lsst.org).
5  * See the COPYRIGHT file at the top-level directory of this distribution
6  * for details of code ownership.
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 GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #include "pybind11/pybind11.h"
23 #include "pybind11/eigen.h"
24 #include "pybind11/stl.h"
25 
26 #include "ndarray/pybind11.h"
27 
29 
30 namespace py = pybind11;
31 using namespace pybind11::literals;
32 
33 namespace lsst {
34 namespace geom {
35 namespace {
36 
37 using PyAffineTransform = py::class_<AffineTransform, std::shared_ptr<AffineTransform>>;
38 
40  py::module::import("lsst.geom.linearTransform");
41  py::module::import("lsst.geom.coordinates");
42 
43  PyAffineTransform cls(mod, "AffineTransform");
44 
45  // Parameters enum is really only used as integer constants.
46  cls.attr("XX") = py::cast(int(AffineTransform::Parameters::XX));
47  cls.attr("YX") = py::cast(int(AffineTransform::Parameters::YX));
48  cls.attr("XY") = py::cast(int(AffineTransform::Parameters::XY));
49  cls.attr("YY") = py::cast(int(AffineTransform::Parameters::YY));
50  cls.attr("X") = py::cast(int(AffineTransform::Parameters::X));
51  cls.attr("Y") = py::cast(int(AffineTransform::Parameters::Y));
52 
53  /* Constructors */
54  cls.def(py::init<>());
55  cls.def(py::init<Eigen::Matrix3d const &>(), "matrix"_a);
56  cls.def(py::init<Eigen::Matrix2d const &>(), "linear"_a);
57  cls.def(py::init<Eigen::Vector2d const &>(), "translation"_a);
58  cls.def(py::init<Eigen::Matrix2d const &, Eigen::Vector2d const &>(), "linear"_a, "translation"_a);
59  cls.def(py::init<LinearTransform const &>(), "linear"_a);
60  cls.def(py::init<Extent2D const &>(), "translation"_a);
61  cls.def(py::init<LinearTransform const &, Extent2D const &>(), "linear"_a, "translation"_a);
62 
63  /* Operators and special methods */
64  cls.def("__mul__", &AffineTransform::operator*, py::is_operator());
65  cls.def("__call__", (Point2D(AffineTransform::*)(Point2D const &) const) & AffineTransform::operator());
66  cls.def("__call__", (Extent2D(AffineTransform::*)(Extent2D const &) const) & AffineTransform::operator());
67  cls.def("__setitem__", [](AffineTransform &self, int i, double value) {
68  if (i < 0 || i > 5) {
69  PyErr_Format(PyExc_IndexError, "Invalid index for AffineTransform: %d", i);
70  throw py::error_already_set();
71  }
72  self[i] = value;
73  });
74  cls.def("__getitem__", [](AffineTransform const &self, int row, int col) {
75  if (row < 0 || row > 2 || col < 0 || col > 2) {
76  PyErr_Format(PyExc_IndexError, "Invalid index for AffineTransform: %d, %d", row, col);
77  throw py::error_already_set();
78  }
79  return (self.getMatrix())(row, col);
80  });
81  cls.def("__getitem__", [](AffineTransform const &self, int i) {
82  if (i < 0 || i > 5) {
83  PyErr_Format(PyExc_IndexError, "Invalid index for AffineTransform: %d", i);
84  throw py::error_already_set();
85  }
86  return self[i];
87  });
88  cls.def("__str__", [](AffineTransform const &self) { return py::str(py::cast(self.getMatrix())); });
89  cls.def("__repr__", [](AffineTransform const &self) {
90  return py::str("AffineTransform(\n{}\n)").format(py::cast(self.getMatrix()));
91  });
92  cls.def("__reduce__", [cls](AffineTransform const &self) {
93  return py::make_tuple(cls, py::make_tuple(py::cast(self.getMatrix())));
94  });
95 
96  /* Members */
97  cls.def("inverted", &AffineTransform::inverted);
98  cls.def("invert", &AffineTransform::invert);
99  cls.def("isIdentity", &AffineTransform::isIdentity);
100  cls.def("getTranslation", (Extent2D & (AffineTransform::*)()) & AffineTransform::getTranslation);
101  cls.def("getLinear", (LinearTransform & (AffineTransform::*)()) & AffineTransform::getLinear);
102  cls.def("getMatrix", &AffineTransform::getMatrix);
103  cls.def("getParameterVector", &AffineTransform::getParameterVector);
104  cls.def("setParameterVector", &AffineTransform::setParameterVector);
105  cls.def_static("makeScaling", (AffineTransform(*)(double)) & AffineTransform::makeScaling);
106  cls.def_static("makeScaling", (AffineTransform(*)(double, double)) & AffineTransform::makeScaling);
107  cls.def_static("makeRotation", &AffineTransform::makeRotation, "angle"_a);
108  cls.def_static("makeTranslation", &AffineTransform::makeTranslation, "translation"_a);
109 
110  /* Non-members */
111  mod.def("makeAffineTransformFromTriple", makeAffineTransformFromTriple);
112 }
113 
114 } // namespace
115 } // namespace geom
116 } // namespace lsst
int col
Definition: CR.cc:144
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
Definition: Relationship.h:55
Point< double, 2 > Point2D
Definition: Point.h:324
A base class for image defects.
Definition: cameraGeom.dox:3
PYBIND11_MODULE(cameraSys, mod)
Definition: cameraSys.cc:62
Extent< double, 2 > Extent2D
Definition: Extent.h:396
AffineTransform makeAffineTransformFromTriple(Point2D const &p1, Point2D const &p2, Point2D const &p3, Point2D const &q1, Point2D const &q2, Point2D const &q3)
int row
Definition: CR.cc:145