1 Creating Widgets {#tutorial_creating_widgets}
4 @prev_tutorial{tutorial_transformations}
5 @next_tutorial{tutorial_histo3D}
10 In this tutorial you will learn how to
12 - Create your own widgets using WidgetAccessor and VTK.
13 - Show your widget in the visualization window.
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
24 Here is the general structure of the program:
26 - Extend Widget3D class to create a new 3D widget.
28 class WTriangle : public viz::Widget3D
31 WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white());
34 - Assign a VTK actor to the widget.
36 // Store this actor in the widget in order that visualizer can access it
37 viz::WidgetAccessor::setProp(*this, actor);
39 - Set color of the widget.
41 // Set the color of the widget. This has to be called after WidgetAccessor.
44 - Construct a triangle widget and display it in the window.
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());
49 /// Show widget in the visualizer window
50 myWindow.showWidget("TRIANGLE", tw);
56 Here is the result of the program.
58 ![](images/red_triangle.png)