#ifndef CURVATURE_H
#define CURVATURE_H

#include "my_mesh.h"
#include "quad_patch.h"


template <typename T>
class MyStats {
private:
    std::vector<T> _distrib ;
public:
    MyStats () {} ;

    void push_back (T data)
		{
			_distrib.push_back(data) ;
		}

    T min ()
		{
			T tmp = _distrib.at(0) ;
			for (size_t i=1 ; i<_distrib.size(); i++)
				{
					if (_distrib.at(i) < tmp)
						tmp = _distrib.at(i) ;
				}
			return tmp ;
		}

    T max ()
		{
			T tmp = _distrib.at(0) ;
			for (size_t i=1 ; i<_distrib.size(); i++)
				{
					if (_distrib.at(i) > tmp)
						tmp = _distrib.at(i) ;
				}
			return tmp ;
		}

    T mean ()
		{
			T acc(0) ;
			std::cout << "acc : " << acc << std::endl;
			if (_distrib.size() > 0)
				{
					for(size_t i=0; i<_distrib.size(); i++)
						{
							acc += _distrib.at(i) ;
						}
					return acc/(_distrib.size()) ;
				}
			else
				return acc ;
		}

    T stdev ()
		{
			return stdev(mean());
		}

    T stdev (T m)
		{
			T acc(0), tmp ;
			if (_distrib.size() > 0)
				{
					for(size_t i=0; i<_distrib.size(); i++)
						{
							tmp = _distrib.at(i) - m ;
							acc += tmp * tmp ;
						}
					return sqrt(acc/(_distrib.size())) ;
				}
			else
				return acc ;
		}
};


class Courbures {
private:
    MyMesh &_mesh ;

public:
    OpenMesh::VPropHandleT<double> vprop_K;
    OpenMesh::VPropHandleT<double> vprop_H;
	OpenMesh::VPropHandleT<QuadPatch> vprop_quad;

	Courbures(MyMesh &mesh) : _mesh(mesh) {}

    void set_fixed_colors() ;
    void normales_locales() ;
    std::vector<MyMesh::VertexHandle> get_two_neighborhood(MyMesh::VertexHandle vh);
    QuadPatch fit_quad(MyMesh::VertexHandle vh);
    void compute_KH() ;
    void set_K_colors() ;
};


#endif