source: trunk/src/Interpolator1D.cpp @ 2731

Last change on this file since 2731 was 2731, 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 Locator and its derived classes as template class.


File size: 1.5 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
26Interpolator1D::Interpolator1D()
27  : order_(1),
28    n_(0),
29    x_(0),
30    y_(0),
31    locator_(0)
32{
33}
34
35Interpolator1D::~Interpolator1D()
36{
37  if (locator_)
38    delete locator_;
39}
40
41void Interpolator1D::setData(double *x, float *y, unsigned int n)
42{
43  x_ = x;
44  y_ = y;
45  n_ = n;
46  createLocator();
47  locator_->set(x, n);
48}
49
50void Interpolator1D::setX(double *x, unsigned int n)
51{
52  assert(n_ == 0 || n_ == n);
53  x_ = x;
54  n_ = n;
55  createLocator();
56  locator_->set(x, n);
57}
58
59void Interpolator1D::setY(float *y, unsigned int n)
60{
61  assert(n_ == 0 || n_ == n);
62  y_ = y;
63  n_ = n;
64}
65
66void Interpolator1D::reset()
67{
68  n_ = 0;
69  x_ = 0;
70  y_ = 0;
71  if (locator_) {
72    delete locator_;
73    locator_ = 0;
74  }
75}
76
77bool Interpolator1D::isready()
78{
79  return (n_ > 0 && x_ != 0 && y_ != 0);
80}
81
82unsigned int Interpolator1D::locate(double x)
83{
84  return locator_->locate(x);
85}
86
87void Interpolator1D::createLocator()
88{
89  if (!locator_) {
90    if (n_ > 1000)
91      locator_ = new HuntLocator<double>();
92    else
93      locator_ = new BisectionLocator<double>();
94  }
95}
96
97}
Note: See TracBrowser for help on using the repository browser.