当前位置:网站首页>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 .
边栏推荐
- Linked list interview questions (Graphic explanation)
- opencv学习笔记八--答题卡识别
- [1. Delphi foundation] 1 Introduction to Delphi Programming
- Jerry's general penetration test - do data transmission with app Communication [article]
- 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
- 861. Score after flipping the matrix
- leecode-C语言实现-15. 三数之和------思路待改进版
- Ble of Jerry [chapter]
- Ble of Jerry [chapter]
- Get the path of edge browser
猜你喜欢
随机推荐
[dictionary tree] [trie] p3879 [tjoi2010] reading comprehension
[computer skills]
实现精细化生产, MES、APS、ERP必不可少
Google may return to the Chinese market after the Spring Festival.
Mise en œuvre du langage leecode - C - 15. Somme des trois chiffres - - - - - idées à améliorer
C # create database connection object SQLite database
leecode-C語言實現-15. 三數之和------思路待改進版
word怎么只删除英语保留汉语或删除汉语保留英文
The way to learn go (I) the basic introduction of go to the first HelloWorld
WebRTC系列-H.264预估码率计算
解决方案:智慧工地智能巡检方案视频监控系统
Sharing of source code anti disclosure scheme under burning scenario
解决方案:智慧工地智能巡檢方案視頻監控系統
Leecode-c language implementation -15 Sum of three ----- ideas to be improved
Ali's redis interview question is too difficult, isn't it? I was pressed on the ground and rubbed
Basics of reptile - Scratch reptile
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
[count] [combined number] value series
49. Sound card driven article collection
TS 体操 &(交叉运算) 和 接口的继承的区别