From f07486b563d92bf1864992eec5342bad4cd77de3 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Thu, 4 Jul 2013 17:44:41 +0300 Subject: [PATCH] cylinder widget implementation --- modules/viz/include/opencv2/viz/widgets.hpp | 6 +++++ modules/viz/src/simple_widgets.cpp | 25 ++++++++++++++++++++- modules/viz/test/test_viz3d.cpp | 6 ++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index 3535f486a..a731dcf93 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -67,5 +67,11 @@ namespace temp_viz public: CircleWidget(const Point3f& pt, double radius, const Color &color = Color::white()); }; + + class CV_EXPORTS CylinderWidget : public Widget + { + public: + CylinderWidget(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides = 30, const Color &color = Color::white()); + }; } diff --git a/modules/viz/src/simple_widgets.cpp b/modules/viz/src/simple_widgets.cpp index 51edc9b13..36b22d99d 100644 --- a/modules/viz/src/simple_widgets.cpp +++ b/modules/viz/src/simple_widgets.cpp @@ -158,7 +158,7 @@ temp_viz::ArrowWidget::ArrowWidget(const Point3f& pt1, const Point3f& pt2, const /////////////////////////////////////////////////////////////////////////////////////////////// /// circle widget implementation -temp_viz::CircleWidget::CircleWidget(const Point3f& pt, double radius, const Color &color) +temp_viz::CircleWidget::CircleWidget(const temp_viz::Point3f& pt, double radius, const temp_viz::Color& color) { vtkSmartPointer disk = vtkSmartPointer::New (); // Maybe the resolution should be lower e.g. 50 or 25 @@ -185,3 +185,26 @@ temp_viz::CircleWidget::CircleWidget(const Point3f& pt, double radius, const Col setColor(color); } +/////////////////////////////////////////////////////////////////////////////////////////////// +/// cylinder widget implementation + +temp_viz::CylinderWidget::CylinderWidget(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides, const Color &color) +{ + const cv::Point3f pt2 = pt_on_axis + axis_direction; + vtkSmartPointer line = vtkSmartPointer::New (); + line->SetPoint1 (pt_on_axis.x, pt_on_axis.y, pt_on_axis.z); + line->SetPoint2 (pt2.x, pt2.y, pt2.z); + + vtkSmartPointer tuber = vtkSmartPointer::New (); + tuber->SetInputConnection (line->GetOutputPort ()); + tuber->SetRadius (radius); + tuber->SetNumberOfSides (numsides); + + vtkSmartPointer mapper = vtkSmartPointer::New (); + mapper->SetInput(tuber->GetOutput ()); + + vtkSmartPointer actor = WidgetAccessor::getActor(*this); + actor->SetMapper(mapper); + + setColor(color); +} diff --git a/modules/viz/test/test_viz3d.cpp b/modules/viz/test/test_viz3d.cpp index 55e590e16..66a78b1b3 100644 --- a/modules/viz/test/test_viz3d.cpp +++ b/modules/viz/test/test_viz3d.cpp @@ -92,17 +92,19 @@ TEST(Viz_viz3d, accuracy) int col_green = 0; int col_red = 0; // v.showCircle("circle1", cv::Point3f(0,0,0), 1.0, temp_viz::Color(0,255,0)); - temp_viz::LineWidget lw(cv::Point3f(0.0,0.0,0.0), cv::Point3f(1.0,1.0,1.0), temp_viz::Color(0,255,0)); + temp_viz::LineWidget lw(cv::Point3f(0.0,0.0,0.0), cv::Point3f(4.0,4.0,4.0), temp_viz::Color(0,255,0)); temp_viz::PlaneWidget pw(cv::Vec4f(0.0,1.0,2.0,3.0)); temp_viz::SphereWidget sw(cv::Point3f(0,0,0), 0.5); temp_viz::ArrowWidget aw(cv::Point3f(0,0,0), cv::Point3f(1,1,1), temp_viz::Color(255,0,0)); temp_viz::CircleWidget cw(cv::Point3f(0,0,0), 1.0, temp_viz::Color(0,255,0)); + temp_viz::CylinderWidget cyw(cv::Point3f(0,0,0), cv::Point3f(-1,-1,-1), 0.5, 30, temp_viz::Color(0,255,0)); v.showWidget("line", lw); v.showWidget("plane", pw); v.showWidget("sphere", sw); v.showWidget("arrow", aw); v.showWidget("circle", cw); + v.showWidget("cylinder", cyw); temp_viz::LineWidget lw2 = lw; @@ -128,6 +130,8 @@ TEST(Viz_viz3d, accuracy) pw.setPose(cloudPosition); aw.setPose(cloudPosition); cw.setPose(cloudPosition); + cyw.setPose(cloudPosition); + lw.setPose(cloudPosition); angle_x += 0.1f; angle_y -= 0.1f;