Add next and previous navigation links to all tutorials
[platform/upstream/opencv.git] / doc / tutorials / viz / launching_viz / launching_viz.markdown
1 Launching Viz {#tutorial_launching_viz}
2 =============
3
4 @next_tutorial{tutorial_widget_pose}
5
6 Goal
7 ----
8
9 In this tutorial you will learn how to
10
11 -   Open a visualization window.
12 -   Access a window by its name.
13 -   Start event loop.
14 -   Start event loop for a given amount of time.
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/launching_viz.cpp).
20 @include samples/cpp/tutorial_code/viz/launching_viz.cpp
21
22 Explanation
23 -----------
24
25 Here is the general structure of the program:
26
27 -   Create a window.
28     @code{.cpp}
29     /// Create a window
30     viz::Viz3d myWindow("Viz Demo");
31     @endcode
32 -   Start event loop. This event loop will run until user terminates it by pressing **e**, **E**,
33     **q**, **Q**.
34     @code{.cpp}
35     /// Start event loop
36     myWindow.spin();
37     @endcode
38 -   Access same window via its name. Since windows are implicitly shared, **sameWindow** is exactly
39     the same with **myWindow**. If the name does not exist, a new window is created.
40     @code{.cpp}
41     /// Access window via its name
42     viz::Viz3d sameWindow = viz::getWindowByName("Viz Demo");
43     @endcode
44 -   Start a controlled event loop. Once it starts, **wasStopped** is set to false. Inside the while
45     loop, in each iteration, **spinOnce** is called to prevent event loop from completely stopping.
46     Inside the while loop, user can execute other statements including those which interact with the
47     window.
48     @code{.cpp}
49     /// Event loop is over when pressed q, Q, e, E
50     /// Start event loop once for 1 millisecond
51     sameWindow.spinOnce(1, true);
52     while(!sameWindow.wasStopped())
53     {
54         /// Interact with window
55
56         /// Event loop for 1 millisecond
57         sameWindow.spinOnce(1, true);
58     }
59     @endcode
60
61 Results
62 -------
63
64 Here is the result of the program.
65
66 ![](images/window_demo.png)