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

vuSphericView.cpp

Go to the documentation of this file.
00001 #include "vuSphericView.h"
00002 
00003 template <int S, class T>
00004 vuSphericView<S,T>::vuSphericView()
00005 {
00006   m_map        = NULL;
00007   m_lookFrom   = vuVector(1,0,0);
00008   m_up         = vuVector(0,1,0);
00009   m_isMapNewed = false;
00010 }
00011 
00012 template <int S, class T>
00013 vuSphericView<S,T>::vuSphericView(vuFixelMap<S,T> *map,
00014                                   vuVector &lookFrom,
00015                                   vuVector &up)
00016 {
00017   m_map        = map;
00018   m_lookFrom   = lookFrom;
00019   m_up         = up;
00020   m_isMapNewed = false;
00021 }
00022 
00023 template <int S, class T>
00024 vuSphericView<S,T>::vuSphericView(dword width, dword height,
00025                                   vuVector lookFrom,
00026                                   vuVector up)
00027 {
00028   m_map        = new vuFixelMap<S,T>(width, height);
00029   m_lookFrom   = lookFrom;
00030   m_up         = up;
00031   m_isMapNewed = true;
00032 }
00033 
00034 template <int S, class T>
00035 vuSphericView<S,T>::~vuSphericView()
00036 {
00037   if (m_isMapNewed && m_map != NULL) {
00038     delete m_map;
00039     m_map = NULL;
00040   }
00041 }
00042 
00043 template <int S, class T>
00044 vuSphericView<S,T>::vuSphericView(const vuSphericView &other)
00045 {
00046   cerr << "vuSphericView(other)" << endl;
00047   if (!other.m_isMapNewed) {
00048     m_map        = other.m_map;
00049     m_lookFrom   = other.m_lookFrom;
00050     m_up         = other.m_up;
00051     m_isMapNewed = false;
00052   }
00053   else {
00054     cerr << "vuSphericView::copy constructor this case is not implmented!";
00055     cerr << endl;
00056     throw "vuSphericView::copy constructor this case is not implmented!";
00057   }
00058 }
00059 
00060 template <int S, class T>
00061 void vuSphericView<S,T>::setLookFrom(const vuVector &lookFrom)
00062 {
00063   m_lookFrom = lookFrom;
00064 }
00065 
00066 template <int S, class T>
00067 vuVector &vuSphericView<S,T>::getLookFrom()
00068 {
00069   return m_lookFrom;
00070 }
00071 
00072 template <int S, class T>
00073 void vuSphericView<S,T>::setUp(const vuVector &up)
00074 {
00075   m_up = up;
00076 }
00077 
00078 template <int S, class T>
00079 vuVector &vuSphericView<S,T>::getUp()
00080 {
00081   return m_up;
00082 }
00083 
00084 
00085 template <int S, class T>
00086 vuFixelMap<S,T> *vuSphericView<S,T>::getMap()
00087 {
00088   return m_map;
00089 }
00090 
00091 template <int S, class T>
00092 dword vuSphericView<S,T>::getWidth()
00093 {
00094   return (m_map == NULL) ? 0 : m_map->getWidth();
00095 }
00096 
00097 
00098 template <int S, class T>
00099 dword vuSphericView<S,T>::getHeight()
00100 {
00101   return (m_map == NULL) ? 0 : m_map->getHeight();
00102 }
00103 
00104 
00105 /* ----------------------------------------------------------------------- */
00106 /* --- some Open Gl related things --------------------------------------- */
00107 /* ----------------------------------------------------------------------- */
00108 
00109 template <int S, class T>
00110 void vuSphericView<S,T>::initOpenGL()
00111 {
00112   if (m_map) m_map->initOpenGL();
00113 }
00114 
00115 template <int S, class T>
00116 void vuSphericView<S,T>::glResize(dword width, dword height)
00117 {
00118   if (m_map) m_map->glResize(width, height);
00119 }
00120 
00121 template <int S, class T>
00122 void vuSphericView<S,T>::glRender()
00123 {
00124   if (m_map) m_map->glRender();
00125 }
00126 
00127 
00128 
00129 template <int S, class T>
00130 vuSphericView<S,T> &vuSphericView<S,T>::operator=(const vuSphericView &other)
00131 {
00132   if (!other.m_isMapNewed) {
00133     m_map        = other.m_map;
00134     m_lookFrom   = other.m_lookFrom;
00135     m_up         = other.m_up;
00136     m_isMapNewed = false;
00137   }
00138   else {
00139     cerr << "vuSphericView::operator= this case is not implmented!";
00140     cerr << endl;
00141     throw "vuSphericView::operator= this case is not implmented!";
00142   }
00143   return *this;
00144 }
00145 
00146 template <int S, class T>
00147 bool vuSphericView<S,T>::writeToFileStream(ostream *out)
00148 {
00149   if (out) {
00150     m_lookFrom.normalize(); // sets 4th component to 1.0 (homogenous space)
00151     out->write((const char*)&m_lookFrom[0], sizeof(float));
00152     out->write((const char*)&m_lookFrom[1], sizeof(float));
00153     out->write((const char*)&m_lookFrom[2], sizeof(float));
00154 
00155     m_up.normalize(); // sets 4th component to 1.0 (homogenous space)
00156     out->write((const char*)&m_up[0], sizeof(float));
00157     out->write((const char*)&m_up[1], sizeof(float));
00158     out->write((const char*)&m_up[2], sizeof(float));
00159 
00160     if (out->bad()) return false;
00161     if (m_map != NULL)
00162       return m_map->writeToFileStream(out);
00163     else
00164       return false; // nothing to write, but it's still wrong
00165   }
00166   return false;
00167 }
00168 
00169 template <int S, class T>
00170 bool vuSphericView<S,T>::readFromFileStream(istream *in,
00171                                             dword width,
00172                                             dword height)
00173 {
00174   if (in) {
00175     in->read((char*)&m_lookFrom[0], sizeof(float));
00176     in->read((char*)&m_lookFrom[1], sizeof(float));
00177     in->read((char*)&m_lookFrom[2], sizeof(float));
00178     m_lookFrom[3] = 1.0f;
00179 
00180     in->read((char*)&m_up[0], sizeof(float));
00181     in->read((char*)&m_up[1], sizeof(float));
00182     in->read((char*)&m_up[2], sizeof(float));
00183     m_up[3] = 1.0f;
00184 
00185     if (in->bad()) return false;
00186     if (m_map == NULL) {
00187       m_map        = new vuFixelMap<S,T>;
00188       m_isMapNewed = true;
00189     }
00190     return m_map->readFromFileStream(in, width, height);
00191   }
00192   return false;
00193 }
00194 
00195 template <int S, class T>
00196 void vuSphericView<S,T>::readFromBuffer(byte *buffer,
00197                                         dword width,
00198                                         dword height)
00199 {
00200   float *fBuf = (float *)buffer;
00201     
00202   m_lookFrom[0] = *fBuf; fBuf++;
00203   m_lookFrom[1] = *fBuf; fBuf++;
00204   m_lookFrom[2] = *fBuf; fBuf++;
00205   m_lookFrom[3] = 1.0f;
00206 
00207   m_up[0] = *fBuf; fBuf++;
00208   m_up[1] = *fBuf; fBuf++;
00209   m_up[2] = *fBuf; fBuf++;
00210   m_up[3] = 1.0f;
00211  
00212   byte *ptr = (byte *)fBuf;
00213 
00214   if (m_map == NULL) {
00215     m_map        = new vuFixelMap<S,T>;
00216     m_isMapNewed = true;
00217   }
00218   m_map->assignBuffer((T*)ptr, width, height);
00219 }
00220 
00221 template <int S, class T>
00222 void vuSphericView<S,T>::writeIntoBuffer(byte *buffer,
00223                                          dword width,
00224                                          dword height)
00225 {
00226   float *fBuf = (float *)buffer;
00227     
00228   m_lookFrom.normalize(); // sets 4th component to 1.0 (homogenous space)
00229   *fBuf = m_lookFrom[0]; fBuf++;
00230   *fBuf = m_lookFrom[1]; fBuf++;
00231   *fBuf = m_lookFrom[2]; fBuf++;
00232 
00233   m_up.normalize(); // sets 4th component to 1.0 (homogenous space)
00234   *fBuf = m_up[0]; fBuf++;
00235   *fBuf = m_up[1]; fBuf++;
00236   *fBuf = m_up[2]; fBuf++;
00237 
00238   // Info: this method only writes the viewing anlges into the buffer
00239 }
00240 
00241 template <int S, class T>
00242 dword vuSphericView<S,T>::getSizeInByte(dword width, dword height)
00243 { 
00244   dword result = 0;
00245 
00246   result += (S*sizeof(T)*width*height); // m_map
00247   result += (3*sizeof(float));          // m_lookFrom (3 floats)
00248   result += (3*sizeof(float));          // m_up       (3 floats)
00249   return (result);
00250 }

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