00001 #include "vuSphericLightfieldFourier.h"
00002 #include "../vuFixelType.h"
00003
00004 template <int SI, class TI, int SO, class TO>
00005 vuSphericLightfieldFourier<SI,TI,SO,TO>::vuSphericLightfieldFourier()
00006 {
00007 m_PlanExists = false;
00008 }
00009
00010 template <int SI, class TI, int SO, class TO>
00011 vuSphericLightfieldFourier<SI,TI,SO,TO>::~vuSphericLightfieldFourier()
00012 {
00013 if (m_PlanExists) {
00014 fftwnd_destroy_plan(m_Plan);
00015 fftwnd_destroy_plan(m_PlanForward);
00016 m_PlanExists = false;
00017 }
00018 }
00019
00020 template <int SI, class TI, int SO, class TO>
00021 void vuSphericLightfieldFourier<SI,TI,SO,TO>::_ensurePlan(dword width,
00022 dword height)
00023 {
00024 if (!m_PlanExists) {
00025
00026 m_Plan = fftw2d_create_plan(height, width, FFTW_BACKWARD, FFTW_MEASURE
00027 | FFTW_IN_PLACE);
00028
00029 m_PlanForward = fftw2d_create_plan(height, width, FFTW_FORWARD,
00030 FFTW_MEASURE | FFTW_IN_PLACE);
00031 m_PlanExists = true;
00032
00033 }
00034 }
00035
00036 template <int SI, class TI, int SO, class TO>
00037 void vuSphericLightfieldFourier<SI,TI,SO,TO>::_convert(vuSphericView<SI,TI>*in,
00038 vuSphericView<SO,TO>*out)
00039 {
00040 if (!_areViewsValid(in, out)) return;
00041
00042 dword width = in->getWidth();
00043 dword height = in->getHeight();
00044
00045 _ensurePlan(width, height);
00046
00047 if ((SI == 1) && (SO == 2)) {
00048 const TI *src = in->getMap()->getBuffer();
00049 TO *dest = out->getMap()->getBuffer();
00050
00051 for (dword j=0; j<height; j++) {
00052 for (dword i=0; i<width; i++) {
00053 *dest = vuFixelTypeConverter<TI,TO>::getValue(*src);
00054 dest++;
00055 *dest = (TO)0;
00056 dest++; src++;
00057 }
00058 }
00059
00060 fftwnd_one(m_PlanForward, (fftw_complex*)out->getMap()->getBuffer(), NULL);
00061 fftwnd_one(m_Plan, (fftw_complex*)out->getMap()->getBuffer(), NULL);
00062
00063 vuFixelMap<SO,TO> *map = out->getMap();
00064
00065 *map *= ((float)1/(float)(width*height));
00066 }
00067 else if ((SI == 2) && (SO == 2)) {
00068 const TI *src = in->getMap()->getBuffer();
00069 TO *dest = out->getMap()->getBuffer();
00070
00071 for (dword j=0; j<height; j++) {
00072 for (dword i=0; i<width; i++) {
00073 *(dest++) = vuFixelTypeConverter<TI,TO>::getValue(*(src++));
00074 *(dest++) = vuFixelTypeConverter<TI,TO>::getValue(*(src++));
00075 }
00076 }
00077 fftwnd_one(m_Plan, (fftw_complex*)out->getMap()->getBuffer(), NULL);
00078 }
00079
00080 }
00081
00082 vuBasicLightfieldConverter*
00083 vuSphericLightfieldFourierFactory::getConverter(vuString &name)
00084 {
00085 if (name == "1F1F")
00086 return new vuSphLFFourier1F1F();
00087 else if (name == "1F2F")
00088 return new vuSphLFFourier1F2F();
00089
00090
00091
00092
00093 else if (name == "2F2F")
00094 return new vuSphLFFourier2F2F();
00095
00096
00097
00098
00099
00100
00101
00102
00103 else if (name == "1B2F")
00104 return new vuSphLFFourier1B2F();
00105 else
00106 return NULL;
00107 }