1 | // |
---|
2 | // C++ Implementation: Interpolator1D |
---|
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 <casa/Arrays/Vector.h> |
---|
15 | #include <casa/Exceptions/Error.h> |
---|
16 | |
---|
17 | #include "Interpolator1D.h" |
---|
18 | #include "Locator.h" |
---|
19 | #include "BisectionLocator.h" |
---|
20 | #include "HuntLocator.h" |
---|
21 | |
---|
22 | using namespace casa; |
---|
23 | |
---|
24 | namespace asap { |
---|
25 | |
---|
26 | template <class T, class U> Interpolator1D<T, U>::Interpolator1D() |
---|
27 | : order_(1), |
---|
28 | n_(0), |
---|
29 | x_(0), |
---|
30 | y_(0), |
---|
31 | locator_(0) |
---|
32 | { |
---|
33 | } |
---|
34 | |
---|
35 | template <class T, class U> Interpolator1D<T, U>::~Interpolator1D() |
---|
36 | { |
---|
37 | if (locator_) |
---|
38 | delete locator_; |
---|
39 | } |
---|
40 | |
---|
41 | template <class T, class U> |
---|
42 | void Interpolator1D<T, U>::setData(T *x, U *y, unsigned int n) |
---|
43 | { |
---|
44 | x_ = x; |
---|
45 | y_ = y; |
---|
46 | n_ = n; |
---|
47 | createLocator(); |
---|
48 | locator_->set(x, n); |
---|
49 | } |
---|
50 | |
---|
51 | template <class T, class U> |
---|
52 | void Interpolator1D<T, U>::setX(T *x, unsigned int n) |
---|
53 | { |
---|
54 | assert(n_ == 0 || n_ == n); |
---|
55 | x_ = x; |
---|
56 | n_ = n; |
---|
57 | createLocator(); |
---|
58 | locator_->set(x, n); |
---|
59 | } |
---|
60 | |
---|
61 | template <class T, class U> |
---|
62 | void Interpolator1D<T, U>::setY(U *y, unsigned int n) |
---|
63 | { |
---|
64 | assert(n_ == 0 || n_ == n); |
---|
65 | y_ = y; |
---|
66 | n_ = n; |
---|
67 | } |
---|
68 | |
---|
69 | template <class T, class U> void Interpolator1D<T, U>::reset() |
---|
70 | { |
---|
71 | n_ = 0; |
---|
72 | x_ = 0; |
---|
73 | y_ = 0; |
---|
74 | if (locator_) { |
---|
75 | delete locator_; |
---|
76 | locator_ = 0; |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | template <class T, class U> bool Interpolator1D<T, U>::isready() |
---|
81 | { |
---|
82 | return (n_ > 0 && x_ != 0 && y_ != 0); |
---|
83 | } |
---|
84 | |
---|
85 | template <class T, class U> unsigned int Interpolator1D<T, U>::locate(T x) |
---|
86 | { |
---|
87 | return locator_->locate(x); |
---|
88 | } |
---|
89 | |
---|
90 | template <class T, class U> void Interpolator1D<T, U>::createLocator() |
---|
91 | { |
---|
92 | if (!locator_) { |
---|
93 | if (n_ > 1000) |
---|
94 | locator_ = new HuntLocator<T>(); |
---|
95 | else |
---|
96 | locator_ = new BisectionLocator<T>(); |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | } |
---|