00001 #include "ibr.h"
00002 #include "../vuSphericFilterFactory.h"
00003 #include "General/vuLightfield/vuSphericViewFilterFactory.h"
00004
00005 template <int SIZE, class TYPE>
00006 vu1611_2<SIZE,TYPE>::vu1611_2()
00007 {
00008 m_Filter = NULL;
00009 m_ViewFilter = NULL;
00010
00011 setFilter(vuSphericFilterFactory<SIZE,TYPE>::getFilter("BestMatch"));
00012 setViewFilter(vuSphericViewFilterFactory<SIZE,TYPE>::getFilter("Lazy"));
00013 }
00014
00015 template <int SIZE, class TYPE>
00016 vu1611_2<SIZE,TYPE>::~vu1611_2()
00017 {
00018 CHECKNDELETE(m_Filter);
00019 CHECKNDELETE(m_ViewFilter);
00020 }
00021
00022 template <int SIZE, class TYPE>
00023 vuSphericFilter<SIZE,TYPE> *vu1611_2<SIZE,TYPE>::getFilter()
00024 {
00025 return m_Filter;
00026 }
00027
00028 template <int SIZE, class TYPE>
00029 void vu1611_2<SIZE,TYPE>::setFilter(vuSphericFilter<SIZE,TYPE> *filter)
00030 {
00031 if (filter == NULL) return;
00032
00033 if (m_Filter != filter) {
00034 CHECKNDELETE(m_Filter);
00035 filter->setVolume(this);
00036 m_Filter = filter;
00037 }
00038 }
00039
00040 template <int SIZE, class TYPE>
00041 void vu1611_2<SIZE,TYPE>::setViewFilter(vuSphericViewFilter<SIZE,TYPE> *filter)
00042 {
00043 if (filter == NULL) return;
00044
00045 if (m_ViewFilter != filter) {
00046 CHECKNDELETE(m_ViewFilter);
00047 m_ViewFilter = filter;
00048 }
00049 }
00050
00051 template <int SIZE, class TYPE>
00052 vuSphericViewFilter<SIZE,TYPE> *vu1611_2<SIZE,TYPE>::getViewFilter()
00053 {
00054 return m_ViewFilter;
00055 }
00056
00057
00058 template <int SIZE, class TYPE>
00059 void vu1611_2<SIZE,TYPE>::preprocess(vuProgressHandler *handler)
00060 {
00061 if (m_ViewFilter == NULL || m_Filter == NULL) return;
00062
00063 if (m_ViewFilter->needPreprocessing()) {
00064 m_Filter->applyFilteredViews(m_ViewFilter);
00065 m_ViewFilter->preprocess(handler);
00066 }
00067 }
00068
00069 template <int SIZE, class TYPE>
00070 void vu1611_2<SIZE,TYPE>::initOpenGL(void)
00071 {
00072 if (m_ViewFilter) m_ViewFilter->initOpenGL();
00073 }
00074
00075 template <int SIZE, class TYPE>
00076 void vu1611_2<SIZE,TYPE>::glResize(dword width, dword height)
00077 {
00078 vu1611<SIZE,TYPE>::glResize(width, height);
00079 if (m_ViewFilter) m_ViewFilter->glResize(width, height);
00080 }
00081
00082 template <int SIZE, class TYPE>
00083 void vu1611_2<SIZE,TYPE>::render()
00084 {
00085 if (m_ViewFilter == NULL) return;
00086
00087 if (m_Filter && m_ViewFilter->needViewsForFiltering())
00088 m_Filter->applyFilteredViews(m_ViewFilter);
00089
00090 m_ViewFilter->filter(m_Camera);
00091 m_ViewFilter->glRender();
00092 }
00093
00094 template <int SIZE, class TYPE>
00095 vuFixelMap<SIZE,TYPE>* vu1611_2<SIZE,TYPE>::computeAndReturnImage()
00096 {
00097 if (m_ViewFilter == NULL) {
00098 cerr << "ibr::getImage(): view filter is not set" << endl;
00099 return NULL;
00100 }
00101
00102 if (m_Filter && m_ViewFilter->needViewsForFiltering())
00103 m_Filter->applyFilteredViews(m_ViewFilter);
00104
00105 m_ViewFilter->filter(m_Camera);
00106
00107 return m_ViewFilter->getMap();
00108 }
00109
00110 template <int SIZE, class TYPE>
00111 bool vu1611_2<SIZE,TYPE>::read(void)
00112 {
00113 if (!vu1611<SIZE,TYPE>::read()) return false;
00114 return true;
00115 }
00116
00117 template <int SIZE, class TYPE>
00118 void vu1611_2<SIZE,TYPE>::preview(int hint)
00119 {
00120 if (m_Camera == NULL) {
00121 cerr << "ibr.preview() no camera set" << endl;
00122 return;
00123 }
00124
00125 vuVector look = m_Camera->getLookAtVector().makeUnit()*-1;
00126
00127 vuMatrix rotX = vuMatrix().makeRotateX(90);
00128 vuVector tmp = rotX * look;
00129 vuSpherical sph = vuSpherical(tmp);
00130 float alpha = (-sph.getLongitude() * 180 / M_PI) + 270;
00131 float beta = -((sph.getLatitude() * 180 / M_PI) - 90);
00132
00133
00134
00135
00136
00137 glMatrixMode(GL_MODELVIEW);
00138 glPushMatrix();
00139 glLoadIdentity();
00140
00141 #if 0
00142 glBegin(GL_LINES);
00143 glColor3ub(255,0,0);
00144 glVertex3f(0.0f,0.0f,0.0f);
00145 glVertex3f(1.0f,0.0f,0.0f);
00146 glColor3ub(0,255,0);
00147 glVertex3f(0.0f,0.0f,0.0f);
00148 glVertex3f(0.0f,1.0f,0.0f);
00149 glColor3ub(0,0,255);
00150 glVertex3f(0.0f,0.0f,0.0f);
00151 glVertex3f(0.0f,0.0f,1.0f);
00152 glColor3ub(255,255,0);
00153 glVertex3f(0.0f,0.0f,0.0f);
00154 glVertex3f(look[0],look[1],look[2]);
00155 glEnd();
00156 #endif
00157
00158
00159 glRotatef(beta, 1.0f, 0.0f, 0.0f);
00160 glRotatef(alpha, 0.0f, 1.0f, 0.0f);
00161
00162
00163
00164 #if 1
00165 glPointSize(5.0);
00166 glColor3ub(255,0,255);
00167 glBegin(GL_POINTS);
00168 glVertex3f(look[0],look[1],look[2]);
00169 glEnd();
00170 #endif
00171
00172 glPointSize(1.0);
00173
00174 glBegin(GL_POINTS);
00175 glColor3ub(255, 255, 255);
00176
00177 for(dword i=0; i<m_numberOfViews; i++) {
00178 vuVector lookFrom = m_views[i].getLookFrom().makeUnit();
00179 if (look.dot(lookFrom) >= 0)
00180 glVertex3f(lookFrom[0], lookFrom[1], lookFrom[2]);
00181 }
00182 glEnd();
00183
00184 if (m_Filter) m_Filter->preview(hint);
00185
00186 glPopMatrix();
00187 }