opencv/doc/tutorials/viz/creating_widgets/creating_widgets.markdown

56 lines
1.5 KiB
Markdown
Raw Normal View History

2014-11-27 20:39:05 +08:00
Creating Widgets {#tutorial_creating_widgets}
================
Goal
----
In this tutorial you will learn how to
- Create your own widgets using WidgetAccessor and VTK.
- Show your widget in the visualization window.
Code
----
You can download the code from [here ](https://github.com/opencv/opencv/tree/3.4/samples/cpp/tutorial_code/viz/creating_widgets.cpp).
@include samples/cpp/tutorial_code/viz/creating_widgets.cpp
2014-11-27 20:39:05 +08:00
2014-11-28 21:21:28 +08:00
Explanation
-----------
2014-11-27 20:39:05 +08:00
2014-11-28 21:21:28 +08:00
Here is the general structure of the program:
2014-11-27 20:39:05 +08:00
2014-11-28 21:21:28 +08:00
- Extend Widget3D class to create a new 3D widget.
@code{.cpp}
class WTriangle : public viz::Widget3D
{
public:
WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white());
};
@endcode
- Assign a VTK actor to the widget.
@code{.cpp}
2014-11-27 20:39:05 +08:00
// Store this actor in the widget in order that visualizer can access it
viz::WidgetAccessor::setProp(*this, actor);
2014-11-28 21:21:28 +08:00
@endcode
- Set color of the widget.
@code{.cpp}
2014-11-27 20:39:05 +08:00
// Set the color of the widget. This has to be called after WidgetAccessor.
setColor(color);
2014-11-28 21:21:28 +08:00
@endcode
- Construct a triangle widget and display it in the window.
@code{.cpp}
2014-11-27 20:39:05 +08:00
/// Create a triangle widget
WTriangle tw(Point3f(0.0,0.0,0.0), Point3f(1.0,1.0,1.0), Point3f(0.0,1.0,0.0), viz::Color::red());
/// Show widget in the visualizer window
myWindow.showWidget("TRIANGLE", tw);
2014-11-28 21:21:28 +08:00
@endcode
2014-11-27 20:39:05 +08:00
Results
-------
Here is the result of the program.
2014-11-28 21:21:28 +08:00
![](images/red_triangle.png)