/// 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_STATSCALCULATOR_H
#define X3DTK_MESH_STATSCALCULATOR_H

#include "MESH_StatsCalculatorStateVariables.h"
#include "X3DOnePassProcessor.h"
#include "MESH_SceneGraphTypes.h"
#include "DFSGraphTraversal.h"
#include "MESH_StatsCalculatorCoreVisitor.h"
#include "MESH_Mesh.h"
#include "MESH_MeshData.h"

namespace X3DTK {
namespace MESH {

/*! \brief Class declared in <b><X3DTK/MESH/statscalculator.h></b> providing a processor that 
 *  computes some statistics of a MESH scene graph.
 *
 *  You can get:
 *  \li the number of vertices, edges and faces of the model.
 *  \li the number of instances of each X3DTK::MESH::TemplateMesh.
 *  \li the number of vertices, edges and faces per X3DTK::MESH::TemplateMesh.
 *  
 *  \ingroup MESH
 */

template<class MData, class VData, class EData, class FData, bool RW>
class TemplateStatsCalculator : public X3DOnePassProcessor
{
public:
  /// Constructor.
  TemplateStatsCalculator();
  /// Destructor.
  virtual ~TemplateStatsCalculator();
  
  /// Draws the faces.
  void calculate(X3DNode *N);
  
  /// 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 per node.
  inline unsigned int getFacesOf(SFNode N) const;
  /// Gets the number of vertices per node.
  inline unsigned int getVerticesOf(SFNode N) const;
  /// Gets the number of edges per node.
  inline unsigned int getEdgesOf(SFNode N) const;
  /// Gets the matrix of the node.
  const SFMatrix34f &getMatrixOf(SFNode N);
  
  /// Gets the model Info.
  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 Info.
  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 calculate. If empty, then all the graph is calculated.
  void setSelectedNodes(const MFNode &selectedNodes);
  /// Gets the selected nodes.
  MFNode getSelectedNodes() const;
};

/// Default TemplateStatsCalculator.
typedef TemplateStatsCalculator<MeshData, VertexData, EdgeData, FaceData, true> StatsCalculator;

}
}

#include "MESH_StatsCalculator.inl"

#endif

