COPASI API  4.16.103
CopasiPlot.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2003 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 // the plot object for COPASI
16 
17 #ifndef COPASIPLOT_H
18 #define COPASIPLOT_H
19 
20 #include <string>
21 #include <vector>
22 #include <fstream>
23 #include <iostream>
24 
25 #include <QtGui/QPainter>
26 #include <QtCore/QMutex>
27 #include <QtCore/QWaitCondition>
28 
29 #include <qwt_plot.h>
30 #include <qwt_painter.h>
31 #include <qwt_data.h>
32 #include <qwt_plot_curve.h>
33 
34 #include "plot/CPlotItem.h"
35 
36 #include "report/CCopasiObject.h"
38 #include "utilities/CopasiTime.h"
39 #include "utilities/CVector.h"
40 
41 // NaN are ignored bounding rectangle
42 class C2DCurveData : public QwtData
43 {
44 public:
45  C2DCurveData();
46  C2DCurveData(const CVector< double > & x, const CVector< double > & y, size_t size);
47  virtual ~C2DCurveData();
48 
49  virtual QwtData *copy() const;
50 
51  virtual size_t size() const;
52 
53  virtual double x(size_t i) const;
54  virtual double y(size_t i) const;
55 
56  virtual QwtDoubleRect boundingRect() const;
57 
58  void setSize(const size_t & size);
59 
60  void reallocated(const CVector< double > * pX, const CVector< double > * pY);
61 
62 protected:
64 
65 private:
66  const double * mpX;
67  const double * mpY;
68  size_t mSize;
69  size_t mMaxSize;
70 
71  mutable size_t mLastRectangle;
72  mutable double mMinX;
73  mutable double mMaxX;
74  mutable double mMinY;
75  mutable double mMaxY;
76 };
77 
78 class CBandedGraphData : public QwtData
79 {
80 public:
83  const CVector< double > & y1,
84  const CVector< double > & y2,
85  size_t size);
86  virtual ~CBandedGraphData();
87 
88  virtual QwtData *copy() const;
89 
90  virtual size_t size() const;
91 
92  virtual double x(size_t i) const;
93  virtual double y(size_t i) const;
94  double y1(size_t i) const;
95  double y2(size_t i) const;
96 
97  virtual QwtDoubleRect boundingRect() const;
98 
99  void setSize(const size_t & size);
100 
101  void reallocated(const CVector< double > * pX, const CVector< double > * pY1, const CVector< double > * pY2);
102 
103 protected:
105 
106 private:
107  const double * mpX;
108  const double * mpY1;
109  const double * mpY2;
110 
111  size_t mSize;
112  size_t mMaxSize;
113 
114  mutable size_t mLastRectangle;
115  mutable double mMinX;
116  mutable double mMaxX;
117  mutable double mMinY;
118  mutable double mMaxY;
119 };
120 
121 class CHistoCurveData : public QwtData
122 {
123 public:
124  CHistoCurveData();
125  CHistoCurveData(const CVector< double > & x, size_t size,
126  const C_FLOAT64 & increment);
127  virtual ~CHistoCurveData();
128 
129  virtual QwtData *copy() const;
130 
131  virtual size_t size() const;
132 
133  virtual double x(size_t i) const;
134  virtual double y(size_t i) const;
135 
136  virtual QwtDoubleRect boundingRect() const;
137 
138  void setSize(const size_t & size);
139 
140  void reallocated(const CVector< double > * pX);
141 
142 protected:
144 
145 private:
146  const double * mpX;
147  size_t mSize;
148  size_t mMaxSize;
149 
150  mutable size_t mLastRectangle;
151  mutable double mMinX;
152  mutable double mMaxX;
153  mutable double mMinY;
154  mutable double mMaxY;
155 
156  double mIncrement;
157 
158  mutable std::map<C_INT32, C_INT32> mMap;
161 };
162 
163 // NaN in data splits curve
164 class C2DPlotCurve : public QwtPlotCurve
165 {
166 public:
167  C2DPlotCurve(QMutex * pMutex, const CPlotItem::Type & type,
168  const COutputInterface::Activity & activity, const QString & title):
169  QwtPlotCurve(title),
170  mpMutex(pMutex),
171  mCurveType(type),
172  mIncrement(1.0),
173  mActivity(activity)
174  {
175  assert(mpMutex != NULL);
176  }
177 
178  void setDataSize(const size_t & size);
179 
180  void reallocatedData(const CVector< double > * pX, const CVector< double > * pY, const CVector< double > * pY2 = 0);
181 
182  void setIncrement(const C_FLOAT64 & increment);
183 
184  const C_FLOAT64 & getIncrement() const;
185 
186  const CPlotItem::Type & getType() const;
187 
188  const COutputInterface::Activity & getActivity() const;
189 
190 protected:
191  void myDrawLines(QPainter *painter,
192  const QwtScaleMap &xMap, const QwtScaleMap &yMap,
193  int from, int to) const;
194 
195  //Reroute curve plotting to our own routine
196  virtual void drawCurve(QPainter *painter, int style,
197  const QwtScaleMap &xMap, const QwtScaleMap &yMap,
198  int from, int to) const;
199 
200  //Reroute drawing to our own routine, mainly to disable plotting of NaN values.
201  virtual void drawSymbols(QPainter *painter, const QwtSymbol &symbol,
202  const QwtScaleMap &xMap, const QwtScaleMap &yMap,
203  int from, int to) const;
204 
205 private:
206  QMutex * mpMutex;
207 
209 
211 
213 };
214 
215 //*******************************************************
216 
217 class CPlotSpec2Vector;
218 class CPlotSpecification;
219 class QwtPlotZoomer;
220 
221 class CopasiPlot : public QwtPlot, public COutputInterface
222 {
223  Q_OBJECT
224 private:
225  /**
226  * Default constructor which may never be called.
227  * @param QWidget* parent (default: NULL)
228  */
229  CopasiPlot(QWidget* parent = NULL);
230 
231 public:
232  /**
233  * Specific constructor
234  * @param const CPlotSpecification* plotspec
235  * @param QWidget* parent (default: NULL)
236  */
237  CopasiPlot(const CPlotSpecification* plotspec, QWidget* parent = NULL);
238 
239  /**
240  * Initialize the the plot from the specification
241  * @param const CPlotSpecification* plotspec
242  */
243  bool initFromSpec(const CPlotSpecification* plotspec);
244 
245  /**
246  * Destructor
247  */
248  virtual ~CopasiPlot();
249 
250  /**
251  * compile the object list from name vector
252  * @param std::vector< CCopasiContainer * > listOfContainer
253  * @param const CCopasiDataModel* pDataModel
254  * @return bool success
255  */
256  virtual bool compile(std::vector< CCopasiContainer * > listOfContainer, const CCopasiDataModel* pDataModel);
257 
258  /**
259  * Perform an output event for the current activity
260  * @param const Activity & activity
261  */
262  virtual void output(const Activity & activity);
263 
264  /**
265  * Introduce an additional separator into the output
266  * @param const Activity & activity
267  */
268  virtual void separate(const Activity & activity);
269 
270  /**
271  * Finish the output
272  */
273  virtual void finish();
274 
275  /**
276  * Save tab delimited data to file
277  * @param const std::string & filename
278  * @return bool success
279  */
280  bool saveData(const std::string & filename);
281 
282  /**
283  * Shows or hide all curves depending on whether visibility is false or true
284  * @param const bool & visibility
285  */
286  void setCurvesVisibility(const bool & visibility);
287 
288 public slots:
289  virtual void replot();
290 
291 private:
292  /**
293  * Tell the curves where the data is located. It must be called
294  * after reallocating the memory for the curve data.
295  */
296  void updateCurves(const size_t & activity);
297 
298  /**
299  * Resize the curve data
300  */
301  void resizeCurveData(const size_t & activity);
302 
303  /**
304  * Redraw the plot
305  */
306  void updatePlot();
307 
308  /**
309  * Clear all allocate buffers and set reset values
310  */
311  void clearBuffers();
312 
313  /**
314  * Set the units of the indexed axis based on the
315  * type of the object.
316  * @param const C_INT32 & index
317  * @param const CCopasiObject * pObject
318  */
319  void setAxisUnits(const C_INT32 & index,
320  const CCopasiObject * pObject);
321 
322 private slots:
323  /**
324  * Slot used to turn curves on and of through the legend buttons.
325  * @param QwtPlotItem *item
326  * @param bool on
327  */
328  void showCurve(QwtPlotItem *item, bool on);
329 
330 private:
331  /**
332  * The value for missing objects
333  */
335 
336  /**
337  * Mutex preventing access to data during reallocation.
338  */
339  QMutex mMutex;
340 
341  /**
342  * Vector that contains pointers to vectors of data in the selected columns.
343  */
344  std::vector< std::vector< CVector< double > * > > mData;
345 
346  /**
347  * Vector of pointers to the current object values
348  */
349  std::vector< std::vector< const C_FLOAT64 * > > mObjectValues;
350 
351  /**
352  * Vector of bool indicating whether the current object value is integer
353  */
354  std::vector< std::vector< bool > > mObjectInteger;
355 
356  /**
357  * The order of 2d curve objects used when the data is saved.
358  * The first object in each vector is the object for the X axis.
359  */
360  std::vector< std::vector < const CCopasiObject * > > mSaveCurveObjects;
361 
362  /**
363  * The order of histogram objects used when the data is saved.
364  */
365  std::vector< const CCopasiObject * > mSaveHistogramObjects;
366 
367  /**
368  * Vector of actual data lines in the local buffers
369  */
370  std::vector< size_t > mDataSize;
371 
372  /**
373  * Map curve and channel to index pair indicating where the data is stored.
374  */
375  std::vector< std::vector< std::pair < Activity, size_t > > > mDataIndex;
376 
377  /**
378  * Map activity and object to index indicating where data is stored within
379  * the current activity.
380  */
381  std::map< Activity, std::map< const CCopasiObject *, size_t > > mObjectIndex;
382 
383  /**
384  * The list of curves
385  */
387 
388  /**
389  * A map between a specification identified by its key and a curve
390  */
391  std::map< std::string, C2DPlotCurve * > mCurveMap;
392 
393  /**
394  * Vector of the activity of each item (curve)
395  */
396  // std::vector<Activity> mCurveActivities;
397 
398  /**
399  * Map of curve to the index to the corresponding histogram.
400  */
401  //std::vector<size_t> mHistoIndices;
402 
403  /**
404  * Count of data lines recorded during activity BEFORE.
405  */
406  size_t mDataBefore;
407 
408  /**
409  * Count of data lines recorded during activity DURING.
410  */
411  size_t mDataDuring;
412 
413  /**
414  * Count of data lines recorded during activity AFTER.
415  */
416  size_t mDataAfter;
417 
418  /**
419  * Flag indicating whether there are any curves recording
420  * data during activity BEFORE.
421  */
423 
424  /**
425  * Flag indicating whether there are any curves recording
426  * data during activity DURING.
427  */
429 
430  /**
431  * Flag indicating whether there are any curves recording
432  * data during activity AFTER.
433  */
435 
436  /**
437  * Pointer to the specification for the plot.
438  */
440 
441  /**
442  * The next time a plot update is performed
443  */
445 
446  /**
447  * Indicates whether redrawing/updating shall be suppressed during initialization.
448  */
450 
451 public:
452  /**
453  * Pointer to the zooming engine for the plot.
454  */
455  QwtPlotZoomer * mpZoomer;
456 
457 protected:
459 
460 signals:
461  void replotSignal();
462 };
463 
464 #endif // COPASIPLOT_H
std::vector< size_t > mDataSize
Definition: CopasiPlot.h:370
CPlotItem::Type mCurveType
Definition: CopasiPlot.h:208
virtual size_t size() const
Definition: CopasiPlot.cpp:474
void resizeCurveData(const size_t &activity)
CVector< double > mHistoX
Definition: CopasiPlot.h:159
static C_FLOAT64 MissingValue
Definition: CopasiPlot.h:334
CBandedGraphData & operator=(const CBandedGraphData &rhs)
Definition: CopasiPlot.cpp:409
virtual void separate(const Activity &activity)
void setIncrement(const C_FLOAT64 &increment)
Definition: CopasiPlot.cpp:647
size_t mDataAfter
Definition: CopasiPlot.h:416
CopasiPlot(QWidget *parent=NULL)
Definition: CopasiPlot.cpp:762
bool mHaveBefore
Definition: CopasiPlot.h:422
virtual ~CHistoCurveData()
Definition: CopasiPlot.cpp:462
double mMinX
Definition: CopasiPlot.h:72
const CPlotSpecification * mpPlotSpecification
Definition: CopasiPlot.h:439
virtual double x(size_t i) const
Definition: CopasiPlot.cpp:479
virtual size_t size() const
Definition: CopasiPlot.cpp:84
virtual QwtDoubleRect boundingRect() const
Definition: CopasiPlot.cpp:489
std::map< std::string, C2DPlotCurve * > mCurveMap
Definition: CopasiPlot.h:391
bool mIgnoreUpdate
Definition: CopasiPlot.h:449
double y2(size_t i) const
Definition: CopasiPlot.cpp:291
void setSize(const size_t &size)
Definition: CopasiPlot.cpp:566
void setCurvesVisibility(const bool &visibility)
double y1(size_t i) const
Definition: CopasiPlot.cpp:286
virtual double y(size_t i) const
Definition: CopasiPlot.cpp:272
std::vector< std::vector< const CCopasiObject * > > mSaveCurveObjects
Definition: CopasiPlot.h:360
virtual QwtDoubleRect boundingRect() const
Definition: CopasiPlot.cpp:297
double mMaxY
Definition: CopasiPlot.h:75
size_t mDataBefore
Definition: CopasiPlot.h:406
#define C_INT32
Definition: copasi.h:90
CHistoCurveData & operator=(const CHistoCurveData &rhs)
Definition: CopasiPlot.cpp:580
size_t mSize
Definition: CopasiPlot.h:68
std::vector< std::vector< bool > > mObjectInteger
Definition: CopasiPlot.h:354
virtual QwtData * copy() const
Definition: CopasiPlot.cpp:465
virtual QwtDoubleRect boundingRect() const
Definition: CopasiPlot.cpp:99
const CPlotItem::Type & getType() const
Definition: CopasiPlot.cpp:657
void setSize(const size_t &size)
Definition: CopasiPlot.cpp:179
void updatePlot()
virtual void replot()
virtual ~CopasiPlot()
bool mHaveDuring
Definition: CopasiPlot.h:428
void setAxisUnits(const C_INT32 &index, const CCopasiObject *pObject)
void updateCurves(const size_t &activity)
void reallocated(const CVector< double > *pX)
Definition: CopasiPlot.cpp:572
virtual double x(size_t i) const
Definition: CopasiPlot.cpp:89
virtual bool compile(std::vector< CCopasiContainer * > listOfContainer, const CCopasiDataModel *pDataModel)
const C_FLOAT64 & getIncrement() const
Definition: CopasiPlot.cpp:652
CVector< double > mHistoY
Definition: CopasiPlot.h:160
void reallocated(const CVector< double > *pX, const CVector< double > *pY)
Definition: CopasiPlot.cpp:185
std::vector< std::vector< std::pair< Activity, size_t > > > mDataIndex
Definition: CopasiPlot.h:375
std::map< Activity, std::map< const CCopasiObject *, size_t > > mObjectIndex
Definition: CopasiPlot.h:381
const double * mpX
Definition: CopasiPlot.h:107
QMutex mMutex
Definition: CopasiPlot.h:339
double mMinY
Definition: CopasiPlot.h:74
QwtPlotZoomer * mpZoomer
Definition: CopasiPlot.h:455
const double * mpY
Definition: CopasiPlot.h:67
std::vector< std::vector< const C_FLOAT64 * > > mObjectValues
Definition: CopasiPlot.h:349
virtual double y(size_t i) const
Definition: CopasiPlot.cpp:484
void setDataSize(const size_t &size)
Definition: CopasiPlot.cpp:602
size_t mLastRectangle
Definition: CopasiPlot.h:71
const double * mpX
Definition: CopasiPlot.h:66
void reallocated(const CVector< double > *pX, const CVector< double > *pY1, const CVector< double > *pY2)
Definition: CopasiPlot.cpp:399
QMutex * mpMutex
Definition: CopasiPlot.h:206
COutputInterface::Activity mActivity
Definition: CopasiPlot.h:212
size_t mLastRectangle
Definition: CopasiPlot.h:150
CVector< C2DPlotCurve * > mCurves
Definition: CopasiPlot.h:386
virtual ~C2DCurveData()
Definition: CopasiPlot.cpp:72
virtual QwtData * copy() const
Definition: CopasiPlot.cpp:75
std::vector< std::vector< CVector< double > * > > mData
Definition: CopasiPlot.h:344
void replotSignal()
void clearBuffers()
double mIncrement
Definition: CopasiPlot.h:156
virtual double y(size_t i) const
Definition: CopasiPlot.cpp:94
std::map< C_INT32, C_INT32 > mMap
Definition: CopasiPlot.h:158
C2DPlotCurve(QMutex *pMutex, const CPlotItem::Type &type, const COutputInterface::Activity &activity, const QString &title)
Definition: CopasiPlot.h:167
std::vector< const CCopasiObject * > mSaveHistogramObjects
Definition: CopasiPlot.h:365
void setSize(const size_t &size)
Definition: CopasiPlot.cpp:392
C2DCurveData & operator=(const C2DCurveData &rhs)
Definition: CopasiPlot.cpp:194
void showCurve(QwtPlotItem *item, bool on)
const double * mpX
Definition: CopasiPlot.h:146
bool mReplotFinished
Definition: CopasiPlot.h:458
virtual void drawCurve(QPainter *painter, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
Definition: CopasiPlot.cpp:698
#define C_FLOAT64
Definition: copasi.h:92
size_t mDataDuring
Definition: CopasiPlot.h:411
bool initFromSpec(const CPlotSpecification *plotspec)
Definition: CopasiPlot.cpp:836
virtual double x(size_t i) const
Definition: CopasiPlot.cpp:262
virtual ~CBandedGraphData()
Definition: CopasiPlot.cpp:245
virtual QwtData * copy() const
Definition: CopasiPlot.cpp:249
bool saveData(const std::string &filename)
const double * mpY2
Definition: CopasiPlot.h:109
size_t mMaxSize
Definition: CopasiPlot.h:69
bool mHaveAfter
Definition: CopasiPlot.h:434
void reallocatedData(const CVector< double > *pX, const CVector< double > *pY, const CVector< double > *pY2=0)
Definition: CopasiPlot.cpp:624
virtual size_t size() const
Definition: CopasiPlot.cpp:259
size_t mLastRectangle
Definition: CopasiPlot.h:114
const COutputInterface::Activity & getActivity() const
Definition: CopasiPlot.cpp:662
virtual void finish()
virtual void output(const Activity &activity)
double mMaxX
Definition: CopasiPlot.h:73
C_FLOAT64 mIncrement
Definition: CopasiPlot.h:210
void myDrawLines(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
Definition: CopasiPlot.cpp:668
const double * mpY1
Definition: CopasiPlot.h:108
virtual void drawSymbols(QPainter *painter, const QwtSymbol &symbol, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
Definition: CopasiPlot.cpp:714
CCopasiTimeVariable mNextPlotTime
Definition: CopasiPlot.h:444