Add next and previous navigation links to all tutorials
[platform/upstream/opencv.git] / doc / tutorials / viz / creating_widgets / creating_widgets.markdown
1 Creating Widgets {#tutorial_creating_widgets}
2 ================
3
4 @prev_tutorial{tutorial_transformations}
5 @next_tutorial{tutorial_histo3D}
6
7 Goal
8 ----
9
10 In this tutorial you will learn how to
11
12 -   Create your own widgets using WidgetAccessor and VTK.
13 -   Show your widget in the visualization window.
14
15 Code
16 ----
17
18 You can download the code from [here ](https://github.com/opencv/opencv/tree/3.4/samples/cpp/tutorial_code/viz/creating_widgets.cpp).
19 @include samples/cpp/tutorial_code/viz/creating_widgets.cpp
20
21 Explanation
22 -----------
23
24 Here is the general structure of the program:
25
26 -   Extend Widget3D class to create a new 3D widget.
27     @code{.cpp}
28     class WTriangle : public viz::Widget3D
29     {
30         public:
31             WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white());
32     };
33     @endcode
34 -   Assign a VTK actor to the widget.
35     @code{.cpp}
36     // Store this actor in the widget in order that visualizer can access it
37     viz::WidgetAccessor::setProp(*this, actor);
38     @endcode
39 -   Set color of the widget.
40     @code{.cpp}
41     // Set the color of the widget. This has to be called after WidgetAccessor.
42     setColor(color);
43     @endcode
44 -   Construct a triangle widget and display it in the window.
45     @code{.cpp}
46     /// Create a triangle widget
47     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());
48
49     /// Show widget in the visualizer window
50     myWindow.showWidget("TRIANGLE", tw);
51     @endcode
52
53 Results
54 -------
55
56 Here is the result of the program.
57
58 ![](images/red_triangle.png)