util::GraphInset Class Reference

Class used to draw a graph of time stamped data in the model window. More...

#include <util/graph_inset.h>

List of all members.

Classes

struct  Data
 Data structure used to store the time stamped values. More...

Public Types

typedef std::list< Data >
::const_iterator 
iterator
 Constant iterator on the stamped data.
typedef const Datapointer
 Type of a pointer on the data.
typedef const Datareference
 Type of a reference on the data.
typedef std::list< Data >
::const_reverse_iterator 
reverse_iterator
 Constant reverse iterator on the stamped data.
typedef Data value_type
 Type of the data.

Public Member Functions

void addData (double time, const double *values, bool changed=false)
 Add time stamped values.
template<size_t N>
void addData (double time, const util::Vector< N, double > &values, bool changed=false)
 Add time stamped values.
void addData (double time, double value1, double value2, double value3, double value4, double value5, bool changed=false)
 Helper to add time stamped values.
void addData (double time, double value1, double value2, double value3, double value4, bool changed=false)
 Helper to add time stamped values.
void addData (double time, double value1, double value2, double value3, bool changed=false)
 Helper to add time stamped values.
void addData (double time, double value1, double value2, bool changed=false)
 Helper to add time stamped values.
void addData (double time, double value, bool changed=false)
 Helper to add time stamped values.
void addData (double time, const std::vector< double > &values, bool changed=false)
 Add time stamped values.
void check ()
 Check if the object is correctly initialized.
void cleanData ()
 Remove all data that won't be drawn because they are older than the time span of the graph.
void clear ()
 Remove all data from the graph.
void closeGraph ()
 Order the graph to close.
void dataSourceChanged ()
void draw (Viewer *viewer, const util::Palette &palette)
 Draw the graph in the viewer.
void drawFrame (size_t id, Viewer *viewer)
 Draw the frame only in the viewer.
void drawWithName (size_t id, Viewer *viewer)
 Draw the graph in the viewer with a given name.
bool graphClosed () const
 Tell if the graph is closed.
 GraphInset (int nb_lines=0)
 Construct a new graph inset.
int numberOfLines () const
 Returns the numbers of lines drawn.
void openGraph ()
 Order the graph to open up.
void readParms (const QString &section, util::Parms parms)
 Read the parameters for the graph.
void setNumberOfLines (size_t nb_lines)
 Change the number of lines.
void setTime (double t)
 Kepp the graph informed of the current time in the system.
bool writeCSV (const QString &filename)
 Write the data in a .csv file.
STL-like methods

reference back () const
iterator begin () const
iterator end () const
reference front () const
reverse_iterator rbegin () const
reverse_iterator rend () const
size_t size () const
 Number of values stored.

Public Attributes

bool autoOpenClose
 Automatically open/close the graph.
int backColor
 Color of the back of the graph.
double backgroundOffset
 Offset to draw the background of the graph.
int changeSourceColor
 Color of the line used to indicate a data change (typically if the data correspond to another cell).
double changeSourceOffset
 Offset to draw the data source change line.
int changeSourceWidth
 Width of the line used to indicate a data change (typically if the data correspond to another cell).
int contourColor
 Color of the contour.
double contourOffset
 Offset to draw the contour of the graph.
int contourWidth
 Width of the line used for the contour.
bool keepAllData
 Order the object to keep all the data.
std::vector< int > linesColor
 Color of the lines.
std::vector< util::Vector
< 2, double > > 
linesMinMaxView
 Extrema value shown for each line.
std::vector< double > linesOffset
 Offset to draw the lines.
std::vector< double > linesWidth
 Width of the lines.
bool showAll
 If true, show all the data.
std::vector< size_t > showIndices
 If not showing all data, contains the indices to show.
double time
 Time of the system.
double timeSpan
 Time span to keep the data.
util::Vector< 2, int > windowPosition
 Position of the top-left corner of the graph window in pixels.
util::Vector< 2, size_t > windowSize
 Size of the graph window in pixels.

Protected Attributes

size_t _numberOfLines
 Number of lines drawn by the graph.
bool closed
 State if the graph window should be closed.
std::list< Datadata
 Data to be draw.
bool initialized
 Check the system is correctly initialized.

Detailed Description

Class used to draw a graph of time stamped data in the model window.

Definition at line 30 of file graph_inset.h.


Member Typedef Documentation

Constant iterator on the stamped data.

Definition at line 69 of file graph_inset.h.

Type of a pointer on the data.

Definition at line 83 of file graph_inset.h.

Type of a reference on the data.

Definition at line 87 of file graph_inset.h.

typedef std::list<Data>::const_reverse_iterator util::GraphInset::reverse_iterator

Constant reverse iterator on the stamped data.

Definition at line 74 of file graph_inset.h.

Type of the data.

Definition at line 79 of file graph_inset.h.


Constructor & Destructor Documentation

util::GraphInset::GraphInset ( int  nb_lines = 0  ) 

Construct a new graph inset.

Parameters:
nb_lines Number of lines to draw (i.e. nb of values given each time)

Definition at line 7 of file graph_inset.cpp.

Referenced by readParms().

00016 {


Member Function Documentation

void util::GraphInset::addData ( double  time,
const double *  values,
bool  changed = false 
) [inline]

Add time stamped values.

Definition at line 187 of file graph_inset.h.

References _numberOfLines, and addData().

00188     {
00189       std::vector<double> vec_values(_numberOfLines);
00190       for(size_t i = 0 ; i < _numberOfLines ; ++i)
00191       {
00192         vec_values[i] = values[i];
00193       }
00194       addData(time, vec_values, changed);
00195     }

template<size_t N>
void util::GraphInset::addData ( double  time,
const util::Vector< N, double > &  values,
bool  changed = false 
) [inline]

Add time stamped values.

Definition at line 174 of file graph_inset.h.

References addData().

00175     {
00176       std::vector<double> vec_values(N);
00177       for(size_t i = 0 ; i < N ; ++i)
00178       {
00179         vec_values[i] = values[i];
00180       }
00181       addData(time, vec_values, changed);
00182     }

void util::GraphInset::addData ( double  time,
double  value1,
double  value2,
double  value3,
double  value4,
double  value5,
bool  changed = false 
) [inline]

Helper to add time stamped values.

Definition at line 160 of file graph_inset.h.

References addData().

00161     {
00162       std::vector<double> vs(5, value1);
00163       vs[1] = value2;
00164       vs[2] = value3;
00165       vs[3] = value4;
00166       vs[4] = value5;
00167       addData(time, vs, changed);
00168     }

void util::GraphInset::addData ( double  time,
double  value1,
double  value2,
double  value3,
double  value4,
bool  changed = false 
) [inline]

Helper to add time stamped values.

Definition at line 148 of file graph_inset.h.

References addData().

00149     {
00150       std::vector<double> vs(4, value1);
00151       vs[1] = value2;
00152       vs[2] = value3;
00153       vs[3] = value4;
00154       addData(time, vs, changed);
00155     }

void util::GraphInset::addData ( double  time,
double  value1,
double  value2,
double  value3,
bool  changed = false 
) [inline]

Helper to add time stamped values.

Definition at line 137 of file graph_inset.h.

References addData().

00138     {
00139       std::vector<double> vs(3, value1);
00140       vs[1] = value2;
00141       vs[2] = value3;
00142       addData(time, vs, changed);
00143     }

void util::GraphInset::addData ( double  time,
double  value1,
double  value2,
bool  changed = false 
) [inline]

Helper to add time stamped values.

Definition at line 127 of file graph_inset.h.

References addData().

00128     {
00129       std::vector<double> vs(2, value1);
00130       vs[1] = value2;
00131       addData(time, vs, changed);
00132     }

void util::GraphInset::addData ( double  time,
double  value,
bool  changed = false 
) [inline]

Helper to add time stamped values.

Definition at line 118 of file graph_inset.h.

References addData().

00119     {
00120       std::vector<double> vs(1, value);
00121       addData(time, vs, changed);
00122     }

void util::GraphInset::addData ( double  time,
const std::vector< double > &  values,
bool  changed = false 
)

Add time stamped values.

Parameters:
time Timestamp
values Values to add, must be in equal number as declared before
changed Indicate the source of the value changed (a line will be drawn at that time on the graph)

Definition at line 86 of file graph_inset.cpp.

Referenced by addData().

00094   {

void util::GraphInset::check (  ) 

Check if the object is correctly initialized.

This function must be called before using the object. It is automatically called within readParms.

Definition at line 219 of file graph_inset.cpp.

00226   {
00227     util::Palette palette;
00228     glPushName((GLuint)id);
00229     draw(viewer,palette);
00230     glPopName();
00231   }
00232 
00233   void GraphInset::check()
00234   {
00235     initialized = false;
00236     if(_numberOfLines <= 0)
00237     {
00238       cerr << "Number of lines <= 0" << endl;
00239       return;
00240     }
00241     forall(const Data& d, data)
00242     {
00243       if(d.values.size() != _numberOfLines)
00244       {
00245         cerr << "Number of values inconsistant with the number of lines" << endl;
00246         return;
00247       }
00248     }
00249     if(linesWidth.size() < showIndices.size())
00250     {
00251       cerr << "Number of line widths < number of shown lines" << endl;
00252       return;
00253     }
00254     if(linesColor.size() < showIndices.size())
00255     {
00256       cerr << "Number of line colors < number of shown lines" << endl;
00257       return;
00258     }
00259     if(linesMinMaxView.size() < showIndices.size())
00260     {
00261       cerr << "Number of line min max views < number of shown lines" << endl;
00262       return;
00263     }
00264     if(linesOffset.size() < showIndices.size())
00265     {
00266       cerr << "Number of line offsets < number of shown lines" << endl;
00267       return;
00268     }
00269     forall(double& w, linesWidth)
00270     {
00271       if(w < 0)
00272       {
00273         cerr << "Line width < 0" << endl;
00274         return;
00275       }
00276     }
00277     forall(int& c, linesColor)
00278     {
00279       if(c < 0 || c > 255)
00280       {
00281         cerr << "Line color < 0 or > 255" << endl;
00282         return;
00283       }
00284     }
00285     if(contourWidth < 0)
00286     {
00287       cerr << "Contour width < 0" << endl;
00288       return;
00289     }
00290     if(contourColor < 0 || contourColor > 255)
00291     {
00292       cerr << "Contour color < 0 or > 255" << endl;

void util::GraphInset::cleanData (  ) 

Remove all data that won't be drawn because they are older than the time span of the graph.

Definition at line 101 of file graph_inset.cpp.

References autoOpenClose, data, openGraph(), and time.

00101   {
00102     data.push_back(Data(t,values, changed));
00103     if(autoOpenClose)
00104       openGraph();
00105     if(time < t)
00106       time = t;
00107   }
00108 
00109   void GraphInset::dataSourceChanged()

void util::GraphInset::clear (  ) 

Remove all data from the graph.

Definition at line 79 of file graph_inset.cpp.

00081       {
00082         for(size_t i = 0 ; i < showIndices.size() ; ++i)
00083         {
00084           if(showIndices[i] > nb_lines)

void util::GraphInset::closeGraph (  ) 

Order the graph to close.

Definition at line 294 of file graph_inset.cpp.

00296     {
00297       cerr << "Source width < 0" << endl;

void util::GraphInset::draw ( Viewer viewer,
const util::Palette palette 
)

Draw the graph in the viewer.

Definition at line 111 of file graph_inset.cpp.

00116   {
00117     while(!data.empty() && (time - data.front().time) > timeSpan)
00118     {
00119       data.pop_front();
00120     }
00121     if(autoOpenClose && data.empty())
00122       closeGraph();
00123   }
00124 
00125   void GraphInset::draw(Viewer* viewer, const util::Palette& palette)
00126   {
00127     if(!initialized)
00128     {
00129       cerr << "Trying to draw an uninitialized graph" << endl;
00130       return;
00131     }
00132     if(!keepAllData)
00133       cleanData();
00134     if(!closed)
00135     {
00136       glPushAttrib(GL_LIGHTING_BIT|GL_LINE_BIT|GL_POLYGON_BIT);
00137       glDisable(GL_LIGHTING);
00138       QSize wndSize = viewer->size();
00139       int x1,y1,x2,y2;
00140       if(windowPosition.x() < 0)
00141         x1 = wndSize.width() + windowPosition.x();
00142       else
00143         x1 = windowPosition.x();
00144       if(windowPosition.y() < 0)
00145         y1 = wndSize.height() + windowPosition.y();
00146       else
00147         y1 = windowPosition.y();
00148       x2 = x1+(int)windowSize.x();
00149       y2 = y1+(int)windowSize.y();
00150       viewer->startScreenCoordinatesSystem();
00151       // First draw a square
00152       glPolygonMode(GL_FRONT, GL_FILL);
00153       if(backColor >= 0)
00154       {
00155         palette.useColor(backColor);
00156         glBegin(GL_POLYGON);
00157         glVertex3d(x1,y1,backgroundOffset);
00158         glVertex3d(x1,y2,backgroundOffset);
00159         glVertex3d(x2,y2,backgroundOffset);
00160         glVertex3d(x2,y1,backgroundOffset);
00161         glEnd();
00162       }
00163       glPolygonMode(GL_FRONT, GL_LINE);
00164       palette.useColor(contourColor);
00165       glLineWidth(contourWidth);
00166       glBegin(GL_POLYGON);
00167       glVertex3d(x1,y1,contourOffset);
00168       glVertex3d(x1,y2,contourOffset);
00169       glVertex3d(x2,y2,contourOffset);
00170       glVertex3d(x2,y1,contourOffset);
00171       glEnd();
00172       if((data.size() > 1) && (time - data.back().time) < timeSpan)
00173       {
00174         std::list<Data>::reverse_iterator it;
00175         double ratio_x = windowSize.x()/timeSpan;
00176         for(size_t idx = 0 ; idx < showIndices.size() ; ++idx)
00177         {
00178           size_t k = showIndices[idx]-1;
00179           if(k >= _numberOfLines)
00180             continue;
00181           glLineWidth(linesWidth[k]);
00182           double ratio_y = (windowSize.y()-contourWidth)/(linesMinMaxView[k][1] - linesMinMaxView[k][0]);
00183           double shift_y = linesMinMaxView[k][0];
00184           palette.useColor(linesColor[k]);
00185           glBegin(GL_LINE_STRIP);
00186           for(it = data.rbegin() ; it != data.rend() ; ++it)
00187           {
00188             const Data& d = *it;
00189             if((time - d.time) > timeSpan)
00190               break;
00191             const std::vector<double>& values = d.values;
00192             double x = x2 + (d.time - time)*ratio_x;
00193             glVertex3d(x, y2 - std::max(std::min((values[k]-shift_y)*ratio_y,(double)windowSize.y()), 0.0), linesOffset[k]);
00194             if(d.changed)
00195             {
00196               glEnd();
00197               glBegin(GL_LINE_STRIP);
00198             }
00199           }
00200           glEnd();
00201         }
00202         palette.useColor(changeSourceColor);
00203         glLineWidth(changeSourceWidth);
00204         glBegin(GL_LINES);
00205         for(it = data.rbegin() ; it != data.rend() ; ++it)
00206         {
00207           const Data& d = *it;
00208           if((time - d.time) > timeSpan)
00209             break;

void util::GraphInset::drawFrame ( size_t  id,
Viewer viewer 
)

Draw the frame only in the viewer.

Used for selection purposes.

void util::GraphInset::drawWithName ( size_t  id,
Viewer viewer 
)

Draw the graph in the viewer with a given name.

Used for selection purposes. Useful if the background is selected as transparent.

Definition at line 211 of file graph_inset.cpp.

References changeSourceOffset, and time.

00211           {
00212             //            double x = x1 + (d.time-shift_time)*ratio_x;
00213             double x = x2 + (d.time - time)*ratio_x;
00214             glVertex3d(x, y1, changeSourceOffset);
00215             glVertex3d(x, y2, changeSourceOffset);
00216           }
00217         }

bool util::GraphInset::graphClosed (  )  const [inline]

Tell if the graph is closed.

Definition at line 238 of file graph_inset.h.

References closed.

00238 { return closed; }

int util::GraphInset::numberOfLines (  )  const [inline]

Returns the numbers of lines drawn.

Definition at line 253 of file graph_inset.h.

References _numberOfLines.

00253 { return (int)_numberOfLines; }

void util::GraphInset::openGraph (  ) 

Order the graph to open up.

Definition at line 299 of file graph_inset.cpp.

Referenced by cleanData().

00301     {
00302       cerr << "Source color < 0 or > 255" << endl;

void util::GraphInset::readParms ( const QString section,
util::Parms  parms 
)

Read the parameters for the graph.

Parameters:
section Section to read the parameters from
parms util::Parms object to read the parameters from

Definition at line 14 of file graph_inset.cpp.

References _numberOfLines, util::Parms::all(), GraphInset(), linesColor, linesMinMaxView, linesOffset, linesWidth, showAll, showIndices, windowPosition, and windowSize.

00016 {
00017 
00018   using std::endl;
00019   using std::cerr;
00020 
00021   GraphInset::GraphInset(int nb_lines)
00022     : _numberOfLines(nb_lines)
00023     , initialized(false)
00024     , closed(true)
00025   {
00026   }
00027 
00028   void GraphInset::readParms(const QString& section, util::Parms parms)
00029   {
00030     parms(section, "Size", windowSize);
00031     parms(section, "Position", windowPosition);
00032 
00033     parms(section, "ShowAll", showAll);
00034     if(!showAll)
00035     {
00036       parms(section, "Show", showIndices);
00037     }
00038     else
00039     {
00040       showIndices.clear();
00041       for(size_t i = 0 ; i < _numberOfLines ; ++i)
00042       {
00043         showIndices.push_back(i+1);
00044       }
00045     }
00046     cerr << "Number of lines to be shown: " << showIndices.size() << endl;
00047 
00048     parms.all(section, "LineColor", linesColor);
00049     parms.all(section, "LineWidth", linesWidth);
00050     parms.all(section, "LineMinMaxView", linesMinMaxView);
00051     parms.all(section, "LineOffset", linesOffset);

void util::GraphInset::setNumberOfLines ( size_t  nb_lines  ) 

Change the number of lines.

If the number of lines is actually changed, then the system is reset

Definition at line 53 of file graph_inset.cpp.

00068   {
00069     if(_numberOfLines != nb_lines)
00070     {
00071       _numberOfLines = nb_lines;
00072       if(showAll)
00073       {
00074         showIndices.clear();
00075         for(size_t i = 0 ; i < nb_lines ; ++i)
00076         {
00077           showIndices.push_back(i);

void util::GraphInset::setTime ( double  t  )  [inline]

Kepp the graph informed of the current time in the system.

Definition at line 243 of file graph_inset.h.

References time.

00243 { time = t; }

size_t util::GraphInset::size (  )  const [inline]

Number of values stored.

Definition at line 280 of file graph_inset.h.

References data.

00280 { return data.size(); }

bool util::GraphInset::writeCSV ( const QString filename  ) 

Write the data in a .csv file.

Definition at line 304 of file graph_inset.cpp.

00309   {
00310     closed = true;
00311   }
00312 
00313   void GraphInset::openGraph()
00314   {
00315     closed = false;
00316   }
00317 
00318   bool GraphInset::writeCSV(const QString& filename)
00319   {
00320     QFile f(filename);
00321     if(!f.open(QIODevice::WriteOnly))
00322     {
00323       cerr << "Error, cannot open file " << filename.toStdString() << " for writing" << endl;
00324       return false;
00325     }
00326     QTextStream ts(&f);
00327     ts << "Time";
00328     for(size_t i = 0 ; i < _numberOfLines ; ++i)
00329     {
00330       ts << ",Data" << i;
00331     }
00332     ts << ",Source Changed\r\n";


Member Data Documentation

Number of lines drawn by the graph.

Definition at line 299 of file graph_inset.h.

Referenced by addData(), numberOfLines(), and readParms().

Automatically open/close the graph.

Graph is opened as soon as some data is added to it.

Graph is closed when the data set is empty.

Definition at line 420 of file graph_inset.h.

Referenced by cleanData().

Color of the back of the graph.

If negative, the background will be transparent

Definition at line 328 of file graph_inset.h.

Offset to draw the background of the graph.

Definition at line 386 of file graph_inset.h.

Color of the line used to indicate a data change (typically if the data correspond to another cell).

Definition at line 375 of file graph_inset.h.

Offset to draw the data source change line.

Definition at line 396 of file graph_inset.h.

Referenced by drawWithName().

Width of the line used to indicate a data change (typically if the data correspond to another cell).

Definition at line 381 of file graph_inset.h.

bool util::GraphInset::closed [protected]

State if the graph window should be closed.

Definition at line 309 of file graph_inset.h.

Referenced by graphClosed().

Color of the contour.

Definition at line 348 of file graph_inset.h.

Offset to draw the contour of the graph.

Definition at line 391 of file graph_inset.h.

Width of the line used for the contour.

Definition at line 353 of file graph_inset.h.

std::list<Data> util::GraphInset::data [protected]

Data to be draw.

Definition at line 314 of file graph_inset.h.

Referenced by cleanData(), and size().

Check the system is correctly initialized.

Definition at line 304 of file graph_inset.h.

Order the object to keep all the data.

Definition at line 411 of file graph_inset.h.

std::vector<int> util::GraphInset::linesColor

Color of the lines.

Definition at line 333 of file graph_inset.h.

Referenced by readParms().

Extrema value shown for each line.

Definition at line 343 of file graph_inset.h.

Referenced by readParms().

std::vector<double> util::GraphInset::linesOffset

Offset to draw the lines.

Definition at line 401 of file graph_inset.h.

Referenced by readParms().

std::vector<double> util::GraphInset::linesWidth

Width of the lines.

Definition at line 338 of file graph_inset.h.

Referenced by readParms().

If true, show all the data.

Definition at line 425 of file graph_inset.h.

Referenced by readParms().

std::vector<size_t> util::GraphInset::showIndices

If not showing all data, contains the indices to show.

Definition at line 430 of file graph_inset.h.

Referenced by readParms().

Time of the system.

Definition at line 406 of file graph_inset.h.

Referenced by cleanData(), drawWithName(), and setTime().

Time span to keep the data.

Definition at line 321 of file graph_inset.h.

Position of the top-left corner of the graph window in pixels.

(0,0) is the top-left corner of the screen.

Negative values are considered distance from the bottom-right corner. Positives and negatives values can be mixed (i.e. (-100,30) = 100 pixel from the right, 30 pixels from the top)

Definition at line 364 of file graph_inset.h.

Referenced by readParms().

Size of the graph window in pixels.

Definition at line 369 of file graph_inset.h.

Referenced by readParms().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:38:29 2013 for VVE by  doxygen 1.6.3