9 #include "IException.h"
10 #include "Interpolator.h"
17 Interpolator::Interpolator() {
34 Interpolator::~Interpolator() {}
37 void Interpolator::Init() {
56 double Interpolator::Interpolate(
const double isamp,
const double iline,
61 string message =
"Interpolator type not set";
62 throw IException(IException::Programmer, message, _FILEINFO_);
65 case NearestNeighborType:
66 return NearestNeighbor(isamp, iline, buf);
69 return BiLinear(isamp, iline, buf);
71 case CubicConvolutionType:
72 return CubicConvolution(isamp, iline, buf);
76 string message =
"Invalid interpolator";
77 throw IException(IException::Programmer, message, _FILEINFO_);
101 double Interpolator::NearestNeighbor(
const double isamp,
const double iline,
102 const double buf[]) {
118 double Interpolator::BiLinear(
const double isamp,
const double iline,
119 const double buf[]) {
122 double j = int (isamp);
123 double k = int (iline);
124 double a = isamp - j;
125 double b = iline - k;
128 for(
int i = 0; i < 4; i++) {
130 return NearestNeighbor(isamp, iline,
131 &buf[(
int)(a + 0.5) + 2 * (
int)(b+0.5)]);
137 return (1.0 - a) * (1.0 - b) * buf[0] +
138 a * (1.0 - b) * buf[1] +
139 (1.0 - a) * b * buf[2] +
156 double Interpolator::CubicConvolution(
const double isamp,
158 const double buf[]) {
161 for(
int i = 0; i < 16; i++) {
163 double tbuf[4] = {buf[5], buf[6], buf[9], buf[10]};
164 return BiLinear(isamp, iline, tbuf);
169 double j = int (isamp);
170 double k = int (iline);
171 double a = isamp - j;
172 double b = iline - k;
181 return -b * (1.0 - b) * (1.0 - b) * (-a * (1.0 - a) * (1.0 - a) * buf[0] +
182 (1.0 - 2.0 * a * a + a * a * a) * buf[1] +
183 a * (1.0 + a - a * a) * buf[2] -
184 a * a * (1.0 - a) * buf[3]) +
186 (1.0 - 2.0 * b * b + b * b * b) * (-a * (1.0 - a) * (1.0 - a) * buf[4] +
187 (1.0 - 2.0 * a * a + a * a * a) * buf[5] +
188 a * (1.0 + a - a * a) * buf[6] -
189 a * a * (1.0 - a) * buf[7]) +
191 b * (1.0 + b - b * b) * (-a * (1.0 - a) * (1.0 - a) * buf[8] +
192 (1.0 - 2.0 * a * a + a * a * a) * buf[9] +
193 a * (1.0 + a - a * a) * buf[10] -
194 a * a * (1.0 - a) * buf[11]) +
196 b * b * (b - 1.0) * (-a * (1.0 - a) * (1.0 - a) * buf[12] +
197 (1.0 - 2.0 * a * a + a * a * a) * buf[13] +
198 a * (1.0 + a - a * a) * buf[14] -
199 a * a * (1.0 - a) * buf[15]);
208 int Interpolator::Samples() {
212 string message =
"Interpolator type not set";
213 throw IException(IException::Programmer, message, _FILEINFO_);
216 case NearestNeighborType:
222 case CubicConvolutionType:
227 string message =
"Invalid interpolator";
228 throw IException(IException::Programmer, message, _FILEINFO_);
236 int Interpolator::Lines() {
240 string message =
"Interpolator type not set";
241 throw IException(IException::Programmer, message, _FILEINFO_);
244 case NearestNeighborType:
250 case CubicConvolutionType:
255 string message =
"Invalid interpolator";
256 throw IException(IException::Programmer, message, _FILEINFO_);
265 double Interpolator::HotSample() {
269 string message =
"Interpolator type not set";
270 throw IException(IException::Programmer, message, _FILEINFO_);
274 case NearestNeighborType:
282 case CubicConvolutionType:
287 string message =
"Invalid interpolator";
288 throw IException(IException::Programmer, message, _FILEINFO_);
297 double Interpolator::HotLine() {
301 string message =
"Interpolator type not set";
302 throw IException(IException::Programmer, message, _FILEINFO_);
306 case NearestNeighborType:
314 case CubicConvolutionType:
319 string message =
"Invalid interpolator";
320 throw IException(IException::Programmer, message, _FILEINFO_);