// Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud@inria.fr>

#ifndef _Mesh_h_
#define _Mesh_h_

#include <vector>
#include <string>
#include <Eigen/Core>

/** \class Mesh
  * A class to represent a 3D triangular mesh
  */
class Mesh
{
public:
  
    Mesh();

    /** Default constructor loading a triangular mesh from the file \a filename */
    Mesh(const std::string& filename);

    /** Destructor */
    virtual ~Mesh();

    /** Loads a triangular mesh in the OFF format */
    void loadOFF(const std::string& filename);
    void loadOBJ(const std::string& filename);

    /** Send the mesh to OpenGL for drawing
      * \param prg_id id of the GLSL program used to draw the geometry */
    virtual void drawGeometry(int prg_id);

    void create();

protected:
  
    void initialize();
    
    /** Represents a vertex of the mesh */
    struct Vertex
    {
      Vertex()
        : position(Eigen::Vector3f(0,0,0)), normal(Eigen::Vector3f(1,1,1))
      {}
      Vertex(const Eigen::Vector3f& pos)
        : position(pos), normal(Eigen::Vector3f(0,0,0))
      {}
      Vertex(const Eigen::Vector3f& pos, const Eigen::Vector3f& c)
        : position(pos), normal(c)
      {}
      
      
      Eigen::Vector3f position;
      Eigen::Vector3f normal;
    };

    /** The list of vertices */
    std::vector<Vertex> mVertices;
    
    /** The list of face indices */
    std::vector<Eigen::Vector3i> mFaces;
    
    unsigned int mVertexArrayId;
    unsigned int mVertexBufferId; ///< the id of the BufferObject storing the vertex attributes
    unsigned int mIndexBufferId;  ///< the id of the BufferObject storing the faces indices
    bool mIsInitialized;

    //TODO Ajouter une matrice de transformation à l'objet
};

#endif
