Here is the source code provided by Steven Lovegrove's github: https://github.com/stevenlovegrove/Pangolin/blob/master/examples/SimpleDisplay/main.cpp
Original Result at first of all:
The website does not give a very clear explanation about the structure CustomType()
struct CustomType
{
CustomType()
: x(0), y(0.0f) {}
CustomType(int x, float y, std::string z)
: x(x), y(y), z(z) {}
int x;
float y;
std::string z;
};
To understand C++ key word operator, I referred to this article: http://www.cnblogs.com/xiangxiaodong/archive/2012/02/12/2348144.html
pangolin::ParseVarsFile("/.../app.cfg") is to load configuration data, refer to: http://docs.ros.org/fuerte/api/pangolin_wrapper/html/vars_8cpp.html
To define camera render object
//Define Camera Render Object (for view / scene browsing)
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
pangolin::ModelViewLookAt(-0,0.5,-3, 0,0,0, pangolin::AxisY)
);
const int UI_WIDTH = 180;
Create panel:
// Add named Panel and bind to variables beginning 'ui'
// A Panel is just a View with a default layout and input handling
pangolin::CreatePanel("ui")
.SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(UI_WIDTH));
About pangolin::CreatePanel():
View& CreatePanel(const std::string& name)
{
Panel * p = new Panel(name);
bool inserted = context->named_managed_views.insert(name, p).second;
if(!inserted) throw exception();
context->base.views.push_back(p);
return *p;
}
Then we can create variables as below:
// Safe and efficient binding of named variables.
// Specializations mean no conversions take place for exact types
// and conversions between scalar types are cheap.
pangolin::Var<bool> a_button("ui.A_Button",false,false);
pangolin::Var<double> a_double("ui.A_Double",3,0,5);
pangolin::Var<int> an_int("ui.An_Int",2,0,5);
pangolin::Var<double> a_double_log("ui.Log_scale var",3,1,1E4, true);
pangolin::Var<bool> a_checkbox("ui.A_Checkbox",false,true);
pangolin::Var<int> an_int_no_input("ui.An_Int_No_Input",2);
pangolin::Var<CustomType> any_type("ui.Some_Type", CustomType(0,1.2,"Hello") );
pangolin::Var<bool> save_window("ui.Save_Window",false,false);
pangolin::Var<bool> save_cube("ui.Save_Cube",false,false);
pangolin::Var<bool> record_cube("ui.Record_Cube",false,false);
And other functions about those Vars:
// Demonstration of how we can register a keyboard hook to alter a Var
pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'b', pangolin::SetVarFunctor<double>("ui.A_Double", 3.5));
// Demonstration of how we can register a keyboard hook to trigger a method
pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'r', SampleMethod);
They will create different types of variables as shown in the result. By pressing "ctrl + b", A_Double would be reset to 3.5.
Um, I don't really understand why Steven Lovegrove added this:
if( pangolin::Pushed(a_button) )
std::cout << "You Pushed a button!" << std::endl;
It just made me know pangolin::Pushed( button name ) means I clicked a button...important?
To save an image:
if( pangolin::Pushed(save_window) )
pangolin::SaveWindowOnRender("window");
It's defined in display.h line 112,113:
/// Save window contents to image.
PANGOLIN_EXPORT
void SaveWindowOnRender(std::string filename_prefix);
And to record a video:
if( pangolin::Pushed(record_cube) )
pangolin::DisplayBase().RecordOnRender("ffmpeg:[fps=50,bps=8388608,unique_filename]//screencap.avi");