cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vctPlot2DBase.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Anton Deguet
7  Created on: 2010-05-05
8 
9  (C) Copyright 2010-2013 Johns Hopkins University (JHU), All Rights Reserved.
10 
11 --- begin cisst license - do not edit ---
12 
13 This software is provided "as is" under an open source license, with
14 no warranty. The complete license can be found in license.txt and
15 http://www.cisst.org/cisst/license.txt.
16 
17 --- end cisst license ---
18 */
19 
20 #ifndef _vctPlot2DBase_h
21 #define _vctPlot2DBase_h
22 
23 #include <map>
24 #include <string>
25 
29 
30 // Always include last
31 #include <cisstVector/vctExport.h>
32 
45 {
46 
47  public:
48 
49  class Scale;
50 
56  {
57  friend class vctPlot2DBase;
58  friend class vctPlot2DBase::Scale;
59  friend class vctPlot2DOpenGL;
60  friend class vctPlot2DVTK;
61  public:
62  Signal(const std::string & name, size_t numberOfPoints, size_t pointDimension = 2);
63  ~Signal();
64 
65  // see AppendPoint
66  void CISST_DEPRECATED AddPoint(const vctDouble2 & point);
67 
71  void AppendPoint(const vctDouble2 & point);
72 
76  vctDouble2 GetPointAt(size_t index) throw (std::runtime_error);
77 
81  void SetPointAt(size_t index, const vctDouble2 & point) throw (std::runtime_error);
82 
88  void SetArrayAt(size_t index, const double * pointArray, size_t arraySize, size_t pointDimension = 2) throw (std::runtime_error);
89 
95  bool PrependArray(const double * pointArray, size_t arraySize, size_t pointDimension = 2) throw (std::runtime_error);
96 
102  bool AppendArray(const double * pointArray, size_t arraySize, size_t pointDimension = 2) throw (std::runtime_error);
103 
104  void Freeze(bool freeze);
105  bool GetFreeze(void) const;
106 
110  void ComputeDataRangeX(double & min, double & max, bool assumesDataSorted = false) const;
111  void ComputeDataRangeY(double & min, double & max) const;
112  void ComputeDataRangeXY(vctDouble2 & min, vctDouble2 & max) const;
114 
115  void CISST_DEPRECATED SetNumberOfPoints(size_t numberOfPoints);
116  void CISST_DEPRECATED GetNumberOfPoints(size_t & numberOfPoints, size_t & bufferSize) const;
117 
119  size_t GetSize(void) const;
120 
122  size_t GetNumberOfPoints(void) const;
123 
124  void SetColor(const vctDouble3 & colorInRange0To1);
125 
129  void SetSize(size_t numberOfPoints);
130 
131  bool IsVisible(void) const;
132  void SetVisible(const bool visible);
133 
137  void Resize(size_t numberOfPoints, bool trimOlder = true);
138 
139  /* Helper Function */
140  vctPlot2DBase::Signal * AddSignal(const std::string & name);
141  vctPlot2DBase::Scale * GetParent(void);
142  const std::string & GetName(void) const;
143 
144  protected:
145  Scale * Parent;
147  std::string Name;
148  bool Empty;
149  bool Visible;
150  bool Frozen;
152  double * Buffer;
153  size_t PointSize;
155  typedef vctFixedSizeVectorRef<double, 2, 1> PointRef;
156  vctDynamicVector<PointRef> Data;
157  size_t IndexFirst;
158  size_t IndexLast;
159  vctDouble3 Color;
160  double LineWidth;
161  };
162 
165  {
166  friend class vctPlot2DBase;
167  friend class vctPlot2DOpenGL;
168  friend class vctPlot2DVTK;
169  public:
170  VerticalLine(const std::string & name, const double x = 0.0);
171  ~VerticalLine();
172 
173  void SetX(const double x);
174  void SetColor(const vctDouble3 & colorInRange0To1);
175 
176  protected:
177  std::string Name;
178  double X;
179  bool Visible;
181  double LineWidth;
182  };
183 
185  {
186  friend class vctPlot2DBase;
187  friend class vctPlot2DOpenGL;
188  friend class vctPlot2DVTK;
189  public:
190 
191  // keep signals in a std::map
192  typedef std::map<std::string, Signal *> SignalsType;
194 
195  // keep vertical lines in a std::map
196  typedef std::map<std::string, VerticalLine *> VerticalLinesType;
198 
199  Scale(const std::string & name, size_t pointDimension = 2);
200  ~Scale();
201 
202  const std::string & GetName(void) const;
203 
204  vctPlot2DBase::Signal * AddSignal(const std::string & name);
205  bool RemoveSignal(const std::string & name);
206  bool RemoveSignal(const Signal * signal);
207 
208  inline const SignalsType & GetSignals(void) const {
209  return Signals;
210  }
211 
212  vctPlot2DBase::VerticalLine * AddVerticalLine(const std::string & name);
213 
214  void SetColor(const vctDouble3 & colorInRange0To1);
215 
216  void Freeze(bool freeze);
217  bool GetFreeze(void) const;
218 
219  void ContinuousUpdate(void);
223  void SetContinuousFitX(bool fit);
224  void SetContinuousFitY(bool fit);
225  void SetContinuousExpandY(bool expand);
227 
229  inline bool GetContinuousFitX(void) const {
230  return ContinuousFitX;
231  }
232  inline bool GetContinuousFitY(void) const {
233  return ContinuousFitY;
234  }
235  inline bool GetContinuousExpandY(void) const {
236  return ContinuousExpandY;
237  }
238  const vctDouble2 & GetViewingRangeX(void) {
239  return this->ViewingRangeX;
240  }
241  const vctDouble2 & GetViewingRangeY(void) {
242  return this->ViewingRangeY;
243  }
245 
253  bool ComputeDataRangeX(double & min, double & max, bool assumesDataSorted = false) const;
254  bool ComputeDataRangeY(double & min, double & max);
255  bool ComputeDataRangeXY(vctDouble2 & min, vctDouble2 & max);
257 
267  void AutoFitX(double padding = 0.0);
268  void FitX(double min, double max, double padding = 0.0);
269  void AutoFitY(double padding = 0.1);
270  void AutoExpandY(double padding = 0.1);
271  void FitY(double min, double max, double padding = 0.1);
272  void AutoFitXY(const vctDouble2 & padding = vctDouble2(0.0, 0.1));
273  void AutoFitXExpandY(const vctDouble2 & padding = vctDouble2(0.0, 0.1));
274  void FitXY(vctDouble2 min, vctDouble2 max, const vctDouble2 & padding = vctDouble2(0.0, 0.1));
276 
277  protected:
281  double ExpandYMin, ExpandYMax;
282 
283  // viewport sizes
285  // stores the min and max corresponding to the viewport
286  vctDouble2 ViewingRangeX, ViewingRangeY;
289 
290 
291  private:
292  std::string Name;
293  size_t PointSize;
294  vctDouble3 Color;
295  double LineWidth;
296  };
297 
301  typedef std::map<std::string, Scale *> ScalesType;
303 
307  vctPlot2DBase::Scale * AddScale(const std::string & name);
308 
310  vctPlot2DBase::Scale * FindScale(const std::string & name);
311 
313  bool RemoveScale(const std::string & name);
314 
316  bool RemoveScale(const vctPlot2DBase::Scale * scale);
317 
319  inline ScalesType & GetScales(void) {
320  return Scales;
321  }
322 
323  vctPlot2DBase(size_t PointSize = 2);
324  virtual ~vctPlot2DBase();
325 
327  void SetNumberOfPoints(size_t numberOfPoints);
328 
334  Signal CISST_DEPRECATED * AddSignal(const std::string & name);
335 
341  VerticalLine CISST_DEPRECATED * AddVerticalLine(const std::string & name);
342 
352  void AutoFitX(double padding = 0.0);
353  void FitX(double min, double max, double padding = 0.0);
354  void AutoFitY(double padding = 0.1);
355  void FitY(double min, double max, double padding = 0.1);
357 
362  void Freeze(bool freeze);
363 
365  bool GetFreeze(void) const;
366 
369  void SetContinuousFitX(bool fit);
370  void SetContinuousFitY(bool fit);
371  void SetContinuousExpandY(bool expand);
373 
375  bool GetContinuousFitX(void) const;
376 
378  bool GetContinuousFitY(void) const;
379 
381  bool GetContinuousExpandY(void) const;
382 
383  //*! Get currently used viewing range */
385  inline const vctDouble2 & GetViewingRangeX(void) const {
386  return this->ViewingRangeX;
387  }
388  inline const vctDouble2 & GetViewingRangeY(void) const {
389  return this->ViewingRangeY;
390  }
392 
394  void SetBackgroundColor(const vctDouble3 & colorInRange0To1);
395 
396  protected:
397 
400  virtual void RenderInitialize(void) = 0;
401  virtual void RenderResize(double width, double height) = 0;
402  virtual void Render(void) = 0;
404 
405  protected:
408  size_t PointSize;
409 
410  // default number of points for all signals
412 
413  // viewport sizes
415  // stores the min and max corresponding to the viewport
416  vctDouble2 ViewingRangeX, ViewingRangeY;
417 
420  void ContinuousUpdate(void);
421 
422  // background color
424 };
425 
426 #endif // _vctPlot2DBase_h
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
bool Visible
Definition: vctPlot2DBase.h:179
A vector object of dynamic size.
Definition: vctDynamicVector.h:127
Typedef for dynamic vectors.
Definition: vctPlot2DBase.h:184
vctDouble2 ScaleValue
Definition: vctPlot2DBase.h:288
int CISST_EXPORT Resize(svlSampleImage *src_img, unsigned int src_videoch, svlSampleImage *dst_img, unsigned int dst_videoch, bool interpolation)
#define CISST_DEPRECATED
Definition: cmnPortability.h:310
bool GetContinuousFitY(void) const
Definition: vctPlot2DBase.h:232
bool ContinuousFitY
Definition: vctPlot2DBase.h:279
An implementation of the ``abstract'' vctFixedSizeVectorBase.
Definition: vctFixedSizeVectorRef.h:46
Definition: vctPlot2DBase.h:164
double ExpandYMin
Definition: vctPlot2DBase.h:281
const vctDouble2 & GetViewingRangeY(void) const
Definition: vctPlot2DBase.h:388
vctDouble3 BackgroundColor
Definition: vctPlot2DBase.h:423
const SignalsType & GetSignals(void) const
Definition: vctPlot2DBase.h:208
vctFixedSizeVector< double, 2 > vctDouble2
Definition: vctFixedSizeVectorTypes.h:40
Typedef for fixed size vectors.
std::map< std::string, VerticalLine * > VerticalLinesType
Definition: vctPlot2DBase.h:196
vctDouble2 Viewport
Definition: vctPlot2DBase.h:284
bool ContinuousExpandY
Definition: vctPlot2DBase.h:280
const vctDouble2 & GetViewingRangeY(void)
Definition: vctPlot2DBase.h:241
vctDouble3 Color
Definition: vctPlot2DBase.h:180
ScalesType Scales
Definition: vctPlot2DBase.h:302
vctDouble2 Translation
Definition: vctPlot2DBase.h:287
Declaration of vctDynamicVector.
std::map< std::string, Signal * > SignalsType
Definition: vctPlot2DBase.h:192
std::map< std::string, Scale * > ScalesType
Definition: vctPlot2DBase.h:301
size_t PointSize
Definition: vctPlot2DBase.h:408
const vctDouble2 & GetViewingRangeX(void)
Definition: vctPlot2DBase.h:238
bool GetContinuousFitX(void) const
Definition: vctPlot2DBase.h:229
VerticalLinesType VerticalLines
Definition: vctPlot2DBase.h:197
SignalsType Signals
Definition: vctPlot2DBase.h:193
double LineWidth
Definition: vctPlot2DBase.h:181
Definition: vctPlot2DOpenGL.h:29
double X
Definition: vctPlot2DBase.h:178
vctDouble2 Viewport
Definition: vctPlot2DBase.h:414
bool GetContinuousExpandY(void) const
Definition: vctPlot2DBase.h:235
vctDouble2 ViewingRangeY
Definition: vctPlot2DBase.h:286
Macros to export the symbols of cisstVector (in a Dll).
ScalesType & GetScales(void)
Definition: vctPlot2DBase.h:319
bool ContinuousFitX
Definition: vctPlot2DBase.h:278
Definition: vctPlot2DBase.h:55
Definition: vctPlot2DBase.h:44
const vctDouble2 & GetViewingRangeX(void) const
Definition: vctPlot2DBase.h:385
size_t NumberOfPoints
Definition: vctPlot2DBase.h:411
vctDouble2 ViewingRangeY
Definition: vctPlot2DBase.h:416
std::string Name
Definition: vctPlot2DBase.h:177