Widget
In this section, the widget framework is explained. Widgets represent 2D or 3D objects, varying from simple ones such as lines to complex one such as point clouds and meshes.
Widgets are implicitly shared. Therefore, one can add a widget to the scene, and modify the widget without re-adding the widget.
...
/// Create a cloud widget
viz::WCloud cw(cloud, viz::Color::red());
/// Display it in a window
myWindow.showWidget("CloudWidget1", cw);
/// Modify it, and it will be modified in the window.
cw.setColor(viz::Color::yellow());
...
viz::Widget
Base class of all widgets. Widget is implicitly shared.
class CV_EXPORTS Widget
{
public:
Widget();
Widget(const Widget& other);
Widget& operator=(const Widget& other);
~Widget();
//! Create a widget directly from ply file
static Widget fromPlyFile(const String &file_name);
//! Rendering properties of this particular widget
void setRenderingProperty(int property, double value);
double getRenderingProperty(int property) const;
//! Casting between widgets
template<typename _W> _W cast();
private:
/* hidden */
};
viz::Widget::fromPlyFile
Creates a widget from ply file.
viz::Widget::setRenderingProperty
Sets rendering property of the widget.
viz::Widget::getRenderingProperty
Returns rendering property of the widget.
viz::Widget::cast
Casts a widget to another.
// Create a sphere widget
viz::WSphere sw(Point3f(0.0f,0.0f,0.0f), 0.5f);
// Cast sphere widget to cloud widget
viz::WCloud cw = sw.cast<viz::WCloud>();
Note
3D Widgets can only be cast to 3D Widgets. 2D Widgets can only be cast to 2D Widgets.
viz::WidgetAccessor
This class is for users who want to develop their own widgets using VTK library API.
struct CV_EXPORTS WidgetAccessor
{
static vtkSmartPointer<vtkProp> getProp(const Widget &widget);
static void setProp(Widget &widget, vtkSmartPointer<vtkProp> prop);
};
viz::WidgetAccessor::getProp
Returns vtkProp
of a given widget.
Note
vtkProp has to be down cast appropriately to be modified.
vtkActor * actor = vtkActor::SafeDownCast(viz::WidgetAccessor::getProp(widget));
viz::WidgetAccessor::setProp
Sets vtkProp
of a given widget.
viz::Widget3D
Base class of all 3D widgets.
class CV_EXPORTS Widget3D : public Widget
{
public:
Widget3D() {}
void setPose(const Affine3f &pose);
void updatePose(const Affine3f &pose);
Affine3f getPose() const;
void setColor(const Color &color);
private:
/* hidden */
};
viz::Widget3D::setPose
Sets pose of the widget.
viz::Widget3D::updateWidgetPose
Updates pose of the widget by pre-multiplying its current pose.
viz::Widget3D::getPose
Returns the current pose of the widget.
viz::Widget3D::setColor
Sets the color of the widget.
viz::Widget2D
Base class of all 2D widgets.
class CV_EXPORTS Widget2D : public Widget
{
public:
Widget2D() {}
void setColor(const Color &color);
};
viz::Widget2D::setColor
Sets the color of the widget.
viz::WLine
This 3D Widget defines a finite line.
class CV_EXPORTS WLine : public Widget3D
{
public:
WLine(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white());
};
viz::WLine::WLine
Constructs a WLine.
viz::WPlane
This 3D Widget defines a finite plane.
class CV_EXPORTS WPlane : public Widget3D
{
public:
WPlane(const Vec4f& coefs, double size = 1.0, const Color &color = Color::white());
WPlane(const Vec4f& coefs, const Point3f& pt, double size = 1.0, const Color &color = Color::white());
private:
/* hidden */
};
viz::WPlane::WPlane
Constructs a WPlane.
viz::WSphere
This 3D Widget defines a sphere.
class CV_EXPORTS WSphere : public Widget3D
{
public:
WSphere(const cv::Point3f ¢er, float radius, int sphere_resolution = 10, const Color &color = Color::white())
};
viz::WSphere::WSphere
Constructs a WSphere.
viz::WArrow
This 3D Widget defines an arrow.
class CV_EXPORTS WArrow : public Widget3D
{
public:
WArrow(const Point3f& pt1, const Point3f& pt2, double thickness = 0.03, const Color &color = Color::white());
};
viz::WArrow::WArrow
Constructs an WArrow.
Arrow head is located at the end point of the arrow.
viz::WCircle
This 3D Widget defines a circle.
class CV_EXPORTS WCircle : public Widget3D
{
public:
WCircle(const Point3f& pt, double radius, double thickness = 0.01, const Color &color = Color::white());
};
viz::WCircle::WCircle
Constructs a WCircle.
viz::WCylinder
This 3D Widget defines a cylinder.
class CV_EXPORTS WCylinder : public Widget3D
{
public:
WCylinder(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides = 30, const Color &color = Color::white());
};
viz::WCylinder::WCylinder
Constructs a WCylinder.
viz::WCube
This 3D Widget defines a cube.
class CV_EXPORTS WCube : public Widget3D
{
public:
WCube(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame = true, const Color &color = Color::white());
};
viz::WCube::WCube
Constructs a WCube.

viz::WCoordinateSystem
This 3D Widget represents a coordinate system.
class CV_EXPORTS WCoordinateSystem : public Widget3D
{
public:
WCoordinateSystem(double scale = 1.0);
};
viz::WCoordinateSystem::WCoordinateSystem
Constructs a WCoordinateSystem.
viz::WPolyLine
This 3D Widget defines a poly line.
class CV_EXPORTS WPolyLine : public Widget3D
{
public:
WPolyLine(InputArray points, const Color &color = Color::white());
private:
/* hidden */
};
viz::WPolyLine::WPolyLine
Constructs a WPolyLine.
viz::WGrid
This 3D Widget defines a grid.
class CV_EXPORTS WGrid : public Widget3D
{
public:
//! Creates grid at the origin
WGrid(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white());
//! Creates grid based on the plane equation
WGrid(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white());
private:
/* hidden */
};
viz::WGrid::WGrid
Constructs a WGrid.
viz::WText3D
This 3D Widget represents 3D text. The text always faces the camera.
class CV_EXPORTS WText3D : public Widget3D
{
public:
WText3D(const String &text, const Point3f &position, double text_scale = 1.0, double face_camera = true, const Color &color = Color::white());
void setText(const String &text);
String getText() const;
};
viz::WText3D::WText3D
Constructs a WText3D.
viz::WText3D::setText
Sets the text content of the widget.
viz::WText3D::getText
Returns the current text content of the widget.
viz::WText
This 2D Widget represents text overlay.
class CV_EXPORTS WText : public Widget2D
{
public:
WText(const String &text, const Point2i &pos, int font_size = 10, const Color &color = Color::white());
void setText(const String &text);
String getText() const;
};
viz::WText::WText
Constructs a WText.
viz::WText::setText
Sets the text content of the widget.
viz::WText::getText
Returns the current text content of the widget.
viz::WImageOverlay
This 2D Widget represents an image overlay.
class CV_EXPORTS WImageOverlay : public Widget2D
{
public:
WImageOverlay(const Mat &image, const Rect &rect);
void setImage(const Mat &image);
};
viz::WImageOverlay::WImageOverlay
Constructs an WImageOverlay.
viz::WImageOverlay::setImage
Sets the image content of the widget.
viz::WImage3D
This 3D Widget represents an image in 3D space.
class CV_EXPORTS WImage3D : public Widget3D
{
public:
//! Creates 3D image at the origin
WImage3D(const Mat &image, const Size &size);
//! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation
WImage3D(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size);
void setImage(const Mat &image);
};
viz::WImage3D::WImage3D
Constructs an WImage3D.
viz::WImage3D::setImage
Sets the image content of the widget.
viz::WCameraPosition
This 3D Widget represents camera position in a scene by its axes or viewing frustum.
class CV_EXPORTS WCameraPosition : public Widget3D
{
public:
//! Creates camera coordinate frame (axes) at the origin
WCameraPosition(double scale = 1.0);
//! Creates frustum based on the intrinsic marix K at the origin
WCameraPosition(const Matx33f &K, double scale = 1.0, const Color &color = Color::white());
//! Creates frustum based on the field of view at the origin
WCameraPosition(const Vec2f &fov, double scale = 1.0, const Color &color = Color::white());
//! Creates frustum and display given image at the far plane
WCameraPosition(const Matx33f &K, const Mat &img, double scale = 1.0, const Color &color = Color::white());
//! Creates frustum and display given image at the far plane
WCameraPosition(const Vec2f &fov, const Mat &img, double scale = 1.0, const Color &color = Color::white());
};
viz::WCameraPosition::WCameraPosition
Constructs a WCameraPosition.
-
Display camera coordinate frame.
-
Display the viewing frustum.
-
Display image on the far plane of the viewing frustum.
viz::WTrajectory
This 3D Widget represents a trajectory.
class CV_EXPORTS WTrajectory : public Widget3D
{
public:
enum {DISPLAY_FRAMES = 1, DISPLAY_PATH = 2};
//! Displays trajectory of the given path either by coordinate frames or polyline
WTrajectory(const std::vector<Affine3f> &path, int display_mode = WTrajectory::DISPLAY_PATH, const Color &color = Color::white(), double scale = 1.0);
//! Displays trajectory of the given path by frustums
WTrajectory(const std::vector<Affine3f> &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white());
//! Displays trajectory of the given path by frustums
WTrajectory(const std::vector<Affine3f> &path, const Vec2f &fov, double scale = 1.0, const Color &color = Color::white());
private:
/* hidden */
};
viz::WTrajectory::WTrajectory
Constructs a WTrajectory.
viz::WSpheresTrajectory
This 3D Widget represents a trajectory using spheres and lines, where spheres represent the positions of the camera, and lines represent the direction from previous position to the current.
class CV_EXPORTS WSpheresTrajectory : public Widget3D
{
public:
WSpheresTrajectory(const std::vector<Affine3f> &path, float line_length = 0.05f,
double init_sphere_radius = 0.021, sphere_radius = 0.007,
Color &line_color = Color::white(), const Color &sphere_color = Color::white());
};
viz::WSpheresTrajectory::WSpheresTrajectory
Constructs a WSpheresTrajectory.
viz::WCloud
This 3D Widget defines a point cloud.
class CV_EXPORTS WCloud : public Widget3D
{
public:
//! Each point in cloud is mapped to a color in colors
WCloud(InputArray cloud, InputArray colors);
//! All points in cloud have the same color
WCloud(InputArray cloud, const Color &color = Color::white());
private:
/* hidden */
};
viz::WCloud::WCloud
Constructs a WCloud.
Note
In case there are four channels in the cloud, fourth channel is ignored.
viz::WCloudCollection
This 3D Widget defines a collection of clouds.
class CV_EXPORTS WCloudCollection : public Widget3D
{
public:
WCloudCollection();
//! Each point in cloud is mapped to a color in colors
void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity());
//! All points in cloud have the same color
void addCloud(InputArray cloud, const Color &color = Color::white(), Affine3f &pose = Affine3f::Identity());
private:
/* hidden */
};
viz::WCloudCollection::WCloudCollection
Constructs a WCloudCollection.
viz::WCloudCollection::addCloud
Adds a cloud to the collection.
Note
In case there are four channels in the cloud, fourth channel is ignored.
viz::WCloudNormals
This 3D Widget represents normals of a point cloud.
class CV_EXPORTS WCloudNormals : public Widget3D
{
public:
WCloudNormals(InputArray cloud, InputArray normals, int level = 100, float scale = 0.02f, const Color &color = Color::white());
private:
/* hidden */
};
viz::WCloudNormals::WCloudNormals
Constructs a WCloudNormals.
Note
In case there are four channels in the cloud, fourth channel is ignored.
viz::WMesh
This 3D Widget defines a mesh.
class CV_EXPORTS WMesh : public Widget3D
{
public:
WMesh(const Mesh3d &mesh);
private:
/* hidden */
};
viz::WMesh::WMesh
Constructs a WMesh.