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
linearTransform.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 
28 #include "lsst/utils/python.h"
29 
30 #include "lsst/geom/Extent.h"
31 #include "lsst/geom/Point.h"
33 
34 namespace py = pybind11;
35 using namespace pybind11::literals;
36 
37 namespace lsst {
38 namespace geom {
39 namespace {
40 
41 using PyLinearTransform = py::class_<LinearTransform, std::shared_ptr<LinearTransform>>;
42 
44  py::module::import("lsst.geom.coordinates");
45 
46  PyLinearTransform cls(mod, "LinearTransform");
47 
48  // Parameters enum is really only used as integer constants.
49  cls.attr("XX") = py::cast(int(LinearTransform::Parameters::XX));
50  cls.attr("YX") = py::cast(int(LinearTransform::Parameters::YX));
51  cls.attr("XY") = py::cast(int(LinearTransform::Parameters::XY));
52  cls.attr("YY") = py::cast(int(LinearTransform::Parameters::YY));
53 
54  /* Constructors */
55  cls.def(py::init<>());
56  cls.def(py::init<LinearTransform::Matrix const &>(), "matrix"_a);
57 
58  /* Operators */
59  cls.def("__call__", (Point2D(LinearTransform::*)(Point2D const &) const) & LinearTransform::operator());
60  cls.def("__call__", (Extent2D(LinearTransform::*)(Extent2D const &) const) & LinearTransform::operator());
61  cls.def("__getitem__",
62  [](LinearTransform const &self, int i) { return self[lsst::utils::python::cppIndex(4, i)]; });
63  cls.def("__getitem__", [](LinearTransform const &self, std::pair<int, int> i) {
64  auto row = lsst::utils::python::cppIndex(2, i.first);
65  auto col = lsst::utils::python::cppIndex(2, i.second);
66  return self.getMatrix()(row, col);
67  });
68  cls.def("__mul__", &LinearTransform::operator*, py::is_operator());
69  cls.def("__add__", &LinearTransform::operator+, py::is_operator());
70  cls.def("__sub__", &LinearTransform::operator-, py::is_operator());
71  cls.def("__iadd__", &LinearTransform::operator+=);
72  cls.def("__isub__", &LinearTransform::operator-=);
73 
74  /* Members */
75  cls.def_static("makeScaling", (LinearTransform(*)(double))LinearTransform::makeScaling, "scale"_a);
76  cls.def_static("makeScaling", (LinearTransform(*)(double, double))LinearTransform::makeScaling);
77  cls.def_static("makeRotation", (LinearTransform(*)(Angle t))LinearTransform::makeRotation, "angle"_a);
78  cls.def("getParameterVector", &LinearTransform::getParameterVector);
79  cls.def("getMatrix",
80  (LinearTransform::Matrix const &(LinearTransform::*)() const) & LinearTransform::getMatrix);
81  cls.def("inverted", &LinearTransform::inverted);
82  cls.def("invert", &LinearTransform::invert);
83  cls.def("computeDeterminant", &LinearTransform::computeDeterminant);
84  cls.def("isIdentity", &LinearTransform::isIdentity);
85 
86  cls.def("set",
87  [](LinearTransform &self, double xx, double yx, double xy, double yy) {
88  self[LinearTransform::XX] = xx;
89  self[LinearTransform::XY] = xy;
90  self[LinearTransform::YX] = yx;
91  self[LinearTransform::YY] = yy;
92  },
93  "xx"_a, "yx"_a, "xy"_a, "yy"_a);
94 
95  cls.def("__str__", [](LinearTransform const &self) { return py::str(py::cast(self.getMatrix())); });
96  cls.def("__repr__", [](LinearTransform const &self) {
97  return py::str("LinearTransform(\n{}\n)").format(py::cast(self.getMatrix()));
98  });
99  cls.def("__reduce__", [cls](LinearTransform const &self) {
100  return py::make_tuple(cls, py::make_tuple(py::cast(self.getMatrix())));
101  });
102 }
103 
104 } // namespace
105 } // namespace geom
106 } // namespace lsst
int col
Definition: CR.cc:144
std::size_t cppIndex(std::ptrdiff_t size, std::ptrdiff_t i)
Compute a C++ index from a Python index (negative values count from the end) and range-check.
Definition: python.h:119
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
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
Typedefs to be used for probability and parameter values.
Definition: common.h:45
lsst::geom::Angle Angle
Definition: misc.h:33
Extent< double, 2 > Extent2D
Definition: Extent.h:396
int row
Definition: CR.cc:145