Xmipp  v3.23.11-Nereus
primitive_FST.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  **************************************************************************
3 
4  Spherical Harmonic Transform Kit 2.7
5 
6 
7  Contact: Peter Kostelec
8  geelong@cs.dartmouth.edu
9 
10 
11  Copyright 1997-2003 Sean Moore, Dennis Healy,
12  Dan Rockmore, Peter Kostelec
13 
14 
15  Copyright 2004 Peter Kostelec, Dan Rockmore
16 
17 
18  SpharmonicKit 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  SpharmonicKit 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 this program; if not, write to the Free Software
30  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 
32 
33  Commercial use is absolutely prohibited.
34 
35  See the accompanying LICENSE file for details.
36 
37  ************************************************************************
38  ************************************************************************/
39 
40 
41 /**********************************************************
42 
43  Just some primitive (i.e. utility) functions that the
44  various flavours (hybrid, seminaive) of spherical transforms
45  share ...
46 
47 
48  ********************************************************/
49 
50 /*****************************************************************
51 
52  Given bandwidth bw, seanindex(m,l,bw) will give the position of the
53  coefficient f-hat(m,l) in the one-row array that Sean stores the spherical
54  coefficients. This is needed to help preserve the symmetry that the
55  coefficients have: (l = degree, m = order, and abs(m) <= l)
56 
57  f-hat(l,-m) = (-1)^m * conjugate( f-hat(l,m) )
58 
59  Thanks for your help Mark!
60 
61  ******************************************************************/
62 
63 #include <cmath>
64 
65 int seanindex(int m,
66  int l,
67  int bw)
68 {
69  int bigL;
70 
71  bigL = bw - 1;
72 
73  if( m >= 0 )
74  return( m * ( bigL + 1 ) - ( ( m * (m - 1) ) /2 ) + ( l - m ) );
75  else
76  return( ( ( bigL * ( bigL + 3 ) ) /2 ) + 1 +
77  ( ( bigL + m ) * ( bigL + m + 1 ) / 2 ) + ( l - std::abs( m ) ) );
78 }
79 
80 
81 /*****************************************************************
82  just like seanindex(m,l,bw) but returns the array coordinates
83  for (l,m) AND (l,-m)
84 
85  ASSUMING THE M IS GREATER THAN 0 !!!
86 
87  this is used in the FST_semi routine
88 
89  loc is a 2 element integer array
90 
91  ******************************************************************/
92 
93 void seanindex2(int m,
94  int l,
95  int bw,
96  int *loc)
97 {
98  int bigL;
99 
100  bigL = bw - 1;
101 
102  /* first index for (l,m) */
103  loc[0] = m * ( bigL + 1 ) - ( ( m * (m - 1) ) /2 ) + ( l - m );
104 
105  /* second index for (l,-m) */
106  loc[1] = ( ( bigL * ( bigL + 3 ) ) /2 ) + 1 +
107  ( ( bigL - m ) * ( bigL - m + 1 ) / 2 ) + ( l - m ) ;
108 
109 }
110 
111 
112 /****************************************************
113 
114  just a function to transpose a square array IN PLACE !!!
115 
116  array = array to transpose
117  size = dimension of array (assuming the array is square, size * size)
118 
119  **************************************************/
120 
121 void transpose(double *array,
122  int size)
123 {
124  int i, j;
125  double t1, t2, t3, t4;
126 
127  for(i = 0; i < size; i += 2)
128  {
129  t1 = array[(i * size) + i + 1];
130  array[(i * size) + i + 1] = array[((i + 1) * size) + i];
131  array[((i + 1) * size) + i] = t1;
132  for(j = (i + 2); j < size; j += 2)
133  {
134  t1 = array[(i*size)+j]; t2 = array[(i*size)+j+1];
135  t3 = array[((i+1)*size)+j]; t4 = array[((i+1)*size)+j+1];
136  array[(i*size)+j] = array[(j*size)+i];
137  array[(i*size)+j+1] = array[((j+1)*size)+i];
138  array[((i+1)*size)+j] = array[(j*size)+i+1];
139  array[((i+1)*size)+j+1] = array[((j+1)*size)+i+1];
140  array[(j*size)+i] = t1;
141  array[((j+1)*size)+i] = t2;
142  array[(j*size)+i+1] = t3;
143  array[((j+1)*size)+i+1] = t4;
144  }
145  }
146 }
147 
void abs(Image< double > &op)
#define i
void transpose(double *array, int size)
#define j
int m
int seanindex(int m, int l, int bw)
void seanindex2(int m, int l, int bw, int *loc)