次のチュートリアル: ウィジェットの姿勢
目的
このチュートリアルでは、次のことを学ぶ
- 可視化ウィンドウを開く。
- 名前でウィンドウにアクセスする。
- イベントループを開始する。
- 指定した時間だけイベントループを開始する。
コード
コードは こちら からダウンロードできる。
#include <iostream>
static void help()
{
cout
<< "--------------------------------------------------------------------------" << endl
<< "This program shows how to launch a 3D visualization window. You can stop event loop to continue executing. "
<< "You can access the same window via its name. You can run event loop for a given period of time. " << endl
<< "Usage:" << endl
<< "./launching_viz" << endl
<< endl;
}
{
help();
myWindow.spin();
cout << "First event loop is over" << endl;
viz::Viz3d sameWindow = viz::getWindowByName(
"Viz Demo");
cout << "Second event loop is over" << endl;
{
}
cout << "Last event loop is over" << endl;
return 0;
}
The Viz3d class represents a 3D visualizer window. This class is implicitly shared.
Definition viz3d.hpp:68
void spin()
The window renders and starts the event loop.
void spinOnce(int time=1, bool force_redraw=false)
Starts the event loop for a given time.
bool wasStopped() const
Returns whether the event loop has been stopped.
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3
解説
プログラムの全体的な構造を以下に示す。
- ウィンドウを作成する。
- イベントループを開始する。このイベントループはユーザーが e, E, q, Q を押して終了させるまで実行される。
- 同じウィンドウに名前でアクセスする。ウィンドウは暗黙的に共有されるため、sameWindow は myWindow とまったく同じである。名前が存在しない場合は、新しいウィンドウが作成される。
viz::Viz3d sameWindow = viz::getWindowByName(
"Viz Demo");
- 制御されたイベントループを開始する。開始されると、wasStopped はfalseに設定される。whileループの内側で、各反復において spinOnce が呼び出され、イベントループが完全に停止するのを防ぐ。whileループの内側では、ユーザーはウィンドウと相互作用するものを含め、他の文を実行できる。
結果
これがプログラムの実行結果である。