
#include "ImportOBJ.h"
#include "ComputeEdgeLength.h"
#include "PropertyMap.h"
#include "CGAL/Simple_cartesian.h"
#include "CGAL/Polyhedron_items_3.h"
#include "CGAL/HalfedgeDS_list.h"
#include "CGAL/Polyhedron_3.h"

typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel, 
	                       CGAL::Polyhedron_items_3, 
						   CGAL::HalfedgeDS_list> CgalPolyhedron;

// Compute the length of all half-edges in a CGAL::Polyhedron_3 and stores it 
// in edgeLengths.
// TPolyhedron is a type of CGAL::Polyhedron_3.
// TEdgeLengths is a property map which associates the edge length to half-edge 
// in the CGAL::Polyhdeon_3.
template<class TPolyhedron, class TEdgeLengths>
void computeEdgeLengths(const TPolyhedron& polyhedron, TEdgeLengths* edgeLengths)
{
	if(edgeLengths == 0)
	{
		return;
	}
	
	typename TPolyhedron::Halfedge_const_iterator _begin = polyhedron.halfedges_begin();
	typename TPolyhedron::Halfedge_const_iterator _end   = polyhedron.halfedges_end();

	SMeshLib::Operations::ComputeEdgeLength<TPolyhedron> _computeEdgeLength;
	CGAL_For_all(_begin, _end)
	{
		edgeLengths->setValue(&*_begin, _computeEdgeLength(*_begin));
	}
}

void testComputeEdgeLength()
{
	CgalPolyhedron _poly;
	SMeshLib::IO::importOBJ("Venus.obj", &_poly);
	
	typedef SMeshLib::PropertyMap<const CgalPolyhedron::Halfedge*, double> EdgeLengthPM;
	EdgeLengthPM _edgeLengths;
	computeEdgeLengths(_poly, &_edgeLengths);
}
