src/common.h

Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include "compiler_options.h"
00004 
00005 #include <glew/glew.h>
00006 #include <GL/glu.h>
00007 #include <devil/il.h>
00008 
00009 #include <windows.h>
00010 #include <commdlg.h>
00011 #include <stdlib.h>
00012 #include <io.h>
00013 #include <math.h>
00014 
00015 #include <iostream>
00016 #include <sstream>
00017 #include <string>
00018 
00019 
00020 // workaround: incompatibilities with header files
00021 #undef min
00022 #undef max
00023 
00024 #define TF_TEXTURE_SIZE 4096
00025 
00026 #ifndef PI
00027         #define PI 3.14159265f
00028 #endif
00029 
00030 #define BOUNDARY 0.9125f
00031 
00032 #define SLIDER_RANGE           4096   // range for QSlider elements
00033 #define STEP_SLIDER_RANGE          1000   // range for the maximum number of steps for the RC-ray
00034 #define LIGHT_SLIDER_RANGE     100    // range of light settings
00035 
00036 #define DENSITY_COUNT          4096   // 4096 different density levels in Volume
00037 
00038 #define OPENGL_SLICE_VIEW_SIZE 250  // size of slice-views (width = heigth)
00039 #define OPENGL_3D_VIEW_SIZE    600  // size of 3d-view (width = heigth)
00040 
00041 #define NUMBER_OF_GL_WIDGETS 4    // number of glWidgets for independent OpenGL-views
00042 #define OPENGL_3D_VIEW       3    // number of glWidget for 3D-OpenGL-view
00043 
00044 #define RENDER_3D_VIEW       3    // render-flag 'on' for glWidget for 3D-OpenGL-view
00045 #define NO_RENDER_3D_VIEW    4    // render-flag 'off' for glWidget for 3D-OpenGL-view
00046 
00047 #define SHOW_VOLUME          1    // flag for showing volume in 3D-view
00048 #define SHOW_FRONT_SIDE      2    // flag for showing front-side-cube in 3D-view
00049 #define SHOW_BACK_SIDE       3    // flag for showing back-side-cube in 3D-view
00050 
00051 
00052 typedef enum AXIS {X_AXIS, Y_AXIS, Z_AXIS} AXIS;        // describes axis better than 0..1..2
00053 typedef enum SHADES {RED, GREEN, BLUE, ALPHA, SHADES_COUNT} SHADES;
00054 
00055 typedef enum RENDER_MODE {comp = 0, mip   = 1, fh     = 2, 
00056                           avg  = 3, avgTF = 4, compPh = 5 } RENDER_MODE; // saved in oglWidget::m_rendermode
00057 
00058 typedef enum LIGHT_MODEL {diffuse = 0, ambient, specular, gloss } LIGHT_MODEL;
00059 
00060 // converts from string to Type
00061 template <class Type>
00062 inline const Type fromString(const std::string & strString)
00063 {
00064         Type tValue;
00065         std::stringstream(std::string(strString)) >> tValue;
00066         return tValue;
00067 };
00068 
00069 // converts from string to Type, returns true if successful
00070 template <class Type>
00071 inline const bool fromString(Type & tValue, const std::string & strString)
00072 {
00073         Type tTemp;
00074 
00075         std::stringstream ss;
00076         ss << strString;
00077         ss >> std::ws;
00078 
00079         if (ss >> tTemp)
00080         {
00081                 ss >> std::ws;
00082 
00083                 if (ss.eof())
00084                 {
00085                         tValue = tTemp;
00086                         return true;
00087                 }
00088         }
00089 
00090         return false;
00091 };
00092 
00093 // converts from Type to string
00094 template <class Type>
00095 inline const std::string toString(const Type & tValue)
00096 {
00097         std::stringstream ss;
00098         ss << tValue;
00099         return ss.str();
00100 };
00101 
00102 // trims whitespace form the beginning of the string
00103 inline const std::string trimLeft( const std::string &str, const std::string &strWhitespace = "\n\r\t ")
00104 {
00105         size_t uIndex = str.find_first_not_of(strWhitespace);
00106         if( uIndex != std::string::npos )
00107                 return str.substr(uIndex);
00108 
00109         return "";
00110 };
00111 
00112 // trims whitespace form the end of the string
00113 inline const std::string trimRight( const std::string &str, const std::string &strWhitespace = "\n\r\t ")
00114 {
00115         size_t  uIndex = str.find_last_not_of(strWhitespace);
00116         if( uIndex != std::string::npos )
00117                 return str.substr(0,uIndex+1);
00118 
00119         return str;
00120 };
00121 
00122 // trims whitespace from beginning and end of the string
00123 inline const std::string trim( const std::string &str, const std::string & strWhitespace = "\n\r\t ")
00124 {
00125         return trimRight(trimLeft(str,strWhitespace),strWhitespace);
00126 };
00127 
00128 
00129 // Utility class for STL stream extraction operator
00130 class eat
00131 {
00132         friend std::istream & operator>>(std::istream &is, eat & e);
00133 
00134 public:
00135         eat(const std::string & strString) : m_strString(strString)
00136         {
00137         };
00138 
00139 private:
00140         void process(std::istream & is)
00141         {
00142                 const unsigned int uLength = unsigned int(m_strString.size());
00143 
00144                 if (uLength > 0)
00145                 {
00146                         char c;
00147                         unsigned int uIndex = 0;
00148 
00149                         is >> std::ws;
00150                         std::ios::fmtflags f = is.flags();
00151                         is.unsetf(std::ios::skipws);
00152 
00153                         do
00154                         {
00155                                 if (!(is >> c))
00156                                 {
00157                                         break;
00158                                 }
00159                                 else
00160                                 {
00161                                         if (c != m_strString[uIndex])
00162                                         {
00163                                                 is.setstate(std::ios::failbit);
00164                                                 break;
00165                                         }
00166                                 }
00167                         }
00168                         while (++uIndex < uLength);
00169 
00170                         is.flags(f);
00171 
00172                         if (!is.fail())
00173                                 is >> std::ws;
00174                 }
00175         };
00176 
00177 private:
00178         std::string m_strString;
00179 };
00180 
00181 inline std::istream & operator>> (std::istream &is, eat & e)
00182 {
00183         e.process(is);
00184         return is;
00185 }

Generated on Mon Dec 10 18:18:11 2007 for VisLU by  doxygen 1.5.4