WGeometryFunctions.h 3.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WGEOMETRYFUNCTIONS_H
#define WGEOMETRYFUNCTIONS_H

#include <map>
Mathias Goldau's avatar
Mathias Goldau committed
29
#include <utility>
30 31 32
#include <vector>

#include "../WAssert.h"
33
#include "linearAlgebra/WVectorFixed.h"
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

namespace utility
{
    /**
     * \class Edge
     *
     * A helper class that is used to store edges as pairs of vertex indices. The indices are sorted.
     */
    class Edge : public std::pair< unsigned int, unsigned int >
    {
    public:
        /**
         * Constructor that sorts the input indices.
         *
         * \param i the first index.
         * \param j The second index.
         */
        Edge( unsigned int i, unsigned int j )
            : std::pair< unsigned int, unsigned int >( i < j ? i : j, i < j ? j : i )
        {
        }

        /**
         * Compare two edges. This operator defines a weak ordering on the edges.
         *
         * \param e The edge to compare to.
         * \return True, iff this edge is 'smaller' than the given edge.
         */
        bool operator < ( Edge const& e ) const
        {
            return first < e.first || ( first == e.first && second < e.second );
        }

        /**
         * Compare two edges for equality.
         *
         * \param e The edge to compare to.
         * \return True, iff this edge has the same vertex indices as the given edge.
         */
        bool operator == ( Edge const& e ) const
        {
            return first == e.first && second == e.second;
        }
    };

} // namespace utility

/**
 * Tesselates an icosahedron in order to generate a triangle-based approximation of a sphere.
 * The content of the provided vectors will be cleared and replaced. Triangle vertices are stored as
 * successive values in the triangle vector.
 *
 * \param[out] vertices The vertices of the mesh.
 * \param[out] triangles The resulting triangles as a list of indices into the vertex vector.
 * \param level The tesselation level.
 */
90
void tesselateIcosahedron( std::vector< WVector3d >* vertices, std::vector< unsigned int >* triangles, unsigned int level );
91 92

#endif  // WGEOMETRYFUNCTIONS_H