From 658f4a7d386cb2fd421494921944c592960ebd87 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sun, 12 Jan 2014 14:58:22 +0400 Subject: [PATCH] refactoed plane --- modules/viz/doc/widget.rst | 25 ++++++++++------- modules/viz/include/opencv2/viz/widgets.hpp | 7 +++-- modules/viz/src/shapes.cpp | 30 +++++++++++++++++++++ modules/viz/test/tests_simple.cpp | 6 +++-- 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/modules/viz/doc/widget.rst b/modules/viz/doc/widget.rst index 5b72adbd59..bec5188a32 100644 --- a/modules/viz/doc/widget.rst +++ b/modules/viz/doc/widget.rst @@ -274,25 +274,30 @@ This 3D Widget defines a finite plane. :: class CV_EXPORTS WPlane : public Widget3D { public: - WPlane(const Vec4d& coefs, double size = 1.0, const Color &color = Color::white()); - WPlane(const Vec4d& coefs, const Point3f& pt, double size = 1.0, const Color &color = Color::white()); + //! created default plane with center point at origin and normal oriented along z-axis + WPlane(const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()); + + //! repositioned plane + WPlane(const Point3d& center, const Vec3d& normal, const Vec3d& new_plane_yaxis,const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()); }; viz::WPlane::WPlane ------------------- -Constructs a WPlane. +Constructs a default plane with center point at origin and normal oriented along z-axis. -.. ocv:function:: WPlane(const Vec4d& coefs, double size = 1.0, const Color &color = Color::white()) +.. ocv:function:: WPlane(const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()); - :param coefs: Plane coefficients as in (A,B,C,D) where Ax + By + Cz + D = 0. - :param size: Size of the plane. + :param size: Size of the plane :param color: :ocv:class:`Color` of the plane. -.. ocv:function:: WPlane(const Vec4d& coefs, const Point3f& pt, double size = 1.0, const Color &color = Color::white()) +viz::WPlane::WPlane +Constructs a repositioned plane + +.. ocv:function:: WPlane(const Point3d& center, const Vec3d& normal, const Vec3d& new_plane_yaxis,const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()); - :param coefs: Plane coefficients as in (A,B,C,D) where Ax + By + Cz + D = 0. - :param pt: Position of the plane. - :param size: Size of the plane. + :param center: Center of the plane + :param normal: Plane normal orientation + :param new_plane_yaxis: Up-vector. New orientation of plane y-axis. :param color: :ocv:class:`Color` of the plane. viz::WSphere diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index 75f9670f36..f740a6210b 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -145,8 +145,11 @@ namespace cv class CV_EXPORTS WPlane : public Widget3D { public: - WPlane(const Vec4d& coefs, double size = 1.0, const Color &color = Color::white()); - WPlane(const Vec4d& coefs, const Point3d& pt, double size = 1.0, const Color &color = Color::white()); + //! created default plane with center point at origin and normal oriented along z-axis + WPlane(const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()); + + //! repositioned plane + WPlane(const Point3d& center, const Vec3d& normal, const Vec3d& new_plane_yaxis,const Size2d& size = Size2d(1.0, 1.0), const Color &color = Color::white()); }; class CV_EXPORTS WSphere : public Widget3D diff --git a/modules/viz/src/shapes.cpp b/modules/viz/src/shapes.cpp index 2e36a6d096..468022f978 100644 --- a/modules/viz/src/shapes.cpp +++ b/modules/viz/src/shapes.cpp @@ -125,6 +125,36 @@ namespace cv { namespace viz { namespace }; }}} +cv::viz::WPlane::WPlane(const Size2d& size, const Color &color) +{ + vtkSmartPointer plane = vtkSmartPointer::New(); + plane->SetOrigin(-0.5 * size.width, -0.5 * size.height, 0.0); + plane->SetPoint1( 0.5 * size.width, -0.5 * size.height, 0.0); + plane->SetPoint2(-0.5 * size.width, 0.5 * size.height, 0.0); + plane->Update(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, plane->GetOutput()); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + actor->GetProperty()->LightingOff(); + + WidgetAccessor::setProp(*this, actor); + setColor(color); +} + +cv::viz::WPlane::WPlane(const Point3d& center, const Vec3d& normal, const Vec3d& new_plane_yaxis, const Size2d& size, const Color &color) +{ + Vec3d zvec = normalize(normal); + Vec3d xvec = normalize(new_plane_yaxis.cross(zvec)); + Vec3d yvec = zvec.cross(xvec); + + WPlane plane(size, color); + plane.applyTransform(makeTransformToGlobal(xvec, yvec, zvec, center)); + *this = plane; +} + cv::viz::WPlane::WPlane(const Vec4d& coefs, double size, const Color &color) { vtkSmartPointer plane = vtkSmartPointer::New(); diff --git a/modules/viz/test/tests_simple.cpp b/modules/viz/test/tests_simple.cpp index fe5cf33a05..85cdeacf1b 100644 --- a/modules/viz/test/tests_simple.cpp +++ b/modules/viz/test/tests_simple.cpp @@ -304,16 +304,18 @@ TEST(Viz, show_simple_widgets) viz.showWidget("con1", WCone(0.125, Point3d(0.5, -0.5, 0.5), Point3d(0.5, -1.0, 0.5), 6, Color::turquoise())); viz.showWidget("text2d", WText("Simple text", Point(20, 20), 20, Color::green())); - viz.showWidget("text3d", WText3D("Simple 3D text", Point3d( 0.5, 0.5, 0.5), 0.125, false, Color::green())); + viz.showWidget("plane1", WPlane(Size2d(0.25, 0.75))); + viz.showWidget("plane2", WPlane(Vec3d(0.5, -0.5, -0.5), Vec3d(0.0, 1.0, 1.0), Vec3d(1.0, 1.0, 0.0), Size2d(1.0, 0.5), Color::gold())); + viz.spinOnce(1500, true); viz.getWidget("text2d").cast().setText("New simple text"); viz.getWidget("text3d").cast().setText("Updated text 3D"); viz.spin(); } -TEST(Viz, show_follower) +TEST(Viz, DISABLED_show_follower) { Viz3d viz("show_follower"); -- GitLab