| 1 |
chrisfen |
1287 |
/*************************************************************************** |
| 2 |
|
|
************************************************************************** |
| 3 |
|
|
|
| 4 |
|
|
S2kit 1.0 |
| 5 |
|
|
|
| 6 |
|
|
A lite version of Spherical Harmonic Transform Kit |
| 7 |
|
|
|
| 8 |
|
|
Peter Kostelec, Dan Rockmore |
| 9 |
|
|
{geelong,rockmore}@cs.dartmouth.edu |
| 10 |
|
|
|
| 11 |
|
|
Contact: Peter Kostelec |
| 12 |
|
|
geelong@cs.dartmouth.edu |
| 13 |
|
|
|
| 14 |
|
|
Copyright 2004 Peter Kostelec, Dan Rockmore |
| 15 |
|
|
|
| 16 |
|
|
This file is part of S2kit. |
| 17 |
|
|
|
| 18 |
|
|
S2kit is free software; you can redistribute it and/or modify |
| 19 |
|
|
it under the terms of the GNU General Public License as published by |
| 20 |
|
|
the Free Software Foundation; either version 2 of the License, or |
| 21 |
|
|
(at your option) any later version. |
| 22 |
|
|
|
| 23 |
|
|
S2kit is distributed in the hope that it will be useful, |
| 24 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 26 |
|
|
GNU General Public License for more details. |
| 27 |
|
|
|
| 28 |
|
|
You should have received a copy of the GNU General Public License |
| 29 |
|
|
along with S2kit; if not, write to the Free Software |
| 30 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 31 |
|
|
|
| 32 |
|
|
See the accompanying LICENSE file for details. |
| 33 |
|
|
|
| 34 |
|
|
************************************************************************ |
| 35 |
|
|
************************************************************************/ |
| 36 |
|
|
|
| 37 |
|
|
|
| 38 |
|
|
|
| 39 |
|
|
/* source code for generating cosine transforms |
| 40 |
|
|
of Pml and Gml functions */ |
| 41 |
|
|
|
| 42 |
|
|
#include <math.h> |
| 43 |
|
|
#include <string.h> /* to declare memcpy */ |
| 44 |
|
|
#include <stdlib.h> |
| 45 |
|
|
#include <stdio.h> |
| 46 |
|
|
|
| 47 |
|
|
#include "primitive.h" |
| 48 |
|
|
|
| 49 |
|
|
/************************************************************************/ |
| 50 |
|
|
/* generate all of the Pmls for a specified value of m. |
| 51 |
|
|
|
| 52 |
|
|
storeplm points to a double array of size 2 * bw * (bw - m); |
| 53 |
|
|
|
| 54 |
|
|
Workspace needs to be |
| 55 |
|
|
16 * bw |
| 56 |
|
|
|
| 57 |
|
|
P(m,l,j) respresents the associated Legendre function P_l^m |
| 58 |
|
|
evaluated at the j-th Chebyshev point (for the bandwidth bw) |
| 59 |
|
|
Cos((2 * j + 1) * PI / (2 * bw)). |
| 60 |
|
|
|
| 61 |
|
|
The array is placed in storeplm as follows: |
| 62 |
|
|
|
| 63 |
|
|
P(m,m,0) P(m,m,1) ... P(m,m,2*bw-1) |
| 64 |
|
|
P(m,m+1,0) P(m,m+1,1)... P(m,m+1,2*bw-1) |
| 65 |
|
|
P(m,m+2,0) P(m,m+2,1)... P(m,m+2,2*bw-1) |
| 66 |
|
|
... |
| 67 |
|
|
P(m,bw-1,0) P(m,bw-1,1) ... P(m,bw-1,2*bw-1) |
| 68 |
|
|
|
| 69 |
|
|
This array will eventually be used by the naive transform algorithm. |
| 70 |
|
|
This function will precompute the arrays necessary for the algorithm. |
| 71 |
|
|
*/ |
| 72 |
|
|
|
| 73 |
|
|
void PmlTableGen(int bw, |
| 74 |
|
|
int m, |
| 75 |
|
|
double *storeplm, |
| 76 |
|
|
double *workspace) |
| 77 |
|
|
{ |
| 78 |
|
|
double *prev, *prevprev; |
| 79 |
|
|
double *temp1, *temp2, *temp3, *temp4; |
| 80 |
|
|
double *x_i, *eval_args; |
| 81 |
|
|
int i; |
| 82 |
|
|
|
| 83 |
|
|
prevprev = workspace; |
| 84 |
|
|
prev = prevprev + (2*bw); |
| 85 |
|
|
temp1 = prev + (2*bw); |
| 86 |
|
|
temp2 = temp1 + (2*bw); |
| 87 |
|
|
temp3 = temp2 + (2*bw); |
| 88 |
|
|
temp4 = temp3 + (2*bw); |
| 89 |
|
|
x_i = temp4 + (2*bw); |
| 90 |
|
|
eval_args = x_i + (2*bw); |
| 91 |
|
|
|
| 92 |
|
|
|
| 93 |
|
|
/* get the evaluation nodes */ |
| 94 |
|
|
EvalPts(2*bw,x_i); |
| 95 |
|
|
ArcCosEvalPts(2*bw,eval_args); |
| 96 |
|
|
|
| 97 |
|
|
/* set initial values of first two Pmls */ |
| 98 |
|
|
for (i=0; i<2*bw; i++) |
| 99 |
|
|
prevprev[i] = 0.0; |
| 100 |
|
|
if (m == 0) |
| 101 |
|
|
for (i=0; i<2*bw; i++) |
| 102 |
|
|
prev[i] = 0.707106781186547 ; |
| 103 |
|
|
else |
| 104 |
|
|
Pmm_L2(m, eval_args, 2*bw, prev); |
| 105 |
|
|
|
| 106 |
|
|
memcpy(storeplm, prev, sizeof(double) * 2 * bw); |
| 107 |
|
|
|
| 108 |
|
|
for(i = 0; i < bw - m - 1; i++) |
| 109 |
|
|
{ |
| 110 |
|
|
vec_mul(L2_cn(m,m+i),prevprev,temp1,2*bw); |
| 111 |
|
|
vec_pt_mul(prev, x_i, temp2, 2*bw); |
| 112 |
|
|
vec_mul(L2_an(m,m+i), temp2, temp3, 2*bw); |
| 113 |
|
|
vec_add(temp3, temp1, temp4, 2*bw); /* temp4 now contains P(m,m+i+1) */ |
| 114 |
|
|
|
| 115 |
|
|
storeplm += (2 * bw); |
| 116 |
|
|
memcpy(storeplm, temp4, sizeof(double) * 2 * bw); |
| 117 |
|
|
memcpy(prevprev, prev, sizeof(double) * 2 * bw); |
| 118 |
|
|
memcpy(prev, temp4, sizeof(double) * 2 * bw); |
| 119 |
|
|
} |
| 120 |
|
|
} |
| 121 |
|
|
|
| 122 |
|
|
|