Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

vuFourierVolume.h

Go to the documentation of this file.
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   // Default constructor, copy constructor,
00019   // and destructor.
00020   vuFourierVolume<SIZE>();
00021   vuFourierVolume<SIZE>(vuFourierVolume<SIZE>& inst);
00022   ~vuFourierVolume<SIZE>();
00023 
00024   // Assignment operator for the volume class.
00025   vuFourierVolume<SIZE>& operator=(vuFourierVolume<SIZE>& rhs);
00026 
00027   // Set the interpolation filter.
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   // Compute the slice for the current angle and
00037   // return the rgb's in a byte*.
00038   // Stop is middle section, pass is bandwidth
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   // Get the dimensions of the current image (for
00046   // the current version, the same values are returned
00047   // for all angles.)
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   // set oversampling -- 2 uses twice the number of samples
00061   void setOversampling(float s);
00062 
00063   dword computeDimensions(dword XSize, dword YSize, dword ZSize,
00064                           float mult_pad, dword add_pad);
00065 
00066   // Set the width of the wrap in the frequency
00067   // domain.  Should be half the filter size.
00068   void setWrap(dword wrap);
00069   dword getWrap();
00070 
00071   // Interpolate the slice, using the currently selected filter.
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   // --- rendering ---------------------------------------------------------
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   // Fix the frequency volume so that it wraps its
00108   // values periodically to half of the filter width.
00109   void wrapVolume(float *volume);
00110 
00111   // call wrapVolume() and set oversampling
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   // Variables for the volume.
00126   float* m_Volume;       // Volume frequency data
00127   dword  m_XSize;        // Width of volume (and slice)
00128   dword  m_YSize;        // Height of volume (and slice)
00129   dword  m_ZSize;        // Depth of volume
00130   dword  m_Wrap;         // Width of the wrap on the volume
00131 
00132   // Variables for the interpolation filter
00133   vuFourierFilter* m_Filter;
00134 
00135   // Variables for the slice
00136   float*   m_Slice;        // Slice frequency data
00137 
00138   vuVector m_XStep;        // Xstep for sampling
00139   vuVector m_YStep;        // Ystep for sampling
00140   dword    m_SliceXSize;   // Slice x-size
00141   dword    m_SliceYSize;   // Slice y-size
00142   vuVector m_XAxis;        // Slice x-axis
00143   vuVector m_YAxis;        // Slice y-axis
00144   vuVector m_ZAxis;        // Slice z-axis
00145   vuVector m_Origin;       // Bottom left corner of slice
00146 
00147   // image vars
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   // --- rendering --------------------------------------------------------
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   /* method: 0 ... spatial image
00177              1 ... frequency amplitude
00178              2 ... frequency phase
00179              3 ... frequency real part
00180              4 ... frequency imaginary part
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   // Read the volume
00195   // bool read(char* in, float s = 1.0, float m_pad = 1.0f, dword a_pad = 0);
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

Generated on Wed Dec 15 21:20:34 2004 for vuVolume by  doxygen 1.3.9.1