Add next and previous navigation links to all tutorials
[platform/upstream/opencv.git] / doc / tutorials / viz / widget_pose / widget_pose.markdown
1 Pose of a widget {#tutorial_widget_pose}
2 ================
3
4 @prev_tutorial{tutorial_launching_viz}
5 @next_tutorial{tutorial_transformations}
6
7 Goal
8 ----
9
10 In this tutorial you will learn how to
11
12 -   Add widgets to the visualization window
13 -   Use Affine3 to set pose of a widget
14 -   Rotating and translating a widget along an axis
15
16 Code
17 ----
18
19 You can download the code from [here ](https://github.com/opencv/opencv/tree/3.4/samples/cpp/tutorial_code/viz/widget_pose.cpp).
20 @include samples/cpp/tutorial_code/viz/widget_pose.cpp
21
22 Explanation
23 -----------
24
25 Here is the general structure of the program:
26
27 -   Create a visualization window.
28     @code{.cpp}
29     /// Create a window
30     viz::Viz3d myWindow("Coordinate Frame");
31     @endcode
32 -   Show coordinate axes in the window using CoordinateSystemWidget.
33     @code{.cpp}
34     /// Add coordinate axes
35     myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
36     @endcode
37 -   Display a line representing the axis (1,1,1).
38     @code{.cpp}
39     /// Add line to represent (1,1,1) axis
40     viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f));
41     axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);
42     myWindow.showWidget("Line Widget", axis);
43     @endcode
44 -   Construct a cube.
45     @code{.cpp}
46     /// Construct a cube widget
47     viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue());
48     cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
49     myWindow.showWidget("Cube Widget", cube_widget);
50     @endcode
51 -   Create rotation matrix from rodrigues vector
52     @code{.cpp}
53     /// Rotate around (1,1,1)
54     rot_vec.at<float>(0,0) += CV_PI * 0.01f;
55     rot_vec.at<float>(0,1) += CV_PI * 0.01f;
56     rot_vec.at<float>(0,2) += CV_PI * 0.01f;
57
58     ...
59
60     Mat rot_mat;
61     Rodrigues(rot_vec, rot_mat);
62     @endcode
63 -   Use Affine3f to set pose of the cube.
64     @code{.cpp}
65     /// Construct pose
66     Affine3f pose(rot_mat, Vec3f(translation, translation, translation));
67     myWindow.setWidgetPose("Cube Widget", pose);
68     @endcode
69 -   Animate the rotation using wasStopped and spinOnce
70     @code{.cpp}
71     while(!myWindow.wasStopped())
72     {
73         ...
74
75         myWindow.spinOnce(1, true);
76     }
77     @endcode
78
79 Results
80 -------
81
82 Here is the result of the program.
83
84 \htmlonly
85 <div align="center">
86 <iframe width="420" height="315" src="https://www.youtube.com/embed/22HKMN657U0" frameborder="0" allowfullscreen></iframe>
87 </div>
88 \endhtmlonly