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