From e10582ce4f51a80b592d4e40ae44ec120ed9291c Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Wed, 29 May 2013 20:58:57 +0200 Subject: [PATCH 1/2] Initial implementation of keyboard callback registration mechanism without boost --- modules/viz/include/opencv2/viz/viz3d.hpp | 3 ++ modules/viz/src/interactor_style.cpp | 26 ++++++++++-- modules/viz/src/q/interactor_style.h | 31 +++++++++++--- modules/viz/src/q/viz3d_impl.hpp | 49 +++++++++++++++-------- modules/viz/src/viz3d.cpp | 5 +++ modules/viz/src/viz_main.cpp | 13 +++--- 6 files changed, 95 insertions(+), 32 deletions(-) diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index e48f5202f3..9386094d78 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -10,6 +10,7 @@ #include #include +#include namespace temp_viz { @@ -57,6 +58,8 @@ namespace temp_viz void spin (); void spinOnce (int time = 1, bool force_redraw = false); + + void registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void* cookie = NULL); private: Viz3d(const Viz3d&); diff --git a/modules/viz/src/interactor_style.cpp b/modules/viz/src/interactor_style.cpp index d13ad3c353..32fe6a104a 100644 --- a/modules/viz/src/interactor_style.cpp +++ b/modules/viz/src/interactor_style.cpp @@ -35,6 +35,10 @@ void temp_viz::InteractorStyle::Initialize () init_ = true; stereo_anaglyph_mask_default_ = true; + + // Initialize the keyboard callback as none + keyboardCallback_ = NULL; + keyboard_callback_cookie_ = NULL; } ////////////////////////////////////////////////////////////////////////////////////////////// @@ -144,9 +148,17 @@ boost::signals2::connection temp_viz::InteractorStyle::registerMouseCallback (bo } ////////////////////////////////////////////////////////////////////////////////////////////// -boost::signals2::connection temp_viz::InteractorStyle::registerKeyboardCallback (boost::function callback) +// boost::signals2::connection temp_viz::InteractorStyle::registerKeyboardCallback (boost::function callback) +// { +// return (keyboard_signal_.connect (callback)); +// } + +////////////////////////////////////////////////////////////////////////////////////////////// +void temp_viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void *cookie) { - return (keyboard_signal_.connect (callback)); + /* Register the new callback function by assigning it to the internal callback function pointer */ + keyboardCallback_ = callback; + keyboard_callback_cookie_ = NULL; } ////////////////////////////////////////////////////////////////////////////////////////////// @@ -508,7 +520,10 @@ temp_viz::InteractorStyle::OnKeyDown () } KeyboardEvent event (true, Interactor->GetKeySym (), Interactor->GetKeyCode (), Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); - keyboard_signal_ (event); + // Check if there is a keyboard callback registered + if (keyboardCallback_ != NULL) + keyboardCallback_(event, keyboard_callback_cookie_); + //keyboard_signal_ (event); renderer_->Render (); Interactor->Render (); @@ -518,7 +533,10 @@ temp_viz::InteractorStyle::OnKeyDown () void temp_viz::InteractorStyle::OnKeyUp () { KeyboardEvent event (false, Interactor->GetKeySym (), Interactor->GetKeyCode (), Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); - keyboard_signal_ (event); + // Check if there is a keyboard callback registered + if (keyboardCallback_ != NULL) + keyboardCallback_(event, keyboard_callback_cookie_); +// keyboard_signal_ (event); Superclass::OnKeyUp (); } diff --git a/modules/viz/src/q/interactor_style.h b/modules/viz/src/q/interactor_style.h index 91493eda6b..6c99d88e10 100644 --- a/modules/viz/src/q/interactor_style.h +++ b/modules/viz/src/q/interactor_style.h @@ -68,13 +68,27 @@ namespace temp_viz */ boost::signals2::connection registerMouseCallback (boost::function cb); - /** \brief Register a callback boost::function for keyboard events - * \param[in] cb a boost function that will be registered as a callback for a keyboard event - * \return a connection object that allows to disconnect the callback function. + /** \brief Register a callback function for keyboard events + * \param[in] callback a function that will be registered as a callback for a keyboard event + * \param[in] cookie user data passed to the callback function */ - boost::signals2::connection registerKeyboardCallback (boost::function cb); - - + void registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void * cookie = NULL); + + + // TODO Implement callback function as a method of an instance + /** \brief Register a callback function for keyboard input + * \param[in] callback function that will be registered as a callback for a keyboard event + * \param[in] instance the instance that the callback function belongs to + * \param[in] cookie for passing user data to callback + */ +// template inline void registerKeyboardCallback(void (T::*callback)(const cv::KeyboardEvent&, void*), T& instance, void* cookie = NULL) +// { +// registerKeyboardCallback(callback, cookie); +// // Set the instance for calling the callback +// keyboard_callback_instance_ = (void *) &instance; +// +// } + /** \brief Save the current rendered image to disk, as a PNG screenshot. * \param[in] file the name of the PNG file */ @@ -146,5 +160,10 @@ namespace temp_viz /** \brief The keyboard modifier to use. Default: Alt. */ KeyboardModifier modifier_; + + /** \brief Keyboard-Callback function */ + void (*keyboardCallback_)(const cv::KeyboardEvent&, void*); + void *keyboard_callback_cookie_; + void *keyboard_callback_instance_; }; } diff --git a/modules/viz/src/q/viz3d_impl.hpp b/modules/viz/src/q/viz3d_impl.hpp index 1d946f1e13..a6e3de5944 100644 --- a/modules/viz/src/q/viz3d_impl.hpp +++ b/modules/viz/src/q/viz3d_impl.hpp @@ -22,23 +22,41 @@ public: virtual ~VizImpl (); void setFullScreen (bool mode); void setWindowName (const std::string &name); + + /** \brief Register a callback function for keyboard input + * \param[in] callback function that will be registered as a callback for a keyboard event + * \param[in] cookie for passing user data to callback + */ + void registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void* cookie = NULL); + + // TODO Implement callback function as a method of an instance + /** \brief Register a callback function for keyboard input + * \param[in] callback function that will be registered as a callback for a keyboard event + * \param[in] instance the instance that the callback function belongs to + * \param[in] cookie for passing user data to callback + */ + +// template inline void registerKeyboardCallback(void (T::*callback)(const cv::KeyboardEvent&, void*), T& instance, void* cookie = NULL) +// { } - /** \brief Register a callback boost::function for keyboard events - * \param[in] cb a boost function that will be registered as a callback for a keyboard event - * \return a connection object that allows to disconnect the callback function. - */ - boost::signals2::connection registerKeyboardCallback (boost::function cb); - inline boost::signals2::connection registerKeyboardCallback (void (*callback) (const cv::KeyboardEvent&, void*), void* cookie = NULL) - { return (registerKeyboardCallback (boost::bind (callback, _1, cookie))); } - /** \brief Register a callback function for keyboard events - * \param[in] callback the member function that will be registered as a callback for a keyboard event - * \param[in] instance instance to the class that implements the callback function - * \param[in] cookie user data that is passed to the callback - * \return a connection object that allows to disconnect the callback function. - */ - template inline boost::signals2::connection registerKeyboardCallback (void (T::*callback) (const cv::KeyboardEvent&, void*), T& instance, void* cookie = NULL) - { return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie))); } + +// /** \brief Register a callback boost::function for keyboard events +// * \param[in] cb a boost function that will be registered as a callback for a keyboard event +// * \return a connection object that allows to disconnect the callback function. +// */ +// void registerKeyboardCallback (boost::function cb); +// inline boost::signals2::connection registerKeyboardCallback (void (*callback) (const cv::KeyboardEvent&, void*), void* cookie = NULL) +// { return (registerKeyboardCallback (boost::bind (callback, _1, cookie))); } +// +// /** \brief Register a callback function for keyboard events +// * \param[in] callback the member function that will be registered as a callback for a keyboard event +// * \param[in] instance instance to the class that implements the callback function +// * \param[in] cookie user data that is passed to the callback +// * \return a connection object that allows to disconnect the callback function. +// */ +// template inline boost::signals2::connection registerKeyboardCallback (void (T::*callback) (const cv::KeyboardEvent&, void*), T& instance, void* cookie = NULL) +// { return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie))); } /** \brief Register a callback function for mouse events * \param[in] cb a boost function that will be registered as a callback for a mouse event @@ -446,7 +464,6 @@ private: void allocVtkPolyData (vtkSmartPointer &polydata); void allocVtkPolyData (vtkSmartPointer &polydata); void allocVtkUnstructuredGrid (vtkSmartPointer &polydata); - }; //void getTransformationMatrix (const Eigen::Vector4f &origin, const Eigen::Quaternionf& orientation, Eigen::Matrix4f &transformation); diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 9e35e42e9a..ed219f48c6 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -92,3 +92,8 @@ bool temp_viz::Viz3d::removeCoordinateSystem (const String &id) { return impl_->removeCoordinateSystem(id); } + +void temp_viz::Viz3d::registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void* cookie) +{ + impl_->registerKeyboardCallback(callback, cookie); +} \ No newline at end of file diff --git a/modules/viz/src/viz_main.cpp b/modules/viz/src/viz_main.cpp index 2c2fe52453..a64d62f9d8 100644 --- a/modules/viz/src/viz_main.cpp +++ b/modules/viz/src/viz_main.cpp @@ -94,18 +94,19 @@ temp_viz::Viz3d::VizImpl::~VizImpl () ///////////////////////////////////////////////////////////////////////////////////////////// void temp_viz::Viz3d::VizImpl::saveScreenshot (const std::string &file) { style_->saveScreenshot (file); } -///////////////////////////////////////////////////////////////////////////////////////////// -boost::signals2::connection temp_viz::Viz3d::VizImpl::registerKeyboardCallback (boost::function callback) -{ - return (style_->registerKeyboardCallback (callback)); -} - ///////////////////////////////////////////////////////////////////////////////////////////// boost::signals2::connection temp_viz::Viz3d::VizImpl::registerMouseCallback (boost::function callback) { return (style_->registerMouseCallback (callback)); } +///////////////////////////////////////////////////////////////////////////////////////////// +void temp_viz::Viz3d::VizImpl::registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void* cookie) +{ + // Register the callback function in the interactor style + style_->registerKeyboardCallback(callback, cookie); +} + ///////////////////////////////////////////////////////////////////////////////////////////// void temp_viz::Viz3d::VizImpl::spin () { From 6603cc4405977ed9458fc4310774f003d06e985d Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Thu, 30 May 2013 20:01:33 +0200 Subject: [PATCH 2/2] boost dependency has been removed --- modules/viz/CMakeLists.txt | 19 ------ modules/viz/include/opencv2/viz/viz3d.hpp | 3 +- modules/viz/src/interactor_style.cpp | 73 +++++++++++++---------- modules/viz/src/precomp.hpp | 4 +- modules/viz/src/q/interactor_style.h | 38 ++++-------- modules/viz/src/q/viz3d_impl.hpp | 48 ++------------- modules/viz/src/viz3d.cpp | 5 ++ modules/viz/src/viz_main.cpp | 5 +- 8 files changed, 70 insertions(+), 125 deletions(-) diff --git a/modules/viz/CMakeLists.txt b/modules/viz/CMakeLists.txt index 0509478fd5..b45060371b 100644 --- a/modules/viz/CMakeLists.txt +++ b/modules/viz/CMakeLists.txt @@ -36,26 +36,7 @@ macro(find_vtk) endif() endmacro() -macro(find_boost) - # Disable the config mode of find_package(Boost) - set(Boost_NO_BOOST_CMAKE ON) - set(Boost_USE_STATIC_LIBS ON) - - find_package(Boost 1.49.0 REQUIRED COMPONENTS system thread) - - if(Boost_FOUND) - set(HAVE_BOOST ON) - - # Obtain diagnostic information about Boost's automatic linking outputted during compilation time. - add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS}) - include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) - link_directories(${Boost_LIBRARY_DIRS}) - message(STATUS "Boost found (include: ${Boost_INCLUDE_DIRS})") - endif() -endmacro() - find_vtk() -find_boost() find_package(OpenGL) diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index 9386094d78..fe0851a604 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -59,7 +59,8 @@ namespace temp_viz void spin (); void spinOnce (int time = 1, bool force_redraw = false); - void registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void* cookie = NULL); + void registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void* cookie = 0); + void registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie = 0); private: Viz3d(const Viz3d&); diff --git a/modules/viz/src/interactor_style.cpp b/modules/viz/src/interactor_style.cpp index 32fe6a104a..00a1ed1725 100644 --- a/modules/viz/src/interactor_style.cpp +++ b/modules/viz/src/interactor_style.cpp @@ -36,9 +36,13 @@ void temp_viz::InteractorStyle::Initialize () init_ = true; stereo_anaglyph_mask_default_ = true; - // Initialize the keyboard callback as none - keyboardCallback_ = NULL; - keyboard_callback_cookie_ = NULL; + // Initialize the keyboard event callback as none + keyboardCallback_ = 0; + keyboard_callback_cookie_ = 0; + + // Initialize the mouse event callback as none + mouseCallback_ = 0; + mouse_callback_cookie_ = 0; } ////////////////////////////////////////////////////////////////////////////////////////////// @@ -142,23 +146,19 @@ void temp_viz::InteractorStyle::OnChar () } ////////////////////////////////////////////////////////////////////////////////////////////// -boost::signals2::connection temp_viz::InteractorStyle::registerMouseCallback (boost::function callback) +void temp_viz::InteractorStyle::registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie) { - return (mouse_signal_.connect (callback)); + // Register the callback function and store the user data + mouseCallback_ = callback; + mouse_callback_cookie_ = cookie; } -////////////////////////////////////////////////////////////////////////////////////////////// -// boost::signals2::connection temp_viz::InteractorStyle::registerKeyboardCallback (boost::function callback) -// { -// return (keyboard_signal_.connect (callback)); -// } - ////////////////////////////////////////////////////////////////////////////////////////////// void temp_viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void *cookie) { - /* Register the new callback function by assigning it to the internal callback function pointer */ + // Register the callback function and store the user data keyboardCallback_ = callback; - keyboard_callback_cookie_ = NULL; + keyboard_callback_cookie_ = cookie; } ////////////////////////////////////////////////////////////////////////////////////////////// @@ -521,9 +521,8 @@ temp_viz::InteractorStyle::OnKeyDown () KeyboardEvent event (true, Interactor->GetKeySym (), Interactor->GetKeyCode (), Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); // Check if there is a keyboard callback registered - if (keyboardCallback_ != NULL) + if (keyboardCallback_) keyboardCallback_(event, keyboard_callback_cookie_); - //keyboard_signal_ (event); renderer_->Render (); Interactor->Render (); @@ -534,9 +533,9 @@ void temp_viz::InteractorStyle::OnKeyUp () { KeyboardEvent event (false, Interactor->GetKeySym (), Interactor->GetKeyCode (), Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); // Check if there is a keyboard callback registered - if (keyboardCallback_ != NULL) + if (keyboardCallback_) keyboardCallback_(event, keyboard_callback_cookie_); -// keyboard_signal_ (event); + Superclass::OnKeyUp (); } @@ -545,7 +544,8 @@ void temp_viz::InteractorStyle::OnMouseMove () { Vec2i p(Interactor->GetEventPosition()); MouseEvent event (MouseEvent::MouseMove, MouseEvent::NoButton, p, Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); - mouse_signal_ (event); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); Superclass::OnMouseMove (); } @@ -555,7 +555,8 @@ void temp_viz::InteractorStyle::OnLeftButtonDown () Vec2i p(Interactor->GetEventPosition()); MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick; MouseEvent event (type, MouseEvent::LeftButton, p, Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); - mouse_signal_ (event); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); Superclass::OnLeftButtonDown (); } @@ -564,7 +565,8 @@ void temp_viz::InteractorStyle::OnLeftButtonUp () { Vec2i p(Interactor->GetEventPosition()); MouseEvent event (MouseEvent::MouseButtonRelease, MouseEvent::LeftButton, p, Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); - mouse_signal_ (event); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); Superclass::OnLeftButtonUp (); } @@ -575,7 +577,8 @@ void temp_viz::InteractorStyle::OnMiddleButtonDown () MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick; MouseEvent event (type, MouseEvent::MiddleButton, p, Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); - mouse_signal_ (event); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); Superclass::OnMiddleButtonDown (); } @@ -584,7 +587,8 @@ void temp_viz::InteractorStyle::OnMiddleButtonUp () { Vec2i p(Interactor->GetEventPosition()); MouseEvent event (MouseEvent::MouseButtonRelease, MouseEvent::MiddleButton, p, Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); - mouse_signal_ (event); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); Superclass::OnMiddleButtonUp (); } @@ -595,7 +599,8 @@ void temp_viz::InteractorStyle::OnRightButtonDown () MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick; MouseEvent event (type, MouseEvent::RightButton, p, Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); - mouse_signal_ (event); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); Superclass::OnRightButtonDown (); } @@ -604,7 +609,8 @@ void temp_viz::InteractorStyle::OnRightButtonUp () { Vec2i p(Interactor->GetEventPosition()); MouseEvent event (MouseEvent::MouseButtonRelease, MouseEvent::RightButton, p, Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); - mouse_signal_ (event); + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); Superclass::OnRightButtonUp (); } @@ -613,9 +619,11 @@ void temp_viz::InteractorStyle::OnMouseWheelForward () { Vec2i p(Interactor->GetEventPosition()); MouseEvent event (MouseEvent::MouseScrollUp, MouseEvent::VScroll, p, Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); - mouse_signal_ (event); - if (Interactor->GetRepeatCount ()) - mouse_signal_ (event); + // If a mouse callback registered, call it! + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + if (Interactor->GetRepeatCount () && mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); if (Interactor->GetAltKey ()) { @@ -643,10 +651,13 @@ void temp_viz::InteractorStyle::OnMouseWheelBackward () { Vec2i p(Interactor->GetEventPosition()); MouseEvent event (MouseEvent::MouseScrollDown, MouseEvent::VScroll, p, Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ()); - mouse_signal_ (event); - if (Interactor->GetRepeatCount ()) - mouse_signal_ (event); - + // If a mouse callback registered, call it! + if (mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + + if (Interactor->GetRepeatCount () && mouseCallback_) + mouseCallback_(event, mouse_callback_cookie_); + if (Interactor->GetAltKey ()) { // zoom diff --git a/modules/viz/src/precomp.hpp b/modules/viz/src/precomp.hpp index ec60d5021f..5e73951731 100644 --- a/modules/viz/src/precomp.hpp +++ b/modules/viz/src/precomp.hpp @@ -4,11 +4,11 @@ #include #include - +/* #include #include #include -#include +#include */ #include diff --git a/modules/viz/src/q/interactor_style.h b/modules/viz/src/q/interactor_style.h index 6c99d88e10..3a196a7285 100644 --- a/modules/viz/src/q/interactor_style.h +++ b/modules/viz/src/q/interactor_style.h @@ -56,38 +56,22 @@ namespace temp_viz */ inline void setCloudActorMap (const cv::Ptr& actors) { actors_ = actors; } - /** \brief Pass a set of renderers to the interactor style. * \param[in] rens the vtkRendererCollection to use */ void setRenderer (vtkSmartPointer& ren) { renderer_ = ren; } /** \brief Register a callback function for mouse events - * \param[in] cb a boost function that will be registered as a callback for a mouse event - * \return a connection object that allows to disconnect the callback function. - */ - boost::signals2::connection registerMouseCallback (boost::function cb); + * \param[in] ccallback function that will be registered as a callback for a mouse event + * \param[in] cookie for passing user data to callback + */ + void registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie = 0); /** \brief Register a callback function for keyboard events * \param[in] callback a function that will be registered as a callback for a keyboard event * \param[in] cookie user data passed to the callback function */ - void registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void * cookie = NULL); - - - // TODO Implement callback function as a method of an instance - /** \brief Register a callback function for keyboard input - * \param[in] callback function that will be registered as a callback for a keyboard event - * \param[in] instance the instance that the callback function belongs to - * \param[in] cookie for passing user data to callback - */ -// template inline void registerKeyboardCallback(void (T::*callback)(const cv::KeyboardEvent&, void*), T& instance, void* cookie = NULL) -// { -// registerKeyboardCallback(callback, cookie); -// // Set the instance for calling the callback -// keyboard_callback_instance_ = (void *) &instance; -// -// } + void registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void * cookie = 0); /** \brief Save the current rendered image to disk, as a PNG screenshot. * \param[in] file the name of the PNG file @@ -127,9 +111,6 @@ namespace temp_viz /** \brief Internal window to image filter. Needed by \a snapshot_writer_. */ vtkSmartPointer wif_; - boost::signals2::signal mouse_signal_; - boost::signals2::signal keyboard_signal_; - /** \brief Interactor style internal method. Gets called whenever a key is pressed. */ virtual void OnChar (); @@ -161,9 +142,14 @@ namespace temp_viz /** \brief The keyboard modifier to use. Default: Alt. */ KeyboardModifier modifier_; - /** \brief Keyboard-Callback function */ + /** \brief KeyboardEvent callback function pointer*/ void (*keyboardCallback_)(const cv::KeyboardEvent&, void*); + /** \brief KeyboardEvent callback user data*/ void *keyboard_callback_cookie_; - void *keyboard_callback_instance_; + + /** \brief MouseEvent callback function pointer */ + void (*mouseCallback_)(const cv::MouseEvent&, void*); + /** \brief MouseEvent callback user data */ + void *mouse_callback_cookie_; }; } diff --git a/modules/viz/src/q/viz3d_impl.hpp b/modules/viz/src/q/viz3d_impl.hpp index a6e3de5944..5e72280a57 100644 --- a/modules/viz/src/q/viz3d_impl.hpp +++ b/modules/viz/src/q/viz3d_impl.hpp @@ -27,53 +27,13 @@ public: * \param[in] callback function that will be registered as a callback for a keyboard event * \param[in] cookie for passing user data to callback */ - void registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void* cookie = NULL); + void registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void* cookie = 0); - // TODO Implement callback function as a method of an instance - /** \brief Register a callback function for keyboard input - * \param[in] callback function that will be registered as a callback for a keyboard event - * \param[in] instance the instance that the callback function belongs to - * \param[in] cookie for passing user data to callback - */ - -// template inline void registerKeyboardCallback(void (T::*callback)(const cv::KeyboardEvent&, void*), T& instance, void* cookie = NULL) -// { } - - - -// /** \brief Register a callback boost::function for keyboard events -// * \param[in] cb a boost function that will be registered as a callback for a keyboard event -// * \return a connection object that allows to disconnect the callback function. -// */ -// void registerKeyboardCallback (boost::function cb); -// inline boost::signals2::connection registerKeyboardCallback (void (*callback) (const cv::KeyboardEvent&, void*), void* cookie = NULL) -// { return (registerKeyboardCallback (boost::bind (callback, _1, cookie))); } -// -// /** \brief Register a callback function for keyboard events -// * \param[in] callback the member function that will be registered as a callback for a keyboard event -// * \param[in] instance instance to the class that implements the callback function -// * \param[in] cookie user data that is passed to the callback -// * \return a connection object that allows to disconnect the callback function. -// */ -// template inline boost::signals2::connection registerKeyboardCallback (void (T::*callback) (const cv::KeyboardEvent&, void*), T& instance, void* cookie = NULL) -// { return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie))); } - /** \brief Register a callback function for mouse events - * \param[in] cb a boost function that will be registered as a callback for a mouse event - * \return a connection object that allows to disconnect the callback function. + * \param[in] ccallback function that will be registered as a callback for a mouse event + * \param[in] cookie for passing user data to callback */ - boost::signals2::connection registerMouseCallback (boost::function cb); - inline boost::signals2::connection registerMouseCallback (void (*callback) (const cv::MouseEvent&, void*), void* cookie = NULL) - { return (registerMouseCallback (boost::bind (callback, _1, cookie))); } - - /** \brief Register a callback function for mouse events - * \param[in] callback the member function that will be registered as a callback for a mouse event - * \param[in] instance instance to the class that implements the callback function - * \param[in] cookie user data that is passed to the callback - * \return a connection object that allows to disconnect the callback function. - */ - template inline boost::signals2::connection registerMouseCallback (void (T::*callback) (const cv::MouseEvent&, void*), T& instance, void* cookie = NULL) - { return (registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie))); } + void registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie = 0); void spin (); void spinOnce (int time = 1, bool force_redraw = false); diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index ed219f48c6..974013d2fd 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -96,4 +96,9 @@ bool temp_viz::Viz3d::removeCoordinateSystem (const String &id) void temp_viz::Viz3d::registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void* cookie) { impl_->registerKeyboardCallback(callback, cookie); +} + +void temp_viz::Viz3d::registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie) +{ + impl_->registerMouseCallback(callback, cookie); } \ No newline at end of file diff --git a/modules/viz/src/viz_main.cpp b/modules/viz/src/viz_main.cpp index a64d62f9d8..1ea8368af9 100644 --- a/modules/viz/src/viz_main.cpp +++ b/modules/viz/src/viz_main.cpp @@ -95,9 +95,10 @@ temp_viz::Viz3d::VizImpl::~VizImpl () void temp_viz::Viz3d::VizImpl::saveScreenshot (const std::string &file) { style_->saveScreenshot (file); } ///////////////////////////////////////////////////////////////////////////////////////////// -boost::signals2::connection temp_viz::Viz3d::VizImpl::registerMouseCallback (boost::function callback) +void temp_viz::Viz3d::VizImpl::registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie) { - return (style_->registerMouseCallback (callback)); + // Register the callback function in the interactor style + style_->registerMouseCallback(callback, cookie); } /////////////////////////////////////////////////////////////////////////////////////////////