22 delete this->interface_config;
33 GtkWidget *
title = gtk_label_new(
"");
34 gtk_label_set_markup(GTK_LABEL(title),
"<big>Real Time Classification</big>");
36 TabAdd(gtk_hseparator_new());
42 this->interface_box = gtk_vbox_new(
false, 0);
43 this->updating_view =
false;
49 btn_train_classifier = gtk_button_new_with_label(
"Train Classifier");
50 g_signal_connect(G_OBJECT(btn_train_classifier),
52 G_CALLBACK(CB_trainClassifier),
55 btn_start = gtk_button_new_with_label(
"Start Classifying");
56 g_signal_connect(G_OBJECT(btn_start),
61 btn_stop = gtk_button_new_with_label(
"Stop Classifying");
62 gtk_widget_set_sensitive(btn_stop,
false);
63 g_signal_connect(G_OBJECT(btn_stop),
70 GtkWidget * controls_hbox1 = gtk_hbox_new(
false,0);
71 GtkWidget * controls_hbox2 = gtk_hbox_new(
false,0);
72 GtkWidget * btn_box1 = gtk_hbutton_box_new();
73 GtkWidget * btn_box2 = gtk_hbutton_box_new();
74 gtk_button_box_set_layout(GTK_BUTTON_BOX(btn_box1),GTK_BUTTONBOX_START);
75 gtk_button_box_set_layout(GTK_BUTTON_BOX(btn_box2),GTK_BUTTONBOX_START);
80 gtk_box_pack_start(GTK_BOX(btn_box1),btn_train_classifier,
false,
false,2);
81 gtk_box_pack_start(GTK_BOX(controls_hbox1),btn_box1,
false,
false,2);
83 gtk_box_pack_end(GTK_BOX(controls_hbox1),source_combo,
false,
true,2);
84 gtk_box_pack_end(GTK_BOX(controls_hbox1),gtk_label_new(
"Data Source: "),
false,
false,2);
86 gtk_box_pack_start(GTK_BOX(btn_box2),btn_start,
false,
false,2);
87 gtk_box_pack_start(GTK_BOX(btn_box2),btn_stop,
false,
false,2);
88 gtk_box_pack_start(GTK_BOX(controls_hbox2),btn_box2,
false,
false,2);
91 controls_box = gtk_vbox_new(
false,0);
92 gtk_box_pack_start(GTK_BOX(controls_box), controls_hbox1,
true,
true, 2);
93 gtk_box_pack_start(GTK_BOX(controls_box), controls_hbox2,
true,
true, 2);
100 gtk_box_pack_end(GTK_BOX(controls_hbox2),this->interface_combo,
false,
false,0);
101 this->btn_interface_cfg = this->interface_config->
getButton();
102 gtk_box_pack_end(GTK_BOX(controls_hbox2),btn_interface_cfg,
false,
false,0);
103 gtk_widget_show_all(controls_hbox2);
105 this->
interface = NULL;
107 gtk_widget_set_size_request(controls_box,700,-1);
108 TabFrameAdd(controls_box,
"Classification Config");
109 TabAdd(interface_box,
true,
true,0);
117 this->updating_view =
true;
126 if(new_interface != this->interface)
128 if(this->interface != NULL)
130 this->interface->
hide();
131 gtk_container_remove(GTK_CONTAINER(this->interface_box),this->interface->
getContainer());
134 this->
interface = new_interface;
135 if(this->interface != NULL)
137 gtk_box_pack_start(GTK_BOX(this->interface_box),this->interface->
getContainer(),
true,
true,0);
141 this->interface->
show();
146 this->updating_view =
false;
158 void TabRealTimeClassification::updateInterface()
169 gint TabRealTimeClassification::timedUpdateInterface(gpointer parent)
178 tab->CB_stop(NULL,tab);
184 if(tab->interface==NULL)
186 tab->CB_stop(NULL,tab);
193 if(selected_class >= 0)
200 std::vector<double> std_props =
204 if(!(std_props[0] >= 0 || std_props[0] < 0)){
205 for(
unsigned int i = 0; i<std_props.size();i++){
206 std_props[i]=1.0/std_props.size();
210 ublas::vector<double> proportions =
212 if(proportions.size() > 0)
224 void TabRealTimeClassification::disableControls()
226 gtk_widget_set_sensitive(btn_train_classifier,
false);
227 gtk_widget_set_sensitive(btn_stop,
true);
228 gtk_widget_set_sensitive(btn_start,
false);
229 gtk_widget_set_sensitive(interface_combo,
false);
230 gtk_widget_set_sensitive(source_combo,
false);
231 gtk_widget_set_sensitive(btn_interface_cfg,
false);
234 void TabRealTimeClassification::enableControls()
236 gtk_widget_set_sensitive(btn_train_classifier,
true);
237 gtk_widget_set_sensitive(btn_stop,
false);
238 gtk_widget_set_sensitive(btn_start,
true);
239 gtk_widget_set_sensitive(interface_combo,
true);
240 gtk_widget_set_sensitive(source_combo,
true);
241 gtk_widget_set_sensitive(btn_interface_cfg,
true);
249 this->CB_stop(NULL,
this);
250 if(this->interface != NULL)
252 this->interface->
hide();
253 gtk_container_remove(GTK_CONTAINER(this->interface_box),this->interface->
getContainer());
255 this->
interface = NULL;
256 this->enableControls();
264 void TabRealTimeClassification::CB_trainClassifier(GtkWidget *w, gpointer data)
270 WidgetUtils::AlertError(
"No Training Data",
"There is no training data available. Either load data in training tab or perform a training session.");
280 gtk_main_iteration();
285 gtk_main_iteration();
295 void TabRealTimeClassification::CB_start(GtkWidget *w, gpointer data)
309 WidgetUtils::AlertError(
"Cannot Start Classifciation",
"Real-time classification not ready. Make sure you have trained the selected classifier.");
311 else if(nClasses > tClasses)
313 std::ostringstream warning;
314 warning <<
"Real-time classification not ready. Classifier is trained for " << tClasses<<
" classes, " << nClasses <<
" classes selected.";
328 if(nClasses<tClasses)
330 cout<<
"Classifier trained for " << tClasses <<
". Only the first " << nClasses <<
" will be used in classification."<<endl;
339 string msg =
"There was an error starting the classification process.\n(" + string(e.what()) +
"). Make sure you have installed the most recent classifier plugins.";
343 tab->disableControls();
344 g_timeout_add(150, timedUpdateInterface, tab);
348 void TabRealTimeClassification::CB_stop(GtkWidget *w, gpointer data)
351 tab->enableControls();
353 if(tab->interface != NULL)