Commit 658f4a7d authored by Anatoly Baksheev's avatar Anatoly Baksheev

refactoed plane

parent 53b82186
...@@ -274,25 +274,30 @@ This 3D Widget defines a finite plane. :: ...@@ -274,25 +274,30 @@ This 3D Widget defines a finite plane. ::
class CV_EXPORTS WPlane : public Widget3D class CV_EXPORTS WPlane : public Widget3D
{ {
public: public:
WPlane(const Vec4d& coefs, 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 Vec4d& coefs, const Point3f& pt, double size = 1.0, const Color &color = Color::white()); 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 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. :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 center: Center of the plane
:param pt: Position of the plane. :param normal: Plane normal orientation
:param size: Size of the plane. :param new_plane_yaxis: Up-vector. New orientation of plane y-axis.
:param color: :ocv:class:`Color` of the plane. :param color: :ocv:class:`Color` of the plane.
viz::WSphere viz::WSphere
......
...@@ -145,8 +145,11 @@ namespace cv ...@@ -145,8 +145,11 @@ namespace cv
class CV_EXPORTS WPlane : public Widget3D class CV_EXPORTS WPlane : public Widget3D
{ {
public: public:
WPlane(const Vec4d& coefs, 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 Vec4d& coefs, const Point3d& pt, double size = 1.0, const Color &color = Color::white()); 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 class CV_EXPORTS WSphere : public Widget3D
......
...@@ -125,6 +125,36 @@ namespace cv { namespace viz { namespace ...@@ -125,6 +125,36 @@ namespace cv { namespace viz { namespace
}; };
}}} }}}
cv::viz::WPlane::WPlane(const Size2d& size, const Color &color)
{
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::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<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
VtkUtils::SetInputData(mapper, plane->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::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) cv::viz::WPlane::WPlane(const Vec4d& coefs, double size, const Color &color)
{ {
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New(); vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New();
......
...@@ -304,16 +304,18 @@ TEST(Viz, show_simple_widgets) ...@@ -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("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("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("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.spinOnce(1500, true);
viz.getWidget("text2d").cast<WText>().setText("New simple text"); viz.getWidget("text2d").cast<WText>().setText("New simple text");
viz.getWidget("text3d").cast<WText3D>().setText("Updated text 3D"); viz.getWidget("text3d").cast<WText3D>().setText("Updated text 3D");
viz.spin(); viz.spin();
} }
TEST(Viz, show_follower) TEST(Viz, DISABLED_show_follower)
{ {
Viz3d viz("show_follower"); Viz3d viz("show_follower");
......
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