anatomist  5.1.2
3D neuroimaging data viewer
spline.h
Go to the documentation of this file.
1 /**************************************************************************
2 * This file is part of the Fraqtive program.
3 * Copyright (C) 2005 Michal Mecinski.
4 * This program is licensed under the GNU General Public License.
5 **************************************************************************/
6 
7 #ifndef SPLINE_H
8 #define SPLINE_H
9 
10 #include <vector>
11 #include <qsize.h>
12 #include <qpoint.h>
13 
17 class Spline
18 {
19 public:
23  Spline();
24 
29 
30 public:
36  int getNodesCnt() const
37  {
38  return _array.size();
39  }
40 
44  void clear()
45  {
46  _array.clear();
47  }
48 
57  int findNode(QSize gradSize, QPoint ptPos, QSize ptSize) const;
58 
68  void findSegment(QSize gradSize, QPoint ptPos, int& p1, int& p2) const;
69 
70 
71 
81  void addNode(double x, double y)
82  {
83  _array.push_back(Coord(x, y));
84  }
85 
93  int insertNode(double x, double y);
94 
102  void setNode(int index, double x, double y)
103  {
104  _array[index]._x = x;
105  _array[index]._y = y;
106  }
107 
113  void removeNode(int index)
114  {
115  _array.erase(_array.begin() + index);
116  }
117 
123  void insertAt(int index)
124  {
125  _array.insert(_array.begin() + index, Coord());
126  }
127 
134  double getNodeX(int index) const
135  {
136  return _array[index]._x;
137  }
138 
145  double getNodeY(int index) const
146  {
147  return _array[index]._y;
148  }
149 
156  double getLimitMin(int index) const
157  {
158  if (index == 0)
159  return 0.0;
160  return _array[index - 1]._x;
161  }
162 
169  double getLimitMax(int index) const
170  {
171  if (index == (int)_array.size() - 1)
172  return 1.0;
173  return _array[index + 1]._x;
174  }
175 
179  void invert();
180 
187  void generateSpline(double* buffer, int count) const;
188 
194  QString toString() const;
195 
201  void fromString(const QString& string);
202 
203 private:
204  struct Coord
205  {
206  Coord()
207  {
208  }
209 
210  Coord(double x, double y) : _x(x), _y(y)
211  {
212  }
213 
214  double _x, _y;
215  };
216 
217  typedef std::vector<Coord> CoordArray;
218 
219  CoordArray _array;
220 };
221 
222 #endif
A spline used to store gradient components waveforms.
Definition: spline.h:18
void clear()
Remove all spline nodes.
Definition: spline.h:44
double getNodeX(int index) const
Get the x coordinate of the given node.
Definition: spline.h:134
~Spline()
Destructor.
QString toString() const
Encode the spline data as a string.
double getLimitMin(int index) const
Get the minimum x coordinate of the given node.
Definition: spline.h:156
double getLimitMax(int index) const
Get the maximum x coordinate of the given node.
Definition: spline.h:169
void generateSpline(double *buffer, int count) const
Generate the spline waveform.
int getNodesCnt() const
Get the number of nodes in the spline.
Definition: spline.h:36
void setNode(int index, double x, double y)
Change the position of a node.
Definition: spline.h:102
void insertAt(int index)
Insert a node at the given position.
Definition: spline.h:123
int findNode(QSize gradSize, QPoint ptPos, QSize ptSize) const
Find a node at the specified position.
int insertNode(double x, double y)
Insert a node into the spline.
Spline()
Constructor.
void removeNode(int index)
Remove a node.
Definition: spline.h:113
void addNode(double x, double y)
Add a node to the spline.
Definition: spline.h:81
void invert()
Invert the nodes in the spline.
void fromString(const QString &string)
Decode the spline data from a string.
double getNodeY(int index) const
Get the y coordinate of the given node.
Definition: spline.h:145
void findSegment(QSize gradSize, QPoint ptPos, int &p1, int &p2) const
Find a segment at the specified position.