/// 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_MESH_STATSCALCULATORSTATEVARIABLES_H
#define X3DTK_MESH_STATSCALCULATORSTATEVARIABLES_H

#include "MESH_SceneGraphTypes.h"
#include "MESH_Mesh.h"
#include "MESH_Info.h"

#include <list>
#include <map>
#include <vector>

namespace X3DTK {
namespace MESH {

/*! \brief Class declared in <b><X3DTK/MESH/statscalculator.h></b> providing the StateVariables
 *  of the MESH::TemplateStatsCalculator processor.
 *
 *  \ingroup MESH
 */

template<class MData, class VData, class EData, class FData, bool RW>
class TemplateStatsCalculatorStateVariables : public StateVariables
{
public:
  /// Constructor.
  TemplateStatsCalculatorStateVariables();

  /// Initializes the traversal.
  void init();
  /// Finishes the traversal.
  void finish();

  /// Adds the node.
  void addNode(SFNode N);
  /// Returns true if the node has already been visited.
  bool getNode(SFNode N) const;
  
  /// Sets the current Mesh.
  void setCurrentMesh(TemplateMesh<MData, VData, EData, FData, RW> *mesh);
  /// Adds the number of faces.
  void addFaces(unsigned int faces);
  /// Adds the number of vertices.
  void addVertices(unsigned int vertices);
  /// Adds the number of edges.
  void addEdges(unsigned int edges);
  /// Sets the number of instances.
  void setInstances(unsigned int instances);
  
  /// Gets the number of faces.
  inline unsigned int getModelFaces() const;
  /// Gets the number of vertices.
  inline unsigned int getModelVertices() const;
  /// Gets the number of edges.
  inline unsigned int getModelEdges() const;
  
  /// Gets the number of faces.
  inline unsigned int getFacesOf(SFNode N);
  /// Gets the number of vertices.
  inline unsigned int getVerticesOf(SFNode N);
  /// Gets the number of edges.
  inline unsigned int getEdgesOf(SFNode N);
  
  /// Gets the model MeshInfo.
  inline const TemplateMeshInfo<MData, VData, EData, FData, RW> &getModelMeshInfo() const;
  /// Gets the list of Mesh, Info pair.
  inline const std::list<std::pair<SFNode, TemplateMeshInfo<MData, VData, EData, FData, RW> > > &getMeshInfoList() const;
  /// Gets the model VertexInfo.
  inline const TemplateVertexInfo<MData, VData, EData, FData, RW> &getModelVertexInfo() const;
  /// Gets the list of Mesh, Info pair.
  inline const std::list<std::pair<SFNode, TemplateVertexInfo<MData, VData, EData, FData, RW> > > &getVertexInfoList() const;
    
  /// Sets the selected nodes to draw. If empty, then all the graph is drawn.
  void setSelectedNodes(const MFNode &selectedNodes);
  /// Gets the selected nodes to draw. If empty, then all the graph is drawn.
  MFNode getSelectedNodes() const;
  
private:
  std::list<SFNode> _nodeList;
  TemplateMesh<MData, VData, EData, FData, RW> *_currentMesh;
  TemplateMeshInfo<MData, VData, EData, FData, RW> _modelMeshInfo;
  TemplateVertexInfo<MData, VData, EData, FData, RW> _modelVertexInfo;
  std::list<std::pair<SFNode, TemplateMeshInfo<MData, VData, EData, FData, RW> > > _meshInfoList;
  std::list<std::pair<SFNode, TemplateVertexInfo<MData, VData, EData, FData, RW> > > _vertexInfoList;
  MFNode _selectedNodes;
};

}
}

#include "MESH_StatsCalculatorStateVariables.inl"

#endif
