cisst-saw
Loading...
Searching...
No Matches
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 Author(s): Anton Deguet
6 Created on: 2010-05-05
7
8 (C) Copyright 2010-2018 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19#ifndef _vctPlot2DBase_h
20#define _vctPlot2DBase_h
21
22#include <map>
23#include <string>
24
28
29// Always include last
31
44{
45
46 public:
47
48 class Scale;
49
55 {
56 friend class vctPlot2DBase;
58 friend class vctPlot2DOpenGL;
59 friend class vctPlot2DVTK;
60 public:
61 Signal(const std::string & name, size_t numberOfPoints, size_t pointDimension = 2);
63
64 // see AppendPoint
66
70 void AppendPoint(const vctDouble2 & point);
71
75 vctDouble2 GetPointAt(size_t index) CISST_THROW(std::runtime_error);
76
80 void SetPointAt(size_t index, const vctDouble2 & point) CISST_THROW(std::runtime_error);
81
87 void SetArrayAt(size_t index, const double * pointArray, size_t arraySize, size_t pointDimension = 2) CISST_THROW(std::runtime_error);
88
94 bool PrependArray(const double * pointArray, size_t arraySize, size_t pointDimension = 2) CISST_THROW(std::runtime_error);
95
101 bool AppendArray(const double * pointArray, size_t arraySize, size_t pointDimension = 2) CISST_THROW(std::runtime_error);
102
103 void Freeze(bool freeze);
104 bool GetFreeze(void) const;
105
109 void ComputeDataRangeX(double & min, double & max, bool assumesDataSorted = false) const;
110 void ComputeDataRangeY(double & min, double & max) const;
111 void ComputeDataRangeXY(vctDouble2 & min, vctDouble2 & max) const;
113
114 void CISST_DEPRECATED SetNumberOfPoints(size_t numberOfPoints);
115 void CISST_DEPRECATED GetNumberOfPoints(size_t & numberOfPoints, size_t & bufferSize) const;
116
118 size_t GetSize(void) const;
119
121 size_t GetNumberOfPoints(void) const;
122
123 void SetColor(const vctDouble3 & colorInRange0To1);
124
128 void SetSize(size_t numberOfPoints);
129
130 bool IsVisible(void) const;
131 void SetVisible(const bool visible);
132
136 void Resize(size_t numberOfPoints, bool trimOlder = true);
137
138 /* Helper Function */
139 vctPlot2DBase::Signal * AddSignal(const std::string & name);
141 const std::string & GetName(void) const;
142
143 protected:
146 std::string Name;
147 bool Empty;
149 bool Frozen;
151 double * Buffer;
152 size_t PointSize;
154 typedef vctFixedSizeVectorRef<double, 2, 1> PointRef;
157 size_t IndexLast;
159 double LineWidth;
160 };
161
164 {
165 friend class vctPlot2DBase;
166 friend class vctPlot2DOpenGL;
167 friend class vctPlot2DVTK;
168 public:
169 VerticalLine(const std::string & name, const double x = 0.0);
171
172 void SetX(const double x);
173 void SetColor(const vctDouble3 & colorInRange0To1);
174
175 protected:
176 std::string Name;
177 double X;
180 double LineWidth;
181 };
182
184 {
185 friend class vctPlot2DBase;
186 friend class vctPlot2DOpenGL;
187 friend class vctPlot2DVTK;
188 public:
189
190 // keep signals in a std::map
191 typedef std::map<std::string, Signal *> SignalsType;
193
194 // keep vertical lines in a std::map
195 typedef std::map<std::string, VerticalLine *> VerticalLinesType;
197
198 Scale(const std::string & name, size_t pointDimension = 2);
200
201 const std::string & GetName(void) const;
202
203 vctPlot2DBase::Signal * AddSignal(const std::string & name);
204 bool RemoveSignal(const std::string & name);
205 bool RemoveSignal(const Signal * signal);
206
207 inline const SignalsType & GetSignals(void) const {
208 return Signals;
209 }
210
211 vctPlot2DBase::VerticalLine * AddVerticalLine(const std::string & name);
212
213 void SetColor(const vctDouble3 & colorInRange0To1);
214
215 void Freeze(bool freeze);
216 bool GetFreeze(void) const;
217
222 void SetContinuousFitX(bool fit);
223 void SetContinuousFitY(bool fit);
224 void SetContinuousExpandY(bool expand);
226
228 inline bool GetContinuousFitX(void) const {
229 return ContinuousFitX;
230 }
231 inline bool GetContinuousFitY(void) const {
232 return ContinuousFitY;
233 }
234 inline bool GetContinuousExpandY(void) const {
235 return ContinuousExpandY;
236 }
238 return this->ViewingRangeX;
239 }
241 return this->ViewingRangeY;
242 }
243
244
252 bool ComputeDataRangeX(double & min, double & max, bool assumesDataSorted = false) const;
253 bool ComputeDataRangeY(double & min, double & max);
256
266 void AutoFitX(double padding = 0.0);
267 void FitX(double min, double max, double padding = 0.0);
268 void AutoFitY(double padding = 0.1);
269 void AutoExpandY(double padding = 0.1);
270 void FitY(double min, double max, double padding = 0.1);
271 void AutoFitXY(const vctDouble2 & padding = vctDouble2(0.0, 0.1));
272 void AutoFitXExpandY(const vctDouble2 & padding = vctDouble2(0.0, 0.1));
273 void FitXY(vctDouble2 min, vctDouble2 max, const vctDouble2 & padding = vctDouble2(0.0, 0.1));
275
276 protected:
281
282 // viewport sizes
284 // stores the min and max corresponding to the viewport
288
289
290 private:
291 std::string Name;
292 size_t PointSize;
293 vctDouble3 Color;
294 double LineWidth;
295 };
296
300 typedef std::map<std::string, Scale *> ScalesType;
302
306 vctPlot2DBase::Scale * AddScale(const std::string & name);
307
309 vctPlot2DBase::Scale * FindScale(const std::string & name);
310
312 bool RemoveScale(const std::string & name);
313
316
318 inline ScalesType & GetScales(void) {
319 return Scales;
320 }
321
323 virtual ~vctPlot2DBase();
324
326 void SetNumberOfPoints(size_t numberOfPoints);
327
333 Signal CISST_DEPRECATED * AddSignal(const std::string & name);
334
340 VerticalLine CISST_DEPRECATED * AddVerticalLine(const std::string & name);
341
351 void AutoFitX(double padding = 0.0);
352 void FitX(double min, double max, double padding = 0.0);
353 void AutoFitY(double padding = 0.1);
354 void FitY(double min, double max, double padding = 0.1);
356
361 void Freeze(bool freeze);
362
364 bool GetFreeze(void) const;
365
368 void SetContinuousFitX(bool fit);
369 void SetContinuousFitY(bool fit);
370 void SetContinuousExpandY(bool expand);
372
374 bool GetContinuousFitX(void) const;
375
377 bool GetContinuousFitY(void) const;
378
380 bool GetContinuousExpandY(void) const;
381
382 //*! Get currently used viewing range */
384 inline const vctDouble2 & GetViewingRangeX(void) const {
385 return this->ViewingRangeX;
386 }
387 inline const vctDouble2 & GetViewingRangeY(void) const {
388 return this->ViewingRangeY;
389 }
390
391
393 void SetBackgroundColor(const vctDouble3 & colorInRange0To1);
394
395 protected:
396
399 virtual void RenderInitialize(void) = 0;
400 virtual void RenderResize(double width, double height) = 0;
401 virtual void Render(void) = 0;
403
404 protected:
407 size_t PointSize;
408
409 // default number of points for all signals
411
412 // viewport sizes
414 // stores the min and max corresponding to the viewport
416
420
421 // background color
423};
424
425#endif // _vctPlot2DBase_h
Definition vctForwardDeclarations.h:131
Definition vctForwardDeclarations.h:89
Definition vctPlot2DBase.h:184
void AutoFitXExpandY(const vctDouble2 &padding=vctDouble2(0.0, 0.1))
void SetContinuousExpandY(bool expand)
bool RemoveSignal(const Signal *signal)
Scale(const std::string &name, size_t pointDimension=2)
void FitY(double min, double max, double padding=0.1)
void FitX(double min, double max, double padding=0.0)
double ExpandYMax
Definition vctPlot2DBase.h:280
const vctDouble2 & GetViewingRangeY(void)
Definition vctPlot2DBase.h:240
bool GetFreeze(void) const
bool ContinuousFitY
Definition vctPlot2DBase.h:278
friend class vctPlot2DOpenGL
Definition vctPlot2DBase.h:186
vctDouble2 Translation
Definition vctPlot2DBase.h:286
bool GetContinuousExpandY(void) const
Definition vctPlot2DBase.h:234
void Freeze(bool freeze)
bool GetContinuousFitY(void) const
Definition vctPlot2DBase.h:231
vctDouble2 Viewport
Definition vctPlot2DBase.h:283
void AutoExpandY(double padding=0.1)
bool ContinuousExpandY
Definition vctPlot2DBase.h:279
bool GetContinuousFitX(void) const
Definition vctPlot2DBase.h:228
const vctDouble2 & GetViewingRangeX(void)
Definition vctPlot2DBase.h:237
const SignalsType & GetSignals(void) const
Definition vctPlot2DBase.h:207
const std::string & GetName(void) const
bool ComputeDataRangeXY(vctDouble2 &min, vctDouble2 &max)
friend class vctPlot2DVTK
Definition vctPlot2DBase.h:187
void SetContinuousFitY(bool fit)
double ExpandYMin
Definition vctPlot2DBase.h:280
vctPlot2DBase::VerticalLine * AddVerticalLine(const std::string &name)
vctDouble2 ViewingRangeX
Definition vctPlot2DBase.h:285
bool ComputeDataRangeY(double &min, double &max)
bool RemoveSignal(const std::string &name)
SignalsType Signals
Definition vctPlot2DBase.h:192
friend class vctPlot2DBase
Definition vctPlot2DBase.h:185
void AutoFitXY(const vctDouble2 &padding=vctDouble2(0.0, 0.1))
bool ComputeDataRangeX(double &min, double &max, bool assumesDataSorted=false) const
VerticalLinesType VerticalLines
Definition vctPlot2DBase.h:196
void FitXY(vctDouble2 min, vctDouble2 max, const vctDouble2 &padding=vctDouble2(0.0, 0.1))
vctDouble2 ViewingRangeY
Definition vctPlot2DBase.h:285
std::map< std::string, VerticalLine * > VerticalLinesType
Definition vctPlot2DBase.h:195
vctPlot2DBase::Signal * AddSignal(const std::string &name)
vctDouble2 ScaleValue
Definition vctPlot2DBase.h:287
void AutoFitX(double padding=0.0)
void SetContinuousFitX(bool fit)
void ContinuousUpdate(void)
std::map< std::string, Signal * > SignalsType
Definition vctPlot2DBase.h:191
void AutoFitY(double padding=0.1)
bool ContinuousFitX
Definition vctPlot2DBase.h:277
void SetColor(const vctDouble3 &colorInRange0To1)
Definition vctPlot2DBase.h:55
void AppendPoint(const vctDouble2 &point)
void SetColor(const vctDouble3 &colorInRange0To1)
bool GetFreeze(void) const
void ComputeDataRangeY(double &min, double &max) const
void CISST_DEPRECATED AddPoint(const vctDouble2 &point)
friend class vctPlot2DBase::Scale
Definition vctPlot2DBase.h:57
void Resize(size_t numberOfPoints, bool trimOlder=true)
friend class vctPlot2DOpenGL
Definition vctPlot2DBase.h:58
bool Frozen
Definition vctPlot2DBase.h:149
size_t PointSize
Definition vctPlot2DBase.h:152
vctPlot2DBase::Signal * AddSignal(const std::string &name)
void ComputeDataRangeX(double &min, double &max, bool assumesDataSorted=false) const
size_t GetSize(void) const
void CISST_DEPRECATED GetNumberOfPoints(size_t &numberOfPoints, size_t &bufferSize) const
vctDouble2 GetPointAt(size_t index) CISST_THROW(std void SetPointAt(size_t index, const vctDouble2 &point) CISST_THROW(std void SetArrayAt(size_t index, const double *pointArray, size_t arraySize, size_t pointDimension=2) CISST_THROW(std bool PrependArray(const double *pointArray, size_t arraySize, size_t pointDimension=2) CISST_THROW(std bool AppendArray(const double *pointArray, size_t arraySize, size_t pointDimension=2) CISST_THROW(std void Freeze(bool freeze)
Definition vctPlot2DBase.h:103
friend class vctPlot2DVTK
Definition vctPlot2DBase.h:59
vctDynamicVector< PointRef > Data
Definition vctPlot2DBase.h:155
vctPlot2DBase::Scale * GetParent(void)
bool Empty
Definition vctPlot2DBase.h:147
double * Buffer
Definition vctPlot2DBase.h:151
bool Visible
Definition vctPlot2DBase.h:148
vctFixedSizeVectorRef< double, 2, 1 > PointRef
Definition vctPlot2DBase.h:154
vctDouble3 Color
Definition vctPlot2DBase.h:158
double LineWidth
Definition vctPlot2DBase.h:159
size_t IndexLast
Definition vctPlot2DBase.h:157
Signal(const std::string &name, size_t numberOfPoints, size_t pointDimension=2)
friend class vctPlot2DBase
Definition vctPlot2DBase.h:56
const std::string & GetName(void) const
void CISST_DEPRECATED SetNumberOfPoints(size_t numberOfPoints)
Scale * Parent
Definition vctPlot2DBase.h:144
bool IsVisible(void) const
void SetVisible(const bool visible)
void SetSize(size_t numberOfPoints)
size_t IndexFirst
Definition vctPlot2DBase.h:156
std::string Name
Definition vctPlot2DBase.h:146
void ComputeDataRangeXY(vctDouble2 &min, vctDouble2 &max) const
Definition vctPlot2DBase.h:164
friend class vctPlot2DOpenGL
Definition vctPlot2DBase.h:166
double LineWidth
Definition vctPlot2DBase.h:180
vctDouble3 Color
Definition vctPlot2DBase.h:179
double X
Definition vctPlot2DBase.h:177
std::string Name
Definition vctPlot2DBase.h:176
friend class vctPlot2DVTK
Definition vctPlot2DBase.h:167
void SetX(const double x)
bool Visible
Definition vctPlot2DBase.h:178
friend class vctPlot2DBase
Definition vctPlot2DBase.h:165
void SetColor(const vctDouble3 &colorInRange0To1)
VerticalLine(const std::string &name, const double x=0.0)
const vctDouble2 & GetViewingRangeX(void) const
Definition vctPlot2DBase.h:384
std::map< std::string, Scale * > ScalesType
Definition vctPlot2DBase.h:300
VerticalLine CISST_DEPRECATED * AddVerticalLine(const std::string &name)
vctPlot2DBase::Scale * AddScale(const std::string &name)
virtual ~vctPlot2DBase()
bool GetFreeze(void) const
void SetNumberOfPoints(size_t numberOfPoints)
vctDouble2 Viewport
Definition vctPlot2DBase.h:413
vctPlot2DBase(size_t PointSize=2)
size_t PointSize
Definition vctPlot2DBase.h:407
ScalesType & GetScales(void)
Definition vctPlot2DBase.h:318
ScalesType Scales
Definition vctPlot2DBase.h:301
vctDouble2 ViewingRangeY
Definition vctPlot2DBase.h:415
Signal CISST_DEPRECATED * AddSignal(const std::string &name)
bool GetContinuousFitY(void) const
vctDouble3 BackgroundColor
Definition vctPlot2DBase.h:422
virtual void RenderResize(double width, double height)=0
vctPlot2DBase::Scale * FindScale(const std::string &name)
bool RemoveScale(const vctPlot2DBase::Scale *scale)
void AutoFitX(double padding=0.0)
bool RemoveScale(const std::string &name)
void SetContinuousExpandY(bool expand)
void AutoFitY(double padding=0.1)
vctDouble2 ViewingRangeX
Definition vctPlot2DBase.h:415
virtual void RenderInitialize(void)=0
const vctDouble2 & GetViewingRangeY(void) const
Definition vctPlot2DBase.h:387
void FitX(double min, double max, double padding=0.0)
void SetContinuousFitX(bool fit)
bool GetContinuousExpandY(void) const
void SetContinuousFitY(bool fit)
size_t NumberOfPoints
Definition vctPlot2DBase.h:410
virtual void Render(void)=0
void SetBackgroundColor(const vctDouble3 &colorInRange0To1)
bool GetContinuousFitX(void) const
void FitY(double min, double max, double padding=0.1)
void Freeze(bool freeze)
void ContinuousUpdate(void)
#define CISST_EXPORT
Definition cmnExportMacros.h:50
#define CISST_DEPRECATED
Definition cmnPortability.h:314
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
STL namespace.
size_type height() const
Definition vctDynamicConstMatrixBase.h:248
size_type width() const
Definition vctDynamicConstMatrixBase.h:253
Declaration of vctDynamicVector.
Typedef for dynamic vectors.
Macros to export the symbols of cisstVector (in a Dll).
Typedef for fixed size vectors.
vctFixedSizeVector< double, 3 > vctDouble3
Definition vctFixedSizeVectorTypes.h:45
vctFixedSizeVector< double, 2 > vctDouble2
Definition vctFixedSizeVectorTypes.h:40