/// 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_SIMPLEMESHLOADER_H
#define X3DTK_SIMPLEMESHLOADER_H

#include "X3D_Loader.h"
#include "MESH_Scene.h"
#include "MESH_Mesh.h"
#include "MESH_MeshData.h"
#include "X3D_Scene.h"
#include "X3D_BBoxUpdater.h"
#include "X3D_WorldCoordTranslator.h"
#include "X3D_MeshBuilder.h"
#include "MESH_NormalsUpdater.h"
#include "MESH_MeshSimplifier.h"
#include "MemReleaser.h"

namespace X3DTK {

/*! \brief Class declared in <b><X3DTK/simplifiedmeshscene.h></b> defining a facade to allow an easy load of a MESH scene.
 *
 * This class is an easy entry point to the library. You can then use the default
 * drawer X3DTK::MESH::TemplateFacesDrawer.
 */
 
template<class MData, class VData, class EData, class FData, bool RW>
class TemplateSimplifiedMeshScene
{
public:
  /// Constructor.
  TemplateSimplifiedMeshScene();
  /// Destructor.
  ~TemplateSimplifiedMeshScene();
  
  /// Loads the file and returns a simple X3DTK::MESH::TemplateMesh node that only has a 
  /// X3DTK::MESH::TemplateVertex node as child. There are some loss of information but 
  /// the structure is light and easily usable.
  void load(const char *file);

  /// Gets the Mesh.
  inline MESH::TemplateMesh<MData, VData, EData, FData, RW> *getMesh() const {return mesh;};
  
  /// Gets the bounding box minimum.
  inline const SFVec3f &getBBoxMin() const {return min;};
  /// Gets the bounding box maximum.
  inline const SFVec3f &getBBoxMax() const {return max;};
  
protected:
  X3D::Loader *loader;
  X3D::BBoxUpdater *bboxupdater;
  X3D::WorldCoordTranslator *translator;
  X3D::TemplateMeshBuilder<MData, VData, EData, FData, RW> *meshbuilder;
  MESH::TemplateNormalsUpdater<MData, VData, EData, FData, RW> *normalsupdater;
  MESH::TemplateMeshSimplifier<MData, VData, EData, FData, RW> *meshsimplifier;
  MemReleaser *releaser;
  MESH::TemplateMesh<MData, VData, EData, FData, RW> *mesh;
  SFVec3f min;
  SFVec3f max;
};

typedef TemplateSimplifiedMeshScene<MESH::MeshData, MESH::VertexData, MESH::EdgeData, MESH::FaceData, true> SimplifiedMeshScene;

}

#include "SimplifiedMeshScene.inl"

#endif
