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

vuFourierClusterN.cpp

Go to the documentation of this file.
00001 #include "vuFourierClusterN.h"
00002 
00003 template <int S, class T>
00004 bool vuFourierClusterN<S,T>::isPreprocessed()
00005 {
00006   return m_Volume[0].isPreprocessed();
00007 }
00008 
00009 template <int S, class T>
00010 bool vuFourierClusterN<S,T>::isPreparedForInteractive()
00011 {
00012   return m_Volume[0].isPreparedForInteractive();
00013 }
00014 
00015 template <int S, class T>
00016 void vuFourierClusterN<S,T>::setNoInteractiveMode()
00017 {
00018   for (int i=0; i<S; i++) m_Volume[i].setNoInteractiveMode();
00019 }
00020 
00021 template <int S, class T>
00022 void vuFourierClusterN<S,T>::prepareForInteractive(dword width, dword height)
00023 {
00024   for (int i=0; i<S; i++) m_Volume[i].prepareForInteractive(width, height);
00025 }
00026 
00027 template <int S, class T>
00028 void vuFourierClusterN<S,T>::setSliceFilter(vuSliceFilter *sliceFilter)
00029 {
00030   for (int i=0; i<S; i++) m_Volume[i].setSliceFilter(sliceFilter);
00031 }
00032 
00033 template <int S, class T>
00034 vuSliceFilter *vuFourierClusterN<S,T>::getSliceFilter()
00035 {
00036   return m_Volume[0].getSliceFilter();
00037 }
00038 
00039 template <int S, class T>
00040 dword vuFourierClusterN<S,T>::getImageWidth()
00041 {
00042   return m_Volume[0].getImageWidth();
00043 }
00044 
00045 template <int S, class T>
00046 dword vuFourierClusterN<S,T>::getImageHeight()
00047 {
00048   return m_Volume[0].getImageHeight();
00049 }
00050 
00051 
00052 template <int S, class T>
00053 void vuFourierClusterN<S,T>::setFilter(vuFourierFilter* filter)
00054 {
00055   for (int i=0; i<S; i++) m_Volume[i].setFilter(filter);
00056 }
00057 
00058 template <int S, class T>
00059 bool vuFourierClusterN<S,T>::writeFourierToFile(const char *fileName,
00060                                                 vuProgressHandler *handler)
00061 {
00062   bool result = true;
00063   vuString myFileName;
00064 
00065   if (S == 1) {
00066     myFileName = fileName;
00067     if (!myFileName.hasSuffix(".fvr")) myFileName += ".fvr";
00068     result = m_Volume[0].writeFourierToFile(myFileName, handler);
00069   }
00070   else {
00071     int oldRange = 0;
00072 
00073     if (handler) {
00074       oldRange = handler->getRange();
00075       handler->setRange(oldRange/S);
00076     }
00077 
00078     for (int i=0; i<S; i++) {
00079       myFileName = fileName;
00080       if (myFileName.hasSuffix(".fvr")) {
00081         myFileName = myFileName.substr(0, myFileName.getLength()-5);
00082       }
00083       myFileName += "_";
00084       myFileName += i;
00085       myFileName += ".fvr";
00086 
00087       result = result && m_Volume[i].writeFourierToFile(myFileName, handler);
00088       if (result == false) break;
00089     }
00090     if (handler) handler->setRange(oldRange);
00091   }
00092   return result;
00093 }
00094 
00095 template <int S, class T>
00096 bool vuFourierClusterN<S,T>::writeSpatialVolume(const char *fileName,
00097                                                 vuProgressHandler *handler)
00098 {
00099   bool result = true;
00100   vuString myFileName;
00101 
00102   if (S == 1) {
00103     myFileName = fileName;
00104     if (!myFileName.hasSuffix(".vud")) myFileName += ".vud";
00105     result = m_Volume[0].writeSpatialVolume(myFileName, handler);
00106   }
00107   else {
00108     for (int i=0; i<S; i++) {
00109       myFileName = fileName;
00110       if (myFileName.hasSuffix(".vud")) {
00111         myFileName = myFileName.substr(0, myFileName.getLength()-5);
00112       }
00113       myFileName += "_";
00114       myFileName += i;
00115       myFileName += ".vud";
00116 
00117       result = result && m_Volume[i].writeSpatialVolume(myFileName, handler);
00118     }
00119   }
00120   return result;
00121 }
00122 
00123 
00124 template <int S, class T>
00125 void vuFourierClusterN<S,T>::setCamera(vuCamera *camera)
00126 {
00127   for (int i=0; i<S; i++) m_Volume[i].setCamera(camera);
00128 }
00129 
00130 template <int S, class T>
00131 void vuFourierClusterN<S,T>::computeSlice()
00132 {
00133   for (int i=0; i<S; i++) m_Volume[i].computeSlice();
00134 }
00135 
00136 template <int S, class T>
00137 void vuFourierClusterN<S,T>::scaleAndBias(T* data)
00138 {
00139   for (int i=0; i<S; i++) m_Volume[i].scaleAndBias(data);
00140 }
00141 
00142 template <int S, class T>
00143 void vuFourierClusterN<S,T>::computeUnscaledImage(vuCamera *camera,
00144                                                   vuFixelMap<S,float>* &image,
00145                                                   float &minVal, float &maxVal,
00146                                                   word method)
00147 {
00148   vuFixelMap<1,float> *map = NULL;
00149 
00150   for (int i=0; i<S; i++) {
00151     if (m_Volume[i].isPreprocessed()) {
00152       if (S == 1) map = (vuFixelMap<1,float>*)image;
00153 
00154       m_Volume[i].setCamera(camera);
00155       m_Volume[i].computeUnscaledImage(map, minVal, maxVal, method);
00156 
00157       if (S > 1) {
00158         if (image == NULL)
00159           image = new vuFixelMap<S,float>(map->getWidth(), map->getHeight());
00160         if (!image->hasSameDimensions(map)) {
00161           CHECKNDELETE(image);
00162           image = new vuFixelMap<S,float>(map->getWidth(), map->getHeight());
00163         }
00164         image->copyMapToChannel(map, i);
00165         CHECKNDELETE(map);
00166       }
00167     }
00168     else {
00169       // return black image
00170       if (image == NULL) image = new vuFixelMap<S,float>(16,16);
00171       image->clear(vuFixel<S,float>(0.0f));
00172       return;
00173     }
00174   }
00175 
00176   if (S == 1) image = (vuFixelMap<S,float>*)map;
00177 }
00178 
00179 template <int S, class T>
00180 void vuFourierClusterN<S,T>::addView(vuSphericView<1,T> *view)
00181 {
00182   // ToDo: ???
00183 }
00184 
00185 template <int S, class T>
00186 void vuFourierClusterN<S,T>::preprocess(dword numOfViews, 
00187                                         vuSphericView<S,T> **views,
00188                                         vuProgressHandler *handler)
00189 {
00190   if (numOfViews == 0) return;
00191 
00192   if (handler == NULL) return _preprocess(numOfViews, views);
00193 
00194   dword range     = handler->getRange();
00195   dword constFact = 10;
00196   float delta     = (float)range / (float)(S*(numOfViews+2*constFact));
00197 
00198   dword width  = views[0]->getWidth();
00199   dword height = views[0]->getHeight();
00200 
00201   if (m_Volume[0].getSliceFilter() != NULL) {
00202     vuSphericView<1,T> *view = NULL;
00203     vuFixelMap<1,T>    *map  = NULL;
00204     bool               isInterupted = false;
00205     float              progress     = 0.0f;
00206 
00207     for (int j=0; j<S; j++) {
00208       vuString prefix = "";
00209       vuString msg    = "Initialize Volume";
00210 
00211       if (S > 1) {
00212         switch (j) {
00213           case 0: prefix += "Red: ";   break;
00214           case 1: prefix += "Green: "; break;
00215           case 2: prefix += "Blue: ";  break;
00216         }
00217       }
00218       msg = prefix + msg;
00219 
00220       progress = delta * (numOfViews+2*constFact) * j;
00221       handler->update((int)progress, (const char*)msg.c_str());
00222       m_Volume[j].initializeVolume(width, height);
00223       progress+= delta*constFact;
00224 
00225       if (!isInterupted) {
00226         for (dword i=0; i<numOfViews; i++) {
00227           if (S == 1)
00228             view = (vuSphericView<1,T> *)views[i];
00229           else {
00230             views[i]->getMap()->getChannel(map, j);
00231             view = new vuSphericView<1,T>(map, views[i]->getLookFrom(),
00232                                           views[i]->getUp());
00233           }
00234           msg  = "add view ";
00235           msg += i;
00236           msg = prefix + msg;
00237 
00238           progress += delta;
00239           if (!handler->update((int)progress, msg.c_str())) {
00240             isInterupted = true;
00241             break;
00242           }
00243           m_Volume[j].addViewToVolume(view);
00244         }
00245       }
00246       msg = "Normalize Volume";
00247       msg = prefix + msg;
00248       progress+= delta*constFact;
00249       handler->update((int)progress, msg.c_str());
00250       m_Volume[j].normalizeVolume();
00251       m_Volume[j].wrapAndInitialize(1.0);
00252       m_Volume[j].m_IsPreprocessed           = true;
00253       m_Volume[j].m_IsPreparedForInteractive = false;
00254     }
00255     if (S > 1) {
00256       CHECKNDELETE(view);
00257       CHECKNDELETE(map);
00258     }
00259   }
00260   else {    
00261     cerr << "vuFourierClusterN::preprocess(): sliceFilter is not set!" << endl;
00262   }
00263 }
00264 
00265 template <int S, class T>
00266 void vuFourierClusterN<S,T>::_preprocess(dword num, vuSphericView<S,T> **views)
00267 {
00268   if (num == 0) return;
00269 
00270   dword width  = views[0]->getWidth();
00271   dword height = views[0]->getHeight();
00272 
00273   for (int i=0; i<S; i++) m_Volume[i].initializeVolume(width, height);
00274 
00275   if (m_Volume[0].getSliceFilter() != NULL) {
00276     for (dword i=0; i<num; i++) {
00277       cerr << "add slice " << i << ": ";
00278       for (int j=0; j<S; j++) {
00279         vuSphericView<1,T> *view = NULL;
00280         vuFixelMap<1,T>    *map  = NULL;
00281 
00282         if (S == 1)
00283           view = (vuSphericView<1,T> *)views[i];
00284         else {
00285           cerr << "+";
00286           views[i]->getMap()->getChannel(map, j);
00287           view = new vuSphericView<1,T>(map, views[i]->getLookFrom(),
00288                                         views[i]->getUp());
00289         }
00290         m_Volume[j].addViewToVolume(view);
00291 
00292         if (S > 1) {
00293           CHECKNDELETE(view);
00294           CHECKNDELETE(map);
00295         }
00296       }
00297       cerr << " done." << endl;
00298     }
00299     for (int i=0; i<S; i++) m_Volume[i].normalizeVolume();
00300   }
00301   else {    
00302     cerr << "vuFourierClusterN::preprocess(): sliceFilter is not set!" << endl;
00303   }
00304 
00305   for (int i=0; i<S; i++) {
00306     m_Volume[i].wrapAndInitialize(1.0);
00307     m_Volume[i].m_IsPreprocessed           = true;
00308     m_Volume[i].m_IsPreparedForInteractive = false;
00309   }
00310 }

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