HOG2
Plot2D.h
Go to the documentation of this file.
1 /*
2  * Plot2D.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 4/18/07.
6  * Copyright 2007 Nathan Sturtevant, University of Alberta. All rights reserved.
7  *
8  */
9 
10 #ifndef PLOT2D_H
11 #define PLOT2D_H
12 
13 #include <vector>
14 #include "GLUtil.h"
15 #include "FPUtil.h"
16 #include "Graphics.h"
17 
18 namespace Plotting {
19 
20  enum tPlotType {
21  kLinePlot, // draw from point to point
22  kImpulsePlot // draw impulses at at y-axis value
23  };
24 
25  class Line {
26  public:
27  Line(const char *label, tPlotType = kLinePlot);
28  void AddPoint(double x, double y);
29  void AddPoint(double x);
30  void Clear();
31  const char *GetLabel() { return name; }
32 
33  void ClearColor();
34  void SetColor(double, double, double);
35  void SetColor(const rgbColor &c);
36  void SetWidth(float w) { width = w; }
37  void OpenGLDraw() const;
38  void Draw(Graphics::Display &display, double xOff, double yOff, double xScale, double yScale) const;
39  void SetHidden( bool val) { hidden = val; }
40  bool IsHidden() { return hidden; }
41 
42  inline void Smooth(unsigned int windowSize);
43  inline bool GetChanged() { return changedLine; }
44  inline void SetChange(bool val) { changedLine = val; }
45  inline double GetMaxX() { return xMax; }
46  inline double GetMaxY() { return yMax; }
47  inline double GetMinX() { return xMin; }
48  inline double GetMinY() { return yMin; }
49 
50  double DistanceToLine(double xp, double yp);
51  double VerticalDistanceToLine(double xp, double yp);
52  private:
55  double xMin, xMax, yMin, yMax;
56  double r, g, b;
57  std::vector<double> x;
58  std::vector<double> y;
59  bool hidden;
60  char name[1024];
61  float width;
62  };
63 
64  struct Point {
65  double x, y, r;
67  void Draw(Graphics::Display &display, double xOff, double yOff, double xScale, double yScale) const;
68  };
69 
70  class Plot2D {
71  public:
72  Plot2D();
73  void Clear();
74  void AddLine(Line *);
75  void AddPoint(const Point &p);
76  void SetXAxisLabel(const char *);
77  void SetYAxisLabel(const char *);
78  // void SetCurrMouse(double, double, Rect &winRect);
79 // void Recenter(double, double, Rect &rectPort);
80  double GetMaxX() { return dRight; }
81  double GetMinX() { return dLeft; }
82  double GetMaxY() { return dTop; }
83  double GetMinY() { return dBottom; }
84  void OffsetCurrMouse(double deltaX, double deltaY);
85  void SetAxis(double, double, double, double);
86  void Zoom(double);
87  void ResetAxis();
88  void OpenGLDraw() const;
89  void Draw(Graphics::Display &display) const;
90  void SmoothLines();
91  void NormalizeAxes();
92  private:
93  point3d MakeHOG(double x, double y) const;
94  double MakeHOGWidth(double w) const;
96  double dLeft, dRight, dTop, dBottom;
97  double xMin, xMax, yMin, yMax;
100  std::vector<Point> points;
101  std::vector<Line *> lines;
102  std::string xLabel, yLabel;
103  mutable double xOffset;
104  mutable double yOffset;
105  mutable double xScale;
106  mutable double yScale;
107 };
108 
109 }
110 
111 #endif
Plotting::Line::GetLabel
const char * GetLabel()
Definition: Plot2D.h:31
Plotting::Line::xMin
double xMin
Definition: Plot2D.h:55
rgbColor
A color; r/g/b are between 0...1.
Definition: Colors.h:17
Plotting::Plot2D::yScale
double yScale
Definition: Plot2D.h:106
Plotting::Plot2D::Clear
void Clear()
Definition: Plot2D.cpp:212
Plotting::Line::Clear
void Clear()
Definition: Plot2D.cpp:32
Plotting::Plot2D::lines
std::vector< Line * > lines
Definition: Plot2D.h:101
Plotting::Line::GetMinY
double GetMinY()
Definition: Plot2D.h:48
Plotting::Line::DistanceToLine
double DistanceToLine(double xp, double yp)
Definition: Plot2D.cpp:69
Plotting::Line::y
std::vector< double > y
Definition: Plot2D.h:58
Plotting
Definition: Plot2D.cpp:16
Plotting::Line::b
double b
Definition: Plot2D.h:56
Plotting::Line::r
double r
Definition: Plot2D.h:56
Plotting::Plot2D::dBottom
double dBottom
Definition: Plot2D.h:96
Plotting::Plot2D::GetMaxY
double GetMaxY()
Definition: Plot2D.h:82
Plotting::Line::OpenGLDraw
void OpenGLDraw() const
Definition: Plot2D.cpp:138
Plotting::Line::Smooth
void Smooth(unsigned int windowSize)
Definition: Plot2D.cpp:99
Plotting::Plot2D::points
std::vector< Point > points
Definition: Plot2D.h:100
Plotting::Line::plotType
tPlotType plotType
Definition: Plot2D.h:54
Plotting::Plot2D::mouseYLoc
double mouseYLoc
Definition: Plot2D.h:95
Plotting::Plot2D::yOffset
double yOffset
Definition: Plot2D.h:104
Plotting::Line::GetMaxY
double GetMaxY()
Definition: Plot2D.h:46
Plotting::Plot2D::xScale
double xScale
Definition: Plot2D.h:105
FPUtil.h
Plotting::Line::Draw
void Draw(Graphics::Display &display, double xOff, double yOff, double xScale, double yScale) const
Definition: Plot2D.cpp:174
Plotting::Plot2D::dLeft
double dLeft
Definition: Plot2D.h:96
Plotting::Plot2D::drawMouse
bool drawMouse
Definition: Plot2D.h:98
Plotting::Line::IsHidden
bool IsHidden()
Definition: Plot2D.h:40
Plotting::Plot2D::recomputeBorders
bool recomputeBorders
Definition: Plot2D.h:98
Plotting::Line::GetMinX
double GetMinX()
Definition: Plot2D.h:47
Plotting::Line::name
char name[1024]
Definition: Plot2D.h:60
Plotting::Plot2D::Draw
void Draw(Graphics::Display &display) const
Definition: Plot2D.cpp:561
Plotting::Point::y
double y
Definition: Plot2D.h:65
Plotting::Plot2D::xLabel
std::string xLabel
Definition: Plot2D.h:102
Plotting::Line::SetHidden
void SetHidden(bool val)
Definition: Plot2D.h:39
Plotting::Line::SetWidth
void SetWidth(float w)
Definition: Plot2D.h:36
Plotting::Plot2D::lastSelectedLine
int lastSelectedLine
Definition: Plot2D.h:99
Plotting::Line::changedLine
bool changedLine
Definition: Plot2D.h:53
Plotting::Line::xMax
double xMax
Definition: Plot2D.h:55
Plotting::Plot2D::GetMaxX
double GetMaxX()
Definition: Plot2D.h:80
Plotting::Plot2D::NormalizeAxes
void NormalizeAxes()
Definition: Plot2D.cpp:467
Plotting::kLinePlot
@ kLinePlot
Definition: Plot2D.h:21
Plotting::Plot2D::MakeHOG
point3d MakeHOG(double x, double y) const
Definition: Plot2D.cpp:547
Plotting::Plot2D::xMin
double xMin
Definition: Plot2D.h:97
Plotting::Plot2D
Definition: Plot2D.h:70
Plotting::Plot2D::mouseXLoc
double mouseXLoc
Definition: Plot2D.h:95
Plotting::Point::c
rgbColor c
Definition: Plot2D.h:66
point3d
#define point3d
Definition: GLUtil.h:123
Plotting::Plot2D::OpenGLDraw
void OpenGLDraw() const
Definition: Plot2D.cpp:480
Graphics::Display
Definition: Graphics.h:146
Plotting::Plot2D::OffsetCurrMouse
void OffsetCurrMouse(double deltaX, double deltaY)
Definition: Plot2D.cpp:372
Plotting::Line::Line
Line(const char *label, tPlotType=kLinePlot)
Definition: Plot2D.cpp:18
Plotting::Plot2D::Plot2D
Plot2D()
Definition: Plot2D.cpp:204
Plotting::Line::SetColor
void SetColor(double, double, double)
Definition: Plot2D.cpp:133
Plotting::Point::Draw
void Draw(Graphics::Display &display, double xOff, double yOff, double xScale, double yScale) const
Definition: Plot2D.cpp:197
Plotting::Plot2D::yMin
double yMin
Definition: Plot2D.h:97
Plotting::Plot2D::SetAxis
void SetAxis(double, double, double, double)
Definition: Plot2D.cpp:313
Plotting::tPlotType
tPlotType
Definition: Plot2D.h:20
Plotting::Plot2D::MakeHOGWidth
double MakeHOGWidth(double w) const
Definition: Plot2D.cpp:552
Plotting::Plot2D::SetYAxisLabel
void SetYAxisLabel(const char *)
Definition: Plot2D.cpp:224
Plotting::Line::ClearColor
void ClearColor()
Definition: Plot2D.cpp:121
Plotting::Plot2D::SmoothLines
void SmoothLines()
Definition: Plot2D.cpp:460
Plotting::Plot2D::ResetAxis
void ResetAxis()
Definition: Plot2D.cpp:322
Plotting::kImpulsePlot
@ kImpulsePlot
Definition: Plot2D.h:22
Plotting::Line::x
std::vector< double > x
Definition: Plot2D.h:57
Plotting::Line::width
float width
Definition: Plot2D.h:61
Plotting::Point::x
double x
Definition: Plot2D.h:65
Plotting::Line::yMin
double yMin
Definition: Plot2D.h:55
GLUtil.h
Graphics.h
Plotting::Line::VerticalDistanceToLine
double VerticalDistanceToLine(double xp, double yp)
Definition: Plot2D.cpp:83
Plotting::Point
Definition: Plot2D.h:64
Plotting::Plot2D::yMax
double yMax
Definition: Plot2D.h:97
Plotting::Line::yMax
double yMax
Definition: Plot2D.h:55
Plotting::Line::GetChanged
bool GetChanged()
Definition: Plot2D.h:43
Plotting::Plot2D::forceAxis
bool forceAxis
Definition: Plot2D.h:98
Plotting::Plot2D::yLabel
std::string yLabel
Definition: Plot2D.h:102
Plotting::Plot2D::AddPoint
void AddPoint(const Point &p)
Definition: Plot2D.cpp:254
Plotting::Line
Definition: Plot2D.h:25
Plotting::Plot2D::AddLine
void AddLine(Line *)
Definition: Plot2D.cpp:231
Plotting::Line::g
double g
Definition: Plot2D.h:56
Plotting::Line::SetChange
void SetChange(bool val)
Definition: Plot2D.h:44
Plotting::Plot2D::xOffset
double xOffset
Definition: Plot2D.h:103
Plotting::Plot2D::Zoom
void Zoom(double)
Definition: Plot2D.cpp:292
Plotting::Line::GetMaxX
double GetMaxX()
Definition: Plot2D.h:45
Plotting::Plot2D::SetXAxisLabel
void SetXAxisLabel(const char *)
Definition: Plot2D.cpp:219
Plotting::Line::AddPoint
void AddPoint(double x, double y)
Definition: Plot2D.cpp:51
Plotting::Plot2D::xMax
double xMax
Definition: Plot2D.h:97
Plotting::Plot2D::GetMinX
double GetMinX()
Definition: Plot2D.h:81
Plotting::Plot2D::dTop
double dTop
Definition: Plot2D.h:96
Plotting::Plot2D::GetMinY
double GetMinY()
Definition: Plot2D.h:83
Plotting::Line::hidden
bool hidden
Definition: Plot2D.h:59
Plotting::Plot2D::dRight
double dRight
Definition: Plot2D.h:96
Plotting::Point::r
double r
Definition: Plot2D.h:65