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