1 #include <iostream>
2 #include <pangolin/pangolin.h>
3
4 struct CustomType
5 {
CustomTypeCustomType6 CustomType()
7 : x(0), y(0.0f) {}
8
CustomTypeCustomType9 CustomType(int x, float y, std::string z)
10 : x(x), y(y), z(z) {}
11
12 int x;
13 float y;
14 std::string z;
15 };
16
operator <<(std::ostream & os,const CustomType & o)17 std::ostream& operator<< (std::ostream& os, const CustomType& o){
18 os << o.x << " " << o.y << " " << o.z;
19 return os;
20 }
21
operator >>(std::istream & is,CustomType & o)22 std::istream& operator>> (std::istream& is, CustomType& o){
23 is >> o.x;
24 is >> o.y;
25 is >> o.z;
26 return is;
27 }
28
SampleMethod()29 void SampleMethod()
30 {
31 std::cout << "You typed ctrl-r or pushed reset" << std::endl;
32 }
33
34
main()35 int main(/*int argc, char* argv[]*/)
36 {
37 // Load configuration data
38 pangolin::ParseVarsFile("app.cfg");
39
40 // Create OpenGL window in single line
41 pangolin::CreateWindowAndBind("Main",640,480);
42
43 // 3D Mouse handler requires depth testing to be enabled
44 glEnable(GL_DEPTH_TEST);
45
46 // Define Camera Render Object (for view / scene browsing)
47 pangolin::OpenGlRenderState s_cam(
48 pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
49 pangolin::ModelViewLookAt(-0,0.5,-3, 0,0,0, pangolin::AxisY)
50 );
51
52 const int UI_WIDTH = 180;
53
54 // Add named OpenGL viewport to window and provide 3D Handler
55 pangolin::View& d_cam = pangolin::CreateDisplay()
56 .SetBounds(0.0, 1.0, pangolin::Attach::Pix(UI_WIDTH), 1.0, -640.0f/480.0f)
57 .SetHandler(new pangolin::Handler3D(s_cam));
58
59 // Add named Panel and bind to variables beginning 'ui'
60 // A Panel is just a View with a default layout and input handling
61 pangolin::CreatePanel("ui")
62 .SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(UI_WIDTH));
63
64 // Safe and efficient binding of named variables.
65 // Specialisations mean no conversions take place for exact types
66 // and conversions between scalar types are cheap.
67 pangolin::Var<bool> a_button("ui.A_Button",false,false);
68 pangolin::Var<double> a_double("ui.A_Double",3,0,5);
69 pangolin::Var<int> an_int("ui.An_Int",2,0,5);
70 pangolin::Var<double> a_double_log("ui.Log_scale var",3,1,1E4, true);
71 pangolin::Var<bool> a_checkbox("ui.A_Checkbox",false,true);
72 pangolin::Var<int> an_int_no_input("ui.An_Int_No_Input",2);
73 pangolin::Var<CustomType> any_type("ui.Some_Type", CustomType(0,1.2f,"Hello") );
74
75 pangolin::Var<bool> save_window("ui.Save_Window",false,false);
76 pangolin::Var<bool> save_cube("ui.Save_Cube",false,false);
77
78 pangolin::Var<bool> record_cube("ui.Record_Cube",false,false);
79
80 // std::function objects can be used for Var's too. These work great with C++11 closures.
81 pangolin::Var<std::function<void(void)> > reset("ui.Reset", SampleMethod);
82
83 // Demonstration of how we can register a keyboard hook to alter a Var
84 pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'b', pangolin::SetVarFunctor<double>("ui.A_Double", 3.5));
85
86 // Demonstration of how we can register a keyboard hook to trigger a method
87 pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'r', SampleMethod);
88
89 // Default hooks for exiting (Esc) and fullscreen (tab).
90 while( !pangolin::ShouldQuit() )
91 {
92 // Clear entire screen
93 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
94
95 if( pangolin::Pushed(a_button) )
96 std::cout << "You Pushed a button!" << std::endl;
97
98 // Overloading of Var<T> operators allows us to treat them like
99 // their wrapped types, eg:
100 if( a_checkbox )
101 an_int = (int)a_double;
102
103 if( !any_type->z.compare("robot"))
104 any_type = CustomType(1,2.3f,"Boogie");
105
106 an_int_no_input = an_int;
107
108 if( pangolin::Pushed(save_window) )
109 pangolin::SaveWindowOnRender("window");
110
111 if( pangolin::Pushed(save_cube) )
112 d_cam.SaveOnRender("cube");
113
114 if( pangolin::Pushed(record_cube) )
115 pangolin::DisplayBase().RecordOnRender("ffmpeg:[fps=50,bps=8388608,unique_filename]//screencap.avi");
116
117 // Activate efficiently by object
118 d_cam.Activate(s_cam);
119
120 // Render some stuff
121 glColor3f(1.0,1.0,1.0);
122 pangolin::glDrawColouredCube();
123
124 // Swap frames and Process Events
125 pangolin::FinishFrame();
126 }
127
128 return 0;
129 }
130