00001 #ifndef Impala_Visualisation_Plot_TimeLine_h
00002 #define Impala_Visualisation_Plot_TimeLine_h
00003
00004 #include "Visualization/Plot/Plottable.h"
00005 #include <deque>
00006
00007 namespace Impala
00008 {
00009 namespace Visualization
00010 {
00011 namespace Plot
00012 {
00013
00014 class TimeLine : public Plottable
00015 {
00016 public:
00017 TimeLine(double z, int samples)
00018 {
00019 mMaxVal = mMinVal = 0;
00020 mMaxSamples = samples;
00021 SetDimensionsX(-samples, 0);
00022 SetDimensionsY(0, 0);
00023 SetDimensionsZ(z, z);
00024 }
00025
00026 virtual void
00027 Add(double sample)
00028 {
00029 if (sample > mMaxVal)
00030 {
00031 mMaxVal = sample;
00032 SetDimensionsY(mMinVal, mMaxVal);
00033 }
00034 else
00035 if (sample < mMinVal)
00036 {
00037 mMinVal = sample;
00038 SetDimensionsY(mMinVal, mMaxVal);
00039 }
00040 mData.push_back(sample);
00041 if (mData.size() > mMaxSamples)
00042 mData.pop_front();
00043 }
00044
00045 virtual void
00046 Draw(Plot* plot)
00047 {
00048 glColor3f(mRed, mGreen, mBlue);
00049
00050 double dx = (double)(mMaxX - mMinX) / ((double)mMaxSamples-1.);
00051 double x = mMinX + (mMaxSamples-mData.size())*dx;
00052 if(mData.size() > 2)
00053 {
00054 glBegin(GL_LINE_STRIP);
00055 for (int i=0 ; i<mData.size() ; i++)
00056 {
00057 glVertex3d(x, mData[i], mMinZ);
00058 x += dx;
00059 }
00060 glEnd();
00061 }
00062 }
00063
00064 protected:
00065 int mMaxSamples;
00066 std::deque<double> mData;
00067 double mMaxVal,mMinVal;
00068 double mZ;
00069 };
00070
00071 }
00072 }
00073 }
00074
00075 #endif Impala_Visualisation_Plot_TimeLine_h