From ce8630945a7eb34371e982fa0aedc4e5535a02cf Mon Sep 17 00:00:00 2001 From: Samuel Felton Date: Tue, 8 Oct 2024 12:45:16 +0200 Subject: [PATCH] Setup trampoline class for visual odometry interface --- modules/python/bindings/include/rbt.hpp | 2 + modules/python/bindings/include/rbt/vo.hpp | 49 +++++++++++++++++++ modules/python/config/rbt.json | 4 ++ .../include/visp3/rbt/vpRBVisualOdometry.h | 18 +++++++ 4 files changed, 73 insertions(+) create mode 100644 modules/python/bindings/include/rbt/vo.hpp create mode 100644 modules/tracker/rbt/include/visp3/rbt/vpRBVisualOdometry.h diff --git a/modules/python/bindings/include/rbt.hpp b/modules/python/bindings/include/rbt.hpp index a3c1b127a2..b918ec0826 100644 --- a/modules/python/bindings/include/rbt.hpp +++ b/modules/python/bindings/include/rbt.hpp @@ -36,6 +36,8 @@ #define VISP_PYTHON_RBT_HPP #include "rbt/feature_tracker.hpp" +#include "rbt/vo.hpp" + diff --git a/modules/python/bindings/include/rbt/vo.hpp b/modules/python/bindings/include/rbt/vo.hpp new file mode 100644 index 0000000000..50462b1fea --- /dev/null +++ b/modules/python/bindings/include/rbt/vo.hpp @@ -0,0 +1,49 @@ + +#ifndef VISP_PYTHON_RBT_VO_HPP +#define VISP_PYTHON_RBT_VO_HPP + +#include +#include + + +class TrampolineRBVisualOdometry : public vpRBVisualOdometry +{ +public: + using vpRBVisualOdometry::vpRBVisualOdometry; + + TrampolineRBVisualOdometry() : vpRBVisualOdometry() { } + + virtual void compute(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame) VP_OVERRIDE + { + pybind11::gil_scoped_acquire gil; // Acquire the GIL while in this scope. + // Try to look up the overridden method on the Python side. + pybind11::function override = pybind11::get_override(this, "compute"); + if (override) { // method is found + // Pybind seems to copy the frames, so we pass the pointers + override(&frame, &previousFrame); + } + } + + virtual vpHomogeneousMatrix getCameraMotion() const VP_OVERRIDE + { + PYBIND11_OVERRIDE( + vpHomogeneousMatrix, /* Return type */ + vpRBVisualOdometry, /* Parent class */ + getCameraMotion, /* Name of function in C++ (must match Python name) */ + + ); + } + virtual vpHomogeneousMatrix getCameraPose() const VP_OVERRIDE + { + PYBIND11_OVERRIDE( + vpHomogeneousMatrix, /* Return type */ + vpRBVisualOdometry, /* Parent class */ + getCameraPose, /* Name of function in C++ (must match Python name) */ + + ); + } +}; + + + +#endif diff --git a/modules/python/config/rbt.json b/modules/python/config/rbt.json index 08efe92ceb..1c595e35d6 100644 --- a/modules/python/config/rbt.json +++ b/modules/python/config/rbt.json @@ -264,6 +264,10 @@ } ] }, + "vpRBVisualOdometry": { + "trampoline": "TrampolineRBVisualOdometry", + "use_publicist": true + }, "vpObjectCentricRenderer": { "methods": [ { diff --git a/modules/tracker/rbt/include/visp3/rbt/vpRBVisualOdometry.h b/modules/tracker/rbt/include/visp3/rbt/vpRBVisualOdometry.h new file mode 100644 index 0000000000..9a89021331 --- /dev/null +++ b/modules/tracker/rbt/include/visp3/rbt/vpRBVisualOdometry.h @@ -0,0 +1,18 @@ +#ifndef VP_RB_VISUAL_ODOMETRY_H +#define VP_RB_VISUAL_ODOMETRY_H + +#include + +class vpRBFeatureTrackerInput; +class vpHomogeneousMatrix; + +class VISP_EXPORT vpRBVisualOdometry +{ +public: + virtual void compute(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame) = 0; + virtual vpHomogeneousMatrix getCameraMotion() const = 0; + virtual vpHomogeneousMatrix getCameraPose() const = 0; +}; + + +#endif