OpenWalnut  1.5.0dev
WGeometryFunctions.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WGEOMETRYFUNCTIONS_H
26 #define WGEOMETRYFUNCTIONS_H
27 
28 #include <map>
29 #include <utility>
30 #include <vector>
31 
32 #include "../WAssert.h"
33 #include "linearAlgebra/WVectorFixed.h"
34 
35 namespace utility
36 {
37  /**
38  * \class Edge
39  *
40  * A helper class that is used to store edges as pairs of vertex indices. The indices are sorted.
41  */
42  class Edge : public std::pair< unsigned int, unsigned int >
43  {
44  public:
45  /**
46  * Constructor that sorts the input indices.
47  *
48  * \param i the first index.
49  * \param j The second index.
50  */
51  Edge( unsigned int i, unsigned int j )
52  : std::pair< unsigned int, unsigned int >( i < j ? i : j, i < j ? j : i )
53  {
54  }
55 
56  /**
57  * Compare two edges. This operator defines a weak ordering on the edges.
58  *
59  * \param e The edge to compare to.
60  * \return True, iff this edge is 'smaller' than the given edge.
61  */
62  bool operator < ( Edge const& e ) const
63  {
64  return first < e.first || ( first == e.first && second < e.second );
65  }
66 
67  /**
68  * Compare two edges for equality.
69  *
70  * \param e The edge to compare to.
71  * \return True, iff this edge has the same vertex indices as the given edge.
72  */
73  bool operator == ( Edge const& e ) const
74  {
75  return first == e.first && second == e.second;
76  }
77  };
78 
79 } // namespace utility
80 
81 /**
82  * Tesselates an icosahedron in order to generate a triangle-based approximation of a sphere.
83  * The content of the provided vectors will be cleared and replaced. Triangle vertices are stored as
84  * successive values in the triangle vector.
85  *
86  * \param[out] vertices The vertices of the mesh.
87  * \param[out] triangles The resulting triangles as a list of indices into the vertex vector.
88  * \param level The tesselation level.
89  */
90 void tesselateIcosahedron( std::vector< WVector3d >* vertices, std::vector< unsigned int >* triangles, unsigned int level );
91 
92 #endif // WGEOMETRYFUNCTIONS_H
A helper class that is used to store edges as pairs of vertex indices.
bool operator<(Edge const &e) const
Compare two edges.
Edge(unsigned int i, unsigned int j)
Constructor that sorts the input indices.
bool operator==(Edge const &e) const
Compare two edges for equality.