00001 #include "vuSphLfFlt_FitAngle.h"
00002
00003 template <int S, class T>
00004 vuSphLfFlt_FitAngle<S,T>::vuSphLfFlt_FitAngle(const vuString& filterName)
00005 : vuSphericFilter<S,T>(filterName)
00006 {
00007 m_Angle = 45.0;
00008 }
00009
00010
00011 template <int S, class T>
00012 void vuSphLfFlt_FitAngle<S,T>::setAngle(float angle)
00013 {
00014 if (angle < 0) angle = 0;
00015 if (angle > 180) angle = 180;
00016
00017 m_Angle = angle;
00018 }
00019
00020 template <int S, class T>
00021 float vuSphLfFlt_FitAngle<S,T>::getAngle()
00022 {
00023 return m_Angle;
00024 }
00025
00026 template <int S, class T> void vuSphLfFlt_FitAngle<S,T>::
00027 calcFilteredViews(vuSphericView<S,T>**& views,dword& count)
00028 {
00029 CHECKNDELETE(views);
00030 count = 0;
00031
00032 if (m_volume == NULL) return;
00033
00034 float cosOfAngle = cos((m_Angle/180)*M_PI);
00035 dword numOfViews = m_volume->getNumberOfViews();
00036 vuVector lookAt = m_volume->getCameraPtr()->getLookAtVector().makeUnit()*-1;
00037 dword idxOfBest = 0;
00038 float bestDot = -1;
00039
00040 if (numOfViews == 0) return;
00041
00042 vuSphericView<S,T> **viewsTmp = NULL;
00043
00044 viewsTmp = new vuSphericView<S,T>*[numOfViews];
00045
00046 for (dword i=0; i<numOfViews; i++) {
00047 vuSphericView<S,T> *view = m_volume->getView(i);
00048 vuVector lookFrom = view->getLookFrom();
00049 float dot = lookFrom.dot(lookAt);
00050
00051 if (dot > cosOfAngle) {
00052 viewsTmp[count] = view;
00053 count++;
00054 }
00055 if (bestDot < dot) {
00056 bestDot = dot;
00057 idxOfBest = i;
00058 }
00059 }
00060
00061 if (count == 0) {
00062 viewsTmp[count] = m_volume->getView(idxOfBest);
00063 count++;
00064 }
00065
00066 views = new vuSphericView<S,T>*[count];
00067 for (dword i=0; i<count; i++) {
00068 views[i] = viewsTmp[i];
00069 }
00070 CHECKNDELETE(viewsTmp);
00071 }
00072