little refactoring

pull/1453/head
Anatoly Baksheev 12 years ago
parent 7cfa3cbd8a
commit c65d888875
  1. 38
      modules/viz/include/opencv2/viz/events.hpp
  2. 4
      modules/viz/include/opencv2/viz/viz3d.hpp
  3. 28
      modules/viz/src/interactor_style.cpp
  4. 38
      modules/viz/src/q/interactor_style.h
  5. 14
      modules/viz/src/q/viz3d_impl.hpp
  6. 4
      modules/viz/src/viz3d.cpp
  7. 4
      modules/viz/src/viz_main.cpp
  8. 6
      modules/viz/test/test_precomp.hpp
  9. 7
      modules/viz/test/test_viz3d.cpp

@ -3,7 +3,7 @@
#include <string> #include <string>
#include <opencv2/viz/types.hpp> #include <opencv2/viz/types.hpp>
namespace cv namespace temp_viz
{ {
class KeyboardEvent class KeyboardEvent
{ {
@ -13,13 +13,13 @@ namespace cv
static const unsigned int Shift = 4; static const unsigned int Shift = 4;
/** \brief Constructor /** \brief Constructor
* \param[in] action true for key was pressed, false for released * \param[in] action true for key was pressed, false for released
* \param[in] key_sym the key-name that caused the action * \param[in] key_sym the key-name that caused the action
* \param[in] key the key code that caused the action * \param[in] key the key code that caused the action
* \param[in] alt whether the alt key was pressed at the time where this event was triggered * \param[in] alt whether the alt key was pressed at the time where this event was triggered
* \param[in] ctrl whether the ctrl was pressed at the time where this event was triggered * \param[in] ctrl whether the ctrl was pressed at the time where this event was triggered
* \param[in] shift whether the shift was pressed at the time where this event was triggered * \param[in] shift whether the shift was pressed at the time where this event was triggered
*/ */
KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift); KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift);
bool isAltPressed () const; bool isAltPressed () const;
@ -28,7 +28,7 @@ namespace cv
unsigned char getKeyCode () const; unsigned char getKeyCode () const;
const std::string& getKeySym () const; const String& getKeySym () const;
bool keyDown () const; bool keyDown () const;
bool keyUp () const; bool keyUp () const;
@ -37,7 +37,7 @@ namespace cv
bool action_; bool action_;
unsigned int modifiers_; unsigned int modifiers_;
unsigned char key_code_; unsigned char key_code_;
std::string key_sym_; String key_sym_;
}; };
class MouseEvent class MouseEvent
@ -75,7 +75,7 @@ namespace cv
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
/// Implementation /// Implementation
inline cv::KeyboardEvent::KeyboardEvent (bool _action, const std::string& _key_sym, unsigned char key, bool alt, bool ctrl, bool shift) inline temp_viz::KeyboardEvent::KeyboardEvent (bool _action, const std::string& _key_sym, unsigned char key, bool alt, bool ctrl, bool shift)
: action_ (_action), modifiers_ (0), key_code_(key), key_sym_ (_key_sym) : action_ (_action), modifiers_ (0), key_code_(key), key_sym_ (_key_sym)
{ {
if (alt) if (alt)
@ -88,15 +88,15 @@ inline cv::KeyboardEvent::KeyboardEvent (bool _action, const std::string& _key_s
modifiers_ |= Shift; modifiers_ |= Shift;
} }
inline bool cv::KeyboardEvent::isAltPressed () const { return (modifiers_ & Alt) != 0; } inline bool temp_viz::KeyboardEvent::isAltPressed () const { return (modifiers_ & Alt) != 0; }
inline bool cv::KeyboardEvent::isCtrlPressed () const { return (modifiers_ & Ctrl) != 0; } inline bool temp_viz::KeyboardEvent::isCtrlPressed () const { return (modifiers_ & Ctrl) != 0; }
inline bool cv::KeyboardEvent::isShiftPressed () const { return (modifiers_ & Shift) != 0; } inline bool temp_viz::KeyboardEvent::isShiftPressed () const { return (modifiers_ & Shift) != 0; }
inline unsigned char cv::KeyboardEvent::getKeyCode () const { return key_code_; } inline unsigned char temp_viz::KeyboardEvent::getKeyCode () const { return key_code_; }
inline const std::string& cv::KeyboardEvent::getKeySym () const { return (key_sym_); } inline const temp_viz::String& temp_viz::KeyboardEvent::getKeySym () const { return key_sym_; }
inline bool cv::KeyboardEvent::keyDown () const { return action_; } inline bool temp_viz::KeyboardEvent::keyDown () const { return action_; }
inline bool cv::KeyboardEvent::keyUp () const { return !action_; } inline bool temp_viz::KeyboardEvent::keyUp () const { return !action_; }
inline cv::MouseEvent::MouseEvent (const Type& _type, const MouseButton& _button, const Point& _p, bool alt, bool ctrl, bool shift) inline temp_viz::MouseEvent::MouseEvent (const Type& _type, const MouseButton& _button, const Point& _p, bool alt, bool ctrl, bool shift)
: type(_type), button(_button), pointer(_p), key_state(0) : type(_type), button(_button), pointer(_p), key_state(0)
{ {
if (alt) if (alt)

@ -53,8 +53,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 = 0); void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void* cookie = 0);
void registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie = 0); void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
bool wasStopped() const; bool wasStopped() const;
private: private:

@ -133,7 +133,7 @@ void temp_viz::InteractorStyle::OnChar ()
} }
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
void temp_viz::InteractorStyle::registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie) void temp_viz::InteractorStyle::registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie)
{ {
// Register the callback function and store the user data // Register the callback function and store the user data
mouseCallback_ = callback; mouseCallback_ = callback;
@ -141,7 +141,7 @@ void temp_viz::InteractorStyle::registerMouseCallback(void (*callback)(const cv:
} }
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
void temp_viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void *cookie) void temp_viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void *cookie)
{ {
// Register the callback function and store the user data // Register the callback function and store the user data
keyboardCallback_ = callback; keyboardCallback_ = callback;
@ -290,17 +290,19 @@ temp_viz::InteractorStyle::OnKeyDown ()
case 'c': case 'C': case 'c': case 'C':
{ {
vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->GetActiveCamera (); vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->GetActiveCamera ();
double clip[2], focal[3], pos[3], view[3];
cam->GetClippingRange (clip); Vec2d clip;
cam->GetFocalPoint (focal); Vec3d focal, pose, view;
cam->GetPosition (pos); cam->GetClippingRange (clip.val);
cam->GetViewUp (view); cam->GetFocalPoint (focal.val);
int *win_pos = Interactor->GetRenderWindow ()->GetPosition (); cam->GetPosition (pose.val);
int *win_size = Interactor->GetRenderWindow ()->GetSize (); cam->GetViewUp (view.val);
std::cerr << clip[0] << "," << clip[1] << "/" << focal[0] << "," << focal[1] << "," << focal[2] << "/" << Vec2i win_pos(Interactor->GetRenderWindow()->GetPosition ());
pos[0] << "," << pos[1] << "," << pos[2] << "/" << view[0] << "," << view[1] << "," << view[2] << "/" << Vec2i win_size(Interactor->GetRenderWindow()->GetSize ());
cam->GetViewAngle () / 180.0 * M_PI << "/" << win_size[0] << "," << win_size[1] << "/" << win_pos[0] << "," << win_pos[1] std::cerr << Mat(clip, false).reshape(1, 1) << "/" << Mat(focal, false).reshape(1, 1) << "/" <<
<< endl; Mat(pose, false).reshape(1, 1) << "/" << Mat(view, false).reshape(1, 1) << "/" <<
cam->GetViewAngle () / 180.0 * M_PI << "/" <<
Mat(win_size, false).reshape(1,1) << "/" << Mat(win_pos, false).reshape(1,1) << endl;
break; break;
} }
case '=': case '=':

@ -16,7 +16,7 @@ namespace temp_viz
* - j, J : take a .PNG snapshot of the current window view * - j, J : take a .PNG snapshot of the current window view
* - c, C : display current camera/window parameters * - c, C : display current camera/window parameters
* - f, F : fly to point mode * - f, F : fly to point mode
* - e, E : exit the interactor\ * - e, E : exit the interactor
* - q, Q : stop and call VTK's TerminateApp * - q, Q : stop and call VTK's TerminateApp
* - + / - : increment/decrement overall point size * - + / - : increment/decrement overall point size
* - r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}] * - r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]
@ -52,8 +52,8 @@ namespace temp_viz
virtual void Initialize (); virtual void Initialize ();
/** \brief Pass a pointer to the actor map /** \brief Pass a pointer to the actor map
* \param[in] actors the actor map that will be used with this style * \param[in] actors the actor map that will be used with this style
*/ */
inline void setCloudActorMap (const cv::Ptr<CloudActorMap>& actors) { actors_ = actors; } inline void setCloudActorMap (const cv::Ptr<CloudActorMap>& actors) { actors_ = actors; }
/** \brief Pass a set of renderers to the interactor style. /** \brief Pass a set of renderers to the interactor style.
@ -62,17 +62,17 @@ namespace temp_viz
void setRenderer (vtkSmartPointer<vtkRenderer>& ren) { renderer_ = ren; } void setRenderer (vtkSmartPointer<vtkRenderer>& ren) { renderer_ = ren; }
/** \brief Register a callback function for mouse events /** \brief Register a callback function for mouse events
* \param[in] ccallback function that will be registered as a callback for a mouse event * \param[in] ccallback function that will be registered as a callback for a mouse event
* \param[in] cookie for passing user data to callback * \param[in] cookie for passing user data to callback
*/ */
void registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie = 0); void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
/** \brief Register a callback function for keyboard events /** \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] callback a function that will be registered as a callback for a keyboard event
* \param[in] cookie user data passed to the callback function * \param[in] cookie user data passed to the callback function
*/ */
void registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void * cookie = 0); void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0);
/** \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
*/ */
@ -141,15 +141,15 @@ namespace temp_viz
/** \brief The keyboard modifier to use. Default: Alt. */ /** \brief The keyboard modifier to use. Default: Alt. */
KeyboardModifier modifier_; KeyboardModifier modifier_;
/** \brief KeyboardEvent callback function pointer*/ /** \brief KeyboardEvent callback function pointer*/
void (*keyboardCallback_)(const cv::KeyboardEvent&, void*); void (*keyboardCallback_)(const KeyboardEvent&, void*);
/** \brief KeyboardEvent callback user data*/ /** \brief KeyboardEvent callback user data*/
void *keyboard_callback_cookie_; void *keyboard_callback_cookie_;
/** \brief MouseEvent callback function pointer */ /** \brief MouseEvent callback function pointer */
void (*mouseCallback_)(const cv::MouseEvent&, void*); void (*mouseCallback_)(const MouseEvent&, void*);
/** \brief MouseEvent callback user data */ /** \brief MouseEvent callback user data */
void *mouse_callback_cookie_; void *mouse_callback_cookie_;
}; };
} }

@ -27,13 +27,13 @@ public:
* \param[in] callback function that will be registered as a callback for a keyboard event * \param[in] callback function that will be registered as a callback for a keyboard event
* \param[in] cookie for passing user data to callback * \param[in] cookie for passing user data to callback
*/ */
void registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void* cookie = 0); void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void* cookie = 0);
/** \brief Register a callback function for mouse events /** \brief Register a callback function for mouse events
* \param[in] ccallback function that will be registered as a callback for a mouse event * \param[in] ccallback function that will be registered as a callback for a mouse event
* \param[in] cookie for passing user data to callback * \param[in] cookie for passing user data to callback
*/ */
void registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie = 0); void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
void spin (); void spin ();
void spinOnce (int time = 1, bool force_redraw = false); void spinOnce (int time = 1, bool force_redraw = false);
@ -494,16 +494,16 @@ struct ApplyAffine
const Affine3f& affine_; const Affine3f& affine_;
ApplyAffine(const Affine3f& affine) : affine_(affine) {} ApplyAffine(const Affine3f& affine) : affine_(affine) {}
template<typename _Tp> Point3_<_Tp> operator()(const Point3_<_Tp>& p) { return affine_ * p; } template<typename _Tp> Point3_<_Tp> operator()(const Point3_<_Tp>& p) const { return affine_ * p; }
template<typename _Tp> Vec<_Tp, 3> operator()(const Vec<_Tp, 3>& v) template<typename _Tp> Vec<_Tp, 3> operator()(const Vec<_Tp, 3>& v) const
{ {
const float* m = affine_.matrix.val; const float* m = affine_.matrix.val;
Vec<_Tp, 3> result; Vec<_Tp, 3> result;
result[0] = m[0] * v[0] + m[1] * v[1] + m[ 2] * v[2] + m[ 3]; result[0] = (_Tp)(m[0] * v[0] + m[1] * v[1] + m[ 2] * v[2] + m[ 3]);
result[1] = m[4] * v[0] + m[5] * v[1] + m[ 6] * v[2] + m[ 7]; result[1] = (_Tp)(m[4] * v[0] + m[5] * v[1] + m[ 6] * v[2] + m[ 7]);
result[2] = m[8] * v[0] + m[9] * v[1] + m[10] * v[2] + m[11]; result[2] = (_Tp)(m[8] * v[0] + m[9] * v[1] + m[10] * v[2] + m[11]);
return result; return result;
} }
}; };

@ -93,12 +93,12 @@ 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) void temp_viz::Viz3d::registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void* cookie)
{ {
impl_->registerKeyboardCallback(callback, cookie); impl_->registerKeyboardCallback(callback, cookie);
} }
void temp_viz::Viz3d::registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie) void temp_viz::Viz3d::registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie)
{ {
impl_->registerMouseCallback(callback, cookie); impl_->registerMouseCallback(callback, cookie);
} }

@ -95,14 +95,14 @@ 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); }
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
void temp_viz::Viz3d::VizImpl::registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie) void temp_viz::Viz3d::VizImpl::registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie)
{ {
// Register the callback function in the interactor style // Register the callback function in the interactor style
style_->registerMouseCallback(callback, cookie); style_->registerMouseCallback(callback, cookie);
} }
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
void temp_viz::Viz3d::VizImpl::registerKeyboardCallback(void (*callback)(const cv::KeyboardEvent&, void*), void* cookie) void temp_viz::Viz3d::VizImpl::registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void* cookie)
{ {
// Register the callback function in the interactor style // Register the callback function in the interactor style
style_->registerKeyboardCallback(callback, cookie); style_->registerKeyboardCallback(callback, cookie);

@ -10,7 +10,11 @@
#define __OPENCV_TEST_PRECOMP_HPP__ #define __OPENCV_TEST_PRECOMP_HPP__
#include "opencv2/ts.hpp" #include "opencv2/ts.hpp"
#include "opencv2/core/core_c.h" #include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream> #include <iostream>
#include <fstream>
#include <string>
#endif #endif

@ -41,16 +41,9 @@
//M*/ //M*/
#include "test_precomp.hpp" #include "test_precomp.hpp"
#include <opencv2/viz.hpp> #include <opencv2/viz.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <fstream>
#include <string>
#include <opencv2/viz/types.hpp> #include <opencv2/viz/types.hpp>
#include <opencv2/viz/mesh_load.hpp> #include <opencv2/viz/mesh_load.hpp>
cv::Mat cvcloud_load() cv::Mat cvcloud_load()
{ {
cv::Mat cloud(1, 20000, CV_32FC3); cv::Mat cloud(1, 20000, CV_32FC3);

Loading…
Cancel
Save