source: trunk/src/BufferedLinearInterpolator1D.tcc@ 2746

Last change on this file since 2746 was 2733, checked in by Takeshi Nakazato, 12 years ago

New Development: No

JIRA Issue: Yes CAS-4770

Ready for Test: Yes

Interface Changes: Yes/No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Redefined Interpolator1D and derived classes as template class.


File size: 1.5 KB
Line 
1//
2// C++ Implementation: BufferedLinearInterpolator1D
3//
4// Description:
5//
6//
7// Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp>, (C) 2012
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#include <assert.h>
13
14#include "BufferedLinearInterpolator1D.h"
15
16namespace asap {
17
18template <class T, class U>
19BufferedLinearInterpolator1D<T, U>::BufferedLinearInterpolator1D()
20 : Interpolator1D<T, U>(),
21 reusable_(false)
22{}
23
24template <class T, class U>
25BufferedLinearInterpolator1D<T, U>::~BufferedLinearInterpolator1D()
26{}
27
28template <class T, class U>
29void BufferedLinearInterpolator1D<T, U>::setData(T *x, U *y, unsigned int n)
30{
31 Interpolator1D<T, U>::setData(x, y, n);
32 reusable_ = false;
33}
34
35template <class T, class U>
36void BufferedLinearInterpolator1D<T, U>::setX(T *x, unsigned int n)
37{
38 Interpolator1D<T, U>::setX(x, n);
39 reusable_ = false;
40}
41
42template <class T, class U>
43U BufferedLinearInterpolator1D<T, U>::interpolate(T x)
44{
45 assert(this->isready());
46 if (this->n_ == 1)
47 return this->y_[0];
48
49 unsigned int i;
50 bool b = (reusable_ && x == xold_);
51 if (b) {
52 i = prev_;
53 }
54 else {
55 i = this->locator_->locate(x);
56 prev_ = i;
57 xold_ = x;
58 }
59
60 // do not perform extrapolation
61 if (i == 0) {
62 return this->y_[i];
63 }
64 else if (i == this->n_) {
65 return this->y_[i-1];
66 }
67
68 // linear interpolation
69 if (!b)
70 factor_ = (x - this->x_[i-1]) / (this->x_[i] - this->x_[i-1]);
71 U y = this->y_[i-1] + (this->y_[i] - this->y_[i-1]) * factor_;
72 reusable_ = true;
73 return y;
74}
75
76}
Note: See TracBrowser for help on using the repository browser.