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

vuSphericFilter.cpp

Go to the documentation of this file.
00001 #include "vuSphericFilter.h"
00002 #include "General/vuCamera/vuCamera.h"
00003 
00004 vuSphericFilter_ST::vuSphericFilter_ST() 
00005 {
00006 }
00007 
00008 vuSphericFilter_ST::vuSphericFilter_ST(const vuString& filterName) 
00009   : vuFilter(filterName)
00010 {
00011 }
00012 
00013 vuSphericFilter_ST::~vuSphericFilter_ST()
00014 {
00015 }
00016 
00017 void vuSphericFilter_ST::preview(int hint)
00018 {
00019 }
00020 
00021 // -------------------------------------------------------------------------
00022 
00023 template <int S, class T>
00024 vuSphericFilter<S,T>::vuSphericFilter()
00025 {
00026   m_volume    = NULL;
00027 }
00028 
00029 template <int S, class T>
00030 vuSphericFilter<S,T>::vuSphericFilter(const vuString &filterName)
00031   : vuSphericFilter_ST(filterName)
00032 {
00033   m_volume     = NULL;
00034 }
00035 
00036 template <int S, class T>
00037 vuSphericFilter<S,T>::vuSphericFilter(const vuSphericFilter<S,T> &other)
00038 { 
00039   if (*this != other) {
00040     m_volume     = other.m_volume;
00041   }
00042 }
00043 
00044 template <int S, class T>
00045 vuSphericFilter<S,T>::~vuSphericFilter()
00046 {
00047 }
00048 
00049 template <int S, class T>
00050 void vuSphericFilter<S,T>::setVolume(vu1611<S,T> *volume)
00051 {
00052   m_volume = volume;
00053 }
00054 
00055 template <int S, class T>
00056 vu1611<S,T> *vuSphericFilter<S,T>::getVolume()
00057 {
00058   return m_volume;
00059 }
00060 
00061 template <int S, class T>
00062 void vuSphericFilter<S,T>::log(const char *msg)
00063 {
00064   cerr << msg << endl;
00065 }
00066 
00067 template <int S, class T> void vuSphericFilter<S,T>::
00068 applyFilteredViews(vuSphericViewFilter<S,T> *viewFilter)
00069 {
00070   dword              count   = 0;
00071   vuSphericView<S,T> **views = NULL;
00072   
00073   calcFilteredViews(views, count);
00074   viewFilter->setNumberOfViews(count);
00075 
00076   for (dword i=0; i<count; i++) {
00077     viewFilter->setView(i, views[i]);
00078   }
00079   CHECKNDELETE(views);
00080 }
00081 
00082 template <int S, class T>
00083 bool vuSphericFilter<S,T>::getNearestViews(dword* &idxList, dword &count)
00084 {
00085   if (!m_volume) {
00086     log("vuSphFlt.getNearestView(): no volume set!");
00087     return false;
00088   }
00089 
00090   vuCamera *camera = m_volume->getCameraPtr();
00091 
00092   if (!camera) {
00093     log("vuSphFlt.getNearestView(): no camera set!");
00094     return false;
00095   }
00096 
00097   vuVector lookFrom = camera->getLookAtVector().makeUnit() * -1;
00098 
00099   return vuSphericFilter<S,T>::getNearestViews(idxList, count, lookFrom,
00100                                                m_volume->getNumberOfViews(),
00101                                                m_volume->getViews());
00102 }
00103 
00104 template <int S, class T>
00105 bool vuSphericFilter<S,T>::getNearestViews(dword* &idxList, dword &count,
00106                                            vuVector lookFrom)
00107 {
00108   if (!m_volume) {
00109     log("vuSphFlt.getNearestView(): no volume set!");
00110     return false;
00111   }
00112   return vuSphericFilter<S,T>::getNearestViews(idxList, count, lookFrom,
00113                                                m_volume->getNumberOfViews(),
00114                                                m_volume->getViews());
00115 }
00116 
00117 template <int S, class T> bool vuSphericFilter<S,T>::
00118 getNearestViews(dword* &idxList, dword &count, vuVector lookFrom,
00119                 dword numOfViews, vuSphericView<S,T>* &views)
00120 {
00121   if (count == 0) { // count=> how many views have to be calculated?
00122     cerr << "vuSphFlt.getNearestView(): count is 0!" << endl;
00123     return false;
00124   }
00125   if (idxList != NULL) {
00126     cerr << "vuSphFlt.getNearestView():idxList is not initalized" << endl;
00127     return false;
00128   }
00129   if (numOfViews == 0) {
00130     cerr << "vuSphFlt.getNearestView(): numOfViews is 0!" << endl;
00131     return false;
00132   }
00133   
00134   dword    i;
00135   float    *dots = NULL; // holds the last computed dot products
00136 
00137   if (count > numOfViews) count = numOfViews; 
00138 
00139   idxList = new dword[count];
00140   dots    = new float[count];
00141 
00142   for (i=0; i<count; i++) {
00143     idxList[i] = 0;
00144     dots[i]    = -1.0f;
00145   }
00146 
00147   for(i=0; i<numOfViews; i++) {
00148     vuVector from1     = views[i].getLookFrom().makeUnit();
00149     float    dot       = lookFrom.dot(from1);
00150     float    lastDot   = 0.0f; 
00151     dword    lastIdx   = 0;
00152     bool     didFound  = false;
00153 
00154     for (dword j=0; j<count; j++) {
00155       if (didFound) {
00156         float tmpDot = dots[j];
00157         dword tmpIdx = idxList[j];
00158 
00159         dots[j]    = lastDot;
00160         idxList[j] = lastIdx;
00161 
00162         lastDot = tmpDot;
00163         lastIdx = tmpIdx;
00164       }
00165       else if (dot > dots[j]) {
00166         lastDot = dots[j];
00167         lastIdx = idxList[j];
00168 
00169         dots[j]     = dot;
00170         idxList[j] = i;
00171 
00172         didFound = true;
00173       }
00174     }
00175   }
00176   delete [] dots;
00177   return true;
00178 }
00179 
00180 template <int S, class T> bool vuSphericFilter<S,T>::
00181 getNearestViews(dword* &idxList, dword &count, vuVector lookFrom,
00182                 dword numOfViews, vuSphericView<S,T>** views)
00183 {
00184   if (count == 0) { // count=> how many views have to be calculated?
00185     cerr << "vuSphFlt.getNearestView(): count is 0!" << endl;
00186     return false;
00187   }
00188   if (idxList != NULL) {
00189     cerr << "vuSphFlt.getNearestView():idxList is not initalized" << endl;
00190     return false;
00191   }
00192   if (numOfViews == 0) {
00193     cerr << "vuSphFlt.getNearestView(): numOfViews is 0!" << endl;
00194     return false;
00195   }
00196   
00197   dword    i;
00198   float    *dots = NULL; // holds the last computed dot products
00199 
00200   if (count > numOfViews) count = numOfViews; 
00201 
00202   idxList = new dword[count];
00203   dots    = new float[count];
00204 
00205   for (i=0; i<count; i++) {
00206     idxList[i] = 0;
00207     dots[i]    = -1.0f;
00208   }
00209 
00210   for(i=0; i<numOfViews; i++) {
00211     vuVector from1     = views[i]->getLookFrom().makeUnit();
00212     float    dot       = lookFrom.dot(from1);
00213     float    lastDot   = 0.0f; 
00214     dword    lastIdx   = 0;
00215     bool     didFound  = false;
00216 
00217     for (dword j=0; j<count; j++) {
00218       if (didFound) {
00219         float tmpDot = dots[j];
00220         dword tmpIdx = idxList[j];
00221 
00222         dots[j]    = lastDot;
00223         idxList[j] = lastIdx;
00224 
00225         lastDot = tmpDot;
00226         lastIdx = tmpIdx;
00227       }
00228       else if (dot > dots[j]) {
00229         lastDot = dots[j];
00230         lastIdx = idxList[j];
00231 
00232         dots[j]     = dot;
00233         idxList[j] = i;
00234 
00235         didFound = true;
00236       }
00237     }
00238   }
00239   delete [] dots;
00240   return true;
00241 }
00242 
00243 template <int S, class T>
00244 bool vuSphericFilter<S,T>::operator==(const vuSphericFilter<S,T> &other)
00245 {
00246   if (this == &other) return true;
00247   else return false;
00248 }
00249 
00250 template <int S, class T>
00251 bool vuSphericFilter<S,T>::operator!=(const vuSphericFilter<S,T> &other)
00252 {
00253   return !(operator==(other));
00254 }

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