LSSTApplications  12.1-5-gbdcc3ab+2,15.0+13,15.0+26,15.0-1-g19261fa+17,15.0-1-g60afb23+26,15.0-1-g615e0bb+18,15.0-1-g788a293+26,15.0-1-ga91101e+26,15.0-1-gae1598d+12,15.0-1-gd076f1f+24,15.0-1-gdf18595+5,15.0-1-gf4f1c34+12,15.0-11-g7db6e543+4,15.0-12-g3681e7a+4,15.0-15-gc15de322,15.0-16-g83b84f4,15.0-2-g100d730+19,15.0-2-g1f9c9cf+4,15.0-2-g8aea5f4+1,15.0-2-gf38729e+21,15.0-29-ga12a2b06e,15.0-3-g11fe1a0+14,15.0-3-g707930d+3,15.0-3-g9103c06+12,15.0-3-gd3cbb57+3,15.0-4-g2d82b59,15.0-4-g535e784+10,15.0-4-g92ca6c3+4,15.0-4-gf906033+2,15.0-5-g23e394c+14,15.0-5-g4be42a9,15.0-6-g69628aa,15.0-6-g86e3f3d+1,15.0-6-gfa9b38f+4,15.0-7-g949993c+3,15.0-8-g67a62d3+1,15.0-8-gcf05001+1,15.0-9-g1e7c341+1,w.2018.21
LSSTDataManagementBasePackage
linearTransform.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2016 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
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 LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include "pybind11/pybind11.h"
24 #include "pybind11/stl.h"
25 
26 #include "ndarray/pybind11.h"
27 
28 #include "lsst/utils/python.h"
29 
30 #include "lsst/afw/geom/Extent.h"
31 #include "lsst/afw/geom/Point.h"
33 
34 namespace py = pybind11;
35 using namespace pybind11::literals;
36 
37 namespace lsst {
38 namespace afw {
39 namespace geom {
40 namespace {
41 
42 using PyLinearTransform = py::class_<LinearTransform, std::shared_ptr<LinearTransform>>;
43 
45  py::module mod("linearTransform");
46 
47  py::module::import("lsst.afw.geom.coordinates");
48 
49  PyLinearTransform cls(mod, "LinearTransform");
50 
51  // Parameters enum is really only used as integer constants.
52  cls.attr("XX") = py::cast(int(LinearTransform::Parameters::XX));
53  cls.attr("YX") = py::cast(int(LinearTransform::Parameters::YX));
54  cls.attr("XY") = py::cast(int(LinearTransform::Parameters::XY));
55  cls.attr("YY") = py::cast(int(LinearTransform::Parameters::YY));
56 
57  /* Constructors */
58  cls.def(py::init<>());
59  cls.def(py::init<LinearTransform::Matrix const &>(), "matrix"_a);
60 
61  /* Operators */
62  cls.def("__call__", (Point2D (LinearTransform::*)(Point2D const &) const) & LinearTransform::operator());
63  cls.def("__call__",
64  (Extent2D (LinearTransform::*)(Extent2D const &) const) & LinearTransform::operator());
65  cls.def("__getitem__",
66  [](LinearTransform const &self, int i) { return self[lsst::utils::python::cppIndex(4, i)]; });
67  cls.def("__getitem__", [](LinearTransform const &self, std::pair<int, int> i) {
68  auto row = lsst::utils::python::cppIndex(2, i.first);
69  auto col = lsst::utils::python::cppIndex(2, i.second);
70  return self.getMatrix()(row, col);
71  });
72  cls.def("__mul__", &LinearTransform::operator*, py::is_operator());
73  cls.def("__add__", &LinearTransform::operator+, py::is_operator());
74  cls.def("__sub__", &LinearTransform::operator-, py::is_operator());
75  cls.def("__iadd__", &LinearTransform::operator+=);
76  cls.def("__isub__", &LinearTransform::operator-=);
77 
78  /* Members */
79  cls.def_static("makeScaling", (LinearTransform(*)(double))LinearTransform::makeScaling, "scale"_a);
80  cls.def_static("makeScaling", (LinearTransform(*)(double, double))LinearTransform::makeScaling);
81  cls.def_static("makeRotation", (LinearTransform(*)(Angle t))LinearTransform::makeRotation, "angle"_a);
82  cls.def("getParameterVector", &LinearTransform::getParameterVector);
83  cls.def("getMatrix",
84  (LinearTransform::Matrix const &(LinearTransform::*)() const) & LinearTransform::getMatrix);
85  cls.def("invert", &LinearTransform::invert);
86  cls.def("computeDeterminant", &LinearTransform::computeDeterminant);
87  cls.def("isIdentity", &LinearTransform::isIdentity);
88 
89  cls.def("set",
90  [](LinearTransform &self, double xx, double yx, double xy, double yy) {
91  self[LinearTransform::XX] = xx;
92  self[LinearTransform::XY] = xy;
93  self[LinearTransform::YX] = yx;
94  self[LinearTransform::YY] = yy;
95  },
96  "xx"_a, "yx"_a, "xy"_a, "yy"_a);
97 
98  cls.def("__str__", [](LinearTransform const &self) { return py::str(py::cast(self.getMatrix())); });
99  cls.def("__repr__", [](LinearTransform const &self) {
100  return py::str("LinearTransform(\n{}\n)").format(py::cast(self.getMatrix()));
101  });
102  cls.def("__reduce__", [cls](LinearTransform const &self) {
103  return py::make_tuple(cls, py::make_tuple(py::cast(self.getMatrix())));
104  });
105 
106  return mod.ptr();
107 }
108 }
109 }
110 }
111 } // namespace lsst::afw::geom::<anonymous>
int col
Definition: CR.cc:156
lsst::afw::geom::Angle Angle
Definition: misc.h:33
Extent< double, 2 > Extent2D
Definition: Extent.h:383
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
PYBIND11_PLUGIN(_cameraSys)
Definition: cameraSys.cc:62
A base class for image defects.
Definition: cameraGeom.dox:3
Point< double, 2 > Point2D
Definition: Point.h:304
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
Typedefs to be used for probability and parameter values.
Definition: common.h:45
int row
Definition: CR.cc:157