Commit d324c03b authored by ozantonkal's avatar ozantonkal

initial redesigning widgets

parent 061c28cd
...@@ -13,5 +13,6 @@ namespace temp_viz ...@@ -13,5 +13,6 @@ namespace temp_viz
struct CV_EXPORTS WidgetAccessor struct CV_EXPORTS WidgetAccessor
{ {
static vtkSmartPointer<vtkProp> getActor(const Widget &widget); static vtkSmartPointer<vtkProp> getActor(const Widget &widget);
static void setVtkProp(Widget &widget, vtkSmartPointer<vtkProp> actor);
}; };
} }
...@@ -13,32 +13,44 @@ namespace temp_viz ...@@ -13,32 +13,44 @@ namespace temp_viz
Widget(); Widget();
Widget(const Widget &other); Widget(const Widget &other);
Widget& operator =(const Widget &other); Widget& operator =(const Widget &other);
~Widget(); ~Widget();
void copyTo(Widget &dst); private:
class Impl;
void setColor(const Color &color); Impl *impl_;
friend struct WidgetAccessor;
};
/////////////////////////////////////////////////////////////////////////////
/// The base class for all 3D widgets
class CV_EXPORTS Widget3D : public Widget
{
public:
Widget3D();
void setPose(const Affine3f &pose); void setPose(const Affine3f &pose);
void updatePose(const Affine3f &pose); void updatePose(const Affine3f &pose);
Affine3f getPose() const; Affine3f getPose() const;
protected: void setColor(const Color &color);
Widget(bool text_widget);
private: private:
class Impl; struct MatrixConverter;
Impl* impl_;
void create();
void release();
void create(bool text_widget);
friend struct WidgetAccessor;
}; };
/////////////////////////////////////////////////////////////////////////////
/// The base class for all 2D widgets
class CV_EXPORTS Widget2D : public Widget
{
public:
Widget2D();
};
class CV_EXPORTS LineWidget : public Widget3D
class CV_EXPORTS LineWidget : public Widget
{ {
public: public:
LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white()); LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white());
...@@ -47,58 +59,56 @@ namespace temp_viz ...@@ -47,58 +59,56 @@ namespace temp_viz
float getLineWidth(); float getLineWidth();
}; };
class CV_EXPORTS PlaneWidget : public Widget class CV_EXPORTS PlaneWidget : public Widget3D
{ {
public: public:
PlaneWidget(const Vec4f& coefs, double size = 1.0, const Color &color = Color::white()); PlaneWidget(const Vec4f& coefs, double size = 1.0, const Color &color = Color::white());
PlaneWidget(const Vec4f& coefs, const Point3f& pt, double size = 1.0, const Color &color = Color::white()); PlaneWidget(const Vec4f& coefs, const Point3f& pt, double size = 1.0, const Color &color = Color::white());
}; };
class CV_EXPORTS SphereWidget : public Widget class CV_EXPORTS SphereWidget : public Widget3D
{ {
public: public:
SphereWidget(const cv::Point3f &center, float radius, int sphere_resolution = 10, const Color &color = Color::white()); SphereWidget(const cv::Point3f &center, float radius, int sphere_resolution = 10, const Color &color = Color::white());
}; };
class CV_EXPORTS ArrowWidget : public Widget class CV_EXPORTS ArrowWidget : public Widget3D
{ {
public: public:
ArrowWidget(const Point3f& pt1, const Point3f& pt2, const Color &color = Color::white()); ArrowWidget(const Point3f& pt1, const Point3f& pt2, const Color &color = Color::white());
}; };
class CV_EXPORTS CircleWidget : public Widget class CV_EXPORTS CircleWidget : public Widget3D
{ {
public: public:
CircleWidget(const Point3f& pt, double radius, double thickness = 0.01, const Color &color = Color::white()); CircleWidget(const Point3f& pt, double radius, double thickness = 0.01, const Color &color = Color::white());
}; };
class CV_EXPORTS CylinderWidget : public Widget class CV_EXPORTS CylinderWidget : public Widget3D
{ {
public: public:
CylinderWidget(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides = 30, const Color &color = Color::white()); CylinderWidget(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides = 30, const Color &color = Color::white());
}; };
class CV_EXPORTS CubeWidget : public Widget class CV_EXPORTS CubeWidget : public Widget3D
{ {
public: public:
CubeWidget(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame = true, const Color &color = Color::white()); CubeWidget(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame = true, const Color &color = Color::white());
}; };
class CV_EXPORTS CoordinateSystemWidget : public Widget class CV_EXPORTS CoordinateSystemWidget : public Widget3D
{ {
public: public:
CoordinateSystemWidget(double scale, const Affine3f& affine); CoordinateSystemWidget(double scale, const Affine3f& affine);
}; };
class CV_EXPORTS TextWidget : public Widget class CV_EXPORTS TextWidget : public Widget2D
{ {
public: public:
TextWidget(const String &text, const Point2i &pos, int font_size = 10, const Color &color = Color::white()); TextWidget(const String &text, const Point2i &pos, int font_size = 10, const Color &color = Color::white());
// TODO Overload setColor method, and hide setPose, updatePose, getPose methods
}; };
class CV_EXPORTS CloudWidget : public Widget class CV_EXPORTS CloudWidget : public Widget3D
{ {
public: public:
CloudWidget(InputArray _cloud, InputArray _colors); CloudWidget(InputArray _cloud, InputArray _colors);
...@@ -107,7 +117,7 @@ namespace temp_viz ...@@ -107,7 +117,7 @@ namespace temp_viz
struct CreateCloudWidget; struct CreateCloudWidget;
}; };
class CV_EXPORTS CloudNormalsWidget : public Widget class CV_EXPORTS CloudNormalsWidget : public Widget3D
{ {
public: public:
CloudNormalsWidget(InputArray _cloud, InputArray _normals, int level = 100, float scale = 0.02f, const Color &color = Color::white()); CloudNormalsWidget(InputArray _cloud, InputArray _normals, int level = 100, float scale = 0.02f, const Color &color = Color::white());
......
...@@ -9,6 +9,8 @@ namespace temp_viz ...@@ -9,6 +9,8 @@ namespace temp_viz
/// line widget implementation /// line widget implementation
temp_viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color) temp_viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color)
{ {
WidgetAccessor::setVtkProp(*this, vtkSmartPointer<vtkLODActor>::New());
vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New(); vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New();
line->SetPoint1 (pt1.x, pt1.y, pt1.z); line->SetPoint1 (pt1.x, pt1.y, pt1.z);
line->SetPoint2 (pt2.x, pt2.y, pt2.z); line->SetPoint2 (pt2.x, pt2.y, pt2.z);
...@@ -40,6 +42,8 @@ float temp_viz::LineWidget::getLineWidth() ...@@ -40,6 +42,8 @@ float temp_viz::LineWidget::getLineWidth()
temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, double size, const Color &color) temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, double size, const Color &color)
{ {
WidgetAccessor::setVtkProp(*this, vtkSmartPointer<vtkLODActor>::New());
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New (); vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New ();
plane->SetNormal (coefs[0], coefs[1], coefs[2]); plane->SetNormal (coefs[0], coefs[1], coefs[2]);
double norm = cv::norm(cv::Vec3f(coefs.val)); double norm = cv::norm(cv::Vec3f(coefs.val));
...@@ -57,6 +61,8 @@ temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, double size, const Color ...@@ -57,6 +61,8 @@ temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, double size, const Color
temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, const Point3f& pt, double size, const Color &color) temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, const Point3f& pt, double size, const Color &color)
{ {
WidgetAccessor::setVtkProp(*this, vtkSmartPointer<vtkLODActor>::New());
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New (); vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New ();
cv::Point3f coefs3(coefs[0], coefs[1], coefs[2]); cv::Point3f coefs3(coefs[0], coefs[1], coefs[2]);
double norm_sqr = 1.0 / coefs3.dot (coefs3); double norm_sqr = 1.0 / coefs3.dot (coefs3);
...@@ -81,6 +87,8 @@ temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, const Point3f& pt, double ...@@ -81,6 +87,8 @@ temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, const Point3f& pt, double
temp_viz::SphereWidget::SphereWidget(const cv::Point3f &center, float radius, int sphere_resolution, const Color &color) temp_viz::SphereWidget::SphereWidget(const cv::Point3f &center, float radius, int sphere_resolution, const Color &color)
{ {
WidgetAccessor::setVtkProp(*this, vtkSmartPointer<vtkLODActor>::New());
vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New (); vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New ();
sphere->SetRadius (radius); sphere->SetRadius (radius);
sphere->SetCenter (center.x, center.y, center.z); sphere->SetCenter (center.x, center.y, center.z);
...@@ -103,6 +111,8 @@ temp_viz::SphereWidget::SphereWidget(const cv::Point3f &center, float radius, in ...@@ -103,6 +111,8 @@ temp_viz::SphereWidget::SphereWidget(const cv::Point3f &center, float radius, in
temp_viz::ArrowWidget::ArrowWidget(const Point3f& pt1, const Point3f& pt2, const Color &color) temp_viz::ArrowWidget::ArrowWidget(const Point3f& pt1, const Point3f& pt2, const Color &color)
{ {
WidgetAccessor::setVtkProp(*this, vtkSmartPointer<vtkLODActor>::New());
vtkSmartPointer<vtkArrowSource> arrowSource = vtkSmartPointer<vtkArrowSource>::New (); vtkSmartPointer<vtkArrowSource> arrowSource = vtkSmartPointer<vtkArrowSource>::New ();
float startPoint[3], endPoint[3]; float startPoint[3], endPoint[3];
...@@ -165,6 +175,8 @@ temp_viz::ArrowWidget::ArrowWidget(const Point3f& pt1, const Point3f& pt2, const ...@@ -165,6 +175,8 @@ temp_viz::ArrowWidget::ArrowWidget(const Point3f& pt1, const Point3f& pt2, const
temp_viz::CircleWidget::CircleWidget(const temp_viz::Point3f& pt, double radius, double thickness, const temp_viz::Color& color) temp_viz::CircleWidget::CircleWidget(const temp_viz::Point3f& pt, double radius, double thickness, const temp_viz::Color& color)
{ {
WidgetAccessor::setVtkProp(*this, vtkSmartPointer<vtkLODActor>::New());
vtkSmartPointer<vtkDiskSource> disk = vtkSmartPointer<vtkDiskSource>::New (); vtkSmartPointer<vtkDiskSource> disk = vtkSmartPointer<vtkDiskSource>::New ();
// Maybe the resolution should be lower e.g. 50 or 25 // Maybe the resolution should be lower e.g. 50 or 25
disk->SetCircumferentialResolution (50); disk->SetCircumferentialResolution (50);
...@@ -194,6 +206,8 @@ temp_viz::CircleWidget::CircleWidget(const temp_viz::Point3f& pt, double radius, ...@@ -194,6 +206,8 @@ temp_viz::CircleWidget::CircleWidget(const temp_viz::Point3f& pt, double radius,
temp_viz::CylinderWidget::CylinderWidget(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides, const Color &color) temp_viz::CylinderWidget::CylinderWidget(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides, const Color &color)
{ {
WidgetAccessor::setVtkProp(*this, vtkSmartPointer<vtkLODActor>::New());
const cv::Point3f pt2 = pt_on_axis + axis_direction; const cv::Point3f pt2 = pt_on_axis + axis_direction;
vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New (); vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New ();
line->SetPoint1 (pt_on_axis.x, pt_on_axis.y, pt_on_axis.z); line->SetPoint1 (pt_on_axis.x, pt_on_axis.y, pt_on_axis.z);
...@@ -218,6 +232,8 @@ temp_viz::CylinderWidget::CylinderWidget(const Point3f& pt_on_axis, const Point3 ...@@ -218,6 +232,8 @@ temp_viz::CylinderWidget::CylinderWidget(const Point3f& pt_on_axis, const Point3
temp_viz::CubeWidget::CubeWidget(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame, const Color &color) temp_viz::CubeWidget::CubeWidget(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame, const Color &color)
{ {
WidgetAccessor::setVtkProp(*this, vtkSmartPointer<vtkLODActor>::New());
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New (); vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New ();
cube->SetBounds (pt_min.x, pt_max.x, pt_min.y, pt_max.y, pt_min.z, pt_max.z); cube->SetBounds (pt_min.x, pt_max.x, pt_min.y, pt_max.y, pt_min.z, pt_max.z);
...@@ -238,6 +254,8 @@ temp_viz::CubeWidget::CubeWidget(const Point3f& pt_min, const Point3f& pt_max, b ...@@ -238,6 +254,8 @@ temp_viz::CubeWidget::CubeWidget(const Point3f& pt_min, const Point3f& pt_max, b
temp_viz::CoordinateSystemWidget::CoordinateSystemWidget(double scale, const Affine3f& affine) temp_viz::CoordinateSystemWidget::CoordinateSystemWidget(double scale, const Affine3f& affine)
{ {
WidgetAccessor::setVtkProp(*this, vtkSmartPointer<vtkLODActor>::New());
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New (); vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New ();
axes->SetOrigin (0, 0, 0); axes->SetOrigin (0, 0, 0);
axes->SetScaleFactor (scale); axes->SetScaleFactor (scale);
...@@ -285,8 +303,10 @@ temp_viz::CoordinateSystemWidget::CoordinateSystemWidget(double scale, const Aff ...@@ -285,8 +303,10 @@ temp_viz::CoordinateSystemWidget::CoordinateSystemWidget(double scale, const Aff
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
/// text widget implementation /// text widget implementation
temp_viz::TextWidget::TextWidget(const String &text, const Point2i &pos, int font_size, const Color &color) : Widget(true) temp_viz::TextWidget::TextWidget(const String &text, const Point2i &pos, int font_size, const Color &color)
{ {
WidgetAccessor::setVtkProp(*this, vtkSmartPointer<vtkTextActor>::New());
vtkTextActor *actor = vtkTextActor::SafeDownCast(WidgetAccessor::getActor(*this)); vtkTextActor *actor = vtkTextActor::SafeDownCast(WidgetAccessor::getActor(*this));
actor->SetPosition (pos.x, pos.y); actor->SetPosition (pos.x, pos.y);
actor->SetInput (text.c_str ()); actor->SetInput (text.c_str ());
...@@ -400,6 +420,8 @@ temp_viz::CloudWidget::CloudWidget(InputArray _cloud, InputArray _colors) ...@@ -400,6 +420,8 @@ temp_viz::CloudWidget::CloudWidget(InputArray _cloud, InputArray _colors)
CV_Assert(cloud.type() == CV_32FC3 || cloud.type() == CV_64FC3 || cloud.type() == CV_32FC4 || cloud.type() == CV_64FC4); CV_Assert(cloud.type() == CV_32FC3 || cloud.type() == CV_64FC3 || cloud.type() == CV_32FC4 || cloud.type() == CV_64FC4);
CV_Assert(colors.type() == CV_8UC3 && cloud.size() == colors.size()); CV_Assert(colors.type() == CV_8UC3 && cloud.size() == colors.size());
WidgetAccessor::setVtkProp(*this, vtkSmartPointer<vtkLODActor>::New());
vtkLODActor * actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this)); vtkLODActor * actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this));
vtkIdType nr_points; vtkIdType nr_points;
vtkSmartPointer<vtkPolyData> polydata = CreateCloudWidget::create(cloud, nr_points); vtkSmartPointer<vtkPolyData> polydata = CreateCloudWidget::create(cloud, nr_points);
...@@ -441,6 +463,8 @@ temp_viz::CloudWidget::CloudWidget(InputArray _cloud, const Color &color) ...@@ -441,6 +463,8 @@ temp_viz::CloudWidget::CloudWidget(InputArray _cloud, const Color &color)
Mat cloud = _cloud.getMat(); Mat cloud = _cloud.getMat();
CV_Assert(cloud.type() == CV_32FC3 || cloud.type() == CV_64FC3 || cloud.type() == CV_32FC4 || cloud.type() == CV_64FC4); CV_Assert(cloud.type() == CV_32FC3 || cloud.type() == CV_64FC3 || cloud.type() == CV_32FC4 || cloud.type() == CV_64FC4);
WidgetAccessor::setVtkProp(*this, vtkSmartPointer<vtkLODActor>::New());
vtkLODActor * actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this)); vtkLODActor * actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this));
vtkIdType nr_points; vtkIdType nr_points;
vtkSmartPointer<vtkPolyData> polydata = CreateCloudWidget::create(cloud, nr_points); vtkSmartPointer<vtkPolyData> polydata = CreateCloudWidget::create(cloud, nr_points);
...@@ -551,6 +575,8 @@ temp_viz::CloudNormalsWidget::CloudNormalsWidget(InputArray _cloud, InputArray _ ...@@ -551,6 +575,8 @@ temp_viz::CloudNormalsWidget::CloudNormalsWidget(InputArray _cloud, InputArray _
CV_Assert(cloud.type() == CV_32FC3 || cloud.type() == CV_64FC3 || cloud.type() == CV_32FC4 || cloud.type() == CV_64FC4); CV_Assert(cloud.type() == CV_32FC3 || cloud.type() == CV_64FC3 || cloud.type() == CV_32FC4 || cloud.type() == CV_64FC4);
CV_Assert(cloud.size() == normals.size() && cloud.type() == normals.type()); CV_Assert(cloud.size() == normals.size() && cloud.type() == normals.type());
WidgetAccessor::setVtkProp(*this, vtkSmartPointer<vtkLODActor>::New());
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New(); vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
vtkIdType nr_normals = 0; vtkIdType nr_normals = 0;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment