[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libcvd-members] GVars3 example
From: |
Edward Rosten |
Subject: |
Re: [libcvd-members] GVars3 example |
Date: |
Tue, 3 Jun 2008 15:13:09 -0600 (MDT) |
On Tue, 3 Jun 2008, Pablo Barrera Gonz?lez wrote:
Hello everyone,
I am new in the mailing list and I would like to introduce me. My name is
Pablo Barrera and I am working as teaching assistant at Rey Juan Carlos
University, where I have just finished my PhD in Computer Science. I am
interested in use CVD in some projects for object tracking. So far no
problem, however I am not able to understand how GVars3 works.
Is there any example or small tutorial about how to use GVars3?
No, so here's a basic example:
#include <gvars3/instances.h>
#include <iostream>
using namespace GVars3;
using namespace std;
int main(int argc, char** argv)
{
GUI.LoadFile("autoexec.cfg"); //Read a configuration file.
GUI.parseArguments(argc, argv); //Read command line argments.
//Read an integer from the database, and display it.
//This is probably the most common use of GVars.
int i = GV3::get<int>("an_integer");
cout << i << endl;
//get also returns writeable values
GV3::get<int>("an_integer") = -10;
cout << GV3::get<int>("an_integer") << endl;
//You can also have a variable type which is linked
//to the database:
gvar3<int> an_integer("an_integer");
cout << *an_integer << endl;
//Now change the value
GV3::get<int>("an_integer") = 200;
//The new value is reflected here:
cout << *an_integer << endl;
}
The configuration file contains lines like:
varname=value
an_integer=10
Any line which doesn't look like that is a command. The command
commandlist
lists all commands currently registered (you can also add your own).
Commandline arguments are of the form
--var value
and can only be used to set variables. The one exception is
--exec file
which will load a configuration file.
There are quite a lot more features. There is a very basic scripting
language, and you can bind GUI toolkit elements to database entries, if
you have compiled it with a GUI toolkit (one of Motif, FLTK or FLTK2).
Here is an example of how to bind a slider bar to a float, in a window.
All interaction on the C++ side is the same as before. The GUI is written
in the configuration file.
#include <gvars3/instances.h>
#include <iostream>
#include <sstream>
using namespace GVars3;
using namespace std;
//Inline a configuration file
string conf_file=
"keep_running=1 \n"
"a_float=7 \n"
" \n"
"GUI.InitXInterface \n"
" \n"
"GUI.AddWindow ex Example \n"
"ex.AddSlider a_float -10 10 \n"
"ex.AddPushButton \"Quit\" keep_running=0 \n";
int main(int argc, char** argv)
{
istringstream file_stream(conf_file);
GUI.ParseStream(file_stream);
gvar3<int> keep_running("keep_running");
gvar3<float> a_float("a_float");
while(*keep_running)
{
GUI_Widgets.process_in_crnt_thread();
cout << *a_float << endl;
}
}
As you slide the bar, the number printed should change. Press the button
to quit.
Hope this helps
-Ed