MCPcopy Create free account
hub / github.com/colmap/colmap / BindEigenGeometry

Function BindEigenGeometry

src/pycolmap/geometry/eigen.cc:15–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13namespace py = pybind11;
14
15void BindEigenGeometry(py::module& m) {
16 using Rotation3dWrapper = pycolmap::Rotation3dWrapper;
17 py::classh_ext<Rotation3dWrapper> PyRotation3d(m, "Rotation3d");
18 PyRotation3d.def(py::init<>())
19 .def(py::init<const Eigen::Vector4d&>(),
20 "xyzw"_a,
21 "Quaternion in [x,y,z,w] format.")
22 .def(py::init<const Eigen::Matrix3d&>(),
23 "matrix"_a,
24 "3x3 rotation matrix.")
25 .def(py::init<const Eigen::Vector3d&>(),
26 "axis_angle"_a,
27 "Axis-angle 3D vector.")
28 .def_static(
29 "from_buffer",
30 [](py::array_t<double> arr) {
31 THROW_CHECK_EQ(arr.size(), 4);
32 return Rotation3dWrapper(std::move(arr));
33 },
34 "array"_a,
35 "Create from numpy array view (zero-copy if contiguous).")
36 .def_property(
37 "quat",
38 [](Rotation3dWrapper& self) { return self.data; },
39 [](Rotation3dWrapper& self, const Eigen::Vector4d& quat) {
40 self.map().coeffs() = quat;
41 },
42 "Quaternion in [x,y,z,w] format.")
43 .def("__mul__",
44 [](const Rotation3dWrapper& self, const Rotation3dWrapper& other) {
45 return Rotation3dWrapper(self.map() * other.map());
46 })
47 .def("__mul__",
48 [](const Rotation3dWrapper& self, const Eigen::Vector3d& v) {
49 return Eigen::Vector3d(self.map() * v);
50 })
51 .def("__mul__",
52 [](const Rotation3dWrapper& self,
53 const py::EigenDRef<const Eigen::MatrixX3d>& points)
54 -> Eigen::MatrixX3d {
55 return points * self.map().toRotationMatrix().transpose();
56 })
57 .def("normalize", [](Rotation3dWrapper& self) { self.map().normalize(); })
58 .def("matrix",
59 [](const Rotation3dWrapper& self) {
60 return self.map().toRotationMatrix();
61 })
62 .def("norm",
63 [](const Rotation3dWrapper& self) { return self.map().norm(); })
64 .def("angle",
65 [](const Rotation3dWrapper& self) {
66 return Eigen::AngleAxis<double>(self.map()).angle();
67 })
68 .def(
69 "angle_to",
70 [](const Rotation3dWrapper& self, const Rotation3dWrapper& other) {
71 return self.map().angularDistance(other.map());
72 },

Callers 1

BindGeometryFunction · 0.85

Calls 4

Rotation3dWrapperClass · 0.85
MakeDataclassFunction · 0.85
sizeMethod · 0.80
mapMethod · 0.80

Tested by

no test coverage detected