Newer
Older
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
{
val = 0.0;
kvector = kernel_vector;
for (i=kwidth; i--;)
val += *(kvector++)**(pixin++);
*(pixout++) = val;
for (n=1; n<naxis; n++)
{
pixin+=step[n-1];
if (++linecount[n]<prof->kernelwidth[n])
break;
else
linecount[n] = 0; /* No need to initialize it to 0! */
}
}
/* Second step: interpolate along other axes from the interpolation buffer */
for (n=1; n<naxis; n++)
{
make_kernel(dpos[n], kernel_vector, prof->interptype[n]);
kwidth = prof->kernelwidth[n];
pixout = pixin = prof->kernelbuf;
for (j = (nlines/=kwidth); j--;)
{
val = 0.0;
kvector = kernel_vector;
for (i=kwidth; i--;)
val += *(kvector++)**(pixin++);
*(pixout++) = val;
}
}
return prof->kernelbuf[0];
}
/****** interpolate_pix ******************************************************
PROTO void interpolate_pix(float *posin, float *pix, int naxisn,
interpenum interptype)
PURPOSE Interpolate a model profile at a given position.
INPUT Profile structure,
input position vector,
input pixmap dimension vector,
interpolation type.
OUTPUT -.
NOTES -.
AUTHOR E. Bertin (IAP)
VERSION 07/12/2006
***/
static float interpolate_pix(float *posin, float *pix, int *naxisn,
float buffer[INTERP_MAXKERNELWIDTH],
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
kernel[INTERP_MAXKERNELWIDTH], dpos[2],
*kvector, *pixin, *pixout,
val;
int fac, ival, kwidth, start, width, step,
i,j, n;
kwidth = interp_kernwidth[interptype];
start = 0;
fac = 1;
for (n=0; n<2; n++)
{
val = *(posin++);
width = naxisn[n];
/*-- Get the integer part of the current coordinate or nearest neighbour */
ival = (interptype==INTERP_NEARESTNEIGHBOUR)? (int)(val-0.50001):(int)val;
/*-- Store the fractional part of the current coordinate */
dpos[n] = val - ival;
/*-- Check if interpolation start/end exceed image boundary... */
ival-=kwidth/2;
if (ival<0 || ival+kwidth<=0 || ival+kwidth>width)
return 0.0;
/*-- Update starting pointer */
start += ival*fac;
/*-- Update step between interpolated regions */
fac *= width;
}
/* First step: interpolate along NAXIS1 from the data themselves */
make_kernel(dpos[0], kernel, interptype);
step = naxisn[0]-kwidth;
pixin = pix+start;
pixout = buffer;
for (j=kwidth; j--;)
{
val = 0.0;
kvector = kernel;
for (i=kwidth; i--;)
val += *(kvector++)**(pixin++);
*(pixout++) = val;
pixin += step;
}
/* Second step: interpolate along NAXIS2 from the interpolation buffer */
make_kernel(dpos[1], kernel, interptype);
pixin = buffer;
val = 0.0;
kvector = kernel;
for (i=kwidth; i--;)
val += *(kvector++)**(pixin++);
return val;
}
/****** make_kernel **********************************************************
PROTO void make_kernel(float pos, float *kernel, interpenum interptype)
PURPOSE Conpute interpolation-kernel data
INPUT Position,
Pointer to the output kernel data,
Interpolation method.
OUTPUT -.
NOTES -.
AUTHOR E. Bertin (IAP)
void make_kernel(float pos, float *kernel, interpenum interptype)
float x, val, sinx1,sinx2,sinx3,cosx1;
if (interptype == INTERP_NEARESTNEIGHBOUR)
*kernel = 1;
else if (interptype == INTERP_BILINEAR)
{
*(kernel++) = 1.0-pos;
*kernel = pos;
}
else if (interptype == INTERP_LANCZOS2)
{
if (pos<1e-5 && pos>-1e-5)
{
*(kernel++) = 0.0;
*(kernel++) = 1.0;
*(kernel++) = 0.0;
*kernel = 0.0;
}
else
{
x = -PI/2.0*(pos+1.0);
sincosf(x, &sinx1, &cosx1);
sinx1 = sinf(x);
cosx1 = cosf(x);
#endif
val = (*(kernel++) = sinx1/(x*x));
x += PI/2.0;
val += (*(kernel++) = -cosx1/(x*x));
x += PI/2.0;
val += (*(kernel++) = -sinx1/(x*x));
x += PI/2.0;
val += (*kernel = cosx1/(x*x));
val = 1.0/val;
*(kernel--) *= val;
*(kernel--) *= val;
*(kernel--) *= val;
*kernel *= val;
}
}
else if (interptype == INTERP_LANCZOS3)
{
if (pos<1e-5 && pos>-1e-5)
{
*(kernel++) = 0.0;
*(kernel++) = 0.0;
*(kernel++) = 1.0;
*(kernel++) = 0.0;
*(kernel++) = 0.0;
*kernel = 0.0;
}
else
{
x = -PI/3.0*(pos+2.0);
#ifdef HAVE_SINCOS
sincosf(x, &sinx1, &cosx1);
sinx1 = sinf(x);
cosx1 = cosf(x);
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
#endif
val = (*(kernel++) = sinx1/(x*x));
x += PI/3.0;
val += (*(kernel++) = (sinx2=-0.5*sinx1-0.866025403785*cosx1)
/ (x*x));
x += PI/3.0;
val += (*(kernel++) = (sinx3=-0.5*sinx1+0.866025403785*cosx1)
/(x*x));
x += PI/3.0;
val += (*(kernel++) = sinx1/(x*x));
x += PI/3.0;
val += (*(kernel++) = sinx2/(x*x));
x += PI/3.0;
val += (*kernel = sinx3/(x*x));
val = 1.0/val;
*(kernel--) *= val;
*(kernel--) *= val;
*(kernel--) *= val;
*(kernel--) *= val;
*(kernel--) *= val;
*kernel *= val;
}
}
else if (interptype == INTERP_LANCZOS4)
{
if (pos<1e-5 && pos>-1e-5)
{
*(kernel++) = 0.0;
*(kernel++) = 0.0;
*(kernel++) = 0.0;
*(kernel++) = 1.0;
*(kernel++) = 0.0;
*(kernel++) = 0.0;
*(kernel++) = 0.0;
*kernel = 0.0;
}
else
{
x = -PI/4.0*(pos+3.0);
#ifdef HAVE_SINCOS
sincosf(x, &sinx1, &cosx1);
sinx1 = sinf(x);
cosx1 = cosf(x);
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
#endif
val = (*(kernel++) = sinx1/(x*x));
x += PI/4.0;
val +=(*(kernel++) = -(sinx2=0.707106781186*(sinx1+cosx1))
/(x*x));
x += PI/4.0;
val += (*(kernel++) = cosx1/(x*x));
x += PI/4.0;
val += (*(kernel++) = -(sinx3=0.707106781186*(cosx1-sinx1))/(x*x));
x += PI/4.0;
val += (*(kernel++) = -sinx1/(x*x));
x += PI/4.0;
val += (*(kernel++) = sinx2/(x*x));
x += PI/4.0;
val += (*(kernel++) = -cosx1/(x*x));
x += PI/4.0;
val += (*kernel = sinx3/(x*x));
val = 1.0/val;
*(kernel--) *= val;
*(kernel--) *= val;
*(kernel--) *= val;
*(kernel--) *= val;
*(kernel--) *= val;
*(kernel--) *= val;
*(kernel--) *= val;
*kernel *= val;
}
}
else
error(EXIT_FAILURE, "*Internal Error*: Unknown interpolation type in ",
"make_kernel()");
return;
}