paella/Code/include/Geometry/Mesh.hpp

151 lines
6.0 KiB
C++

////////////////////////////////////////////////////////////////////////////////
//
// Paella
// Copyright (C) 2015 - Thomas FORGIONE, Emilie JALRAS, Marion LENFANT, Thierry MALON, Amandine PAILLOUX
// Authors :
// Thomas FORGIONE
// Emilie JALRAS
// Marion LENFANT
// Thierry MALON
// Amandine PAILLOUX
//
// This file is part of the project Paella
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
////////////////////////////////////////////////////////////////////////////////
#ifndef MESH_HPP
#define MESH_HPP
#include <vector>
#include <Geometry/Spline.hpp>
#include <Geometry/Vector.hpp>
namespace geo
{
///////////////////////////////////////////////////////////////
/// \brief Utility to manipulate meshes
///////////////////////////////////////////////////////////////
class Mesh
{
public:
//////////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Initialize all arrays
//////////////////////////////////////////////////////////////////
Mesh() : vertices{}, faces{}, glVertices{}, glNormals{} {};
////////////////////////////////////////////////////////////////////////
/// \brief Overload of the operator+=
///
/// \param m Mesh to add to the current mesh
///
/// \return A reference to *this
////////////////////////////////////////////////////////////////////////
Mesh& operator+=(Mesh const& m);
////////////////////////////////////////////////////////////////////////
/// \brief Overload of the operator<<
///
/// \param out Stream to print the mesh
///
/// \param mesh Mesh printed to the stream
///
/// \return A reference to out
///
/// Print the mesh according to the Obj format
////////////////////////////////////////////////////////////////////////
friend std::ostream& operator<<(std::ostream& out, Mesh const& mesh);
////////////////////////////////////////////////////////////////////////
/// \brief Draw the mesh using OpenGL
///
/// \see prepare
///
/// OpenGL must be correctly initialized. You should use prepare to generate
/// the arrays that will be used to draw.
///
////////////////////////////////////////////////////////////////////////
void draw() const;
////////////////////////////////////////////////////////////////////////
/// \brief Draw the edges of the mesh using OpenGL
///
/// \see prepareEdges
///
/// OpenGL must be correctly initialized. You should use prepareEdges to generate
/// the arrays that will be used to draw.
////////////////////////////////////////////////////////////////////////
void drawEdges() const;
////////////////////////////////////////////////////////////////////////
/// \brief Compute the arrays for drawing
///
/// \param gouraudShading If true, gouraudShading will be enabled.
/// Normals will be computed by the mean of the faces in which each
/// vertex is. If false, the normals will be the same for all points in
/// a face.
///
/// \see draw glVertices glNormals
///
////////////////////////////////////////////////////////////////////////
void prepare(bool gouraudShading = true);
////////////////////////////////////////////////////////////////////////
/// \brief Compute the arrays for drawing the edges
///
/// \see drawEdges glVertices glNormals
///
////////////////////////////////////////////////////////////////////////
void prepareEdges();
std::vector<geo::Vector3<float>> vertices; ///< The vertices of the mesh
std::vector<geo::Vector3<unsigned int>> faces; ///< The faces of the mesh
std::vector<geo::Vector3<float>> normals; ///< The normals of each vertex
std::vector<geo::Vector3<float>> glVertices; ///< Vertices for the drawing
std::vector<geo::Vector3<float>> glNormals; ///< Normals for the drawing
private:
////////////////////////////////////////////////////////////////////////
/// \brief Finishes to compute the normals of Gouraud shading
////////////////////////////////////////////////////////////////////////
void prepareGouraudShading();
////////////////////////////////////////////////////////////////////////
/// \brief Finishes to compute the normals
////////////////////////////////////////////////////////////////////////
void prepareNormalShading();
};
////////////////////////////////////////////////////////////////////////
/// \brief create a triangular meshing from circles of a spline
///
/// \param circles Vector containing the circles along the curve of the
/// spline
///
/// \param offset Offset between the vertices indices and the edges
///
/// \return A triangular mesh composed of circles around the spline
////////////////////////////////////////////////////////////////////////
Mesh splineMeshing(std::vector<geo::Circle<float>> const& circles, unsigned int offset=0);
}
#endif // MESH_HPP