MeVisLab Toolbox Reference
mlCurveData.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_CURVE_DATA_H
14 #define ML_CURVE_DATA_H
15 
16 
20 
21 // ML includes
22 #include <mlRefCountedBase.h>
23 #include <mlTreeNode.h>
24 
25 
26 #include "mlBaseInit.h"
27 #include "mlBaseList.h"
28 
29 
30 ML_START_NAMESPACE
31 
32 
33 // --- Type definitions
34 
36 typedef std::vector<double> CurveSeries;
37 
38 
39 
40 // ------------------------------------------------------------------
41 // Base object class CurveData
42 
54 // ------------------------------------------------------------------
56 {
57 protected:
59  ~CurveData() override = default;
60 
61 public:
62 
64  enum { ctyLine,
68  ctyErrorBar
69  };
70 
71 
72  // --------------------------------------------
74  // --------------------------------------------
76 
80  CurveData (const CurveData &curveData);
81 
83  CurveData &operator = (const CurveData &srcCurve);
84 
86 
87  friend bool operator==(const CurveData& x, const CurveData& y);
88  friend bool operator!=(const CurveData& x, const CurveData& y);
89 
90 
91  // --------------------------------------------
93  // --------------------------------------------
95 
97  void clearData ();
99  void clear ();
100 
106  void setX (MLssize_t nPoints = 0, const double *data = nullptr, MLssize_t step = 1);
107  void setX (MLssize_t nPoints, const float *data, MLssize_t step = 1);
108 
114  void setY (MLssize_t nPoints, const double *data, MLssize_t step = 1);
115  void setY (MLssize_t nPoints, const float *data, MLssize_t step = 1);
116 
122  void setY (MLssize_t iSeries, MLssize_t nPoints, const double *data, MLssize_t step = 1);
123  void setY (MLssize_t iSeries, MLssize_t nPoints, const float *data, MLssize_t step = 1);
124 
126  void setXValue (double value, MLssize_t iPoint);
129  void setYValue (double value, MLssize_t iSeries, MLssize_t iPoint);
131  void setYValue (double value, MLssize_t iPoint);
132 
134  void resizeX(MLssize_t nPoints);
136  void resizeY(MLssize_t nPoints);
138  void resizeY(MLssize_t iSeries, MLssize_t nPoints);
139 
141 
142 
143  // --------------------------------------------
145  // --------------------------------------------
147 
152 
154  double getXValue (MLssize_t iPoint);
156  double getYValue (MLssize_t iSeries, MLssize_t iPoint);
158  double getYValue (MLssize_t iPoint);
159 
161 
162 
163  // --------------------------------------------
165  // --------------------------------------------
167 
169  void setXRange (double xMin, double xMax);
171  void setAutoXRange ();
173  void setYRange (double yMin, double yMax);
175  void setAutoYRange ();
176 
178  void setCurveType (int type);
180  void setCurveStyle (int style);
182  void setId(MLssize_t id);
183 
185  void setTitle (std::string title);
187  void setUnit (std::string unit);
189  void setSymbol (std::string symbol);
190 
192 
193 
194  // --------------------------------------------
196  // --------------------------------------------
198 
200  bool isAutoX () const { return _autoX; }
201 
203  double getXMin ();
205  double getXMax ();
207  double getYMin ();
209  double getYMax ();
211  void getXYRange (double *xMin, double *xMax, double *yMin, double *yMax);
212 
214  int getCurveType () const;
216  int getCurveStyle () const;
218  MLssize_t getId() const;
219 
221  std::string getTitle () const;
223  std::string getUnit () const;
225  std::string getSymbol () const;
226 
228 
230  void addStateToTree(TreeNode* /*parent*/) const override;
231 
233  void readStateFromTree(TreeNode* /*parent*/) override;
234 
235  // set current version number
237 
239  CurveData* deepCopy() const override { return new CurveData(*this); };
240 
241 protected:
242 
244  void setXChanged ();
246  void setYChanged ();
247 
249  void setSeries (CurveSeries &v, MLssize_t nPoints, const double *data, MLssize_t step);
251  void setSeries (CurveSeries &v, MLssize_t nPoints, const float *data, MLssize_t step);
252 
253 
254 protected:
256  void updateAutoX ();
258  void updateXRange ();
260  void updateYRange ();
261 
262 protected:
266  std::vector<CurveSeries> _yData;
267 
269  bool _autoX;
270 
275 
280 
282  double _xMin, _xMax,
283  _yMin, _yMax;
285 
292 
294  std::string _title;
296  std::string _unit;
298  std::string _symbol;
299 
300 
303 };
304 
306 
307 ML_END_NAMESPACE
308 
309 #endif
310 // __mlCurveData_H
311 
Base object class representing a single curve object, consisting of zero or one X- and any number of ...
Definition: mlCurveData.h:56
void setYRange(double yMin, double yMax)
Explicitly set Y value range to yMin ... yMax.
double getXMin()
Get minimum X data value.
void clearData()
Clear curve data.
double getYMax()
Get maximum Y data value.
MLssize_t getPoints()
Get number of data points (i.e. minimum length of all X- and Y-series)
CurveSeries _xData
X series data.
Definition: mlCurveData.h:264
bool _autoXRange
Flag for automatic X value ranges.
Definition: mlCurveData.h:272
void setId(MLssize_t id)
Set (numeric) id.
std::string _title
Curve title.
Definition: mlCurveData.h:294
int getCurveStyle() const
Get curve style (= index into a style palette used for drawing)
ML_SET_ADDSTATE_VERSION(1)
void setYValue(double value, MLssize_t iPoint)
Set Y value at index iPoint in first Y series to value (ignored if index is out of range).
std::vector< CurveSeries > _yData
Y series data.
Definition: mlCurveData.h:266
bool _autoYRange
Flag for automatic Y value ranges.
Definition: mlCurveData.h:274
bool _validXRange
Flag indicating up-to-date X range values.
Definition: mlCurveData.h:277
int _curveType
Curve type (equal to one of the cty* curve type constants)
Definition: mlCurveData.h:287
void updateXRange()
Update automatically generated X range.
double getYValue(MLssize_t iSeries, MLssize_t iPoint)
Get Y value at index iPoint in iSeries-th Y series, 0 if out of range.
void setCurveType(int type)
Set curve type (use cty* curve type constants)
void setY(MLssize_t nPoints, const double *data, MLssize_t step=1)
Set Y data to a single series of nPoints double values copied from the source array data.
void readStateFromTree(TreeNode *) override
Reads the object state from the children of the given parent node.
void setX(MLssize_t nPoints, const float *data, MLssize_t step=1)
MLssize_t _id
Curve id.
Definition: mlCurveData.h:291
void clear()
Clear curve data and reset curve properties.
void setAutoXRange()
Set X value range to 'automatic', i.e. dependent on X series data.
std::string getUnit() const
Get curve unit.
double getYMin()
Get minimum Y data value.
void setXValue(double value, MLssize_t iPoint)
Set X-series value at index iPoint to value (ignored if index is out of range).
void resizeX(MLssize_t nPoints)
Change length of X-series. New values are initialized to zero.
void setXRange(double xMin, double xMax)
Explicitly set X value range to xMin ... xMax.
MLssize_t getId() const
Get numeric id.
int getCurveType() const
Get curve type (equal to one of the cty* curve type constants)
void addStateToTree(TreeNode *) const override
Attaches the object state as children of the given parent node.
void setY(MLssize_t iSeries, MLssize_t nPoints, const float *data, MLssize_t step=1)
double getXMax()
Get maximum X data value.
void setX(MLssize_t nPoints=0, const double *data=nullptr, MLssize_t step=1)
Set X-series to nPoints double values copied from the source array data.
@ ctyLineDeltaArea
Line and shaded area between two lines, represented by a triple of Y-series.
Definition: mlCurveData.h:67
@ ctyDeltaArea
Shaded area between two lines, represented by a pair of Y-series.
Definition: mlCurveData.h:66
@ ctyArea
Shaded area under/above single line.
Definition: mlCurveData.h:65
@ ctyLine
Single line, represented by a single Y-series.
Definition: mlCurveData.h:64
double getXValue(MLssize_t iPoint)
Get X-value at index iPoint, return 0 if index is out of range.
void setXChanged()
Invalidate automatic X series properties.
void setY(MLssize_t iSeries, MLssize_t nPoints, const double *data, MLssize_t step=1)
Set the iSeries-th Y-series to nPoints double values copied from the source array data.
bool _validYRange
Flag indicating up-to-date Y range values.
Definition: mlCurveData.h:279
bool isAutoX() const
Return true if X data is generated automatically (numbered 0, 1, ...)
Definition: mlCurveData.h:200
void setAutoYRange()
Set Y value range to 'automatic', i.e. dependent on Y series data.
CurveData(const CurveData &curveData)
Copy constructor, series data is copied.
int _curveStyle
Curve style (= index into a style palette used for drawing)
Definition: mlCurveData.h:289
void resizeY(MLssize_t iSeries, MLssize_t nPoints)
Change length of iSeries-th Y-series. New values are initialized to zero.
std::string getSymbol() const
Get curve symbol.
CurveData()
Default constructor.
friend bool operator==(const CurveData &x, const CurveData &y)
void setY(MLssize_t nPoints, const float *data, MLssize_t step=1)
void updateYRange()
Update automatically generated Y range.
void setYValue(double value, MLssize_t iSeries, MLssize_t iPoint)
Set Y value at index iPoint in iSeries-th Y series to value (ignored if indices are out of range).
void updateAutoX()
Update automatically generated X data.
void getXYRange(double *xMin, double *xMax, double *yMin, double *yMax)
Get X and Y value ranges (NULL pointers are allowed)
double getYValue(MLssize_t iPoint)
Get Y value at index iPoint in first Y series, 0 if out of range.
void setSymbol(std::string symbol)
Set curve symbol.
void setUnit(std::string unit)
Set curve unit.
friend bool operator!=(const CurveData &x, const CurveData &y)
void setSeries(CurveSeries &v, MLssize_t nPoints, const double *data, MLssize_t step)
Set series data (double)
std::string _symbol
Curve symbol.
Definition: mlCurveData.h:298
void setSeries(CurveSeries &v, MLssize_t nPoints, const float *data, MLssize_t step)
Set series data (float)
void setTitle(std::string title)
Set curve title.
~CurveData() override=default
Destructor shouldn't be called directly anymore, always use the CurveDataPtr smart-pointer.
MLssize_t getNumSeries()
Get number of Y-series.
void resizeY(MLssize_t nPoints)
Change length of first Y-series. New values are initialized to zero.
void setYChanged()
Invalidate automatic Y series properties.
std::string _unit
Curve unit.
Definition: mlCurveData.h:296
bool _autoX
Flag for automatically generated X data.
Definition: mlCurveData.h:269
void setCurveStyle(int style)
Set curve style (= index into a style palette used for drawing)
std::string getTitle() const
Get curve title.
CurveData * deepCopy() const override
Create a deep copy of the CurveDate.
Definition: mlCurveData.h:239
RefCountedBase class adds intrusive reference counting support to the Base class.
The class TreeNode is the abstract base class for the import/export of ML objects.
Definition: mlTreeNode.h:154
#define MLBASEEXPORT
defined Header file mlBaseInit.h
Definition: mlBaseInit.h:22
#define ML_REFCOUNTED_PTR(CLASSNAME)
Macro that defines convenience Ptr/ConstPtr typedefs to be used instead of intrusive_ptr templates.
#define ML_CLASS_HEADER(className)
Same like ML_CLASS_HEADER_EXPORTED with a non-existing export symbol.
SSIZE_T MLssize_t
The signed ML size type that is a signed 32-bit size_t on 32-bit platforms and 64-bit one on 64-bit p...
Definition: mlTypeDefs.h:566
std::vector< double > CurveSeries
Type definition of a standard vector of single series of X- or Y-values.
Definition: mlCurveData.h:36