Equalizer  1.2.1
typedefs.h
00001 
00002 /* Copyright (c) 2007, Tobias Wolf <twolf@access.unizh.ch>
00003  *               2009, Cedric Stalder <cedric.stalder@gmail.com>
00004  *               2011, Stefan Eilemann <eile@eyescale.ch>
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright notice, this
00010  *   list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright notice,
00012  *   this list of conditions and the following disclaimer in the documentation
00013  *   and/or other materials provided with the distribution.
00014  * - Neither the name of Eyescale Software GmbH nor the names of its
00015  *   contributors may be used to endorse or promote products derived from this
00016  *   software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028  * POSSIBILITY OF SUCH DAMAGE.
00029   
00030     
00031     Type definitions for the mesh classes.
00032 */
00033 
00034 
00035 #ifndef MESH_TYPEDEFS_H
00036 #define MESH_TYPEDEFS_H
00037 
00038 #define EQUALIZER  1
00039 
00040 #ifdef EQUALIZER
00041 #  include <eq/eq.h>
00042 #  define MESHASSERT  EQASSERT
00043 #  define MESHERROR   EQERROR
00044 #  define MESHWARN    EQWARN
00045 #  define MESHINFO    EQINFO
00046 #else
00047 #  include <vmmlib/vmmlib.hpp>
00048 #  ifdef _WIN32
00049 #    include <Winsock2.h>
00050 #    include <Windows.h>
00051 #  endif
00052 #  ifdef __APPLE__
00053 #    include <OpenGL/gl.h>
00054 #  else
00055 #    include <GL/gl.h>
00056 #  endif
00057 #  include <cassert>
00058 #  define MESHASSERT  assert
00059 #  define MESHERROR   std::cerr
00060 #  define MESHWARN    std::cout
00061 #  define MESHINFO    std::cout
00062 #endif
00063 
00064 #include <exception>
00065 #include <iostream>
00066 #include <string>
00067 
00068 namespace mesh 
00069 {
00070     // basic type definitions   
00071     typedef vmml::vector< 3, GLfloat >    Vertex;
00072     typedef vmml::vector< 4, GLubyte >    Color;
00073     typedef vmml::vector< 3, GLfloat >    Normal;
00074     typedef vmml::matrix< 4, 4, float >   Matrix4f;
00075     typedef size_t                        Index;
00076     typedef GLushort                      ShortIndex;    
00077     
00078     // mesh exception
00079     struct MeshException : public std::exception
00080     {
00081         explicit MeshException( const std::string& msg ) : _message( msg ) {}
00082         virtual ~MeshException() throw() {}
00083         virtual const char* what() const throw() { return _message.c_str(); }
00084     private:
00085         std::string _message;
00086     };
00087     
00088     // null output stream that discards everything written to it
00089     struct NullOStream : std::ostream
00090     {
00091         struct NullStreamBuf : std::streambuf
00092         {
00093             int overflow( int c ) { return traits_type::not_eof( c ); }
00094         } _nullBuf;
00095         
00096         NullOStream() : std::ios( &_nullBuf ), std::ostream( &_nullBuf ) {}
00097     };
00098     
00099     // wrapper to enable array use where arrays would not be allowed otherwise
00100     template< class T, size_t d >
00101     struct ArrayWrapper
00102     {
00103         ArrayWrapper() {}
00104         ArrayWrapper( const T* from ) { memcpy( data, from, sizeof( data )); }
00105         T& operator[]( const size_t i )
00106         {
00107             MESHASSERT( i < d );
00108             return data[i];
00109         }
00110         
00111         const T& operator[]( const size_t i ) const
00112         {
00113             MESHASSERT( i < d );
00114             return data[i];
00115         }
00116         
00117     private:
00118         T data[d];
00119     };
00120     
00121     
00122     // compound type definitions
00123     typedef vmml::vector< 3, Index >    Triangle;
00124     typedef ArrayWrapper< Vertex, 2 >   BoundingBox;
00125     typedef vmml::vector< 4, float >    BoundingSphere;
00126     typedef ArrayWrapper< float, 2 >    Range;    
00127     
00128     // maximum triangle count per leaf node (keep in mind that the number of
00129     // different vertices per leaf must stay below ShortIndex range; usually
00130     // #vertices ~ #triangles/2, but max #vertices = #triangles * 3)
00131     const Index             LEAF_SIZE( 21845 );
00132     
00133     // binary mesh file version, increment if changing the file format
00134     const unsigned short    FILE_VERSION ( 0x0115 );
00135     
00136     
00137     // enumeration for the sort axis
00138     enum Axis
00139     {
00140         AXIS_X,
00141         AXIS_Y,
00142         AXIS_Z
00143     };
00144     inline std::ostream& operator << ( std::ostream& os, const Axis axis )
00145     {
00146         os << ( axis == AXIS_X ? "x axis" : axis == AXIS_Y ? "y axis" :
00147                 axis == AXIS_Z ? "z axis" : "ERROR" );
00148         return os;
00149     }
00150     
00151     // enumeration for the buffer objects
00152     enum BufferObject
00153     {
00154         VERTEX_OBJECT,
00155         NORMAL_OBJECT,
00156         COLOR_OBJECT,
00157         INDEX_OBJECT
00158     };
00159     
00160     // enumeration for the render modes
00161     enum RenderMode
00162     {
00163         RENDER_MODE_IMMEDIATE = 0,
00164         RENDER_MODE_DISPLAY_LIST,
00165         RENDER_MODE_BUFFER_OBJECT,
00166         RENDER_MODE_ALL // must be last
00167     };
00168     inline std::ostream& operator << ( std::ostream& os, const RenderMode mode )
00169     {
00170         os << ( mode == RENDER_MODE_IMMEDIATE     ? "immediate mode" : 
00171                 mode == RENDER_MODE_DISPLAY_LIST  ? "display list mode" : 
00172                 mode == RENDER_MODE_BUFFER_OBJECT ? "VBO mode" : "ERROR" );
00173         return os;
00174     }
00175     
00176     // enumeration for kd-tree node types
00177     enum NodeType
00178     {
00179         ROOT_TYPE = 0x07,
00180         NODE_TYPE = 0xde,
00181         LEAF_TYPE = 0xef
00182     };
00183     
00184     
00185     // helper function for MMF (memory mapped file) reading
00186     inline void memRead( char* destination, char** source, size_t length )
00187     {
00188         memcpy( destination, *source, length );
00189         *source += length;
00190     }
00191     
00192     
00193     // internally linked null stream, every translation unit gets a copy
00194     static mesh::NullOStream cnul;
00195 }
00196 
00197 
00198 #endif // MESH_TYPEDEFS_H
Generated on Fri Jun 8 2012 15:44:32 for Equalizer 1.2.1 by  doxygen 1.8.0