iRoCS Toolbox  1.1.0
SH_backward.hh
Go to the documentation of this file.
1 /***************************************************************************
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 
40 Source code to test FORWARD spherical harmonic transform
41 using the seminaive and naive algorithms coded up during October, 1995.
42 It will compute the spherical coefficients of the function whose
43 sample values are given in the named input file, and will write
44 those coefficients in the named output file.
45 
46 In its current state, assuming that will seminaive at ALL orders.
47 If you wish to change this, modify the CUTOFF variable in this file, i.e.
48 cutoff = at what order to switch from semi-naive to naive algorithm
49 
50 WILL PRECOMPUTE IN MEMORY EVERYTHING BEFORE DOING TRANSFORM!
51 
52 Sample call
53 
54  test_s2_semi_memo_for sampleFile outputFile bw [output_format]
55 
56  test_s2_semi_memo_for y31_bw8.dat y31_coef.dat 8
57 
58  output_format is an optional argument:
59  = 0 -> coefficients in "code" order,
60  i.e. suitable for test_s2_semi_memo_inv
61 
62  = 1 -> coefficients in prettier "human" order,
63  i.e. if f_{l,m} is the coefficient of degree l, order m,
64  then the coefficients will be arranged this way:
65  f_{0,0},
66  f_{1,-1}, f_{1,0}, f_{1,1},
67  f_{2,-2}, f_{2,-1}, f_{2,0}, f_{2,1}, f_{2,2},
68  ...
69 
70 The default output format is "code" order. To help you out,
71 the function
72 
73  seanindex(m, l, bw)
74 
75 defined in FST_semi_memo.c, returns the array index of
76 the coefficient f_{l,m} (so you know where it goes). Since we're
77 talking in C here, the indexing begins at 0.
78 
79 The format of the input sample file will be an interleaved
80 real/imaginary parts of the function samples arranged in
81 "latitude-major" format, i.e. the function will be sampled
82 in this order:
83 
84  (theta_0, phi_0)
85  (theta_0, phi_1)
86  (theta_0, phi_2)
87  ...
88  (theta_0, phi_{bw-1})
89  (theta_1, phi_0)
90  (theta_1, phi_1)
91  ...
92  (theta_{bw-1}, phi_{bw-1})
93 
94  where theta_k = pi*(2*j+1)/(4*bw)
95  phi_j = 2*pi*k/(2*bw)
96 
97 The format of the output depends on whether or not it's human
98 or code-ordered. For code-ordered, it's interleaved real/imaginary.
99 For human-ordered, it's verbose and it's one coefficient per line,
100 e.g. l = 2 m = 1 2.3 + 6 I
101 
102 
103 */
104 
105 #ifndef SH_BACKWARD_HH
106 #define SH_BACKWARD_HH
107 
108 #ifdef HAVE_CONFIG_H
109 #include <config.hh>
110 #endif
111 
112 #include <fftw3.h>
113 
114 extern "C" {
115 #include <lmbs2kit/makeweights.h>
116 #include <lmbs2kit/cospmls.h>
117 #include <lmbs2kit/FST_semi_memo.h>
118 #include <lmbs2kit/csecond.h>
119 #include <lmbs2kit/primitive.h>
120 #include <lmbs2kit/naive_synthesis.h>
121 #include <lmbs2kit/seminaive.h>
122 #include <lmbs2kit/pmls.h>
123 }
124 
125 #include <map>
126 
127 /**************************************************/
128 /**************************************************/
130 {
131 
132 private:
133 
134  int i, size ;
135  int l, m, dummy;
136  int cutoff, order ;
137  int rank, howmany_rank ;
138  double *rdata, *idata ;
139  double *rcoeffs, *icoeffs ;
140  double *weights ;
141  double *seminaive_naive_tablespace, *workspace,
142  *trans_seminaive_naive_tablespace;
143  double **seminaive_naive_table, **trans_seminaive_naive_table;
144  double tstart, tstop;
145  fftw_plan idctPlan, ifftPlan ;
146  fftw_iodim dims[1], howmany_dims[1];
147  int _bw;
148  static std::map<int,SH_backward*> SH_backward_cache;
149 
150  class CacheCleaner
151  {
152  CacheCleaner();
153  void init();
154  ~CacheCleaner();
155  friend class SH_backward;
156  };
157 
158  SH_backward(const SH_backward&);
159  SH_backward(int bw);
160 
161  public:
162 
163  static SH_backward &instance(int bw);
164 
165  ~SH_backward();
166 
167  int sh_semi_memo_back(double const *indata, double *outdata);
168 
169 };
170 
171 #endif
static SH_backward & instance(int bw)
int sh_semi_memo_back(double const *indata, double *outdata)