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

volume.cpp

Go to the documentation of this file.
00001 #include "volume.h"
00002 #include "vuString.h"
00003 #include <stdio.h>
00004 #include <string.h>
00005 #include "vuSimpleTypes.h"
00006 
00007 //----------------------------------------------------------------------------
00008 //------------------------- The default constructor --------------------------
00009 //----------------------------------------------------------------------------
00010 
00011 vu1::vu1()
00012 {
00013     m_Data        = NULL;
00014     m_DataSize    = 0;
00015 
00016     m_RenderState = 0;
00017 
00018     m_Error       = false;
00019     m_ErrorLevel  = 0;
00020 
00021     m_rerendering = true;
00022     m_Camera      = NULL;
00023 }
00024 
00025 //----------------------------------------------------------------------------
00026 //------------------------- The copy constructor -----------------------------
00027 //----------------------------------------------------------------------------
00028 
00029 vu1::vu1(const vu1 &inst)
00030 {
00031     //Copy over the instance data.
00032     m_DataSize = inst.m_DataSize;
00033     m_RenderState = inst.m_RenderState;
00034     m_FileName = inst.m_FileName;
00035     m_Header = inst.m_Header;
00036     m_Binary = inst.m_Binary;
00037     m_Error = inst.m_Error;
00038     m_ErrorMessage = inst.m_ErrorMessage;
00039     m_ErrorLevel = inst.m_ErrorLevel;
00040     
00041     //Copy the volume data, if any.
00042     if (inst.m_Data != 0)
00043     {
00044         m_Data = new byte[m_DataSize];
00045         memcpy(m_Data,inst.m_Data,m_DataSize);
00046     }
00047     else
00048         m_Data = 0;
00049     //Copy the camera, if any
00050     if (inst.m_Camera != NULL)
00051     {
00052         throw "Copy constructor of vu1 not fully implemented yet!";
00053     }
00054     else
00055         m_Camera = NULL;
00056 }
00057 
00058 //----------------------------------------------------------------------------
00059 //------------------------- The destructor -----------------------------------
00060 //----------------------------------------------------------------------------
00061 
00062 vu1::~vu1()
00063 {
00064     if (m_Data != NULL) {
00065       delete [] m_Data;
00066       m_Data = NULL;
00067     }
00068     if (m_Camera != NULL) {
00069       delete m_Camera;
00070       m_Camera = NULL;
00071     }
00072 }
00073 
00074 //----------------------------------------------------------------------------
00075 //------------------------- The assignment operator --------------------------
00076 //----------------------------------------------------------------------------
00077 
00078 vu1& vu1::operator=(const vu1 &rhs)
00079 {
00080     if (this != &rhs)
00081     {
00082         //Copy over the instance data.
00083         m_DataSize = rhs.m_DataSize;
00084         m_RenderState = rhs.m_RenderState;
00085         m_FileName = rhs.m_FileName;
00086         m_Header = rhs.m_Header;
00087         m_Binary = rhs.m_Binary;
00088         m_Error = rhs.m_Error;
00089         m_ErrorMessage = rhs.m_ErrorMessage;
00090         m_ErrorLevel = rhs.m_ErrorLevel;
00091 
00092         //Copy over the volume data..
00093         if (m_Data != 0) delete [] m_Data;
00094         if (rhs.m_Data != 0)
00095         {
00096             m_Data = new byte[m_DataSize];
00097             memcpy(m_Data,rhs.m_Data,m_DataSize);
00098         }
00099         else
00100             m_Data = 0;
00101     }
00102     return *this;
00103 }
00104 
00105 //----------------------------------------------------------------------------
00106 //------------------------- public errorOccurred() ---------------------------
00107 //----------------------------------------------------------------------------
00108 
00109 bool vu1::errorOccurred() const
00110 {
00111     return m_Error;
00112 }
00113 
00114 //----------------------------------------------------------------------------
00115 //------------------------- public getErrorLevel() ---------------------------
00116 //----------------------------------------------------------------------------
00117 
00118 byte vu1::getErrorLevel() const
00119 {
00120     return m_ErrorLevel;
00121 }
00122 
00123 //----------------------------------------------------------------------------
00124 //------------------------- public getErrorMessage() -------------------------
00125 //----------------------------------------------------------------------------
00126 
00127 const char *vu1::getErrorMessage() const
00128 {
00129     return m_ErrorMessage.c_str();
00130 }
00131 
00132 //----------------------------------------------------------------------------
00133 //------------------------- public setTransferFunc() --------------------------
00134 //----------------------------------------------------------------------------
00135 
00136 //see comment in .h and for volume::m_TFunc
00137 /*
00138 void vu1::setTransferFunc(const vuTFDesign& tf)  
00139 // Every subclass of volume (i.e. every algorithm) has a transfer function.
00140 {
00141     m_TFunc = tf;
00142 }
00143 */
00144 
00145 //----------------------------------------------------------------------------
00146 //------------------------- public setRenderState() --------------------------
00147 //----------------------------------------------------------------------------
00148 
00149 void vu1::setRenderState(dword val)
00150 {
00151     m_RenderState = val;
00152 }
00153 
00154 //----------------------------------------------------------------------------
00155 //------------------------- public getRenderState() --------------------------
00156 //----------------------------------------------------------------------------
00157 
00158 dword vu1::getRenderState(void) const
00159 {
00160     return m_RenderState;
00161 }
00162 
00163 //----------------------------------------------------------------------------
00164 //------------------------- public getDataSize() -----------------------------
00165 //----------------------------------------------------------------------------
00166 
00167 dword vu1::getDataSize()
00168   //Function useful because m_DataSize is protected and cannot always be
00169   //accessed.
00170 {
00171   return m_DataSize;
00172 }
00173 
00174 //----------------------------------------------------------------------------
00175 //------------------------- public setFileName() -----------------------------
00176 //----------------------------------------------------------------------------
00177 
00178 void vu1::setFileName(const char *val)
00179 {
00180     m_FileName = val;
00181 }
00182 
00183 //----------------------------------------------------------------------------
00184 //------------------------- public getFileName() -----------------------------
00185 //----------------------------------------------------------------------------
00186 
00187 const char *vu1::getFileName() const
00188 {
00189     return m_FileName.c_str();
00190 }
00191 
00192 //----------------------------------------------------------------------------
00193 //------------------------- public getHeader() -------------------------------
00194 //----------------------------------------------------------------------------
00195 
00196 const char *vu1::getHeader() const
00197 {
00198     return m_Header.c_str();
00199 }
00200 
00201 //----------------------------------------------------------------------------
00202 //------------------------- protected close() --------------------------------
00203 //----------------------------------------------------------------------------
00204 
00205 void vu1::close()
00206 {
00207     //Delete the volume data.
00208     if (m_Data != 0) delete [] m_Data;
00209     m_Data = 0;
00210     m_DataSize = 0;
00211     
00212     //Clear the data header.
00213     m_Header.empty();
00214 
00215     //Clear any error information.
00216     m_Error = false;
00217     m_ErrorMessage.empty();
00218     m_ErrorLevel = 0;
00219 }
00220 
00221 //----------------------------------------------------------------------------
00222 //------------------------- protected read() ---------------------------------
00223 //----------------------------------------------------------------------------
00224 
00225 bool vu1::read(FILE *file)
00226 {
00227     int len = 0;
00228     int ret = 0;
00229     char header[257]="";
00230 
00231     //Read in the standard vuVolume header to assert the file type.
00232     ret = fscanf(file,"# vu DataFile Version 1.0%n",&len);
00233     if ((len != 25) || (fgetc(file) != '\n')) return setInvalidFormatError();
00234     ret = 0;  len = 0;
00235 
00236     //Read in the data header and assign it to the header string.
00237     if ( fgets(header,257,file) == NULL ) return setInvalidFormatError();
00238     m_Header = header;
00239 
00240         //There is no m_Header.trim() yet, so
00241         while(m_Header.getLength()>0 && 
00242               m_Header[m_Header.getLength()-1]<=32)
00243             m_Header[m_Header.getLength()-1] = 0;
00244                 
00245     //Read in the format of the file.
00246     if (( fscanf(file,"ASCII %n",&len) == 0 ) && (len >= 6) )
00247         m_Binary = false;
00248     else if (( fscanf(file,"BINARY %n",&len) == 0 ) && (len >= 7) )
00249         m_Binary = true;
00250     else 
00251         return setInvalidFormatError();
00252 
00253     return true;
00254 }
00255 
00256 //----------------------------------------------------------------------------
00257 //------------------------- protected write() --------------------------------
00258 //----------------------------------------------------------------------------
00259 
00260 bool vu1::write(FILE *file) 
00261 {
00262     int ret = 0;
00263 
00264     //Write the standard vuVolume header.
00265     fprintf(file,"# vu DataFile Version 1.0\n");
00266 
00267     //Write the data header.
00268     if (!m_Header.isEmpty())
00269         fprintf(file,"%s\n",m_Header.c_str());
00270     else
00271         fprintf(file,"Volume Data\n");
00272 
00273     //Write the file format.
00274     if (m_Binary)
00275         ret = fprintf(file,"BINARY\n");
00276     else
00277         ret = fprintf(file,"ASCII\n");
00278 
00279     if (ret > 0)
00280         return true;
00281     else
00282         return setWriteError();
00283 };
00284 
00285 //----------------------------------------------------------------------------
00286 //------------------------- protected setError() -----------------------------
00287 //----------------------------------------------------------------------------
00288 
00289 bool vu1::setError(const char *Message, byte ErrorLevel)
00290 {
00291     m_ErrorMessage = Message;
00292     m_ErrorLevel = ErrorLevel;
00293     m_Error = true;
00294 
00295     //Return false for programming conveniance
00296     return false;
00297 }
00298 
00299 //----------------------------------------------------------------------------
00300 //------------------------- protected setInvalidFormatError() ----------------
00301 //----------------------------------------------------------------------------
00302 
00303 bool vu1::setInvalidFormatError()
00304 {
00305     return setError("Unsupported data format.");
00306 }
00307 
00308 //----------------------------------------------------------------------------
00309 //------------------------- protected setWriteError() ------------------------
00310 //----------------------------------------------------------------------------
00311 
00312 bool vu1::setWriteError()
00313 {
00314     return setError("Could not write data to the file.");
00315 }
00316 
00317 bool vu1::IsReRendering ()
00318 {
00319         return m_rerendering;
00320 }
00321 
00322 void vu1::setIsReRendering (bool isit)
00323 {
00324         m_rerendering = isit;
00325 }
00326 
00327 //----------------------------------------------------------------------------
00328 //------------------------------ public preview() ----------------------------
00329 //----------------------------------------------------------------------------
00330 
00331 void vu1::preview(int hint)
00332 {
00333   // sub implementations can provide a (fast renderable) preview here (ms)
00334 }
00335 
00336 void vu1::setCamera(vuCamera *myCamera)
00337 {
00338   if (m_Camera == myCamera) return;
00339 
00340   if (m_Camera != NULL) delete m_Camera;
00341 
00342   m_Camera = myCamera;
00343 }
00344 
00345 vuCamera& vu1::getCamera()
00346 {
00347   return *m_Camera;
00348 }
00349 
00350 vuCamera* vu1::getCameraPtr()
00351 {
00352   return m_Camera;
00353 }
00354 
00355 vuVector vu1::getCenter() const
00356 {
00357   cerr << "Warning: vu1::getCenter() was not overwritten." << endl;
00358   return vuVector();
00359 }
00360 
00361 
00362 void vu1::glInit() 
00363 {
00364   cerr<<"Warning: glInit unimplemented."<<endl;
00365 }
00366 
00367 void vu1::glResize(dword width, dword height)
00368 {
00369   cerr<<"Warning: glResize default implementation."<<endl;
00370 }
00371 

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