source: trunk/src/Interpolator1D.tcc @ 2733

Last change on this file since 2733 was 2733, checked in by Takeshi Nakazato, 11 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.7 KB
Line 
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
22using namespace casa;
23
24namespace asap {
25
26template <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
35template <class T, class U> Interpolator1D<T, U>::~Interpolator1D()
36{
37  if (locator_)
38    delete locator_;
39}
40
41template <class T, class U>
42void 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
51template <class T, class U>
52void 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
61template <class T, class U>
62void Interpolator1D<T, U>::setY(U *y, unsigned int n)
63{
64  assert(n_ == 0 || n_ == n);
65  y_ = y;
66  n_ = n;
67}
68
69template <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
80template <class T, class U> bool Interpolator1D<T, U>::isready()
81{
82  return (n_ > 0 && x_ != 0 && y_ != 0);
83}
84
85template <class T, class U> unsigned int Interpolator1D<T, U>::locate(T x)
86{
87  return locator_->locate(x);
88}
89
90template <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}
Note: See TracBrowser for help on using the repository browser.