Debian Codegraph @

src/pycolmap/scene/frame.cc

raw
1 #include "colmap/scene/frame.h"
2
3 #include "pycolmap/helpers.h"
4 #include "pycolmap/pybind11_extension.h"
5 #include "pycolmap/scene/types.h"
6
7 #include <memory>
8 #include <optional>
9 #include <sstream>
10
11 #include <pybind11/eigen.h>
12 #include <pybind11/pybind11.h>
13 #include <pybind11/stl.h>
14 #include <pybind11/stl_bind.h>
15
16 using namespace colmap;
17 using namespace pybind11::literals;
18 namespace py = pybind11;
19
20 void BindFrame(py::module& m) {
21 py::classh<Frame> PyFrame(m, "Frame");
22 PyFrame.def(py::init<>())
23 .def_property("frame_id",
24 &Frame::FrameId,
25 &Frame::SetFrameId,
26 "Unique identifier of the frame.")
27 .def_property("rig_id",
28 &Frame::RigId,
29 &Frame::SetRigId,
30 "Unique identifier of the rig.")
31 .def("has_rig_id", &Frame::HasRigId, "Check whether the rig_id is set.")
32 .def("add_data_id", &Frame::AddDataId, "Associate data with frame.")
33 .def("num_data_ids",
34 &Frame::NumDataIds,
35 "Number of associated data items in frame.")
36 .def("has_data",
37 &Frame::HasDataId,
38 "Check whether frame has associated data.")
39 .def("clear_data_ids",
40 &Frame::ClearDataIds,
41 "Clear all the associated data.")
42 .def("finalize_data_ids",
43 &Frame::FinalizeDataIds,
44 "Finalize data ids, preventing further modifications.")
45 .def("has_final_data_ids",
46 &Frame::HasFinalDataIds,
47 "Check whether data ids have been finalized.")
48 .def_property_readonly(
49 "data_ids",
50 [](const Frame& self) { return self.DataIds(); },
51 "The associated data.")
52 // Cannot have the same name as the property "data_ids" above due to
53 // pybind11 limitations.
54 .def(
55 "data_ids_by_sensor",
56 [](const Frame& self, SensorType type) {
57 const auto data_ids = self.DataIds(type);
58 return std::vector<data_t>(data_ids.begin(), data_ids.end());
59 },
60 "type"_a,
61 "The associated data for a given sensor type.")
62 .def_property_readonly(
63 "image_ids",
64 [](const Frame& self) {
65 const auto image_ids = self.ImageIds();
66 return std::vector<data_t>(image_ids.begin(), image_ids.end());
67 },
68 "The associated image data.")
69 .def_property(
70 "rig",
71 [](Frame& self) -> py::typing::Optional<Rig> {
72 if (self.HasRigPtr()) {
73 return py::cast(self.RigPtr());
74 } else {
75 return py::none();
76 }
77 },
78 &Frame::SetRigPtr,
79 "The associated rig object.")
80 .def("reset_rig_ptr",
81 &Frame::ResetRigPtr,
82 "Make the rig pointer a nullptr.")
83 .def_property(
84 "rig_from_world",
85 py::overload_cast<>(&Frame::MaybeRigFromWorld),
86 py::overload_cast<const std::optional<Rigid3d>&>(
87 &Frame::SetRigFromWorld),
88 "The pose of the frame, defined as the transformation from world to "
89 "rig space.")
90 .def("has_pose", &Frame::HasPose, "Whether the frame has a valid pose.")
91 .def("reset_pose", &Frame::ResetPose, "Invalidate the pose of the frame.")
92 .def("sensor_from_world",
93 &Frame::SensorFromWorld,
94 "sensor_id"_a,
95 "The transformation from the world to a specific sensor.")
96 .def("set_cam_from_world",
97 &Frame::SetCamFromWorld,
98 "camera_id"_a,
99 "cam_from_world"_a,
100 "Set the world to frame from the given camera from world "
101 "transformation.");
102 MakeDataclass(PyFrame);
103
104 py::bind_map<FrameMap>(m, "FrameMap");
105 }