Initial implementation of keyboard callback registration mechanism without boost
This commit is contained in:
parent
e75057956a
commit
e10582ce4f
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <opencv2/viz/types.hpp>
|
#include <opencv2/viz/types.hpp>
|
||||||
|
#include <opencv2/viz/events.hpp>
|
||||||
|
|
||||||
namespace temp_viz
|
namespace temp_viz
|
||||||
{
|
{
|
||||||
@ -57,6 +58,8 @@ namespace temp_viz
|
|||||||
|
|
||||||
void spin ();
|
void spin ();
|
||||||
void spinOnce (int time = 1, bool force_redraw = false);
|
void spinOnce (int time = 1, bool force_redraw = false);
|
||||||
|
|
||||||
|
void registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void* cookie = NULL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Viz3d(const Viz3d&);
|
Viz3d(const Viz3d&);
|
||||||
|
@ -35,6 +35,10 @@ void temp_viz::InteractorStyle::Initialize ()
|
|||||||
|
|
||||||
init_ = true;
|
init_ = true;
|
||||||
stereo_anaglyph_mask_default_ = 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<void (const cv::KeyboardEvent&)> callback)
|
// boost::signals2::connection temp_viz::InteractorStyle::registerKeyboardCallback (boost::function<void (const cv::KeyboardEvent&)> 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 ());
|
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 ();
|
renderer_->Render ();
|
||||||
Interactor->Render ();
|
Interactor->Render ();
|
||||||
@ -518,7 +533,10 @@ temp_viz::InteractorStyle::OnKeyDown ()
|
|||||||
void temp_viz::InteractorStyle::OnKeyUp ()
|
void temp_viz::InteractorStyle::OnKeyUp ()
|
||||||
{
|
{
|
||||||
KeyboardEvent event (false, Interactor->GetKeySym (), Interactor->GetKeyCode (), Interactor->GetAltKey (), Interactor->GetControlKey (), Interactor->GetShiftKey ());
|
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 ();
|
Superclass::OnKeyUp ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,13 +68,27 @@ namespace temp_viz
|
|||||||
*/
|
*/
|
||||||
boost::signals2::connection registerMouseCallback (boost::function<void (const cv::MouseEvent&)> cb);
|
boost::signals2::connection registerMouseCallback (boost::function<void (const cv::MouseEvent&)> cb);
|
||||||
|
|
||||||
/** \brief Register a callback boost::function for keyboard events
|
/** \brief Register a callback function for keyboard events
|
||||||
* \param[in] cb a boost function that will be registered as a callback for a keyboard event
|
* \param[in] callback a function that will be registered as a callback for a keyboard event
|
||||||
* \return a connection object that allows to disconnect the callback function.
|
* \param[in] cookie user data passed to the callback function
|
||||||
*/
|
*/
|
||||||
boost::signals2::connection registerKeyboardCallback (boost::function<void (const cv::KeyboardEvent&)> 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<typename T> 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.
|
/** \brief Save the current rendered image to disk, as a PNG screenshot.
|
||||||
* \param[in] file the name of the PNG file
|
* \param[in] file the name of the PNG file
|
||||||
*/
|
*/
|
||||||
@ -146,5 +160,10 @@ namespace temp_viz
|
|||||||
|
|
||||||
/** \brief The keyboard modifier to use. Default: Alt. */
|
/** \brief The keyboard modifier to use. Default: Alt. */
|
||||||
KeyboardModifier modifier_;
|
KeyboardModifier modifier_;
|
||||||
|
|
||||||
|
/** \brief Keyboard-Callback function */
|
||||||
|
void (*keyboardCallback_)(const cv::KeyboardEvent&, void*);
|
||||||
|
void *keyboard_callback_cookie_;
|
||||||
|
void *keyboard_callback_instance_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -22,23 +22,41 @@ public:
|
|||||||
virtual ~VizImpl ();
|
virtual ~VizImpl ();
|
||||||
void setFullScreen (bool mode);
|
void setFullScreen (bool mode);
|
||||||
void setWindowName (const std::string &name);
|
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<typename T> 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<void (const cv::KeyboardEvent&)> 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
|
// /** \brief Register a callback boost::function for keyboard events
|
||||||
* \param[in] instance instance to the class that implements the callback function
|
// * \param[in] cb a boost function that will be registered as a callback for a keyboard event
|
||||||
* \param[in] cookie user data that is passed to the callback
|
// * \return a connection object that allows to disconnect the callback function.
|
||||||
* \return a connection object that allows to disconnect the callback function.
|
// */
|
||||||
*/
|
// void registerKeyboardCallback (boost::function<void (const cv::KeyboardEvent&)> cb);
|
||||||
template<typename T> inline boost::signals2::connection registerKeyboardCallback (void (T::*callback) (const cv::KeyboardEvent&, void*), T& instance, void* cookie = NULL)
|
// inline boost::signals2::connection registerKeyboardCallback (void (*callback) (const cv::KeyboardEvent&, void*), void* cookie = NULL)
|
||||||
{ return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie))); }
|
// { 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<typename T> 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
|
/** \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
|
* \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<vtkAppendPolyData> &polydata);
|
void allocVtkPolyData (vtkSmartPointer<vtkAppendPolyData> &polydata);
|
||||||
void allocVtkPolyData (vtkSmartPointer<vtkPolyData> &polydata);
|
void allocVtkPolyData (vtkSmartPointer<vtkPolyData> &polydata);
|
||||||
void allocVtkUnstructuredGrid (vtkSmartPointer<vtkUnstructuredGrid> &polydata);
|
void allocVtkUnstructuredGrid (vtkSmartPointer<vtkUnstructuredGrid> &polydata);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//void getTransformationMatrix (const Eigen::Vector4f &origin, const Eigen::Quaternionf& orientation, Eigen::Matrix4f &transformation);
|
//void getTransformationMatrix (const Eigen::Vector4f &origin, const Eigen::Quaternionf& orientation, Eigen::Matrix4f &transformation);
|
||||||
|
@ -92,3 +92,8 @@ bool temp_viz::Viz3d::removeCoordinateSystem (const String &id)
|
|||||||
{
|
{
|
||||||
return impl_->removeCoordinateSystem(id);
|
return impl_->removeCoordinateSystem(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void temp_viz::Viz3d::registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void* cookie)
|
||||||
|
{
|
||||||
|
impl_->registerKeyboardCallback(callback, cookie);
|
||||||
|
}
|
@ -94,18 +94,19 @@ temp_viz::Viz3d::VizImpl::~VizImpl ()
|
|||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
void temp_viz::Viz3d::VizImpl::saveScreenshot (const std::string &file) { style_->saveScreenshot (file); }
|
void temp_viz::Viz3d::VizImpl::saveScreenshot (const std::string &file) { style_->saveScreenshot (file); }
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
boost::signals2::connection temp_viz::Viz3d::VizImpl::registerKeyboardCallback (boost::function<void (const cv::KeyboardEvent&)> callback)
|
|
||||||
{
|
|
||||||
return (style_->registerKeyboardCallback (callback));
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
boost::signals2::connection temp_viz::Viz3d::VizImpl::registerMouseCallback (boost::function<void (const cv::MouseEvent&)> callback)
|
boost::signals2::connection temp_viz::Viz3d::VizImpl::registerMouseCallback (boost::function<void (const cv::MouseEvent&)> callback)
|
||||||
{
|
{
|
||||||
return (style_->registerMouseCallback (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 ()
|
void temp_viz::Viz3d::VizImpl::spin ()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user