/// This file is part of the X3DToolKit library
/// Copyright (C) 2002-2004  Yannick Le Goc (legoc@imag.fr)

/// http://artis.imag.fr/Members/Yannick.Legoc/X3D/

/// This library 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 2.1 of the License, or (at your option) any later version.

/// This library 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 this library; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#ifndef X3DTK_GL_TRIANGLESET_H
#define X3DTK_GL_TRIANGLESET_H

#include "GL_X3DComposedGeometryNode.h"

#include <vector>

namespace X3DTK {
namespace GL {

/*! \brief Class declared in <b><X3DTK/GL/scenegraph.h></b> providing the GL implementation
 *  of X3D::TriangleSet.
 *
 *  \ingroup GLSceneGraph
 */
 
class TriangleSet : public X3DComposedGeometryNode
{
public:
  /// Constructor.
  TriangleSet();
  /// Constructor.
  virtual ~TriangleSet();
 
  /// Sets the N3F_V3F vertexArray.
  void setN3F_V3F_vertexArray(const std::vector<N3F_V3F> &N3F_V3FvertexArray);
  /// Sets the C4F_N3F_V3F vertexArray.
  void setC4F_N3F_V3F_vertexArray(const std::vector<C4F_N3F_V3F> &C4F_N3F_V3FvertexArray);
  /// Sets the T2F_N3F_V3F vertexArray.
  void setT2F_N3F_V3F_vertexArray(const std::vector<T2F_N3F_V3F> &T2F_N3F_V3F_vertexArray);
  /// Sets the T2F_C4F_N3F_V3F vertexArray.
  void setT2F_C4F_N3F_V3F_vertexArray(const std::vector<T2F_C4F_N3F_V3F> &T2F_C4F_N3F_V3F_vertexArray);
  
  /// Gets the N3F_V3F vertexArray.
  inline std::vector<N3F_V3F> &N3F_V3F_vertexArray() {return _N3F_V3F_vertexArray;};
  /// Gets the C4F_N3F_V3F vertexArray.
  inline std::vector<C4F_N3F_V3F> &C4F_N3F_V3F_vertexArray() {return _C4F_N3F_V3F_vertexArray;};
  /// Gets the T2F_N3F_V3F vertexArray.
  inline std::vector<T2F_N3F_V3F> &T2F_N3F_V3F_vertexArray() {return _T2F_N3F_V3F_vertexArray;};
  /// Gets the T2F_C4F_N3F_V3F vertexArray.
  inline std::vector<T2F_C4F_N3F_V3F> &T2F_C4F_N3F_V3F_vertexArray() {return _T2F_C4F_N3F_V3F_vertexArray;};

  /// Updates the attributes of the node.
  virtual void update();
  /// Renders the node in an openGL context.
  virtual void draw() const; 

private:  
  /// N3F_V3F vertexArray.
  std::vector<N3F_V3F> _N3F_V3F_vertexArray;
  /// C4F_N3F_V3F vertexArray.
  std::vector<C4F_N3F_V3F> _C4F_N3F_V3F_vertexArray;
  /// T2F_N3F_V3F vertexArray.
  std::vector<T2F_N3F_V3F> _T2F_N3F_V3F_vertexArray;
  /// T2F_C4F_N3F_V3F vertexArray.
  std::vector<T2F_C4F_N3F_V3F> _T2F_C4F_N3F_V3F_vertexArray;
  
  ///  Computes the vertex Array with no color and no texCoord.
  void computeNoColorNoTexCoord(const MFVec3f &vertexArray, const MFVec3f &normalArray);
  /// Computes the vertex Array with color and no texCoord.
  void computeColorNoTexCoord(const MFVec3f &vertexArray, const MFVec3f &normalArray);
  /// Computes the vertex Array with no color and texCoord.
  void computeNoColorTexCoord(const MFVec3f &vertexArray, const MFVec3f &normalArray);
  /// Computes the vertex Array with color and texCoord.
  void computeColorTexCoord(const MFVec3f &vertexArray, const MFVec3f &normalArray);
  /// Computes the arrays.
  void computeArrays(const MFVec3f &vertexArray, MFVec3f &normalArray);
};

}
}

#endif
