kwave  18.07.70
Kwave::Curve Class Reference

#include <Curve.h>

Inheritance diagram for Kwave::Curve:
Inheritance graph
Collaboration diagram for Kwave::Curve:
Collaboration graph

Public Types

typedef QListIterator< QPointF > ConstIterator
 
typedef QMutableListIterator< QPointF > Iterator
 
typedef QPointF Point
 

Public Member Functions

 Curve ()
 
 Curve (const QString &command)
 
virtual ~Curve ()
 
void firstHalf ()
 
void secondHalf ()
 
void deletePoint (Point p, bool check)
 
void deleteSecondPoint ()
 
void HFlip ()
 
void VFlip ()
 
void scaleFit (unsigned int range=1024)
 
void insert (double x, double y)
 
Point findPoint (double x, double y, double tol=.05)
 
void fromCommand (const QString &command)
 
QString getCommand ()
 
Kwave::interpolation_t interpolationType ()
 
void setInterpolationType (Kwave::interpolation_t type)
 
Kwave::Interpolationinterpolation ()
 
QVector< double > interpolation (unsigned int points)
 

Static Public Attributes

static QPointF NoPoint
 

Protected Member Functions

void sort ()
 

Private Attributes

Kwave::Interpolation m_interpolation
 

Detailed Description

Definition at line 37 of file Curve.h.

Member Typedef Documentation

◆ ConstIterator

typedef QListIterator<QPointF> Kwave::Curve::ConstIterator

Iterator

Definition at line 42 of file Curve.h.

◆ Iterator

typedef QMutableListIterator<QPointF> Kwave::Curve::Iterator

Iterator

Definition at line 45 of file Curve.h.

◆ Point

typedef QPointF Kwave::Curve::Point

class used for the points

Definition at line 48 of file Curve.h.

Constructor & Destructor Documentation

◆ Curve() [1/2]

Kwave::Curve::Curve ( )

Default constructor, creates an empty curve.

Definition at line 36 of file Curve.cpp.

38 {
39 }
Kwave::Interpolation m_interpolation
Definition: Curve.h:165

◆ Curve() [2/2]

Kwave::Curve::Curve ( const QString &  command)
explicit

Constructor, creates a curve from a command string.

Parameters
commandstring with parameters

Definition at line 42 of file Curve.cpp.

References fromCommand().

44 {
45  fromCommand(command);
46 }
void fromCommand(const QString &command)
Definition: Curve.cpp:55
Kwave::Interpolation m_interpolation
Definition: Curve.h:165
Here is the call graph for this function:

◆ ~Curve()

Kwave::Curve::~Curve ( )
virtual

Destructor

Definition at line 49 of file Curve.cpp.

50 {
51  clear();
52 }

Member Function Documentation

◆ deletePoint()

void Kwave::Curve::deletePoint ( Point  p,
bool  check 
)

Removes and deletes a point from the curve. Note that after this call the passed point is no longer valid!

Parameters
ppoint to be deleted
checkif true, the last or first point will not be deleted

Definition at line 112 of file Curve.cpp.

Referenced by Kwave::CurveWidget::deleteLast(), and Kwave::CurveWidget::mouseMoveEvent().

113 {
114  Iterator it(*this);
115  if (!it.findNext(p)) return;
116  if ((!check) || (it.hasPrevious() && it.hasNext()))
117  it.remove();
118 }
QMutableListIterator< QPointF > Iterator
Definition: Curve.h:45
Here is the caller graph for this function:

◆ deleteSecondPoint()

void Kwave::Curve::deleteSecondPoint ( )

Deletes every second point.

Definition at line 135 of file Curve.cpp.

Referenced by Kwave::CurveWidget::deleteSecond().

136 {
137  if (isEmpty()) return;
138 
139  Iterator it(*this);
140  while (it.hasNext()) {
141  it.next();
142  it.remove();
143  }
144 }
QMutableListIterator< QPointF > Iterator
Definition: Curve.h:45
Here is the caller graph for this function:

◆ findPoint()

Kwave::Curve::Point Kwave::Curve::findPoint ( double  x,
double  y,
double  tol = .05 
)

Searches for a point at given coordinates with a definable tolerance.

Parameters
xcoordinate on the x axis
ycoordinate on the y axis
toltolerance for x and y direction, absolute value
Returns
pointer to the found point or "NoPoint" if nothing found.

Definition at line 226 of file Curve.cpp.

References NoPoint.

Referenced by Kwave::CurveWidget::findPoint(), and Kwave::CurveWidget::mouseMoveEvent().

227 {
228  Point best = NoPoint;
229  double min_dist = tol;
230 
231  QMutableListIterator<Point> it(*this);
232  while (it.hasNext()) {
233  Point &p = it.next();
234  // use the length of the difference vector as criterium
235  double dist = hypot(px - p.x(), py - p.y());
236  if (dist < min_dist) {
237  min_dist = dist;
238  best = p;
239  }
240  }
241  return best;
242 }
QPointF Point
Definition: Curve.h:48
static QPointF NoPoint
Definition: Curve.h:51
Here is the caller graph for this function:

◆ firstHalf()

void Kwave::Curve::firstHalf ( )

Moves all current points into the left half

Definition at line 159 of file Curve.cpp.

Referenced by Kwave::CurveWidget::firstHalf().

160 {
161  if (isEmpty()) return;
162 
163  QMutableListIterator<Point> it(*this);
164  while (it.hasNext()) {
165  Point &p = it.next();
166  p.setX(p.x() / 2.0);
167  }
168  append(Point(1.0, first().y()));
169 }
QPointF Point
Definition: Curve.h:48
Here is the caller graph for this function:

◆ fromCommand()

void Kwave::Curve::fromCommand ( const QString &  command)

Sets a curve from a command string. Opposite of getCommand().

Parameters
commanda string that contains the interpolation type and pairs of x/y coordinates.

Definition at line 55 of file Curve.cpp.

References Kwave::Interpolation::find(), Kwave::Parser::firstParam(), Kwave::Parser::isDone(), m_interpolation, setInterpolationType(), and Kwave::Parser::toDouble().

Referenced by Curve(), Kwave::CurveWidget::CurveWidget(), Kwave::AmplifyFreePlugin::interpreteParameters(), Kwave::CurveWidget::loadPreset(), and Kwave::CurveWidget::setCurve().

56 {
57  clear();
58 
59  Kwave::Parser parse(command);
60  QString t = parse.firstParam();
62 
63  while (!parse.isDone()) {
64  double x = parse.toDouble();
65  if (parse.isDone()) break; // half point ?
66  double y = parse.toDouble();
67  append(Point(x, y));
68  }
69 }
QPointF Point
Definition: Curve.h:48
void setInterpolationType(Kwave::interpolation_t type)
Definition: Curve.cpp:100
Kwave::Interpolation m_interpolation
Definition: Curve.h:165
static Kwave::interpolation_t find(const QString &name)
Definition: Interpolation.h:83
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCommand()

QString Kwave::Curve::getCommand ( )

Returns a command string out of the curve points and interpolation type.

Definition at line 72 of file Curve.cpp.

References _, m_interpolation, Kwave::Interpolation::name(), and Kwave::Interpolation::type().

Referenced by Kwave::CurveWidget::getCommand(), and Kwave::CurveWidget::savePreset().

73 {
74  QString cmd = _("curve(");
76 
77  foreach (const Point &p, *this) {
78  QString par = _(",%1,%2");
79  cmd += par.arg(p.x()).arg(p.y());
80  }
81  cmd += _(")");
82  return cmd;
83 }
Kwave::interpolation_t type()
QPointF Point
Definition: Curve.h:48
static QString name(Kwave::interpolation_t type)
Kwave::Interpolation m_interpolation
Definition: Curve.h:165
#define _(m)
Definition: memcpy.c:66
Here is the call graph for this function:
Here is the caller graph for this function:

◆ HFlip()

void Kwave::Curve::HFlip ( )

Flips/mirrors the curve horizontally (x-axis).

Definition at line 184 of file Curve.cpp.

References sort().

Referenced by Kwave::CurveWidget::HFlip().

185 {
186  if (isEmpty()) return;
187 
188  // flip all x coordinates
189  QMutableListIterator<Point> it(*this);
190  while (it.hasNext()) {
191  Point &p = it.next();
192  p.setX(1.0 - p.x());
193  }
194 
195  // reverse the order it the list
196  sort();
197 }
QPointF Point
Definition: Curve.h:48
void sort()
Definition: Curve.cpp:251
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert()

void Kwave::Curve::insert ( double  x,
double  y 
)

Creates a new point and inserts it into the curve. The new point will be sorted in by it's x coordinate.

Parameters
xcoordinate on the x axis, should be [0...+1.0]
ycoordinate on the y axis, should be [0...+1.0]

Definition at line 147 of file Curve.cpp.

References sort().

Referenced by Kwave::CurveWidget::addPoint(), Kwave::CurveWidget::mouseMoveEvent(), Kwave::PlayBackPlugin::run(), and secondHalf().

148 {
149  if ((x < 0.0) || (x > 1.0)) {
150  qWarning("Curve::insert(%0.2f,%0.2f): out of range !",x,y);
151  return;
152  }
153 
154  append(Point(x, y));
155  sort();
156 }
QPointF Point
Definition: Curve.h:48
void sort()
Definition: Curve.cpp:251
Here is the call graph for this function:
Here is the caller graph for this function:

◆ interpolation() [1/2]

Kwave::Interpolation & Kwave::Curve::interpolation ( )

Returns a reference to the Interpolation object itself

Definition at line 86 of file Curve.cpp.

References m_interpolation, and Kwave::Interpolation::prepareInterpolation().

Referenced by Kwave::CurveWidget::paintEvent(), and scaleFit().

87 {
89  return m_interpolation;
90 }
bool prepareInterpolation(const Kwave::Curve &points)
Kwave::Interpolation m_interpolation
Definition: Curve.h:165
Here is the call graph for this function:
Here is the caller graph for this function:

◆ interpolation() [2/2]

QVector< double > Kwave::Curve::interpolation ( unsigned int  points)

Returns an array of points, calculated out of the current interpolation parameters.

Parameters
pointsnumber of points
Returns
Array of interpolated values or null if the number of points was zero or the curve was empty.

Definition at line 93 of file Curve.cpp.

References Kwave::Interpolation::interpolation(), m_interpolation, and Kwave::Interpolation::prepareInterpolation().

94 {
96  return m_interpolation.interpolation(*this, points);
97 }
bool prepareInterpolation(const Kwave::Curve &points)
QVector< double > interpolation(const Kwave::Curve &points, unsigned int len)
Kwave::Interpolation m_interpolation
Definition: Curve.h:165
Here is the call graph for this function:

◆ interpolationType()

Kwave::interpolation_t Kwave::Curve::interpolationType ( )

Returns the interpolation type.

Definition at line 106 of file Curve.cpp.

References m_interpolation, and Kwave::Interpolation::type().

107 {
108  return m_interpolation.type();
109 }
Kwave::interpolation_t type()
Kwave::Interpolation m_interpolation
Definition: Curve.h:165
Here is the call graph for this function:

◆ scaleFit()

void Kwave::Curve::scaleFit ( unsigned int  range = 1024)

Scales the curve vertically to fit into a range of (+/- range/2) on the y-axis.

Parameters
rangethe size range to use for scaling

Definition at line 200 of file Curve.cpp.

References Kwave::Interpolation::interpolation(), interpolation(), m_interpolation, and Kwave::Interpolation::type().

Referenced by Kwave::CurveWidget::scaleFit().

201 {
202  double min = std::numeric_limits<double>::max();
203  double max = std::numeric_limits<double>::min();
204 
206 
207  QVector<double> y = interpolation.interpolation(*this, range);
208  foreach (double yi, y) {
209  if (yi > max) max = yi;
210  if (yi < min) min = yi;
211  }
212 
213  QMutableListIterator<Point> it(*this);
214  while (it.hasNext()) {
215  Point &p = it.next();
216  p.ry() -= min;
217  if (!qFuzzyCompare(max, min))
218  p.ry() /= (max - min);
219  else
220  p.ry() = min;
221  }
222 
223 }
Kwave::interpolation_t type()
QPointF Point
Definition: Curve.h:48
Kwave::Interpolation & interpolation()
Definition: Curve.cpp:86
QVector< double > interpolation(const Kwave::Curve &points, unsigned int len)
Kwave::Interpolation m_interpolation
Definition: Curve.h:165
Here is the call graph for this function:
Here is the caller graph for this function:

◆ secondHalf()

void Kwave::Curve::secondHalf ( )

Moves all current points into the right half

Definition at line 121 of file Curve.cpp.

References insert().

Referenced by Kwave::CurveWidget::secondHalf().

122 {
123  if (isEmpty()) return;
124 
125  QMutableListIterator<Point> it(*this);
126  while (it.hasNext()) {
127  Point &p = it.next();
128  p.setX(0.5 + p.x() / 2.0);
129  }
130 
131  insert(0.0, first().y());
132 }
QPointF Point
Definition: Curve.h:48
void insert(double x, double y)
Definition: Curve.cpp:147
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setInterpolationType()

void Kwave::Curve::setInterpolationType ( Kwave::interpolation_t  type)

Sets a new interpolation type.

Parameters
typethe new interpolation type

Definition at line 100 of file Curve.cpp.

References m_interpolation, and Kwave::Interpolation::setType().

Referenced by fromCommand(), and Kwave::CurveWidget::selectInterpolationType().

101 {
102  m_interpolation.setType(type);
103 }
Kwave::Interpolation m_interpolation
Definition: Curve.h:165
void setType(Kwave::interpolation_t t)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sort()

void Kwave::Curve::sort ( )
protected

sorts the list by ascending x coordinate

Definition at line 251 of file Curve.cpp.

References cmp().

Referenced by HFlip(), and insert().

252 {
253  if (!isEmpty())
254  std::sort(begin(), end(), cmp);
255 }
static bool cmp(const Kwave::Curve::Point &a, const Kwave::Curve::Point &b)
Definition: Curve.cpp:245
Here is the call graph for this function:
Here is the caller graph for this function:

◆ VFlip()

void Kwave::Curve::VFlip ( )

Flips/mirrors the curve vertically (y-axis).

Definition at line 172 of file Curve.cpp.

Referenced by Kwave::CurveWidget::VFlip().

173 {
174  if (isEmpty()) return;
175 
176  QMutableListIterator<Point> it(*this);
177  while (it.hasNext()) {
178  Point &p = it.next();
179  p.setY(1.0 - p.y());
180  }
181 }
QPointF Point
Definition: Curve.h:48
Here is the caller graph for this function:

Member Data Documentation

◆ m_interpolation

Kwave::Interpolation Kwave::Curve::m_interpolation
private

interpolation object

Definition at line 165 of file Curve.h.

Referenced by fromCommand(), getCommand(), interpolation(), interpolationType(), scaleFit(), and setInterpolationType().

◆ NoPoint


The documentation for this class was generated from the following files: