slight refactoring of widget system code

This commit is contained in:
Anatoly Baksheev
2013-07-04 13:54:00 +04:00
parent daa2a205a4
commit efa7f09048
12 changed files with 195 additions and 180 deletions

View File

@@ -1,3 +1,6 @@
#pragma once
#include <opencv2/viz/types.hpp>
#include <opencv2/viz/widgets.hpp>
#include <opencv2/viz/viz3d.hpp>

View File

@@ -36,8 +36,6 @@ namespace temp_viz
using cv::DataType;
struct CV_EXPORTS ModelCoefficients
{
std::vector<float> values;
@@ -81,6 +79,8 @@ namespace temp_viz
std::vector<Vertices> polygons;
};
/////////////////////////////////////////////////////////////////////////////
/// Utility functions
inline Color vtkcolor(const Color& color)
{
@@ -90,11 +90,7 @@ namespace temp_viz
}
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); }
inline bool isNan(float x)
{
@@ -113,30 +109,4 @@ namespace temp_viz
template<typename _Tp> inline bool isNan(const Point3_<_Tp>& p)
{ return isNan(p.x) || isNan(p.y) || isNan(p.z); }
class Widget
{
public:
Widget();
Widget(const Widget &other);
Widget& operator =(const Widget &other);
void copyTo(Widget &dst);
void setColor(const Color &color);
void setPose(const Affine3f &pose);
void updatePose(const Affine3f &pose);
Affine3f getPose() const;
private:
class Impl;
cv::Ptr<Impl> impl_;
friend struct WidgetAccessor;
};
class LineWidget : public Widget
{
public:
LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color(255,255,255));
};
}

View File

@@ -10,6 +10,7 @@
#include <string>
#include <opencv2/viz/types.hpp>
#include <opencv2/viz/widgets.hpp>
#include <opencv2/viz/events.hpp>
namespace temp_viz
@@ -33,8 +34,8 @@ namespace temp_viz
bool addPointCloudNormals (const Mat &cloud, const Mat& normals, int level = 100, float scale = 0.02f, const String& id = "cloud");
void showLine(const String& id, const Point3f& pt1, const Point3f& pt2, const Color& color = Color::white());
void showPlane(const String& id, const Vec4f& coefs, const Color& color = Color::white());
void showPlane(const String& id, const Vec4f& coefs, const Point3f& pt, const Color& color = Color::white());
void showPlane(const String& id, const Vec4f& coeffs, const Color& color = Color::white());
void showPlane(const String& id, const Vec4f& coeffs, const Point3f& pt, const Color& color = Color::white());
void showCube(const String& id, const Point3f& pt1, const Point3f& pt2, const Color& color = Color::white());
void showCylinder(const String& id, const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int num_sides, const Color& color = Color::white());
void showCircle(const String& id, const Point3f& pt, double radius, const Color& color = Color::white());

View File

@@ -1,11 +1,15 @@
#pragma once
#include <opencv2/viz/types.hpp>
#include <opencv2/viz/widgets.hpp>
#include <vtkSmartPointer.h>
#include <vtkLODActor.h>
namespace temp_viz
{
struct WidgetAccessor
//The class is only that depends on VTK in its interface.
//It is indended for those user who want to develop own widgets system using VTK library API.
struct CV_EXPORTS WidgetAccessor
{
static CV_EXPORTS vtkSmartPointer<vtkLODActor> getActor(const Widget &widget);
static vtkSmartPointer<vtkLODActor> getActor(const Widget &widget);
};
}
}

View File

@@ -0,0 +1,38 @@
#pragma once
#include <opencv2/viz/types.hpp>
namespace temp_viz
{
/////////////////////////////////////////////////////////////////////////////
/// brief The base class for all widgets
class CV_EXPORTS Widget
{
public:
Widget();
Widget(const Widget &other);
Widget& operator =(const Widget &other);
void copyTo(Widget &dst);
void setColor(const Color &color);
void setPose(const Affine3f &pose);
void updatePose(const Affine3f &pose);
Affine3f getPose() const;
private:
class Impl;
cv::Ptr<Impl> impl_;
friend struct WidgetAccessor;
};
class CV_EXPORTS LineWidget : public Widget
{
public:
LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white());
};
}