r641: no message
[ctsim.git] / include / fourier.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          fourier.h
5 **   Purpose:       Header for Fourier transform functions
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  Dec 2000
8 **
9 **  This is part of the CTSim program
10 **  Copyright (c) 1983-2001 Kevin Rosenberg
11 **
12 **  $Id: fourier.h,v 1.7 2001/03/21 21:45:31 kevin Exp $
13 **
14 **  This program is free software; you can redistribute it and/or modify
15 **  it under the terms of the GNU General Public License (version 2) as
16 **  published by the Free Software Foundation.
17 **
18 **  This program is distributed in the hope that it will be useful,
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 **  GNU General Public License for more details.
22 **
23 **  You should have received a copy of the GNU General Public License
24 **  along with this program; if not, write to the Free Software
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 ******************************************************************************/
27
28 #include <complex>
29
30 class ImageFile;
31
32 class Fourier {
33 public:
34     static void shuffleFourierToNaturalOrder (ImageFile& im);
35     static void shuffleNaturalToFourierOrder (ImageFile& im);
36
37 // Odd Number of Points
38 //   Natural Frequency Order: -(n-1)/2...-1,0,1...(n-1)/2
39 //   Fourier Frequency Order: 0, 1..(n-1)/2,-(n-1)/2...-1
40 // Even Number of Points
41 //   Natural Frequency Order: -n/2...-1,0,1...((n/2)-1)
42 //   Fourier Frequency Order: 0,1...((n/2)-1),-n/2...-1
43     template<class T>
44     static void shuffleNaturalToFourierOrder (T* pVector, const int n) 
45     {
46       T* pTemp = new T [n];
47       int i;
48       if (isOdd(n)) { // Odd
49         int iHalfN = (n - 1) / 2;
50
51         pTemp[0] = pVector[iHalfN];
52         for (i = 0; i < iHalfN; i++)
53           pTemp[i + 1] = pVector[i + 1 + iHalfN];
54         for (i = 0; i < iHalfN; i++)
55           pTemp[i + iHalfN + 1] = pVector[i];
56       } else {     // Even
57         int iHalfN = n / 2;
58         pTemp[0] = pVector[iHalfN];
59         for (i = 0; i < iHalfN - 1; i++)
60         pTemp[i + 1] = pVector[i + iHalfN + 1];
61         for (i = 0; i < iHalfN; i++)
62           pTemp[i + iHalfN] = pVector[i];
63       }
64
65     for (i = 0; i < n; i++)
66       pVector[i] = pTemp[i];
67     delete pTemp;
68   }
69
70   template<class T>
71   static void shuffleFourierToNaturalOrder (T* pVector, const int n)
72   {
73     T* pTemp = new T [n];
74     int i;
75     if (isOdd(n)) { // Odd
76       int iHalfN = (n - 1) / 2;
77     
78       pTemp[iHalfN] = pVector[0];
79       for (i = 0; i < iHalfN; i++)
80         pTemp[i + 1 + iHalfN] = pVector[i + 1];
81       for (i = 0; i < iHalfN; i++)
82         pTemp[i] = pVector[i + iHalfN + 1];
83     } else {     // Even
84       int iHalfN = n / 2;
85       pTemp[iHalfN] = pVector[0];
86       for (i = 0; i < iHalfN; i++)
87         pTemp[i] = pVector[i + iHalfN];
88       for (i = 0; i < iHalfN - 1; i++)
89         pTemp[i + iHalfN + 1] = pVector[i+1];
90     }
91   
92     for (i = 0; i < n; i++)
93       pVector[i] = pTemp[i];
94     delete pTemp;
95   }
96 #if 0
97     static void shuffleNaturalToFourierOrder (float* pdVector, const int n);
98     static void shuffleNaturalToFourierOrder (double* pdVector, const int n);
99     static void shuffleNaturalToFourierOrder (std::complex<double>* pdVector, const int n);
100     static void shuffleFourierToNaturalOrder (float* pdVector, const int n);
101     static void shuffleFourierToNaturalOrder (double* pdVector, const int n);
102     static void shuffleFourierToNaturalOrder (std::complex<double>* pdVector, const int n);
103 #endif
104 };
105
106