more refactoring

This commit is contained in:
Anatoly Baksheev
2013-07-13 19:08:25 +04:00
parent 512afe2a90
commit d6e2b657f9
14 changed files with 482 additions and 662 deletions

View File

@@ -60,7 +60,30 @@ namespace cv
//! takes coordiante frame data and builds transfrom to global coordinate frame
CV_EXPORTS Affine3f makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin = Vec3f::all(0));
//! constructs camera pose from posiont, focal_point and up_vector (see gluLookAt() for more infromation
CV_EXPORTS Affine3f makeCameraPose(const Vec3f& position, const Vec3f& focal_point, const Vec3f& up_vector);
//! checks float value for Nan
inline bool isNan(float x)
{
unsigned int *u = reinterpret_cast<unsigned int *>(&x);
return ((u[0] & 0x7f800000) == 0x7f800000) && (u[0] & 0x007fffff);
}
//! checks double value for Nan
inline bool isNan(double x)
{
unsigned int *u = reinterpret_cast<unsigned int *>(&x);
return (u[1] & 0x7ff00000) == 0x7ff00000 && (u[0] != 0 || (u[1] & 0x000fffff) != 0);
}
//! checks vectors for Nans
template<typename _Tp, int cn> inline bool isNan(const Vec<_Tp, cn>& v)
{ return isNan(v.val[0]) || isNan(v.val[1]) || isNan(v.val[2]); }
//! checks point for Nans
template<typename _Tp> inline bool isNan(const Point3_<_Tp>& p)
{ return isNan(p.x) || isNan(p.y) || isNan(p.z); }
}
}

View File

@@ -1,113 +0,0 @@
#pragma once
#include <string>
#include <opencv2/viz/types.hpp>
namespace cv
{
namespace viz
{
class KeyboardEvent
{
public:
static const unsigned int Alt = 1;
static const unsigned int Ctrl = 2;
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
*/
KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift);
bool isAltPressed () const;
bool isCtrlPressed () const;
bool isShiftPressed () const;
unsigned char getKeyCode () const;
const String& getKeySym () const;
bool keyDown () const;
bool keyUp () const;
protected:
bool action_;
unsigned int modifiers_;
unsigned char key_code_;
String key_sym_;
};
class MouseEvent
{
public:
enum Type
{
MouseMove = 1,
MouseButtonPress,
MouseButtonRelease,
MouseScrollDown,
MouseScrollUp,
MouseDblClick
} ;
enum MouseButton
{
NoButton = 0,
LeftButton,
MiddleButton,
RightButton,
VScroll /*other buttons, scroll wheels etc. may follow*/
} ;
MouseEvent (const Type& type, const MouseButton& button, const Point& p, bool alt, bool ctrl, bool shift);
Type type;
MouseButton button;
Point pointer;
unsigned int key_state;
};
}
}
////////////////////////////////////////////////////////////////////
/// Implementation
inline cv::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)
modifiers_ = Alt;
if (ctrl)
modifiers_ |= Ctrl;
if (shift)
modifiers_ |= Shift;
}
inline bool cv::viz::KeyboardEvent::isAltPressed () const { return (modifiers_ & Alt) != 0; }
inline bool cv::viz::KeyboardEvent::isCtrlPressed () const { return (modifiers_ & Ctrl) != 0; }
inline bool cv::viz::KeyboardEvent::isShiftPressed () const { return (modifiers_ & Shift) != 0; }
inline unsigned char cv::viz::KeyboardEvent::getKeyCode () const { return key_code_; }
inline const cv::String& cv::viz::KeyboardEvent::getKeySym () const { return key_sym_; }
inline bool cv::viz::KeyboardEvent::keyDown () const { return action_; }
inline bool cv::viz::KeyboardEvent::keyUp () const { return !action_; }
inline cv::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)
key_state = KeyboardEvent::Alt;
if (ctrl)
key_state |= KeyboardEvent::Ctrl;
if (shift)
key_state |= KeyboardEvent::Shift;
}

View File

@@ -1,6 +1,6 @@
#pragma once
#include <vector>
#include <string>
#include <opencv2/core/cvdef.h>
#include <opencv2/core.hpp>
#include <opencv2/core/affine.hpp>
@@ -8,35 +8,7 @@
namespace cv
{
typedef std::string String;
// //qt creator hack
// typedef cv::Scalar Scalar;
// typedef cv::Mat Mat;
// typedef std::string String;
// typedef cv::Vec3d Vec3d;
// typedef cv::Vec3f Vec3f;
// typedef cv::Vec4d Vec4d;
// typedef cv::Vec4f Vec4f;
// typedef cv::Vec2d Vec2d;
// typedef cv::Vec2i Vec2i;
// typedef cv::Vec3b Vec3b;
// typedef cv::Matx33d Matx33d;
// typedef cv::Affine3f Affine3f;
// typedef cv::Affine3d Affine3d;
// typedef cv::Point2i Point2i;
// typedef cv::Point3f Point3f;
// typedef cv::Point3d Point3d;
// typedef cv::Matx44d Matx44d;
// typedef cv::Matx44f Matx44f;
// typedef cv::Size Size;
// typedef cv::Point Point;
// typedef cv::InputArray InputArray;
// using cv::Point3_;
// using cv::Vec;
// using cv::Mat_;
// using cv::DataDepth;
// using cv::DataType;
// using cv::Ptr;
namespace viz
{
class CV_EXPORTS Color : public Scalar
@@ -79,35 +51,58 @@ namespace cv
};
/////////////////////////////////////////////////////////////////////////////
/// Utility functions
inline Color vtkcolor(const Color& color)
class CV_EXPORTS KeyboardEvent
{
Color scaled_color = color * (1.0/255.0);
std::swap(scaled_color[0], scaled_color[2]);
return scaled_color;
}
public:
static const unsigned int Alt = 1;
static const unsigned int Ctrl = 2;
static const unsigned int Shift = 4;
inline Vec3d vtkpoint(const Point3f& point) { return Vec3d(point.x, point.y, point.z); }
template<typename _Tp> inline _Tp normalized(const _Tp& v) { return v * 1/cv::norm(v); }
/** \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
*/
KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift);
inline bool isNan(float x)
bool isAltPressed () const;
bool isCtrlPressed () const;
bool isShiftPressed () const;
unsigned char getKeyCode () const;
const String& getKeySym () const;
bool keyDown () const;
bool keyUp () const;
protected:
bool action_;
unsigned int modifiers_;
unsigned char key_code_;
String key_sym_;
};
class CV_EXPORTS MouseEvent
{
unsigned int *u = reinterpret_cast<unsigned int *>(&x);
return ((u[0] & 0x7f800000) == 0x7f800000) && (u[0] & 0x007fffff);
}
public:
enum Type { MouseMove = 1, MouseButtonPress, MouseButtonRelease, MouseScrollDown, MouseScrollUp, MouseDblClick } ;
enum MouseButton { NoButton = 0, LeftButton, MiddleButton, RightButton, VScroll } ;
MouseEvent (const Type& type, const MouseButton& button, const Point& p, bool alt, bool ctrl, bool shift);
Type type;
MouseButton button;
Point pointer;
unsigned int key_state;
};
} /* namespace viz */
} /* namespace cv */
inline bool isNan(double x)
{
unsigned int *u = reinterpret_cast<unsigned int *>(&x);
return (u[1] & 0x7ff00000) == 0x7ff00000 && (u[0] != 0 || (u[1] & 0x000fffff) != 0);
}
template<typename _Tp, int cn> inline bool isNan(const Vec<_Tp, cn>& v)
{ return isNan(v.val[0]) || isNan(v.val[1]) || isNan(v.val[2]); }
template<typename _Tp> inline bool isNan(const Point3_<_Tp>& p)
{ return isNan(p.x) || isNan(p.y) || isNan(p.z); }
}
}

View File

@@ -4,14 +4,9 @@
//#error "Viz is in beta state now. Please define macro above to use it"
#endif
#include <opencv2/core/cvdef.h>
#include <opencv2/core.hpp>
#include <string>
#include <opencv2/viz/types.hpp>
#include <opencv2/viz/widgets.hpp>
#include <opencv2/viz/events.hpp>
namespace cv
{
@@ -20,28 +15,21 @@ namespace cv
class CV_EXPORTS Viz3d
{
public:
typedef cv::Ptr<Viz3d> Ptr;
typedef void (*KeyboardCallback)(const KeyboardEvent&, void*);
typedef void (*MouseCallback)(const MouseEvent&, void*);
Viz3d(const String& window_name = String());
~Viz3d();
void setBackgroundColor(const Color& color = Color::black());
bool addPolygonMesh (const Mesh3d& mesh, const String& id = "polygon");
bool updatePolygonMesh (const Mesh3d& mesh, const String& id = "polygon");
//to refactor
bool addPolygonMesh(const Mesh3d& mesh, const String& id = "polygon");
bool updatePolygonMesh(const Mesh3d& mesh, const String& id = "polygon");
bool addPolylineFromPolygonMesh (const Mesh3d& mesh, const String& id = "polyline");
bool addPolygon(const Mat& cloud, const Color& color, const String& id = "polygon");
void spin ();
void spinOnce (int time = 1, bool force_redraw = false);
void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void* cookie = 0);
void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
bool wasStopped() const;
void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity());
void removeWidget(const String &id);
@@ -50,6 +38,13 @@ namespace cv
void setWidgetPose(const String &id, const Affine3f &pose);
void updateWidgetPose(const String &id, const Affine3f &pose);
Affine3f getWidgetPose(const String &id) const;
void spin();
void spinOnce(int time = 1, bool force_redraw = false);
bool wasStopped() const;
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
void registerMouseCallback(MouseCallback callback, void* cookie = 0);
private:
Viz3d(const Viz3d&);
Viz3d& operator=(const Viz3d&);
@@ -57,8 +52,9 @@ namespace cv
struct VizImpl;
VizImpl* impl_;
};
}
}
} /* namespace viz */
} /* namespace cv */