Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sarlinpe committed Jan 6, 2024
1 parent 83c7fba commit f23955d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 4 additions & 1 deletion pycolmap/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ template <typename T, typename... options>
inline void MakeDataclass(py::class_<T, options...> cls) {
AddDefaultsToDocstrings(cls);
cls.def("mergedict", &UpdateFromDict);
cls.def("summary", &CreateSummary<T>, "write_type"_a = false);
if (!py::hasattr(cls, "summary")) {
cls.def("summary", &CreateSummary<T>, "write_type"_a = false);
}
cls.attr("__repr__") = cls.attr("summary");
cls.def("todict", &ConvertToDict<T>);
cls.def(py::init([cls](py::dict dict) {
auto self = py::object(cls());
Expand Down
9 changes: 4 additions & 5 deletions pycolmap/scene/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ void BindCamera(py::module& m) {
.def_property(
"model_name",
&Camera::ModelName,
[](Camera& self, std::string model_name) {
self.model_id = CameraModelNameToId(model_name);
[](Camera& self, CameraModelId model_id) { // implicit conversion
self.model_id = model_id;
},
"Camera model name (connected to model_id).")
.def_readwrite("width", &Camera::width, "Width of camera sensor.")
Expand Down Expand Up @@ -203,8 +203,8 @@ void BindCamera(py::module& m) {
.def("__repr__", &PrintCamera);
PyCamera.def(py::init([PyCamera](py::dict dict) {
auto self = py::object(PyCamera());
for (auto& it : dict) {
auto key_str = it.first.cast<std::string>();
for (const auto& it : dict) {
const auto key_str = it.first.cast<std::string>();
if ((key_str == "model") || (key_str == "model_name")) {
self.attr("model_id") = it.second; // Implicit conversion.
} else {
Expand All @@ -218,6 +218,5 @@ void BindCamera(py::module& m) {
py::dict dict = kwargs.cast<py::dict>();
return PyCamera(dict).cast<Camera>();
}));

py::implicitly_convertible<py::dict, Camera>();
}

0 comments on commit f23955d

Please sign in to comment.