plotter.h
Go to the documentation of this file.
00001 /* This file is part of the Pangolin Project.
00002  * http://github.com/stevenlovegrove/Pangolin
00003  *
00004  * Copyright (c) 2011 Steven Lovegrove
00005  *
00006  * Permission is hereby granted, free of charge, to any person
00007  * obtaining a copy of this software and associated documentation
00008  * files (the "Software"), to deal in the Software without
00009  * restriction, including without limitation the rights to use,
00010  * copy, modify, merge, publish, distribute, sublicense, and/or sell
00011  * copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following
00013  * conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be
00016  * included in all copies or substantial portions of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00019  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00020  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00021  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00022  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00023  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00024  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00025  * OTHER DEALINGS IN THE SOFTWARE.
00026  */
00027 
00028 #ifndef PLOTTER_H
00029 #define PLOTTER_H
00030 
00031 #include "pangolin.h"
00032 #include <vector>
00033 #include <boost/circular_buffer.hpp>
00034 
00035 namespace pangolin
00036 {
00037 
00038 struct Plotter;
00039 struct DataLog;
00040 
00041 Plotter& CreatePlotter(const std::string& name, DataLog* log = 0);
00042 
00043 struct DataUnavailableException : std::exception
00044 {
00045     DataUnavailableException(std::string str) : desc(str) {}
00046     DataUnavailableException(std::string str, std::string detail)
00047     {
00048         desc = str + "\n\t" + detail;
00049     }
00050     ~DataUnavailableException() throw() {}
00051     const char* what() const throw()
00052     {
00053         return desc.c_str();
00054     }
00055     std::string desc;
00056 };
00057 
00058 struct DataSequence
00059 {
00060     DataSequence(unsigned int buffer_size = 1024, unsigned size = 0, float val = 0.0f );
00061 
00062     void Add(float val);
00063     void Clear();
00064     float operator[](unsigned int i) const;
00065 
00066     inline bool HasData(int i) const;
00067 
00068     boost::circular_buffer<float> y;
00069     int firstn;
00070     int n;
00071     float sum_y;
00072     float sum_y_sq;
00073     float min_y;
00074     float max_y;
00075 };
00076 
00077 inline bool DataSequence::HasData(int i) const
00078 {
00079     return i >= (int)firstn && i < (int)n;
00080 }
00081 
00082 struct DataLog
00083 {
00084     DataLog(unsigned int buffer_size = 10000 );
00085     void Log(float v);
00086     void Log(float v1, float v2);
00087     void Log(float v1, float v2, float v3);
00088     void Log(float v1, float v2, float v3, float v4);
00089     void Log(float v1, float v2, float v3, float v4, float v5);
00090     void Log(float v1, float v2, float v3, float v4, float v5, float v6);
00091     void Log(unsigned int N, const float * vals);
00092     void Log(const std::vector<float> & vals);
00093     void SetLabels(const std::vector<std::string> & labels);
00094     void Clear();
00095     void Save(std::string filename);
00096 
00097     unsigned int buffer_size;
00098     int x;
00099     std::vector<DataSequence> sequences;
00100     std::vector<std::string> labels;
00101 };
00102 
00103 const static int num_plot_colours = 12;
00104 const static float plot_colours[][3] =
00105 {
00106     {1.0, 0.0, 0.0},
00107     {0.0, 1.0, 0.0},
00108     {0.0, 0.0, 1.0},
00109     {1.0, 0.0, 1.0},
00110     {0.5, 0.5, 0.0},
00111     {0.5, 0.0, 0.0},
00112     {0.0, 0.5, 0.0},
00113     {0.0, 0.0, 0.5},
00114     {0.5, 0.0, 1.0},
00115     {0.0, 1.0, 0.5},
00116     {1.0, 0.0, 0.5},
00117     {0.0, 0.5, 1.0}
00118 };
00119 
00120 
00121 const static float colour_bg[3] = {0.0,0.0,0.0};
00122 const static float colour_tk[3] = {0.1,0.1,0.1};
00123 const static float colour_ms[3] = {0.3,0.3,0.3};
00124 const static float colour_ax[3] = {0.5,0.5,0.5};
00125 
00126 const static int draw_modes_n = 2;
00127 const static int draw_modes[] = {GL_LINE_STRIP, GL_POINTS};
00128 
00129 struct Plotter : public View, Handler
00130 {
00131     Plotter(DataLog* log, float left=0, float right=600, float bottom=-1, float top=1, float tickx=30, float ticky=0.5 );
00132     void Render();
00133     void DrawSequence(const DataSequence& seq);
00134     void DrawSequence(const DataSequence& x,const DataSequence& y);
00135     void DrawSequenceHistogram(const std::vector<DataSequence>& seq);
00136     void DrawTicks();
00137 
00138     void ResetView();
00139 
00140     void Keyboard(View&, unsigned char key, int x, int y, bool pressed);
00141     void Mouse(View&, MouseButton button, int x, int y, bool pressed, int mouse_state);
00142     void MouseMotion(View&, int x, int y, int mouse_state);
00143 
00144     void ScreenToPlot(int x, int y);
00145 
00146     DataLog* log;
00147     bool track_front;
00148     float int_x_dflt[2];
00149     float int_y_dflt[2];
00150     float int_x[2];
00151     float int_y[2];
00152     float ticks[2];
00153     int last_mouse_pos[2];
00154     int mouse_state;
00155     float mouse_xy[2];
00156 
00157     int draw_mode;
00158 
00159     enum PLOT_MODES { TIME_SERIES, XY, STACKED_HISTOGRAM};
00160     static const unsigned modes_n = 3;
00161     unsigned plot_mode;
00162     const static unsigned int show_n = 9;
00163     bool show[show_n];
00164 };
00165 
00166 } // namespace pangolin
00167 
00168 #endif // PLOTTER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


pangolin_wrapper
Author(s): Todor Stoyanov
autogenerated on Wed Feb 13 2013 14:03:25