mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 13:47:32 +08:00
little refactoring
This commit is contained in:
parent
7cfa3cbd8a
commit
c65d888875
@ -3,7 +3,7 @@
|
||||
#include <string>
|
||||
#include <opencv2/viz/types.hpp>
|
||||
|
||||
namespace cv
|
||||
namespace temp_viz
|
||||
{
|
||||
class KeyboardEvent
|
||||
{
|
||||
@ -13,13 +13,13 @@ namespace cv
|
||||
static const unsigned int Shift = 4;
|
||||
|
||||
/** \brief Constructor
|
||||
* \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 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] 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] action true for key was pressed, false for released
|
||||
* \param[in] key_sym the key-name 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] 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
|
||||
*/
|
||||
KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift);
|
||||
|
||||
bool isAltPressed () const;
|
||||
@ -28,7 +28,7 @@ namespace cv
|
||||
|
||||
unsigned char getKeyCode () const;
|
||||
|
||||
const std::string& getKeySym () const;
|
||||
const String& getKeySym () const;
|
||||
bool keyDown () const;
|
||||
bool keyUp () const;
|
||||
|
||||
@ -37,7 +37,7 @@ namespace cv
|
||||
bool action_;
|
||||
unsigned int modifiers_;
|
||||
unsigned char key_code_;
|
||||
std::string key_sym_;
|
||||
String key_sym_;
|
||||
};
|
||||
|
||||
class MouseEvent
|
||||
@ -75,7 +75,7 @@ namespace cv
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// 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)
|
||||
{
|
||||
if (alt)
|
||||
@ -88,15 +88,15 @@ inline cv::KeyboardEvent::KeyboardEvent (bool _action, const std::string& _key_s
|
||||
modifiers_ |= Shift;
|
||||
}
|
||||
|
||||
inline bool cv::KeyboardEvent::isAltPressed () const { return (modifiers_ & Alt) != 0; }
|
||||
inline bool cv::KeyboardEvent::isCtrlPressed () const { return (modifiers_ & Ctrl) != 0; }
|
||||
inline bool cv::KeyboardEvent::isShiftPressed () const { return (modifiers_ & Shift) != 0; }
|
||||
inline unsigned char cv::KeyboardEvent::getKeyCode () const { return key_code_; }
|
||||
inline const std::string& cv::KeyboardEvent::getKeySym () const { return (key_sym_); }
|
||||
inline bool cv::KeyboardEvent::keyDown () const { return action_; }
|
||||
inline bool cv::KeyboardEvent::keyUp () const { return !action_; }
|
||||
inline bool temp_viz::KeyboardEvent::isAltPressed () const { return (modifiers_ & Alt) != 0; }
|
||||
inline bool temp_viz::KeyboardEvent::isCtrlPressed () const { return (modifiers_ & Ctrl) != 0; }
|
||||
inline bool temp_viz::KeyboardEvent::isShiftPressed () const { return (modifiers_ & Shift) != 0; }
|
||||
inline unsigned char temp_viz::KeyboardEvent::getKeyCode () const { return key_code_; }
|
||||
inline const temp_viz::String& temp_viz::KeyboardEvent::getKeySym () const { return key_sym_; }
|
||||
inline bool temp_viz::KeyboardEvent::keyDown () 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)
|
||||
{
|
||||
if (alt)
|
||||
|
@ -53,8 +53,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 = 0);
|
||||
void registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie = 0);
|
||||
void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void* cookie = 0);
|
||||
void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
|
||||
|
||||
bool wasStopped() const;
|
||||
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
|
||||
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
|
||||
keyboardCallback_ = callback;
|
||||
@ -290,17 +290,19 @@ temp_viz::InteractorStyle::OnKeyDown ()
|
||||
case 'c': case 'C':
|
||||
{
|
||||
vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->GetActiveCamera ();
|
||||
double clip[2], focal[3], pos[3], view[3];
|
||||
cam->GetClippingRange (clip);
|
||||
cam->GetFocalPoint (focal);
|
||||
cam->GetPosition (pos);
|
||||
cam->GetViewUp (view);
|
||||
int *win_pos = Interactor->GetRenderWindow ()->GetPosition ();
|
||||
int *win_size = Interactor->GetRenderWindow ()->GetSize ();
|
||||
std::cerr << clip[0] << "," << clip[1] << "/" << focal[0] << "," << focal[1] << "," << focal[2] << "/" <<
|
||||
pos[0] << "," << pos[1] << "," << pos[2] << "/" << view[0] << "," << view[1] << "," << view[2] << "/" <<
|
||||
cam->GetViewAngle () / 180.0 * M_PI << "/" << win_size[0] << "," << win_size[1] << "/" << win_pos[0] << "," << win_pos[1]
|
||||
<< endl;
|
||||
|
||||
Vec2d clip;
|
||||
Vec3d focal, pose, view;
|
||||
cam->GetClippingRange (clip.val);
|
||||
cam->GetFocalPoint (focal.val);
|
||||
cam->GetPosition (pose.val);
|
||||
cam->GetViewUp (view.val);
|
||||
Vec2i win_pos(Interactor->GetRenderWindow()->GetPosition ());
|
||||
Vec2i win_size(Interactor->GetRenderWindow()->GetSize ());
|
||||
std::cerr << Mat(clip, false).reshape(1, 1) << "/" << Mat(focal, false).reshape(1, 1) << "/" <<
|
||||
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;
|
||||
}
|
||||
case '=':
|
||||
|
@ -16,7 +16,7 @@ namespace temp_viz
|
||||
* - j, J : take a .PNG snapshot of the current window view
|
||||
* - c, C : display current camera/window parameters
|
||||
* - f, F : fly to point mode
|
||||
* - e, E : exit the interactor\
|
||||
* - e, E : exit the interactor
|
||||
* - q, Q : stop and call VTK's TerminateApp
|
||||
* - + / - : increment/decrement overall point size
|
||||
* - r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]
|
||||
@ -52,8 +52,8 @@ namespace temp_viz
|
||||
virtual void Initialize ();
|
||||
|
||||
/** \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; }
|
||||
|
||||
/** \brief Pass a set of renderers to the interactor style.
|
||||
@ -62,17 +62,17 @@ namespace temp_viz
|
||||
void setRenderer (vtkSmartPointer<vtkRenderer>& ren) { renderer_ = ren; }
|
||||
|
||||
/** \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] cookie for passing user data to callback
|
||||
*/
|
||||
void registerMouseCallback(void (*callback)(const cv::MouseEvent&, void*), void* cookie = 0);
|
||||
* \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 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 = 0);
|
||||
|
||||
void registerKeyboardCallback(void (*callback)(const 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
|
||||
*/
|
||||
@ -141,15 +141,15 @@ namespace temp_viz
|
||||
|
||||
/** \brief The keyboard modifier to use. Default: Alt. */
|
||||
KeyboardModifier modifier_;
|
||||
|
||||
/** \brief KeyboardEvent callback function pointer*/
|
||||
void (*keyboardCallback_)(const cv::KeyboardEvent&, void*);
|
||||
/** \brief KeyboardEvent callback user data*/
|
||||
void *keyboard_callback_cookie_;
|
||||
|
||||
/** \brief MouseEvent callback function pointer */
|
||||
void (*mouseCallback_)(const cv::MouseEvent&, void*);
|
||||
/** \brief MouseEvent callback user data */
|
||||
void *mouse_callback_cookie_;
|
||||
|
||||
/** \brief KeyboardEvent callback function pointer*/
|
||||
void (*keyboardCallback_)(const KeyboardEvent&, void*);
|
||||
/** \brief KeyboardEvent callback user data*/
|
||||
void *keyboard_callback_cookie_;
|
||||
|
||||
/** \brief MouseEvent callback function pointer */
|
||||
void (*mouseCallback_)(const MouseEvent&, void*);
|
||||
/** \brief MouseEvent callback user data */
|
||||
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] 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
|
||||
* \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);
|
||||
void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
|
||||
|
||||
void spin ();
|
||||
void spinOnce (int time = 1, bool force_redraw = false);
|
||||
@ -494,16 +494,16 @@ struct ApplyAffine
|
||||
const Affine3f& 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;
|
||||
|
||||
Vec<_Tp, 3> result;
|
||||
result[0] = 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[2] = m[8] * v[0] + m[9] * v[1] + m[10] * v[2] + m[11];
|
||||
result[0] = (_Tp)(m[0] * v[0] + m[1] * v[1] + m[ 2] * v[2] + m[ 3]);
|
||||
result[1] = (_Tp)(m[4] * v[0] + m[5] * v[1] + m[ 6] * v[2] + m[ 7]);
|
||||
result[2] = (_Tp)(m[8] * v[0] + m[9] * v[1] + m[10] * v[2] + m[11]);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
@ -93,12 +93,12 @@ 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)
|
||||
void temp_viz::Viz3d::registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void* 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);
|
||||
}
|
||||
|
@ -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::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
|
||||
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
|
||||
style_->registerKeyboardCallback(callback, cookie);
|
||||
|
@ -10,7 +10,11 @@
|
||||
#define __OPENCV_TEST_PRECOMP_HPP__
|
||||
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#endif
|
||||
|
@ -41,16 +41,9 @@
|
||||
//M*/
|
||||
#include "test_precomp.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/mesh_load.hpp>
|
||||
|
||||
|
||||
cv::Mat cvcloud_load()
|
||||
{
|
||||
cv::Mat cloud(1, 20000, CV_32FC3);
|
||||
|
Loading…
Reference in New Issue
Block a user