00001 #ifndef _FVR_vuFourierVolume_H_
00002 #define _FVR_vuFourierVolume_H_
00003
00004 #include <fstream.h>
00005 #include "vuSimpleTypes.h"
00006 #include "vuLinAlg/vuVector.h"
00007 #include "vuFourierFilter/vuFourierFilter.h"
00008 #include <fftw.h>
00009 #include "vuCamera/vuCamera.h"
00010 #include <math.h>
00011 #include "vuLightfield/vuFixelMap.h"
00012 #include "vuMisc/vuProgressHandler.h"
00013
00014 template <int SIZE>
00015 class vuFourierVolume
00016 {
00017 public:
00018
00019
00020 vuFourierVolume<SIZE>();
00021 vuFourierVolume<SIZE>(vuFourierVolume<SIZE>& inst);
00022 ~vuFourierVolume<SIZE>();
00023
00024
00025 vuFourierVolume<SIZE>& operator=(vuFourierVolume<SIZE>& rhs);
00026
00027
00028 void setFilter(vuFourierFilter* filter);
00029 vuFourierFilter *getFilter();
00030
00031 void setCamera(const vuCamera *camera);
00032 void setViewVectors(const vuVector& view,const vuVector& up,const vuVector& right);
00033
00034 static void calcViewVectors(vuVector& lookAt, vuVector& up, vuVector& right);
00035
00036
00037
00038
00039 void clearSlice();
00040 void computeSlice();
00041 void transformSlice();
00042
00043 void computeSlice(dword x_stop, dword y_stop, dword x_pass, dword y_pass);
00044
00045
00046
00047
00048 dword getImageWidth() const;
00049 dword getImageHeight() const;
00050
00051 dword getSliceWidth() const;
00052 dword getSliceHeight() const;
00053
00054 dword getXSize();
00055 dword getYSize();
00056 dword getZSize();
00057
00058 float *getSliceData() const;
00059
00060
00061 void setOversampling(float s);
00062
00063 dword computeDimensions(dword XSize, dword YSize, dword ZSize,
00064 float mult_pad, dword add_pad);
00065
00066
00067
00068 void setWrap(dword wrap);
00069 dword getWrap();
00070
00071
00072 void interpolateSlice();
00073 void interpolateSlice(dword x_stop, dword y_stop, dword x_pass, dword y_pass);
00074
00075 bool isInitialized();
00076
00079 bool writeSpatialVolume(const char *fileName,
00080 vuProgressHandler *handler=NULL) const;
00081
00082
00083
00084 void setRenderMethod(dword renderMethod);
00085 dword getRenderMethod();
00086
00087 void setScale(float scale);
00088 float getScale();
00089 void fitScale();
00090
00091 void setBias(float bias);
00092 float getBias();
00093 void fitBias();
00094
00095 bool getIsChannelActive(dword idx);
00096 void setIsChannelActive(dword idx, bool flag);
00097
00098 void setIsReRendering(bool flag);
00099 bool getIsReRendering();
00100
00101 vuFixelMap<SIZE,float> *getUnscaledImage();
00102 void computeUnscaledImage(bool doSlicing=true);
00103 void glResize(dword width, dword height);
00104 void render();
00105
00106 protected:
00107
00108
00109 void wrapVolume(float *volume);
00110
00111
00112 void wrapAndInitialize(float overSampling);
00113
00114 inline int vcoord(int x, int y, int z) const
00115 {
00116 return ((z * m_YSize + y) * m_XSize + x) * 2 * SIZE;
00117 }
00118
00119 inline int scoord(int x, int y) const
00120 {
00121 return (y * m_SliceXSize + x) * 2 * SIZE;
00122 }
00123
00124 protected:
00125
00126 float* m_Volume;
00127 dword m_XSize;
00128 dword m_YSize;
00129 dword m_ZSize;
00130 dword m_Wrap;
00131
00132
00133 vuFourierFilter* m_Filter;
00134
00135
00136 float* m_Slice;
00137
00138 vuVector m_XStep;
00139 vuVector m_YStep;
00140 dword m_SliceXSize;
00141 dword m_SliceYSize;
00142 vuVector m_XAxis;
00143 vuVector m_YAxis;
00144 vuVector m_ZAxis;
00145 vuVector m_Origin;
00146
00147
00148 dword m_ImageXSize;
00149 dword m_ImageYSize;
00150 dword m_ImageStep;
00151 float* m_SlicePtr;
00152
00153 dword m_InnerXSize;
00154 dword m_InnerYSize;
00155
00156 fftwnd_plan m_Plan2D;
00157
00158
00159 dword m_RenderMethod;
00160 float m_Scale;
00161 float m_Bias;
00162 bool m_Channels[SIZE];
00163 bool m_IsReRendering;
00164 vuFixelMap<SIZE,float> *m_UnscaledImage;
00165
00166 protected:
00167 void loadWisdom();
00168 void saveWisdom();
00169 void transform2D(float* x);
00170 void destroyTransform2D();
00171 public:
00172 static void shift2D(float* x, dword XSize, dword YSize);
00173 static void shiftCopy2D(float* dest, float* src, dword XSize, dword YSize);
00174
00175 public:
00176
00177
00178
00179
00180
00181
00182 void computeUnscaledImage(vuFixelMap<SIZE,float>* &image, word method, bool doSlicing=true);
00183 void computeUnscaledImage(vuFixelMap<SIZE,float>* &image, float &minVal,
00184 float &maxVal, word method, bool doSlicing=true);
00185 protected:
00186 void _copyImageAndFindMinMax(vuFixelMap<SIZE,float> *image,
00187 float *slice,
00188 float &minVal,
00189 float &maxVal,
00190 word method);
00191
00192 #if 1
00193 public:
00194
00195
00196
00200 bool readFourierFromFile(const char *fileName, dword wrap=4, float s=1.0);
00201
00204 bool writeFourierToFile(const char *fileName,
00205 vuProgressHandler *handler=NULL) const;
00206
00207 void write_fvr(char* out) const;
00208 bool read_fvr(ifstream& fin, dword XSize, dword YSize, dword ZSize, dword d_size);
00209
00210 #endif
00211
00212 };
00213
00214 template class vuFourierVolume<1>;
00215 template class vuFourierVolume<2>;
00216 template class vuFourierVolume<3>;
00217
00218 typedef vuFourierVolume<1> vuFourierVolume1;
00219 typedef vuFourierVolume<2> vuFourierVolume2;
00220 typedef vuFourierVolume<3> vuFourierVolume3;
00221
00222 #endif
00223
00224
00225
00226 #if 0
00229 bool readSpatialVolume(byte *data, dword XSize, dword YSize, dword ZSize,
00230 float s=1.0, float mult_pad=M_SQRT2, dword add_pad=0);
00231
00232 void preprocess();
00233 static void transform3D(float* x, dword xx, dword yy, dword zz);
00234 static void shift3D(float* x, dword XSize, dword YSize, dword ZSize);
00235
00236 #endif