HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_VoxelFFT.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_VoxelFFT.h ( UT Library, C++)
7  *
8  * COMMENTS: Functions for performing 2D and 3D FFTs on voxel arrays.
9  */
10 
11 #ifndef __UT_VOXELFFT_H
12 #define __UT_VOXELFFT_H
13 
14 #include "UT_API.h"
15 
16 #include "UT_ValArray.h"
17 #include "UT_VoxelArray.h"
18 #include "UT_Complex.h"
19 
20 
22 {
23 public:
24 
26 
27  virtual ~UT_VoxelFFT();
28 
29  /// Perform a forward or inverse FFT on the pair of 2D or 3D voxel arrays
30  /// representing real and imaginary parts of the complex input and output.
31  /// If invert is true, this function computes an inverse FFT.
32  /// Shift assumes the frequency-space data is shifted on input or output
33  /// so that the DC (zero-th) frequency is in the center, similar to
34  /// Matlab's fftshift and ifftshift functions.
35  /// Normalize applies a 1/N normalization factor to the inverse FFT so that
36  /// a forward FFT followed by inverse FFT yields the original input.
37  /// If sliceaxis is 0, 1, or 2, a 3D input array will be treated as a series
38  /// of 2D FFTs sliced along the specified axis.
39  /// NOTE: as with most FFTs, performance is best with input arrays whose
40  /// dimensions are powers of 2.
41  void fft(UT_VoxelArrayF &re, UT_VoxelArrayF &im,
42  bool invert, bool shift, bool normalize,
43  int sliceaxis = -1, bool realdata = false);
44 
45  /// Performs forward or inverse FFT's on several pairs of 2D or 3D voxel
46  /// arrays representing real and imaginary parts of the complex input and
47  /// output. All sequential complex pairs with the same resolution are
48  /// transformed at once, which can yield signicant speedups.
49  /// If invert is true, this function computes an inverse FFT.
50  /// Shift assumes the frequency-space data is shifted on input or output
51  /// so that the DC (zero-th) frequency is in the center, similar to
52  /// Matlab's fftshift and ifftshift functions.
53  /// Normalize applies a 1/N normalization factor to the inverse FFT so that
54  /// a forward FFT followed by inverse FFT yields the original input.
55  /// If sliceaxis is 0, 1, or 2, a 3D input array will be treated as a series
56  /// of 2D FFTs sliced along the specified axis.
57  /// NOTE: as with most FFTs, performance is best with input arrays whose
58  /// dimensions are powers of 2.
59  void fft(const UT_ValArray<UT_VoxelArrayF *> &re,
61  bool invert, bool shift, bool normalize,
62  int sliceaxis = -1, bool realdata = false);
63 
64 
65  // FFT interface
66  class ut_fft
67  {
68  protected:
69  int myRank;
70  int myDims[3];
71  bool myInvert;
74  bool myRealData;
75  public:
76  ut_fft(int rank, int *dims, bool invert, int ntransforms,
77  bool realdata)
78  {
79  myEntries = 1;
80  myRank = rank;
81  for (int i = 0; i < myRank; i++)
82  {
83  myEntries *= dims[i];
84  myDims[i] = dims[i];
85  }
86  myNTransforms = ntransforms;
87  myInvert = invert;
88  myRealData = realdata;
89  }
90 
91  virtual ~ut_fft() {}
92 
93  // Common fft functions.
94 
95  virtual bool supportsHermitianComplex() const { return false; }
96 
97  virtual void allocBuffers() = 0;
98 
99  virtual void *mapInBuffer() = 0;
100 
101  virtual void *mapOutBuffer() = 0;
102 
103  virtual void unmapInBuffer(void *) = 0;
104 
105  virtual void unmapOutBuffer(void *) = 0;
106 
107  virtual void releaseBuffers() = 0;
108 
109  virtual exint entries() const { return myEntries; }
110 
111  virtual bool isMatching(int rank, int *dims, bool invert, int ntransforms,
112  bool realdata)
113  {
114  if (rank != myRank || invert != myInvert ||
115  ntransforms != myNTransforms || realdata != myRealData)
116  return false;
117  for (int i = 0; i < myRank; i++)
118  if (dims[i] != myDims[i])
119  return false;
120  return true;
121  }
122 
123  // Returns distance in input buffer between transforms.
124  virtual size_t getInputDistance() const { return entries(); }
125 
126  // Returns distance in output buffer between transforms.
127  virtual size_t getOutputDistance() const { return entries(); }
128 
129  virtual bool fft() = 0;
130  };
131 
132 protected:
133  void computeFFTDims(const UT_VoxelArrayF &re,
134  int &sliceaxis, int &ndims, int *dims,
135  int &slicetransforms, UT_Vector3I &axes);
136 
137  // Override point where we can control which descendant of ut_fft we'll
138  // create to actually compute the fft. (see CE_VoxelArrayFFT)
139  virtual void fftSequence(const UT_ValArray<UT_VoxelArrayF *> &realvox,
140  const UT_ValArray<UT_VoxelArrayF *> &imagvox,
141  int begin, int end,
142  bool invert, bool shift,
143  bool normalize, int sliceaxis, bool realdata);
144 
145  void fftSequence(ut_fft &fft,
146  const UT_ValArray<UT_VoxelArrayF *> &realvox,
147  const UT_ValArray<UT_VoxelArrayF *> &imagvox,
148  int begin, int end,
149  bool invert, bool shift,
150  bool normalize, int sliceaxis,
151  bool realdata);
152 
153  THREADED_METHOD8(UT_VoxelFFT, resrc.numTiles() > 16,
154  copyToComplex,
155  const UT_VoxelArrayF &, resrc,
156  const UT_VoxelArrayF &, imsrc,
157  UT_ComplexF *, dst,
158  const UT_Vector3I &, axes,
159  bool, shift,
160  bool, sliced,
161  bool, realonly,
162  bool, hermitian);
163  void copyToComplexPartial(const UT_VoxelArrayF &resrc,
164  const UT_VoxelArrayF &imsrc,
165  UT_ComplexF *dst,
166  const UT_Vector3I &axes,
167  bool shift,
168  bool sliced,
169  bool realonly,
170  bool hermitian,
171  const UT_JobInfo &info);
172 
173  THREADED_METHOD9(UT_VoxelFFT, redst.numTiles() > 16,
174  copyFromComplex,
175  const UT_ComplexF *, src,
176  UT_VoxelArrayF &, redst,
177  UT_VoxelArrayF &, imdst,
178  fpreal32, scale,
179  const UT_Vector3I &, axes,
180  bool, shift,
181  bool, sliced,
182  bool, realonly,
183  bool, hermitian);
184  void copyFromComplexPartial(const UT_ComplexF *src,
185  UT_VoxelArrayF &redst,
186  UT_VoxelArrayF &imdst,
187  fpreal32 scale,
188  const UT_Vector3I &axes,
189  bool shift,
190  bool sliced,
191  bool realonly,
192  bool hermitian,
193  const UT_JobInfo &info);
194 
195  THREADED_METHOD4(UT_VoxelFFT, redst.numTiles() > 16,
196  copyFromReal,
197  const fpreal32 *, src,
198  UT_VoxelArrayF &, redst,
199  fpreal32, scale,
200  const UT_Vector3I &, axes);
201  void copyFromRealPartial(const fpreal32 *src,
202  UT_VoxelArrayF &redst,
203  fpreal32 scale,
204  const UT_Vector3I &axes,
205  const UT_JobInfo &info);
206 
207  THREADED_METHOD4(UT_VoxelFFT, resrc.numTiles() > 16,
208  copyToReal,
209  const UT_VoxelArrayF &, resrc,
210  fpreal32 *, dst,
211  fpreal32, scale,
212  const UT_Vector3I &, axes);
213  void copyToRealPartial(const UT_VoxelArrayF& resrc,
214  fpreal32* dst,
215  fpreal32 scale,
216  const UT_Vector3I &axes,
217  const UT_JobInfo& info);
218 };
219 
220 #endif
#define THREADED_METHOD8(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4, PARMTYPE5, PARMNAME5, PARMTYPE6, PARMNAME6, PARMTYPE7, PARMNAME7, PARMTYPE8, PARMNAME8)
GLboolean invert
Definition: glcorearb.h:548
virtual exint entries() const
Definition: UT_VoxelFFT.h:109
#define UT_API
Definition: UT_API.h:13
png_uint_32 i
Definition: png.h:2877
virtual size_t getInputDistance() const
Definition: UT_VoxelFFT.h:124
GA_API const UT_StringHolder scale
int64 exint
Definition: SYS_Types.h:116
GLuint GLuint end
Definition: glcorearb.h:474
virtual bool isMatching(int rank, int *dims, bool invert, int ntransforms, bool realdata)
Definition: UT_VoxelFFT.h:111
virtual bool supportsHermitianComplex() const
Definition: UT_VoxelFFT.h:95
#define THREADED_METHOD4(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4)
GridType::Ptr normalize(const GridType &grid, bool threaded, InterruptT *interrupt)
Normalize the vectors of the given vector-valued grid.
GLenum GLenum dst
Definition: glcorearb.h:1792
png_infop png_sPLT_tpp entries
Definition: png.h:2481
size_t *lastDimSize unsigned int rank
Definition: wrapArray.h:326
virtual size_t getOutputDistance() const
Definition: UT_VoxelFFT.h:127
#define THREADED_METHOD9(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4, PARMTYPE5, PARMNAME5, PARMTYPE6, PARMNAME6, PARMTYPE7, PARMNAME7, PARMTYPE8, PARMNAME8, PARMTYPE9, PARMNAME9)
ut_fft(int rank, int *dims, bool invert, int ntransforms, bool realdata)
Definition: UT_VoxelFFT.h:76
float fpreal32
Definition: SYS_Types.h:191
GLenum src
Definition: glcorearb.h:1792