当前位置:网站首页>Pangolin Library: control panel, control components, shortcut key settings
Pangolin Library: control panel, control components, shortcut key settings
2022-07-06 07:44:00 【Jason. Li_ 0012】
Viewport control
Based on Windows , Optionally add control components to complete the operation . The basic controls have buttons 、 Slide bar 、 Radio buttons 、 String information, etc .
Build a camera
First , Construct a Pangolin Camera object :
#include <string>
#include <iostream>
#include "main.h"
int main()
{
/*-------- structure Pangolin The camera --------*/
// window
pangolin::CreateWindowAndBind("Viewer",640,480);
// Start the depth test
glEnable(GL_DEPTH_TEST);
// The camera
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
pangolin::ModelViewLookAt(-1,1,-1, 0,0,0, pangolin::AxisY)
);
while( !pangolin::ShouldQuit() )
{
// Clear color 、 Deep cache
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// The background color
glClearColor(0.1f, 0.2f, 0.3f, 0.3f);
// Activate the camera object
d_cam.Activate(s_cam);
// Frame cycle
pangolin::FinishFrame();
}
return 0;
}
Build control panel 、 Interactive view
The control panel is built using the following statements :
pangolin::CreatePanel(const std::string& name)
.SetBounds(Attach bottom, Attach top, Attach left, Attach right);
name
: The control panel's Tag namepanel_tag
SetBounds
: Set the size of the control panel 、 Location
Generally, the control panel is placed on the left side of the window , Place the interactive diagram on the right side of the window :
// The boundary between interactive view and control panel
const int UI_WIDTH = 180;
// On the right side : Interactive view
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, pangolin::Attach::Pix(UI_WIDTH), 1.0, -640.0f/480.0f)
.SetHandler(new pangolin::Handler3D(s_cam));
// left : Control panel
pangolin::CreatePanel("ui")
.SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(UI_WIDTH));
here , Define a constant UI_WITH
As the interface between the two , Subsequent use pangolin::Attach::Pix()
Get the corresponding pixel information . Set up the control panel Tag The name is ui
, The effect is as follows :
Build basic controls
Pangolin Will all “ Control ” Treat as an object pangolin::Var
, Can be used to build buttons 、 Slide bar 、 Control object 、 Information display and other contents :
Button
The button control is Bool type , Controls that cannot be reversed :
pangolin::Var<bool> Button(const std::string& name, const bool& value, bool toggle);
name
: Button control Tag, Fill in the form :panel_tag.controller_tag
value
: Control default valuetoggle
: Whether the control can be reversed , Button control should be filled infalse
for example , Implement a button :
pangolin::Var<bool> A_Button("ui.a_button", false, false);
The effect is as follows :
Radio buttons
The radio box control is Bool type , Controls that can be reversed :
pangolin::Var<bool> A_Checkbox(const std::string& name, const bool& value, bool toggle);
name
: Button control Tag, Fill in the form :panel_tag.controller_tag
value
: Control default valuetoggle
: Whether the control can be reversed , The radio box control should be filledtrue
for example , Implement a radio box object :
pangolin::Var<bool> A_Checkbox("ui.a_checkbox", false, true);
The effect is as follows :
Slider object
The slider object is a numeric object ::
pangolin::Var<T> Double_Slider(const std::string& name, const T& value,
double min, double max, bool logscale = false);
T
: value type , Optionalint、double、float
typename
: The control of Tag, Fill in the form :panel_tag.controller_tag
value
: Default value for controlmin、max
: The minimum of the slider 、 Maximum value , Default 0~1logscale
: Whether to display in logarithmic coordinates
for example , Achieve one Double Type slider object :
pangolin::Var<double> Double_Slider("ui.a_slider", 3, 0, 5);
The effect is as follows :
Message object
The message is displayed as std::string
Type object :
pangolin::Var<std::string> A_string(const std::string& name, const std::string& value = std::string() )
name
: The control of Tag, Fill in the form :panel_tag.controller_tag
value
: The displayed message content
for example , Build a message display object :
pangolin::Var<std::string> A_string("ui.a_string", "Hello Pangolin");
The effect is as follows :
Basic control callback
Controls are built for different controls , Therefore, the callback of the control should be realized
Button
Button controls should be monitored , When the button is pressed, perform the specified operation , Use the following function to monitor the button status
pangolin::Pushed(A_Button)
Radio buttons
The radio box control is bool type , Just check whether its value is true that will do
Slider bar
The slider control is numeric , The current value can be obtained directly .
comprehensive
thus , Complete the construction of the control :
#include <string>
#include <iostream>
#include "main.h"
int main()
{
/*-------- structure Pangolin The camera --------*/
// window
pangolin::CreateWindowAndBind("Viewer",640,480);
// Start the depth test
glEnable(GL_DEPTH_TEST);
// The camera
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
pangolin::ModelViewLookAt(-1,1,-1, 0,0,0, pangolin::AxisY)
);
// The boundary between interactive view and control panel
const int UI_WIDTH = 180;
// On the right side : Interactive view
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, pangolin::Attach::Pix(UI_WIDTH), 1.0, -640.0f/480.0f)
.SetHandler(new pangolin::Handler3D(s_cam));
// left : Control panel
pangolin::CreatePanel("ui")
.SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(UI_WIDTH));
/* -------- Build controls -------- */
// Button object
pangolin::Var<bool> A_Button("ui.a_button", false, false);
// Radio box objects
pangolin::Var<bool> A_Checkbox("ui.a_checkbox", false, true);
// Slide bar ,Double type
pangolin::Var<double> Double_Slider("ui.a_slider", 3, 0, 5);
// Slide bar ,Int type
pangolin::Var<double> Int_Slider("ui.int_slider", 3, 0, 5);
// character string
pangolin::Var<std::string> A_string("ui.a_string", "Hello Pangolin");
// Button , Save view frame
pangolin::Var<bool> SAVE_WIN("ui.save_win", false, false);
while( !pangolin::ShouldQuit() )
{
// Clear color 、 Deep cache
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// The background color
glClearColor(0.1f, 0.2f, 0.3f, 0.3f);
/*-------- Control callback function --------*/
// Button
if (pangolin::Pushed(A_Button)) {
std::cout << "Push button A." << std::endl; }
// Radio buttons
if (A_Checkbox) {
Int_Slider = (int) Double_Slider; }
// Button , Save image
if (pangolin::Pushed(SAVE_WIN)) {
pangolin::SaveWindowOnRender("window"); }
// Activate the camera object
d_cam.Activate(s_cam);
/*-------- The plot --------*/
pangolin::glDrawColouredCube();
// Frame cycle
pangolin::FinishFrame();
}
return 0;
}
The effect is as follows :
Other controls
Function button callback
pangolin::Var<std::function<void()>> (const std::string& name, std::function<void(void)> func)
name
: The control of Tag, Fill in the form :panel_tag.controller_tag
func
: Control corresponding function
This kind of button control , When the button is pressed , Will perform func
function .
Shortcut key binding
pangolin::RegisterKeyPressCallback(int key, std::function<void(void)> func);
Shortcut key binding control is used to bind buttons on the keyboard , When a fixed button is pressed , Will trigger the specified func
.
For example, using ctrl+r
Execute function :
pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'r', SampleMethod);
Special keys on the keyboard , Can be found in pangolin Use the corresponding constant to call :
const int PANGO_SPECIAL = 128;
const int PANGO_CTRL = -96;
const int PANGO_OPTN = 132;
// Ordinary keys
const int PANGO_KEY_TAB = 9;
const int PANGO_KEY_ESCAPE = 27;
// Special Keys (same as GLUT_ defines)
const int PANGO_KEY_F1 = 1;
const int PANGO_KEY_F2 = 2;
const int PANGO_KEY_F3 = 3;
const int PANGO_KEY_F4 = 4;
const int PANGO_KEY_F5 = 5;
const int PANGO_KEY_F6 = 6;
const int PANGO_KEY_F7 = 7;
const int PANGO_KEY_F8 = 8;
const int PANGO_KEY_F9 = 9;
const int PANGO_KEY_F10 = 10;
const int PANGO_KEY_F11 = 11;
const int PANGO_KEY_F12 = 12;
const int PANGO_KEY_LEFT = 100;
const int PANGO_KEY_UP = 101;
const int PANGO_KEY_RIGHT = 102;
const int PANGO_KEY_DOWN = 103;
const int PANGO_KEY_PAGE_UP = 104;
const int PANGO_KEY_PAGE_DOWN = 105;
const int PANGO_KEY_HOME = 106;
const int PANGO_KEY_END = 107;
const int PANGO_KEY_INSERT = 108;
comprehensive
#include <string>
#include <iostream>
#include "main.h"
int main()
{
/*-------- structure Pangolin The camera --------*/
// window
pangolin::CreateWindowAndBind("Viewer",640,480);
// Start the depth test
glEnable(GL_DEPTH_TEST);
// The camera
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
pangolin::ModelViewLookAt(-1,1,-1, 0,0,0, pangolin::AxisY)
);
// The boundary between interactive view and control panel
const int UI_WIDTH = 180;
// On the right side : Interactive view
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, pangolin::Attach::Pix(UI_WIDTH), 1.0, -640.0f/480.0f)
.SetHandler(new pangolin::Handler3D(s_cam));
// left : Control panel
pangolin::CreatePanel("ui")
.SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(UI_WIDTH));
/* -------- Build controls -------- */
// Button object
pangolin::Var<bool> A_Button("ui.a_button", false, false);
// Radio box objects
pangolin::Var<bool> A_Checkbox("ui.a_checkbox", false, true);
// Slide bar ,Double type
pangolin::Var<double> Double_Slider("ui.a_slider", 3, 0, 5);
// Slide bar ,Int type
pangolin::Var<double> Int_Slider("ui.int_slider", 3, 0, 5);
// character string
pangolin::Var<std::string> A_string("ui.a_string", "Hello Pangolin");
// Button , Save view frame
pangolin::Var<bool> SAVE_WIN("ui.save_win", false, false);
// Button , Function trigger
pangolin::Var<std::function<void()>> reset("ui.Reset", SampleMethod);
// Bind keyboard shortcuts
pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'b', pangolin::SetVarFunctor<double>("ui.a_slider", 3.5));
pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'r', SampleMethod);
while( !pangolin::ShouldQuit() )
{
// Clear color 、 Deep cache
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// The background color
glClearColor(0.1f, 0.2f, 0.3f, 0.3f);
/*-------- Control callback function --------*/
//
if (pangolin::Pushed(A_Button)) {
std::cout << "Push button A." << std::endl; }
if (A_Checkbox) {
Int_Slider = (int) Double_Slider; }
// Button , Save image callback function implementation
if (pangolin::Pushed(SAVE_WIN)) {
pangolin::SaveWindowOnRender("window"); }
// Activate the camera object
d_cam.Activate(s_cam);
/*-------- The plot --------*/
pangolin::glDrawColouredCube();
// Frame cycle
pangolin::FinishFrame();
}
return 0;
}
void SampleMethod()
{
std::cout << "You typed ctrl-r or pushed reset" << std::endl;
}
here , Press down Ctrl+R
Trigger function SampleMethod
; Press down Ctrl+B
Trigger function saves image . meanwhile ,pangolin By default, press the key ESC
Exit procedure ,Tab
Full screen .
边栏推荐
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- word中把帶有某個符號的行全部選中,更改為標題
- . Net 6 learning notes: what is NET Core
- 洛谷P4127 [AHOI2009]同类分布 题解
- C # create database connection object SQLite database
- Google可能在春节后回归中国市场。
- Ble of Jerry [chapter]
- Onie supports pice hard disk
- P3047 [USACO12FEB]Nearby Cows G(树形dp)
- How to delete all the words before or after a symbol in word
猜你喜欢
Mise en œuvre du langage leecode - C - 15. Somme des trois chiffres - - - - - idées à améliorer
DataX self check error /datax/plugin/reader/_ drdsreader/plugin. Json] does not exist
Relevant introduction of clip image
[CF Gym101196-I] Waif Until Dark 网络最大流
TS 类型体操 之 extends,Equal,Alike 使用场景和实现对比
Key value judgment in the cycle of TS type gymnastics, as keyword use
If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]
datax自检报错 /datax/plugin/reader/._drdsreader/plugin.json]不存在
Opencv learning notes 9 -- background modeling + optical flow estimation
Esrally domestic installation and use pit avoidance Guide - the latest in the whole network
随机推荐
Scala language learning-08-abstract classes
P3047 [USACO12FEB]Nearby Cows G(树形dp)
Ble of Jerry [chapter]
onie支持pice硬盘
解决方案:智慧工地智能巡检方案视频监控系统
Typescript interface and the use of generics
实现精细化生产, MES、APS、ERP必不可少
xpath中的position()函数使用
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]
Google可能在春节后回归中国市场。
TS 类型体操 之 循环中的键值判断,as 关键字使用
Word setting directory
Excel的相关操作
C # display the list control, select the file to obtain the file path and filter the file extension, and RichTextBox displays the data
[MySQL learning notes 30] lock (non tutorial)
Generator Foundation
Significance and measures of encryption protection for intelligent terminal equipment
Qualitative risk analysis of Oracle project management system
After the hot update of uniapp, "mismatched versions may cause application exceptions" causes and Solutions