CEBL  2.1
EEGPlot.hpp
Go to the documentation of this file.
1 /*
2 * CEBL : CSU EEG Brain-Computer Interface Lab
3 *
4 * Author: Jeshua Bratman - jeshuabratman@gmail.com
5 *
6 * This file is part of CEBL.
7 *
8 * CEBL is free software; you can redistribute it and/or modify it.
9 * We only ask that if you use our code that you cite the source in
10 * your project or publication.
11 *
12 * EEG Group (www.cs.colostate.edu/eeg)
13 * Department of Computer Science
14 * Colorado State University
15 *
16 */
17 
25 #ifndef EEGPLOT_H
26 #define EEGPLOT_H
27 
28 
29 // gtk includes
30 #include <gtk/gtk.h>
31 #include <glib.h>
32 #include <stdlib.h>
33 
34 // gktextra includes
35 #include <gtkextra/gtkplot.h>
36 #include <gtkextra/gtkplotdata.h>
37 #include <gtkextra/gtkplotcanvas.h>
38 #include <gtkextra/gtkplotcanvasplot.h>
39 #include <gtkextra/gtkplotcanvastext.h>
40 
41 // include ublas
42 #include <boost/numeric/ublas/matrix.hpp>
43 #include <boost/numeric/ublas/vector.hpp>
44 namespace ublas = boost::numeric::ublas;
45 
46 class EEGMonitor;
47 
48 class EEGPlot
49 {
50  private:
51  GtkWidget *current_plot;
52  gint num_layers;
53  GtkWidget *canvas;
54  GtkWidget *vbox_container;
55  GtkPlotCanvasChild *lines;
56 
57  //points two dimensional arrays for each channel and each sample
58  GtkPlotData **datasets;
59  double **px;
60  double **py;
61  std::vector<std::string> labels;
62  int num_samples;
63  int num_display_samples;
64  double zoom;
65 
66  //max number of channels with space allocated for them
67  int num_channels;
68 
69  //number of channels currently plotted
70  int num_plotted_channels;
71  int ymax;
72 
73  //has the plot been initialized
74  bool initialized;
75 
76  //restraints of graph
77  double x1,x2,y1,y2;
78  double height;
79 
80  //size of plotting window
81  double window_width, window_height;
82 
83  //background colors
84  int BG_RED;
85  int BG_GREEN;
86  int BG_BLUE;
87 
88  //create a new layer
89  GtkWidget *newLayer(GtkWidget *canvas);
90 
91  //functions to handle queued redraws
92  static gint timedRedraw(gpointer);
93  gint redraw_timeout_id;
94 
95 
96  public:
97  EEGPlot(int num_channels);
98  ~EEGPlot();
99  operator GtkWidget*();
100 
101  //Initialize plot
102  void init();
103  //Plot data in window
104  void plot(ublas::matrix<double>);
105  //Redraw the plot
106  void redraw();
107 
108  //queues a redraw to be run in a specified time
109  void queueRedraw();
110 
111 
112  //setters to configure how the plot should display
113 
115  void setLabels(std::vector<std::string> labels);
117  void setWindowWidth(double width);
119  void setWindowHeight(double height);
121  void setBGColor(int red, int green, int blue) { BG_RED = red; BG_GREEN = green; BG_BLUE = blue; }
123  void setNumDisplaySamples(int n);
125  void setZoom(double zoom);
126 
127  // getters
128 
130  int getDisplaySamples() { return num_display_samples; };
131 
132 
133 };
134 
135 
136 #endif
137