33 this->num_channels = num_channels;
34 this->num_plotted_channels = 0;
37 px =
new double*[num_channels];
38 py =
new double*[num_channels];
39 datasets =
new GtkPlotData*[num_channels];
40 for(
int channel=0;channel<num_channels;channel++)
42 datasets[channel] = GTK_PLOT_DATA(gtk_plot_data_new());
50 this->num_samples = 0;
51 this->window_width = 500;
52 this->window_height = 500;
53 this->num_display_samples = 400;
57 this->initialized =
false;
58 this->redraw_timeout_id = -1;
63 if(this->redraw_timeout_id >= 0)
64 gtk_timeout_remove(this->redraw_timeout_id);
66 for(
int channel=0;channel<num_channels;channel++)
68 if(px != NULL && px[channel] != NULL)
70 if(py != NULL && py[channel] != NULL)
82 GtkWidget *EEGPlot::newLayer(GtkWidget *canvas)
85 return gtk_plot_new_with_size(NULL, .65, .45);
89 EEGPlot::operator GtkWidget*()
91 return vbox_container;
98 this->labels = labels;
107 gint page_width = int(this->window_width);
108 gint page_height = int(this->window_height * 0.9);
111 this->vbox_container = gtk_vbox_new(FALSE,0);
112 gtk_widget_show(this->vbox_container);
115 this->canvas = gtk_plot_canvas_new(page_width,page_height, 1.);
116 GTK_PLOT_CANVAS_UNSET_FLAGS(GTK_PLOT_CANVAS(canvas), GTK_PLOT_CANVAS_DND_FLAGS);
117 gtk_box_pack_start(GTK_BOX(vbox_container),canvas, TRUE, TRUE, 0);
118 gtk_widget_show(canvas);
121 gdk_color_parse(
"white", &color);
123 color.green = BG_GREEN;
124 color.blue = BG_BLUE;
126 gdk_color_alloc(gtk_widget_get_colormap(canvas), &color);
127 gtk_plot_canvas_set_background(GTK_PLOT_CANVAS(canvas), &color);
130 this->current_plot = newLayer(canvas);
131 gdk_color_alloc(gtk_widget_get_colormap(current_plot), &color);
132 gtk_plot_set_background(GTK_PLOT(current_plot), &color);
135 gtk_plot_set_ticks(GTK_PLOT(current_plot), GTK_PLOT_AXIS_X, 20, 1);
136 gtk_plot_set_ticks(GTK_PLOT(current_plot), GTK_PLOT_AXIS_Y, 40, 1);
137 gtk_plot_set_xrange(GTK_PLOT(current_plot), 0, getDisplaySamples());
138 gtk_plot_set_yrange(GTK_PLOT(current_plot), 0, this->ymax);
140 gtk_plot_axis_show_ticks(gtk_plot_get_axis(GTK_PLOT(current_plot),GTK_PLOT_AXIS_RIGHT),
false,
false);
141 gtk_plot_axis_show_ticks(gtk_plot_get_axis(GTK_PLOT(current_plot),GTK_PLOT_AXIS_LEFT),
false,
false);
142 gtk_plot_axis_set_tick_labels(gtk_plot_get_axis(GTK_PLOT(current_plot),GTK_PLOT_AXIS_LEFT), NULL);
145 gtk_plot_axis_show_labels(gtk_plot_get_axis(GTK_PLOT(current_plot),GTK_PLOT_AXIS_LEFT), 0);
146 gtk_plot_axis_show_labels(gtk_plot_get_axis(GTK_PLOT(current_plot),GTK_PLOT_AXIS_RIGHT), 0);
149 gtk_plot_axis_set_visible(gtk_plot_get_axis(GTK_PLOT(current_plot), GTK_PLOT_AXIS_TOP), FALSE);
150 gtk_plot_axis_set_visible(gtk_plot_get_axis(GTK_PLOT(current_plot), GTK_PLOT_AXIS_RIGHT), FALSE);
151 gtk_plot_axis_set_visible(gtk_plot_get_axis(GTK_PLOT(current_plot), GTK_PLOT_AXIS_BOTTOM), FALSE);
152 gtk_plot_axis_set_visible(gtk_plot_get_axis(GTK_PLOT(current_plot), GTK_PLOT_AXIS_LEFT), FALSE);
155 gtk_plot_axis_set_title(gtk_plot_get_axis(GTK_PLOT(current_plot), GTK_PLOT_AXIS_LEFT),
"");
156 gtk_plot_axis_move_title(gtk_plot_get_axis(GTK_PLOT(current_plot),GTK_PLOT_AXIS_LEFT),0,.145,.4);
160 gtk_plot_grids_set_visible(GTK_PLOT(current_plot), FALSE, TRUE, FALSE, FALSE);
163 gtk_widget_show(current_plot);
166 gtk_plot_hide_legends(GTK_PLOT(current_plot));
169 this->lines = gtk_plot_canvas_plot_new(GTK_PLOT(current_plot));
176 gtk_plot_canvas_put_child(GTK_PLOT_CANVAS(canvas), lines, x1, y1, x2, y2);
177 GtkPlotCanvasChild *child;
179 for(
int channel=0;channel<this->num_channels;channel++)
182 gtk_plot_data_show_labels(datasets[channel], FALSE);
186 gdk_color_alloc(gdk_colormap_get_system(), &color);
187 gtk_plot_data_set_line_attributes(datasets[channel],
189 GDK_CAP_NOT_LAST, GDK_JOIN_MITER, 1, &color);
192 double text_size = window_width/90.0;
194 double y_pos = (double(channel)/num_channels) * .953 + 0.05;
196 if(
unsigned(channel) < labels.size())
197 label = labels[channel];
204 child = gtk_plot_canvas_text_new(
"Times-Roman", (
int)text_size, 0, NULL, NULL, TRUE,
208 gtk_plot_canvas_put_child(GTK_PLOT_CANVAS(canvas), child, x_pos, y_pos, 0, 0);
211 gtk_plot_add_data(GTK_PLOT(current_plot), datasets[channel]);
212 gtk_widget_show(GTK_WIDGET(datasets[channel]));
215 gtk_plot_canvas_paint(GTK_PLOT_CANVAS(canvas));
216 gtk_plot_canvas_refresh(GTK_PLOT_CANVAS(canvas));
217 this->initialized =
true;
227 this->num_display_samples = n;
228 if(this->initialized)
238 if(zoom == this->zoom)
253 if(this->initialized)
264 if(data.size1() <= 0 || data.size2() <= 0)
268 if(data.size1() > 72){
269 data.resize(72,data.size2());
276 int max_samples = getDisplaySamples();
277 int orig_size = num_samples;
278 int num_new_samples = data.size2();
279 int num_old_samples = num_samples;
281 num_samples += num_new_samples;
282 if(num_samples > max_samples)
284 num_old_samples = max_samples-num_new_samples;
285 if(num_new_samples > max_samples)
287 num_new_samples = max_samples;
306 int nchannels = num_channels;
307 if(
unsigned(num_channels) > data.size1())
308 nchannels = data.size1();
309 this->num_plotted_channels = nchannels;
311 double ymax = this->ymax;
312 double yscale = zoom * 5.0 / (num_channels * .2);
313 double yoffset = ymax/nchannels;
314 double *px_new,*py_new;
315 int new_array_counter;
316 for(
int channel=0;channel<nchannels;channel++)
318 px_new =
new double[size];
319 py_new =
new double[size];
322 new_array_counter = 0;
323 for(
int i = orig_size-num_old_samples;
327 py_new[new_array_counter] = py[channel][i];
328 px_new[new_array_counter] = (new_array_counter+1);
333 for(
unsigned int i = data.size2() - num_new_samples;
337 py_new[new_array_counter] = data(channel,i)*yscale + ((nchannels-channel))*yoffset;
338 px_new[new_array_counter] = new_array_counter;
343 if(px != NULL && px[channel] != NULL)
344 delete[] px[channel];
345 if(py != NULL && py[channel] != NULL)
346 delete[] py[channel];
349 px[channel] = px_new;
350 py[channel] = py_new;
359 if(
this == NULL || current_plot == NULL)
362 if(this->redraw_timeout_id >= 0)
363 gtk_timeout_remove(this->redraw_timeout_id);
365 gtk_plot_set_xrange(GTK_PLOT(current_plot), 0, this->num_display_samples);
367 for(
int channel=0;channel<this->num_plotted_channels;channel++)
370 dataset_index = channel;
372 gtk_plot_data_set_numpoints(datasets[dataset_index], num_samples);
373 gtk_plot_data_set_x(datasets[dataset_index], px[channel]);
374 gtk_plot_data_set_y(datasets[dataset_index], py[channel]);
376 gtk_plot_canvas_paint(GTK_PLOT_CANVAS(canvas));
377 gtk_plot_canvas_refresh(GTK_PLOT_CANVAS(canvas));
385 if(this->redraw_timeout_id < 0)
387 this->redraw_timeout_id = gtk_timeout_add(200, timedRedraw,
this);
391 gtk_timeout_remove(this->redraw_timeout_id);
392 this->redraw_timeout_id = gtk_timeout_add(200, timedRedraw,
this);
401 this->window_width = width;
403 this->window_width = 1224;
410 this->window_height = height;
412 this->window_height = 1024;
417 gint EEGPlot::timedRedraw(gpointer data)