First version of 'viz' module
This commit is contained in:
3
modules/viz/include/opencv2/viz.hpp
Normal file
3
modules/viz/include/opencv2/viz.hpp
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include <opencv2/viz/viz3d.hpp>
|
110
modules/viz/include/opencv2/viz/events.hpp
Normal file
110
modules/viz/include/opencv2/viz/events.hpp
Normal file
@@ -0,0 +1,110 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <opencv2/viz/types.hpp>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
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 std::string& getKeySym () const;
|
||||
bool keyDown () const;
|
||||
bool keyUp () const;
|
||||
|
||||
protected:
|
||||
|
||||
bool action_;
|
||||
unsigned int modifiers_;
|
||||
unsigned char key_code_;
|
||||
std::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::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::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 cv::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;
|
||||
}
|
10
modules/viz/include/opencv2/viz/mesh_load.hpp
Normal file
10
modules/viz/include/opencv2/viz/mesh_load.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/viz/types.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace temp_viz
|
||||
{
|
||||
CV_EXPORTS Mesh3d::Ptr mesh_load(const String& file);
|
||||
}
|
84
modules/viz/include/opencv2/viz/types.hpp
Normal file
84
modules/viz/include/opencv2/viz/types.hpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <opencv2/core/cvdef.h>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/core/affine.hpp>
|
||||
|
||||
namespace temp_viz
|
||||
{
|
||||
//qt creator hack
|
||||
typedef cv::Scalar Scalar;
|
||||
typedef cv::Mat Mat;
|
||||
typedef std::string String;
|
||||
|
||||
typedef cv::Vec3d Vec3d;
|
||||
typedef cv::Vec4d Vec4d;
|
||||
typedef cv::Vec2d Vec2d;
|
||||
typedef cv::Vec2i Vec2i;
|
||||
typedef cv::Matx33d Matx33d;
|
||||
typedef cv::Affine3f Affine3f;
|
||||
typedef cv::Affine3d Affine3d;
|
||||
typedef cv::Point3f Point3f;
|
||||
typedef cv::Matx44d Matx44d;
|
||||
typedef cv::Matx44f Matx44f;
|
||||
typedef cv::Size Size;
|
||||
typedef cv::Point Point;
|
||||
|
||||
|
||||
|
||||
struct CV_EXPORTS ModelCoefficients
|
||||
{
|
||||
std::vector<float> values;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS Color : public Scalar
|
||||
{
|
||||
public:
|
||||
Color();
|
||||
Color(double gray);
|
||||
Color(double blue, double green, double red);
|
||||
|
||||
Color(const Scalar& color);
|
||||
|
||||
static Color black();
|
||||
static Color blue();
|
||||
static Color green();
|
||||
static Color cyan();
|
||||
|
||||
static Color red();
|
||||
static Color magenta();
|
||||
static Color yellow();
|
||||
static Color white();
|
||||
|
||||
static Color gray();
|
||||
};
|
||||
|
||||
|
||||
struct CV_EXPORTS Vertices
|
||||
{
|
||||
std::vector<unsigned int> vertices;
|
||||
};
|
||||
|
||||
class CV_EXPORTS Mesh3d
|
||||
{
|
||||
public:
|
||||
typedef cv::Ptr<Mesh3d> Ptr;
|
||||
|
||||
Mat cloud, colors;
|
||||
std::vector<Vertices> polygons;
|
||||
};
|
||||
|
||||
|
||||
inline Color vtkcolor(const Color& color)
|
||||
{
|
||||
Color scaled_color = color * (1.0/255.0);
|
||||
std::swap(scaled_color[0], scaled_color[2]);
|
||||
return scaled_color;
|
||||
}
|
||||
|
||||
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); }
|
||||
}
|
71
modules/viz/include/opencv2/viz/viz3d.hpp
Normal file
71
modules/viz/include/opencv2/viz/viz3d.hpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
#if !defined YES_I_AGREE_THAT_VIZ_API_IS_NOT_STABLE_NOW_AND_BINARY_COMPARTIBILITY_WONT_BE_SUPPORTED
|
||||
//#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>
|
||||
|
||||
namespace temp_viz
|
||||
{
|
||||
class CV_EXPORTS Viz3d
|
||||
{
|
||||
public:
|
||||
|
||||
typedef cv::Ptr<Viz3d> Ptr;
|
||||
|
||||
Viz3d(const String& window_name = String());
|
||||
~Viz3d();
|
||||
|
||||
void setBackgroundColor(const Color& color = Color::black());
|
||||
|
||||
void addCoordinateSystem(double scale, const Affine3f& t, const String &id = "coordinate");
|
||||
|
||||
void addPointCloud(const Mat& cloud, const Mat& colors, const String& id = "cloud", const Mat& mask = Mat());
|
||||
|
||||
bool addPointCloudNormals (const Mat &cloud, const Mat& normals, int level = 100, float scale = 0.02f, const String &id = "cloud");
|
||||
|
||||
|
||||
|
||||
|
||||
bool addPlane (const ModelCoefficients &coefficients, const String &id = "plane");
|
||||
bool addPlane (const ModelCoefficients &coefficients, double x, double y, double z, const String &id = "plane");
|
||||
bool removeCoordinateSystem (const String &id = "coordinate");
|
||||
|
||||
|
||||
bool updatePointCloud (const Mat& cloud, const Mat& colors, const String& id = "cloud", const Mat& mask = Mat());
|
||||
|
||||
|
||||
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 addText (const String &text, int xpos, int ypos, const Color& color, int fontsize = 10, const String &id = "");
|
||||
|
||||
|
||||
bool addPolygon(const Mat& cloud, const Color& color, const String &id = "polygon");
|
||||
|
||||
bool addSphere (const Point3f ¢er, double radius, const Color& color, const String &id = "sphere");
|
||||
|
||||
|
||||
void spin ();
|
||||
void spinOnce (int time = 1, bool force_redraw = false);
|
||||
|
||||
private:
|
||||
Viz3d(const Viz3d&);
|
||||
Viz3d& operator=(const Viz3d&);
|
||||
|
||||
struct VizImpl;
|
||||
VizImpl* impl_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user