File: class_qwt_spline.html

package info (click to toggle)
libqwt 4.2.0-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,832 kB
  • ctags: 5,512
  • sloc: cpp: 22,973; ansic: 244; makefile: 64
file content (329 lines) | stat: -rw-r--r-- 16,451 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Qwt User&apos;s Guide: QwtSpline Class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.8 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<h1>QwtSpline Class Reference</h1><a href="class_qwt_spline-members.html">List of all members.</a><hr><a name="_details"></a><h2>Detailed Description</h2>
A class for spline interpolation. 
<p>
The QwtSpline class is used for cubical spline interpolation. Two types of splines, natural and periodic, are supported.<p>
<dl compact><dt><b>Usage:</b></dt><dd><ol>
<li>
First call <a class="el" href="class_qwt_spline.html#a3">QwtSpline::recalc()</a> to determine the spline coefficients for a tabulated function y(x). </li>
<li>
After the coefficients have been set up, the interpolated function value for an argument x can be determined by calling <a class="el" href="class_qwt_spline.html#a2">QwtSpline::value()</a>. </li>
</ol>
In order to save storage space, QwtSpline can be advised not to buffer the contents of x and y. This means that the arrays have to remain valid and unchanged for the interpolation to work properly. This can be achieved by calling <a class="el" href="class_qwt_spline.html#a5">QwtSpline::copyValues()</a>.</dd></dl>
<dl compact><dt><b>Example:</b></dt><dd><div class="fragment"><pre><span class="preprocessor">#include&lt;qwt_spline.h&gt;</span>
<span class="preprocessor">#include&lt;iostream.h&gt;</span>

<a class="code" href="class_qwt_spline.html">QwtSpline</a> s;
<span class="keywordtype">double</span> x[30], y[30], xInter[300], yInter[300];
<span class="keywordtype">int</span> i;

<span class="keywordflow">for</span>(i=0;i&lt;30;i++)               <span class="comment">// fill up x[] and y[]</span>
cin &gt;&gt; x[i] &gt;&gt; y[i];

<span class="keywordflow">if</span> (s.<a class="code" href="class_qwt_spline.html#a3">recalc</a>(x,y,30,0) == 0)    <span class="comment">// build natural spline</span>
{
   <span class="keywordflow">for</span>(i=0;i&lt;300;i++)          <span class="comment">// interpolate</span>
   {
     xInter[i] = x[0] + double(i) * (x[29] - x[0]) / 299.0;
     yInter[i] = s.<a class="code" href="class_qwt_spline.html#a2">value</a>( xInter[i] );
   }

   do_something(xInter, yInter, 300);
}
<span class="keywordflow">else</span>
  cerr &lt;&lt; <span class="stringliteral">"Uhhh...\n"</span>;
</pre></div></dd></dl>

<p>
Definition at line <a class="el" href="qwt__spline_8h-source.html#l00063">63</a> of file <a class="el" href="qwt__spline_8h-source.html">qwt_spline.h</a>.<table border=0 cellpadding=0 cellspacing=0>
<tr><td></td></tr>
<tr><td colspan=2><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top>&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="class_qwt_spline.html#a0">QwtSpline</a> ()</td></tr>

<tr><td class="memItemLeft" nowrap align=right valign=top>&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="class_qwt_spline.html#a1">~QwtSpline</a> ()</td></tr>

<tr><td class="memItemLeft" nowrap align=right valign=top>double&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="class_qwt_spline.html#a2">value</a> (double x) const</td></tr>

<tr><td class="memItemLeft" nowrap align=right valign=top>int&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="class_qwt_spline.html#a3">recalc</a> (double *x, double *y, int n, int periodic=0)</td></tr>

<tr><td class="memItemLeft" nowrap align=right valign=top>int&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="class_qwt_spline.html#a4">recalc</a> (const QwtArray&lt; double &gt; &amp;x, const QwtArray&lt; double &gt; &amp;y, int periodic=0)</td></tr>

<tr><td class="memItemLeft" nowrap align=right valign=top>void&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="class_qwt_spline.html#a5">copyValues</a> (int tf=1)</td></tr>

</table>
<hr><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" name="a0" doxytag="QwtSpline::QwtSpline" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> QwtSpline::QwtSpline           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="mdname1" valign="top" nowrap>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
CTOR. 
<p>
Definition at line <a class="el" href="qwt__spline_8cpp-source.html#l00031">31</a> of file <a class="el" href="qwt__spline_8cpp-source.html">qwt_spline.cpp</a>.    </td>
  </tr>
</table>
<a class="anchor" name="a1" doxytag="QwtSpline::~QwtSpline" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> QwtSpline::~<a class="el" href="class_qwt_spline.html">QwtSpline</a>           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="mdname1" valign="top" nowrap>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
DTOR. 
<p>
Definition at line <a class="el" href="qwt__spline_8cpp-source.html#l00068">68</a> of file <a class="el" href="qwt__spline_8cpp-source.html">qwt_spline.cpp</a>.    </td>
  </tr>
</table>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="a5" doxytag="QwtSpline::copyValues" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> void QwtSpline::copyValues           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top">int&nbsp;</td>
          <td class="mdname1" valign="top" nowrap> <em>tf</em> = <code>1</code>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Advise <a class="el" href="class_qwt_spline.html#a3">recalc()</a> to buffer the tabulated function or switch off internal buffering. 
<p>
By default, QwtSpline maintains an internal copy of the tabulated function given as *x and *y arguments of <a class="el" href="class_qwt_spline.html#a3">QwtSpline::recalc()</a>.<p>
If <a class="el" href="class_qwt_spline.html#a5">QwtSpline::copyValues()</a> is called with zero argument, subsequent calls to <a class="el" href="class_qwt_spline.html#a3">QwtSpline::recalc()</a> will not buffer these values anymore and just store the pointers instead. The <a class="el" href="class_qwt_spline.html#a2">QwtSpline::value()</a> function will then silently assume that these pointers remained valid and that the contents of the arrays have not been changed since the last <a class="el" href="class_qwt_spline.html#a3">QwtSpline::recalc()</a>.<p>
If called with no or nonzero argument, any following <a class="el" href="class_qwt_spline.html#a3">QwtSpline::recalc()</a> calls will use the internal buffer.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td></td><td valign=top><em>tf</em>&nbsp;</td><td>if nonzero, the function table will be buffered </td></tr>
  </table>
</dl>
<dl compact><dt><b>Warning:</b></dt><dd><a class="el" href="class_qwt_spline.html#a5">copyValues()</a> resets all the contents of QwtSpline. A subsequent <a class="el" href="class_qwt_spline.html#a3">recalc()</a> will be necessary. </dd></dl>
Definition at line <a class="el" href="qwt__spline_8cpp-source.html#l00061">61</a> of file <a class="el" href="qwt__spline_8cpp-source.html">qwt_spline.cpp</a>.    </td>
  </tr>
</table>
<a class="anchor" name="a4" doxytag="QwtSpline::recalc" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> int QwtSpline::recalc           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top">const QwtArray&lt; double &gt; &amp;&nbsp;</td>
          <td class="mdname" nowrap> <em>x</em>, </td>
        </tr>
        <tr>
          <td class="md" nowrap align="right"></td>
          <td></td>
          <td class="md" nowrap>const QwtArray&lt; double &gt; &amp;&nbsp;</td>
          <td class="mdname" nowrap> <em>y</em>, </td>
        </tr>
        <tr>
          <td class="md" nowrap align="right"></td>
          <td></td>
          <td class="md" nowrap>int&nbsp;</td>
          <td class="mdname" nowrap> <em>periodic</em> = <code>0</code></td>
        </tr>
        <tr>
          <td></td>
          <td class="md">)&nbsp;</td>
          <td class="md" colspan="2"></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
re-calculate the spline coefficients 
<p>
Depending on the value of <em>periodic</em>, this function will determine the coefficients for a natural or a periodic spline and store them internally. It also buffers the values of x and y, which are needed for the interpolation (See <a class="el" href="class_qwt_spline.html#a2">QwtSpline::value()</a>). <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td></td><td valign=top><em>x</em>&nbsp;</td><td>QwtArray&lt;double&gt; of points </td></tr>
    <tr><td></td><td valign=top><em>y</em>&nbsp;</td><td>QwtArray&lt;double&gt; of points </td></tr>
    <tr><td></td><td valign=top><em>periodic</em>&nbsp;</td><td>if non-zero, calculate periodic spline </td></tr>
  </table>
</dl>
<dl compact><dt><b>Returns:</b></dt><dd><dl>
<dt>0</dt>
<dd>successful </dd>
<dt>Qwt::ErrMono&lt;dd&gt;Sequence of x values is not strictly monotone increasing </dt>
<dd></dd>
<dt>Qwt::ErrNoMem&lt;dd&gt;Couldn't allocate memory </dt>
<dd></dd>
</dl>
</dd></dl>
<dl compact><dt><b>Warning:</b></dt><dd>The sequence of x (but not y) values has to be strictly monotone increasing, which means <code>x[0] &lt; x[1] &lt; .... &lt; x[n-1]</code>. If this is not the case, the function will return an error. </dd></dl>
Definition at line <a class="el" href="qwt__spline_8cpp-source.html#l00206">206</a> of file <a class="el" href="qwt__spline_8cpp-source.html">qwt_spline.cpp</a>.
<p>
References <a class="el" href="qwt__spline_8cpp-source.html#l00127">recalc()</a>.    </td>
  </tr>
</table>
<a class="anchor" name="a3" doxytag="QwtSpline::recalc" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> int QwtSpline::recalc           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top">double *&nbsp;</td>
          <td class="mdname" nowrap> <em>x</em>, </td>
        </tr>
        <tr>
          <td class="md" nowrap align="right"></td>
          <td></td>
          <td class="md" nowrap>double *&nbsp;</td>
          <td class="mdname" nowrap> <em>y</em>, </td>
        </tr>
        <tr>
          <td class="md" nowrap align="right"></td>
          <td></td>
          <td class="md" nowrap>int&nbsp;</td>
          <td class="mdname" nowrap> <em>n</em>, </td>
        </tr>
        <tr>
          <td class="md" nowrap align="right"></td>
          <td></td>
          <td class="md" nowrap>int&nbsp;</td>
          <td class="mdname" nowrap> <em>periodic</em> = <code>0</code></td>
        </tr>
        <tr>
          <td></td>
          <td class="md">)&nbsp;</td>
          <td class="md" colspan="2"></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
re-calculate the spline coefficients 
<p>
Depending on the value of <em>periodic</em>, this function will determine the coefficients for a natural or a periodic spline and store them internally. By default, it also buffers the values of x and y, which are needed for the interpolation (See <a class="el" href="class_qwt_spline.html#a2">QwtSpline::value()</a>). In order to save memory, this last behaviour may be changed with the <a class="el" href="class_qwt_spline.html#a5">QwtSpline::copyValues()</a> function.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td></td><td valign=top><em>x</em>&nbsp;</td><td></td></tr>
    <tr><td></td><td valign=top><em>y</em>&nbsp;</td><td>points </td></tr>
    <tr><td></td><td valign=top><em>n</em>&nbsp;</td><td>number of points </td></tr>
    <tr><td></td><td valign=top><em>periodic</em>&nbsp;</td><td>if non-zero, calculate periodic spline </td></tr>
  </table>
</dl>
<dl compact><dt><b>Returns:</b></dt><dd><dl>
<dt>0</dt>
<dd>successful </dd>
<dt>Qwt::ErrMono&lt;dd&gt;Sequence of x values is not strictly monotone increasing </dt>
<dd></dd>
<dt>Qwt::ErrNoMem&lt;dd&gt;Couldn't allocate memory </dt>
<dd></dd>
</dl>
</dd></dl>
<dl compact><dt><b>Warning:</b></dt><dd>The sequence of x (but not y) values has to be strictly monotone increasing, which means <code>x[0] &lt; x[1] &lt; .... &lt; x[n-1]</code>. If this is not the case, the function will return an error. </dd></dl>
Definition at line <a class="el" href="qwt__spline_8cpp-source.html#l00127">127</a> of file <a class="el" href="qwt__spline_8cpp-source.html">qwt_spline.cpp</a>.
<p>
Referenced by <a class="el" href="qwt__curve_8cpp-source.html#l00583">QwtCurve::drawSpline()</a>, and <a class="el" href="qwt__spline_8cpp-source.html#l00206">recalc()</a>.    </td>
  </tr>
</table>
<a class="anchor" name="a2" doxytag="QwtSpline::value" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> double QwtSpline::value           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top">double&nbsp;</td>
          <td class="mdname1" valign="top" nowrap> <em>x</em>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap> const</td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Calculate the interpolated function value corresponding to a given argument x. Definition at line <a class="el" href="qwt__spline_8cpp-source.html#l00018">18</a> of file <a class="el" href="qwt__spline_8cpp-source.html">qwt_spline.cpp</a>.
<p>
Referenced by <a class="el" href="qwt__curve_8cpp-source.html#l00583">QwtCurve::drawSpline()</a>.    </td>
  </tr>
</table>
<hr size="1"><address style="align: right;"><small>Generated on Tue Nov 16 21:12:41 2004 for Qwt User's Guide by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.8 </small></address>
</body>
</html>