mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 03:30:34 +08:00
refactoed plane
This commit is contained in:
parent
53b8218652
commit
658f4a7d38
@ -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
|
||||
|
||||
: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.
|
||||
.. 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 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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New();
|
||||
|
@ -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<WText>().setText("New simple text");
|
||||
viz.getWidget("text3d").cast<WText3D>().setText("Updated text 3D");
|
||||
viz.spin();
|
||||
}
|
||||
|
||||
TEST(Viz, show_follower)
|
||||
TEST(Viz, DISABLED_show_follower)
|
||||
{
|
||||
Viz3d viz("show_follower");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user