OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WGEOMETRYFUNCTIONS_H 00026 #define WGEOMETRYFUNCTIONS_H 00027 00028 #include <map> 00029 #include <utility> 00030 #include <vector> 00031 00032 #include "../WAssert.h" 00033 #include "linearAlgebra/WVectorFixed.h" 00034 00035 namespace utility 00036 { 00037 /** 00038 * \class Edge 00039 * 00040 * A helper class that is used to store edges as pairs of vertex indices. The indices are sorted. 00041 */ 00042 class Edge : public std::pair< unsigned int, unsigned int > 00043 { 00044 public: 00045 /** 00046 * Constructor that sorts the input indices. 00047 * 00048 * \param i the first index. 00049 * \param j The second index. 00050 */ 00051 Edge( unsigned int i, unsigned int j ) 00052 : std::pair< unsigned int, unsigned int >( i < j ? i : j, i < j ? j : i ) 00053 { 00054 } 00055 00056 /** 00057 * Compare two edges. This operator defines a weak ordering on the edges. 00058 * 00059 * \param e The edge to compare to. 00060 * \return True, iff this edge is 'smaller' than the given edge. 00061 */ 00062 bool operator < ( Edge const& e ) const 00063 { 00064 return first < e.first || ( first == e.first && second < e.second ); 00065 } 00066 00067 /** 00068 * Compare two edges for equality. 00069 * 00070 * \param e The edge to compare to. 00071 * \return True, iff this edge has the same vertex indices as the given edge. 00072 */ 00073 bool operator == ( Edge const& e ) const 00074 { 00075 return first == e.first && second == e.second; 00076 } 00077 }; 00078 00079 } // namespace utility 00080 00081 /** 00082 * Tesselates an icosahedron in order to generate a triangle-based approximation of a sphere. 00083 * The content of the provided vectors will be cleared and replaced. Triangle vertices are stored as 00084 * successive values in the triangle vector. 00085 * 00086 * \param[out] vertices The vertices of the mesh. 00087 * \param[out] triangles The resulting triangles as a list of indices into the vertex vector. 00088 * \param level The tesselation level. 00089 */ 00090 void tesselateIcosahedron( std::vector< WVector3d >* vertices, std::vector< unsigned int >* triangles, unsigned int level ); 00091 00092 #endif // WGEOMETRYFUNCTIONS_H