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
affineTransform.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 
29 
30 namespace py = pybind11;
31 using namespace pybind11::literals;
32 
33 namespace lsst {
34 namespace afw {
35 namespace geom {
36 namespace {
37 
38 using PyAffineTransform = py::class_<AffineTransform, std::shared_ptr<AffineTransform>>;
39 
41  py::module mod("affineTransform");
42 
43  py::module::import("lsst.afw.geom.linearTransform");
44  py::module::import("lsst.afw.geom.coordinates");
45 
46  PyAffineTransform cls(mod, "AffineTransform");
47 
48  // Parameters enum is really only used as integer constants.
49  cls.attr("XX") = py::cast(int(AffineTransform::Parameters::XX));
50  cls.attr("YX") = py::cast(int(AffineTransform::Parameters::YX));
51  cls.attr("XY") = py::cast(int(AffineTransform::Parameters::XY));
52  cls.attr("YY") = py::cast(int(AffineTransform::Parameters::YY));
53  cls.attr("X") = py::cast(int(AffineTransform::Parameters::X));
54  cls.attr("Y") = py::cast(int(AffineTransform::Parameters::Y));
55 
56  /* Constructors */
57  cls.def(py::init<>());
58  cls.def(py::init<Eigen::Matrix3d const &>(), "matrix"_a);
59  cls.def(py::init<Eigen::Matrix2d const &>(), "linear"_a);
60  cls.def(py::init<Eigen::Vector2d const &>(), "translation"_a);
61  cls.def(py::init<Eigen::Matrix2d const &, Eigen::Vector2d const &>(), "linear"_a, "translation"_a);
62  cls.def(py::init<LinearTransform const &>(), "linear"_a);
63  cls.def(py::init<Extent2D const &>(), "translation"_a);
64  cls.def(py::init<LinearTransform const &, Extent2D const &>(), "linear"_a, "translation"_a);
65 
66  /* Operators and special methods */
67  cls.def("__mul__", &AffineTransform::operator*, py::is_operator());
68  cls.def("__call__", (Point2D (AffineTransform::*)(Point2D const &) const) & AffineTransform::operator());
69  cls.def("__call__",
70  (Extent2D (AffineTransform::*)(Extent2D const &) const) & AffineTransform::operator());
71  cls.def("__setitem__", [](AffineTransform &self, int i, double value) {
72  if (i < 0 || i > 5) {
73  PyErr_Format(PyExc_IndexError, "Invalid index for AffineTransform: %d", i);
74  throw py::error_already_set();
75  }
76  self[i] = value;
77  });
78  cls.def("__getitem__", [](AffineTransform const &self, int row, int col) {
79  if (row < 0 || row > 2 || col < 0 || col > 2) {
80  PyErr_Format(PyExc_IndexError, "Invalid index for AffineTransform: %d, %d", row, col);
81  throw py::error_already_set();
82  }
83  return (self.getMatrix())(row, col);
84  });
85  cls.def("__getitem__", [](AffineTransform const &self, int i) {
86  if (i < 0 || i > 5) {
87  PyErr_Format(PyExc_IndexError, "Invalid index for AffineTransform: %d", i);
88  throw py::error_already_set();
89  }
90  return self[i];
91  });
92  cls.def("__str__", [](AffineTransform const &self) { return py::str(py::cast(self.getMatrix())); });
93  cls.def("__repr__", [](AffineTransform const &self) {
94  return py::str("AffineTransform(\n{}\n)").format(py::cast(self.getMatrix()));
95  });
96  cls.def("__reduce__", [cls](AffineTransform const &self) {
97  return py::make_tuple(cls, py::make_tuple(py::cast(self.getMatrix())));
98  });
99 
100  /* Members */
101  cls.def("invert", &AffineTransform::invert);
102  cls.def("isIdentity", &AffineTransform::isIdentity);
103  cls.def("getTranslation", (Extent2D & (AffineTransform::*)()) & AffineTransform::getTranslation);
104  cls.def("getLinear", (LinearTransform & (AffineTransform::*)()) & AffineTransform::getLinear);
105  cls.def("getMatrix", &AffineTransform::getMatrix);
106  cls.def("getParameterVector", &AffineTransform::getParameterVector);
107  cls.def("setParameterVector", &AffineTransform::setParameterVector);
108  cls.def_static("makeScaling", (AffineTransform(*)(double)) & AffineTransform::makeScaling);
109  cls.def_static("makeScaling", (AffineTransform(*)(double, double)) & AffineTransform::makeScaling);
110  cls.def_static("makeRotation", &AffineTransform::makeRotation, "angle"_a);
111  cls.def_static("makeTranslation", &AffineTransform::makeTranslation, "translation"_a);
112 
113  /* Non-members */
114  mod.def("makeAffineTransformFromTriple", makeAffineTransformFromTriple);
115 
116  return mod.ptr();
117 }
118 }
119 }
120 }
121 } // namespace lsst::afw::geom::<anonymous>
int col
Definition: CR.cc:156
Extent< double, 2 > Extent2D
Definition: Extent.h:383
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
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:157